@jwilleke/ngdpbase-types 5.42.0 → 5.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/lib/src/context/ApiContext.js +1 -1
  2. package/lib/src/context/BaseContext.d.ts +20 -20
  3. package/lib/src/context/BaseContext.js +41 -24
  4. package/lib/src/context/JobContext.d.ts +31 -0
  5. package/lib/src/context/JobContext.js +34 -1
  6. package/lib/src/managers/AddonsManager.d.ts +0 -28
  7. package/lib/src/managers/AgentTokenManager.d.ts +8 -0
  8. package/lib/src/managers/ConfigurationManager.d.ts +15 -0
  9. package/lib/src/managers/PageManager.d.ts +185 -23
  10. package/lib/src/managers/PolicyEvaluator.d.ts +99 -24
  11. package/lib/src/managers/ShareManager.d.ts +3 -2
  12. package/lib/src/managers/UserManager.d.ts +19 -5
  13. package/lib/src/managers/ValidationManager.d.ts +3 -1
  14. package/lib/src/providers/AgentTokenAuthProvider.js +1 -1
  15. package/lib/src/providers/BaseAuthProvider.d.ts +2 -0
  16. package/lib/src/security/PolicyDecisionPoint.d.ts +57 -1
  17. package/lib/src/security/PolicyInformationPoint.d.ts +86 -6
  18. package/lib/src/security/permissions.generated.d.ts +8 -0
  19. package/lib/src/types/Page.d.ts +0 -7
  20. package/lib/src/types/Policy.d.ts +67 -6
  21. package/lib/src/types/Policy.js +6 -0
  22. package/lib/src/types/Provider.d.ts +12 -0
  23. package/lib/src/types/User.d.ts +6 -0
  24. package/lib/src/utils/addonPageSync.d.ts +0 -12
  25. package/lib/src/utils/auditEventNames.generated.d.ts +2 -0
  26. package/lib/src/utils/auditEventNames.generated.js +2 -0
  27. package/lib/src/utils/auditEvents.d.ts +2 -0
  28. package/lib/src/utils/auditEvents.js +3 -1
  29. package/lib/src/utils/frontmatterAccess.d.ts +15 -24
  30. package/lib/src/utils/legacyStoreKeys.d.ts +16 -0
  31. package/lib/src/utils/pageWritePolicies.d.ts +55 -0
  32. package/lib/src/utils/permissionCatalog.d.ts +2 -0
  33. package/lib/src/utils/permissionCatalog.js +19 -0
  34. package/lib/src/utils/policyAttributes.d.ts +141 -0
  35. package/lib/src/utils/policyAttributes.js +219 -0
  36. package/lib/src/utils/privateStoreAccess.d.ts +24 -4
  37. package/lib/src/utils/privateStoreAccess.js +19 -4
  38. package/lib/src/utils/username.d.ts +13 -2
  39. package/lib/src/utils/username.js +18 -3
  40. package/package.json +1 -1
@@ -50,6 +50,25 @@ export function withRetiredExpanded(names) {
50
50
  }
51
51
  return out;
52
52
  }
