@andco/protocol 0.0.1 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +33 -3
- package/dist/api-errors.d.ts +109 -0
- package/dist/api-errors.d.ts.map +1 -0
- package/dist/api-errors.js +111 -0
- package/dist/authorization-preparation.d.ts +52 -543
- package/dist/authorization-preparation.d.ts.map +1 -1
- package/dist/authorization-preparation.js +19 -42
- package/dist/authorization.d.ts +64 -22
- package/dist/authorization.d.ts.map +1 -1
- package/dist/authorization.js +136 -55
- package/dist/consent.d.ts +5 -8
- package/dist/consent.d.ts.map +1 -1
- package/dist/consent.js +5 -62
- package/dist/constants.d.ts +19 -3
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +19 -3
- package/dist/errors.d.ts +156 -58
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +176 -57
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/intent-input.d.ts +1010 -279
- package/dist/intent-input.d.ts.map +1 -1
- package/dist/intent-input.js +268 -40
- package/dist/messages/error.d.ts +1 -2
- package/dist/messages/error.d.ts.map +1 -1
- package/dist/messages/error.js +5 -2
- package/dist/messages/index.d.ts +3 -3
- package/dist/messages/index.js +2 -2
- package/dist/messages/presentation-response.d.ts +20 -0
- package/dist/messages/presentation-response.d.ts.map +1 -0
- package/dist/messages/presentation-response.js +17 -0
- package/dist/native-copy.d.ts +23 -2
- package/dist/native-copy.d.ts.map +1 -1
- package/dist/native-copy.js +42 -98
- package/dist/native-intent.d.ts +126 -75
- package/dist/native-intent.d.ts.map +1 -1
- package/dist/native-intent.js +140 -48
- package/dist/rar/account-matchers.d.ts +579 -0
- package/dist/rar/account-matchers.d.ts.map +1 -0
- package/dist/rar/account-matchers.js +480 -0
- package/dist/rar/bank.d.ts +1549 -0
- package/dist/rar/bank.d.ts.map +1 -0
- package/dist/rar/bank.js +379 -0
- package/dist/rar/catalog.d.ts +1155 -0
- package/dist/rar/catalog.d.ts.map +1 -0
- package/dist/rar/catalog.js +175 -0
- package/dist/rar/detail.d.ts +39 -0
- package/dist/rar/detail.d.ts.map +1 -0
- package/dist/rar/detail.js +44 -0
- package/dist/rar/index.d.ts +9 -0
- package/dist/rar/index.d.ts.map +1 -0
- package/dist/rar/index.js +8 -0
- package/dist/rar/money.d.ts +58 -0
- package/dist/rar/money.d.ts.map +1 -0
- package/dist/rar/money.js +61 -0
- package/dist/rar/project-users.d.ts +43 -0
- package/dist/rar/project-users.d.ts.map +1 -0
- package/dist/rar/project-users.js +63 -0
- package/dist/rar/subject-data.d.ts +170 -0
- package/dist/rar/subject-data.d.ts.map +1 -0
- package/dist/rar/subject-data.js +127 -0
- package/dist/rar/subject.d.ts +166 -0
- package/dist/rar/subject.d.ts.map +1 -0
- package/dist/rar/subject.js +119 -0
- package/dist/scopes.d.ts +5 -30
- package/dist/scopes.d.ts.map +1 -1
- package/dist/scopes.js +0 -13
- package/dist/service-grants.d.ts +44 -0
- package/dist/service-grants.d.ts.map +1 -0
- package/dist/service-grants.js +45 -0
- package/dist/signing.d.ts +56 -0
- package/dist/signing.d.ts.map +1 -0
- package/dist/signing.js +233 -0
- package/dist/transport/financial-events.d.ts +90 -35
- package/dist/transport/financial-events.d.ts.map +1 -1
- package/dist/transport/financial-events.js +7 -1
- package/dist/transport/generated/oauth-api.d.ts +908 -440
- package/dist/transport/generated/oauth-api.d.ts.map +1 -1
- package/dist/transport/index.d.ts +0 -1
- package/dist/transport/index.d.ts.map +1 -1
- package/dist/transport/index.js +0 -1
- package/dist/transport/intents.d.ts +155 -23
- package/dist/transport/intents.d.ts.map +1 -1
- package/dist/transport/intents.js +192 -59
- package/dist/transport/rest.d.ts +18 -8
- package/dist/transport/rest.d.ts.map +1 -1
- package/dist/transport/rest.js +1 -1
- package/dist/urls.d.ts.map +1 -1
- package/dist/urls.js +1 -1
- package/dist/userinfo.d.ts +10 -1
- package/dist/userinfo.d.ts.map +1 -1
- package/dist/userinfo.js +10 -1
- package/dist/utils.d.ts +15 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +31 -0
- package/dist/webhooks.d.ts +154 -0
- package/dist/webhooks.d.ts.map +1 -0
- package/dist/webhooks.js +249 -0
- package/package.json +18 -1
- package/dist/automatic-charge.d.ts +0 -314
- package/dist/automatic-charge.d.ts.map +0 -1
- package/dist/automatic-charge.js +0 -126
- package/dist/bank-account-authorization.d.ts +0 -6
- package/dist/bank-account-authorization.d.ts.map +0 -1
- package/dist/bank-account-authorization.js +0 -13
- package/dist/messages/authorization-response.d.ts +0 -12
- package/dist/messages/authorization-response.d.ts.map +0 -1
- package/dist/messages/authorization-response.js +0 -9
- package/dist/transport/webhooks.d.ts +0 -27
- package/dist/transport/webhooks.d.ts.map +0 -1
- package/dist/transport/webhooks.js +0 -68
- package/dist/webhook-input.d.ts +0 -22
- package/dist/webhook-input.d.ts.map +0 -1
- package/dist/webhook-input.js +0 -11
- package/dist/webhook-signature.d.ts +0 -54
- package/dist/webhook-signature.d.ts.map +0 -1
- package/dist/webhook-signature.js +0 -74
package/dist/native-intent.js
CHANGED
|
@@ -1,17 +1,38 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
|
-
import {
|
|
3
|
-
import { ANDCO_NATIVE_TEXT as t } from "./native-copy.js";
|
|
2
|
+
import { TransferConfirmationSchema } from "./intent-input.js";
|
|
3
|
+
import { ANDCO_NATIVE_INTENT_TYPE_COPY, ANDCO_NATIVE_TEXT as t } from "./native-copy.js";
|
|
4
|
+
import { MONEY_PATTERN, MoneyOrZeroSchema } from "./rar/money.js";
|
|
4
5
|
import { SafeURL } from "./urls.js";
|
|
5
6
|
const text = /* @__PURE__ */ v.string();
|
|
6
|
-
|
|
7
|
+
// Every amount Platform presents here, credited totals and pending targets included, may
|
|
8
|
+
// legitimately be zero -- "no credited amount yet" is a real, tested state, not an error. Being
|
|
9
|
+
// permissive about zero where zero cannot occur costs nothing; being strict where it does occur
|
|
10
|
+
// would reject Platform's own output before it reaches the screen, which Platform treats as its own
|
|
11
|
+
// bug. The defect this scalar had to fix was the missing digit ceiling, not the admission of zero.
|
|
12
|
+
const money = MoneyOrZeroSchema;
|
|
13
|
+
// Amounts the native command channel transmits (never zero, matching the previous v.number()
|
|
14
|
+
// commands' v.minValue(1)) share the same digit ceiling as every other money value that travels
|
|
15
|
+
// through the protocol, instead of a second regex written by hand.
|
|
16
|
+
const transmittedAmount = /* @__PURE__ */ v.pipe(text, v.regex(new RegExp(MONEY_PATTERN)));
|
|
7
17
|
const uuid = /* @__PURE__ */ v.pipe(text, v.uuid());
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
18
|
+
const accountType = /* @__PURE__ */ v.picklist(["checking", "debit", "savings"]);
|
|
19
|
+
/** One Andco account, by Account Alias or by identifier, in the matcher vocabulary of a request. */
|
|
20
|
+
const aliasAccount = /* @__PURE__ */ v.object({ type: v.literal("alias"), alias: text });
|
|
21
|
+
const idAccount = /* @__PURE__ */ v.object({ type: v.literal("account"), id: uuid });
|
|
22
|
+
/**
|
|
23
|
+
* An account at another bank, the only destination a person may still correct on a screen.
|
|
24
|
+
*
|
|
25
|
+
* An Andco account named by Alias or identifier already denotes exactly one account, so there is
|
|
26
|
+
* nothing on the screen to correct: it is never editable.
|
|
27
|
+
*/
|
|
28
|
+
const editableDestination = /* @__PURE__ */ v.object({
|
|
29
|
+
type: v.literal("external"),
|
|
13
30
|
bank_id: text,
|
|
14
|
-
|
|
31
|
+
account_type: accountType,
|
|
32
|
+
account_id: text,
|
|
33
|
+
holder_id: text,
|
|
34
|
+
holder_name: text,
|
|
35
|
+
editable: v.boolean(),
|
|
15
36
|
});
|
|
16
37
|
const base = {
|
|
17
38
|
id: uuid,
|
|
@@ -27,11 +48,12 @@ const base = {
|
|
|
27
48
|
"failed",
|
|
28
49
|
"failed.insufficient_funds",
|
|
29
50
|
"cancelled",
|
|
51
|
+
"rejected",
|
|
30
52
|
"expired",
|
|
31
53
|
]),
|
|
32
|
-
amount: v.object({ currency: v.literal("CLP"),
|
|
54
|
+
amount: v.object({ currency: v.literal("CLP"), value: money, editable: v.boolean() }),
|
|
33
55
|
fee: v.object({ currency: v.literal("CLP"), amount: money }),
|
|
34
|
-
note: v.optional(v.object({
|
|
56
|
+
note: v.optional(v.object({ value: text, editable: v.boolean() })),
|
|
35
57
|
expires_at: v.nullable(text),
|
|
36
58
|
server_time: text,
|
|
37
59
|
can_confirm: v.boolean(),
|
|
@@ -44,7 +66,14 @@ export const AndCoNativeIntentPreparationSchema = /* @__PURE__ */ v.object({
|
|
|
44
66
|
...base,
|
|
45
67
|
type: v.literal("deposit"),
|
|
46
68
|
amount: v.nullable(v.object({ ...base.amount.entries, confirmed: v.nullable(money), frozen_at: v.nullable(text) })),
|
|
47
|
-
destination: v.object({
|
|
69
|
+
destination: v.object({
|
|
70
|
+
type: v.literal("account"),
|
|
71
|
+
id: uuid,
|
|
72
|
+
number: text,
|
|
73
|
+
account_type: accountType,
|
|
74
|
+
holder_id: v.nullable(text),
|
|
75
|
+
holder_name: text,
|
|
76
|
+
}),
|
|
48
77
|
progress: v.object({ credited: money, remaining: v.nullable(money) }),
|
|
49
78
|
closure: v.nullable(v.object({ closed_at: text, total: money })),
|
|
50
79
|
completion: v.nullable(v.object({ completed_at: text, total: money })),
|
|
@@ -61,11 +90,19 @@ export const AndCoNativeIntentPreparationSchema = /* @__PURE__ */ v.object({
|
|
|
61
90
|
currency: v.literal("CLP"),
|
|
62
91
|
})),
|
|
63
92
|
}),
|
|
93
|
+
// Money leaving an account towards a destination. `amount` is what the transfer orders and
|
|
94
|
+
// `settled` what it moved, null until it succeeded: a Host that reconciles reads `settled`.
|
|
64
95
|
v.object({
|
|
65
96
|
...base,
|
|
66
|
-
type: v.literal("
|
|
67
|
-
|
|
68
|
-
|
|
97
|
+
type: v.literal("transfer"),
|
|
98
|
+
settled: v.nullable(v.object({ currency: v.literal("CLP"), value: money, at: text })),
|
|
99
|
+
signed: v.boolean(),
|
|
100
|
+
destination: v.variant("type", [
|
|
101
|
+
v.object({ ...aliasAccount.entries, editable: v.literal(false) }),
|
|
102
|
+
v.object({ ...idAccount.entries, editable: v.literal(false) }),
|
|
103
|
+
editableDestination,
|
|
104
|
+
]),
|
|
105
|
+
source: v.nullable(v.variant("type", [aliasAccount, idAccount])),
|
|
69
106
|
}),
|
|
70
107
|
]),
|
|
71
108
|
sources: v.array(v.object({ id: uuid, number: text, name: v.nullable(text) })),
|
|
@@ -103,22 +140,26 @@ export const AndCoNativeIntentCommandSchema = /* @__PURE__ */ v.variant("action"
|
|
|
103
140
|
action: v.literal("fund_deposit"),
|
|
104
141
|
commandId: v.optional(uuid),
|
|
105
142
|
sourceAccountId: uuid,
|
|
106
|
-
amount:
|
|
143
|
+
amount: transmittedAmount,
|
|
107
144
|
note: v.optional(v.pipe(text, v.maxLength(140))),
|
|
108
145
|
}),
|
|
146
|
+
// One command confirms money movement, whichever of the two forms carries it: what the person
|
|
147
|
+
// decides -- which account it leaves from, how much, where it lands and under what reference -- is
|
|
148
|
+
// the same question in both. Its members are the confirmation schema's own, so a value that is not
|
|
149
|
+
// editable has no separate shape here to be injected through.
|
|
109
150
|
v.strictObject({
|
|
110
|
-
action: v.literal("
|
|
111
|
-
sourceAccountId:
|
|
112
|
-
amount:
|
|
113
|
-
|
|
114
|
-
note:
|
|
151
|
+
action: v.literal("confirm_transfer"),
|
|
152
|
+
sourceAccountId: TransferConfirmationSchema.entries.source_account_id,
|
|
153
|
+
amount: TransferConfirmationSchema.entries.amount,
|
|
154
|
+
destination: TransferConfirmationSchema.entries.destination,
|
|
155
|
+
note: TransferConfirmationSchema.entries.note,
|
|
115
156
|
}),
|
|
116
157
|
v.strictObject({ action: v.literal("fund_development_deposit") }),
|
|
117
158
|
v.strictObject({ action: v.literal("close_deposit") }),
|
|
118
159
|
v.strictObject({
|
|
119
160
|
action: v.literal("confirm_deposit_target"),
|
|
120
|
-
amount:
|
|
121
|
-
expectedTarget:
|
|
161
|
+
amount: transmittedAmount,
|
|
162
|
+
expectedTarget: transmittedAmount,
|
|
122
163
|
}),
|
|
123
164
|
v.strictObject({
|
|
124
165
|
action: v.literal("assign_deposit_credits"),
|
|
@@ -215,6 +256,7 @@ export class AndCoNativeIntentSession {
|
|
|
215
256
|
constructor(load) {
|
|
216
257
|
this.load = load;
|
|
217
258
|
}
|
|
259
|
+
/** Observes snapshot changes and returns a function that removes the listener. */
|
|
218
260
|
subscribe(listener) {
|
|
219
261
|
this.listeners.add(listener);
|
|
220
262
|
return () => {
|
|
@@ -228,6 +270,7 @@ export class AndCoNativeIntentSession {
|
|
|
228
270
|
for (const listener of this.listeners)
|
|
229
271
|
listener();
|
|
230
272
|
}
|
|
273
|
+
/** Refreshes the snapshot and starts polling; failures are exposed through `snapshot.error`. */
|
|
231
274
|
async refresh() {
|
|
232
275
|
if (this.disposed || this.snapshot.pending)
|
|
233
276
|
return;
|
|
@@ -256,6 +299,7 @@ export class AndCoNativeIntentSession {
|
|
|
256
299
|
this.reading = undefined;
|
|
257
300
|
}
|
|
258
301
|
}
|
|
302
|
+
/** Sends one command, retaining uncertain writes for a retry with the same command identity. */
|
|
259
303
|
async submit(command) {
|
|
260
304
|
if (this.disposed || this.snapshot.pending)
|
|
261
305
|
return;
|
|
@@ -280,7 +324,7 @@ export class AndCoNativeIntentSession {
|
|
|
280
324
|
...this.snapshot,
|
|
281
325
|
pending: false,
|
|
282
326
|
retryCommand: this.snapshot.retryCommand ??
|
|
283
|
-
((submitted.action === "fund_deposit" || submitted.action === "
|
|
327
|
+
((submitted.action === "fund_deposit" || submitted.action === "confirm_transfer") &&
|
|
284
328
|
!(error instanceof NativeIntentRequestError && error.status < 500)
|
|
285
329
|
? submitted
|
|
286
330
|
: undefined),
|
|
@@ -291,6 +335,7 @@ export class AndCoNativeIntentSession {
|
|
|
291
335
|
if (!this.disposed && !this.snapshot.error)
|
|
292
336
|
this.timer = setTimeout(() => void this.refresh(), 2000);
|
|
293
337
|
}
|
|
338
|
+
/** Stops polling and notifications without cancelling the financial operation. */
|
|
294
339
|
dispose() {
|
|
295
340
|
this.disposed = true;
|
|
296
341
|
clearTimeout(this.timer);
|
|
@@ -303,7 +348,7 @@ export function ANDCO_NATIVE_INTENT_VIEW(data, now = Date.now(), observedAt = no
|
|
|
303
348
|
const remaining = intent.expires_at === null
|
|
304
349
|
? null
|
|
305
350
|
: Math.max(0, Date.parse(intent.expires_at) - Date.parse(intent.server_time) - (now - observedAt));
|
|
306
|
-
const terminal = ["succeeded", "completed", "closed", "cancelled", "expired"].includes(intent.status) ||
|
|
351
|
+
const terminal = ["succeeded", "completed", "closed", "cancelled", "rejected", "expired"].includes(intent.status) ||
|
|
307
352
|
intent.status.startsWith("failed");
|
|
308
353
|
const expired = intent.status === "expired" || (intent.status === "requires_action" && remaining === 0);
|
|
309
354
|
const processing = intent.status.startsWith("processing.");
|
|
@@ -320,7 +365,7 @@ export function ANDCO_NATIVE_INTENT_VIEW(data, now = Date.now(), observedAt = no
|
|
|
320
365
|
(intent.type === "deposit" ||
|
|
321
366
|
(!processing && intent.can_confirm) ||
|
|
322
367
|
(intent.status === "processing.confirmed" && data.retryable)),
|
|
323
|
-
title: intent.type
|
|
368
|
+
title: t(ANDCO_NATIVE_INTENT_TYPE_COPY[intent.type].title),
|
|
324
369
|
status: ["succeeded", "completed"].includes(intent.status)
|
|
325
370
|
? t("Operación completada")
|
|
326
371
|
: expired
|
|
@@ -332,60 +377,107 @@ export function ANDCO_NATIVE_INTENT_VIEW(data, now = Date.now(), observedAt = no
|
|
|
332
377
|
: t("Revisa los datos antes de continuar"),
|
|
333
378
|
};
|
|
334
379
|
}
|
|
380
|
+
/**
|
|
381
|
+
* Where the money lands when it is another bank's account, or `null` when a screen cannot correct
|
|
382
|
+
* it: an Andco account named by Alias or identifier already denotes exactly one account.
|
|
383
|
+
*/
|
|
384
|
+
function proposedDestination(intent) {
|
|
385
|
+
if (intent.type === "transfer" && intent.destination.type === "external")
|
|
386
|
+
return intent.destination;
|
|
387
|
+
return null;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* The lines a native sheet shows for where the money lands, so both renderers read one answer: a
|
|
391
|
+
* deposit's account as a payer at another bank types it, a transfer's Andco account by Alias or by
|
|
392
|
+
* identifier, or another bank's account as the form holds it (a person's corrections included).
|
|
393
|
+
* `null` when the Intent names no destination.
|
|
394
|
+
*
|
|
395
|
+
* @example
|
|
396
|
+
* const lines = ANDCO_NATIVE_INTENT_DESTINATION_LINES(data, form); // ["Cuenta proveedores"]
|
|
397
|
+
*/
|
|
398
|
+
export function ANDCO_NATIVE_INTENT_DESTINATION_LINES(data, form, locale) {
|
|
399
|
+
const intent = data.intent;
|
|
400
|
+
const kind = (type) => t({ checking: "Corriente", debit: "Vista", savings: "Ahorro" }[type], {}, locale);
|
|
401
|
+
if (intent.type === "deposit") {
|
|
402
|
+
const account = intent.destination;
|
|
403
|
+
return [
|
|
404
|
+
account.holder_name,
|
|
405
|
+
...(account.holder_id ? [account.holder_id] : []),
|
|
406
|
+
"Andco",
|
|
407
|
+
`${kind(account.account_type)} · ${account.number}`,
|
|
408
|
+
];
|
|
409
|
+
}
|
|
410
|
+
const destination = intent.destination;
|
|
411
|
+
if (destination.type === "alias")
|
|
412
|
+
return [t("Cuenta {{alias}}", { alias: destination.alias }, locale)];
|
|
413
|
+
if (destination.type === "account")
|
|
414
|
+
return [t("Cuenta Andco {{id}}", { id: destination.id.slice(-8) }, locale)];
|
|
415
|
+
const external = form?.destination ?? destination;
|
|
416
|
+
return [
|
|
417
|
+
external.holder_name,
|
|
418
|
+
external.holder_id,
|
|
419
|
+
external.bank_id,
|
|
420
|
+
`${kind(external.account_type)} · ${external.account_id}`,
|
|
421
|
+
];
|
|
422
|
+
}
|
|
335
423
|
/** Restores accepted command values; otherwise defaults only an unambiguous source. */
|
|
336
424
|
export function ANDCO_NATIVE_INTENT_FORM(data, retry) {
|
|
337
425
|
const intent = data.intent;
|
|
338
426
|
if (retry?.action === "fund_deposit")
|
|
339
|
-
return { source: retry.sourceAccountId, amount: String(retry.amount), note: retry.note ?? "",
|
|
340
|
-
const
|
|
427
|
+
return { source: retry.sourceAccountId, amount: String(retry.amount), note: retry.note ?? "", destination: null };
|
|
428
|
+
const transferRetry = retry?.action === "confirm_transfer" ? retry : undefined;
|
|
429
|
+
const destination = proposedDestination(intent);
|
|
341
430
|
return {
|
|
342
|
-
source:
|
|
431
|
+
source: transferRetry?.sourceAccountId ??
|
|
343
432
|
data.funding?.pendingSourceId ??
|
|
344
|
-
(intent.type
|
|
345
|
-
? intent.source.
|
|
433
|
+
(intent.type !== "deposit" && intent.source?.type === "account"
|
|
434
|
+
? intent.source.id
|
|
346
435
|
: data.sources.length === 1
|
|
347
436
|
? data.sources[0]?.id
|
|
348
437
|
: undefined) ??
|
|
349
438
|
"",
|
|
350
|
-
amount:
|
|
439
|
+
amount: transferRetry?.amount ??
|
|
351
440
|
data.funding?.pendingAmount ??
|
|
352
|
-
(intent.type === "deposit" ? (intent.progress.remaining ?? "") : intent.amount.
|
|
353
|
-
note:
|
|
354
|
-
|
|
441
|
+
(intent.type === "deposit" ? (intent.progress.remaining ?? "") : intent.amount.value),
|
|
442
|
+
note: transferRetry?.note ?? data.funding?.pendingNote ?? data.confirmedNote ?? intent.note?.value ?? "",
|
|
443
|
+
destination: destination ? { ...destination, ...transferRetry?.destination } : null,
|
|
355
444
|
};
|
|
356
445
|
}
|
|
357
|
-
/** Builds an explicit command without resending editable values
|
|
446
|
+
/** Builds an explicit command without resending frozen or non-editable values of a money movement. */
|
|
358
447
|
export function ANDCO_NATIVE_INTENT_COMMAND(data, form) {
|
|
359
448
|
const intent = data.intent;
|
|
360
449
|
const frozen = intent.status.startsWith("processing.");
|
|
361
|
-
|
|
450
|
+
// Editability is read from the Intent the server sent and never from the form, so a screen that
|
|
451
|
+
// holds an edited value cannot turn a frozen amount, destination or note into a confirmed one.
|
|
452
|
+
const proposed = proposedDestination(intent);
|
|
453
|
+
const destination = form.destination;
|
|
362
454
|
return v.parse(AndCoNativeIntentCommandSchema, intent.type === "deposit"
|
|
363
455
|
? {
|
|
364
456
|
action: "fund_deposit",
|
|
365
457
|
sourceAccountId: form.source,
|
|
366
|
-
amount:
|
|
458
|
+
amount: data.funding?.pendingAmount ?? intent.progress.remaining ?? form.amount,
|
|
367
459
|
note: form.note,
|
|
368
460
|
}
|
|
369
461
|
: {
|
|
370
|
-
action: "
|
|
462
|
+
action: "confirm_transfer",
|
|
371
463
|
sourceAccountId: form.source || undefined,
|
|
372
|
-
note: frozen
|
|
464
|
+
note: !frozen && intent.note?.editable ? form.note : undefined,
|
|
373
465
|
amount: !frozen && intent.amount.editable ? form.amount : undefined,
|
|
374
|
-
|
|
466
|
+
destination: !frozen && proposed?.editable && destination
|
|
375
467
|
? {
|
|
376
|
-
|
|
377
|
-
bank_id:
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
468
|
+
type: "external",
|
|
469
|
+
bank_id: destination.bank_id,
|
|
470
|
+
account_type: destination.account_type,
|
|
471
|
+
account_id: destination.account_id,
|
|
472
|
+
holder_id: destination.holder_id,
|
|
473
|
+
holder_name: destination.holder_name,
|
|
382
474
|
}
|
|
383
475
|
: undefined,
|
|
384
476
|
});
|
|
385
477
|
}
|
|
386
478
|
/** Validates the proposed command while preserving an already accepted deposit's frozen amount. */
|
|
387
479
|
export function ANDCO_NATIVE_INTENT_FORM_VALID(data, form) {
|
|
388
|
-
if (data.intent.type
|
|
480
|
+
if (data.intent.type !== "deposit" && data.sourceEditable && !form.source)
|
|
389
481
|
return false;
|
|
390
482
|
try {
|
|
391
483
|
const command = ANDCO_NATIVE_INTENT_COMMAND(data, form);
|