@easyslip/sdk 1.0.1 → 1.1.0
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/CHANGELOG.md +7 -0
- package/README.md +8 -6
- package/README.th.md +8 -6
- package/dist/cjs/index.js +2039 -54
- package/dist/cjs/models.d.ts +16 -7
- package/dist/cjs/resources/v1.d.ts +2 -0
- package/dist/cjs/resources/verify.d.ts +2 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/esm/index.js +1997 -7
- package/dist/esm/models.d.ts +16 -7
- package/dist/esm/resources/v1.d.ts +2 -0
- package/dist/esm/resources/verify.d.ts +2 -0
- package/dist/esm/version.d.ts +1 -1
- package/package.json +12 -14
- package/dist/cjs/client.js +0 -150
- package/dist/cjs/core/call.js +0 -60
- package/dist/cjs/core/error-codes.js +0 -87
- package/dist/cjs/core/errors.js +0 -210
- package/dist/cjs/core/files.js +0 -131
- package/dist/cjs/core/http.js +0 -242
- package/dist/cjs/core/meta.js +0 -52
- package/dist/cjs/core/redact.js +0 -208
- package/dist/cjs/core/runtime.js +0 -86
- package/dist/cjs/core/settings.js +0 -22
- package/dist/cjs/core/sha256.js +0 -101
- package/dist/cjs/models.js +0 -234
- package/dist/cjs/resources/bank-accounts.js +0 -126
- package/dist/cjs/resources/banks.js +0 -22
- package/dist/cjs/resources/jobs.js +0 -177
- package/dist/cjs/resources/v1.js +0 -137
- package/dist/cjs/resources/verify.js +0 -105
- package/dist/cjs/version.js +0 -5
- package/dist/cjs/webhooks.js +0 -92
- package/dist/esm/client.js +0 -146
- package/dist/esm/core/call.js +0 -52
- package/dist/esm/core/error-codes.js +0 -84
- package/dist/esm/core/errors.js +0 -184
- package/dist/esm/core/files.js +0 -126
- package/dist/esm/core/http.js +0 -235
- package/dist/esm/core/meta.js +0 -45
- package/dist/esm/core/redact.js +0 -198
- package/dist/esm/core/runtime.js +0 -47
- package/dist/esm/core/settings.js +0 -19
- package/dist/esm/core/sha256.js +0 -96
- package/dist/esm/models.js +0 -228
- package/dist/esm/resources/bank-accounts.js +0 -122
- package/dist/esm/resources/banks.js +0 -18
- package/dist/esm/resources/jobs.js +0 -173
- package/dist/esm/resources/v1.js +0 -133
- package/dist/esm/resources/verify.js +0 -100
- package/dist/esm/version.js +0 -2
- package/dist/esm/webhooks.js +0 -86
package/dist/esm/core/meta.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/** Attaches `meta` without making it part of the value's JSON or its enumerable keys. */
|
|
2
|
-
export function attachMeta(value, meta) {
|
|
3
|
-
Object.defineProperty(value, 'meta', { value: meta, enumerable: false });
|
|
4
|
-
return value;
|
|
5
|
-
}
|
|
6
|
-
export function headersToRecord(headers) {
|
|
7
|
-
const out = {};
|
|
8
|
-
if (headers instanceof Headers) {
|
|
9
|
-
headers.forEach((value, key) => {
|
|
10
|
-
out[key.toLowerCase()] = value;
|
|
11
|
-
});
|
|
12
|
-
return out;
|
|
13
|
-
}
|
|
14
|
-
for (const [key, value] of Object.entries(headers))
|
|
15
|
-
out[key.toLowerCase()] = value;
|
|
16
|
-
return out;
|
|
17
|
-
}
|
|
18
|
-
export function requestIdFrom(headers) {
|
|
19
|
-
return headers['x-request-id'] || headers['cf-ray'] || null;
|
|
20
|
-
}
|
|
21
|
-
function toInt(value) {
|
|
22
|
-
if (value === undefined || !/^\s*-?\d+\s*$/.test(value))
|
|
23
|
-
return null;
|
|
24
|
-
return Number.parseInt(value, 10);
|
|
25
|
-
}
|
|
26
|
-
export function rateLimitFrom(headers) {
|
|
27
|
-
const limit = toInt(headers['x-ratelimit-limit']);
|
|
28
|
-
const remaining = toInt(headers['x-ratelimit-remaining']);
|
|
29
|
-
const reset = toInt(headers['x-ratelimit-reset']);
|
|
30
|
-
if (limit === null || remaining === null || reset === null)
|
|
31
|
-
return null;
|
|
32
|
-
return { limit, remaining, reset };
|
|
33
|
-
}
|
|
34
|
-
/** Seconds from a `Retry-After` header (delta seconds or HTTP date), or null. */
|
|
35
|
-
export function retryAfterFrom(headers, now = Date.now()) {
|
|
36
|
-
const raw = headers['retry-after']?.trim();
|
|
37
|
-
if (!raw)
|
|
38
|
-
return null;
|
|
39
|
-
if (/^\d+$/.test(raw))
|
|
40
|
-
return Number.parseInt(raw, 10);
|
|
41
|
-
const at = Date.parse(raw);
|
|
42
|
-
if (Number.isNaN(at))
|
|
43
|
-
return null;
|
|
44
|
-
return Math.max(0, Math.ceil((at - now) / 1000));
|
|
45
|
-
}
|
package/dist/esm/core/redact.js
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
// Removes the configured API key from everything the SDK takes from a response or a transport
|
|
2
|
-
// error. The key is found by decoding, not by listing encodings.
|
|
3
|
-
/** What the SDK puts where it removed the API key or an Authorization value. */
|
|
4
|
-
export const REDACTED = '[REDACTED]';
|
|
5
|
-
const AUTH_HEADERS = new Set(['authorization', 'proxy-authorization']);
|
|
6
|
-
const MAX_CAUSE_DEPTH = 3;
|
|
7
|
-
export const noRedact = { text: (value) => value, carries: () => false };
|
|
8
|
-
const utf8 = new TextDecoder();
|
|
9
|
-
/** `%HH` (either hex case) becomes that byte; runs of bytes are read as UTF-8. */
|
|
10
|
-
export function percentDecode(text) {
|
|
11
|
-
if (!text.includes('%'))
|
|
12
|
-
return text;
|
|
13
|
-
return text.replace(/(?:%[0-9a-fA-F]{2})+/g, (run) => {
|
|
14
|
-
const bytes = new Uint8Array(run.length / 3);
|
|
15
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
16
|
-
bytes[i] = Number.parseInt(run.slice(i * 3 + 1, i * 3 + 3), 16);
|
|
17
|
-
}
|
|
18
|
-
return utf8.decode(bytes);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
const JSON_ESCAPES = {
|
|
22
|
-
'"': '"',
|
|
23
|
-
'\\': '\\',
|
|
24
|
-
'/': '/',
|
|
25
|
-
b: '\b',
|
|
26
|
-
f: '\f',
|
|
27
|
-
n: '\n',
|
|
28
|
-
r: '\r',
|
|
29
|
-
t: '\t',
|
|
30
|
-
};
|
|
31
|
-
/** JSON string unescaping: `\uXXXX` (either hex case) and the short escapes. */
|
|
32
|
-
export function jsonUnescape(text) {
|
|
33
|
-
if (!text.includes('\\'))
|
|
34
|
-
return text;
|
|
35
|
-
return text.replace(/\\(u[0-9a-fA-F]{4}|["\\/bfnrt])/g, (_, seq) => seq.length === 5
|
|
36
|
-
? String.fromCharCode(Number.parseInt(seq.slice(1), 16))
|
|
37
|
-
: JSON_ESCAPES[seq]);
|
|
38
|
-
}
|
|
39
|
-
/** Matches the key with any subset of its characters percent-encoded, in either hex case. */
|
|
40
|
-
function percentPattern(apiKey) {
|
|
41
|
-
const hex = (byte) => [...byte.toString(16).padStart(2, '0')]
|
|
42
|
-
.map((d) => (/[a-f]/.test(d) ? `[${d}${d.toUpperCase()}]` : d))
|
|
43
|
-
.join('');
|
|
44
|
-
const parts = [...apiKey].map((char) => {
|
|
45
|
-
const literal = char.replace(/[.*+?^${}()|[\]\\/-]/g, '\\$&');
|
|
46
|
-
const encoded = [...new TextEncoder().encode(char)].map((b) => `%${hex(b)}`).join('');
|
|
47
|
-
return `(?:${literal}|${encoded})`;
|
|
48
|
-
});
|
|
49
|
-
return new RegExp(parts.join(''), 'g');
|
|
50
|
-
}
|
|
51
|
-
/** Builds the redactor for one API key. Keys shorter than 4 characters are left alone. */
|
|
52
|
-
export function redactor(apiKey) {
|
|
53
|
-
if (apiKey.length < 4)
|
|
54
|
-
return noRedact;
|
|
55
|
-
const pattern = percentPattern(apiKey);
|
|
56
|
-
const carries = (value) => {
|
|
57
|
-
// The text, its percent-decoding, its JSON unescaping, and each applied to the other,
|
|
58
|
-
// one level deep.
|
|
59
|
-
let views = [value];
|
|
60
|
-
const seen = new Set(views);
|
|
61
|
-
for (let level = 0; level <= 3; level++) {
|
|
62
|
-
if (views.some((view) => view.includes(apiKey)))
|
|
63
|
-
return true;
|
|
64
|
-
const next = [];
|
|
65
|
-
for (const view of views) {
|
|
66
|
-
for (const decoded of [percentDecode(view), jsonUnescape(view)]) {
|
|
67
|
-
if (!seen.has(decoded)) {
|
|
68
|
-
seen.add(decoded);
|
|
69
|
-
next.push(decoded);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (next.length === 0)
|
|
74
|
-
return false;
|
|
75
|
-
views = next;
|
|
76
|
-
}
|
|
77
|
-
return false;
|
|
78
|
-
};
|
|
79
|
-
return {
|
|
80
|
-
carries,
|
|
81
|
-
text(value) {
|
|
82
|
-
if (!value)
|
|
83
|
-
return value;
|
|
84
|
-
const out = value.replace(pattern, REDACTED);
|
|
85
|
-
return carries(out) ? REDACTED : out;
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Authorization and Proxy-Authorization are always `[REDACTED]`; any other value that
|
|
91
|
-
* carries the key becomes `[REDACTED]` as a whole.
|
|
92
|
-
*/
|
|
93
|
-
export function redactHeaders(headers, redact) {
|
|
94
|
-
const out = {};
|
|
95
|
-
for (const [name, value] of Object.entries(headers)) {
|
|
96
|
-
out[name] = AUTH_HEADERS.has(name.toLowerCase()) || redact.carries(value) ? REDACTED : value;
|
|
97
|
-
}
|
|
98
|
-
return out;
|
|
99
|
-
}
|
|
100
|
-
function defineValue(target, key, value) {
|
|
101
|
-
Object.defineProperty(target, key, {
|
|
102
|
-
value,
|
|
103
|
-
enumerable: true,
|
|
104
|
-
writable: true,
|
|
105
|
-
configurable: true,
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Applies `text` to every string of a parsed JSON value, object keys included. Returns the
|
|
110
|
-
* same value when nothing changed.
|
|
111
|
-
*/
|
|
112
|
-
export function redactJson(value, redact) {
|
|
113
|
-
if (typeof value === 'string')
|
|
114
|
-
return redact.text(value);
|
|
115
|
-
if (Array.isArray(value)) {
|
|
116
|
-
const out = value.map((item) => redactJson(item, redact));
|
|
117
|
-
return out.some((item, i) => item !== value[i]) ? out : value;
|
|
118
|
-
}
|
|
119
|
-
if (value === null || typeof value !== 'object')
|
|
120
|
-
return value;
|
|
121
|
-
let changed = false;
|
|
122
|
-
const out = {};
|
|
123
|
-
for (const [key, item] of Object.entries(value)) {
|
|
124
|
-
const safeKey = redact.text(key);
|
|
125
|
-
const safeItem = redactJson(item, redact);
|
|
126
|
-
if (safeKey !== key || safeItem !== item)
|
|
127
|
-
changed = true;
|
|
128
|
-
// defineProperty, so a "__proto__" key stays a plain key
|
|
129
|
-
defineValue(out, safeKey, safeItem);
|
|
130
|
-
}
|
|
131
|
-
return changed ? out : value;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Redaction of a whole body: `body` is `text` parsed as JSON (undefined when it is not JSON). Returns
|
|
135
|
-
* the body that may be shown and the redacted parsed value.
|
|
136
|
-
*/
|
|
137
|
-
export function redactBody(text, body, redact) {
|
|
138
|
-
if (body === undefined)
|
|
139
|
-
return { rawBody: redact.text(text), body };
|
|
140
|
-
const safe = redactJson(body, redact);
|
|
141
|
-
return { rawBody: safe === body ? text : JSON.stringify(safe), body: safe };
|
|
142
|
-
}
|
|
143
|
-
function read(source, key) {
|
|
144
|
-
try {
|
|
145
|
-
return source[key];
|
|
146
|
-
}
|
|
147
|
-
catch {
|
|
148
|
-
return undefined;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
function typeName(source) {
|
|
152
|
-
if (source instanceof Error)
|
|
153
|
-
return String(read(source, 'name') ?? 'Error');
|
|
154
|
-
if (source === null)
|
|
155
|
-
return 'null';
|
|
156
|
-
if (typeof source !== 'object')
|
|
157
|
-
return typeof source;
|
|
158
|
-
const ctor = read(source, 'constructor');
|
|
159
|
-
return typeof ctor?.name === 'string' && ctor.name ? ctor.name : 'Object';
|
|
160
|
-
}
|
|
161
|
-
function messageOf(source) {
|
|
162
|
-
if (typeof source === 'string')
|
|
163
|
-
return source;
|
|
164
|
-
const message = read(source, 'message');
|
|
165
|
-
if (typeof message === 'string')
|
|
166
|
-
return message;
|
|
167
|
-
if (source instanceof Error || (source !== null && typeof source === 'object'))
|
|
168
|
-
return '';
|
|
169
|
-
return String(source);
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* A sanitized copy of a transport failure. It holds the type name, the message after `text`,
|
|
173
|
-
* `code` and `errno` when they are strings or numbers, and the sanitized copy of the
|
|
174
|
-
* original's own cause (at most 3 levels). Never the original or any other property.
|
|
175
|
-
*/
|
|
176
|
-
export function sanitizeCause(cause, redact, depth = 1) {
|
|
177
|
-
const copy = new Error(redact.text(messageOf(cause)));
|
|
178
|
-
copy.name = redact.text(typeName(cause));
|
|
179
|
-
copy.stack = `${copy.name}: ${copy.message}`;
|
|
180
|
-
for (const field of ['code', 'errno']) {
|
|
181
|
-
const value = cause !== null && typeof cause === 'object' ? read(cause, field) : undefined;
|
|
182
|
-
if (typeof value === 'string')
|
|
183
|
-
defineValue(copy, field, redact.text(value));
|
|
184
|
-
else if (typeof value === 'number') {
|
|
185
|
-
defineValue(copy, field, redact.carries(String(value)) ? REDACTED : value);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
const inner = cause !== null && typeof cause === 'object' ? read(cause, 'cause') : undefined;
|
|
189
|
-
if (inner !== undefined && depth < MAX_CAUSE_DEPTH) {
|
|
190
|
-
Object.defineProperty(copy, 'cause', {
|
|
191
|
-
value: sanitizeCause(inner, redact, depth + 1),
|
|
192
|
-
enumerable: false,
|
|
193
|
-
writable: true,
|
|
194
|
-
configurable: true,
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
return copy;
|
|
198
|
-
}
|
package/dist/esm/core/runtime.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// Small runtime probes that work on Node, Bun, Deno and edge runtimes without type packages.
|
|
2
|
-
const g = globalThis;
|
|
3
|
-
/** Reads an environment variable, or undefined when the runtime has none or denies access. */
|
|
4
|
-
export function readEnv(name) {
|
|
5
|
-
try {
|
|
6
|
-
if (g.Deno?.env)
|
|
7
|
-
return g.Deno.env.get(name) || undefined;
|
|
8
|
-
return g.process?.env?.[name] || undefined;
|
|
9
|
-
}
|
|
10
|
-
catch {
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
/** `<runtime>/<version>` for the User-Agent header. */
|
|
15
|
-
export function runtimeToken() {
|
|
16
|
-
if (g.Bun?.version)
|
|
17
|
-
return `bun/${g.Bun.version}`;
|
|
18
|
-
if (g.Deno?.version?.deno)
|
|
19
|
-
return `deno/${g.Deno.version.deno}`;
|
|
20
|
-
if (g.process?.versions?.node)
|
|
21
|
-
return `node/${g.process.versions.node}`;
|
|
22
|
-
return 'edge/unknown';
|
|
23
|
-
}
|
|
24
|
-
let fsPromise;
|
|
25
|
-
/** `node:fs/promises`, or null on runtimes without a file system. */
|
|
26
|
-
export function loadFs() {
|
|
27
|
-
fsPromise ??= import('node:fs/promises').then((mod) => mod.default ?? mod, () => null);
|
|
28
|
-
return fsPromise;
|
|
29
|
-
}
|
|
30
|
-
/** Waits `ms` milliseconds; rejects with the signal's reason when it aborts first. */
|
|
31
|
-
export function sleep(ms, signal) {
|
|
32
|
-
return new Promise((resolve, reject) => {
|
|
33
|
-
if (signal?.aborted) {
|
|
34
|
-
reject(signal.reason);
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
const onAbort = () => {
|
|
38
|
-
clearTimeout(timer);
|
|
39
|
-
reject(signal?.reason);
|
|
40
|
-
};
|
|
41
|
-
const timer = setTimeout(() => {
|
|
42
|
-
signal?.removeEventListener('abort', onAbort);
|
|
43
|
-
resolve();
|
|
44
|
-
}, ms);
|
|
45
|
-
signal?.addEventListener('abort', onAbort, { once: true });
|
|
46
|
-
});
|
|
47
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/** Default hosts, environment variable names and header names the SDK uses. */
|
|
2
|
-
export const settings = {
|
|
3
|
-
baseUrls: {
|
|
4
|
-
v1: 'https://api.easyslip.com/v1',
|
|
5
|
-
v2: 'https://api.easyslip.com/v2',
|
|
6
|
-
},
|
|
7
|
-
userAgentProduct: 'easyslip-js',
|
|
8
|
-
webhook: {
|
|
9
|
-
signatureHeader: 'X-EasySlip-Signature',
|
|
10
|
-
signaturePrefix: 'sha256=',
|
|
11
|
-
},
|
|
12
|
-
env: {
|
|
13
|
-
apiKey: 'EASYSLIP_API_KEY',
|
|
14
|
-
apiKeyFile: 'EASYSLIP_API_KEY_FILE',
|
|
15
|
-
webhookSecret: 'EASYSLIP_WEBHOOK_SECRET',
|
|
16
|
-
v1BaseUrl: 'EASYSLIP_V1_BASE_URL',
|
|
17
|
-
v2BaseUrl: 'EASYSLIP_V2_BASE_URL',
|
|
18
|
-
},
|
|
19
|
-
};
|
package/dist/esm/core/sha256.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/esm/models.js
DELETED
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
// Response models. Field presence follows the API: an optional field (`?`) can
|
|
2
|
-
// be absent, `| null` can be null, and the two are kept apart when a model is serialized again.
|
|
3
|
-
// Enum-like fields are open strings: the known values are listed, unknown values still parse.
|
|
4
|
-
/** Known values of {@link MatchedAccount.type}. */
|
|
5
|
-
export const MatchedAccountType = {
|
|
6
|
-
Personal: 'PERSONAL',
|
|
7
|
-
Natural: 'NATURAL',
|
|
8
|
-
Juristic: 'JURISTIC',
|
|
9
|
-
};
|
|
10
|
-
/** `GET /banks`. Iterable; serializes to the plain array the API sends. */
|
|
11
|
-
export class BankList {
|
|
12
|
-
/** The banks, ordered by code. */
|
|
13
|
-
items;
|
|
14
|
-
constructor(items) {
|
|
15
|
-
this.items = items;
|
|
16
|
-
}
|
|
17
|
-
/** Number of entries. */
|
|
18
|
-
get length() {
|
|
19
|
-
return this.items.length;
|
|
20
|
-
}
|
|
21
|
-
/** Finds an entry by code, for example `004`. */
|
|
22
|
-
find(code) {
|
|
23
|
-
return this.items.find((bank) => bank.code === code);
|
|
24
|
-
}
|
|
25
|
-
[Symbol.iterator]() {
|
|
26
|
-
return this.items[Symbol.iterator]();
|
|
27
|
-
}
|
|
28
|
-
toJSON() {
|
|
29
|
-
return this.items;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
/** Known values of {@link BankAccount.type}. */
|
|
33
|
-
export const BankAccountType = {
|
|
34
|
-
Natural: 'NATURAL',
|
|
35
|
-
Juristic: 'JURISTIC',
|
|
36
|
-
};
|
|
37
|
-
/** Known values of {@link BankAccount.matchMode}. */
|
|
38
|
-
export const MatchMode = {
|
|
39
|
-
Name: 'NAME',
|
|
40
|
-
Number: 'NUMBER',
|
|
41
|
-
NameNumber: 'NAME_NUMBER',
|
|
42
|
-
};
|
|
43
|
-
/** Known values of {@link Job.status}. */
|
|
44
|
-
export const JobStatus = {
|
|
45
|
-
Queued: 'queued',
|
|
46
|
-
Processing: 'processing',
|
|
47
|
-
Retrying: 'retrying',
|
|
48
|
-
Done: 'done',
|
|
49
|
-
Failed: 'failed',
|
|
50
|
-
};
|
|
51
|
-
export function pick(spec, raw) {
|
|
52
|
-
if (spec === 0 || raw === null || typeof raw !== 'object')
|
|
53
|
-
return raw;
|
|
54
|
-
if (Array.isArray(spec)) {
|
|
55
|
-
const item = spec[0];
|
|
56
|
-
return Array.isArray(raw) ? raw.map((value) => pick(item, value)) : raw;
|
|
57
|
-
}
|
|
58
|
-
if (Array.isArray(raw))
|
|
59
|
-
return raw;
|
|
60
|
-
const shape = spec;
|
|
61
|
-
const out = {};
|
|
62
|
-
for (const [key, value] of Object.entries(raw)) {
|
|
63
|
-
const child = shape[key];
|
|
64
|
-
if (child !== undefined && Object.hasOwn(shape, key))
|
|
65
|
-
out[key] = pick(child, value);
|
|
66
|
-
}
|
|
67
|
-
return out;
|
|
68
|
-
}
|
|
69
|
-
const autoRenew = { expired: 0, quota: 0, createdAt: 0, expiresAt: 0 };
|
|
70
|
-
const applicationQuota = { used: 0, max: 0, remaining: 0, totalUsed: 0 };
|
|
71
|
-
const infoShape = {
|
|
72
|
-
application: { name: 0, autoRenew, quota: applicationQuota },
|
|
73
|
-
branch: {
|
|
74
|
-
name: 0,
|
|
75
|
-
isActive: 0,
|
|
76
|
-
quota: { used: 0, totalUsed: 0 },
|
|
77
|
-
},
|
|
78
|
-
account: { email: 0, credit: 0 },
|
|
79
|
-
product: { name: 0 },
|
|
80
|
-
};
|
|
81
|
-
const accountNumber = { type: 0, account: 0 };
|
|
82
|
-
const slipAccount = {
|
|
83
|
-
name: { th: 0, en: 0 },
|
|
84
|
-
bank: accountNumber,
|
|
85
|
-
proxy: accountNumber,
|
|
86
|
-
};
|
|
87
|
-
const slipBank = { id: 0, name: 0, short: 0 };
|
|
88
|
-
const slipParty = { bank: slipBank, account: slipAccount };
|
|
89
|
-
const bankSlipShape = {
|
|
90
|
-
payload: 0,
|
|
91
|
-
transRef: 0,
|
|
92
|
-
date: 0,
|
|
93
|
-
countryCode: 0,
|
|
94
|
-
amount: {
|
|
95
|
-
amount: 0,
|
|
96
|
-
local: { amount: 0, currency: 0 },
|
|
97
|
-
},
|
|
98
|
-
fee: 0,
|
|
99
|
-
ref1: 0,
|
|
100
|
-
ref2: 0,
|
|
101
|
-
ref3: 0,
|
|
102
|
-
sender: slipParty,
|
|
103
|
-
receiver: { ...slipParty, merchantId: 0 },
|
|
104
|
-
};
|
|
105
|
-
const matchedAccount = {
|
|
106
|
-
bank: { nameTh: 0, nameEn: 0, code: 0, shortCode: 0 },
|
|
107
|
-
nameTh: 0,
|
|
108
|
-
nameEn: 0,
|
|
109
|
-
type: 0,
|
|
110
|
-
bankNumber: 0,
|
|
111
|
-
};
|
|
112
|
-
const bankSlipResultShape = {
|
|
113
|
-
remark: 0,
|
|
114
|
-
isDuplicate: 0,
|
|
115
|
-
matchedAccount,
|
|
116
|
-
amountInOrder: 0,
|
|
117
|
-
amountInSlip: 0,
|
|
118
|
-
isAmountMatched: 0,
|
|
119
|
-
rawSlip: bankSlipShape,
|
|
120
|
-
};
|
|
121
|
-
const trueWalletSlipShape = {
|
|
122
|
-
transactionId: 0,
|
|
123
|
-
date: 0,
|
|
124
|
-
amount: 0,
|
|
125
|
-
sender: { name: 0 },
|
|
126
|
-
receiver: { name: 0, phone: 0 },
|
|
127
|
-
};
|
|
128
|
-
const trueWalletResultShape = {
|
|
129
|
-
...bankSlipResultShape,
|
|
130
|
-
rawSlip: trueWalletSlipShape,
|
|
131
|
-
};
|
|
132
|
-
const bankShape = {
|
|
133
|
-
code: 0,
|
|
134
|
-
nameTh: 0,
|
|
135
|
-
nameEn: 0,
|
|
136
|
-
shortCode: 0,
|
|
137
|
-
swiftCode: 0,
|
|
138
|
-
extraVerify: [{ value: 0, label: 0 }],
|
|
139
|
-
};
|
|
140
|
-
const bankAccountShape = {
|
|
141
|
-
id: 0,
|
|
142
|
-
bankCode: 0,
|
|
143
|
-
bankNumber: 0,
|
|
144
|
-
nameTh: 0,
|
|
145
|
-
nameEn: 0,
|
|
146
|
-
type: 0,
|
|
147
|
-
extraVerify: 0,
|
|
148
|
-
matchMode: 0,
|
|
149
|
-
createdAt: 0,
|
|
150
|
-
updatedAt: 0,
|
|
151
|
-
deletedAt: 0,
|
|
152
|
-
};
|
|
153
|
-
const bankAccountPageShape = {
|
|
154
|
-
items: [bankAccountShape],
|
|
155
|
-
total: 0,
|
|
156
|
-
page: 0,
|
|
157
|
-
limit: 0,
|
|
158
|
-
};
|
|
159
|
-
const jobShape = {
|
|
160
|
-
jobId: 0,
|
|
161
|
-
batchId: 0,
|
|
162
|
-
status: 0,
|
|
163
|
-
result: { status: 0, data: bankSlipResultShape },
|
|
164
|
-
error: {
|
|
165
|
-
code: 0,
|
|
166
|
-
message: 0,
|
|
167
|
-
webhook: 0,
|
|
168
|
-
url: 0,
|
|
169
|
-
status: 0,
|
|
170
|
-
at: 0,
|
|
171
|
-
},
|
|
172
|
-
attempts: 0,
|
|
173
|
-
createdAt: 0,
|
|
174
|
-
updatedAt: 0,
|
|
175
|
-
branchId: 0,
|
|
176
|
-
serviceId: 0,
|
|
177
|
-
callbackEventId: 0,
|
|
178
|
-
callbackProtocol: 0,
|
|
179
|
-
callbackDelivery: { state: 0, httpStatus: 0 },
|
|
180
|
-
};
|
|
181
|
-
const webhookEventShape = {
|
|
182
|
-
jobId: 0,
|
|
183
|
-
batchId: 0,
|
|
184
|
-
status: 0,
|
|
185
|
-
data: bankSlipResultShape,
|
|
186
|
-
error: { code: 0, message: 0 },
|
|
187
|
-
timestamp: 0,
|
|
188
|
-
};
|
|
189
|
-
/** Model name to shape, for every model a response can decode into. */
|
|
190
|
-
export const shapes = {
|
|
191
|
-
Info: infoShape,
|
|
192
|
-
BankSlip: bankSlipShape,
|
|
193
|
-
BankSlipResult: bankSlipResultShape,
|
|
194
|
-
TrueWalletSlip: trueWalletSlipShape,
|
|
195
|
-
TrueWalletResult: trueWalletResultShape,
|
|
196
|
-
BankAccount: bankAccountShape,
|
|
197
|
-
BankAccountPage: bankAccountPageShape,
|
|
198
|
-
LinkResult: { linked: 0 },
|
|
199
|
-
UnlinkResult: { unlinked: 0 },
|
|
200
|
-
JobSubmission: { jobId: 0 },
|
|
201
|
-
BatchSubmission: {
|
|
202
|
-
batchId: 0,
|
|
203
|
-
jobs: [{ jobId: 0, index: 0 }],
|
|
204
|
-
},
|
|
205
|
-
Job: jobShape,
|
|
206
|
-
WebhookEvent: webhookEventShape,
|
|
207
|
-
V1Me: {
|
|
208
|
-
application: 0,
|
|
209
|
-
usedQuota: 0,
|
|
210
|
-
maxQuota: 0,
|
|
211
|
-
remainingQuota: 0,
|
|
212
|
-
expiredAt: 0,
|
|
213
|
-
currentCredit: 0,
|
|
214
|
-
},
|
|
215
|
-
QrCode: { image: 0, mime: 0, payload: 0 },
|
|
216
|
-
};
|
|
217
|
-
/** Builds a model from decoded JSON, keeping only the fields the model knows. */
|
|
218
|
-
export function parseModel(name, raw) {
|
|
219
|
-
if (name === 'BankList') {
|
|
220
|
-
const items = Array.isArray(raw) ? pick([bankShape], raw) : [];
|
|
221
|
-
return new BankList(items);
|
|
222
|
-
}
|
|
223
|
-
const value = pick(shapes[name], raw);
|
|
224
|
-
if (value === null || typeof value !== 'object') {
|
|
225
|
-
return {};
|
|
226
|
-
}
|
|
227
|
-
return value;
|
|
228
|
-
}
|