IAPL rename, scripted: preferred names in src, bin, scripts, services, tests; bin files and skill folders moved
Replaced by an explicit list of forms only (ten exported names, runtime env names, project file names and marks, commands, skill names, the log prefix, the brand in prose). Package name, import paths, routes, CSS tokens, data attributes, custom keys, context flags, the cookie and kv keys are not touched. package.json keeps the five old bin names beside the five new ones. The old names stop working in this commit and come back as aliases in the next; docs follow. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
414a4702df
commit
0a4f001797
@@ -30,7 +30,7 @@ export function resolvePanelRole(option: false | Role | undefined): null | Role
|
||||
if (option === false) {return null}
|
||||
const role = option ?? DEFAULT_PANEL_ROLE
|
||||
if (!ROLE_HIERARCHY.includes(role)) {
|
||||
throw new Error(`[ipal] accounts.panelRole must be one of ${ROLE_HIERARCHY.join(', ')} or false, got ${JSON.stringify(option)}.`)
|
||||
throw new Error(`[iapl] accounts.panelRole must be one of ${ROLE_HIERARCHY.join(', ')} or false, got ${JSON.stringify(option)}.`)
|
||||
}
|
||||
return role === ROLE_HIERARCHY[0] ? null : role
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ export function resolvePasswordRule(option: false | PasswordRuleOptions | undefi
|
||||
if (option === false) {return null}
|
||||
const minLength = option?.minLength ?? DEFAULT_PASSWORD_MIN_LENGTH
|
||||
if (typeof minLength !== 'number' || !Number.isInteger(minLength) || minLength < 1) {
|
||||
throw new Error(`[ipal] accounts.password.minLength must be a whole number of 1 or more, got ${JSON.stringify(option?.minLength) ?? String(option?.minLength)}. Use accounts: { password: false } to turn the rule off.`)
|
||||
throw new Error(`[iapl] accounts.password.minLength must be a whole number of 1 or more, got ${JSON.stringify(option?.minLength) ?? String(option?.minLength)}. Use accounts: { password: false } to turn the rule off.`)
|
||||
}
|
||||
return { minLength }
|
||||
}
|
||||
|
||||
@@ -23,14 +23,14 @@ type StaffConfig = { admin?: { user?: string }; custom?: unknown }
|
||||
type MaybePayload = Pick<BasePayload, 'config'> | StaffSource
|
||||
|
||||
/**
|
||||
* The staff lists of the configs ipalKit built in this process, by owner: the
|
||||
* The staff lists of the configs iapl built in this process, by owner: the
|
||||
* running Payload instance once it exists, a token of the config before that.
|
||||
* Used when a predicate gets no source (`isAdmin(req.user)` in a hook).
|
||||
*/
|
||||
const registered = new Map<object, string[]>()
|
||||
|
||||
/**
|
||||
* Called by ipalKit: at config time with a token, then with the Payload
|
||||
* Called by iapl: at config time with a token, then with the Payload
|
||||
* instance (`replaces` = that config's token) on init and after every reload.
|
||||
* Not for projects.
|
||||
*/
|
||||
@@ -49,7 +49,7 @@ export const staffRegistrySize = (): number => registered.size
|
||||
|
||||
/**
|
||||
* The staff collections every config in this process agrees on, or null when
|
||||
* ipalKit never ran here (a browser bundle, Next middleware, the edge
|
||||
* iapl never ran here (a browser bundle, Next middleware, the edge
|
||||
* runtime). Two configs with different lists: only what both call staff — a
|
||||
* call that does not say which config it means must not get the wider answer.
|
||||
*/
|
||||
@@ -83,7 +83,7 @@ export function staffCollectionSlugs(source?: MaybePayload): string[] {
|
||||
* Whether this account's roles may count at all: it belongs to a staff
|
||||
* collection. Checked before any role, and it fails closed:
|
||||
* - an account without `collection` (a user object built by hand) is not staff;
|
||||
* - where the staff collections are not known — no source given and ipalKit
|
||||
* - where the staff collections are not known — no source given and iapl
|
||||
* never ran in this bundle (client components, Next middleware, the edge
|
||||
* runtime) — nobody is staff. Pass the source there: `isAdmin(user, config)`
|
||||
* with the config from `useConfig()` (client components import from
|
||||
@@ -116,7 +116,7 @@ function highestRoleIndex(user: MaybeUser): number {
|
||||
*
|
||||
* Pass `req.payload` as the third argument where you have it (access
|
||||
* functions, hooks, endpoints); without it the staff collections of the
|
||||
* config ipalKit built in this process are used — and where there is none
|
||||
* config iapl built in this process are used — and where there is none
|
||||
* (a browser bundle, middleware) the answer is false: pass the config from
|
||||
* `useConfig()` or `{ staffCollections: ['users'] }` there. A client component
|
||||
* imports it from '@intecion/ipal-kit/client': the main entry does not build there with webpack.
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* The mark lets the plugin see that. It is on the function itself, so it:
|
||||
* - travels with every copy (it is the same function object);
|
||||
* - is on the function that ends up on the collection (set after the 2FA package wrapped the
|
||||
* rule; ipal-kit's own 2FA guard gets a mark of its own for its wrapper);
|
||||
* rule; IAPL's own 2FA guard gets a mark of its own for its wrapper);
|
||||
* - is the same for every instance of this module (`Symbol.for`): after a `next dev` reload the
|
||||
* config was built by one instance and is adopted by another.
|
||||
* It counts only on the very function it was made for (`self`): a Proxy around a marked rule, a
|
||||
|
||||
@@ -160,15 +160,15 @@ export function canHoldStaffRole(collection: Staffish): boolean {
|
||||
export type StaffAccountRules = { applied: string[]; ownRoles: boolean; slug?: string }
|
||||
|
||||
/**
|
||||
* The "seen" marker (`custom.ipalAccounts`): which collection ipalKit handled, and whether as a staff
|
||||
* The "seen" marker (`custom.ipalAccounts`): which collection iapl handled, and whether as a staff
|
||||
* collection. Not a plain `true`: a later plugin may spread a collection into a new slug
|
||||
* (`{ ...staff, slug: 'copy' }`) and the marker travels with it; and in `next dev` a collection object can
|
||||
* outlive a reload in which it became staff.
|
||||
*/
|
||||
export type AccountsMarker = {
|
||||
/**
|
||||
* The operations that had a rule in the project's config when ipalKit ran (before Payload and the 2FA package
|
||||
* filled the missing ones). A collection of the config that becomes staff LATER — a plugin listed after ipalKit
|
||||
* The operations that had a rule in the project's config when iapl ran (before Payload and the 2FA package
|
||||
* filled the missing ones). A collection of the config that becomes staff LATER — a plugin listed after iapl
|
||||
* sets `admin.user` to it — keeps exactly those rules; an operation that had none gets the plugin's.
|
||||
*/
|
||||
own?: string[]
|
||||
@@ -182,7 +182,7 @@ const markerOf = (collection: { custom?: unknown }): AccountsMarker | undefined
|
||||
|
||||
/**
|
||||
* BOTH rules must allow: the plugin's and the one the collection already has. For a collection
|
||||
* that arrives after ipalKit ran (a later plugin), whose config is already sanitized: Payload has
|
||||
* that arrives after iapl ran (a later plugin), whose config is already sanitized: Payload has
|
||||
* filled every missing rule with its default by then, and that default cannot be told from a
|
||||
* rule somebody wrote — not by its name (a production build minifies it away) and not safely by
|
||||
* identity. So nothing is guessed: the plugin's rule is put in FRONT of whatever is there. With
|
||||
@@ -230,10 +230,10 @@ const bothAllowField =
|
||||
* are involved.
|
||||
*
|
||||
* `mode`:
|
||||
* - `'config'` (ipalKit is running, nothing is sanitized): an operation without a rule gets the plugin's;
|
||||
* - `'config'` (iapl is running, nothing is sanitized): an operation without a rule gets the plugin's;
|
||||
* - `'late'` (a staff collection a later plugin added; the config is sanitized, so Payload's default cannot be
|
||||
* told from a written rule): the plugin's rule in front of every rule — except the operations named in `kept`:
|
||||
* the collection was in the config when ipalKit ran and had a rule of the project's for them then (the marker's
|
||||
* the collection was in the config when iapl ran and had a rule of the project's for them then (the marker's
|
||||
* `own`), so they are left as a rule the project wrote, exactly as at config time;
|
||||
* - `'copied'` (a late collection that is not staff, or that keeps its own rules — `custom.ipal.accountRules:
|
||||
* false`): the plugin's rule goes in front ONLY of a rule the plugin wrote for another collection (its mark,
|
||||
@@ -273,7 +273,7 @@ function ruleStaffCollection(collection: CollectionConfig, { create = true, plug
|
||||
if (mark && mark.slug !== slug) {copied = true}
|
||||
if (mode === 'config') {
|
||||
if (there || !enabled) {continue} // a rule the project wrote
|
||||
access[operation] = rule // marked when ipalKit finishes (markStaffRules): the 2FA package wraps it first
|
||||
access[operation] = rule // marked when iapl finishes (markStaffRules): the 2FA package wraps it first
|
||||
} else if ((mode === 'late' && enabled && !kept.includes(operation)) || mark) {
|
||||
access[operation] = markedStaffRule(bothAllow(rule, there), slug)
|
||||
} else {continue}
|
||||
@@ -352,7 +352,7 @@ export function applyStaffAccountAccess(config: Config, staffSlugs: string[], op
|
||||
collections: (config.collections ?? []).map((collection) => {
|
||||
if (!collection.auth) {return collection}
|
||||
// Which operations have a rule of the project's NOW — later nobody can tell (Payload and the 2FA package fill
|
||||
// the missing ones). Kept in the marker for a collection that becomes staff after ipalKit ran.
|
||||
// the missing ones). Kept in the marker for a collection that becomes staff after iapl ran.
|
||||
const own = OPERATIONS.filter((operation) => Boolean((collection.access as Record<string, unknown> | undefined)?.[operation]))
|
||||
if (!staffSlugs.includes(collection.slug)) {
|
||||
return { ...collection, custom: { ...collection.custom, ipalAccounts: { slug: collection.slug, own, staff: false } satisfies AccountsMarker } }
|
||||
@@ -370,14 +370,14 @@ export type LateAdoption = {
|
||||
firstUser: boolean
|
||||
/** The operations whose rule from the project's config was left as it is (a config collection that became staff later). */
|
||||
kept: string[]
|
||||
/** True when the collection was in the config when ipalKit ran (and became staff afterwards); false when a later plugin added it. */
|
||||
/** True when the collection was in the config when iapl ran (and became staff afterwards); false when a later plugin added it. */
|
||||
known: boolean
|
||||
password: boolean
|
||||
slug: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Collections that were not in the config when ipalKit ran — a plugin listed after it added them.
|
||||
* Collections that were not in the config when iapl ran — a plugin listed after it added them.
|
||||
* Called when a config goes live (start, dev reload) with THAT config: a late STAFF collection
|
||||
* gets the account rules (in front of whatever rules it has — `bothAllow`), the roles-field rule
|
||||
* and the password hook; every late auth collection gets the first-user endpoint. Changes the
|
||||
@@ -398,7 +398,7 @@ export function adoptLateAuthCollections(
|
||||
// a copy; a marker that says "not staff" on a collection that is staff now was made before it was named as one.
|
||||
const marker = markerOf(collection)
|
||||
if (marker?.slug === collection.slug && (marker.staff || !staff)) {continue}
|
||||
// In the config when ipalKit ran, not staff then (a later plugin made it the panel's): the rules it had then stay.
|
||||
// In the config when iapl ran, not staff then (a later plugin made it the panel's): the rules it had then stay.
|
||||
const known = marker?.slug === collection.slug
|
||||
const kept = known && Array.isArray(marker.own) ? marker.own : []
|
||||
const done: LateAdoption = { slug: collection.slug, applied: [], firstUser: false, kept: [], known, password: false }
|
||||
@@ -429,7 +429,7 @@ export function adoptLateAuthCollections(
|
||||
/**
|
||||
* Puts the plugin's mark on the rules it filled in during this run (`custom.ipalAccountRules.applied`, for the
|
||||
* collection's own slug). Called AFTER the 2FA package has wrapped them — the mark must be on the function that is
|
||||
* on the collection — and BEFORE ipal-kit's own 2FA guard, which carries the mark to its wrapper. Already marked
|
||||
* on the collection — and BEFORE IAPL's own 2FA guard, which carries the mark to its wrapper. Already marked
|
||||
* functions are left, so it can run more than once.
|
||||
*/
|
||||
export function markStaffRules(config: Config): Config {
|
||||
@@ -449,7 +449,7 @@ export function markStaffRules(config: Config): Config {
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the auth collections ipalKit has seen at config time — with their slug and whether they are staff — so
|
||||
* Marks the auth collections iapl has seen at config time — with their slug and whether they are staff — so
|
||||
* `adoptLateAuthCollections` leaves exactly those alone.
|
||||
*/
|
||||
export function markSeenAuthCollections(config: Config, staffSlugs: string[] = []): Config {
|
||||
@@ -518,7 +518,7 @@ export function buildFirstUserEndpoint(option: FirstUserRouteOption = 'panel'):
|
||||
export function applyFirstUserRoute(config: Config, option: FirstUserRouteOption = 'panel'): Config {
|
||||
if (option === 'all') {return config}
|
||||
if (option !== 'panel' && !Array.isArray(option)) {
|
||||
throw new Error(`[ipal] accounts.firstUserRoute must be 'panel', 'all' or a list of collection slugs, got ${JSON.stringify(option)}.`)
|
||||
throw new Error(`[iapl] accounts.firstUserRoute must be 'panel', 'all' or a list of collection slugs, got ${JSON.stringify(option)}.`)
|
||||
}
|
||||
return {
|
||||
...config,
|
||||
|
||||
@@ -11,7 +11,7 @@ export const ROLE_HIERARCHY = ['user', 'editor', 'admin'] as const
|
||||
export type Role = (typeof ROLE_HIERARCHY)[number]
|
||||
|
||||
/**
|
||||
* `ipalKit({ accounts })` — rules for the accounts of the staff collection. On by default
|
||||
* `iapl({ accounts })` — rules for the accounts of the staff collection. On by default
|
||||
* where they apply; each one has its own switch, `accounts: false` turns them all off.
|
||||
*/
|
||||
export type AccountsOptions = {
|
||||
|
||||
Reference in New Issue
Block a user