@andco/protocol 0.0.6 → 0.0.8

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 (63) hide show
  1. package/README.md +22 -71
  2. package/dist/api-errors.d.ts +5 -5
  3. package/dist/api-errors.d.ts.map +1 -1
  4. package/dist/api-errors.js +5 -5
  5. package/dist/consent.d.ts +2 -2
  6. package/dist/consent.d.ts.map +1 -1
  7. package/dist/consent.js +10 -19
  8. package/dist/errors.d.ts +46 -7
  9. package/dist/errors.d.ts.map +1 -1
  10. package/dist/errors.js +51 -8
  11. package/dist/format-money.d.ts +3 -0
  12. package/dist/format-money.d.ts.map +1 -0
  13. package/dist/format-money.js +7 -0
  14. package/dist/index.d.ts +2 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +2 -1
  17. package/dist/intent-input.d.ts +124 -124
  18. package/dist/intent-input.d.ts.map +1 -1
  19. package/dist/intent-input.js +14 -14
  20. package/dist/miniapp-icon.d.ts +2 -2
  21. package/dist/miniapp-icon.d.ts.map +1 -1
  22. package/dist/miniapp-icon.js +6 -58
  23. package/dist/native-intent.d.ts +20 -29
  24. package/dist/native-intent.d.ts.map +1 -1
  25. package/dist/native-intent.js +13 -56
  26. package/dist/pagination.d.ts +71 -0
  27. package/dist/pagination.d.ts.map +1 -0
  28. package/dist/pagination.js +63 -0
  29. package/dist/rar/account-matchers.d.ts +52 -52
  30. package/dist/rar/account-matchers.d.ts.map +1 -1
  31. package/dist/rar/account-matchers.js +81 -72
  32. package/dist/rar/bank.d.ts +86 -84
  33. package/dist/rar/bank.d.ts.map +1 -1
  34. package/dist/rar/bank.js +26 -24
  35. package/dist/rar/catalog.d.ts +57 -56
  36. package/dist/rar/catalog.d.ts.map +1 -1
  37. package/dist/rar/catalog.js +1 -0
  38. package/dist/rar/detail.d.ts +1 -1
  39. package/dist/rar/detail.d.ts.map +1 -1
  40. package/dist/rar/detail.js +1 -1
  41. package/dist/service-grants.d.ts +6 -3
  42. package/dist/service-grants.d.ts.map +1 -1
  43. package/dist/service-grants.js +17 -3
  44. package/dist/transport/financial-events.d.ts +10 -22
  45. package/dist/transport/financial-events.d.ts.map +1 -1
  46. package/dist/transport/financial-events.js +36 -62
  47. package/dist/transport/generated/oauth-api.d.ts +269 -96
  48. package/dist/transport/generated/oauth-api.d.ts.map +1 -1
  49. package/dist/transport/intents.d.ts +11 -10
  50. package/dist/transport/intents.d.ts.map +1 -1
  51. package/dist/transport/intents.js +20 -19
  52. package/dist/transport/rest.d.ts +3 -3
  53. package/dist/transport/rest.d.ts.map +1 -1
  54. package/dist/transport/rest.js +1 -1
  55. package/dist/transport/runtime.js +3 -3
  56. package/dist/utils.js +3 -3
  57. package/dist/webhooks.d.ts +92 -12
  58. package/dist/webhooks.d.ts.map +1 -1
  59. package/dist/webhooks.js +95 -20
  60. package/package.json +1 -1
  61. package/dist/native-copy.d.ts +0 -28
  62. package/dist/native-copy.d.ts.map +0 -1
  63. package/dist/native-copy.js +0 -400
@@ -5,7 +5,6 @@ export type AndCoFinancialEvent<T extends string = string, P = Record<string, un
5
5
  payload: P;
6
6
  version: 1;
7
7
  occurred_at: string;
8
- cursor: string;
9
8
  };
