@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
@@ -1 +1 @@
1
- {"version":3,"file":"intent-input.d.ts","sourceRoot":"","sources":["../src/intent-input.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAsB7B,gFAAgF;AAChF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAOvD;AAED,6GAA6G;AAC7G,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CASvD;AAkBD,+GAA+G;AAC/G,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAEnD;AAED,2GAA2G;AAC3G,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAShF;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;aAOrC,CAAC;AAEH,gGAAgG;AAChG,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,OAAO;;;;;;;;;;;;;eAE3D"}
@@ -1,19 +1,103 @@
1
1
  import * as v from "valibot";
2
+ import { ANDCO_API_ORIGIN } from "./constants.js";
3
+ import { AccountAliasSchema } from "./rar/account-matchers.js";
4
+ import { MoneySchema } from "./rar/money.js";
2
5
  const text = (max) => v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(max));
3
6
  const accountId = /* @__PURE__ */ v.pipe(v.string(), v.uuid());
4
- const bankAccount = {
5
- account_holder_id: text(64),
6
- account_holder_name: text(256),
7
- account_kind: v.picklist(["checking", "debit", "savings"]),
8
- account_number: text(64),
9
- bank_id: v.pipe(v.string(), v.regex(/^[a-z0-9][a-z0-9_-]{0,63}$/)),
10
- country: v.literal("CL"),
11
- };
12
- const amount = {
7
+ // The regex ceiling of `MoneySchema` (15 digits) already keeps `Number(value)` inside
8
+ // `Number.isSafeInteger` range, so this check can no longer reject anything the regex accepts.
9
+ // Kept anyway as cheap defense in depth: valibot is the only gate this scalar passes through here
10
+ // (unlike the JSON Schema mirrors of the RAR types, which have nowhere to hang a numeric check),
11
+ // so a future edit to the regex that reintroduces the gap fails safely at this check instead of
12
+ // silently shipping an unsafe integer.
13
+ const amountValue = /* @__PURE__ */ v.pipe(MoneySchema, v.check((value) => Number.isSafeInteger(Number(value))));
14
+ /**
15
+ * The amount a deposit asks for: `value` is the number, and `editable: true` lets the payer change
16
+ * it on the screen. It is never what moved; an answered Intent says that apart (`progress.credited`).
17
+ *
18
+ * @example
19
+ * const amount = { currency: "CLP", value: "40000", editable: true };
20
+ */
21
+ const depositAmount = {
13
22
  currency: v.literal("CLP"),
23
+ value: amountValue,
14
24
  editable: v.optional(v.boolean(), false),
15
- suggested: v.pipe(v.string(), v.regex(/^[1-9][0-9]{0,15}$/), v.check((value) => Number.isSafeInteger(Number(value)))),
16
25
  };
26
+ /**
27
+ * The amount a transfer proposes. `editable` only accepts `false`: the confirmation screen cannot
28
+ * change what a transfer moves yet (TODO), so asking for an editable amount is an
29
+ * `invalid_request` at creation instead of an Intent nobody can confirm. What moved is `settled`.
30
+ *
31
+ * @example
32
+ * const amount = { currency: "CLP", value: "40000" };
33
+ */
34
+ const transferAmount = {
35
+ currency: v.literal("CLP"),
36
+ value: amountValue,
37
+ editable: v.optional(v.literal(false), false),
38
+ };
39
+ /**
40
+ * The amount a Signed Instruction orders: the same `{ currency, value }` as a request, with nothing
41
+ * left for a person to change, so there is no `editable`.
42
+ */
43
+ const signedAmount = { currency: v.literal("CLP"), value: amountValue };
44
+ /** A note's text: trimmed, and at most 140 Unicode code points, the way PostgreSQL counts them. */
45
+ const noteText = /* @__PURE__ */ v.pipe(v.string(), v.trim(), v.check((value) => [...value].length <= 140, "note_too_long"));
46
+ /**
47
+ * The account a transfer names, in the vocabulary of the `bank_transfer` matchers it has to fit:
48
+ * `{ type: "alias", alias }` and `{ type: "account", id }` name one Andco account, and
49
+ * `{ type: "external", ... }` names one account at another Chilean bank with every field the
50
+ * `external` matcher can fix. A transfer names exactly one account, so nothing here is a pattern.
51
+ *
52
+ * @example
53
+ * const source: TransferAccount = { type: "alias", alias: "caja-santiago" };
54
+ * const payroll: TransferAccount = {
55
+ * type: "external", bank_id: "banco_de_chile", account_type: "checking", account_id: "1234567890",
56
+ * holder_id: "12345678-5", holder_name: "Ada Lovelace",
57
+ * };
58
+ */
59
+ const transferAlias = { type: /* @__PURE__ */ v.literal("alias"), alias: AccountAliasSchema };
60
+ const transferAccount = { type: /* @__PURE__ */ v.literal("account"), id: accountId };
61
+ const transferExternal = {
62
+ type: /* @__PURE__ */ v.literal("external"),
63
+ bank_id: /* @__PURE__ */ v.pipe(v.string(), v.regex(/^[a-z0-9][a-z0-9_-]{0,63}$/)),
64
+ account_type: /* @__PURE__ */ v.picklist(["checking", "debit", "savings"]),
65
+ account_id: text(64),
66
+ holder_id: text(64),
67
+ holder_name: text(256),
68
+ };
69
+ /**
70
+ * One Andco account of the Grant's subject, named by Account Alias or by identifier: where a
71
+ * transfer's money leaves from, where a deposit lands, and the account a closure closes.
72
+ *
73
+ * @example
74
+ * const account: IntentAccount = { type: "alias", alias: "ventas" };
75
+ */
76
+ const andcoAccount = /* @__PURE__ */ v.variant("type", [
77
+ v.strictObject(transferAlias),
78
+ v.strictObject(transferAccount),
79
+ ]);
80
+ /** Where a transfer's money leaves from: always an Andco account of the Grant's subject. */
81
+ const transferSource = andcoAccount;
82
+ /** Where a signed transfer's money lands: nothing on this path is left for a person to complete. */
83
+ const signedTransferDestination = /* @__PURE__ */ v.variant("type", [
84
+ v.strictObject(transferAlias),
85
+ v.strictObject(transferAccount),
86
+ v.strictObject(transferExternal),
87
+ ]);
88
+ /**
89
+ * Where a proposed transfer's money lands, always locked on the confirmation screen. `editable`
90
+ * only accepts `false`: redirecting a transfer at confirmation is not implemented yet (TODO), so
91
+ * `editable: true` is an `invalid_request` at creation instead of an Intent nobody can confirm.
92
+ */
93
+ const lockedDestination = { editable: /* @__PURE__ */ v.optional(v.literal(false), false) };
94
+ const proposedTransferDestination = /* @__PURE__ */ v.variant("type", [
95
+ v.strictObject({ ...transferAlias, ...lockedDestination }),
96
+ v.strictObject({ ...transferAccount, ...lockedDestination }),
97
+ v.strictObject({ ...transferExternal, ...lockedDestination }),
98
+ ]);
99
+ /** The display label a Cuenta Vista is opened with. Mutable afterwards, and read by no permission. */
100
+ const accountName = /* @__PURE__ */ v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(80));
17
101
  /** Validates fixed-duration syntax without anchoring it to a changing clock. */
