@andco/protocol 0.0.1

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 (126) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +44 -0
  3. package/dist/authorization-preparation.d.ts +754 -0
  4. package/dist/authorization-preparation.d.ts.map +1 -0
  5. package/dist/authorization-preparation.js +187 -0
  6. package/dist/authorization.d.ts +99 -0
  7. package/dist/authorization.d.ts.map +1 -0
  8. package/dist/authorization.js +227 -0
  9. package/dist/automatic-charge.d.ts +314 -0
  10. package/dist/automatic-charge.d.ts.map +1 -0
  11. package/dist/automatic-charge.js +126 -0
  12. package/dist/bank-account-authorization.d.ts +6 -0
  13. package/dist/bank-account-authorization.d.ts.map +1 -0
  14. package/dist/bank-account-authorization.js +13 -0
  15. package/dist/callback-state.d.ts +10 -0
  16. package/dist/callback-state.d.ts.map +1 -0
  17. package/dist/callback-state.js +28 -0
  18. package/dist/consent.d.ts +48 -0
  19. package/dist/consent.d.ts.map +1 -0
  20. package/dist/consent.js +110 -0
  21. package/dist/constants.d.ts +17 -0
  22. package/dist/constants.d.ts.map +1 -0
  23. package/dist/constants.js +20 -0
  24. package/dist/errors.d.ts +70 -0
  25. package/dist/errors.d.ts.map +1 -0
  26. package/dist/errors.js +80 -0
  27. package/dist/index.d.ts +33 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +32 -0
  30. package/dist/intent-input.d.ts +637 -0
  31. package/dist/intent-input.d.ts.map +1 -0
  32. package/dist/intent-input.js +101 -0
  33. package/dist/messages/authorization-response.d.ts +12 -0
  34. package/dist/messages/authorization-response.d.ts.map +1 -0
  35. package/dist/messages/authorization-response.js +9 -0
  36. package/dist/messages/base.d.ts +31 -0
  37. package/dist/messages/base.d.ts.map +1 -0
  38. package/dist/messages/base.js +30 -0
  39. package/dist/messages/click.d.ts +11 -0
  40. package/dist/messages/click.d.ts.map +1 -0
  41. package/dist/messages/click.js +8 -0
  42. package/dist/messages/error.d.ts +13 -0
  43. package/dist/messages/error.d.ts.map +1 -0
  44. package/dist/messages/error.js +9 -0
  45. package/dist/messages/index.d.ts +75 -0
  46. package/dist/messages/index.d.ts.map +1 -0
  47. package/dist/messages/index.js +27 -0
  48. package/dist/messages/init.d.ts +9 -0
  49. package/dist/messages/init.d.ts.map +1 -0
  50. package/dist/messages/init.js +6 -0
  51. package/dist/messages/popup.d.ts +108 -0
  52. package/dist/messages/popup.d.ts.map +1 -0
  53. package/dist/messages/popup.js +62 -0
  54. package/dist/messages/ready.d.ts +9 -0
  55. package/dist/messages/ready.d.ts.map +1 -0
  56. package/dist/messages/ready.js +6 -0
  57. package/dist/messages/set-preferences.d.ts +16 -0
  58. package/dist/messages/set-preferences.d.ts.map +1 -0
  59. package/dist/messages/set-preferences.js +20 -0
  60. package/dist/miniapp-icon.d.ts +4 -0
  61. package/dist/miniapp-icon.d.ts.map +1 -0
  62. package/dist/miniapp-icon.js +68 -0
  63. package/dist/miniapp-manifest.d.ts +71 -0
  64. package/dist/miniapp-manifest.d.ts.map +1 -0
  65. package/dist/miniapp-manifest.js +46 -0
  66. package/dist/native-copy.d.ts +7 -0
  67. package/dist/native-copy.d.ts.map +1 -0
  68. package/dist/native-copy.js +436 -0
  69. package/dist/native-intent.d.ts +402 -0
  70. package/dist/native-intent.d.ts.map +1 -0
  71. package/dist/native-intent.js +410 -0
  72. package/dist/native.d.ts +55 -0
  73. package/dist/native.d.ts.map +1 -0
  74. package/dist/native.js +53 -0
  75. package/dist/oauth.d.ts +4 -0
  76. package/dist/oauth.d.ts.map +1 -0
  77. package/dist/oauth.js +3 -0
  78. package/dist/release.d.ts +3 -0
  79. package/dist/release.d.ts.map +1 -0
  80. package/dist/release.js +2 -0
  81. package/dist/scopes.d.ts +35 -0
  82. package/dist/scopes.d.ts.map +1 -0
  83. package/dist/scopes.js +15 -0
  84. package/dist/server.d.ts +9 -0
  85. package/dist/server.d.ts.map +1 -0
  86. package/dist/server.js +14 -0
  87. package/dist/transport/financial-events.d.ts +134 -0
  88. package/dist/transport/financial-events.d.ts.map +1 -0
  89. package/dist/transport/financial-events.js +120 -0
  90. package/dist/transport/generated/oauth-api.d.ts +1685 -0
  91. package/dist/transport/generated/oauth-api.d.ts.map +1 -0
  92. package/dist/transport/generated/oauth-api.js +5 -0
  93. package/dist/transport/index.d.ts +6 -0
  94. package/dist/transport/index.d.ts.map +1 -0
  95. package/dist/transport/index.js +5 -0
  96. package/dist/transport/intents.d.ts +81 -0
  97. package/dist/transport/intents.d.ts.map +1 -0
  98. package/dist/transport/intents.js +286 -0
  99. package/dist/transport/rest.d.ts +76 -0
  100. package/dist/transport/rest.d.ts.map +1 -0
  101. package/dist/transport/rest.js +48 -0
  102. package/dist/transport/runtime.d.ts +8 -0
  103. package/dist/transport/runtime.d.ts.map +1 -0
  104. package/dist/transport/runtime.js +16 -0
  105. package/dist/transport/webhooks.d.ts +27 -0
  106. package/dist/transport/webhooks.d.ts.map +1 -0
  107. package/dist/transport/webhooks.js +68 -0
  108. package/dist/urls.d.ts +71 -0
  109. package/dist/urls.d.ts.map +1 -0
  110. package/dist/urls.js +132 -0
  111. package/dist/userinfo.d.ts +11 -0
  112. package/dist/userinfo.d.ts.map +1 -0
  113. package/dist/userinfo.js +9 -0
  114. package/dist/utils.d.ts +20 -0
  115. package/dist/utils.d.ts.map +1 -0
  116. package/dist/utils.js +45 -0
  117. package/dist/webhook-input.d.ts +22 -0
  118. package/dist/webhook-input.d.ts.map +1 -0
  119. package/dist/webhook-input.js +11 -0
  120. package/dist/webhook-signature.d.ts +54 -0
  121. package/dist/webhook-signature.d.ts.map +1 -0
  122. package/dist/webhook-signature.js +74 -0
  123. package/dist/window-features.d.ts +28 -0
  124. package/dist/window-features.d.ts.map +1 -0
  125. package/dist/window-features.js +55 -0
  126. package/package.json +63 -0
