@andco/protocol 0.0.7 → 0.0.8
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.
- package/README.md +22 -73
- package/dist/api-errors.d.ts +5 -5
- package/dist/api-errors.d.ts.map +1 -1
- package/dist/api-errors.js +5 -5
- package/dist/consent.d.ts +2 -2
- package/dist/consent.d.ts.map +1 -1
- package/dist/consent.js +10 -19
- package/dist/errors.d.ts +41 -7
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +46 -8
- package/dist/format-money.d.ts +3 -0
- package/dist/format-money.d.ts.map +1 -0
- package/dist/format-money.js +7 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/intent-input.d.ts +124 -124
- package/dist/intent-input.d.ts.map +1 -1
- package/dist/intent-input.js +14 -14
- package/dist/miniapp-icon.d.ts +2 -2
- package/dist/miniapp-icon.d.ts.map +1 -1
- package/dist/miniapp-icon.js +6 -58
- package/dist/native-intent.d.ts +20 -29
- package/dist/native-intent.d.ts.map +1 -1
- package/dist/native-intent.js +13 -56
- package/dist/pagination.d.ts +71 -0
- package/dist/pagination.d.ts.map +1 -0
- package/dist/pagination.js +63 -0
- package/dist/rar/account-matchers.d.ts +52 -52
- package/dist/rar/account-matchers.d.ts.map +1 -1
- package/dist/rar/account-matchers.js +81 -72
- package/dist/rar/bank.d.ts +86 -84
- package/dist/rar/bank.d.ts.map +1 -1
- package/dist/rar/bank.js +26 -24
- package/dist/rar/catalog.d.ts +57 -56
- package/dist/rar/catalog.d.ts.map +1 -1
- package/dist/rar/catalog.js +1 -0
- package/dist/rar/detail.d.ts +1 -1
- package/dist/rar/detail.d.ts.map +1 -1
- package/dist/rar/detail.js +1 -1
- package/dist/service-grants.d.ts +4 -2
- package/dist/service-grants.d.ts.map +1 -1
- package/dist/service-grants.js +15 -2
- package/dist/transport/financial-events.d.ts +10 -22
- package/dist/transport/financial-events.d.ts.map +1 -1
- package/dist/transport/financial-events.js +36 -62
- package/dist/transport/generated/oauth-api.d.ts +269 -96
- package/dist/transport/generated/oauth-api.d.ts.map +1 -1
- package/dist/transport/intents.d.ts +11 -10
- package/dist/transport/intents.d.ts.map +1 -1
- package/dist/transport/intents.js +20 -19
- package/dist/transport/rest.d.ts +3 -3
- package/dist/transport/rest.d.ts.map +1 -1
- package/dist/transport/rest.js +1 -1
- package/dist/transport/runtime.js +3 -3
- package/dist/utils.js +3 -3
- package/dist/webhooks.d.ts +15 -4
- package/dist/webhooks.d.ts.map +1 -1
- package/dist/webhooks.js +50 -17
- package/package.json +1 -1
- package/dist/native-copy.d.ts +0 -28
- package/dist/native-copy.d.ts.map +0 -1
- package/dist/native-copy.js +0 -400
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
/**
|
|
3
|
-
* Syntax of an Account
|
|
3
|
+
* Syntax of an Account Key: the name that identifies one Cuenta Vista among the accounts of its
|
|
4
4
|
* Subject, unique per Subject regardless of which Project opened it.
|
|
5
5
|
*/
|
|
6
|
-
export const
|
|
6
|
+
export const ACCOUNT_KEY_SYNTAX = "^[a-z][a-z0-9_-]{0,63}$";
|
|
7
7
|
/**
|
|
8
|
-
* Syntax of the `pattern` carried by an `
|
|
9
|
-
* one
|
|
8
|
+
* Syntax of the `pattern` carried by an `accountKey` matcher, and the entire grammar of the language:
|
|
9
|
+
* one accountKey literal (`caja-chica-1`), one accountKey literal followed by a single trailing `*`
|
|
10
10
|
* (`caja-chica-*`), or `*` alone. There is no other metacharacter, no anchor and no alternation.
|
|
11
11
|
*
|
|
12
12
|
* Regular expressions were rejected on a decisive technical ground, not on taste. The
|
|
13
13
|
* authorization decision has to answer whether one resolved detail is *contained* in the requested
|
|
14
14
|
* one, and containment of regular languages is PSPACE-complete; with prefix globs it is the three
|
|
15
|
-
* lines of {@link
|
|
15
|
+
* lines of {@link accountKeyPatternContains}. Two further reasons hold independently: the
|
|
16
16
|
* decision runs in Postgres while the schema is validated in JavaScript, and POSIX and ECMAScript
|
|
17
17
|
* are not the same language, so one permission would mean two things depending on where it ran;
|
|
18
18
|
* and Postgres `~` is unanchored, so `cliente-1` would silently also authorize `evil-cliente-123`,
|
|
19
19
|
* failing towards granting more.
|
|
20
20
|
*/
|
|
21
|
-
export const
|
|
21
|
+
export const ACCOUNT_KEY_PATTERN_SYNTAX = "^(?:\\*|[a-z][a-z0-9_-]{0,63}\\*?)$";
|
|
22
22
|
/** Syntax of an Andco account identifier: a UUID. */
|
|
23
23
|
export const ACCOUNT_ID_PATTERN = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$";
|
|
24
|
-
/** An Account
|
|
25
|
-
export const
|
|
26
|
-
/** A prefix glob over Account
|
|
27
|
-
export const
|
|
24
|
+
/** An Account Key, exactly as its holder chose it. */
|
|
25
|
+
export const AccountKeySchema = /* @__PURE__ */ v.pipe(v.string(), v.regex(new RegExp(ACCOUNT_KEY_SYNTAX)));
|
|
26
|
+
/** A prefix glob over Account Keys. See {@link ACCOUNT_KEY_PATTERN_SYNTAX} for the grammar. */
|
|
27
|
+
export const AccountKeyPatternSchema = /* @__PURE__ */ v.pipe(v.string(), v.regex(new RegExp(ACCOUNT_KEY_PATTERN_SYNTAX)));
|
|
28
28
|
/** Upper bound of every matcher list. */
|
|
29
29
|
export const ACCOUNT_MATCHER_LIST_CEILING = 100;
|
|
30
30
|
/** Upper bound of each optional field of an `external` matcher. */
|
|
@@ -37,7 +37,7 @@ const editable = /* @__PURE__ */ v.nullish(v.boolean());
|
|
|
37
37
|
/**
|
|
38
38
|
* How many accounts the person picks at consent for an `editable` matcher of a list she narrows:
|
|
39
39
|
* `"multiple"` (the default) lets her keep several, `"single"` asks for exactly one, which the
|
|
40
|
-
* Grant then fixes as one `account` matcher. Only an `editable` own matcher (`
|
|
40
|
+
* Grant then fixes as one `account` matcher. Only an `editable` own matcher (`accountKey` or
|
|
41
41
|
* `any`/`own`) of a source, `accounts` or Deposit destination list may carry it, and every editable
|
|
42
42
|
* matcher of that list must agree.
|
|
43
43
|
*
|
|
@@ -49,18 +49,18 @@ export const ACCOUNT_SELECTIONS = ["single", "multiple"];
|
|
|
49
49
|
const selection = /* @__PURE__ */ v.nullish(v.picklist(ACCOUNT_SELECTIONS));
|
|
50
50
|
// -- Grant Request matchers ---------------------------------------------------------------------
|
|
51
51
|
/**
|
|
52
|
-
* Accounts of the Subject whose Account
|
|
52
|
+
* Accounts of the Subject whose Account Key matches `pattern` (literal, `prefix*` or `*`),
|
|
53
53
|
* including accounts that will exist tomorrow. `type` may be omitted. With `editable`, the person
|
|
54
54
|
* may narrow it at consent to accounts it currently matches, which the Grant then fixes as
|
|
55
55
|
* `account` matchers.
|
|
56
56
|
*
|
|
57
57
|
* @example
|
|
58
|
-
* const caja:
|
|
59
|
-
* const short:
|
|
58
|
+
* const caja: AccountKey = { type: "account_key", pattern: "caja-*", editable: true };
|
|
59
|
+
* const short: AccountKey = { pattern: "ventas" };
|
|
60
60
|
*/
|
|
61
|
-
export const
|
|
62
|
-
type: v.nullish(v.literal("
|
|
63
|
-
pattern:
|
|
61
|
+
export const AccountKeyMatcherSchema = /* @__PURE__ */ v.strictObject({
|
|
62
|
+
type: v.nullish(v.literal("account_key")),
|
|
63
|
+
pattern: AccountKeyPatternSchema,
|
|
64
64
|
editable,
|
|
65
65
|
selection,
|
|
66
66
|
});
|
|
@@ -112,13 +112,13 @@ export const AccountExternalMatcherSchema = /* @__PURE__ */ v.strictObject({
|
|
|
112
112
|
* destination accepts, so that no permission can debit, read or collect into someone else's account.
|
|
113
113
|
*/
|
|
114
114
|
export const OwnAccountMatcherSchema = /* @__PURE__ */ v.union([
|
|
115
|
-
|
|
115
|
+
AccountKeyMatcherSchema,
|
|
116
116
|
AccountInternalMatcherSchema,
|
|
117
117
|
AnyOwnMatcherSchema,
|
|
118
118
|
]);
|
|
119
119
|
/** Every matcher kind; what a Transfer destination accepts. */
|
|
120
120
|
export const DestinationAccountMatcherSchema = /* @__PURE__ */ v.union([
|
|
121
|
-
|
|
121
|
+
AccountKeyMatcherSchema,
|
|
122
122
|
AccountInternalMatcherSchema,
|
|
123
123
|
AnyOwnMatcherSchema,
|
|
124
124
|
AnyLocalMatcherSchema,
|
|
@@ -126,10 +126,10 @@ export const DestinationAccountMatcherSchema = /* @__PURE__ */ v.union([
|
|
|
126
126
|
AccountExternalMatcherSchema,
|
|
127
127
|
]);
|
|
128
128
|
// -- Grant matchers -----------------------------------------------------------------------------
|
|
129
|
-
/** {@link
|
|
130
|
-
export const
|
|
131
|
-
type: v.literal("
|
|
132
|
-
pattern:
|
|
129
|
+
/** {@link AccountKeyMatcherSchema} as granted: `type` present, no `editable`. */
|
|
130
|
+
export const GrantedAccountKeySchema = /* @__PURE__ */ v.strictObject({
|
|
131
|
+
type: v.literal("account_key"),
|
|
132
|
+
pattern: AccountKeyPatternSchema,
|
|
133
133
|
});
|
|
134
134
|
/** {@link AccountInternalMatcherSchema} as granted. */
|
|
135
135
|
export const GrantedAccountInternalSchema = /* @__PURE__ */ v.strictObject({
|
|
@@ -156,13 +156,13 @@ export const GrantedAccountExternalSchema = /* @__PURE__ */ v.strictObject({
|
|
|
156
156
|
});
|
|
157
157
|
/** {@link OwnAccountMatcherSchema} as granted. */
|
|
158
158
|
export const GrantedOwnAccountMatcherSchema = /* @__PURE__ */ v.union([
|
|
159
|
-
|
|
159
|
+
GrantedAccountKeySchema,
|
|
160
160
|
GrantedAccountInternalSchema,
|
|
161
161
|
GrantedAnyOwnSchema,
|
|
162
162
|
]);
|
|
163
163
|
/** {@link DestinationAccountMatcherSchema} as granted. */
|
|
164
164
|
export const GrantedDestinationAccountMatcherSchema = /* @__PURE__ */ v.union([
|
|
165
|
-
|
|
165
|
+
GrantedAccountKeySchema,
|
|
166
166
|
GrantedAccountInternalSchema,
|
|
167
167
|
GrantedAnyOwnSchema,
|
|
168
168
|
GrantedAnyLocalSchema,
|
|
@@ -183,7 +183,7 @@ export function accountMatcherKey(matcher) {
|
|
|
183
183
|
case "external":
|
|
184
184
|
return `external:${ACCOUNT_EXTERNAL_FIELDS.map((field) => matcher[field] ?? "").join("\u0000")}`;
|
|
185
185
|
default:
|
|
186
|
-
return `
|
|
186
|
+
return `accountKey:${matcher.pattern}`;
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
/**
|
|
@@ -197,7 +197,7 @@ export function accountMatcherList(schema) {
|
|
|
197
197
|
/**
|
|
198
198
|
* Whether the `selection` of a list's matchers is coherent: it only sits on `editable` matchers, and
|
|
199
199
|
* every editable matcher of the list asks for the same one. Lists that are never picked from (the
|
|
200
|
-
*
|
|
200
|
+
* accountKeys of accounts to open, a Transfer's destinations) must carry none: {@link accountSelectionIsAbsent}.
|
|
201
201
|
*
|
|
202
202
|
* @example
|
|
203
203
|
* accountSelectionIsCoherent([{ type: "any", limit: "own", editable: true, selection: "single" }]); // true
|
|
@@ -235,13 +235,13 @@ const nullable = (schema) => ({ anyOf: [{ type: "null" }, schema] });
|
|
|
235
235
|
const editableJson = nullable({ type: "boolean" });
|
|
236
236
|
const selectionJson = nullable({ enum: [...ACCOUNT_SELECTIONS] });
|
|
237
237
|
const externalFieldJson = { type: "string", minLength: 1, maxLength: EXTERNAL_FIELD_CEILING, pattern: "\\S" };
|
|
238
|
-
const
|
|
238
|
+
const accountKeyRequestJson = {
|
|
239
239
|
type: "object",
|
|
240
240
|
additionalProperties: false,
|
|
241
241
|
required: ["pattern"],
|
|
242
242
|
properties: {
|
|
243
|
-
type: nullable({ const: "
|
|
244
|
-
pattern: { type: "string", pattern:
|
|
243
|
+
type: nullable({ const: "account_key" }),
|
|
244
|
+
pattern: { type: "string", pattern: ACCOUNT_KEY_PATTERN_SYNTAX },
|
|
245
245
|
editable: editableJson,
|
|
246
246
|
selection: selectionJson,
|
|
247
247
|
},
|
|
@@ -280,11 +280,11 @@ const externalRequestJson = {
|
|
|
280
280
|
editable: editableJson,
|
|
281
281
|
},
|
|
282
282
|
};
|
|
283
|
-
const
|
|
283
|
+
const accountKeyGrantJson = {
|
|
284
284
|
type: "object",
|
|
285
285
|
additionalProperties: false,
|
|
286
286
|
required: ["type", "pattern"],
|
|
287
|
-
properties: { type: { const: "
|
|
287
|
+
properties: { type: { const: "account_key" }, pattern: { type: "string", pattern: ACCOUNT_KEY_PATTERN_SYNTAX } },
|
|
288
288
|
};
|
|
289
289
|
const accountGrantJson = {
|
|
290
290
|
type: "object",
|
|
@@ -315,11 +315,13 @@ const listJson = (items) => ({
|
|
|
315
315
|
items,
|
|
316
316
|
});
|
|
317
317
|
/** JSON Schema mirror of {@link OwnAccountMatcherSchema}. */
|
|
318
|
-
export const OWN_ACCOUNT_MATCHER_JSON_SCHEMA = {
|
|
318
|
+
export const OWN_ACCOUNT_MATCHER_JSON_SCHEMA = {
|
|
319
|
+
anyOf: [accountKeyRequestJson, accountRequestJson, anyRequestJson("own")],
|
|
320
|
+
};
|
|
319
321
|
/** JSON Schema mirror of {@link DestinationAccountMatcherSchema}. */
|
|
320
322
|
export const DESTINATION_ACCOUNT_MATCHER_JSON_SCHEMA = {
|
|
321
323
|
anyOf: [
|
|
322
|
-
|
|
324
|
+
accountKeyRequestJson,
|
|
323
325
|
accountRequestJson,
|
|
324
326
|
anyRequestJson("own"),
|
|
325
327
|
anyRequestJson("local"),
|
|
@@ -329,75 +331,82 @@ export const DESTINATION_ACCOUNT_MATCHER_JSON_SCHEMA = {
|
|
|
329
331
|
};
|
|
330
332
|
/** JSON Schema mirror of {@link GrantedOwnAccountMatcherSchema}. */
|
|
331
333
|
export const GRANTED_OWN_ACCOUNT_MATCHER_JSON_SCHEMA = {
|
|
332
|
-
anyOf: [
|
|
334
|
+
anyOf: [accountKeyGrantJson, accountGrantJson, anyGrantJson("own")],
|
|
333
335
|
};
|
|
334
336
|
/** JSON Schema mirror of {@link GrantedDestinationAccountMatcherSchema}. */
|
|
335
337
|
export const GRANTED_DESTINATION_ACCOUNT_MATCHER_JSON_SCHEMA = {
|
|
336
|
-
anyOf: [
|
|
338
|
+
anyOf: [
|
|
339
|
+
accountKeyGrantJson,
|
|
340
|
+
accountGrantJson,
|
|
341
|
+
anyGrantJson("own"),
|
|
342
|
+
anyGrantJson("local"),
|
|
343
|
+
anyAllJson,
|
|
344
|
+
externalGrantJson,
|
|
345
|
+
],
|
|
337
346
|
};
|
|
338
347
|
/**
|
|
339
348
|
* JSON Schema mirror of {@link accountMatcherList}. `uniqueItems` compares whole objects, so it is
|
|
340
|
-
* looser than the valibot check, which ignores `editable` and an omitted
|
|
349
|
+
* looser than the valibot check, which ignores `editable` and an omitted accountKey `type`; the gate's
|
|
341
350
|
* own comparison closes the gap.
|
|
342
351
|
*/
|
|
343
352
|
export function accountMatcherListJsonSchema(items) {
|
|
344
353
|
return listJson(items);
|
|
345
354
|
}
|
|
346
|
-
// --
|
|
355
|
+
// -- AccountKey patterns -----------------------------------------------------------------------------
|
|
347
356
|
/**
|
|
348
|
-
* Decides whether `
|
|
357
|
+
* Decides whether `accountKey` belongs to the set described by `pattern`.
|
|
349
358
|
*
|
|
350
|
-
* The grammar of {@link
|
|
359
|
+
* The grammar of {@link ACCOUNT_KEY_PATTERN_SYNTAX} leaves only two cases: a literal matches by
|
|
351
360
|
* equality, and a trailing `*` matches by prefix. `*` alone has the empty prefix and therefore
|
|
352
|
-
* matches every
|
|
353
|
-
* A malformed pattern can only match fewer
|
|
361
|
+
* matches every accountKey — but only an accountKey: an account that carries none is matched by nothing.
|
|
362
|
+
* A malformed pattern can only match fewer accountKeys, never more: `caja*chica` has no trailing `*`,
|
|
354
363
|
* so it is compared as a literal.
|
|
355
364
|
*
|
|
356
365
|
* @example
|
|
357
|
-
*
|
|
358
|
-
*
|
|
366
|
+
* accountKeyPatternMatches("caja-*", "caja-chica"); // true
|
|
367
|
+
* accountKeyPatternMatches("caja-chica", "caja-chica-1"); // false
|
|
359
368
|
*/
|
|
360
|
-
export function
|
|
369
|
+
export function accountKeyPatternMatches(pattern, accountKey) {
|
|
361
370
|
if (!pattern.endsWith("*"))
|
|
362
|
-
return pattern ===
|
|
363
|
-
return
|
|
371
|
+
return pattern === accountKey;
|
|
372
|
+
return accountKey.startsWith(pattern.slice(0, -1));
|
|
364
373
|
}
|
|
365
374
|
/** The literal part of a pattern: the whole pattern for a literal, everything before the `*` otherwise. */
|
|
366
375
|
function literalPrefixOf(pattern) {
|
|
367
376
|
return pattern.endsWith("*") ? pattern.slice(0, -1) : pattern;
|
|
368
377
|
}
|
|
369
378
|
/**
|
|
370
|
-
* Decides whether every
|
|
371
|
-
* set of
|
|
379
|
+
* Decides whether every accountKey matched by `inner` is also matched by `outer`, for every possible
|
|
380
|
+
* set of accountKeys rather than for the ones that happen to exist right now.
|
|
372
381
|
*
|
|
373
|
-
* A literal `outer` denotes a single
|
|
382
|
+
* A literal `outer` denotes a single accountKey, so it can only contain itself — in particular
|
|
374
383
|
* `caja-chica` does not contain `caja-chica*`, whose language is infinite. A glob `outer` contains
|
|
375
384
|
* `inner` exactly when `inner`'s literal prefix starts with `outer`'s.
|
|
376
385
|
*
|
|
377
386
|
* @example
|
|
378
|
-
*
|
|
379
|
-
*
|
|
387
|
+
* accountKeyPatternContains("caja-*", "caja-chica-*"); // true
|
|
388
|
+
* accountKeyPatternContains("caja-chica", "caja-chica*"); // false
|
|
380
389
|
*/
|
|
381
|
-
export function
|
|
390
|
+
export function accountKeyPatternContains(outer, inner) {
|
|
382
391
|
if (!outer.endsWith("*"))
|
|
383
392
|
return inner === outer;
|
|
384
393
|
return literalPrefixOf(inner).startsWith(literalPrefixOf(outer));
|
|
385
394
|
}
|
|
386
|
-
/** Classifies a matcher; an
|
|
395
|
+
/** Classifies a matcher; an accountKey matcher may omit its `type`. */
|
|
387
396
|
export function accountMatcherKind(matcher) {
|
|
388
397
|
if (matcher.type === "any")
|
|
389
398
|
return matcher.limit;
|
|
390
399
|
if (matcher.type === "account" || matcher.type === "external")
|
|
391
400
|
return matcher.type;
|
|
392
|
-
return "
|
|
401
|
+
return "account_key";
|
|
393
402
|
}
|
|
394
403
|
/** Reads an own-account fact without ever reaching the prototype chain. */
|
|
395
|
-
function
|
|
404
|
+
function ownAccountKey(facts, id) {
|
|
396
405
|
const record = facts.ownAccounts;
|
|
397
406
|
if (record === undefined || !Object.hasOwn(record, id))
|
|
398
|
-
return { own: false,
|
|
399
|
-
const
|
|
400
|
-
return { own: true,
|
|
407
|
+
return { own: false, accountKey: null };
|
|
408
|
+
const accountKey = record[id];
|
|
409
|
+
return { own: true, accountKey: typeof accountKey === "string" ? accountKey : null };
|
|
401
410
|
}
|
|
402
411
|
/** An `external` contains another when every field it fixes is fixed to the same value there. */
|
|
403
412
|
function externalContains(outer, inner) {
|
|
@@ -409,20 +418,20 @@ function externalContains(outer, inner) {
|
|
|
409
418
|
/**
|
|
410
419
|
* Decides whether every account admitted by `inner` is also admitted by `outer`. The Grant's (or the
|
|
411
420
|
* Grant Request's) matcher is `outer`; the narrower Grant, or the account an operation names, is
|
|
412
|
-
* `inner`. Containment must keep holding as accounts and
|
|
421
|
+
* `inner`. Containment must keep holding as accounts and accountKeys change.
|
|
413
422
|
*
|
|
414
|
-
* The order is `any(all) ⊇ any(local) ⊇ any(own) ⊇
|
|
423
|
+
* The order is `any(all) ⊇ any(local) ⊇ any(own) ⊇ accountKey ⊇ account`, and `external` only under
|
|
415
424
|
* `all`:
|
|
416
425
|
*
|
|
417
426
|
* - `any(all)` contains every matcher; only `any(all)` contains `any(all)`.
|
|
418
427
|
* - `external` is contained by `any(all)`, and by an `external` whose every fixed field `inner`
|
|
419
428
|
* fixes to the same value. Nothing else contains it, and it contains nothing but such an
|
|
420
429
|
* `external`.
|
|
421
|
-
* - `any(local)` contains every Andco matcher: `any(local)`, `any(own)`, `
|
|
422
|
-
* - `any(own)` contains `any(own)` and `
|
|
430
|
+
* - `any(local)` contains every Andco matcher: `any(local)`, `any(own)`, `accountKey` and `account`.
|
|
431
|
+
* - `any(own)` contains `any(own)` and `accountKey` (an accountKey names an account of the Subject by
|
|
423
432
|
* construction), and an `account` only when `facts.ownAccounts` says it is the Subject's.
|
|
424
|
-
* - `
|
|
425
|
-
* `facts.ownAccounts` gives it an
|
|
433
|
+
* - `accountKey:q` contains `accountKey:p` per {@link accountKeyPatternContains}, and an `account` only when
|
|
434
|
+
* `facts.ownAccounts` gives it an accountKey that `q` matches.
|
|
426
435
|
* - `account:id` contains only `account:id`. It never contains a pattern, not even one matching
|
|
427
436
|
* exactly one account today, because it could match two tomorrow.
|
|
428
437
|
*
|
|
@@ -430,10 +439,10 @@ function externalContains(outer, inner) {
|
|
|
430
439
|
* `scripts/account-matcher-containment-cases.mjs` pin both to the same table.
|
|
431
440
|
*
|
|
432
441
|
* @example
|
|
433
|
-
* accountMatcherContains({ type: "any", limit: "local" }, { type: "
|
|
442
|
+
* accountMatcherContains({ type: "any", limit: "local" }, { type: "account_key", pattern: "caja-*" }); // true
|
|
434
443
|
* accountMatcherContains({ type: "any", limit: "local" }, { type: "external" }); // false
|
|
435
444
|
* accountMatcherContains(
|
|
436
|
-
* { type: "
|
|
445
|
+
* { type: "account_key", pattern: "caja-*" },
|
|
437
446
|
* { type: "account", id: "00000000-0000-4000-8000-000000000001" },
|
|
438
447
|
* { ownAccounts: { "00000000-0000-4000-8000-000000000001": "caja-chica" } },
|
|
439
448
|
* ); // true
|
|
@@ -454,7 +463,7 @@ export function accountMatcherContains(outer, inner, facts = {}) {
|
|
|
454
463
|
return false;
|
|
455
464
|
if (outerKind === "own") {
|
|
456
465
|
if (inner.type === "account")
|
|
457
|
-
return
|
|
466
|
+
return ownAccountKey(facts, inner.id).own;
|
|
458
467
|
return true;
|
|
459
468
|
}
|
|
460
469
|
if (innerKind === "own")
|
|
@@ -462,10 +471,10 @@ export function accountMatcherContains(outer, inner, facts = {}) {
|
|
|
462
471
|
if (outer.type === "account")
|
|
463
472
|
return inner.type === "account" && inner.id === outer.id;
|
|
464
473
|
if (inner.type === "account") {
|
|
465
|
-
const {
|
|
466
|
-
return
|
|
474
|
+
const { accountKey } = ownAccountKey(facts, inner.id);
|
|
475
|
+
return accountKey !== null && "pattern" in outer && accountKeyPatternMatches(outer.pattern, accountKey);
|
|
467
476
|
}
|
|
468
|
-
return "pattern" in outer && "pattern" in inner &&
|
|
477
|
+
return "pattern" in outer && "pattern" in inner && accountKeyPatternContains(outer.pattern, inner.pattern);
|
|
469
478
|
}
|
|
470
479
|
/**
|
|
471
480
|
* Decides whether the set described by the `inner` list is contained in the one described by
|
|
@@ -473,7 +482,7 @@ export function accountMatcherContains(outer, inner, facts = {}) {
|
|
|
473
482
|
*
|
|
474
483
|
* An empty `inner` is contained in anything, since it admits no account at all, and a non-empty
|
|
475
484
|
* `inner` is never contained in an empty `outer`. Containment is not distributed across `outer`:
|
|
476
|
-
* `[
|
|
485
|
+
* `[accountKey:a-*, accountKey:b-*]` does not contain `accountKey:*`, and refusing it is the sound answer.
|
|
477
486
|
*/
|
|
478
487
|
export function accountMatchersContain(outer, inner, facts = {}) {
|
|
479
488
|
return inner.every((one) => outer.some((candidate) => accountMatcherContains(candidate, one, facts)));
|