18
102
  export function isIntentDuration(value) {
19
103
  const match = /^([1-9][0-9]*)\s+(seconds?|minutes?|hours?|days?)$/.exec(value.trim());
@@ -34,68 +118,228 @@ export function isIntentDeadline(value) {
34
118
  Number.isFinite(midnight.getTime()) &&
35
119
  midnight.toISOString().slice(0, 10) === date);
36
120
  }
121
+ const expiresIn = /* @__PURE__ */ v.pipe(v.string(), v.check(isIntentDuration, "invalid_expiration_interval"));
122
+ const expiresAt = /* @__PURE__ */ v.pipe(v.string(), v.check(isIntentDeadline, "invalid_expiration_datetime"));
37
123
  const common = {
38
- expires_in: v.optional(v.pipe(v.string(), v.check(isIntentDuration, "invalid_expiration_interval"))),
39
- expires_at: v.optional(v.pipe(v.string(), v.check(isIntentDeadline, "invalid_expiration_datetime"))),
40
- note: v.optional(v.strictObject({
41
- suggested: v.pipe(v.string(), v.trim(), v.check((value) => [...value].length <= 140, "note_too_long")),
42
- editable: v.optional(v.boolean(), false),
43
- })),
124
+ expires_in: v.optional(expiresIn),
125
+ expires_at: v.optional(expiresAt),
126
+ note: v.optional(v.strictObject({ value: noteText, editable: v.optional(v.boolean(), false) })),
44
127
  metadata: v.optional(v.record(v.string(), v.unknown()), {}),
45
128
  };
