@easyslip/sdk 0.0.0-stage → 1.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 (87) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/LICENSE +21 -0
  3. package/README.md +595 -2
  4. package/README.th.md +610 -0
  5. package/dist/cjs/client.d.ts +59 -0
  6. package/dist/cjs/client.js +150 -0
  7. package/dist/cjs/core/call.d.ts +18 -0
  8. package/dist/cjs/core/call.js +60 -0
  9. package/dist/cjs/core/error-codes.d.ts +8 -0
  10. package/dist/cjs/core/error-codes.js +87 -0
  11. package/dist/cjs/core/errors.d.ts +162 -0
  12. package/dist/cjs/core/errors.js +210 -0
  13. package/dist/cjs/core/files.d.ts +20 -0
  14. package/dist/cjs/core/files.js +131 -0
  15. package/dist/cjs/core/http.d.ts +65 -0
  16. package/dist/cjs/core/http.js +242 -0
  17. package/dist/cjs/core/meta.d.ts +33 -0
  18. package/dist/cjs/core/meta.js +52 -0
  19. package/dist/cjs/core/redact.d.ts +43 -0
  20. package/dist/cjs/core/redact.js +208 -0
  21. package/dist/cjs/core/runtime.d.ts +16 -0
  22. package/dist/cjs/core/runtime.js +86 -0
  23. package/dist/cjs/core/settings.d.ts +19 -0
  24. package/dist/cjs/core/settings.js +22 -0
  25. package/dist/cjs/core/sha256.d.ts +6 -0
  26. package/dist/cjs/core/sha256.js +101 -0
  27. package/dist/cjs/index.d.ts +13 -0
  28. package/dist/cjs/index.js +55 -0
  29. package/dist/cjs/models.d.ts +398 -0
  30. package/dist/cjs/models.js +234 -0
  31. package/dist/cjs/package.json +1 -0
  32. package/dist/cjs/resources/bank-accounts.d.ts +63 -0
  33. package/dist/cjs/resources/bank-accounts.js +126 -0
  34. package/dist/cjs/resources/banks.d.ts +10 -0
  35. package/dist/cjs/resources/banks.js +22 -0
  36. package/dist/cjs/resources/jobs.d.ts +64 -0
  37. package/dist/cjs/resources/jobs.js +177 -0
  38. package/dist/cjs/resources/v1.d.ts +88 -0
  39. package/dist/cjs/resources/v1.js +137 -0
  40. package/dist/cjs/resources/verify.d.ts +39 -0
  41. package/dist/cjs/resources/verify.js +105 -0
  42. package/dist/cjs/version.d.ts +2 -0
  43. package/dist/cjs/version.js +5 -0
  44. package/dist/cjs/webhooks.d.ts +26 -0
  45. package/dist/cjs/webhooks.js +92 -0
  46. package/dist/esm/client.d.ts +59 -0
  47. package/dist/esm/client.js +146 -0
  48. package/dist/esm/core/call.d.ts +18 -0
  49. package/dist/esm/core/call.js +52 -0
  50. package/dist/esm/core/error-codes.d.ts +8 -0
  51. package/dist/esm/core/error-codes.js +84 -0
  52. package/dist/esm/core/errors.d.ts +162 -0
  53. package/dist/esm/core/errors.js +184 -0
  54. package/dist/esm/core/files.d.ts +20 -0
  55. package/dist/esm/core/files.js +126 -0
  56. package/dist/esm/core/http.d.ts +65 -0
  57. package/dist/esm/core/http.js +235 -0
  58. package/dist/esm/core/meta.d.ts +33 -0
  59. package/dist/esm/core/meta.js +45 -0
  60. package/dist/esm/core/redact.d.ts +43 -0
  61. package/dist/esm/core/redact.js +198 -0
  62. package/dist/esm/core/runtime.d.ts +16 -0
  63. package/dist/esm/core/runtime.js +47 -0
  64. package/dist/esm/core/settings.d.ts +19 -0
  65. package/dist/esm/core/settings.js +19 -0
  66. package/dist/esm/core/sha256.d.ts +6 -0
  67. package/dist/esm/core/sha256.js +96 -0
  68. package/dist/esm/index.d.ts +13 -0
  69. package/dist/esm/index.js +7 -0
  70. package/dist/esm/models.d.ts +398 -0
  71. package/dist/esm/models.js +228 -0
  72. package/dist/esm/package.json +1 -0
  73. package/dist/esm/resources/bank-accounts.d.ts +63 -0
  74. package/dist/esm/resources/bank-accounts.js +122 -0
  75. package/dist/esm/resources/banks.d.ts +10 -0
  76. package/dist/esm/resources/banks.js +18 -0
  77. package/dist/esm/resources/jobs.d.ts +64 -0
  78. package/dist/esm/resources/jobs.js +173 -0
  79. package/dist/esm/resources/v1.d.ts +88 -0
  80. package/dist/esm/resources/v1.js +133 -0
  81. package/dist/esm/resources/verify.d.ts +39 -0
  82. package/dist/esm/resources/verify.js +100 -0
  83. package/dist/esm/version.d.ts +2 -0
  84. package/dist/esm/version.js +2 -0
  85. package/dist/esm/webhooks.d.ts +26 -0
  86. package/dist/esm/webhooks.js +86 -0
  87. package/package.json +80 -5