10
9
  /**
11
10
  * An Andco account as an event names it: `{ type: "account", id }`, the same vocabulary a request
@@ -109,13 +108,13 @@ export type AndCoWithdrawalEvent = AndCoFinancialEvent<"withdrawal.posted", {
109
108
  * Frozen values of a confirmed transfer; these do not assert that a debit was posted.
110
109
  *
111
110
  * `destination` is whatever the money was aimed at: an Andco account by identifier, an Andco
112
- * account by the Account Alias its holder chose, or an account at another Chilean bank. An Alias
113
- * stays an Alias here because it resolves at execution, not at confirmation.
111
+ * account by the Account Key its holder chose, or an account at another Chilean bank. An AccountKey
112
+ * stays an AccountKey here because it resolves at execution, not at confirmation.
114
113
  *
115
114
  * @example
116
115
  * const operation: AndCoConfirmedTransfer = {
117
116
  * source: { type: "account", id: "0198d482-82aa-7ef2-ae1b-0cfae7ea5d8a" },
118
- * destination: { type: "alias", alias: "proveedores" },
117
+ * destination: { type: "account_key", accountKey: "proveedores" },
119
118
  * amount: { currency: "CLP", value: "30000" },
120
119
  * note: "Factura 42",
121
120
  * };
@@ -147,20 +146,14 @@ export type AndCoIntentTransferEvent = AndCoFinancialEvent<"transfer.expired", {
147
146
  transaction_id: string | null;
148
147
  observed_at: string;
149
148
  }>;
150
- /** Durable events with an opaque continuation cursor and server observation time. */
151
- export type AndCoEventPage = {
152
- events: AndCoFinancialEvent[];
153
- /** Opaque position after this page; persist only after every handler succeeds. */
154
- next_cursor: string;
155
- /** Whether another page is immediately available. */
156
- has_more: boolean;
157
- /** Server timestamp used to validate the event page. */
158
- server_time: string;
159
- };
149
+ /** Durable events in a standard connection with opaque edge cursors. */
150
+ export type AndCoEventPage = import("../pagination.js").Connection<AndCoFinancialEvent>;
160
151
  /** Checkpoint recovery, polling frequency, and failure handling for one subscription. */
161
152
  export type AndCoEventSubscriptionOptions = {
162
153
  /** Resume after a checkpoint previously acknowledged by this subject's subscription. */
163
154
  after?: string;
155
+ /** Persists the opaque continuation after successful handling or a deliberately skipped event. */
156
+ onCheckpoint?: (checkpoint: string) => void | Promise<void>;
164
157
  /** Receives transport, authorization, cursor, and handler failures. Throwing here stops the subscription. */
165
158
  onError: (error: unknown) => void;
166
159
  /** Delay between polls in milliseconds. Defaults to 1000; minimum 100. */
@@ -173,17 +166,12 @@ export type AndCoEventSubscription = {
173
166
  /** Persist only acknowledged checkpoints; a failed handler leaves this value unchanged. */
174
167
  readonly checkpoint: string | undefined;
175
168
  };
176
- /** Reconciles bounded durable pages; the SDK owns cursor decoding, while callers persist opaque values. */
169
+ /** Reconciles bounded pages using opaque continuation cursors. */
177
170
  export declare function subscribeFinancialEvents<E extends AndCoFinancialEvent>(
178
171
  /** Reads the next bounded page; honor the signal so unsubscribe can abort the request. */
179
172
  read: (after: string | undefined, signal: AbortSignal) => Promise<AndCoEventPage>,
180
173
  /** Maps a recognized event; returning `null` skips delivery to the handler. */
181
174
  decode: (event: AndCoFinancialEvent) => E | null,
182
- /** Process successfully before acknowledgement; failures leave the checkpoint unchanged. */
183
- handler: (event: E) => void | Promise<void>, options: AndCoEventSubscriptionOptions,
184
- /** Scopes the cursor namespace. Any caller-chosen `kind` works; only its consistency is checked. */
185
- subject: {
186
- kind: string;
187
- id: string;
188
- }): AndCoEventSubscription;
175
+ /** Receives the event and its edge cursor; success acknowledges that position. */
176
+ handler: (event: E, cursor: string) => void | Promise<void>, options: AndCoEventSubscriptionOptions): AndCoEventSubscription;
189
177
  //# sourceMappingURL=financial-events.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"financial-events.d.ts","sourceRoot":"","sources":["../../src/transport/financial-events.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IACxF,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,CAAC,CAAC;IACX,OAAO,EAAE,CAAC,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC,OAAO,cAAc,EAAE,kBAAkB,EAAE;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC,CAAC;AAExG,mGAAmG;AACnG,MAAM,MAAM,gBAAgB,GAAG,OAAO,cAAc,EAAE,iBAAiB,CAAC;AAExE,8EAA8E;AAC9E,MAAM,MAAM,uBAAuB,GAC/B,mBAAmB,CACjB,wBAAwB,EACxB;IACE,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,gBAAgB,CAAC;CAC1B,CACF,GACD,mBAAmB,CACjB,gBAAgB,EAChB;IACE,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,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AAC,cAAc,CAAC;AACjF,+EAA+E;AAC/E,MAAM,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,CAAC,GAAG,IAAI;AAChD,kFAAkF;AAClF,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAC3D,OAAO,EAAE,6BAA6B,GACrC,sBAAsB,CAmFxB"}