46
- /** Public creation validation shared by the API and SDK. SQL resolves deadlines and enforces authorization. */
129
+ /**
130
+ * Public creation validation shared by the API and SDK. SQL resolves deadlines and enforces authorization.
131
+ *
132
+ * This is the `application/json` half of the creation contract: an Intent born waiting for an
133
+ * Approval, where a `null` means a person will choose. The `application/jwt` half is
134
+ * {@link SignedIntentSchema}, and the two are separate schemas rather than one with optional fields
135
+ * on purpose — when signed and unsigned members share an object, something eventually reads the
136
+ * wrong ones.
137
+ *
138
+ * `transfer` is the only way money movement is expressed: money leaving an account towards a
139
+ * `destination`, both named in the `bank_transfer` matcher vocabulary (`alias`, `account`,
140
+ * `external`). A null `source` is the confirmation screen's source picker; the amount and the
141
+ * destination are always locked there (`editable: true` is refused). Who may approve the Intent without a person belongs to the Grant, never to
142
+ * the operation itself.
143
+ *
144
+ * @example
145
+ * safeParseIntentCreate({
146
+ * type: "transfer", expires_in: "30 minutes", source: null,
147
+ * destination: { type: "alias", alias: "proveedores" },
148
+ * amount: { currency: "CLP", value: "40000" },
149
+ * note: { value: "Factura 42", editable: true },
150
+ * });
151
+ *
152
+ * `account_opening` is here for the same reason money movement is: everything with banking
153
+ * consequence happens through an Intent, so `/accounts` has no `POST`. It carries no amount, no
154
+ * source and no destination — only the name the account will answer to, and whether naming one that
155
+ * already exists is an error or a request for the account that is already there.
156
+ */
47
157
  export const IntentCreateSchema = /* @__PURE__ */ v.pipe(v.variant("type", [
48
158
  v.strictObject({
49
159
  ...common,
50
160
  type: v.literal("deposit"),
51
- amount: v.optional(v.strictObject(amount)),
52
- expires_at: v.optional(v.nullable(v.pipe(v.string(), v.check(isIntentDeadline, "invalid_expiration_datetime")))),
161
+ destination: v.optional(andcoAccount),
162
+ amount: v.optional(v.strictObject(depositAmount)),
163
+ expires_at: v.optional(v.nullable(expiresAt)),
53
164
  }),
54
165
  v.strictObject({
55
166
  ...common,
56
- type: v.literal("withdrawal"),
57
- amount: v.strictObject(amount),
58
- source: v.optional(v.nullable(v.union([v.strictObject({ bank_account_id: accountId }), v.strictObject(bankAccount)])), null),
59
- beneficiary: v.union([
60
- v.strictObject({ ...bankAccount, editable: v.optional(v.boolean(), false) }),
61
- v.strictObject({ bank_account_id: accountId, editable: v.optional(v.literal(false), false) }),
62
- ]),
167
+ type: v.literal("transfer"),
168
+ amount: v.strictObject(transferAmount),
169
+ // Null or omitted: the person picks among the Grant's sources on the confirmation screen.
170
+ source: v.optional(v.nullable(transferSource), null),
171
+ destination: proposedTransferDestination,
63
172
  }),
64
173
  v.strictObject({
65
174
  ...common,
66
- type: v.literal("automatic_charge"),
67
- amount: v.strictObject({ ...amount, editable: v.optional(v.literal(false), false) }),
68
- source: v.optional(v.nullable(v.strictObject({ bank_account_id: accountId })), null),
69
- beneficiary: v.strictObject({ bank_account_id: accountId }),
175
+ type: v.literal("account_opening"),
176
+ // The holder's own name for the account, unique per subject (ADR 0028) and never reused once
177
+ // the account closes.
178
+ alias: AccountAliasSchema,
179
+ name: v.optional(accountName),
180
+ upsert: v.optional(v.boolean(), false),
181
+ }),
182
+ v.strictObject({
183
+ ...common,
184
+ type: v.literal("account_closure"),
185
+ account: andcoAccount,
70
186
  }),
71
187
  ]), v.check((input) => (input.expires_in !== undefined) !== (input.expires_at !== undefined), "exactly_one_expiration_required"), v.check((input) => input.expires_at !== null || (input.type === "deposit" && input.amount === undefined), "passive_deposit_requires_no_target"), v.check((input) => JSON.stringify(input.metadata).length <= 16384, "metadata_too_large"));
