@andco/protocol 0.0.11 → 0.0.12

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 (120) hide show
  1. package/dist/api-errors.d.ts +5 -128
  2. package/dist/api-errors.d.ts.map +1 -1
  3. package/dist/api-errors.js +5 -131
  4. package/dist/authorization-preparation.d.ts +3 -3
  5. package/dist/authorization-preparation.d.ts.map +1 -1
  6. package/dist/authorization-preparation.js +4 -0
  7. package/dist/authorization.js +2 -2
  8. package/dist/errors.d.ts +52 -16
  9. package/dist/errors.d.ts.map +1 -1
  10. package/dist/errors.js +52 -12
  11. package/dist/index.d.ts +1 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +1 -0
  14. package/dist/intent-input.d.ts +1791 -725
  15. package/dist/intent-input.d.ts.map +1 -1
  16. package/dist/intent-input.js +325 -157
  17. package/dist/issues.d.ts +61 -0
  18. package/dist/issues.d.ts.map +1 -0
  19. package/dist/issues.js +61 -0
  20. package/dist/messages/index.d.ts +2 -2
  21. package/dist/messages/index.d.ts.map +1 -1
  22. package/dist/messages/index.js +10 -3
  23. package/dist/messages/set-preferences.d.ts +13 -1
  24. package/dist/messages/set-preferences.d.ts.map +1 -1
  25. package/dist/messages/set-preferences.js +31 -9
  26. package/dist/miniapp-manifest.d.ts +2 -2
  27. package/dist/miniapp-manifest.d.ts.map +1 -1
  28. package/dist/miniapp-manifest.js +1 -1
  29. package/dist/native-intent.d.ts +48 -28
  30. package/dist/native-intent.d.ts.map +1 -1
  31. package/dist/native-intent.js +76 -24
  32. package/dist/pagination.d.ts +37 -31
  33. package/dist/pagination.d.ts.map +1 -1
  34. package/dist/pagination.js +72 -24
  35. package/dist/rar/account-matchers.d.ts +47 -240
  36. package/dist/rar/account-matchers.d.ts.map +1 -1
  37. package/dist/rar/account-matchers.js +52 -131
  38. package/dist/rar/bank.d.ts +280 -392
  39. package/dist/rar/bank.d.ts.map +1 -1
  40. package/dist/rar/bank.js +68 -137
  41. package/dist/rar/catalog.d.ts +305 -288
  42. package/dist/rar/catalog.d.ts.map +1 -1
  43. package/dist/rar/catalog.js +69 -29
  44. package/dist/rar/detail.d.ts +15 -32
  45. package/dist/rar/detail.d.ts.map +1 -1
  46. package/dist/rar/detail.js +14 -34
  47. package/dist/rar/index.d.ts +2 -1
  48. package/dist/rar/index.d.ts.map +1 -1
  49. package/dist/rar/index.js +2 -1
  50. package/dist/rar/json-schemas.generated.d.ts +4 -0
  51. package/dist/rar/json-schemas.generated.d.ts.map +1 -0
  52. package/dist/rar/json-schemas.generated.js +3570 -0
  53. package/dist/rar/money.d.ts +5 -5
  54. package/dist/rar/money.d.ts.map +1 -1
  55. package/dist/rar/money.js +5 -5
  56. package/dist/rar/project-users.d.ts +40 -14
  57. package/dist/rar/project-users.d.ts.map +1 -1
  58. package/dist/rar/project-users.js +20 -23
  59. package/dist/rar/subject-data.d.ts +96 -48
  60. package/dist/rar/subject-data.d.ts.map +1 -1
  61. package/dist/rar/subject-data.js +61 -34
  62. package/dist/rar/subject.d.ts +18 -85
  63. package/dist/rar/subject.d.ts.map +1 -1
  64. package/dist/rar/subject.js +23 -51
  65. package/dist/rest/accounts.d.ts +347 -0
  66. package/dist/rest/accounts.d.ts.map +1 -0
  67. package/dist/rest/accounts.js +108 -0
  68. package/dist/rest/addresses.d.ts +581 -0
  69. package/dist/rest/addresses.d.ts.map +1 -0
  70. package/dist/rest/addresses.js +190 -0
  71. package/dist/rest/api-error.d.ts +104 -0
  72. package/dist/rest/api-error.d.ts.map +1 -0
  73. package/dist/rest/api-error.js +103 -0
  74. package/dist/rest/authorization.d.ts +123 -0
  75. package/dist/rest/authorization.d.ts.map +1 -0
  76. package/dist/rest/authorization.js +62 -0
  77. package/dist/rest/catalog.d.ts +199 -0
  78. package/dist/rest/catalog.d.ts.map +1 -0
  79. package/dist/rest/catalog.js +63 -0
  80. package/dist/rest/common.d.ts +637 -0
  81. package/dist/rest/common.d.ts.map +1 -0
  82. package/dist/rest/common.js +172 -0
  83. package/dist/rest/contract.d.ts +3480 -0
  84. package/dist/rest/contract.d.ts.map +1 -0
  85. package/dist/rest/contract.js +120 -0
  86. package/dist/rest/events.d.ts +145 -0
  87. package/dist/rest/events.d.ts.map +1 -0
  88. package/dist/rest/events.js +42 -0
  89. package/dist/rest/http.d.ts +49 -0
  90. package/dist/rest/http.d.ts.map +1 -0
  91. package/dist/rest/http.js +25 -0
  92. package/dist/rest/identity.d.ts +627 -0
  93. package/dist/rest/identity.d.ts.map +1 -0
  94. package/dist/rest/identity.js +128 -0
  95. package/dist/rest/index.d.ts +14 -0
  96. package/dist/rest/index.d.ts.map +1 -0
  97. package/dist/rest/index.js +13 -0
  98. package/dist/rest/intents.d.ts +4556 -0
  99. package/dist/rest/intents.d.ts.map +1 -0
  100. package/dist/rest/intents.js +551 -0
  101. package/dist/rest/signatures.d.ts +110 -0
  102. package/dist/rest/signatures.d.ts.map +1 -0
  103. package/dist/rest/signatures.js +113 -0
  104. package/dist/rest/subjects.d.ts +14 -0
  105. package/dist/rest/subjects.d.ts.map +1 -0
  106. package/dist/rest/subjects.js +22 -0
  107. package/dist/service-grants.d.ts +2 -2
  108. package/dist/service-grants.d.ts.map +1 -1
  109. package/dist/service-grants.js +1 -1
  110. package/dist/transport/generated/oauth-api.d.ts +5547 -1448
  111. package/dist/transport/generated/oauth-api.d.ts.map +1 -1
  112. package/dist/transport/intents.d.ts +9 -134
  113. package/dist/transport/intents.d.ts.map +1 -1
  114. package/dist/transport/intents.js +21 -405
  115. package/dist/transport/rest.d.ts +15 -5
  116. package/dist/transport/rest.d.ts.map +1 -1
  117. package/dist/userinfo.d.ts +22 -9
  118. package/dist/userinfo.d.ts.map +1 -1
  119. package/dist/userinfo.js +17 -12
  120. package/package.json +13 -2
