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:
co-authored by
Claude Fable 5.2
parent
0a4f001797
commit
425fac14fb
Vendored
+6
-1
@@ -10,6 +10,11 @@
|
||||
export type EnvKind = 'boolean' | 'email' | 'number' | 'port' | 'string' | 'url'
|
||||
|
||||
export type EnvRule = {
|
||||
/**
|
||||
* Older names of the same variable, read when `name` is missing or empty
|
||||
* (e.g. `IPAL_IP_HEADER` for `IAPL_IP_HEADER`). Messages always use `name`.
|
||||
*/
|
||||
aliases?: readonly string[]
|
||||
/** Shown in the error to tell the deployer what the var is for. */
|
||||
description?: string
|
||||
/** Shape check applied when a value is present. Default 'string' (non-empty). */
|
||||
@@ -106,7 +111,7 @@ export function assertEnv(rules: EnvRule[], options: AssertEnvOptions = {}): voi
|
||||
const problems: string[] = []
|
||||
|
||||
for (const rule of rules) {
|
||||
const raw = env[rule.name]
|
||||
const raw = [rule.name, ...(rule.aliases ?? [])].map((key) => env[key]).find((v) => typeof v === 'string' && v.trim() !== '')
|
||||
const value = typeof raw === 'string' ? raw.trim() : ''
|
||||
const required = rule.required !== false
|
||||
|
||||
|
||||
Vendored
+9
-3
@@ -148,7 +148,7 @@ export function iaplEnvRules(features: IaplEnvFeatures = {}): EnvRule[] {
|
||||
|
||||
if (ipHeader) {
|
||||
rules.push({
|
||||
name: 'IAPL_IP_HEADER',
|
||||
name: 'IAPL_IP_HEADER', aliases: ['IPAL_IP_HEADER'],
|
||||
description: 'Header holding the real client IP, e.g. cf-connecting-ip (Cloudflare) or x-forwarded-for',
|
||||
required: process.env.NODE_ENV === 'production',
|
||||
validate: (v) => (/^[a-z0-9-]+$/i.test(v) ? true : `IAPL_IP_HEADER must be a header name (got "${v}")`),
|
||||
@@ -158,9 +158,9 @@ export function iaplEnvRules(features: IaplEnvFeatures = {}): EnvRule[] {
|
||||
if (cookieCrawl) {
|
||||
const required = process.env.NODE_ENV === 'production'
|
||||
rules.push(
|
||||
{ name: 'IAPL_COOKIE_SCAN_URL', description: 'Cookie crawler service base URL, e.g. https://cookie-crawler.example.com', kind: 'url', required },
|
||||
{ name: 'IAPL_COOKIE_SCAN_URL', aliases: ['IPAL_COOKIE_SCAN_URL'], description: 'Cookie crawler service base URL, e.g. https://cookie-crawler.example.com', kind: 'url', required },
|
||||
{
|
||||
name: 'IAPL_COOKIE_SCAN_TOKEN',
|
||||
name: 'IAPL_COOKIE_SCAN_TOKEN', aliases: ['IPAL_COOKIE_SCAN_TOKEN'],
|
||||
description: 'Token shared with the cookie crawler (this site\'s entry in IAPL_CRAWLER_SITES)',
|
||||
required,
|
||||
validate: (v) => (v.length >= 16 ? true : 'IAPL_COOKIE_SCAN_TOKEN must be at least 16 characters'),
|
||||
@@ -199,3 +199,9 @@ export function iaplEnvRules(features: IaplEnvFeatures = {}): EnvRule[] {
|
||||
|
||||
return rules
|
||||
}
|
||||
|
||||
/** @deprecated The name before 1.17.0; the same function as `iaplEnvRules`. Removed in 2.0. */
|
||||
export const ipalEnvRules = iaplEnvRules
|
||||
|
||||
/** @deprecated The name before 1.17.0; the same type as `IaplEnvFeatures`. Removed in 2.0. */
|
||||
export type IpalEnvFeatures = IaplEnvFeatures
|
||||
|
||||
Vendored
+2
-2
@@ -1,5 +1,5 @@
|
||||
export { assertEnv } from './assertEnv.js'
|
||||
export type { AssertEnvOptions, EnvKind, EnvRule } from './assertEnv.js'
|
||||
export { checkDatabaseName, databaseNameFromUri, databaseNamesFor } from './databaseName.js'
|
||||
export { iaplEnvRules } from './iaplEnvRules.js'
|
||||
export type { IaplEnvFeatures } from './iaplEnvRules.js'
|
||||
export { iaplEnvRules, ipalEnvRules } from './iaplEnvRules.js'
|
||||
export type { IaplEnvFeatures, IpalEnvFeatures } from './iaplEnvRules.js'
|
||||
|
||||
Reference in New Issue
Block a user