72
188
  /** Returns validation issues without throwing across the HTTP boundary. */
73
189
  export function safeParseIntentCreate(input) {
74
190
  return v.safeParse(IntentCreateSchema, input);
75
191
  }
192
+ /**
193
+ * The verified claims of a Signed Instruction: the `application/jwt` half of the same creation.
194
+ *
195
+ * Nothing here is optional that the transfer needs and nothing here is editable. An instruction that
196
+ * does not say where the money comes from or where it goes is not signable, so `source` and
197
+ * `destination` are required and the amount carries no `editable`. `note` is a plain reference for
198
+ * the same reason: there is no screen on this path, so there is nobody to propose it to.
199
+ *
200
+ * There is no `org_id`: the subject is the one of the Grant behind the access token that submits the
201
+ * instruction, and nothing inside the signature may name another.
202
+ *
203
+ * The expiration is present on this side too, and it is not `exp`. `exp` bounds how long the
204
+ * instruction may be *submitted*; the Intent expiration bounds how long the Intent may be approved
205
+ * and executed. They are different deadlines, and because every value a signed transfer uses has to
206
+ * come from inside the signature, the second one cannot arrive in a header or a query string.
207
+ *
208
+ * `account_opening` is signed on the same terms, and `upsert` is the reason it matters here. The
209
+ * flag decides whether naming an Account Alias that already exists is a refusal or a request for the
210
+ * account already carrying it, which is a difference in what the instruction *orders*. Carried as a
211
+ * transport option — a header, a query parameter, a field beside the assertion — anybody holding the
212
+ * signed instruction could flip it, and the order executed would not be the order signed.
213
+ *
214
+ * @example
215
+ * const claims = safeParseSignedIntent(verification.claims);
216
+ * if (claims.success) console.log(claims.output.jti, claims.output.amount.value);
217
+ */
218
+ export const SignedIntentSchema = /* @__PURE__ */ v.pipe(v.variant("type", [
219
+ v.strictObject({
220
+ iss: text(64),
221
+ aud: v.literal(ANDCO_API_ORIGIN),
222
+ jti: text(128),
223
+ exp: v.pipe(v.number(), v.integer()),
224
+ iat: v.optional(v.pipe(v.number(), v.integer())),
225
+ nbf: v.optional(v.pipe(v.number(), v.integer())),
226
+ type: v.literal("transfer"),
227
+ source: transferSource,
228
+ destination: signedTransferDestination,
229
+ amount: v.strictObject(signedAmount),
230
+ expires_in: v.optional(expiresIn),
231
+ expires_at: v.optional(expiresAt),
232
+ note: v.optional(noteText),
233
+ metadata: v.optional(v.record(v.string(), v.unknown()), {}),
234
+ }),
235
+ v.strictObject({
236
+ iss: text(64),
237
+ aud: v.literal(ANDCO_API_ORIGIN),
238
+ jti: text(128),
239
+ exp: v.pipe(v.number(), v.integer()),
240
+ iat: v.optional(v.pipe(v.number(), v.integer())),
241
+ nbf: v.optional(v.pipe(v.number(), v.integer())),
242
+ type: v.literal("account_opening"),
243
+ alias: AccountAliasSchema,
244
+ name: v.optional(accountName),
245
+ // Inside the signature, never beside it: outside the claims anyone holding the assertion could
246
+ // turn "create this account" into "create it or hand me the one that is already there".
247
+ upsert: v.optional(v.boolean(), false),
248
+ expires_in: v.optional(expiresIn),
249
+ expires_at: v.optional(expiresAt),
250
+ metadata: v.optional(v.record(v.string(), v.unknown()), {}),
251
+ }),
252
+ v.strictObject({
253
+ iss: text(64),
254
+ aud: v.literal(ANDCO_API_ORIGIN),
255
+ jti: text(128),
256
+ exp: v.pipe(v.number(), v.integer()),
257
+ iat: v.optional(v.pipe(v.number(), v.integer())),
258
+ nbf: v.optional(v.pipe(v.number(), v.integer())),
259
+ type: v.literal("account_closure"),
260
+ // Required and never editable: an instruction that does not say which account it closes is
261
+ // not signable.
262
+ account: andcoAccount,
263
+ expires_in: v.optional(expiresIn),
264
+ expires_at: v.optional(expiresAt),
265
+ metadata: v.optional(v.record(v.string(), v.unknown()), {}),
266
+ }),
267
+ ]), v.check((input) => (input.expires_in !== undefined) !== (input.expires_at !== undefined), "exactly_one_expiration_required"), v.check((input) => JSON.stringify(input.metadata).length <= 16384, "metadata_too_large"));
268
+ const decisionReason = /* @__PURE__ */ v.pipe(v.string(), v.trim(), v.minLength(1), v.check((value) => [...value].length <= 280, "reason_too_long"));
269
+ /**
270
+ * Cancelling names why, because an Intent that vanished without a reason is an unexplained gap.
271
+ * A Cancellation is the creator withdrawing its own request: only the client that created the
272
+ * Intent may cancel it. An approver declining it is a Rejection ({@link IntentRejectionSchema}).
273
+ *
274
+ * @example
275
+ * safeParseIntentCancellation({ reason: "rejected_by_erp" });
276
+ */
277
+ export const IntentCancellationSchema = /* @__PURE__ */ v.strictObject({ reason: decisionReason });
278
+ /** Returns validation issues for a cancellation reason without throwing across the HTTP boundary. */
279
+ export function safeParseIntentCancellation(input) {
280
+ return v.safeParse(IntentCancellationSchema, input);
281
+ }
282
+ /**
283
+ * Rejecting names why. A Rejection is an approver declining an Intent with a Grant holding the
284
+ * family's `reject` action (`bank_transfer` for a transfer); the audit keeps it apart from a
285
+ * Cancellation, which is the creator withdrawing its own request.
286
+ *
287
+ * @example
288
+ * safeParseIntentRejection({ reason: "duplicated_invoice" });
289
+ */
290
+ export const IntentRejectionSchema = /* @__PURE__ */ v.strictObject({ reason: decisionReason });
291
+ /** Returns validation issues for a rejection reason without throwing across the HTTP boundary. */
292
+ export function safeParseIntentRejection(input) {
293
+ return v.safeParse(IntentRejectionSchema, input);
294
+ }
295
+ /**
296
+ * Error codes an Intent's Approval lifecycle answers with, beyond the generic transport codes.
297
+ *
298
+ * A cancellation or an approval may observe an Intent whose deadline to be approved and executed
299
+ * has already passed; `intent_expired` names that failure so a caller can distinguish it from an
300
+ * ordinary rejection.
301
+ */
302
+ export const ANDCO_INTENT_ERROR_CODES = {
303
+ /** The Intent's deadline to be approved and executed has already passed. */
304
+ INTENT_EXPIRED: "intent_expired",
305
+ };
306
+ /** Returns validation issues for the verified claims without throwing across the HTTP boundary. */
307
+ export function safeParseSignedIntent(input) {
308
+ return v.safeParse(SignedIntentSchema, input);
309
+ }
76
310
  /** Identifies recognized unsupported payment shapes without silently dropping their extra instructions. */