@@ -1,29 +1,16 @@
1
- /** Reconciles bounded durable pages; the SDK owns cursor decoding, while callers persist opaque values. */
1
+ /** Reconciles bounded pages using opaque continuation cursors. */
2
2
  export function subscribeFinancialEvents(
3
3
  /** Reads the next bounded page; honor the signal so unsubscribe can abort the request. */
4
4
  read,
5
5
  /** Maps a recognized event; returning `null` skips delivery to the handler. */
6
6
  decode,
7
- /** Process successfully before acknowledgement; failures leave the checkpoint unchanged. */
8
- handler, options,
9
- /** Scopes the cursor namespace. Any caller-chosen `kind` works; only its consistency is checked. */
10
- subject) {
7
+ /** Receives the event and its edge cursor; success acknowledges that position. */
8
+ handler, options) {
11
9
  const interval = options.pollIntervalMs ?? 1000;
12
10
  if (!Number.isSafeInteger(interval) || interval < 100)
13
11
  throw new TypeError("Invalid event polling interval");
14
12
  if (typeof options.onError !== "function")
15
13
  throw new TypeError("An event error handler is required");
16
- const prefix = `v1:${subject.kind}:${subject.id.toLowerCase()}:`;
17
- const positionOf = (cursor) => {
18
- if (typeof cursor !== "string" ||
19
- !cursor.startsWith(prefix) ||
20
- !/^(0|[1-9][0-9]{0,18})$/.test(cursor.slice(prefix.length)))
21
- throw new TypeError("invalid_or_unsupported_event_cursor");
22
- const position = BigInt(cursor.slice(prefix.length));
23
- if (position > 9223372036854775807n)
24
- throw new TypeError("invalid_or_unsupported_event_cursor");
25
- return position;
26
- };
27
14
  const controller = new AbortController();
28
15
  let checkpoint = options.after;
29
16
  let timer;
@@ -32,64 +19,51 @@ subject) {
32
19
  return;
33
20
  let delay = interval;
34
21
  try {
35
- let acknowledged = checkpoint === undefined ? 0n : positionOf(checkpoint);
36
22
  const page = await read(checkpoint, controller.signal);
37
23
  if (controller.signal.aborted)
38
24
  return;
39
25
  if (!page ||
40
- !Array.isArray(page.events) ||
41
- page.events.length > 100 ||
42
- typeof page.has_more !== "boolean" ||
43
- !VALID_EVENT_TIME(page.server_time))
26
+ !Array.isArray(page["edges"]) ||
27
+ page["edges"].length > 100 ||
28
+ !page["pageInfo"] ||
29
+ typeof page["pageInfo"]["hasNextPage"] !== "boolean")
44
30
  throw new TypeError("invalid_event_response");
45
- const next = positionOf(page.next_cursor);
46
- const identities = new Map();
47
- let previous = -1n;
48
- const positions = page.events.map((event) => {
49
- if (!event ||
50
- event.version !== 1 ||
51
- typeof event.id !== "string" ||
52
- !event.id ||
53
- event.id.length > 128 ||
54
- typeof event.type !== "string" ||
55
- !event.type ||
56
- !event.payload ||
57
- typeof event.payload !== "object" ||
58
- Array.isArray(event.payload) ||
59
- !VALID_EVENT_TIME(event.occurred_at))
60
- throw new TypeError("invalid_event_response");
61
- const position = positionOf(event.cursor);
62
- if (position === 0n || position < previous)
31
+ const next = page["pageInfo"]["endCursor"];
32
+ const identities = new Set();
33
+ for (const { ["node"]: event, ["cursor"]: cursor } of page["edges"]) {
34
+ if (typeof cursor !== "string" ||
35
+ !cursor ||
36
+ !event ||
37
+ event["version"] !== 1 ||
38
+ typeof event["id"] !== "string" ||
39
+ !event["id"] ||
40
+ identities.has(event["id"]) ||
41
+ typeof event["type"] !== "string" ||
42
+ !event["type"] ||
43
+ !event["payload"] ||
44
+ typeof event["payload"] !== "object" ||
45
+ Array.isArray(event["payload"]) ||
46
+ !VALID_EVENT_TIME(event["occurred_at"]))
63
47
  throw new TypeError("invalid_event_response");
64
- const identity = JSON.stringify(event);
65
- if ((identities.has(event.id) && identities.get(event.id) !== identity) ||
66
- (position === previous && identities.get(event.id) !== identity))
67
- throw new TypeError("invalid_event_response");
68
- identities.set(event.id, identity);
69
- previous = position;
70
- return position;
71
- });
72
- if (page.events.length ? next !== positions.at(-1) : next !== acknowledged || page.has_more)
48
+ identities.add(event["id"]);
49
+ }
50
+ if (page["edges"].length
51
+ ? next !== page["edges"].at(-1)["cursor"]
52
+ : next !== null || page["pageInfo"]["hasNextPage"])
73
53
  throw new TypeError("invalid_event_response");
74
- if (page.has_more && next <= acknowledged)
54
+ if (page["pageInfo"]["hasNextPage"] && next === checkpoint)
75
55
  throw new TypeError("invalid_event_response");
76
- for (let index = 0; index < page.events.length; index++) {
56
+ const acknowledgedIndex = page["edges"].findIndex((edge) => edge["cursor"] === checkpoint);
57
+ for (const edge of page["edges"].slice(acknowledgedIndex + 1)) {
77
58
  if (controller.signal.aborted)
78
59
  return;
79
- const event = page.events[index];
80
- const position = positions[index];
81
- // Stable bank/event identities retain their publication position. Old/repeated pages cannot repeat effects.
82
- if (position <= acknowledged)
83
- continue;
84
- const decoded = decode(event);
60
+ const decoded = decode(edge["node"]);
85
61
  if (decoded !== null)
86
- await handler(decoded);
87
- checkpoint = event.cursor;
88
- acknowledged = position;
62
+ await handler(decoded, edge["cursor"]);
63
+ await options.onCheckpoint?.(edge["cursor"]);
64
+ checkpoint = edge["cursor"];
89
65
  }
90
- if (checkpoint === undefined)
91
- checkpoint = page.next_cursor;
92
- if (page.has_more)
66
+ if (page["pageInfo"]["hasNextPage"])
93
67
  delay = 0;
94
68
  }
95
69
  catch (error) {