@@ -0,0 +1,134 @@
1
+ /** Durable financial fact. Presentation messages are never financial events. */
2
+ export type AndCoFinancialEvent<T extends string = string, P = Record<string, unknown>> = {
3
+ id: string;
4
+ type: T;
5
+ payload: P;
6
+ version: 1;
7
+ occurred_at: string;
8
+ cursor: string;
9
+ };
10
+ export type AndCoIntentDepositEvent = AndCoFinancialEvent<"deposit.target_updated", {
11
+ intent_id: string;
12
+ target: string;
13
+ currency: "CLP";
14
+ }> | AndCoFinancialEvent<"deposit.closed", {
15
+ intent_id: string;
16
+ status: "closed";
17
+ total: string;
18
+ closed_at: string;
19
+ }> | AndCoFinancialEvent<"deposit.expired", {
20
+ intent_id: string;
21
+ status: "expired";
22
+ expires_at: string;
23
+ }> | AndCoFinancialEvent<"deposit.assigned", {
24
+ intent_id: string;
25
+ movement_id: string;
26
+ transaction_id: string;
27
+ amount: string;
28
+ currency: "CLP";
29
+ received_at: string;
30
+ note: string | null;
31
+ total: string;
32
+ late: boolean;
33
+ }> | AndCoFinancialEvent<"deposit.unassigned", {
34
+ intent_id: string;
35
+ movement_id: string;
36
+ transaction_id: string;
37
+ amount: string;
38
+ currency: "CLP";
39
+ total: string;
40
+ }> | AndCoFinancialEvent<"deposit.completed", {
41
+ intent_id: string;
42
+ status: "completed";
43
+ total: string;
44
+ target: string;
45
+ completed_at: string;
46
+ }>;
47
+ /** An account-wide bank fact, independent of application attribution. */
48
+ export type AndCoDepositEvent = AndCoFinancialEvent<"deposit.received", {
49
+ account_id: string;
50
+ movement_id: string;
51
+ transaction_id: string;
52
+ amount: string;
53
+ currency: "CLP";
54
+ received_at: string;
55
+ note: string | null;
56
+ outcome: "credited";
57
+ }> | AndCoFinancialEvent<"deposit.reversed", {
58
+ account_id: string;
59
+ movement_id: string;
60
+ transaction_id: string;
61
+ amount: string;
62
+ currency: "CLP";
63
+ received_at: string;
64
+ note: string | null;
65
+ outcome: "reversed";
66
+ observed_at: string;
67
+ }>;
68
+ /** A posted debit or bank reversal, independent of any application request. */
69
+ export type AndCoWithdrawalEvent = AndCoFinancialEvent<"withdrawal.posted", {
70
+ account_id: string;
71
+ movement_id: string;
72
+ transaction_id: string;
73
+ amount: string;
74
+ currency: "CLP";
75
+ posted_at: string;
76
+ note: string | null;
77
+ outcome: "posted";
78
+ }> | AndCoFinancialEvent<"withdrawal.reversed", {
79
+ account_id: string;
80
+ movement_id: string;
81
+ transaction_id: string;
82
+ amount: string;
83
+ currency: "CLP";
84
+ posted_at: string;
85
+ note: string | null;
86
+ outcome: "reversed";
87
+ observed_at: string;
88
+ }>;
89
+ /** Frozen human-confirmed values; these do not assert that a debit was posted. */
90
+ export type AndCoConfirmedWithdrawal = {
91
+ source_account_id: string;
92
+ amount: string;
93
+ currency: "CLP";
94
+ beneficiary: import("./intents.js").AndCoBankAccountReference;
95
+ note: string;
96
+ };
97
+ export type AndCoIntentWithdrawalEvent = AndCoFinancialEvent<`${"withdrawal" | "automatic_charge"}.expired`, {
98
+ intent_id: string;
99
+ status: "expired";
100
+ expires_at: string;
101
+ }> | AndCoFinancialEvent<`${"withdrawal" | "automatic_charge"}.${"confirmed" | "succeeded" | "failed" | "cancelled"}`, {
102
+ intent_id: string;
103
+ status: string;
104
+ detail: string | null;
105
+ operation: AndCoConfirmedWithdrawal | null;
106
+ transaction_id: string | null;
107
+ observed_at: string;
108
+ }>;
109
+ export type AndCoEventPage = {
110
+ events: AndCoFinancialEvent[];
111
+ next_cursor: string;
112
+ has_more: boolean;
113
+ server_time: string;
114
+ };
115
+ export type AndCoEventSubscriptionOptions = {
116
+ /** Resume after a checkpoint previously acknowledged by this subject's subscription. */
117
+ after?: string;
118
+ /** Receives transport, authorization, cursor, and handler failures. Throwing here stops the subscription. */
119
+ onError: (error: unknown) => void;
120
+ pollIntervalMs?: number;
121
+ };
122
+ export type AndCoEventSubscription = {
123
+ unsubscribe(): void;
124
+ /** Persist only acknowledged checkpoints; a failed handler leaves this value unchanged. */
125
+ readonly checkpoint: string | undefined;
126
+ };
127
+ /** Reconciles bounded durable pages; the SDK owns cursor decoding, while callers persist opaque values. */
128
+ export declare function subscribeFinancialEvents<E extends AndCoFinancialEvent>(read: (after: string | undefined, signal: AbortSignal) => Promise<AndCoEventPage>, decode: (event: AndCoFinancialEvent) => E | null, handler: (event: E) => void | Promise<void>, options: AndCoEventSubscriptionOptions,
129
+ /** Scopes the cursor namespace. Any caller-chosen `kind` works; only its consistency is checked. */
130
+ subject: {
131
+ kind: string;
132
+ id: string;
133
+ }): AndCoEventSubscription;
134
+ //# sourceMappingURL=financial-events.d.ts.map
@@ -0,0 +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,MAAM,MAAM,uBAAuB,GAC/B,mBAAmB,CACjB,wBAAwB,EACxB;IACE,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,KAAK,CAAC;CACjB,CACF,GACD,mBAAmB,CACjB,gBAAgB,EAChB;IACE,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,QAAQ,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB,CACF,GACD,mBAAmB,CACjB,iBAAiB,EACjB;IACE,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,SAAS,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,CACF,GACD,mBAAmB,CACjB,kBAAkB,EAClB;IACE,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;I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AA;CAAE,GACpC,sBAAsB,CAyGxB"}
@@ -0,0 +1,120 @@
1
+ /** Reconciles bounded durable pages; the SDK owns cursor decoding, while callers persist opaque values. */
2
+ export function subscribeFinancialEvents(read, decode, handler, options,
3
+ /** Scopes the cursor namespace. Any caller-chosen `kind` works; only its consistency is checked. */
4
+ subject) {
5
+ const interval = options.pollIntervalMs ?? 1000;
6
+ if (!Number.isSafeInteger(interval) || interval < 100)
7
+ throw new TypeError("Invalid event polling interval");
8
+ if (typeof options.onError !== "function")
9
+ throw new TypeError("An event error handler is required");
10
+ const prefix = `v1:${subject.kind}:${subject.id.toLowerCase()}:`;
11
+ const positionOf = (cursor) => {
12
+ if (typeof cursor !== "string" ||
13
+ !cursor.startsWith(prefix) ||
14
+ !/^(0|[1-9][0-9]{0,18})$/.test(cursor.slice(prefix.length)))
15
+ throw new TypeError("invalid_or_unsupported_event_cursor");
16
+ const position = BigInt(cursor.slice(prefix.length));
17
+ if (position > 9223372036854775807n)
18
+ throw new TypeError("invalid_or_unsupported_event_cursor");
19
+ return position;
20
+ };
21
+ const controller = new AbortController();
22
+ let checkpoint = options.after;
23
+ let timer;
24
+ const poll = async () => {
25
+ if (controller.signal.aborted)
26
+ return;
27
+ let delay = interval;
28
+ try {
29
+ let acknowledged = checkpoint === undefined ? 0n : positionOf(checkpoint);
30
+ const page = await read(checkpoint, controller.signal);
31
+ if (controller.signal.aborted)
32
+ return;
33
+ if (!page ||
34
+ !Array.isArray(page.events) ||
35
+ page.events.length > 100 ||
36
+ typeof page.has_more !== "boolean" ||
37
+ !VALID_EVENT_TIME(page.server_time))
38
+ throw new TypeError("invalid_event_response");
39
+ const next = positionOf(page.next_cursor);
40
+ const identities = new Map();
41
+ let previous = -1n;
42
+ const positions = page.events.map((event) => {
43
+ if (!event ||
44
+ event.version !== 1 ||
45
+ typeof event.id !== "string" ||
46
+ !event.id ||
47
+ event.id.length > 128 ||
48
+ typeof event.type !== "string" ||
49
+ !event.type ||
50
+ !event.payload ||
51
+ typeof event.payload !== "object" ||
52
+ Array.isArray(event.payload) ||
53
+ !VALID_EVENT_TIME(event.occurred_at))
54
+ throw new TypeError("invalid_event_response");
55
+ const position = positionOf(event.cursor);
56
+ if (position === 0n || position < previous)
57
+ throw new TypeError("invalid_event_response");
58
+ const identity = JSON.stringify(event);
59
+ if ((identities.has(event.id) && identities.get(event.id) !== identity) ||
60
+ (position === previous && identities.get(event.id) !== identity))
61
+ throw new TypeError("invalid_event_response");
62
+ identities.set(event.id, identity);
63
+ previous = position;
64
+ return position;
65
+ });
66
+ if (page.events.length ? next !== positions.at(-1) : next !== acknowledged || page.has_more)
67
+ throw new TypeError("invalid_event_response");
68
+ if (page.has_more && next <= acknowledged)
69
+ throw new TypeError("invalid_event_response");
70
+ for (let index = 0; index < page.events.length; index++) {
71
+ if (controller.signal.aborted)
72
+ return;
73
+ const event = page.events[index];
74
+ const position = positions[index];
75
+ // Stable bank/event identities retain their publication position. Old/repeated pages cannot repeat effects.
76
+ if (position <= acknowledged)
77
+ continue;
78
+ const decoded = decode(event);
79
+ if (decoded !== null)
80
+ await handler(decoded);
81
+ checkpoint = event.cursor;
82
+ acknowledged = position;
83
+ }
84
+ if (checkpoint === undefined)
85
+ checkpoint = page.next_cursor;
86
+ if (page.has_more)
87
+ delay = 0;
88
+ }
89
+ catch (error) {
90
+ if (controller.signal.aborted)
91
+ return;
92
+ // A broken error callback stops this subscription without producing an unhandled rejection.
93
+ try {
94
+ await options.onError(error);
95
+ }
96
+ catch {
97
+ controller.abort();
98
+ }
99
+ }
100
+ finally {
101
+ if (!controller.signal.aborted)
102
+ timer = setTimeout(() => {
103
+ void poll();
104
+ }, delay);
105
+ }
106
+ };
107
+ void poll();
108
+ return {
109
+ unsubscribe() {
110
+ controller.abort();
111
+ clearTimeout(timer);
112
+ },
113
+ get checkpoint() {
114
+ return checkpoint;
115
+ },
116
+ };
117
+ }
118
+ function VALID_EVENT_TIME(value) {
119
+ return typeof value === "string" && /^\d{4}-\d{2}-\d{2}T/.test(value) && Number.isFinite(Date.parse(value));
120
+ }