77
311
  export function unsupportedIntentPaymentShape(input) {
78
312
  if (!input || typeof input !== "object" || Array.isArray(input))
79
313
  return undefined;
80
314
  const record = input;
81
- if (!["deposit", "withdrawal", "automatic_charge"].includes(String(record["type"])))
315
+ if (!["deposit", "transfer"].includes(String(record["type"])))
82
316
  return undefined;
83
- if (Object.hasOwn(record, "beneficiaries") || Array.isArray(record["beneficiary"]))
84
- return "multiple_beneficiaries_not_implemented";
317
+ if (Object.hasOwn(record, "destinations") || Array.isArray(record["destination"]))
318
+ return "multiple_destinations_not_implemented";
85
319
  if (Object.hasOwn(record, "allocations") || Object.hasOwn(record, "split"))
86
320
  return "split_payments_not_implemented";
87
321
  if (Object.hasOwn(record, "instructions"))
88
322
  return "multiple_instructions_not_implemented";
89
323
  return undefined;
90
324
  }
91
- /** Values proposed by the account holder; the database enforces editability and freezes confirmation. */
92
- export const WithdrawalConfirmationSchema = /* @__PURE__ */ v.strictObject({
325
+ /**
326
+ * Values proposed by the account holder; the database enforces editability and freezes confirmation.
327
+ *
328
+ * Every member but `intent_id` is optional because nothing here is necessarily editable: a screen
329
+ * sends only what the Intent left open, and a value that was frozen has nowhere to arrive from.
330
+ * A transfer is created with its amount and destination locked (`editable: true` is refused at
331
+ * creation), so today `amount` and `destination` always meet `transfer_value_editing_not_implemented`;
332
+ * they stay in the shape for when confirmation-time editing exists.
333
+ */
334
+ export const TransferConfirmationSchema = /* @__PURE__ */ v.strictObject({
93
335
  intent_id: accountId,
94
336
  source_account_id: v.optional(accountId),
95
- amount: v.optional(amount.suggested),
96
- beneficiary: v.optional(v.strictObject(bankAccount)),
97
- note: v.optional(v.pipe(v.string(), v.trim(), v.check((value) => [...value].length <= 140, "note_too_long"))),
337
+ amount: v.optional(amountValue),
338
+ // Only another bank's account is ever editable, so a correction is always an `external` account.
339
+ destination: v.optional(v.strictObject(transferExternal)),
340
+ note: v.optional(noteText),
98
341
  });
99
- export function safeParseWithdrawalConfirmation(input) {
100
- return v.safeParse(WithdrawalConfirmationSchema, input);
342
+ /** Validates proposed confirmation fields without throwing; the server enforces editability. */
343
+ export function safeParseTransferConfirmation(input) {
344
+ return v.safeParse(TransferConfirmationSchema, input);
101
345
  }
@@ -1,9 +1,8 @@
1
1
  import * as v from "valibot";
2
- import { ANDCO_ERROR_CODES } from "../errors.js";
3
2
  export declare const AndCoErrorEventSchema: v.StrictObjectSchema<{
4
3
  readonly type: v.LiteralSchema<"error", undefined>;
5
4
  readonly error: v.StrictObjectSchema<{
6
- readonly code: v.PicklistSchema<[ANDCO_ERROR_CODES, ...ANDCO_ERROR_CODES[]], undefined>;
5
+ readonly code: v.PicklistSchema<readonly ["invalid_endpoint_auth", "invalid_auth_mode", "invalid_client_id", "invalid_redirect_to", "invalid_scope", "invalid_version", "unsupported_theme", "unsupported_theme_mode", "presentation_unsupported", "popup_blocked", "popup_navigation_failed", "popup_timeout", "handshake_timeout", "untrusted_origin", "unknown_error"], undefined>;
7
6
  }, undefined>;
8
7
  readonly protocol: v.LiteralSchema<"andco:sdk", undefined>;
9
8
  readonly version: v.LiteralSchema<2, undefined>;
@@ -1 +1 @@
1
- {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/messages/error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAOjD,eAAO,MAAM,qBAAqB;;;;;;;aAIhC,CAAC;AACH,gEAAgE;AAChE,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,qBAAqB,CAAC,CAAC"}
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/messages/error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAS7B,eAAO,MAAM,qBAAqB;;;;;;;aAIhC,CAAC;AACH,gEAAgE;AAChE,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,qBAAqB,CAAC,CAAC"}
@@ -1,7 +1,10 @@
1
1
  import * as v from "valibot";
2
- import { ANDCO_ERROR_CODES } from "../errors.js";
2
+ import { ANDCO_BRIDGE_ERROR_CODES } from "../errors.js";
3
3
  import { AndCoMessageBaseEntries } from "./base.js";
4
- const AndCoErrorCodeSchema = /* @__PURE__ */ v.picklist(Object.values(ANDCO_ERROR_CODES));
4
+ // Only what a widget can actually report, not the whole vocabulary: a host-page condition has no
5
+ // way to arrive from the iframe, and accepting one here would widen the wire to admit a message
6
+ // nothing can send. A refused code means a new producer appeared and belongs in the list.
7
+ const AndCoErrorCodeSchema = /* @__PURE__ */ v.picklist(ANDCO_BRIDGE_ERROR_CODES);
5
8
  export const AndCoErrorEventSchema = /* @__PURE__ */ v.strictObject({
6
9
  ...AndCoMessageBaseEntries,
7
10
  type: v.literal("error"),
@@ -18,7 +18,7 @@ export declare const AndCoBridgeMessageSchema: v.VariantSchema<"type", [v.Strict
18
18
  }, undefined>, v.StrictObjectSchema<{
19
19
  readonly type: v.LiteralSchema<"error", undefined>;
20
20
  readonly error: v.StrictObjectSchema<{
21
- readonly code: v.PicklistSchema<[import("../errors.js").ANDCO_ERROR_CODES, ...import("../errors.js").ANDCO_ERROR_CODES[]], undefined>;
21
+ readonly code: v.PicklistSchema<readonly ["invalid_endpoint_auth", "invalid_auth_mode", "invalid_client_id", "invalid_redirect_to", "invalid_scope", "invalid_version", "unsupported_theme", "unsupported_theme_mode", "presentation_unsupported", "popup_blocked", "popup_navigation_failed", "popup_timeout", "handshake_timeout", "untrusted_origin", "unknown_error"], undefined>;
22
22
  }, undefined>;
23
23
  readonly protocol: v.LiteralSchema<"andco:sdk", undefined>;
24
24
  readonly version: v.LiteralSchema<2, undefined>;
@@ -1,7 +1,28 @@
1
1
  /** Selects the supported language while preserving Platform's Spanish fallback. */
2
2
  export declare function ANDCO_NATIVE_LOCALE(language?: string): "es" | "en" | "pt";
3
3
  /** Formats CLP on Hermes without BigInt coercion or rounding unsafe integers. */
4
- export declare function ANDCO_NATIVE_MONEY(value: string, locale?: "en" | "es" | "pt"): string;
4
+ export declare function ANDCO_NATIVE_MONEY(value: string, locale?: "es" | "en" | "pt"): string;
5
+ /**
6
+ * Formats a monetary string Andco returned, in any currency and locale, guarding the same way
7
+ * {@link ANDCO_NATIVE_MONEY} does against a value that would silently lose precision going through
8
+ * `Number()`. Every consumer that renders an Andco balance or amount as a string -- example apps
9
+ * included -- should format through this function instead of re-implementing the guard, or skipping
10
+ * it, on its own.
11
+ */
12
+ export declare function ANDCO_FORMAT_MONEY(value: string, currency: string, locale?: string): string;
5
13
  /** Native equivalents of Platform's localized labels; server-owned resource descriptions remain unchanged. */
6
- export declare function ANDCO_NATIVE_TEXT(text: string, values?: Record<string, string | number>, locale?: "en" | "es" | "pt"): string;
14
+ export declare function ANDCO_NATIVE_TEXT(text: string, values?: Record<string, string | number>, locale?: "es" | "en" | "pt"): string;
15
+ /**
16
+ * Untranslated copy keys that vary only by Intent type, shared by every native renderer.
17
+ *
18
+ * Every consumer -- {@link ANDCO_NATIVE_INTENT_VIEW} and both platform Intent drawers -- reads this
19
+ * record instead of re-deriving the same three-way branch with its own chain of ternaries. Each
20
+ * value is a key into {@link ANDCO_NATIVE_TEXT}'s copy table, so callers still translate it with
21
+ * `ANDCO_NATIVE_TEXT(...)` at the point where it is rendered.
22
+ */
23
+ export declare const ANDCO_NATIVE_INTENT_TYPE_COPY: Record<"deposit" | "transfer", {
24
+ title: string;
25
+ amountLabel: string;
26
+ destinationLabel: string;
27
+ }>;
7
28
  //# sourceMappingURL=native-copy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"native-copy.d.ts","sourceRoot":"","sources":["../src/native-copy.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,wBAAgB,mBAAmB,CAAC,QAAQ,SAAiD,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAGjH;AACD,iFAAiF;AACjF,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAwB,UAQ/E;AAED,8GAA8G;AAC9G,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAM,EAC5C,MAAM,qBAAwB,UAK/B"}
1
+ {"version":3,"file":"native-copy.d.ts","sourceRoot":"","sources":["../src/native-copy.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,wBAAgB,mBAAmB,CAAC,QAAQ,SAAiD,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAGjH;AACD,iFAAiF;AACjF,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAwB,UAE/E;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAU,GAAG,MAAM,CAI5F;AAED,8GAA8G;AAC9G,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAM,EAC5C,MAAM,qBAAwB,UAK/B;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,6BAA6B,EAAE,MAAM,CAChD,SAAS,GAAG,UAAU,EACtB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAA;CAAE,CAYjE,CAAC"}