@andco/protocol 0.0.7 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -73
- package/dist/api-errors.d.ts +40 -6
- package/dist/api-errors.d.ts.map +1 -1
- package/dist/api-errors.js +38 -6
- package/dist/consent.d.ts +2 -2
- package/dist/consent.d.ts.map +1 -1
- package/dist/consent.js +10 -19
- package/dist/errors.d.ts +41 -7
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +46 -8
- package/dist/format-money.d.ts +3 -0
- package/dist/format-money.d.ts.map +1 -0
- package/dist/format-money.js +7 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/intent-input.d.ts +134 -126
- package/dist/intent-input.d.ts.map +1 -1
- package/dist/intent-input.js +26 -16
- package/dist/intent-status.d.ts +24 -0
- package/dist/intent-status.d.ts.map +1 -0
- package/dist/intent-status.js +37 -0
- package/dist/miniapp-icon.d.ts +2 -2
- package/dist/miniapp-icon.d.ts.map +1 -1
- package/dist/miniapp-icon.js +6 -58
- package/dist/native-intent.d.ts +24 -33
- package/dist/native-intent.d.ts.map +1 -1
- package/dist/native-intent.js +19 -60
- package/dist/pagination.d.ts +71 -0
- package/dist/pagination.d.ts.map +1 -0
- package/dist/pagination.js +63 -0
- package/dist/rar/account-matchers.d.ts +52 -52
- package/dist/rar/account-matchers.d.ts.map +1 -1
- package/dist/rar/account-matchers.js +81 -72
- package/dist/rar/bank.d.ts +86 -84
- package/dist/rar/bank.d.ts.map +1 -1
- package/dist/rar/bank.js +26 -24
- package/dist/rar/catalog.d.ts +57 -56
- package/dist/rar/catalog.d.ts.map +1 -1
- package/dist/rar/catalog.js +1 -0
- package/dist/rar/detail.d.ts +1 -1
- package/dist/rar/detail.d.ts.map +1 -1
- package/dist/rar/detail.js +1 -1
- package/dist/service-grants.d.ts +4 -2
- package/dist/service-grants.d.ts.map +1 -1
- package/dist/service-grants.js +15 -2
- package/dist/transport/financial-events.d.ts +10 -22
- package/dist/transport/financial-events.d.ts.map +1 -1
- package/dist/transport/financial-events.js +36 -62
- package/dist/transport/generated/oauth-api.d.ts +297 -103
- package/dist/transport/generated/oauth-api.d.ts.map +1 -1
- package/dist/transport/intents.d.ts +11 -10
- package/dist/transport/intents.d.ts.map +1 -1
- package/dist/transport/intents.js +22 -21
- package/dist/transport/rest.d.ts +7 -4
- package/dist/transport/rest.d.ts.map +1 -1
- package/dist/transport/rest.js +1 -1
- package/dist/transport/runtime.js +3 -3
- package/dist/utils.js +3 -3
- package/dist/webhooks.d.ts +15 -4
- package/dist/webhooks.d.ts.map +1 -1
- package/dist/webhooks.js +50 -17
- package/package.json +1 -1
- package/dist/native-copy.d.ts +0 -28
- package/dist/native-copy.d.ts.map +0 -1
- package/dist/native-copy.js +0 -400
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intent-input.d.ts","sourceRoot":"","sources":["../src/intent-input.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAmF7B;;;;;;GAMG;AACH,QAAA,MAAM,YAAY;;;;;;0BAGhB,CAAC;AAEH,
|
|
1
|
+
{"version":3,"file":"intent-input.d.ts","sourceRoot":"","sources":["../src/intent-input.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAmF7B;;;;;;GAMG;AACH,QAAA,MAAM,YAAY;;;;;;0BAGhB,CAAC;AAEH,gGAAgG;AAChG,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,YAAY,CAAC,CAAC;AAK/D,oGAAoG;AACpG,QAAA,MAAM,yBAAyB;;;;;;;;;;;;;0BAI7B,CAAC;AAcH,gFAAgF;AAChF,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAK9E,gFAAgF;AAChF,wBAAgB,gBAAgB,C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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAEnD;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAUzE;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;aAOrC,CAAC;AAEH,gGAAgG;AAChG,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,OAAO;;;;;;;;;;;;;eAE3D"}
|
package/dist/intent-input.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
import { ANDCO_API_ORIGIN } from "./constants.js";
|
|
3
|
-
import {
|
|
3
|
+
import { AccountKeySchema } from "./rar/account-matchers.js";
|
|
4
4
|
import { MoneySchema } from "./rar/money.js";
|
|
5
5
|
const text = (max) => v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(max));
|
|
6
6
|
const accountId = /* @__PURE__ */ v.pipe(v.string(), v.uuid());
|
|
@@ -45,18 +45,18 @@ const signedAmount = { currency: v.literal("CLP"), value: amountValue };
|
|
|
45
45
|
const noteText = /* @__PURE__ */ v.pipe(v.string(), v.trim(), v.check((value) => [...value].length <= 140, "note_too_long"));
|
|
46
46
|
/**
|
|
47
47
|
* The account a transfer names, in the vocabulary of the `bank_transfer` matchers it has to fit:
|
|
48
|
-
* `{ type: "
|
|
48
|
+
* `{ type: "account_key", accountKey }` and `{ type: "account", id }` name one Andco account, and
|
|
49
49
|
* `{ type: "external", ... }` names one account at another Chilean bank with every field the
|
|
50
50
|
* `external` matcher can fix. A transfer names exactly one account, so nothing here is a pattern.
|
|
51
51
|
*
|
|
52
52
|
* @example
|
|
53
|
-
* const source: TransferAccount = { type: "
|
|
53
|
+
* const source: TransferAccount = { type: "account_key", accountKey: "caja-santiago" };
|
|
54
54
|
* const payroll: TransferAccount = {
|
|
55
55
|
* type: "external", bank_id: "banco_de_chile", account_type: "checking", account_id: "1234567890",
|
|
56
56
|
* holder_id: "12345678-5", holder_name: "Ada Lovelace",
|
|
57
57
|
* };
|
|
58
58
|
*/
|
|
59
|
-
const
|
|
59
|
+
const transferAccountKey = { type: /* @__PURE__ */ v.literal("account_key"), accountKey: AccountKeySchema };
|
|
60
60
|
const transferAccount = { type: /* @__PURE__ */ v.literal("account"), id: accountId };
|
|
61
61
|
const transferExternal = {
|
|
62
62
|
type: /* @__PURE__ */ v.literal("external"),
|
|
@@ -67,21 +67,21 @@ const transferExternal = {
|
|
|
67
67
|
holder_name: text(256),
|
|
68
68
|
};
|
|
69
69
|
/**
|
|
70
|
-
* One Andco account of the Grant's subject, named by Account
|
|
70
|
+
* One Andco account of the Grant's subject, named by Account Key or by identifier: where a
|
|
71
71
|
* transfer's money leaves from, where a deposit lands, and the account a closure closes.
|
|
72
72
|
*
|
|
73
73
|
* @example
|
|
74
|
-
* const account: IntentAccount = { type: "
|
|
74
|
+
* const account: IntentAccount = { type: "account_key", accountKey: "ventas" };
|
|
75
75
|
*/
|
|
76
76
|
const andcoAccount = /* @__PURE__ */ v.variant("type", [
|
|
77
|
-
v.strictObject(
|
|
77
|
+
v.strictObject(transferAccountKey),
|
|
78
78
|
v.strictObject(transferAccount),
|
|
79
79
|
]);
|
|
80
80
|
/** Where a transfer's money leaves from: always an Andco account of the Grant's subject. */
|
|
81
81
|
const transferSource = andcoAccount;
|
|
82
82
|
/** Where a signed transfer's money lands: nothing on this path is left for a person to complete. */
|
|
83
83
|
const signedTransferDestination = /* @__PURE__ */ v.variant("type", [
|
|
84
|
-
v.strictObject(
|
|
84
|
+
v.strictObject(transferAccountKey),
|
|
85
85
|
v.strictObject(transferAccount),
|
|
86
86
|
v.strictObject(transferExternal),
|
|
87
87
|
]);
|
|
@@ -92,7 +92,7 @@ const signedTransferDestination = /* @__PURE__ */ v.variant("type", [
|
|
|
92
92
|
*/
|
|
93
93
|
const lockedDestination = { editable: /* @__PURE__ */ v.optional(v.literal(false), false) };
|
|
94
94
|
const proposedTransferDestination = /* @__PURE__ */ v.variant("type", [
|
|
95
|
-
v.strictObject({ ...
|
|
95
|
+
v.strictObject({ ...transferAccountKey, ...lockedDestination }),
|
|
96
96
|
v.strictObject({ ...transferAccount, ...lockedDestination }),
|
|
97
97
|
v.strictObject({ ...transferExternal, ...lockedDestination }),
|
|
98
98
|
]);
|
|
@@ -136,7 +136,7 @@ const common = {
|
|
|
136
136
|
* wrong ones.
|
|
137
137
|
*
|
|
138
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 (`
|
|
139
|
+
* `destination`, both named in the `bank_transfer` matcher vocabulary (`account_key`, `account`,
|
|
140
140
|
* `external`). A null `source` is the confirmation screen's source picker; the amount and the
|
|
141
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
142
|
* the operation itself.
|
|
@@ -144,7 +144,7 @@ const common = {
|
|
|
144
144
|
* @example
|
|
145
145
|
* safeParseIntentCreate({
|
|
146
146
|
* type: "transfer", expires_in: "30 minutes", source: null,
|
|
147
|
-
* destination: { type: "
|
|
147
|
+
* destination: { type: "account_key", accountKey: "proveedores" },
|
|
148
148
|
* amount: { currency: "CLP", value: "40000" },
|
|
149
149
|
* note: { value: "Factura 42", editable: true },
|
|
150
150
|
* });
|
|
@@ -175,7 +175,7 @@ export const IntentCreateSchema = /* @__PURE__ */ v.pipe(v.variant("type", [
|
|
|
175
175
|
type: v.literal("account_opening"),
|
|
176
176
|
// The holder's own name for the account, unique per subject (ADR 0028) and never reused once
|
|
177
177
|
// the account closes.
|
|
178
|
-
|
|
178
|
+
accountKey: AccountKeySchema,
|
|
179
179
|
name: v.optional(accountName),
|
|
180
180
|
upsert: v.optional(v.boolean(), false),
|
|
181
181
|
}),
|
|
@@ -206,7 +206,7 @@ export function safeParseIntentCreate(input) {
|
|
|
206
206
|
* come from inside the signature, the second one cannot arrive in a header or a query string.
|
|
207
207
|
*
|
|
208
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
|
|
209
|
+
* flag decides whether naming an Account Key that already exists is a refusal or a request for the
|
|
210
210
|
* account already carrying it, which is a difference in what the instruction *orders*. Carried as a
|
|
211
211
|
* transport option — a header, a query parameter, a field beside the assertion — anybody holding the
|
|
212
212
|
* signed instruction could flip it, and the order executed would not be the order signed.
|
|
@@ -240,7 +240,7 @@ export const SignedIntentSchema = /* @__PURE__ */ v.pipe(v.variant("type", [
|
|
|
240
240
|
iat: v.optional(v.pipe(v.number(), v.integer())),
|
|
241
241
|
nbf: v.optional(v.pipe(v.number(), v.integer())),
|
|
242
242
|
type: v.literal("account_opening"),
|
|
243
|
-
|
|
243
|
+
accountKey: AccountKeySchema,
|
|
244
244
|
name: v.optional(accountName),
|
|
245
245
|
// Inside the signature, never beside it: outside the claims anyone holding the assertion could
|
|
246
246
|
// turn "create this account" into "create it or hand me the one that is already there".
|
|
@@ -302,16 +302,26 @@ export function safeParseIntentRejection(input) {
|
|
|
302
302
|
export const ANDCO_INTENT_ERROR_CODES = {
|
|
303
303
|
/** The Intent's deadline to be approved and executed has already passed. */
|
|
304
304
|
INTENT_EXPIRED: "intent_expired",
|
|
305
|
+
/**
|
|
306
|
+
* Closing an account is not built yet. Answered as `not_implemented` (501) with this `code`, by the
|
|
307
|
+
* SDK before any request and by the server at Intent creation, whatever the Grant holds.
|
|
308
|
+
*/
|
|
309
|
+
ACCOUNT_CLOSURE_NOT_IMPLEMENTED: "account_closure_not_implemented",
|
|
305
310
|
};
|
|
306
311
|
/** Returns validation issues for the verified claims without throwing across the HTTP boundary. */
|
|
307
312
|
export function safeParseSignedIntent(input) {
|
|
308
313
|
return v.safeParse(SignedIntentSchema, input);
|
|
309
314
|
}
|
|
310
|
-
/**
|
|
311
|
-
|
|
315
|
+
/**
|
|
316
|
+
* Identifies recognized unsupported Intents without silently dropping their extra instructions: an
|
|
317
|
+
* account closure, and payment shapes that carry several destinations, allocations or instructions.
|
|
318
|
+
*/
|
|
319
|
+
export function unsupportedIntentShape(input) {
|
|
312
320
|
if (!input || typeof input !== "object" || Array.isArray(input))
|
|
313
321
|
return undefined;
|
|
314
322
|
const record = input;
|
|
323
|
+
if (record["type"] === "account_closure")
|
|
324
|
+
return ANDCO_INTENT_ERROR_CODES.ACCOUNT_CLOSURE_NOT_IMPLEMENTED;
|
|
315
325
|
if (!["deposit", "transfer"].includes(String(record["type"])))
|
|
316
326
|
return undefined;
|
|
317
327
|
if (Object.hasOwn(record, "destinations") || Array.isArray(record["destination"]))
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The lifecycle stage of an Intent status: what precedes the first dot of `<base>[.<detail>]`.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* INTENT_STATUS_BASE("cancelled.grant_revoked"); // "cancelled"
|
|
7
|
+
* INTENT_STATUS_BASE("succeeded"); // "succeeded"
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export declare function INTENT_STATUS_BASE(status: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Whether an Intent status is one the Intent never leaves, decided by its base alone so a detail the
|
|
13
|
+
* server adds later is never misread: `succeeded`, `completed`, `closed`, `failed`, `cancelled`,
|
|
14
|
+
* `rejected` and `expired` are terminal with or without a detail; `requires_action` and
|
|
15
|
+
* `processing` are not.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* IS_INTENT_TERMINAL_STATUS("cancelled.grant_revoked"); // true
|
|
20
|
+
* IS_INTENT_TERMINAL_STATUS("processing.opening"); // false
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function IS_INTENT_TERMINAL_STATUS(status: string): boolean;
|
|
24
|
+
//# sourceMappingURL=intent-status.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intent-status.d.ts","sourceRoot":"","sources":["../src/intent-status.ts"],"names":[],"mappings":"AAWA;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEjE"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** The bases of an Intent status that never change again. `requires_action` and `processing` do. */
|
|
2
|
+
const TERMINAL_INTENT_STATUS_BASES = /* @__PURE__ */ new Set([
|
|
3
|
+
"succeeded",
|
|
4
|
+
"completed",
|
|
5
|
+
"closed",
|
|
6
|
+
"failed",
|
|
7
|
+
"cancelled",
|
|
8
|
+
"rejected",
|
|
9
|
+
"expired",
|
|
10
|
+
]);
|
|
11
|
+
/**
|
|
12
|
+
* The lifecycle stage of an Intent status: what precedes the first dot of `<base>[.<detail>]`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* INTENT_STATUS_BASE("cancelled.grant_revoked"); // "cancelled"
|
|
17
|
+
* INTENT_STATUS_BASE("succeeded"); // "succeeded"
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function INTENT_STATUS_BASE(status) {
|
|
21
|
+
return status.split(".")[0] ?? status;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Whether an Intent status is one the Intent never leaves, decided by its base alone so a detail the
|
|
25
|
+
* server adds later is never misread: `succeeded`, `completed`, `closed`, `failed`, `cancelled`,
|
|
26
|
+
* `rejected` and `expired` are terminal with or without a detail; `requires_action` and
|
|
27
|
+
* `processing` are not.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* IS_INTENT_TERMINAL_STATUS("cancelled.grant_revoked"); // true
|
|
32
|
+
* IS_INTENT_TERMINAL_STATUS("processing.opening"); // false
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function IS_INTENT_TERMINAL_STATUS(status) {
|
|
36
|
+
return TERMINAL_INTENT_STATUS_BASES.has(INTENT_STATUS_BASE(status));
|
|
37
|
+
}
|
package/dist/miniapp-icon.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { AndCoMiniappManifest } from "./miniapp-manifest.js";
|
|
2
|
-
/** Selects
|
|
3
|
-
export declare function resolveAndCoMiniappIconUrl(manifest: AndCoMiniappManifest, manifestUrl: string | URL): string;
|
|
2
|
+
/** Selects the first valid same-origin icon in manifest order. */
|
|
3
|
+
export declare function resolveAndCoMiniappIconUrl(manifest: AndCoMiniappManifest, manifestUrl: string | URL): string | undefined;
|
|
4
4
|
//# sourceMappingURL=miniapp-icon.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"miniapp-icon.d.ts","sourceRoot":"","sources":["../src/miniapp-icon.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"miniapp-icon.d.ts","sourceRoot":"","sources":["../src/miniapp-icon.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAGlE,kEAAkE;AAClE,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,GAAG,GAAG,sBAWnG"}
|
package/dist/miniapp-icon.js
CHANGED
|
@@ -1,68 +1,16 @@
|
|
|
1
1
|
import { SafeURL } from "./urls.js";
|
|
2
|
-
|
|
3
|
-
const purposes = purpose?.toLowerCase().split(/\s+/).filter(Boolean) ?? [];
|
|
4
|
-
if (purposes.includes("any"))
|
|
5
|
-
return 0;
|
|
6
|
-
if (purposes.includes("maskable"))
|
|
7
|
-
return 1;
|
|
8
|
-
return 2;
|
|
9
|
-
}
|
|
10
|
-
function iconSizeScore(sizes) {
|
|
11
|
-
const sizeTokens = sizes?.toLowerCase().split(/\s+/) ?? [];
|
|
12
|
-
if (sizeTokens.includes("any"))
|
|
13
|
-
return { shapeRank: 0, sizeDistance: 0 };
|
|
14
|
-
const dimensions = sizeTokens.flatMap((size) => {
|
|
15
|
-
const match = /^(\d+)x(\d+)$/.exec(size);
|
|
16
|
-
if (!match)
|
|
17
|
-
return [];
|
|
18
|
-
const width = Number(match[1]);
|
|
19
|
-
const height = Number(match[2]);
|
|
20
|
-
if (!Number.isSafeInteger(width) || !Number.isSafeInteger(height) || width < 1 || height < 1)
|
|
21
|
-
return [];
|
|
22
|
-
return [{ width, height }];
|
|
23
|
-
});
|
|
24
|
-
if (dimensions.some(({ width, height }) => width === height && width >= 40)) {
|
|
25
|
-
return {
|
|
26
|
-
shapeRank: 0,
|
|
27
|
-
sizeDistance: Math.min(...dimensions
|
|
28
|
-
.filter(({ width, height }) => width === height && width >= 40)
|
|
29
|
-
.map(({ width }) => Math.abs(width - 64))),
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
if (dimensions.some(({ width, height }) => width === height)) {
|
|
33
|
-
return {
|
|
34
|
-
shapeRank: 1,
|
|
35
|
-
sizeDistance: Math.min(...dimensions.filter(({ width, height }) => width === height).map(({ width }) => Math.abs(width - 64))),
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
if (dimensions.length) {
|
|
39
|
-
return {
|
|
40
|
-
shapeRank: 2,
|
|
41
|
-
sizeDistance: Math.min(...dimensions.map(({ width, height }) => Math.abs(Math.max(width, height) - 64))),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
return { shapeRank: 3, sizeDistance: Number.MAX_SAFE_INTEGER };
|
|
45
|
-
}
|
|
46
|
-
/** Selects a same-origin manifest icon suited to compact native Host chrome. */
|
|
2
|
+
/** Selects the first valid same-origin icon in manifest order. */
|
|
47
3
|
export function resolveAndCoMiniappIconUrl(manifest, manifestUrl) {
|
|
48
4
|
const base = new SafeURL(manifestUrl);
|
|
49
|
-
const
|
|
50
|
-
for (const [index, icon] of manifest.icons.entries()) {
|
|
5
|
+
for (const icon of manifest.icons) {
|
|
51
6
|
try {
|
|
52
7
|
const url = new SafeURL(new URL(icon.src, base));
|
|
53
|
-
if (url.origin
|
|
54
|
-
|
|
55
|
-
const { shapeRank, sizeDistance } = iconSizeScore(icon.sizes);
|
|
56
|
-
candidates.push({ url: url.href, purposeRank: iconPurposeRank(icon.purpose), shapeRank, sizeDistance, index });
|
|
8
|
+
if (url.origin === base.origin)
|
|
9
|
+
return url.href;
|
|
57
10
|
}
|
|
58
11
|
catch {
|
|
59
|
-
//
|
|
12
|
+
// An invalid icon must not invalidate the Miniapp.
|
|
60
13
|
}
|
|
61
14
|
}
|
|
62
|
-
|
|
63
|
-
left.sizeDistance - right.sizeDistance ||
|
|
64
|
-
left.purposeRank - right.purposeRank ||
|
|
65
|
-
left.url.localeCompare(right.url) ||
|
|
66
|
-
left.index - right.index);
|
|
67
|
-
return candidates[0]?.url;
|
|
15
|
+
return undefined;
|
|
68
16
|
}
|
package/dist/native-intent.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
|
-
import { ANDCO_NATIVE_TEXT as t } from "./native-copy.js";
|
|
3
2
|
/**
|
|
4
3
|
* An account at another bank, the only destination a person may still correct on a screen.
|
|
5
4
|
*
|
|
6
|
-
* An Andco account named by
|
|
5
|
+
* An Andco account named by AccountKey or identifier already denotes exactly one account, so there is
|
|
7
6
|
* nothing on the screen to correct: it is never editable.
|
|
8
7
|
*/
|
|
9
8
|
declare const editableDestination: v.ObjectSchema<{
|
|
@@ -52,14 +51,16 @@ export declare const AndCoNativeIntentPreparationSchema: v.ObjectSchema<{
|
|
|
52
51
|
readonly note: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
53
52
|
readonly outcome: v.PicklistSchema<["credited", "reversed"], undefined>;
|
|
54
53
|
readonly receipt_time_source: v.PicklistSchema<["bank_timestamp", "unknown"], undefined>;
|
|
55
|
-
readonly
|
|
56
|
-
readonly
|
|
57
|
-
readonly
|
|
54
|
+
readonly sender_name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
55
|
+
readonly sender_national_id: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
56
|
+
readonly sender_bank_name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
57
|
+
readonly sender_account_type: v.NullableSchema<v.PicklistSchema<["checking", "debit", "savings"], undefined>, undefined>;
|
|
58
|
+
readonly sender_account_number: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
58
59
|
readonly amount: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
|
|
59
60
|
readonly currency: v.LiteralSchema<"CLP", undefined>;
|
|
60
61
|
}, undefined>, undefined>;
|
|
61
62
|
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
62
|
-
readonly status: v.PicklistSchema<["requires_action", "processing.confirmed", "processing.settling", "processing.reversing", "processing.reconciling", "succeeded", "completed", "closed", "failed", "failed.insufficient_funds", "cancelled", "rejected", "expired"], undefined>;
|
|
63
|
+
readonly status: v.PicklistSchema<["requires_action", "processing.confirmed", "processing.settling", "processing.reversing", "processing.reconciling", "succeeded", "completed", "closed", "failed", "failed.insufficient_funds", "cancelled", "cancelled.grant_revoked", "cancelled.grant_expired", "rejected", "expired"], undefined>;
|
|
63
64
|
readonly fee: v.ObjectSchema<{
|
|
64
65
|
readonly currency: v.LiteralSchema<"CLP", undefined>;
|
|
65
66
|
readonly amount: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
|
|
@@ -85,8 +86,8 @@ export declare const AndCoNativeIntentPreparationSchema: v.ObjectSchema<{
|
|
|
85
86
|
readonly signed: v.BooleanSchema<undefined>;
|
|
86
87
|
readonly destination: v.VariantSchema<"type", [v.ObjectSchema<{
|
|
87
88
|
readonly editable: v.LiteralSchema<false, undefined>;
|
|
88
|
-
readonly type: v.LiteralSchema<"
|
|
89
|
-
readonly
|
|
89
|
+
readonly type: v.LiteralSchema<"account_key", undefined>;
|
|
90
|
+
readonly accountKey: v.StringSchema<undefined>;
|
|
90
91
|
}, undefined>, v.ObjectSchema<{
|
|
91
92
|
readonly editable: v.LiteralSchema<false, undefined>;
|
|
92
93
|
readonly type: v.LiteralSchema<"account", undefined>;
|
|
@@ -101,14 +102,14 @@ export declare const AndCoNativeIntentPreparationSchema: v.ObjectSchema<{
|
|
|
101
102
|
readonly editable: v.BooleanSchema<undefined>;
|
|
102
103
|
}, undefined>], undefined>;
|
|
103
104
|
readonly source: v.NullableSchema<v.VariantSchema<"type", [v.ObjectSchema<{
|
|
104
|
-
readonly type: v.LiteralSchema<"
|
|
105
|
-
readonly
|
|
105
|
+
readonly type: v.LiteralSchema<"account_key", undefined>;
|
|
106
|
+
readonly accountKey: v.StringSchema<undefined>;
|
|
106
107
|
}, undefined>, v.ObjectSchema<{
|
|
107
108
|
readonly type: v.LiteralSchema<"account", undefined>;
|
|
108
109
|
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
109
110
|
}, undefined>], undefined>, undefined>;
|
|
110
111
|
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
111
|
-
readonly status: v.PicklistSchema<["requires_action", "processing.confirmed", "processing.settling", "processing.reversing", "processing.reconciling", "succeeded", "completed", "closed", "failed", "failed.insufficient_funds", "cancelled", "rejected", "expired"], undefined>;
|
|
112
|
+
readonly status: v.PicklistSchema<["requires_action", "processing.confirmed", "processing.settling", "processing.reversing", "processing.reconciling", "succeeded", "completed", "closed", "failed", "failed.insufficient_funds", "cancelled", "cancelled.grant_revoked", "cancelled.grant_expired", "rejected", "expired"], undefined>;
|
|
112
113
|
readonly amount: v.ObjectSchema<{
|
|
113
114
|
readonly currency: v.LiteralSchema<"CLP", undefined>;
|
|
114
115
|
readonly value: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
|
|
@@ -261,14 +262,16 @@ export declare function requestAndCoNativeIntent(options: {
|
|
|
261
262
|
note: string | null;
|
|
262
263
|
outcome: "credited" | "reversed";
|
|
263
264
|
receipt_time_source: "unknown" | "bank_timestamp";
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
265
|
+
sender_name: string | null;
|
|
266
|
+
sender_national_id: string | null;
|
|
267
|
+
sender_bank_name: string | null;
|
|
268
|
+
sender_account_type: "checking" | "debit" | "savings" | null;
|
|
269
|
+
sender_account_number: string | null;
|
|
267
270
|
amount: string;
|
|
268
271
|
currency: "CLP";
|
|
269
272
|
}[];
|
|
270
273
|
id: string;
|
|
271
|
-
status: "completed" | "
|
|
274
|
+
status: "completed" | "succeeded" | "closed" | "failed" | "cancelled" | "rejected" | "expired" | "requires_action" | "processing.confirmed" | "processing.settling" | "processing.reversing" | "processing.reconciling" | "failed.insufficient_funds" | "cancelled.grant_revoked" | "cancelled.grant_expired";
|
|
272
275
|
fee: {
|
|
273
276
|
currency: "CLP";
|
|
274
277
|
amount: string;
|
|
@@ -294,8 +297,8 @@ export declare function requestAndCoNativeIntent(options: {
|
|
|
294
297
|
signed: boolean;
|
|
295
298
|
destination: {
|
|
296
299
|
editable: false;
|
|
297
|
-
type: "
|
|
298
|
-
|
|
300
|
+
type: "account_key";
|
|
301
|
+
accountKey: string;
|
|
299
302
|
} | {
|
|
300
303
|
editable: false;
|
|
301
304
|
type: "account";
|
|
@@ -310,14 +313,14 @@ export declare function requestAndCoNativeIntent(options: {
|
|
|
310
313
|
editable: boolean;
|
|
311
314
|
};
|
|
312
315
|
source: {
|
|
313
|
-
type: "
|
|
314
|
-
|
|
316
|
+
type: "account_key";
|
|
317
|
+
accountKey: string;
|
|
315
318
|
} | {
|
|
316
319
|
type: "account";
|
|
317
320
|
id: string;
|
|
318
321
|
} | null;
|
|
319
322
|
id: string;
|
|
320
|
-
status: "completed" | "
|
|
323
|
+
status: "completed" | "succeeded" | "closed" | "failed" | "cancelled" | "rejected" | "expired" | "requires_action" | "processing.confirmed" | "processing.settling" | "processing.reversing" | "processing.reconciling" | "failed.insufficient_funds" | "cancelled.grant_revoked" | "cancelled.grant_expired";
|
|
321
324
|
amount: {
|
|
322
325
|
currency: "CLP";
|
|
323
326
|
value: string;
|
|
@@ -403,7 +406,7 @@ export declare class AndCoNativeIntentSession {
|
|
|
403
406
|
/** Stops polling and notifications without cancelling the financial operation. */
|
|
404
407
|
dispose(): void;
|
|
405
408
|
}
|
|
406
|
-
/** Server-authoritative lifecycle
|
|
409
|
+
/** Server-authoritative lifecycle state used by native renderers. */
|
|
407
410
|
export declare function ANDCO_NATIVE_INTENT_VIEW(data: AndCoNativeIntentPreparation, now?: number, observedAt?: number): {
|
|
408
411
|
terminal: boolean;
|
|
409
412
|
expired: boolean;
|
|
@@ -411,21 +414,9 @@ export declare function ANDCO_NATIVE_INTENT_VIEW(data: AndCoNativeIntentPreparat
|
|
|
411
414
|
frozen: boolean;
|
|
412
415
|
remaining: number | null;
|
|
413
416
|
canSubmit: boolean;
|
|
414
|
-
title: string;
|
|
415
|
-
status: string;
|
|
416
417
|
};
|
|
417
418
|
/** The destination a person may still correct, which is the only one a screen may send back. */
|
|
418
419
|
export type AndCoNativeIntentDestination = v.InferOutput<typeof editableDestination>;
|
|
419
|
-
/**
|
|
420
|
-
* The lines a native sheet shows for where the money lands, so both renderers read one answer: a
|
|
421
|
-
* deposit's account as a payer at another bank types it, a transfer's Andco account by Alias or by
|
|
422
|
-
* identifier, or another bank's account as the form holds it (a person's corrections included).
|
|
423
|
-
* `null` when the Intent names no destination.
|
|
424
|
-
*
|
|
425
|
-
* @example
|
|
426
|
-
* const lines = ANDCO_NATIVE_INTENT_DESTINATION_LINES(data, form); // ["Cuenta proveedores"]
|
|
427
|
-
*/
|
|
428
|
-
export declare function ANDCO_NATIVE_INTENT_DESTINATION_LINES(data: AndCoNativeIntentPreparation, form: Pick<AndCoNativeIntentForm, "destination"> | null, locale?: Parameters<typeof t>[2]): string[] | null;
|
|
429
420
|
/** User-edited values, separate from the durable financial state. */
|
|
430
421
|
export type AndCoNativeIntentForm = {
|
|
431
422
|
source: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-intent.d.ts","sourceRoot":"","sources":["../src/native-intent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"native-intent.d.ts","sourceRoot":"","sources":["../src/native-intent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAsB7B;;;;;GAKG;AACH,QAAA,MAAM,mBAAmB;;;;;;;;aAQvB,CAAC;AA6BH,+FAA+F;AAC/F,eAAO,MAAM,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAqF7C,CAAC;AACH,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,kCAAkC,CAAC,CAAC;AAEpG,mEAAmE;AACnE,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAkCzC,CAAC;AACH,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,8BAA8B,CAAC,CAAC;AAW5F,qFAAqF;AACrF,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,EAAE,UAAU,EAAE,MAAM,GAAG,GAAG,iBAUnF;AAED,gHAAgH;AAChH,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,MAAM,EAAE,UAA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"./intent-input.js";
|
|
3
|
-
import {
|
|
3
|
+
import { INTENT_STATUS_BASE, IS_INTENT_TERMINAL_STATUS } from "./intent-status.js";
|
|
4
4
|
import { MONEY_PATTERN, MoneyOrZeroSchema } from "./rar/money.js";
|
|
5
5
|
import { SafeURL } from "./urls.js";
|
|
6
6
|
const text = /* @__PURE__ */ v.string();
|
|
@@ -16,13 +16,13 @@ const money = MoneyOrZeroSchema;
|
|
|
16
16
|
const transmittedAmount = /* @__PURE__ */ v.pipe(text, v.regex(new RegExp(MONEY_PATTERN)));
|
|
17
17
|
const uuid = /* @__PURE__ */ v.pipe(text, v.uuid());
|
|
18
18
|
const accountType = /* @__PURE__ */ v.picklist(["checking", "debit", "savings"]);
|
|
19
|
-
/** One Andco account, by Account
|
|
20
|
-
const
|
|
19
|
+
/** One Andco account, by Account Key or by identifier, in the matcher vocabulary of a request. */
|
|
20
|
+
const accountKeyAccount = /* @__PURE__ */ v.object({ type: v.literal("account_key"), accountKey: text });
|
|
21
21
|
const idAccount = /* @__PURE__ */ v.object({ type: v.literal("account"), id: uuid });
|
|
22
22
|
/**
|
|
23
23
|
* An account at another bank, the only destination a person may still correct on a screen.
|
|
24
24
|
*
|
|
25
|
-
* An Andco account named by
|
|
25
|
+
* An Andco account named by AccountKey or identifier already denotes exactly one account, so there is
|
|
26
26
|
* nothing on the screen to correct: it is never editable.
|
|
27
27
|
*/
|
|
28
28
|
const editableDestination = /* @__PURE__ */ v.object({
|
|
@@ -48,6 +48,8 @@ const base = {
|
|
|
48
48
|
"failed",
|
|
49
49
|
"failed.insufficient_funds",
|
|
50
50
|
"cancelled",
|
|
51
|
+
"cancelled.grant_revoked",
|
|
52
|
+
"cancelled.grant_expired",
|
|
51
53
|
"rejected",
|
|
52
54
|
"expired",
|
|
53
55
|
]),
|
|
@@ -83,9 +85,11 @@ export const AndCoNativeIntentPreparationSchema = /* @__PURE__ */ v.object({
|
|
|
83
85
|
note: v.nullable(text),
|
|
84
86
|
outcome: v.picklist(["credited", "reversed"]),
|
|
85
87
|
receipt_time_source: v.picklist(["bank_timestamp", "unknown"]),
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
sender_name: v.nullable(text),
|
|
89
|
+
sender_national_id: v.nullable(text),
|
|
90
|
+
sender_bank_name: v.nullable(text),
|
|
91
|
+
sender_account_type: v.nullable(accountType),
|
|
92
|
+
sender_account_number: v.nullable(text),
|
|
89
93
|
amount: money,
|
|
90
94
|
currency: v.literal("CLP"),
|
|
91
95
|
})),
|
|
@@ -98,11 +102,11 @@ export const AndCoNativeIntentPreparationSchema = /* @__PURE__ */ v.object({
|
|
|
98
102
|
settled: v.nullable(v.object({ currency: v.literal("CLP"), value: money, at: text })),
|
|
99
103
|
signed: v.boolean(),
|
|
100
104
|
destination: v.variant("type", [
|
|
101
|
-
v.object({ ...
|
|
105
|
+
v.object({ ...accountKeyAccount.entries, editable: v.literal(false) }),
|
|
102
106
|
v.object({ ...idAccount.entries, editable: v.literal(false) }),
|
|
103
107
|
editableDestination,
|
|
104
108
|
]),
|
|
105
|
-
source: v.nullable(v.variant("type", [
|
|
109
|
+
source: v.nullable(v.variant("type", [accountKeyAccount, idAccount])),
|
|
106
110
|
}),
|
|
107
111
|
]),
|
|
108
112
|
sources: v.array(v.object({ id: uuid, number: text, name: v.nullable(text) })),
|
|
@@ -307,7 +311,7 @@ export class AndCoNativeIntentSession {
|
|
|
307
311
|
if (this.disposed || this.snapshot.pending)
|
|
308
312
|
return;
|
|
309
313
|
if (this.snapshot.retryCommand && this.snapshot.retryCommand.action !== command.action) {
|
|
310
|
-
this.publish({ ...this.snapshot, error:
|
|
314
|
+
this.publish({ ...this.snapshot, error: "native_intent_pending_operation" });
|
|
311
315
|
return;
|
|
312
316
|
}
|
|
313
317
|
clearTimeout(this.timer);
|
|
@@ -342,16 +346,15 @@ export class AndCoNativeIntentSession {
|
|
|
342
346
|
this.listeners.clear();
|
|
343
347
|
}
|
|
344
348
|
}
|
|
345
|
-
/** Server-authoritative lifecycle
|
|
349
|
+
/** Server-authoritative lifecycle state used by native renderers. */
|
|
346
350
|
export function ANDCO_NATIVE_INTENT_VIEW(data, now = Date.now(), observedAt = now) {
|
|
347
351
|
const intent = data.intent;
|
|
348
352
|
const remaining = intent.expires_at === null
|
|
349
353
|
? null
|
|
350
354
|
: Math.max(0, Date.parse(intent.expires_at) - Date.parse(intent.server_time) - (now - observedAt));
|
|
351
|
-
const terminal =
|
|
352
|
-
intent.status.startsWith("failed");
|
|
355
|
+
const terminal = IS_INTENT_TERMINAL_STATUS(intent.status);
|
|
353
356
|
const expired = intent.status === "expired" || (intent.status === "requires_action" && remaining === 0);
|
|
354
|
-
const processing = intent.status
|
|
357
|
+
const processing = INTENT_STATUS_BASE(intent.status) === "processing";
|
|
355
358
|
const pendingFunding = Boolean(data.funding?.pendingSourceId);
|
|
356
359
|
const frozen = processing || pendingFunding;
|
|
357
360
|
return {
|
|
@@ -365,61 +368,17 @@ export function ANDCO_NATIVE_INTENT_VIEW(data, now = Date.now(), observedAt = no
|
|
|
365
368
|
(intent.type === "deposit" ||
|
|
366
369
|
(!processing && intent.can_confirm) ||
|
|
367
370
|
(intent.status === "processing.confirmed" && data.retryable)),
|
|
368
|
-
title: t(ANDCO_NATIVE_INTENT_TYPE_COPY[intent.type].title),
|
|
369
|
-
status: ["succeeded", "completed"].includes(intent.status)
|
|
370
|
-
? t("Operación completada")
|
|
371
|
-
: expired
|
|
372
|
-
? t("La solicitud venció")
|
|
373
|
-
: processing
|
|
374
|
-
? t("Procesando la operación")
|
|
375
|
-
: terminal
|
|
376
|
-
? t("La operación finalizó")
|
|
377
|
-
: t("Revisa los datos antes de continuar"),
|
|
378
371
|
};
|
|
379
372
|
}
|
|
380
373
|
/**
|
|
381
374
|
* 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
|
|
375
|
+
* it: an Andco account named by AccountKey or identifier already denotes exactly one account.
|
|
383
376
|
*/
|
|
384
377
|
function proposedDestination(intent) {
|
|
385
378
|
if (intent.type === "transfer" && intent.destination.type === "external")
|
|
386
379
|
return intent.destination;
|
|
387
380
|
return null;
|
|
388
381
|
}
|
|
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
|
-
}
|
|
423
382
|
/** Restores accepted command values; otherwise defaults only an unambiguous source. */
|
|
424
383
|
export function ANDCO_NATIVE_INTENT_FORM(data, retry) {
|
|
425
384
|
const intent = data.intent;
|
|
@@ -446,7 +405,7 @@ export function ANDCO_NATIVE_INTENT_FORM(data, retry) {
|
|
|
446
405
|
/** Builds an explicit command without resending frozen or non-editable values of a money movement. */
|
|
447
406
|
export function ANDCO_NATIVE_INTENT_COMMAND(data, form) {
|
|
448
407
|
const intent = data.intent;
|
|
449
|
-
const frozen = intent.status
|
|
408
|
+
const frozen = INTENT_STATUS_BASE(intent.status) === "processing";
|
|
450
409
|
// Editability is read from the Intent the server sent and never from the form, so a screen that
|
|
451
410
|
// holds an edited value cannot turn a frozen amount, destination or note into a confirmed one.
|
|
452
411
|
const proposed = proposedDestination(intent);
|