IAPL rename: the old names keep working, and a second cookie name and counter key for new sites

- exports: ipalKit, IpalOptions, ipalEnvRules, IpalEnvFeatures, ipalT, ipalVar, IPAL_TOKENS,
  IPAL_BREAKPOINTS, IpalTokenName, IpalGlobalSlug are aliases of the iapl names
- env: IAPL_* is read first, IPAL_* as fallback (readEnv; EnvRule.aliases for assertEnv);
  the crawler service reads IPAL_CRAWLER_SITES too
- doctor: reads ipal-doctor.json when it is the only one, the old pointer block, ipal-audit-skip
  and old skill folders; new rule legacy-names (info) and storage-names (warning)
- iapl-skills: installs iapl-*, removes the 16 old folders by exact name, rewrites the old
  pointer block in place; a project's own ipal-* skill stays
- storageNames: 'ipal' (default) | 'iapl': the cookie the scanner declares and the 2FA counter's
  kv prefix; <PageStats visitorCookie>, IAPL_VISITOR_COOKIE, verifyLimit.keyPrefix
- test/legacyNames.test.ts: 24 tests for all of the above

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-25 17:31:13 +01:00
co-authored by Claude Fable 5.2
parent 0a4f001797
commit 425fac14fb
43 changed files with 683 additions and 82 deletions
+24
View File
@@ -0,0 +1,24 @@
/**
* The plugin's own environment variables are spelled `IAPL_<NAME>` since 1.17.0. Before that
* they were `IPAL_<NAME>`, and a deploy that still sets the old spelling keeps working: the new
* name is read first, the old one when the new one is missing or empty. Both set → the new one wins
* (iapl-doctor reports the pair when they differ).
*/
export const ENV_PREFIX = 'IAPL_'
export const LEGACY_ENV_PREFIX = 'IPAL_'
type Env = Record<string, string | undefined>
/** `IAPL_IP_HEADER` → `IPAL_IP_HEADER`; undefined for a name that is not the plugin's. */
export function legacyEnvName(name: string): string | undefined {
return name.startsWith(ENV_PREFIX) ? `${LEGACY_ENV_PREFIX}${name.slice(ENV_PREFIX.length)}` : undefined
}
/** Value of a plugin variable under its new name, else under its old one. Not trimmed. */
export function readEnv(name: string, env: Env = process.env): string | undefined {
const value = env[name]
if (typeof value === 'string' && value.trim() !== '') {return value}
const legacy = legacyEnvName(name)
const old = legacy ? env[legacy] : undefined
return typeof old === 'string' && old.trim() !== '' ? old : value
}
+3 -1
View File
@@ -1,3 +1,5 @@
import { readEnv } from './envName.js'
type Bucket = { count: number; resetAt: number }
/**
@@ -203,7 +205,7 @@ let warnedUnpinned = false
export function clientIp(source: Headers | Request, options: ClientIpOptions = {}): string {
const h = source instanceof Headers ? source : source.headers
const pinned = options.header ?? process.env.IAPL_IP_HEADER
const pinned = options.header ?? readEnv('IAPL_IP_HEADER')
if (!pinned && !warnedUnpinned && process.env.NODE_ENV === 'production') {
warnedUnpinned = true
console.warn(