@@ -0,0 +1,96 @@
1
+ // Synchronous SHA-256 and HMAC-SHA256 (FIPS 180-4, RFC 2104), so webhook checks need no
2
+ // async Web Crypto call and no Node built-in.
3
+ const K = new Uint32Array([
4
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
5
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
6
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
7
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
8
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
9
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
10
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
11
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
12
+ ]);
13
+ /** SHA-256 digest of `data`. */
14
+ export function sha256(data) {
15
+ const bitLength = data.length * 8;
16
+ const padded = new Uint8Array((((data.length + 9 + 63) >> 6) << 6) >>> 0);
17
+ padded.set(data);
18
+ padded[data.length] = 0x80;
19
+ const view = new DataView(padded.buffer);
20
+ view.setUint32(padded.length - 8, Math.floor(bitLength / 0x100000000));
21
+ view.setUint32(padded.length - 4, bitLength >>> 0);
22
+ const h = new Uint32Array([
23
+ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab,
24
+ 0x5be0cd19,
25
+ ]);
26
+ const w = new Uint32Array(64);
27
+ for (let offset = 0; offset < padded.length; offset += 64) {
28
+ for (let i = 0; i < 16; i++)
29
+ w[i] = view.getUint32(offset + i * 4);
30
+ for (let i = 16; i < 64; i++) {
31
+ const w15 = w[i - 15];
32
+ const w2 = w[i - 2];
33
+ const s0 = ((w15 >>> 7) | (w15 << 25)) ^ ((w15 >>> 18) | (w15 << 14)) ^ (w15 >>> 3);
34
+ const s1 = ((w2 >>> 17) | (w2 << 15)) ^ ((w2 >>> 19) | (w2 << 13)) ^ (w2 >>> 10);
35
+ w[i] = (w[i - 16] + s0 + w[i - 7] + s1) >>> 0;
36
+ }
37
+ let a = h[0];
38
+ let b = h[1];
39
+ let c = h[2];
40
+ let d = h[3];
41
+ let e = h[4];
42
+ let f = h[5];
43
+ let g = h[6];
44
+ let hh = h[7];
45
+ for (let i = 0; i < 64; i++) {
46
+ const S1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7));
47
+ const ch = (e & f) ^ (~e & g);
48
+ const t1 = (hh + S1 + ch + K[i] + w[i]) >>> 0;
49
+ const S0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10));
50
+ const maj = (a & b) ^ (a & c) ^ (b & c);
51
+ const t2 = (S0 + maj) >>> 0;
52
+ hh = g;
53
+ g = f;
54
+ f = e;
55
+ e = (d + t1) >>> 0;
56
+ d = c;
57
+ c = b;
58
+ b = a;
59
+ a = (t1 + t2) >>> 0;
60
+ }
61
+ h[0] = (h[0] + a) >>> 0;
62
+ h[1] = (h[1] + b) >>> 0;
63
+ h[2] = (h[2] + c) >>> 0;
64
+ h[3] = (h[3] + d) >>> 0;
65
+ h[4] = (h[4] + e) >>> 0;
66
+ h[5] = (h[5] + f) >>> 0;
67
+ h[6] = (h[6] + g) >>> 0;
68
+ h[7] = (h[7] + hh) >>> 0;
69
+ }
70
+ const out = new Uint8Array(32);
71
+ const outView = new DataView(out.buffer);
72
+ for (let i = 0; i < 8; i++)
73
+ outView.setUint32(i * 4, h[i]);
74
+ return out;
75
+ }
76
+ /** HMAC-SHA256 of `message` under `key`. */
77
+ export function hmacSha256(key, message) {
78
+ const block = new Uint8Array(64);
79
+ block.set(key.length > 64 ? sha256(key) : key);
80
+ const inner = new Uint8Array(64 + message.length);
81
+ const outer = new Uint8Array(64 + 32);
82
+ for (let i = 0; i < 64; i++) {
83
+ inner[i] = block[i] ^ 0x36;
84
+ outer[i] = block[i] ^ 0x5c;
85
+ }
86
+ inner.set(message, 64);
87
+ outer.set(sha256(inner), 64);
88
+ return sha256(outer);
89
+ }
90
+ /** Lower-case hex of `bytes`. */
91
+ export function toHex(bytes) {
92
+ let out = '';
93
+ for (const byte of bytes)
94
+ out += byte.toString(16).padStart(2, '0');
95
+ return out;
96
+ }
@@ -0,0 +1,13 @@
1
+ export { Client, Client as EasySlip, type ClientOptions } from './client.js';
2
+ export { ApiError, type ApiErrorInit, AuthenticationError, BatchSubmitError, ConflictError, DuplicateSlipError, EasySlipError, type ErrorDetails, InputError, type InputErrorCode, InvalidImageError, InvalidRequestError, InvalidUrlError, JobWaitTimeoutError, NetworkError, NotFoundError, PermissionDeniedError, QuotaExceededError, RateLimitError, RequestTimeoutError, ServerError, ServiceUnavailableError, SlipNotFoundError, SlipPendingError, WebhookSignatureError, } from './core/errors.js';
3
+ export { type FileInput, MAX_IMAGE_BYTES } from './core/files.js';
4
+ export type { FetchLike, RequestOptions, RetryClass } from './core/http.js';
5
+ export type { RateLimit, ResponseMeta, WithMeta } from './core/meta.js';
6
+ export * from './models.js';
7
+ export type { AccountType, BankAccounts, CreateBankAccountParams, ListBankAccountsParams, UpdateBankAccountParams, } from './resources/bank-accounts.js';
8
+ export type { Banks } from './resources/banks.js';
9
+ export { type AsyncVerifyOptions, BATCH_MAX, type BatchOptions, type BatchSlip, type Jobs, type WaitForJobOptions, } from './resources/jobs.js';
10
+ export type { BillPaymentQr, MerchantQr, PromptPayQr, QrCodeResult, QrRequest, QrType, TungNgernQr, V1, V1VerifyOptions, } from './resources/v1.js';
11
+ export type { Verify, VerifyCallOptions, VerifyOptions } from './resources/verify.js';
12
+ export { VERSION } from './version.js';
13
+ export { constructWebhookEvent, parseWebhookEvent, type SignatureHeader, verifyWebhookSignature, WEBHOOK_SIGNATURE_HEADER, type WebhookBody, } from './webhooks.js';
@@ -0,0 +1,7 @@
1
+ export { Client, Client as EasySlip } from './client.js';
2
+ export { ApiError, AuthenticationError, BatchSubmitError, ConflictError, DuplicateSlipError, EasySlipError, InputError, InvalidImageError, InvalidRequestError, InvalidUrlError, JobWaitTimeoutError, NetworkError, NotFoundError, PermissionDeniedError, QuotaExceededError, RateLimitError, RequestTimeoutError, ServerError, ServiceUnavailableError, SlipNotFoundError, SlipPendingError, WebhookSignatureError, } from './core/errors.js';
3
+ export { MAX_IMAGE_BYTES } from './core/files.js';
4
+ export * from './models.js';
5
+ export { BATCH_MAX, } from './resources/jobs.js';
6
+ export { VERSION } from './version.js';
7
+ export { constructWebhookEvent, parseWebhookEvent, verifyWebhookSignature, WEBHOOK_SIGNATURE_HEADER, } from './webhooks.js';
@@ -0,0 +1,398 @@
1
+ /** A string union that still accepts values added by the API later. */
2
+ export type Open<T extends string> = T | (string & {});
3
+ /** `GET /info`: the application, branch, account and plan behind the API key. */
4
+ export interface Info {
5
+ application: InfoApplication;
6
+ branch: InfoBranch;
7
+ account: InfoAccount;
8
+ product: InfoProduct;
9
+ }
10
+ export interface InfoApplication {
11
+ /** Application name. */
12
+ name: string;
13
+ autoRenew: AutoRenew;
14
+ quota: ApplicationQuota;
15
+ }
16
+ export interface AutoRenew {
17
+ /** Auto renew of the expiry date is on. */
18
+ expired: boolean;
19
+ /** Auto renew of the quota is on. */
20
+ quota: boolean;
21
+ createdAt: string;
22
+ expiresAt: string;
23
+ }
24
+ export interface ApplicationQuota {
25
+ /** Used in the current period. */
26
+ used: number;
27
+ /** Period limit, null when unlimited. */
28
+ max: number | null;
29
+ /** Left in the current period, null when unlimited. */
30
+ remaining: number | null;
31
+ /** Used since the application was created. */
32
+ totalUsed: number;
33
+ }
34
+ export interface InfoBranch {
35
+ name: string;
36
+ isActive: boolean;
37
+ quota: BranchQuota;
38
+ }
39
+ export interface BranchQuota {
40
+ used: number;
41
+ totalUsed: number;
42
+ }
43
+ export interface InfoAccount {
44
+ email: string;
45
+ /** Account credit balance. */
46
+ credit: number;
47
+ }
48
+ export interface InfoProduct {
49
+ /** Plan name. */
50
+ name: string;
51
+ }
52
+ /** A bank transfer slip as the bank reported it. v2 `rawSlip`, v1 verify `data`. */
53
+ export interface BankSlip {
54
+ payload: string;
55
+ transRef: string;
56
+ /** Transfer time, ISO 8601 with offset. */
57
+ date: string;
58
+ /** Country code, may be empty. */
59
+ countryCode: string;
60
+ amount: SlipAmount;
61
+ fee?: number;
62
+ ref1?: string;
63
+ ref2?: string;
64
+ ref3?: string;
65
+ sender: SlipParty;
66
+ receiver: SlipReceiver;
67
+ }
68
+ export interface SlipAmount {
69
+ amount: number;
70
+ local: LocalAmount;
71
+ }
72
+ /** Foreign leg of the transfer; `0` and `''` when there is none. */
73
+ export interface LocalAmount {
74
+ amount?: number;
75
+ currency?: string;
76
+ }
77
+ export interface SlipParty {
78
+ bank?: SlipBank;
79
+ account: SlipAccount;
80
+ }
81
+ export interface SlipReceiver extends SlipParty {
82
+ /** Merchant id; v2 sends it (often empty), v1 leaves it out. */
83
+ merchantId?: string | null;
84
+ }
85
+ export interface SlipBank {
86
+ /**
87
+ * Bank code, for example `004`. Absent when the bank is unknown: v1 then sends the receiver
88
+ * bank as an empty object.
89
+ */
90
+ id?: string;
91
+ name?: string;
92
+ short?: string;
93
+ }
94
+ export interface SlipAccount {
95
+ name: AccountName;
96
+ bank?: AccountNumber;
97
+ proxy?: AccountNumber;
98
+ }
99
+ /** Account holder name. v2 may send empty strings, v1 leaves empty names out. */
100
+ export interface AccountName {
101
+ th?: string;
102
+ en?: string;
103
+ }
104
+ /** A masked account number or proxy id. */
105
+ export interface AccountNumber {
106
+ /** `BANKAC`, `TOKEN`, `DUMMY` for accounts; `NATID`, `MSISDN`, `EWALLETID`, `EMAIL`, `BILLERID` for proxies. */
107
+ type: Open<'BANKAC' | 'TOKEN' | 'DUMMY' | 'NATID' | 'MSISDN' | 'EWALLETID' | 'EMAIL' | 'BILLERID'>;
108
+ account: string;
109
+ }
110
+ /** Known values of {@link MatchedAccount.type}. */
111
+ export declare const MatchedAccountType: {
112
+ readonly Personal: 'PERSONAL';
113
+ readonly Natural: 'NATURAL';
114
+ readonly Juristic: 'JURISTIC';
115
+ };
116
+ /** The registered bank account the slip's receiver matched (`matchAccount: true`). */
117
+ export interface MatchedAccount {
118
+ bank: MatchedBank;
119
+ nameTh: string;
120
+ nameEn: string;
121
+ /** `PERSONAL`, `NATURAL` or `JURISTIC`. */
122
+ type: Open<(typeof MatchedAccountType)[keyof typeof MatchedAccountType]>;
123
+ bankNumber: string;
124
+ }
125
+ export interface MatchedBank {
126
+ nameTh?: string;
127
+ nameEn?: string;
128
+ code?: string;
129
+ shortCode?: string;
130
+ }
131
+ /** v2 bank slip verification result. Also the `data` of finished jobs and webhooks. */
132
+ export interface BankSlipResult {
133
+ /** Echo of the `remark` option. Absent when not sent. */
134
+ remark?: string;
135
+ /** Present only with `checkDuplicate: true`. */
136
+ isDuplicate?: boolean;
137
+ /** Absent without `matchAccount`; null when no registered account matched. */
138
+ matchedAccount?: MatchedAccount | null;
139
+ /** Present only with `matchAmount`. */
140
+ amountInOrder?: number;
141
+ amountInSlip: number;
142
+ /** Present only with `matchAmount`. */
143
+ isAmountMatched?: boolean;
144
+ rawSlip: BankSlip;
145
+ }
146
+ /** A TrueMoney Wallet slip. v2 `rawSlip`, v1 TrueMoney `data`. */
147
+ export interface TrueWalletSlip {
148
+ transactionId: string;
149
+ date: string;
150
+ amount: number;
151
+ sender: TrueWalletSender;
152
+ receiver: TrueWalletReceiver;
153
+ }
154
+ export interface TrueWalletSender {
155
+ name: string;
156
+ }
157
+ export interface TrueWalletReceiver {
158
+ name: string;
159
+ /** Masked phone number. */
160
+ phone: string;
161
+ }
162
+ /** v2 TrueMoney Wallet verification result. Same options as {@link BankSlipResult}. */
163
+ export interface TrueWalletResult {
164
+ remark?: string;
165
+ isDuplicate?: boolean;
166
+ matchedAccount?: MatchedAccount | null;
167
+ amountInOrder?: number;
168
+ amountInSlip: number;
169
+ isAmountMatched?: boolean;
170
+ rawSlip: TrueWalletSlip;
171
+ }
172
+ /** A bank or receiving kind from `GET /banks`. */
173
+ export interface Bank {
174
+ code: string;
175
+ nameTh: string;
176
+ nameEn: string;
177
+ shortCode: string;
178
+ swiftCode: string;
179
+ /** Allowed `extraVerify` values for accounts at this bank, or null. */
180
+ extraVerify: ExtraVerifyOption[] | null;
181
+ }
182
+ export interface ExtraVerifyOption {
183
+ value: string;
184
+ label: string;
185
+ }
186
+ /** `GET /banks`. Iterable; serializes to the plain array the API sends. */
187
+ export declare class BankList implements Iterable<Bank> {
188
+ /** The banks, ordered by code. */
189
+ readonly items: Bank[];
190
+ constructor(items: Bank[]);
191
+ /** Number of entries. */
192
+ get length(): number;
193
+ /** Finds an entry by code, for example `004`. */
194
+ find(code: string): Bank | undefined;
195
+ [Symbol.iterator](): Iterator<Bank>;
196
+ toJSON(): Bank[];
197
+ }
198
+ /** Known values of {@link BankAccount.type}. */
199
+ export declare const BankAccountType: {
200
+ readonly Natural: 'NATURAL';
201
+ readonly Juristic: 'JURISTIC';
202
+ };
203
+ /** Known values of {@link BankAccount.matchMode}. */
204
+ export declare const MatchMode: {
205
+ readonly Name: 'NAME';
206
+ readonly Number: 'NUMBER';
207
+ readonly NameNumber: 'NAME_NUMBER';
208
+ };
209
+ /** A receiving bank account registered on the service. */
210
+ export interface BankAccount {
211
+ id: number;
212
+ bankCode: string;
213
+ bankNumber: string;
214
+ nameTh: string;
215
+ nameEn: string;
216
+ /** `NATURAL` or `JURISTIC`. */
217
+ type: Open<(typeof BankAccountType)[keyof typeof BankAccountType]>;
218
+ extraVerify: string | null;
219
+ /** PromptPay matching rule, null for other banks. */
220
+ matchMode: Open<(typeof MatchMode)[keyof typeof MatchMode]> | null;
221
+ createdAt: string;
222
+ updatedAt: string;
223
+ deletedAt: string | null;
224
+ }
225
+ /** One page of bank accounts. */
226
+ export interface BankAccountPage {
227
+ items: BankAccount[];
228
+ total: number;
229
+ page: number;
230
+ limit: number;
231
+ }
232
+ export interface LinkResult {
233
+ linked: boolean;
234
+ }
235
+ export interface UnlinkResult {
236
+ unlinked: boolean;
237
+ }
238
+ export interface JobSubmission {
239
+ jobId: string;
240
+ }
241
+ export interface BatchSubmission {
242
+ batchId: string;
243
+ jobs: BatchJob[];
244
+ }
245
+ export interface BatchJob {
246
+ jobId: string;
247
+ /** 0-based position in the submitted list. */
248
+ index: number;
249
+ }
250
+ /** Known values of {@link Job.status}. */
251
+ export declare const JobStatus: {
252
+ readonly Queued: 'queued';
253
+ readonly Processing: 'processing';
254
+ readonly Retrying: 'retrying';
255
+ readonly Done: 'done';
256
+ readonly Failed: 'failed';
257
+ };
258
+ /** An async verification job. Finished when `status` is `done` or `failed`. */
259
+ export interface Job {
260
+ jobId: string;
261
+ /** Absent for single jobs. */
262
+ batchId?: string;
263
+ status: Open<(typeof JobStatus)[keyof typeof JobStatus]>;
264
+ result?: JobResult;
265
+ error?: JobError;
266
+ attempts: number;
267
+ createdAt: string;
268
+ updatedAt: string;
269
+ branchId?: number;
270
+ serviceId?: number;
271
+ callbackEventId?: string;
272
+ callbackProtocol?: number;
273
+ callbackDelivery?: CallbackDelivery;
274
+ }
275
+ export interface JobResult {
276
+ /** `success` or `not_found`. */
277
+ status: Open<'success' | 'not_found'>;
278
+ /** Null for `not_found`. */
279
+ data: BankSlipResult | null;
280
+ }
281
+ export interface JobError {
282
+ code?: string;
283
+ message?: string;
284
+ webhook?: string;
285
+ url?: string;
286
+ status?: number;
287
+ at?: string;
288
+ }
289
+ export interface CallbackDelivery {
290
+ state: string | null;
291
+ httpStatus: number | null;
292
+ }
293
+ /** Body of the webhook the API posts when an async job finishes. */
294
+ export interface WebhookEvent {
295
+ jobId: string;
296
+ /** Null for single jobs. */
297
+ batchId: string | null;
298
+ /** `success`, `not_found` or `failed`. */
299
+ status: Open<'success' | 'not_found' | 'failed'>;
300
+ /** Null for `not_found` and `failed`. */
301
+ data: BankSlipResult | null;
302
+ /** Only on `failed`. */
303
+ error?: WebhookError;
304
+ timestamp: string;
305
+ }
306
+ export interface WebhookError {
307
+ code: string;
308
+ message: string;
309
+ }
310
+ /** v1 `GET /me`. */
311
+ export interface V1Me {
312
+ application: string;
313
+ usedQuota: number;
314
+ maxQuota: number | null;
315
+ remainingQuota: number | null;
316
+ expiredAt: string | null;
317
+ currentCredit: number;
318
+ }
319
+ /** v1 `POST /qr/generate` result. */
320
+ export interface QrCode {
321
+ /** Base64 PNG, no data URI prefix. */
322
+ image: string;
323
+ mime: string;
324
+ /** The EMVCo payload encoded in the QR. */
325
+ payload: string;
326
+ }
327
+ type Spec = 0 | Shape | readonly [Spec];
328
+ interface Shape {
329
+ readonly [key: string]: Spec;
330
+ }
331
+ type ShapeOf<T> = {
332
+ readonly [K in keyof Required<T>]: Spec;
333
+ };
334
+ export declare function pick(spec: Spec, raw: unknown): unknown;
335
+ /** Model name to shape, for every model a response can decode into. */
336
+ export declare const shapes: {
337
+ readonly Info: ShapeOf<Info>;
338
+ readonly BankSlip: ShapeOf<BankSlip>;
339
+ readonly BankSlipResult: ShapeOf<BankSlipResult>;
340
+ readonly TrueWalletSlip: ShapeOf<TrueWalletSlip>;
341
+ readonly TrueWalletResult: ShapeOf<TrueWalletResult>;
342
+ readonly BankAccount: ShapeOf<BankAccount>;
343
+ readonly BankAccountPage: ShapeOf<BankAccountPage>;
344
+ readonly LinkResult: {
345
+ linked: 0;
346
+ };
347
+ readonly UnlinkResult: {
348
+ unlinked: 0;
349
+ };
350
+ readonly JobSubmission: {
351
+ jobId: 0;
352
+ };
353
+ readonly BatchSubmission: {
354
+ batchId: 0;
355
+ jobs: [{
356
+ jobId: 0;
357
+ index: 0;
358
+ }];
359
+ };
360
+ readonly Job: ShapeOf<Job>;
361
+ readonly WebhookEvent: ShapeOf<WebhookEvent>;
362
+ readonly V1Me: {
363
+ application: 0;
364
+ usedQuota: 0;
365
+ maxQuota: 0;
366
+ remainingQuota: 0;
367
+ expiredAt: 0;
368
+ currentCredit: 0;
369
+ };
370
+ readonly QrCode: {
371
+ image: 0;
372
+ mime: 0;
373
+ payload: 0;
374
+ };
375
+ };
376
+ /** Names of the models {@link parseModel} can build. */
377
+ export type ModelName = keyof typeof shapes | 'BankList';
378
+ interface ModelTypes {
379
+ Info: Info;
380
+ BankSlip: BankSlip;
381
+ BankSlipResult: BankSlipResult;
382
+ TrueWalletSlip: TrueWalletSlip;
383
+ TrueWalletResult: TrueWalletResult;
384
+ BankAccount: BankAccount;
385
+ BankAccountPage: BankAccountPage;
386
+ LinkResult: LinkResult;
387
+ UnlinkResult: UnlinkResult;
388
+ JobSubmission: JobSubmission;
389
+ BatchSubmission: BatchSubmission;
390
+ Job: Job;
391
+ WebhookEvent: WebhookEvent;
392
+ V1Me: V1Me;
393
+ QrCode: QrCode;
394
+ BankList: BankList;
395
+ }
396
+ /** Builds a model from decoded JSON, keeping only the fields the model knows. */
397
+ export declare function parseModel<N extends ModelName>(name: N, raw: unknown): ModelTypes[N];
398
+ export {};