53
+ /**
54
+ * The pushed-pages permission for each page write (#2255). A page in a
55
+ * pushed category (shipped by the system or an add-on: `system`,
56
+ * `documentation`, `addon` as shipped) is changed by holders of
57
+ * `pushed-pages-<verb>`; any other page by holders of `page-<verb>`. Which
58
+ * categories are which is the policies' to say — each grants one or the
59
+ * other on `system-category` resources — so a page write is asked as either
60
+ * name, and the policies on the page's category decide.
61
+ */
62
+ const PUSHED_PAGE_WRITES = {
63
+ 'page-edit': 'pushed-pages-edit',
64
+ 'page-delete': 'pushed-pages-delete',
65
+ 'page-rename': 'pushed-pages-rename'
66
+ };
67
+ /** The names a policy may grant `action` under (#2255): a page write and its pushed-pages twin, else the action alone. */
68
+ export function pageWriteAlternatives(action) {
69
+ const pushed = PUSHED_PAGE_WRITES[action];
70
+ return pushed ? [action, pushed] : [action];
71
+ }
53
72
  /**
54
73
  * What the standard OpenID Connect sign-in scopes let an app see, in plain
55
74
  * words (#1572). They are not permissions, so they are not in the catalog;
@@ -0,0 +1,141 @@
1
+ /**
2
+ * The vocabulary of a policy `condition` (#2261): attribute types, the
3
+ * operator table, the nesting limit, and how one comparison is decided.
4
+ * Pure: no I/O, no manager. The evaluator and the validator both import it,
5
+ * so the set of operators lives here and nowhere else.
6
+ */
7
+ /** The types an attribute can be declared with. */
8
+ export declare const ATTRIBUTE_TYPES: readonly ["string", "integer", "boolean", "identity", "list"];
9
+ export type AttributeType = (typeof ATTRIBUTE_TYPES)[number];
10
+ /**
11
+ * How deep a condition may nest. Every node counts, leaves included, so
12
+ * `any-of` > `all-of` > `not` > leaf is 4 and one more level is refused.
13
+ */
14
+ export declare const MAX_CONDITION_DEPTH = 4;
15
+ /**
16
+ * How wide a condition may be (#2261). Depth alone leaves the tree as wide as
17
+ * a config file can make it, and the evaluator walks it for every page a
18
+ * listing or search asks about. A literal `in` list, the children of one
19
+ * `any-of` or `all-of`, and the nodes of the whole condition are each capped.
20
+ */
21
+ export declare const MAX_IN_ITEMS = 256;
22
+ export declare const MAX_GROUP_CHILDREN = 256;
23
+ export declare const MAX_CONDITION_NODES = 512;
24
+ /** What a comparison against an attribute accepts, by operator. */
25
+ interface LeafOperator {
26
+ /** Types the attribute on the left may have. */
27
+ left: readonly AttributeType[];
28
+ }
29
+ /** The operators that compare one attribute with a value. */
30
+ export declare const LEAF_OPERATORS: Readonly<Record<string, LeafOperator>>;
31
+ /** The operators that combine conditions. `not` takes one condition, these take a list. */
32
+ export declare const GROUP_OPERATORS: readonly ["any-of", "all-of"];
33
+ export declare const NOT_OPERATOR = "not";
34
+ /** Every operator, in the order the validator lists them. */
35
+ export declare const CONDITION_OPERATORS: readonly string[];
36
+ /** The type a literal value has, or `null` when it is not a usable literal. */
37
+ export declare function literalType(value: unknown): 'string' | 'integer' | 'boolean' | null;
38
+ /** Can a literal be compared with an attribute of this type? An identity is a string. */
39
+ export declare function literalFits(attributeType: string, value: unknown): boolean;
40
+ /**
41
+ * Does a value read for an attribute fit the type it is declared with? A
42
+ * value that does not is treated as missing by the reader, so a comparison on
43
+ * it is unknown and fails closed, not a definite false or true (#2261). Never
44
+ * coerces: "5" is not an integer. An empty string is a string, a value and not
45
+ * a missing one.
46
+ */
47
+ export declare function valueFits(attributeType: string, value: unknown): boolean;
48
+ /**
49
+ * Decides one comparison once both sides are read. `undefined` is unknown: a
50
+ * side that is missing, or not of a type the operator can compare. Both sides
51
+ * must be the same kind of value (a string, a boolean or a whole number), so
52
+ * "5" never equals 5 and NaN never compares. `in` takes an array, or a Set the
53
+ * evaluator built from a literal list; every entry of an array must be the
54
+ * kind of value on the left. An empty string is a value, not a missing one.
55
+ */
56
+ export declare function compareLeaf(operator: string, left: unknown, right: unknown): boolean | undefined;
57
+ /** The assurance level a sign-in reached: NIST SP 800-63B, 1 to 3. */
58
+ export type SubjectAal = 1 | 2 | 3;
59
+ /** `value` as an assurance level, or `undefined` when it is not 1, 2 or 3. Never coerces. */
60
+ export declare function toAal(value: unknown): SubjectAal | undefined;
61
+ /**
62
+ * What a subject carries that bears on its assurance level (#2261 slice 3).
63
+ * Read from the request's subject, never from a request field: a caller
64
+ * cannot send an `aal` and have it believed.
65
+ */
66
+ export interface AalFacts {
67
+ isAuthenticated?: boolean;
68
+ /** The session's sign-in record; absent on a session from before #1523. */
69
+ signIn?: {
70
+ aal?: unknown;
71
+ } | null;
72
+ /** The highest level the account's methods can reach; the level never exceeds it. */
73
+ aalCap?: number;
74
+ /** A token request: the level stored when the token was made. */
75
+ viaToken?: {
76
+ aal?: unknown;
77
+ } | null;
78
+ /** A share visitor has no sign-in. */
79
+ viaShare?: unknown;
80
+ /** A bearer JWT (Authentik): verified, but it records no sign-in level, so the subject has none (#2287). */
81
+ bearerWithoutLevel?: unknown;
82
+ /** A background job: the level stored when the job was requested. */
83
+ grantedAal?: unknown;
84
+ /** A background job (`JobSubject`): it has no session to read. */
85
+ resolveRolesNow?: unknown;
86
+ }
87
+ /**
88
+ * The subject's `subject:aal`, or `undefined` when it has none (#2261).
89
+ *
90
+ * - Not signed in, or a share visitor: none.
91
+ * - An agent token: the level stored with the token. A token made before this
92
+ * stored one has none.
93
+ * - A background job: the level stored with the job's request. A job with
94
+ * none (a schedule, boot, a request from before this) has none.
95
+ * - A bearer JWT that records no level (Authentik): none. It is not a session
96
+ * from before sign-ins were recorded, so the AAL 1 rule below does not apply.
97
+ * - A session: its sign-in record's level; a session from before sign-ins
98
+ * were recorded (#1523) is AAL 1, as `AuthManager` treats it.
99
+ *
100
+ * Capped at `aalCap`, as a role is. Reads the record; it never works the level
101
+ * out from factors.
102
+ */
103
+ export declare function effectiveAal(subject: AalFacts | null | undefined): SubjectAal | undefined;
104
+ /**
105
+ * The fields of a request's subject that bear on its level, copied by name so
106
+ * a subject rebuilt for a decision keeps them (the #1164 lesson: a field not
107
+ * forwarded is silently lost). Reads nothing else from it.
108
+ */
109
+ export declare function aalFactsOf(subject: object | null | undefined): AalFacts;
110
+ /** Where a subject attribute may be read from: `account:<field>`, `profile:<field>` or `sign-in`. */
111
+ export declare const SUBJECT_SOURCES: readonly ["account:", "profile:", "sign-in"];
112
+ /** One declared subject attribute, as `ngdpbase.access.subject-attributes` holds it. */
113
+ export interface DeclaredSubjectAttribute {
114
+ type?: string;
115
+ from?: string;
116
+ }
117
+ /**
118
+ * `id` and `aal` mean what they mean here, whatever the configuration (or an
119
+ * add-on's default-config.json) says (#2287). `aal` is read from the sign-in
120
+ * record and `id` from the account; a site that could redefine either could
121
+ * make `subject:aal` read a field it controls and pass a "second factor" rule.
122
+ */
123
+ export declare const PINNED_SUBJECT_ATTRIBUTES: Readonly<Record<string, DeclaredSubjectAttribute>>;
124
+ /** The subject attributes a site declares, with `id` and `aal` pinned to their built-in meaning. Anything not an object is ignored. */
125
+ export declare function declaredSubjectAttributes(raw: unknown): Record<string, DeclaredSubjectAttribute>;
126
+ /**
127
+ * What is wrong with the value of `ngdpbase.access.subject-attributes` itself
128
+ * (#2287), one message each: not an object; `id` or `aal` declared with any
129
+ * meaning but the built-in one (the built-in is kept regardless; the same
130
+ * declaration as the built-in is harmless and not reported); and any other
131
+ * declaration `subjectDeclarationProblem` refuses. Used on save, on load and at boot.
132
+ */
133
+ export declare function subjectAttributesProblems(raw: unknown, sensitive: readonly string[]): string[];
134
+ /**
135
+ * What is wrong with a subject attribute's declaration, or `null`: a `type`
136
+ * that is not known, a `from` that is not a subject source, or an account field
137
+ * that must never be read (`sensitive`, the password, email, roles and the
138
+ * like). Said so a condition naming it is refused rather than silently unknown.
139
+ */
140
+ export declare function subjectDeclarationProblem(name: string, decl: DeclaredSubjectAttribute | undefined, sensitive: readonly string[]): string | null;
141
+ export {};
@@ -0,0 +1,219 @@
1
+ /**
2
+ * The vocabulary of a policy `condition` (#2261): attribute types, the
3
+ * operator table, the nesting limit, and how one comparison is decided.
4
+ * Pure: no I/O, no manager. The evaluator and the validator both import it,
5
+ * so the set of operators lives here and nowhere else.
6
+ */
7
+ /** The types an attribute can be declared with. */
8
+ export const ATTRIBUTE_TYPES = ['string', 'integer', 'boolean', 'identity', 'list'];
9
+ /**
10
+ * How deep a condition may nest. Every node counts, leaves included, so
11
+ * `any-of` > `all-of` > `not` > leaf is 4 and one more level is refused.
12
+ */
13
+ export const MAX_CONDITION_DEPTH = 4;
14
+ /**
15
+ * How wide a condition may be (#2261). Depth alone leaves the tree as wide as
16
+ * a config file can make it, and the evaluator walks it for every page a
17
+ * listing or search asks about. A literal `in` list, the children of one
18
+ * `any-of` or `all-of`, and the nodes of the whole condition are each capped.
19
+ */
20
+ export const MAX_IN_ITEMS = 256;
21
+ export const MAX_GROUP_CHILDREN = 256;
22
+ export const MAX_CONDITION_NODES = 512;
23
+ const SCALARS = ['string', 'integer', 'boolean', 'identity'];
24
+ /** The operators that compare one attribute with a value. */
25
+ export const LEAF_OPERATORS = {
26
+ equals: { left: SCALARS },
27
+ 'not-equals': { left: SCALARS },
28
+ in: { left: ['string', 'integer', 'identity'] },
29
+ 'greater-or-equal': { left: ['integer'] },
30
+ 'less-or-equal': { left: ['integer'] }
31
+ };
32
+ /** The operators that combine conditions. `not` takes one condition, these take a list. */
33
+ export const GROUP_OPERATORS = ['any-of', 'all-of'];
34
+ export const NOT_OPERATOR = 'not';
35
+ /** Every operator, in the order the validator lists them. */
36
+ export const CONDITION_OPERATORS = [...Object.keys(LEAF_OPERATORS), ...GROUP_OPERATORS, NOT_OPERATOR];
37
+ /** The type a literal value has, or `null` when it is not a usable literal. */
38
+ export function literalType(value) {
39
+ if (typeof value === 'string')
40
+ return 'string';
41
+ if (typeof value === 'boolean')
42
+ return 'boolean';
43
+ if (typeof value === 'number' && Number.isInteger(value))
44
+ return 'integer';
45
+ return null;
46
+ }
47
+ /** Can a literal be compared with an attribute of this type? An identity is a string. */
48
+ export function literalFits(attributeType, value) {
49
+ const type = literalType(value);
50
+ if (type === null)
51
+ return false;
52
+ return attributeType === 'identity' ? type === 'string' : attributeType === type;
53
+ }
54
+ /** A value a comparison can use: a string, a boolean, or a whole number (not NaN, ±Infinity or 2.5). */
55
+ function isComparable(value) {
56
+ return typeof value === 'string' || typeof value === 'boolean' || (typeof value === 'number' && Number.isInteger(value));
57
+ }
58
+ /**
59
+ * Does a value read for an attribute fit the type it is declared with? A
60
+ * value that does not is treated as missing by the reader, so a comparison on
61
+ * it is unknown and fails closed, not a definite false or true (#2261). Never
62
+ * coerces: "5" is not an integer. An empty string is a string, a value and not
63
+ * a missing one.
64
+ */
65
+ export function valueFits(attributeType, value) {
66
+ switch (attributeType) {
67
+ case 'integer':
68
+ return typeof value === 'number' && Number.isInteger(value);
69
+ case 'boolean':
70
+ return typeof value === 'boolean';
71
+ case 'list':
72
+ return Array.isArray(value) && value.every(isComparable);
73
+ default: // string, identity
74
+ return typeof value === 'string';
75
+ }
76
+ }
77
+ /**
78
+ * Decides one comparison once both sides are read. `undefined` is unknown: a
79
+ * side that is missing, or not of a type the operator can compare. Both sides
80
+ * must be the same kind of value (a string, a boolean or a whole number), so
81
+ * "5" never equals 5 and NaN never compares. `in` takes an array, or a Set the
82
+ * evaluator built from a literal list; every entry of an array must be the
83
+ * kind of value on the left. An empty string is a value, not a missing one.
84
+ */
85
+ export function compareLeaf(operator, left, right) {
86
+ if (!isComparable(left))
87
+ return undefined;
88
+ switch (operator) {
89
+ case 'equals':
90
+ return isComparable(right) && typeof right === typeof left ? left === right : undefined;
91
+ case 'not-equals':
92
+ return isComparable(right) && typeof right === typeof left ? left !== right : undefined;
93
+ case 'in':
94
+ if (right instanceof Set)
95
+ return right.has(left);
96
+ return Array.isArray(right) && right.every((v) => isComparable(v) && typeof v === typeof left) ? right.includes(left) : undefined;
97
+ case 'greater-or-equal':
98
+ return typeof left === 'number' && typeof right === 'number' && Number.isInteger(right) ? left >= right : undefined;
99
+ case 'less-or-equal':
100
+ return typeof left === 'number' && typeof right === 'number' && Number.isInteger(right) ? left <= right : undefined;
101
+ default:
102
+ return undefined;
103
+ }
104
+ }
105
+ /** `value` as an assurance level, or `undefined` when it is not 1, 2 or 3. Never coerces. */
106
+ export function toAal(value) {
107
+ return value === 1 || value === 2 || value === 3 ? value : undefined;
108
+ }
109
+ /**
110
+ * The subject's `subject:aal`, or `undefined` when it has none (#2261).
111
+ *
112
+ * - Not signed in, or a share visitor: none.
113
+ * - An agent token: the level stored with the token. A token made before this
114
+ * stored one has none.
115
+ * - A background job: the level stored with the job's request. A job with
116
+ * none (a schedule, boot, a request from before this) has none.
117
+ * - A bearer JWT that records no level (Authentik): none. It is not a session
118
+ * from before sign-ins were recorded, so the AAL 1 rule below does not apply.
119
+ * - A session: its sign-in record's level; a session from before sign-ins
120
+ * were recorded (#1523) is AAL 1, as `AuthManager` treats it.
121
+ *
122
+ * Capped at `aalCap`, as a role is. Reads the record; it never works the level
123
+ * out from factors.
124
+ */
125
+ export function effectiveAal(subject) {
126
+ if (!subject?.isAuthenticated || subject.viaShare || subject.bearerWithoutLevel)
127
+ return undefined;
128
+ let raw;
129
+ if (subject.viaToken)
130
+ raw = toAal(subject.viaToken.aal);
131
+ else if (subject.resolveRolesNow)
132
+ raw = toAal(subject.grantedAal);
133
+ else
134
+ raw = toAal(subject.signIn?.aal) ?? (subject.signIn ? undefined : 1);
135
+ if (raw === undefined)
136
+ return undefined;
137
+ return toAal(Math.min(raw, typeof subject.aalCap === 'number' && subject.aalCap >= 1 ? subject.aalCap : 3));
138
+ }
139
+ /**
140
+ * The fields of a request's subject that bear on its level, copied by name so
141
+ * a subject rebuilt for a decision keeps them (the #1164 lesson: a field not
142
+ * forwarded is silently lost). Reads nothing else from it.
143
+ */
144
+ export function aalFactsOf(subject) {
145
+ const s = (subject ?? {});
146
+ return {
147
+ signIn: s.signIn,
148
+ aalCap: typeof s.aalCap === 'number' ? s.aalCap : undefined,
149
+ viaToken: s.viaToken,
150
+ viaShare: s.viaShare,
151
+ bearerWithoutLevel: s.bearerWithoutLevel,
152
+ grantedAal: s.grantedAal,
153
+ resolveRolesNow: s.resolveRolesNow
154
+ };
155
+ }
156
+ /** Where a subject attribute may be read from: `account:<field>`, `profile:<field>` or `sign-in`. */
157
+ export const SUBJECT_SOURCES = ['account:', 'profile:', 'sign-in'];
158
+ /**
159
+ * `id` and `aal` mean what they mean here, whatever the configuration (or an
160
+ * add-on's default-config.json) says (#2287). `aal` is read from the sign-in
161
+ * record and `id` from the account; a site that could redefine either could
162
+ * make `subject:aal` read a field it controls and pass a "second factor" rule.
163
+ */
164
+ export const PINNED_SUBJECT_ATTRIBUTES = {
165
+ id: { type: 'identity', from: 'account:id' },
166
+ aal: { type: 'integer', from: 'sign-in' }
167
+ };
168
+ /** The subject attributes a site declares, with `id` and `aal` pinned to their built-in meaning. Anything not an object is ignored. */
169
+ export function declaredSubjectAttributes(raw) {
170
+ const declared = raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : {};
171
+ return { ...declared, ...PINNED_SUBJECT_ATTRIBUTES };
172
+ }
173
+ /**
174
+ * What is wrong with the value of `ngdpbase.access.subject-attributes` itself
175
+ * (#2287), one message each: not an object; `id` or `aal` declared with any
176
+ * meaning but the built-in one (the built-in is kept regardless; the same
177
+ * declaration as the built-in is harmless and not reported); and any other
178
+ * declaration `subjectDeclarationProblem` refuses. Used on save, on load and at boot.
179
+ */
180
+ export function subjectAttributesProblems(raw, sensitive) {
181
+ if (raw === null || raw === undefined)
182
+ return [];
183
+ if (typeof raw !== 'object' || Array.isArray(raw))
184
+ return ['ngdpbase.access.subject-attributes must be an object of attribute name to { type, from }'];
185
+ return Object.entries(raw).flatMap(([name, decl]) => {
186
+ const pinned = Object.hasOwn(PINNED_SUBJECT_ATTRIBUTES, name) ? PINNED_SUBJECT_ATTRIBUTES[name] : undefined;
187
+ if (pinned) {
188
+ const same = !!decl && typeof decl === 'object' && decl.type === pinned.type && decl.from === pinned.from;
189
+ return same ? [] : [`subject attribute '${name}' in ngdpbase.access.subject-attributes cannot be redefined: it is built in (type ${pinned.type}, from ${pinned.from}) and keeps that meaning; remove it`];
190
+ }
191
+ const problem = subjectDeclarationProblem(name, decl, sensitive);
192
+ return problem ? [problem] : [];
193
+ });
194
+ }
195
+ /**
196
+ * What is wrong with a subject attribute's declaration, or `null`: a `type`
197
+ * that is not known, a `from` that is not a subject source, or an account field
198
+ * that must never be read (`sensitive`, the password, email, roles and the
199
+ * like). Said so a condition naming it is refused rather than silently unknown.
200
+ */
201
+ export function subjectDeclarationProblem(name, decl, sensitive) {
202
+ const where = `subject attribute '${name}' in ngdpbase.access.subject-attributes`;
203
+ if (!decl || typeof decl !== 'object')
204
+ return `${where} must be an object with a type and a from`;
205
+ if (!ATTRIBUTE_TYPES.includes(decl.type))
206
+ return `${where} has type ${JSON.stringify(decl.type)}; use one of ${ATTRIBUTE_TYPES.join(', ')}`;
207
+ const from = decl.from;
208
+ const source = typeof from === 'string' ? SUBJECT_SOURCES.find((s) => from === s || (s !== 'sign-in' && from.startsWith(s))) : undefined;
209
+ if (!source)
210
+ return `${where} reads from ${JSON.stringify(from)}; start it with ${SUBJECT_SOURCES.join(', ')}`;
211
+ if (source !== 'sign-in') {
212
+ const field = from.slice(source.length);
213
+ if (!field)
214
+ return `${where} reads from '${source}' with no field; write ${source}<field>`;
215
+ if (sensitive.includes(field))
216
+ return `'${source}${field}' cannot be used in a condition`;
217
+ }
218
+ return null;
219
+ }
@@ -3,8 +3,10 @@
3
3
  * every vault below it (docs/private-stores.md, Access).