@@ -1,4 +1,5 @@
1
1
  import * as v from "valibot";
2
+ import { type Issue } from "../issues.js";
2
3
  /**
3
4
  * Syntax of an Account Key: the name that identifies one Cuenta Vista among the accounts of its
4
5
  * Subject, unique per Subject regardless of which Project opened it.
@@ -19,8 +20,6 @@ export declare const ACCOUNT_KEY_SYNTAX = "^[a-z][a-z0-9_-]{0,63}$";
19
20
  * failing towards granting more.
20
21
  */
21
22
  export declare const ACCOUNT_KEY_PATTERN_SYNTAX = "^(?:\\*|[a-z][a-z0-9_-]{0,63}\\*?)$";
22
- /** Syntax of an Andco account identifier: a UUID. */
23
- export declare 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
23
  /** An Account Key, exactly as its holder chose it. */
25
24
  export declare const AccountKeySchema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
26
25
  /** A prefix glob over Account Keys. See {@link ACCOUNT_KEY_PATTERN_SYNTAX} for the grammar. */
@@ -59,13 +58,26 @@ export declare const AccountKeyMatcherSchema: v.StrictObjectSchema<{
59
58
  readonly selection: v.NullishSchema<v.PicklistSchema<readonly ["single", "multiple"], undefined>, undefined>;
60
59
  }, undefined>;
61
60
  export type AccountKey = v.InferInput<typeof AccountKeyMatcherSchema>;
