@andco/protocol 0.0.3 → 0.0.5

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 (113) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +51 -3
  3. package/dist/api-errors.d.ts +114 -0
  4. package/dist/api-errors.d.ts.map +1 -0
  5. package/dist/api-errors.js +116 -0
  6. package/dist/authorization-preparation.d.ts +52 -543
  7. package/dist/authorization-preparation.d.ts.map +1 -1
  8. package/dist/authorization-preparation.js +19 -42
  9. package/dist/authorization.d.ts +64 -22
  10. package/dist/authorization.d.ts.map +1 -1
  11. package/dist/authorization.js +136 -55
  12. package/dist/consent.d.ts +5 -8
  13. package/dist/consent.d.ts.map +1 -1
  14. package/dist/consent.js +5 -62
  15. package/dist/constants.d.ts +19 -3
  16. package/dist/constants.d.ts.map +1 -1
  17. package/dist/constants.js +19 -3
  18. package/dist/errors.d.ts +154 -58
  19. package/dist/errors.d.ts.map +1 -1
  20. package/dist/errors.js +174 -57
  21. package/dist/index.d.ts +4 -4
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +4 -4
  24. package/dist/intent-input.d.ts +1022 -288
  25. package/dist/intent-input.d.ts.map +1 -1
  26. package/dist/intent-input.js +284 -40
  27. package/dist/messages/error.d.ts +1 -2
  28. package/dist/messages/error.d.ts.map +1 -1
  29. package/dist/messages/error.js +5 -2
  30. package/dist/messages/index.d.ts +1 -1
  31. package/dist/native-copy.d.ts +23 -2
  32. package/dist/native-copy.d.ts.map +1 -1
  33. package/dist/native-copy.js +65 -117
  34. package/dist/native-intent.d.ts +126 -75
  35. package/dist/native-intent.d.ts.map +1 -1
  36. package/dist/native-intent.js +140 -48
  37. package/dist/rar/account-matchers.d.ts +579 -0
  38. package/dist/rar/account-matchers.d.ts.map +1 -0
  39. package/dist/rar/account-matchers.js +480 -0
  40. package/dist/rar/bank.d.ts +1549 -0
  41. package/dist/rar/bank.d.ts.map +1 -0
  42. package/dist/rar/bank.js +379 -0
  43. package/dist/rar/catalog.d.ts +1155 -0
  44. package/dist/rar/catalog.d.ts.map +1 -0
  45. package/dist/rar/catalog.js +175 -0
  46. package/dist/rar/detail.d.ts +39 -0
  47. package/dist/rar/detail.d.ts.map +1 -0
  48. package/dist/rar/detail.js +44 -0
  49. package/dist/rar/index.d.ts +9 -0
  50. package/dist/rar/index.d.ts.map +1 -0
  51. package/dist/rar/index.js +8 -0
  52. package/dist/rar/money.d.ts +58 -0
  53. package/dist/rar/money.d.ts.map +1 -0
  54. package/dist/rar/money.js +61 -0
  55. package/dist/rar/project-users.d.ts +43 -0
  56. package/dist/rar/project-users.d.ts.map +1 -0
  57. package/dist/rar/project-users.js +63 -0
  58. package/dist/rar/subject-data.d.ts +170 -0
  59. package/dist/rar/subject-data.d.ts.map +1 -0
  60. package/dist/rar/subject-data.js +127 -0
  61. package/dist/rar/subject.d.ts +166 -0
  62. package/dist/rar/subject.d.ts.map +1 -0
  63. package/dist/rar/subject.js +119 -0
  64. package/dist/scopes.d.ts +5 -30
  65. package/dist/scopes.d.ts.map +1 -1
  66. package/dist/scopes.js +0 -13
  67. package/dist/service-grants.d.ts +44 -0
  68. package/dist/service-grants.d.ts.map +1 -0
  69. package/dist/service-grants.js +45 -0
  70. package/dist/signing.d.ts +56 -0
  71. package/dist/signing.d.ts.map +1 -0
  72. package/dist/signing.js +233 -0
  73. package/dist/transport/financial-events.d.ts +90 -35
  74. package/dist/transport/financial-events.d.ts.map +1 -1
  75. package/dist/transport/financial-events.js +7 -1
  76. package/dist/transport/generated/oauth-api.d.ts +932 -441
  77. package/dist/transport/generated/oauth-api.d.ts.map +1 -1
  78. package/dist/transport/index.d.ts +0 -1
  79. package/dist/transport/index.d.ts.map +1 -1
  80. package/dist/transport/index.js +0 -1
  81. package/dist/transport/intents.d.ts +155 -23
  82. package/dist/transport/intents.d.ts.map +1 -1
  83. package/dist/transport/intents.js +192 -59
  84. package/dist/transport/rest.d.ts +19 -8
  85. package/dist/transport/rest.d.ts.map +1 -1
  86. package/dist/transport/rest.js +1 -1
  87. package/dist/urls.d.ts.map +1 -1
  88. package/dist/urls.js +1 -1
  89. package/dist/userinfo.d.ts +10 -1
  90. package/dist/userinfo.d.ts.map +1 -1
  91. package/dist/userinfo.js +10 -1
  92. package/dist/utils.d.ts +15 -0
  93. package/dist/utils.d.ts.map +1 -1
  94. package/dist/utils.js +31 -0
  95. package/dist/webhooks.d.ts +154 -0
  96. package/dist/webhooks.d.ts.map +1 -0
  97. package/dist/webhooks.js +249 -0
  98. package/package.json +21 -2
  99. package/dist/automatic-charge.d.ts +0 -314
  100. package/dist/automatic-charge.d.ts.map +0 -1
  101. package/dist/automatic-charge.js +0 -126
  102. package/dist/bank-account-authorization.d.ts +0 -6
  103. package/dist/bank-account-authorization.d.ts.map +0 -1
  104. package/dist/bank-account-authorization.js +0 -13
  105. package/dist/transport/webhooks.d.ts +0 -27
  106. package/dist/transport/webhooks.d.ts.map +0 -1
  107. package/dist/transport/webhooks.js +0 -68
  108. package/dist/webhook-input.d.ts +0 -22
  109. package/dist/webhook-input.d.ts.map +0 -1
  110. package/dist/webhook-input.js +0 -11
  111. package/dist/webhook-signature.d.ts +0 -54
  112. package/dist/webhook-signature.d.ts.map +0 -1
  113. package/dist/webhook-signature.js +0 -74
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bank.d.ts","sourceRoot":"","sources":["../../src/rar/bank.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAoC7B,0EAA0E;AAC1E,eAAO,MAAM,yBAAyB,mCAAoC,CAAC;AAC3E,gGAAgG;AAChG,eAAO,MAAM,2BAA2B,8BAA+B,CAAC;AACxE,+FAA+F;AAC/F,eAAO,MAAM,6BAA6B,gCAAiC,CAAC;AAC5E,2DAA2D;AAC3D,eAAO,MAAM,oBAAoB,2EAIvB,CAAC;AACX,6DAA6D;AAC7D,eAAO,MAAM,wBAAwB,mBAAoB,CAAC;AAC1D,sDAAsD;A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,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAMjC,CAAC;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,sBAAsB,CAAC,CAAC;AA8D5E,mEAAmE;AACnE,eAAO,MAAM,sCAAsC,yBAmBjD,CAAC;AACH,4DAA4D;AAC5D,eAAO,MAAM,8BAA8B,yBAmBzC,CAAC;AAEH,uEAAuE;AACvE,eAAO,MAAM,0CAA0C,yBAOrD,CAAC;AACH,gEAAgE;AAChE,eAAO,MAAM,kCAAkC,yBAO7C,CAAC;AAEH,oEAAoE;AACpE,eAAO,MAAM,uCAAuC,yBAoBlD,CAAC;AACH,6DAA6D;AAC7D,eAAO,MAAM,+BAA+B,yBAmB1C,CAAC;AAEH,mEAAmE;AACnE,eAAO,MAAM,sCAAsC,yBAOjD,CAAC;AACH,4DAA4D;AAC5D,eAAO,MAAM,8BAA8B,yBAOzC,CAAC"}
@@ -0,0 +1,379 @@
1
+ import * as v from "valibot";
2
+ import { ACCOUNT_ALIAS_PATTERN_SYNTAX, AccountAliasMatcherSchema, accountMatcherList, accountMatcherListJsonSchema, accountSelectionIsAbsent, accountSelectionIsCoherent, DESTINATION_ACCOUNT_MATCHER_JSON_SCHEMA, DestinationAccountMatcherSchema, GRANTED_DESTINATION_ACCOUNT_MATCHER_JSON_SCHEMA, GRANTED_OWN_ACCOUNT_MATCHER_JSON_SCHEMA, GrantedAccountAliasSchema, GrantedDestinationAccountMatcherSchema, GrantedOwnAccountMatcherSchema, OWN_ACCOUNT_MATCHER_JSON_SCHEMA, OwnAccountMatcherSchema, } from "./account-matchers.js";
3
+ import { AndcoRarLocationsSchema, actionSet, actionSetJson, detailFormJson, detailTypeJson, nullableJson, } from "./detail.js";
4
+ import { compareMoney, TRANSACTION_LIMIT_PATTERN, TransactionLimitSchema } from "./money.js";
5
+ import { GRANTED_SUBJECT_JSON_SCHEMA, GrantedSubjectSchema, SUBJECT_PICKER_JSON_SCHEMA, SubjectPickerSchema, } from "./subject.js";
6
+ // -- Actions ------------------------------------------------------------------------------------
7
+ /** Reading accounts and their balances. `create` never implies either. */
8
+ export const BANK_ACCOUNT_READ_ACTIONS = ["read", "read_balance"];
9
+ /** Opening and closing accounts, within the alias patterns of `accounts`. Each is an Intent. */
10
+ export const BANK_ACCOUNT_MANAGE_ACTIONS = ["create", "close"];
11
+ /** Approving or rejecting an Account Opening or closing someone else created: dual control. */
12
+ export const BANK_ACCOUNT_APPROVAL_ACTIONS = ["approve", "reject"];
13
+ /** Every `bank_account` action, across its three forms. */
14
+ export const BANK_ACCOUNT_ACTIONS = [
15
+ ...BANK_ACCOUNT_READ_ACTIONS,
16
+ ...BANK_ACCOUNT_MANAGE_ACTIONS,
17
+ ...BANK_ACCOUNT_APPROVAL_ACTIONS,
18
+ ];
19
+ /** Reading the Transactions (ledger entries) of accounts. */
20
+ export const BANK_TRANSACTION_ACTIONS = ["read"];
21
+ /** Proposing Transfers within the detail's bounds. */
22
+ export const BANK_TRANSFER_CREATE_ACTIONS = ["create"];
23
+ /** Approving or rejecting Transfers someone else created: the other half of dual control. */
24
+ export const BANK_TRANSFER_APPROVAL_ACTIONS = ["approve", "reject"];
25
+ /** Every `bank_transfer` action, across its two forms. */
26
+ export const BANK_TRANSFER_ACTIONS = [...BANK_TRANSFER_CREATE_ACTIONS, ...BANK_TRANSFER_APPROVAL_ACTIONS];
27
+ /** Creating, reading and closing Deposits. A Deposit needs no Approval: money arriving is not money leaving. */
28
+ export const BANK_DEPOSIT_ACTIONS = ["create", "read", "close"];
29
+ /** The only currency a bank detail names today. It is still required: a permission never assumes CLP. */
30
+ export const BANK_CURRENCIES = ["CLP"];
31
+ // -- Shared pieces ------------------------------------------------------------------------------
32
+ const currency = /* @__PURE__ */ v.picklist(BANK_CURRENCIES);
33
+ const ownList = /* @__PURE__ */ v.pipe(accountMatcherList(OwnAccountMatcherSchema), v.check((matchers) => accountSelectionIsCoherent(matchers), "account_selection_incoherent"));
34
+ const destinationList = /* @__PURE__ */ v.pipe(accountMatcherList(DestinationAccountMatcherSchema), v.check((matchers) => accountSelectionIsAbsent(matchers), "account_selection_not_pickable"));
35
+ const aliasList = /* @__PURE__ */ v.pipe(accountMatcherList(AccountAliasMatcherSchema), v.check((matchers) => accountSelectionIsAbsent(matchers), "account_selection_not_pickable"));
36
+ const grantedOwnList = /* @__PURE__ */ accountMatcherList(GrantedOwnAccountMatcherSchema);
37
+ const grantedDestinationList = /* @__PURE__ */ accountMatcherList(GrantedDestinationAccountMatcherSchema);
38
+ const grantedAliasList = /* @__PURE__ */ accountMatcherList(GrantedAccountAliasSchema);
39
+ const present = (value) => value !== undefined && value !== null;
40
+ /** `value` fixes an exact amount, so it cannot travel with a range. */
41
+ const valueExcludesRange = (limits) => !present(limits.value) || (!present(limits.minimum) && !present(limits.maximum));
42
+ /** A range must not be empty. */
43
+ const rangeIsOrdered = (limits) => !present(limits.minimum) || !present(limits.maximum) || compareMoney(limits.minimum, limits.maximum) <= 0;
44
+ /**
45
+ * Amount limits of a Transfer permission in a Grant Request. `value` fixes an exact amount;
46
+ * `minimum`/`maximum` define a range, and both forms together are rejected as ambiguous. Every
47
+ * amount is at least {@link MINIMUM_TRANSACTION_AMOUNT}. With `editable`, consent may only lower
48
+ * the maximum or raise the minimum.
49
+ *
50
+ * @example
51
+ * const exact = { value: "25990" };
52
+ * const range = { minimum: "1000", maximum: "5000000", editable: true };
53
+ */
54
+ export const TransferLimitsRequestSchema = /* @__PURE__ */ v.pipe(v.strictObject({
55
+ value: v.nullish(TransactionLimitSchema),
56
+ minimum: v.nullish(TransactionLimitSchema),
57
+ maximum: v.nullish(TransactionLimitSchema),
58
+ editable: v.nullish(v.boolean()),
59
+ }), v.check((limits) => valueExcludesRange(limits), "value_excludes_minimum_and_maximum"), v.check((limits) => rangeIsOrdered(limits), "minimum_above_maximum"));
60
+ /** {@link TransferLimitsRequestSchema} as granted: no `editable`, no `null`. */
61
+ export const TransferLimitsGrantSchema = /* @__PURE__ */ v.pipe(v.strictObject({
62
+ value: v.optional(TransactionLimitSchema),
63
+ minimum: v.optional(TransactionLimitSchema),
64
+ maximum: v.optional(TransactionLimitSchema),
65
+ }), v.check((limits) => valueExcludesRange(limits), "value_excludes_minimum_and_maximum"), v.check((limits) => rangeIsOrdered(limits), "minimum_above_maximum"));
66
+ /** The amount an approver may approve, in a Grant Request. `null` or absent means no bound. */
67
+ export const ApprovalLimitsRequestSchema = /* @__PURE__ */ v.pipe(v.strictObject({ minimum: v.nullish(TransactionLimitSchema), maximum: v.nullish(TransactionLimitSchema) }), v.check((limits) => rangeIsOrdered(limits), "minimum_above_maximum"));
68
+ /** {@link ApprovalLimitsRequestSchema} as granted. */
69
+ export const ApprovalLimitsGrantSchema = /* @__PURE__ */ v.pipe(v.strictObject({ minimum: v.optional(TransactionLimitSchema), maximum: v.optional(TransactionLimitSchema) }), v.check((limits) => rangeIsOrdered(limits), "minimum_above_maximum"));
70
+ // -- bank_account -------------------------------------------------------------------------------
71
+ /**
72
+ * `bank_account` Grant Request: three forms, one per action family, never mixed in one detail.
73
+ *
74
+ * - `read`/`read_balance` over `accounts` (own matchers; absent means every own account).
75
+ * - `create`/`close` within `accounts`, which is required and only takes alias patterns: an
76
+ * application opens the accounts its naming convention owns.
77
+ * - `approve`/`reject` of openings and closings, without accounts.
78
+ *
79
+ * @example
80
+ * const read: BankAccountGrantRequest = {
81
+ * type: "bank_account",
82
+ * actions: ["read", "read_balance"],
83
+ * locations: ["https://api.andco.com"],
84
+ * subject: { type: "organization", editable: true },
85
+ * accounts: [{ type: "alias", pattern: "caja-*", editable: true }],
86
+ * };
87
+ */
88
+ export const BankAccountGrantRequestSchema = /* @__PURE__ */ v.union([
89
+ v.strictObject({
90
+ type: v.literal("bank_account"),
91
+ actions: actionSet(BANK_ACCOUNT_READ_ACTIONS),
92
+ locations: AndcoRarLocationsSchema,
93
+ subject: SubjectPickerSchema,
94
+ accounts: v.nullish(ownList),
95
+ }),
96
+ v.strictObject({
97
+ type: v.literal("bank_account"),
98
+ actions: actionSet(BANK_ACCOUNT_MANAGE_ACTIONS),
99
+ locations: AndcoRarLocationsSchema,
100
+ subject: SubjectPickerSchema,
101
+ accounts: aliasList,
102
+ }),
103
+ v.strictObject({
104
+ type: v.literal("bank_account"),
105
+ actions: actionSet(BANK_ACCOUNT_APPROVAL_ACTIONS),
106
+ locations: AndcoRarLocationsSchema,
107
+ subject: SubjectPickerSchema,
108
+ }),
109
+ ]);
110
+ /** `bank_account` Grant: the three forms with the subject resolved and `accounts` materialized. */
111
+ export const BankAccountGrantSchema = /* @__PURE__ */ v.union([
112
+ v.strictObject({
113
+ type: v.literal("bank_account"),
114
+ actions: actionSet(BANK_ACCOUNT_READ_ACTIONS),
115
+ locations: AndcoRarLocationsSchema,
116
+ subject: GrantedSubjectSchema,
117
+ accounts: grantedOwnList,
118
+ }),
119
+ v.strictObject({
120
+ type: v.literal("bank_account"),
121
+ actions: actionSet(BANK_ACCOUNT_MANAGE_ACTIONS),
122
+ locations: AndcoRarLocationsSchema,
123
+ subject: GrantedSubjectSchema,
124
+ accounts: grantedAliasList,
125
+ }),
126
+ v.strictObject({
127
+ type: v.literal("bank_account"),
128
+ actions: actionSet(BANK_ACCOUNT_APPROVAL_ACTIONS),
129
+ locations: AndcoRarLocationsSchema,
130
+ subject: GrantedSubjectSchema,
131
+ }),
132
+ ]);
133
+ // -- bank_transaction ---------------------------------------------------------------------------
134
+ /**
135
+ * `bank_transaction` Grant Request: read the Transactions of `accounts` (absent means every own
136
+ * account).
137
+ *
138
+ * @example
139
+ * const statement: BankTransactionGrantRequest = {
140
+ * type: "bank_transaction",
141
+ * actions: ["read"],
142
+ * locations: ["https://api.andco.com"],
143
+ * subject: { type: "profile" },
144
+ * accounts: [{ type: "any", limit: "own" }],
145
+ * };
146
+ */
147
+ export const BankTransactionGrantRequestSchema = /* @__PURE__ */ v.strictObject({
148
+ type: v.literal("bank_transaction"),
149
+ actions: actionSet(BANK_TRANSACTION_ACTIONS),
150
+ locations: AndcoRarLocationsSchema,
151
+ subject: SubjectPickerSchema,
152
+ accounts: v.nullish(ownList),
153
+ });
154
+ /** `bank_transaction` Grant. */
155
+ export const BankTransactionGrantSchema = /* @__PURE__ */ v.strictObject({
156
+ type: v.literal("bank_transaction"),
157
+ actions: actionSet(BANK_TRANSACTION_ACTIONS),
158
+ locations: AndcoRarLocationsSchema,
159
+ subject: GrantedSubjectSchema,
160
+ accounts: grantedOwnList,
161
+ });
162
+ // -- bank_transfer ------------------------------------------------------------------------------
163
+ /**
164
+ * `bank_transfer` Grant Request, create form: propose Transfers within explicit bounds.
165
+ *
166
+ * `sources` only takes own matchers (absent means any own account); `destinations` takes every
167
+ * matcher (absent means any account, other banks included). `currency` is required. `budgets` is
168
+ * reserved and must be absent or `null`.
169
+ *
170
+ * @example
171
+ * const propose: BankTransferCreateGrantRequest = {
172
+ * type: "bank_transfer",
173
+ * actions: ["create"],
174
+ * locations: ["https://api.andco.com"],
175
+ * subject: { type: "organization" },
176
+ * sources: [{ type: "alias", pattern: "caja-*", editable: true }],
177
+ * destinations: [{ type: "alias", pattern: "proveedores" }, { type: "external", bank_id: "banco_de_chile" }],
178
+ * currency: "CLP",
179
+ * transactions: { minimum: "1000", maximum: "5000000", editable: true },
180
+ * budgets: null,
181
+ * };
182
+ */
183
+ export const BankTransferCreateGrantRequestSchema = /* @__PURE__ */ v.strictObject({
184
+ type: v.literal("bank_transfer"),
185
+ actions: actionSet(BANK_TRANSFER_CREATE_ACTIONS),
186
+ locations: AndcoRarLocationsSchema,
187
+ subject: SubjectPickerSchema,
188
+ sources: v.nullish(ownList),
189
+ destinations: v.nullish(destinationList),
190
+ currency,
191
+ transactions: v.nullish(TransferLimitsRequestSchema),
192
+ budgets: v.optional(v.null()),
193
+ });
194
+ /**
195
+ * `bank_transfer` Grant Request, approval form: approve or reject Transfers someone else created, up
196
+ * to an optional amount.
197
+ *
198
+ * @example
199
+ * const approve: BankTransferApprovalGrantRequest = {
200
+ * type: "bank_transfer",
201
+ * actions: ["approve", "reject"],
202
+ * locations: ["https://api.andco.com"],
203
+ * subject: { type: "organization", identifier: "42" },
204
+ * transactions: { maximum: "10000000" },
205
+ * };
206
+ */
207
+ export const BankTransferApprovalGrantRequestSchema = /* @__PURE__ */ v.strictObject({
208
+ type: v.literal("bank_transfer"),
209
+ actions: actionSet(BANK_TRANSFER_APPROVAL_ACTIONS),
210
+ locations: AndcoRarLocationsSchema,
211
+ subject: SubjectPickerSchema,
212
+ transactions: v.nullish(ApprovalLimitsRequestSchema),
213
+ });
214
+ /** `bank_transfer` Grant Request: the create form or the approval form, never both in one detail. */
215
+ export const BankTransferGrantRequestSchema = /* @__PURE__ */ v.union([
216
+ BankTransferCreateGrantRequestSchema,
217
+ BankTransferApprovalGrantRequestSchema,
218
+ ]);
219
+ /** `bank_transfer` Grant, create form: sources and destinations materialized, no `budgets`. */
220
+ export const BankTransferCreateGrantSchema = /* @__PURE__ */ v.strictObject({
221
+ type: v.literal("bank_transfer"),
222
+ actions: actionSet(BANK_TRANSFER_CREATE_ACTIONS),
223
+ locations: AndcoRarLocationsSchema,
224
+ subject: GrantedSubjectSchema,
225
+ sources: grantedOwnList,
226
+ destinations: grantedDestinationList,
227
+ currency,
228
+ transactions: v.optional(TransferLimitsGrantSchema),
229
+ });
230
+ /** `bank_transfer` Grant, approval form. Absent `transactions` means no bound. */
231
+ export const BankTransferApprovalGrantSchema = /* @__PURE__ */ v.strictObject({
232
+ type: v.literal("bank_transfer"),
233
+ actions: actionSet(BANK_TRANSFER_APPROVAL_ACTIONS),
234
+ locations: AndcoRarLocationsSchema,
235
+ subject: GrantedSubjectSchema,
236
+ transactions: v.optional(ApprovalLimitsGrantSchema),
237
+ });
238
+ /** `bank_transfer` Grant. */
239
+ export const BankTransferGrantSchema = /* @__PURE__ */ v.union([
240
+ BankTransferCreateGrantSchema,
241
+ BankTransferApprovalGrantSchema,
242
+ ]);
243
+ // -- bank_deposit -------------------------------------------------------------------------------
244
+ /**
245
+ * `bank_deposit` Grant Request: collect money into `destinations`, which is required and only takes
246
+ * own matchers.
247
+ *
248
+ * @example
249
+ * const collect: BankDepositGrantRequest = {
250
+ * type: "bank_deposit",
251
+ * actions: ["create", "read", "close"],
252
+ * locations: ["https://api.andco.com"],
253
+ * subject: { type: "organization" },
254
+ * destinations: [{ type: "alias", pattern: "ventas" }],
255
+ * };
256
+ */
257
+ export const BankDepositGrantRequestSchema = /* @__PURE__ */ v.strictObject({
258
+ type: v.literal("bank_deposit"),
259
+ actions: actionSet(BANK_DEPOSIT_ACTIONS),
260
+ locations: AndcoRarLocationsSchema,
261
+ subject: SubjectPickerSchema,
262
+ destinations: ownList,
263
+ });
264
+ /** `bank_deposit` Grant. */
265
+ export const BankDepositGrantSchema = /* @__PURE__ */ v.strictObject({
266
+ type: v.literal("bank_deposit"),
267
+ actions: actionSet(BANK_DEPOSIT_ACTIONS),
268
+ locations: AndcoRarLocationsSchema,
269
+ subject: GrantedSubjectSchema,
270
+ destinations: grantedOwnList,
271
+ });
272
+ // -- JSON Schema mirrors ------------------------------------------------------------------------
273
+ //
274
+ // Written by hand, like every catalog mirror: `@valibot/to-json-schema` drops `v.check(...)`
275
+ // silently. What JSON Schema cannot say is enforced by valibot and by the gate's SQL: a `minimum`
276
+ // above its `maximum`, uniqueness of matchers that differ only by `editable` or an omitted alias
277
+ // `type`, and that an `account` source belongs to the subject.
278
+ const limitJson = { type: "string", pattern: TRANSACTION_LIMIT_PATTERN };
279
+ const currencyJson = { enum: [...BANK_CURRENCIES] };
280
+ const ownListJson = accountMatcherListJsonSchema(OWN_ACCOUNT_MATCHER_JSON_SCHEMA);
281
+ const destinationListJson = accountMatcherListJsonSchema(DESTINATION_ACCOUNT_MATCHER_JSON_SCHEMA);
282
+ const grantedOwnListJson = accountMatcherListJsonSchema(GRANTED_OWN_ACCOUNT_MATCHER_JSON_SCHEMA);
283
+ const grantedDestinationListJson = accountMatcherListJsonSchema(GRANTED_DESTINATION_ACCOUNT_MATCHER_JSON_SCHEMA);
284
+ const aliasListJson = accountMatcherListJsonSchema({
285
+ type: "object",
286
+ additionalProperties: false,
287
+ required: ["pattern"],
288
+ properties: {
289
+ type: nullableJson({ const: "alias" }),
290
+ pattern: { type: "string", pattern: ACCOUNT_ALIAS_PATTERN_SYNTAX },
291
+ editable: nullableJson({ type: "boolean" }),
292
+ },
293
+ });
294
+ const grantedAliasListJson = accountMatcherListJsonSchema({
295
+ type: "object",
296
+ additionalProperties: false,
297
+ required: ["type", "pattern"],
298
+ properties: { type: { const: "alias" }, pattern: { type: "string", pattern: ACCOUNT_ALIAS_PATTERN_SYNTAX } },
299
+ });
300
+ const transferLimitsRequestJson = nullableJson({
301
+ type: "object",
302
+ additionalProperties: false,
303
+ properties: {
304
+ value: nullableJson(limitJson),
305
+ minimum: nullableJson(limitJson),
306
+ maximum: nullableJson(limitJson),
307
+ editable: nullableJson({ type: "boolean" }),
308
+ },
309
+ if: { required: ["value"], properties: { value: { type: "string" } } },
310
+ // biome-ignore lint/suspicious/noThenProperty: JSON Schema draft-07 `if`/`then`, never awaited.
311
+ then: { properties: { minimum: { type: "null" }, maximum: { type: "null" } } },
312
+ });
313
+ const transferLimitsGrantJson = {
314
+ type: "object",
315
+ additionalProperties: false,
316
+ properties: { value: limitJson, minimum: limitJson, maximum: limitJson },
317
+ not: { anyOf: [{ required: ["value", "minimum"] }, { required: ["value", "maximum"] }] },
318
+ };
319
+ const approvalLimitsRequestJson = nullableJson({
320
+ type: "object",
321
+ additionalProperties: false,
322
+ properties: { minimum: nullableJson(limitJson), maximum: nullableJson(limitJson) },
323
+ });
324
+ const approvalLimitsGrantJson = {
325
+ type: "object",
326
+ additionalProperties: false,
327
+ properties: { minimum: limitJson, maximum: limitJson },
328
+ };
329
+ /** JSON Schema mirror of {@link BankAccountGrantRequestSchema}. */
330
+ export const BANK_ACCOUNT_GRANT_REQUEST_JSON_SCHEMA = /* @__PURE__ */ detailTypeJson([
331
+ detailFormJson("bank_account", actionSetJson(BANK_ACCOUNT_READ_ACTIONS), { subject: SUBJECT_PICKER_JSON_SCHEMA, accounts: nullableJson(ownListJson) }, []),
332
+ detailFormJson("bank_account", actionSetJson(BANK_ACCOUNT_MANAGE_ACTIONS), { subject: SUBJECT_PICKER_JSON_SCHEMA, accounts: aliasListJson }, ["accounts"]),
333
+ detailFormJson("bank_account", actionSetJson(BANK_ACCOUNT_APPROVAL_ACTIONS), { subject: SUBJECT_PICKER_JSON_SCHEMA }, []),
334
+ ]);
335
+ /** JSON Schema mirror of {@link BankAccountGrantSchema}. */
336
+ export const BANK_ACCOUNT_GRANT_JSON_SCHEMA = /* @__PURE__ */ detailTypeJson([
337
+ detailFormJson("bank_account", actionSetJson(BANK_ACCOUNT_READ_ACTIONS), { subject: GRANTED_SUBJECT_JSON_SCHEMA, accounts: grantedOwnListJson }, ["subject", "accounts"]),
338
+ detailFormJson("bank_account", actionSetJson(BANK_ACCOUNT_MANAGE_ACTIONS), { subject: GRANTED_SUBJECT_JSON_SCHEMA, accounts: grantedAliasListJson }, ["subject", "accounts"]),
339
+ detailFormJson("bank_account", actionSetJson(BANK_ACCOUNT_APPROVAL_ACTIONS), { subject: GRANTED_SUBJECT_JSON_SCHEMA }, ["subject"]),
340
+ ]);
341
+ /** JSON Schema mirror of {@link BankTransactionGrantRequestSchema}. */
342
+ export const BANK_TRANSACTION_GRANT_REQUEST_JSON_SCHEMA = /* @__PURE__ */ detailTypeJson([
343
+ detailFormJson("bank_transaction", actionSetJson(BANK_TRANSACTION_ACTIONS), { subject: SUBJECT_PICKER_JSON_SCHEMA, accounts: nullableJson(ownListJson) }, []),
344
+ ]);
345
+ /** JSON Schema mirror of {@link BankTransactionGrantSchema}. */
346
+ export const BANK_TRANSACTION_GRANT_JSON_SCHEMA = /* @__PURE__ */ detailTypeJson([
347
+ detailFormJson("bank_transaction", actionSetJson(BANK_TRANSACTION_ACTIONS), { subject: GRANTED_SUBJECT_JSON_SCHEMA, accounts: grantedOwnListJson }, ["subject", "accounts"]),
348
+ ]);
349
+ /** JSON Schema mirror of {@link BankTransferGrantRequestSchema}. */
350
+ export const BANK_TRANSFER_GRANT_REQUEST_JSON_SCHEMA = /* @__PURE__ */ detailTypeJson([
351
+ detailFormJson("bank_transfer", actionSetJson(BANK_TRANSFER_CREATE_ACTIONS), {
352
+ subject: SUBJECT_PICKER_JSON_SCHEMA,
353
+ sources: nullableJson(ownListJson),
354
+ destinations: nullableJson(destinationListJson),
355
+ currency: currencyJson,
356
+ transactions: transferLimitsRequestJson,
357
+ budgets: { type: "null" },
358
+ }, ["currency"]),
359
+ detailFormJson("bank_transfer", actionSetJson(BANK_TRANSFER_APPROVAL_ACTIONS), { subject: SUBJECT_PICKER_JSON_SCHEMA, transactions: approvalLimitsRequestJson }, []),
360
+ ]);
361
+ /** JSON Schema mirror of {@link BankTransferGrantSchema}. */
362
+ export const BANK_TRANSFER_GRANT_JSON_SCHEMA = /* @__PURE__ */ detailTypeJson([
363
+ detailFormJson("bank_transfer", actionSetJson(BANK_TRANSFER_CREATE_ACTIONS), {
364
+ subject: GRANTED_SUBJECT_JSON_SCHEMA,
365
+ sources: grantedOwnListJson,
366
+ destinations: grantedDestinationListJson,
367
+ currency: currencyJson,
368
+ transactions: transferLimitsGrantJson,
369
+ }, ["subject", "sources", "destinations", "currency"]),
370
+ detailFormJson("bank_transfer", actionSetJson(BANK_TRANSFER_APPROVAL_ACTIONS), { subject: GRANTED_SUBJECT_JSON_SCHEMA, transactions: approvalLimitsGrantJson }, ["subject"]),
371
+ ]);
372
+ /** JSON Schema mirror of {@link BankDepositGrantRequestSchema}. */
373
+ export const BANK_DEPOSIT_GRANT_REQUEST_JSON_SCHEMA = /* @__PURE__ */ detailTypeJson([
374
+ detailFormJson("bank_deposit", actionSetJson(BANK_DEPOSIT_ACTIONS), { subject: SUBJECT_PICKER_JSON_SCHEMA, destinations: ownListJson }, ["destinations"]),
375
+ ]);
376
+ /** JSON Schema mirror of {@link BankDepositGrantSchema}. */
377
+ export const BANK_DEPOSIT_GRANT_JSON_SCHEMA = /* @__PURE__ */ detailTypeJson([
378
+ detailFormJson("bank_deposit", actionSetJson(BANK_DEPOSIT_ACTIONS), { subject: GRANTED_SUBJECT_JSON_SCHEMA, destinations: grantedOwnListJson }, ["subject", "destinations"]),
379
+ ]);