4
4
  *
5
5
  * The owner, a share link the owner issued, or someone acting for the owner
6
- * under a proxy grant that carries `vault-proxy` (#1762). No role reaches in,
7
- * admin included.
6
+ * under a proxy grant that carries `vault-proxy` (#1762). No role reaches in
7
+ * through this rule. At a door, an administrator may also enter a vault that
8
+ * is not encrypted when `ngdpbase.vaults.admin-access` is true (#2255,
9
+ * {@link mayEnterVaultAtDoor}), and each such access is recorded.
8
10
  *
9
11
  * A share link gets in only for a vault it names (#1388), and only when the
10
12
  * caller names that vault: a question about the owner's container as a whole
@@ -25,8 +27,12 @@
25
27
  * slice 4).
26
28
  */
27
29
  import { type ActorContext } from '../context/ActorContext.js';
30
+ /** The administrator's way into a vault (#2255): `PolicyDecisionPoint.adminMayEnterVault`. */
31
+ interface AdminVaultEntry {
32
+ adminMayEnterVault?(ctx: unknown, owner: string, vault: string, resource: string, record?: boolean): Promise<boolean>;
33
+ }
28
34
  /** The PDP surface a vault decision needs. */
29
- export interface VaultDecider {
35
+ export interface VaultDecider extends AdminVaultEntry {
30
36
  decide(subject: unknown, request: {
31
37
  action: string;
32
38
  resource: {
@@ -36,10 +42,12 @@ export interface VaultDecider {
36
42
  attributes: Record<string, unknown>;
37
43
  }): Promise<{
38
44
  permit: boolean;
45
+ policyIds?: string[];
46
+ conditionNotMet?: string[];
39
47
  }>;
40
48
  }
41
49
  /** The PDP surface {@link holdsInVault} needs. */
42
- export interface VaultHolder {
50
+ export interface VaultHolder extends AdminVaultEntry {
43
51
  holds(subject: unknown, action: string, on: {
44
52
  resource: {
45
53
  type: string;
@@ -48,6 +56,17 @@ export interface VaultHolder {
48
56
  attributes: Record<string, unknown>;
49
57
  }): Promise<boolean>;
50
58
  }
59
+ /**
60
+ * The container rule at a door (#2255): the owner or their delegate
61
+ * ({@link mayActInPrivateContainer}), or else an administrator let in by
62
+ * `ngdpbase.vaults.admin-access` to a vault that is not encrypted, recorded
63
+ * when `record`. Lists never ask this; they keep the owner's rule alone.
64
+ */
65
+ export declare function mayEnterVaultAtDoor(pdp: AdminVaultEntry | null | undefined, ctx: ActorContext, where: {
66
+ owner: string;
67
+ vault: string;
68
+ resource: string;
69
+ }, record?: boolean): Promise<boolean>;
51
70
  export declare function mayActInPrivateContainer(ctx: ActorContext, owner: string, opts?: {
52
71
  vault?: string;
53
72
  }): boolean;
@@ -80,3 +99,4 @@ export declare function holdsInVault(pdp: VaultHolder | null | undefined, ctx: A
80
99
  vault: string;
81
100
  resource: string;
82
101
  }): Promise<boolean>;
102
+ export {};
@@ -3,8 +3,10 @@
3
3
  * every vault below it (docs/private-stores.md, Access).
4
4
  *
5
5
  * The owner, a share link the owner issued, or someone acting for the owner
6
- * under a proxy grant that carries `vault-proxy` (#1762). No role reaches in,
7
- * admin included.
6
+ * under a proxy grant that carries `vault-proxy` (#1762). No role reaches in
7
+ * through this rule. At a door, an administrator may also enter a vault that
8
+ * is not encrypted when `ngdpbase.vaults.admin-access` is true (#2255,
9
+ * {@link mayEnterVaultAtDoor}), and each such access is recorded.
8
10
  *
9
11
  * A share link gets in only for a vault it names (#1388), and only when the
10
12
  * caller names that vault: a question about the owner's container as a whole
@@ -29,6 +31,19 @@ import { shareNamesVault } from '../types/Share.js';
29
31
  import { mixesProxyWithDelegation, proxyCarries } from './proxyClaim.js';
30
32
  import { isSharedFolderOwner } from './privateStorePath.js';
31
33
  import { permitsInSharedFolder } from './sharedFolderAccess.js';
34
+ /**
35
+ * The container rule at a door (#2255): the owner or their delegate
36
+ * ({@link mayActInPrivateContainer}), or else an administrator let in by
37
+ * `ngdpbase.vaults.admin-access` to a vault that is not encrypted, recorded
38
+ * when `record`. Lists never ask this; they keep the owner's rule alone.
39
+ */
40
+ export async function mayEnterVaultAtDoor(pdp, ctx, where, record = true) {
41
+ if (mayActInPrivateContainer(ctx, where.owner, { vault: where.vault }))
42
+ return true;
43
+ if (isSharedFolderOwner(where.owner) || typeof pdp?.adminMayEnterVault !== 'function')
44
+ return false;
45
+ return pdp.adminMayEnterVault(ctx, where.owner, where.vault, where.resource, record);
46
+ }
32
47
  export function mayActInPrivateContainer(ctx, owner, opts = {}) {
33
48
  // #2125: the shared folders' container has no owner who acts; a folder is
34
49
  // decided by permission (`permitsInSharedFolder`), never by this rule.
@@ -67,7 +82,7 @@ export function mayActInPrivateContainer(ctx, owner, opts = {}) {
67
82
  export async function permitsInVault(pdp, ctx, action, where) {
68
83
  if (isSharedFolderOwner(where.owner))
69
84
  return permitsInSharedFolder(pdp, ctx, action, where.vault);
70
- if (!pdp || !mayActInPrivateContainer(ctx, where.owner, { vault: where.vault }))
85
+ if (!pdp || !(await mayEnterVaultAtDoor(pdp, ctx, where)))
71
86
  return false;
72
87
  return (await pdp.decide(ctx, { action, resource: { type: 'page', id: where.resource }, attributes: { vault: where.vault } })).permit;
73
88
  }
@@ -78,7 +93,7 @@ export async function permitsInVault(pdp, ctx, action, where) {
78
93
  * folders are not asked: `permitsInVault` decides them by permission alone.
79
94
  */
80
95
  export async function holdsInVault(pdp, ctx, action, where) {
81
- if (isSharedFolderOwner(where.owner) || typeof pdp?.holds !== 'function' || !mayActInPrivateContainer(ctx, where.owner, { vault: where.vault }))
96
+ if (isSharedFolderOwner(where.owner) || typeof pdp?.holds !== 'function' || !(await mayEnterVaultAtDoor(pdp, ctx, where, false)))
82
97
  return false;
83
98
  return pdp.holds(ctx, action, { resource: { type: 'page', id: where.resource }, attributes: { vault: where.vault } });
84
99
  }
@@ -64,6 +64,17 @@ export declare const ACCOUNTLESS_PERSON_PREFIX = "person:";
64
64
  * anything else a username not yet converted.
65
65
  */
66
66
  export declare const IDENTITY_ID_PREFIX = "urn:";
67
+ /**
68
+ * The prefix of an add-on's pages' author (#2255): `addon:<slug>`. The pages
69
+ * an add-on pushes to a site are authored by the add-on, as required pages
70
+ * are by `system`. No username may start with it, so no account is ever an
71
+ * add-on page's author, and a start-up conversion keeps it as it is.
72
+ */
73
+ export declare const ADDON_AUTHOR_PREFIX = "addon:";
74
+ /** The author of the pages add-on `slug` pushes (#2255). */
75
+ export declare function addonAuthor(slug: string): string;
76
+ /** True when `value` names an add-on as a page's author (#2255). */
77
+ export declare function isAddonAuthor(value: unknown): boolean;
67
78
  /**
68
79
  * The prefix a start-up conversion gives a stored username that has no
69
80
  * account (#2041): `orphan:<name>`. The record is then nobody's: a later
@@ -86,7 +97,7 @@ export declare function isNoRecordedUser(value: unknown): boolean;
86
97
  /**
87
98
  * True when the name belongs to a principal rather than a user, is a "no user
88
99
  * recorded" value ({@link NO_RECORDED_USER}, #2097: an account by that name
89
- * would take over the records that hold it), or has the contact, `@id` or
90
- * orphan prefix.
100
+ * would take over the records that hold it), or has the contact, `@id`, orphan or
101
+ * add-on author (#2255) prefix.
91
102
  */
92
103
  export declare function isReservedUsername(username: unknown): boolean;
@@ -71,6 +71,21 @@ export const ACCOUNTLESS_PERSON_PREFIX = 'person:';
71
71
  * anything else a username not yet converted.
72
72
  */
73
73
  export const IDENTITY_ID_PREFIX = 'urn:';
74
+ /**
75
+ * The prefix of an add-on's pages' author (#2255): `addon:<slug>`. The pages
76
+ * an add-on pushes to a site are authored by the add-on, as required pages
77
+ * are by `system`. No username may start with it, so no account is ever an
78
+ * add-on page's author, and a start-up conversion keeps it as it is.
79
+ */
80
+ export const ADDON_AUTHOR_PREFIX = 'addon:';
81
+ /** The author of the pages add-on `slug` pushes (#2255). */
82
+ export function addonAuthor(slug) {
83
+ return `${ADDON_AUTHOR_PREFIX}${slug}`;
84
+ }
85
+ /** True when `value` names an add-on as a page's author (#2255). */
86
+ export function isAddonAuthor(value) {
87
+ return typeof value === 'string' && value.length > ADDON_AUTHOR_PREFIX.length && value.startsWith(ADDON_AUTHOR_PREFIX);
88
+ }
74
89
  /**
75
90
  * The prefix a start-up conversion gives a stored username that has no
76
91
  * account (#2041): `orphan:<name>`. The record is then nobody's: a later
@@ -96,10 +111,10 @@ export function isNoRecordedUser(value) {
96
111
  /**
97
112
  * True when the name belongs to a principal rather than a user, is a "no user
98
113
  * recorded" value ({@link NO_RECORDED_USER}, #2097: an account by that name
99
- * would take over the records that hold it), or has the contact, `@id` or
100
- * orphan prefix.
114
+ * would take over the records that hold it), or has the contact, `@id`, orphan or
115
+ * add-on author (#2255) prefix.
101
116
  */
102
117
  export function isReservedUsername(username) {
103
118
  const name = normalizeUsername(username);
104
- return RESERVED_USERNAMES.includes(name) || NO_RECORDED_USER.includes(name) || name.startsWith(ACCOUNTLESS_PERSON_PREFIX) || name.startsWith(IDENTITY_ID_PREFIX) || name.startsWith(ORPHAN_PREFIX);
119
+ return RESERVED_USERNAMES.includes(name) || NO_RECORDED_USER.includes(name) || name.startsWith(ACCOUNTLESS_PERSON_PREFIX) || name.startsWith(IDENTITY_ID_PREFIX) || name.startsWith(ORPHAN_PREFIX) || name.startsWith(ADDON_AUTHOR_PREFIX);
105
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jwilleke/ngdpbase-types",
3
- "version": "5.42.0",
3
+ "version": "5.43.0",
4
4
  "description": "TypeScript types for ngdpbase add-ons, and a test kit of core's own values. A dev dependency, versioned with ngdpbase.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Jim Willeke",