61
+ /**
62
+ * {@link AccountKeyMatcherSchema} without `selection`: the accountKey patterns within which an
63
+ * application opens and closes accounts (`bank_account` `create`/`close`), a list nobody picks from.
64
+ *
65
+ * @example
66
+ * const shop: ManagedAccountKey = { type: "account_key", pattern: "shop-*" };
67
+ */
68
+ export declare const ManagedAccountKeyMatcherSchema: v.StrictObjectSchema<{
69
+ readonly type: v.NullishSchema<v.LiteralSchema<"account_key", undefined>, undefined>;
70
+ readonly pattern: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
71
+ readonly editable: v.NullishSchema<v.BooleanSchema<undefined>, undefined>;
72
+ }, undefined>;
73
+ export type ManagedAccountKey = v.InferInput<typeof ManagedAccountKeyMatcherSchema>;
62
74
  /**
63
75
  * One exact Andco account. As a source or in `accounts` it must be an account of the Subject; the
64
76
  * gate checks ownership, since the schema cannot.
65
77
  */
66
78
  export declare const AccountInternalMatcherSchema: v.StrictObjectSchema<{
67
79
  readonly type: v.LiteralSchema<"account", undefined>;
68
- readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
80
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
69
81
  readonly editable: v.NullishSchema<v.BooleanSchema<undefined>, undefined>;
70
82
  }, undefined>;
71
83
  export type AccountInternal = v.InferInput<typeof AccountInternalMatcherSchema>;
@@ -118,7 +130,7 @@ export declare const OwnAccountMatcherSchema: v.UnionSchema<[v.StrictObjectSchem
118
130
  readonly selection: v.NullishSchema<v.PicklistSchema<readonly ["single", "multiple"], undefined>, undefined>;
119
131
  }, undefined>, v.StrictObjectSchema<{
120
132
  readonly type: v.LiteralSchema<"account", undefined>;
121
- readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
133
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
122
134
  readonly editable: v.NullishSchema<v.BooleanSchema<undefined>, undefined>;
123
135
  }, undefined>, v.StrictObjectSchema<{
124
136
  readonly type: v.LiteralSchema<"any", undefined>;
@@ -135,7 +147,7 @@ export declare const DestinationAccountMatcherSchema: v.UnionSchema<[v.StrictObj
135
147
  readonly selection: v.NullishSchema<v.PicklistSchema<readonly ["single", "multiple"], undefined>, undefined>;
136
148
  }, undefined>, v.StrictObjectSchema<{
137
149
  readonly type: v.LiteralSchema<"account", undefined>;
138
- readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
150
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
139
151
  readonly editable: v.NullishSchema<v.BooleanSchema<undefined>, undefined>;
140
152
  }, undefined>, v.StrictObjectSchema<{
141
153
  readonly type: v.LiteralSchema<"any", undefined>;
@@ -167,7 +179,7 @@ export declare const GrantedAccountKeySchema: v.StrictObjectSchema<{
167
179
  /** {@link AccountInternalMatcherSchema} as granted. */
168
180
  export declare const GrantedAccountInternalSchema: v.StrictObjectSchema<{
169
181
  readonly type: v.LiteralSchema<"account", undefined>;
170
- readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
182
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
171
183
  }, undefined>;
172
184
  /** {@link AnyOwnMatcherSchema} as granted. */
173
185
  export declare const GrantedAnyOwnSchema: v.StrictObjectSchema<{
@@ -205,7 +217,7 @@ export declare const GrantedOwnAccountMatcherSchema: v.UnionSchema<[v.StrictObje
205
217
  readonly pattern: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
206
218
  }, undefined>, v.StrictObjectSchema<{
207
219
  readonly type: v.LiteralSchema<"account", undefined>;
208
- readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
220
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
209
221
  }, undefined>, v.StrictObjectSchema<{
210
222
  readonly type: v.LiteralSchema<"any", undefined>;
211
223
  readonly limit: v.LiteralSchema<"own", undefined>;
@@ -217,7 +229,7 @@ export declare const GrantedDestinationAccountMatcherSchema: v.UnionSchema<[v.St
217
229
  readonly pattern: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
218
230
  }, undefined>, v.StrictObjectSchema<{
219
231
  readonly type: v.LiteralSchema<"account", undefined>;
220
- readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
232
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
221
233
  }, undefined>, v.StrictObjectSchema<{
222
234
  readonly type: v.LiteralSchema<"any", undefined>;
223
235
  readonly limit: v.LiteralSchema<"own", undefined>;
@@ -242,15 +254,36 @@ export type GrantedDestinationAccountMatcher = v.InferOutput<typeof GrantedDesti
242
254
  */
243
255
  export declare function accountMatcherKey(matcher: DestinationAccountMatcher): string;
244
256
  /**
245
- * A non-empty list of distinct matchers. Empty is rejected rather than read as "everything": a
246
- * permission that listed no account authorizes zero, never all. Absent or `null` is how a Grant
247
- * Request asks for the type's default.
257
+ * A non-empty list of matchers. Empty is rejected rather than read as "everything": a permission that
258
+ * listed no account authorizes zero, never all. Absent or `null` is how a Grant Request asks for the
259
+ * type's default. JSON Schema's `uniqueItems` refuses two equal entries; the rule
260
+ * {@link accountMatcherListIssues} also refuses two that only differ by `editable` or an omitted
261
+ * accountKey `type`, and the gate's own comparison does the same.
262
+ */
263
+ export declare function accountMatcherList<Schema extends v.GenericSchema<DestinationAccountMatcher, DestinationAccountMatcher | GrantedDestinationAccountMatcher>>(schema: Schema): v.SchemaWithPipe<readonly [v.ArraySchema<Schema, undefined>, v.MinLengthAction<v.InferOutput<Schema>[], 1, undefined>, v.MaxLengthAction<v.InferOutput<Schema>[], 100, undefined>, v.MetadataAction<v.InferOutput<Schema>[], {
264
+ readonly uniqueItems: true;
265
+ }>]>;
266
+ /**
267
+ * The rules of a matcher list, in a Grant Request or a Grant:
268
+ *
269
+ * - `duplicate_account_matcher` at a matcher whose {@link accountMatcherKey} an earlier one has.
270
+ * - In a list the person picks from (`pickable`: sources, `accounts`, a Deposit's destinations),
271
+ * `account_selection_incoherent` at the list when {@link accountSelectionIsCoherent} fails.
272
+ * - In a list nobody picks from (a Transfer's destinations), `account_selection_not_pickable` at
273
+ * every `selection`.
274
+ *
275
+ * @example
276
+ * accountMatcherListIssues([{ type: "account_key", pattern: "caja-*" }, { pattern: "caja-*" }], { pickable: true });
277
+ * // [{ type: "duplicate_account_matcher", path: [{ key: 1 }] }]
248
278
  */
249
- export declare function accountMatcherList<Schema extends v.GenericSchema<DestinationAccountMatcher, DestinationAccountMatcher | GrantedDestinationAccountMatcher>>(schema: Schema): v.SchemaWithPipe<readonly [v.ArraySchema<Schema, undefined>, v.MinLengthAction<v.InferOutput<Schema>[], 1, undefined>, v.MaxLengthAction<v.InferOutput<Schema>[], 100, undefined>, v.CheckAction<v.InferOutput<Schema>[], "duplicate_account_matcher">]>;
279
+ export declare function accountMatcherListIssues(matchers: readonly DestinationAccountMatcher[], options: {
280
+ readonly pickable: boolean;
281
+ }): Issue[];
250
282
  /**
251
283
  * Whether the `selection` of a list's matchers is coherent: it only sits on `editable` matchers, and
252
- * every editable matcher of the list asks for the same one. Lists that are never picked from (the
253
- * accountKeys of accounts to open, a Transfer's destinations) must carry none: {@link accountSelectionIsAbsent}.
284
+ * every editable matcher of the list asks for the same one. Lists that are never picked from must
285
+ * carry none: the accountKeys of accounts to open by their shape ({@link ManagedAccountKeyMatcherSchema}),
286
+ * a Transfer's destinations by {@link accountSelectionIsAbsent}.
254
287
  *
255
288
  * @example
256
289
  * accountSelectionIsCoherent([{ type: "any", limit: "own", editable: true, selection: "single" }]); // true
@@ -265,232 +298,6 @@ export declare function accountSelectionIsSingle(matchers: readonly DestinationA
265
298
  export declare const DEFAULT_OWN_ACCOUNT_MATCHERS: readonly GrantedOwnAccountMatcher[];
266
299
  /** What an absent or `null` Transfer destination list means. */
267
300
  export declare const DEFAULT_DESTINATION_ACCOUNT_MATCHERS: readonly GrantedDestinationAccountMatcher[];
268
- /** JSON Schema mirror of {@link OwnAccountMatcherSchema}. */
269
- export declare const OWN_ACCOUNT_MATCHER_JSON_SCHEMA: {
270
- anyOf: ({
271
- type: string;
272
- additionalProperties: boolean;
273
- required: string[];
274
- properties: {
275
- type: {
276
- anyOf: ({
277
- const: string;
278
- } | {
279
- type: string;
280
- })[];
281
- };
282
- pattern: {
283
- type: string;
284
- pattern: string;
285
- };
286
- editable: {
287
- anyOf: ({
288
- type: string;
289
- } | {
290
- type: string;
291
- })[];
292
- };
293
- selection: {
294
- anyOf: ({
295
- enum: ("single" | "multiple")[];
296
- } | {
297
- type: string;
298
- })[];
299
- };
300
- };
301
- } | {
302
- type: string;
303
- additionalProperties: boolean;
304
- required: string[];
305
- properties: {
306
- type: {
307
- const: string;
308
- };
309
- id: {
310
- type: string;
311
- pattern: string;
312
- };
313
- editable: {
314
- anyOf: ({
315
- type: string;
316
- } | {
317
- type: string;
318
- })[];
319
- };
320
- };
321
- } | {
322
- type: string;
323
- additionalProperties: boolean;
324
- required: string[];
325
- properties: {
326
- type: {
327
- const: string;
328
- };
329
- limit: {
330
- const: "own";
331
- };
332
- editable: {
333
- anyOf: ({
334
- type: string;
335
- } | {
336
- type: string;
337
- })[];
338
- };
339
- selection: {
340
- anyOf: ({
341
- enum: ("single" | "multiple")[];
342
- } | {
343
- type: string;
344
- })[];
345
- };
346
- } | {
347
- type: {
348
- const: string;
349
- };
350
- limit: {
351
- const: "local";
352
- };
353
- editable: {
354
- anyOf: ({
355
- type: string;
356
- } | {
357
- type: string;
358
- })[];
359
- };
360
- selection?: undefined;
361
- };
362
- })[];
363
- };
364
- /** JSON Schema mirror of {@link DestinationAccountMatcherSchema}. */
365
- export declare const DESTINATION_ACCOUNT_MATCHER_JSON_SCHEMA: {
366
- anyOf: ({
367
- type: string;
368
- additionalProperties: boolean;
369
- required: string[];
370
- properties: {
371
- type: {
372
- anyOf: ({
373
- const: string;
374
- } | {
375
- type: string;
376
- })[];
377
- };
378
- pattern: {
379
- type: string;
380
- pattern: string;
381
- };
382
- editable: {
383
- anyOf: ({
384
- type: string;
385
- } | {
386
- type: string;
387
- })[];
388
- };
389
- selection: {
390
- anyOf: ({
391
- enum: ("single" | "multiple")[];
392
- } | {
393
- type: string;
394
- })[];
395
- };
396
- };
397
- } | {
398
- type: string;
399
- additionalProperties: boolean;
400
- required: string[];
401
- properties: {
402
- type: {
403
- const: string;
404
- };
405
- limit: {
406
- const: string;
407
- };
408
- };
409
- } | {
410
- type: string;
411
- additionalProperties: boolean;
412
- required: string[];
413
- properties: {
414
- editable: {
415
- anyOf: ({
416
- type: string;
417
- } | {
418
- type: string;
419
- })[];
420
- };
421
- type: {
422
- const: string;
423
- };
424
- };
425
- })[];
426
- };
427
- /** JSON Schema mirror of {@link GrantedOwnAccountMatcherSchema}. */
428
- export declare const GRANTED_OWN_ACCOUNT_MATCHER_JSON_SCHEMA: {
429
- anyOf: ({
430
- type: string;
431
- additionalProperties: boolean;
432
- required: string[];
433
- properties: {
434
- type: {
435
- const: string;
436
- };
437
- pattern: {
438
- type: string;
439
- pattern: string;
440
- };
441
- };
442
- } | {
443
- type: string;
444
- additionalProperties: boolean;
445
- required: string[];
446
- properties: {
447
- type: {
448
- const: string;
449
- };
450
- id: {
451
- type: string;
452
- pattern: string;
453
- };
454
- };
455
- } | {
456
- type: string;
457
- additionalProperties: boolean;
458
- required: string[];
459
- properties: {
460
- type: {
461
- const: string;
462
- };
463
- limit: {
464
- const: "own" | "local";
465
- };
466
- };
467
- })[];
468
- };
469
- /** JSON Schema mirror of {@link GrantedDestinationAccountMatcherSchema}. */
470
- export declare const GRANTED_DESTINATION_ACCOUNT_MATCHER_JSON_SCHEMA: {
471
- anyOf: {
472
- type: string;
473
- additionalProperties: boolean;
474
- required: string[];
475
- properties: {
476
- type: {
477
- const: string;
478
- };
479
- };
480
- }[];
481
- };
482
- /**
483
- * JSON Schema mirror of {@link accountMatcherList}. `uniqueItems` compares whole objects, so it is
484
- * looser than the valibot check, which ignores `editable` and an omitted accountKey `type`; the gate's
485
- * own comparison closes the gap.
486
- */
487
- export declare function accountMatcherListJsonSchema(items: object): {
488
- type: string;
489
- minItems: number;
490
- maxItems: number;
491
- uniqueItems: boolean;
492
- items: object;
493
- };
494
301
  /**
495
302
  * Decides whether `accountKey` belongs to the set described by `pattern`.
496
303
  *
@@ -1 +1 @@
1
- {"version":3,"file":"account-matchers.d.ts","sourceRoot":"","sources":["../../src/rar/account-matchers.ts"],"names":[],"mappings":"AAAA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OG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,SAAS,yBAAyB,EAAE,EAC3C,KAAK,EAAE,SAAS,yBAAyB,EAAE,EAC3C,KAAK,GAAE,mBAAwB,GAC9B,OAAO,CAET"}
@@ -1,4 +1,5 @@
1
1
  import * as v from "valibot";
2
+ import { duplicateIssues } from "../issues.js";
2
3
  /**
3
4
  * Syntax of an Account Key: the name that identifies one Cuenta Vista among the accounts of its
4
5
  * Subject, unique per Subject regardless of which Project opened it.
@@ -19,8 +20,6 @@ export const ACCOUNT_KEY_SYNTAX = "^[a-z][a-z0-9_-]{0,63}$";
19
20
  * failing towards granting more.
20
21
  */
21
22
  export const ACCOUNT_KEY_PATTERN_SYNTAX = "^(?:\\*|[a-z][a-z0-9_-]{0,63}\\*?)$";
22
- /** Syntax of an Andco account identifier: a UUID. */
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
23
  /** An Account Key, exactly as its holder chose it. */
25
24
  export const AccountKeySchema = /* @__PURE__ */ v.pipe(v.string(), v.regex(new RegExp(ACCOUNT_KEY_SYNTAX)));
26
25
  /** A prefix glob over Account Keys. See {@link ACCOUNT_KEY_PATTERN_SYNTAX} for the grammar. */
@@ -31,7 +30,8 @@ export const ACCOUNT_MATCHER_LIST_CEILING = 100;
31
30
  const EXTERNAL_FIELD_CEILING = 128;
32
31
  /** The fields an `external` matcher may fix, each narrowing the accounts it admits. */
33
32
  export const ACCOUNT_EXTERNAL_FIELDS = ["bank_id", "account_type", "account_id", "holder_id", "holder_name"];
34
- const accountId = /* @__PURE__ */ v.pipe(v.string(), v.regex(new RegExp(ACCOUNT_ID_PATTERN)));
33
+ /** An Andco account identifier: any 8-4-4-4-12 hex, with no version or variant check. */
34
+ const accountId = /* @__PURE__ */ v.pipe(v.string(), v.uuid());
35
35
  const externalField = /* @__PURE__ */ v.pipe(v.string(), v.minLength(1), v.maxLength(EXTERNAL_FIELD_CEILING), v.regex(/\S/));
36
36
  const editable = /* @__PURE__ */ v.nullish(v.boolean());
37
37
  /**
@@ -64,6 +64,18 @@ export const AccountKeyMatcherSchema = /* @__PURE__ */ v.strictObject({
64
64
  editable,
65
65
  selection,
66
66
  });
67
+ /**
68
+ * {@link AccountKeyMatcherSchema} without `selection`: the accountKey patterns within which an
69
+ * application opens and closes accounts (`bank_account` `create`/`close`), a list nobody picks from.
70
+ *
71
+ * @example
72
+ * const shop: ManagedAccountKey = { type: "account_key", pattern: "shop-*" };
73
+ */
74
+ export const ManagedAccountKeyMatcherSchema = /* @__PURE__ */ v.strictObject({
75
+ type: v.nullish(v.literal("account_key")),
76
+ pattern: AccountKeyPatternSchema,
77
+ editable,
78
+ });
67
79
  /**
68
80
  * One exact Andco account. As a source or in `accounts` it must be an account of the Subject; the
69
81
  * gate checks ownership, since the schema cannot.
@@ -187,17 +199,48 @@ export function accountMatcherKey(matcher) {
187
199
  }
188
200
  }
189
201
  /**
190
- * A non-empty list of distinct matchers. Empty is rejected rather than read as "everything": a
191
- * permission that listed no account authorizes zero, never all. Absent or `null` is how a Grant
192
- * Request asks for the type's default.
202
+ * A non-empty list of matchers. Empty is rejected rather than read as "everything": a permission that
203
+ * listed no account authorizes zero, never all. Absent or `null` is how a Grant Request asks for the
204
+ * type's default. JSON Schema's `uniqueItems` refuses two equal entries; the rule
205
+ * {@link accountMatcherListIssues} also refuses two that only differ by `editable` or an omitted
206
+ * accountKey `type`, and the gate's own comparison does the same.
193
207
  */
194
208
  export function accountMatcherList(schema) {
195
- return v.pipe(v.array(schema), v.minLength(1), v.maxLength(ACCOUNT_MATCHER_LIST_CEILING), v.check((matchers) => new Set(matchers.map((one) => accountMatcherKey(one))).size === matchers.length, "duplicate_account_matcher"));
209
+ return v.pipe(v.array(schema), v.minLength(1), v.maxLength(ACCOUNT_MATCHER_LIST_CEILING), v.metadata({ uniqueItems: true }));
210
+ }
211
+ /**
212
+ * The rules of a matcher list, in a Grant Request or a Grant:
213
+ *
214
+ * - `duplicate_account_matcher` at a matcher whose {@link accountMatcherKey} an earlier one has.
215
+ * - In a list the person picks from (`pickable`: sources, `accounts`, a Deposit's destinations),
216
+ * `account_selection_incoherent` at the list when {@link accountSelectionIsCoherent} fails.
217
+ * - In a list nobody picks from (a Transfer's destinations), `account_selection_not_pickable` at
218
+ * every `selection`.
219
+ *
220
+ * @example
221
+ * accountMatcherListIssues([{ type: "account_key", pattern: "caja-*" }, { pattern: "caja-*" }], { pickable: true });
222
+ * // [{ type: "duplicate_account_matcher", path: [{ key: 1 }] }]
223
+ */
224
+ export function accountMatcherListIssues(matchers, options) {
225
+ const issues = duplicateIssues(matchers, "duplicate_account_matcher", accountMatcherKey);
226
+ if (options.pickable) {
227
+ if (!accountSelectionIsCoherent(matchers)) {
228
+ issues.push({ type: "account_selection_incoherent", path: undefined });
229
+ }
230
+ return issues;
231
+ }
232
+ matchers.forEach((matcher, index) => {
233
+ if (!accountSelectionIsAbsent([matcher])) {
234
+ issues.push({ type: "account_selection_not_pickable", path: [{ key: index }, { key: "selection" }] });
235
+ }
236
+ });
237
+ return issues;
196
238
  }
197
239
  /**
198
240
  * Whether the `selection` of a list's matchers is coherent: it only sits on `editable` matchers, and
199
- * every editable matcher of the list asks for the same one. Lists that are never picked from (the
200
- * accountKeys of accounts to open, a Transfer's destinations) must carry none: {@link accountSelectionIsAbsent}.
241
+ * every editable matcher of the list asks for the same one. Lists that are never picked from must
242
+ * carry none: the accountKeys of accounts to open by their shape ({@link ManagedAccountKeyMatcherSchema}),
243
+ * a Transfer's destinations by {@link accountSelectionIsAbsent}.
201
244
  *
202
245
  * @example
203
246
  * accountSelectionIsCoherent([{ type: "any", limit: "own", editable: true, selection: "single" }]); // true
@@ -230,128 +273,6 @@ export const DEFAULT_OWN_ACCOUNT_MATCHERS = [{ type: "any", limit: "own" }];
230
273
  export const DEFAULT_DESTINATION_ACCOUNT_MATCHERS = [
231
274
  { type: "any", limit: "all" },
232
275
  ];
233
- // -- JSON Schema mirrors ------------------------------------------------------------------------
234
- const nullable = (schema) => ({ anyOf: [{ type: "null" }, schema] });
235
- const editableJson = nullable({ type: "boolean" });
236
- const selectionJson = nullable({ enum: [...ACCOUNT_SELECTIONS] });
237
- const externalFieldJson = { type: "string", minLength: 1, maxLength: EXTERNAL_FIELD_CEILING, pattern: "\\S" };
238
- const accountKeyRequestJson = {
239
- type: "object",
240
- additionalProperties: false,
241
- required: ["pattern"],
242
- properties: {
243
- type: nullable({ const: "account_key" }),
244
- pattern: { type: "string", pattern: ACCOUNT_KEY_PATTERN_SYNTAX },
245
- editable: editableJson,
246
- selection: selectionJson,
247
- },
248
- };
249
- const accountRequestJson = {
250
- type: "object",
251
- additionalProperties: false,
252
- required: ["type", "id"],
253
- properties: {
254
- type: { const: "account" },
255
- id: { type: "string", pattern: ACCOUNT_ID_PATTERN },
256
- editable: editableJson,
257
- },
258
- };
259
- const anyRequestJson = (limit) => ({
260
- type: "object",
261
- additionalProperties: false,
262
- required: ["type", "limit"],
263
- properties: limit === "own"
264
- ? { type: { const: "any" }, limit: { const: limit }, editable: editableJson, selection: selectionJson }
265
- : { type: { const: "any" }, limit: { const: limit }, editable: editableJson },
266
- });
267
- const anyAllJson = {
268
- type: "object",
269
- additionalProperties: false,
270
- required: ["type", "limit"],
271
- properties: { type: { const: "any" }, limit: { const: "all" } },
272
- };
273
- const externalRequestJson = {
274
- type: "object",
275
- additionalProperties: false,
276
- required: ["type"],
277
- properties: {
278
- type: { const: "external" },
279
- ...Object.fromEntries(ACCOUNT_EXTERNAL_FIELDS.map((field) => [field, nullable(externalFieldJson)])),
280
- editable: editableJson,
281
- },
282
- };
283
- const accountKeyGrantJson = {
284
- type: "object",
285
- additionalProperties: false,
286
- required: ["type", "pattern"],
287
- properties: { type: { const: "account_key" }, pattern: { type: "string", pattern: ACCOUNT_KEY_PATTERN_SYNTAX } },
288
- };
289
- const accountGrantJson = {
290
- type: "object",
291
- additionalProperties: false,
292
- required: ["type", "id"],
293
- properties: { type: { const: "account" }, id: { type: "string", pattern: ACCOUNT_ID_PATTERN } },
294
- };
295
- const anyGrantJson = (limit) => ({
296
- type: "object",
297
- additionalProperties: false,
298
- required: ["type", "limit"],
299
- properties: { type: { const: "any" }, limit: { const: limit } },
300
- });
301
- const externalGrantJson = {
302
- type: "object",
303
- additionalProperties: false,
304
- required: ["type"],
305
- properties: {
306
- type: { const: "external" },
307
- ...Object.fromEntries(ACCOUNT_EXTERNAL_FIELDS.map((field) => [field, externalFieldJson])),
308
- },
309
- };
310
- const listJson = (items) => ({
311
- type: "array",
312
- minItems: 1,
313
- maxItems: ACCOUNT_MATCHER_LIST_CEILING,
314
- uniqueItems: true,
315
- items,
316
- });
317
- /** JSON Schema mirror of {@link OwnAccountMatcherSchema}. */
318
- export const OWN_ACCOUNT_MATCHER_JSON_SCHEMA = {
319
- anyOf: [accountKeyRequestJson, accountRequestJson, anyRequestJson("own")],
320
- };
321
- /** JSON Schema mirror of {@link DestinationAccountMatcherSchema}. */
322
- export const DESTINATION_ACCOUNT_MATCHER_JSON_SCHEMA = {
323
- anyOf: [
324
- accountKeyRequestJson,
325
- accountRequestJson,
326
- anyRequestJson("own"),
327
- anyRequestJson("local"),
328
- anyAllJson,
329
- externalRequestJson,
330
- ],
331
- };
332
- /** JSON Schema mirror of {@link GrantedOwnAccountMatcherSchema}. */
333
- export const GRANTED_OWN_ACCOUNT_MATCHER_JSON_SCHEMA = {
334
- anyOf: [accountKeyGrantJson, accountGrantJson, anyGrantJson("own")],
335
- };
336
- /** JSON Schema mirror of {@link GrantedDestinationAccountMatcherSchema}. */
337
- export const GRANTED_DESTINATION_ACCOUNT_MATCHER_JSON_SCHEMA = {
338
- anyOf: [
339
- accountKeyGrantJson,
340
- accountGrantJson,
341
- anyGrantJson("own"),
342
- anyGrantJson("local"),
343
- anyAllJson,
344
- externalGrantJson,
345
- ],
346
- };
347
- /**
348
- * JSON Schema mirror of {@link accountMatcherList}. `uniqueItems` compares whole objects, so it is
349
- * looser than the valibot check, which ignores `editable` and an omitted accountKey `type`; the gate's
350
- * own comparison closes the gap.
351
- */
352
- export function accountMatcherListJsonSchema(items) {
353
- return listJson(items);
354
- }
355
276
  // -- AccountKey patterns -----------------------------------------------------------------------------
356
277
  /**
357
278
  * Decides whether `accountKey` belongs to the set described by `pattern`.