@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/cjs/core/runtime.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Small runtime probes that work on Node, Bun, Deno and edge runtimes without type packages.
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
-
var ownKeys = function(o) {
|
|
21
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
-
var ar = [];
|
|
23
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
-
return ar;
|
|
25
|
-
};
|
|
26
|
-
return ownKeys(o);
|
|
27
|
-
};
|
|
28
|
-
return function (mod) {
|
|
29
|
-
if (mod && mod.__esModule) return mod;
|
|
30
|
-
var result = {};
|
|
31
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
-
__setModuleDefault(result, mod);
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
})();
|
|
36
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.readEnv = readEnv;
|
|
38
|
-
exports.runtimeToken = runtimeToken;
|
|
39
|
-
exports.loadFs = loadFs;
|
|
40
|
-
exports.sleep = sleep;
|
|
41
|
-
const g = globalThis;
|
|
42
|
-
/** Reads an environment variable, or undefined when the runtime has none or denies access. */
|
|
43
|
-
function readEnv(name) {
|
|
44
|
-
try {
|
|
45
|
-
if (g.Deno?.env)
|
|
46
|
-
return g.Deno.env.get(name) || undefined;
|
|
47
|
-
return g.process?.env?.[name] || undefined;
|
|
48
|
-
}
|
|
49
|
-
catch {
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
/** `<runtime>/<version>` for the User-Agent header. */
|
|
54
|
-
function runtimeToken() {
|
|
55
|
-
if (g.Bun?.version)
|
|
56
|
-
return `bun/${g.Bun.version}`;
|
|
57
|
-
if (g.Deno?.version?.deno)
|
|
58
|
-
return `deno/${g.Deno.version.deno}`;
|
|
59
|
-
if (g.process?.versions?.node)
|
|
60
|
-
return `node/${g.process.versions.node}`;
|
|
61
|
-
return 'edge/unknown';
|
|
62
|
-
}
|
|
63
|
-
let fsPromise;
|
|
64
|
-
/** `node:fs/promises`, or null on runtimes without a file system. */
|
|
65
|
-
function loadFs() {
|
|
66
|
-
fsPromise ??= Promise.resolve(`${'node:fs/promises'}`).then(s => __importStar(require(s))).then((mod) => mod.default ?? mod, () => null);
|
|
67
|
-
return fsPromise;
|
|
68
|
-
}
|
|
69
|
-
/** Waits `ms` milliseconds; rejects with the signal's reason when it aborts first. */
|
|
70
|
-
function sleep(ms, signal) {
|
|
71
|
-
return new Promise((resolve, reject) => {
|
|
72
|
-
if (signal?.aborted) {
|
|
73
|
-
reject(signal.reason);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const onAbort = () => {
|
|
77
|
-
clearTimeout(timer);
|
|
78
|
-
reject(signal?.reason);
|
|
79
|
-
};
|
|
80
|
-
const timer = setTimeout(() => {
|
|
81
|
-
signal?.removeEventListener('abort', onAbort);
|
|
82
|
-
resolve();
|
|
83
|
-
}, ms);
|
|
84
|
-
signal?.addEventListener('abort', onAbort, { once: true });
|
|
85
|
-
});
|
|
86
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.settings = void 0;
|
|
4
|
-
/** Default hosts, environment variable names and header names the SDK uses. */
|
|
5
|
-
exports.settings = {
|
|
6
|
-
baseUrls: {
|
|
7
|
-
v1: 'https://api.easyslip.com/v1',
|
|
8
|
-
v2: 'https://api.easyslip.com/v2',
|
|
9
|
-
},
|
|
10
|
-
userAgentProduct: 'easyslip-js',
|
|
11
|
-
webhook: {
|
|
12
|
-
signatureHeader: 'X-EasySlip-Signature',
|
|
13
|
-
signaturePrefix: 'sha256=',
|
|
14
|
-
},
|
|
15
|
-
env: {
|
|
16
|
-
apiKey: 'EASYSLIP_API_KEY',
|
|
17
|
-
apiKeyFile: 'EASYSLIP_API_KEY_FILE',
|
|
18
|
-
webhookSecret: 'EASYSLIP_WEBHOOK_SECRET',
|
|
19
|
-
v1BaseUrl: 'EASYSLIP_V1_BASE_URL',
|
|
20
|
-
v2BaseUrl: 'EASYSLIP_V2_BASE_URL',
|
|
21
|
-
},
|
|
22
|
-
};
|
package/dist/cjs/core/sha256.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Synchronous SHA-256 and HMAC-SHA256 (FIPS 180-4, RFC 2104), so webhook checks need no
|
|
3
|
-
// async Web Crypto call and no Node built-in.
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.sha256 = sha256;
|
|
6
|
-
exports.hmacSha256 = hmacSha256;
|
|
7
|
-
exports.toHex = toHex;
|
|
8
|
-
const K = new Uint32Array([
|
|
9
|
-
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
10
|
-
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
11
|
-
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
12
|
-
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
13
|
-
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
14
|
-
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
15
|
-
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
16
|
-
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
|
17
|
-
]);
|
|
18
|
-
/** SHA-256 digest of `data`. */
|
|
19
|
-
function sha256(data) {
|
|
20
|
-
const bitLength = data.length * 8;
|
|
21
|
-
const padded = new Uint8Array((((data.length + 9 + 63) >> 6) << 6) >>> 0);
|
|
22
|
-
padded.set(data);
|
|
23
|
-
padded[data.length] = 0x80;
|
|
24
|
-
const view = new DataView(padded.buffer);
|
|
25
|
-
view.setUint32(padded.length - 8, Math.floor(bitLength / 0x100000000));
|
|
26
|
-
view.setUint32(padded.length - 4, bitLength >>> 0);
|
|
27
|
-
const h = new Uint32Array([
|
|
28
|
-
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab,
|
|
29
|
-
0x5be0cd19,
|
|
30
|
-
]);
|
|
31
|
-
const w = new Uint32Array(64);
|
|
32
|
-
for (let offset = 0; offset < padded.length; offset += 64) {
|
|
33
|
-
for (let i = 0; i < 16; i++)
|
|
34
|
-
w[i] = view.getUint32(offset + i * 4);
|
|
35
|
-
for (let i = 16; i < 64; i++) {
|
|
36
|
-
const w15 = w[i - 15];
|
|
37
|
-
const w2 = w[i - 2];
|
|
38
|
-
const s0 = ((w15 >>> 7) | (w15 << 25)) ^ ((w15 >>> 18) | (w15 << 14)) ^ (w15 >>> 3);
|
|
39
|
-
const s1 = ((w2 >>> 17) | (w2 << 15)) ^ ((w2 >>> 19) | (w2 << 13)) ^ (w2 >>> 10);
|
|
40
|
-
w[i] = (w[i - 16] + s0 + w[i - 7] + s1) >>> 0;
|
|
41
|
-
}
|
|
42
|
-
let a = h[0];
|
|
43
|
-
let b = h[1];
|
|
44
|
-
let c = h[2];
|
|
45
|
-
let d = h[3];
|
|
46
|
-
let e = h[4];
|
|
47
|
-
let f = h[5];
|
|
48
|
-
let g = h[6];
|
|
49
|
-
let hh = h[7];
|
|
50
|
-
for (let i = 0; i < 64; i++) {
|
|
51
|
-
const S1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7));
|
|
52
|
-
const ch = (e & f) ^ (~e & g);
|
|
53
|
-
const t1 = (hh + S1 + ch + K[i] + w[i]) >>> 0;
|
|
54
|
-
const S0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10));
|
|
55
|
-
const maj = (a & b) ^ (a & c) ^ (b & c);
|
|
56
|
-
const t2 = (S0 + maj) >>> 0;
|
|
57
|
-
hh = g;
|
|
58
|
-
g = f;
|
|
59
|
-
f = e;
|
|
60
|
-
e = (d + t1) >>> 0;
|
|
61
|
-
d = c;
|
|
62
|
-
c = b;
|
|
63
|
-
b = a;
|
|
64
|
-
a = (t1 + t2) >>> 0;
|
|
65
|
-
}
|
|
66
|
-
h[0] = (h[0] + a) >>> 0;
|
|
67
|
-
h[1] = (h[1] + b) >>> 0;
|
|
68
|
-
h[2] = (h[2] + c) >>> 0;
|
|
69
|
-
h[3] = (h[3] + d) >>> 0;
|
|
70
|
-
h[4] = (h[4] + e) >>> 0;
|
|
71
|
-
h[5] = (h[5] + f) >>> 0;
|
|
72
|
-
h[6] = (h[6] + g) >>> 0;
|
|
73
|
-
h[7] = (h[7] + hh) >>> 0;
|
|
74
|
-
}
|
|
75
|
-
const out = new Uint8Array(32);
|
|
76
|
-
const outView = new DataView(out.buffer);
|
|
77
|
-
for (let i = 0; i < 8; i++)
|
|
78
|
-
outView.setUint32(i * 4, h[i]);
|
|
79
|
-
return out;
|
|
80
|
-
}
|
|
81
|
-
/** HMAC-SHA256 of `message` under `key`. */
|
|
82
|
-
function hmacSha256(key, message) {
|
|
83
|
-
const block = new Uint8Array(64);
|
|
84
|
-
block.set(key.length > 64 ? sha256(key) : key);
|
|
85
|
-
const inner = new Uint8Array(64 + message.length);
|
|
86
|
-
const outer = new Uint8Array(64 + 32);
|
|
87
|
-
for (let i = 0; i < 64; i++) {
|
|
88
|
-
inner[i] = block[i] ^ 0x36;
|
|
89
|
-
outer[i] = block[i] ^ 0x5c;
|
|
90
|
-
}
|
|
91
|
-
inner.set(message, 64);
|
|
92
|
-
outer.set(sha256(inner), 64);
|
|
93
|
-
return sha256(outer);
|
|
94
|
-
}
|
|
95
|
-
/** Lower-case hex of `bytes`. */
|
|
96
|
-
function toHex(bytes) {
|
|
97
|
-
let out = '';
|
|
98
|
-
for (const byte of bytes)
|
|
99
|
-
out += byte.toString(16).padStart(2, '0');
|
|
100
|
-
return out;
|
|
101
|
-
}
|
package/dist/cjs/models.js
DELETED
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Response models. Field presence follows the API: an optional field (`?`) can
|
|
3
|
-
// be absent, `| null` can be null, and the two are kept apart when a model is serialized again.
|
|
4
|
-
// Enum-like fields are open strings: the known values are listed, unknown values still parse.
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.shapes = exports.JobStatus = exports.MatchMode = exports.BankAccountType = exports.BankList = exports.MatchedAccountType = void 0;
|
|
7
|
-
exports.pick = pick;
|
|
8
|
-
exports.parseModel = parseModel;
|
|
9
|
-
/** Known values of {@link MatchedAccount.type}. */
|
|
10
|
-
exports.MatchedAccountType = {
|
|
11
|
-
Personal: 'PERSONAL',
|
|
12
|
-
Natural: 'NATURAL',
|
|
13
|
-
Juristic: 'JURISTIC',
|
|
14
|
-
};
|
|
15
|
-
/** `GET /banks`. Iterable; serializes to the plain array the API sends. */
|
|
16
|
-
class BankList {
|
|
17
|
-
/** The banks, ordered by code. */
|
|
18
|
-
items;
|
|
19
|
-
constructor(items) {
|
|
20
|
-
this.items = items;
|
|
21
|
-
}
|
|
22
|
-
/** Number of entries. */
|
|
23
|
-
get length() {
|
|
24
|
-
return this.items.length;
|
|
25
|
-
}
|
|
26
|
-
/** Finds an entry by code, for example `004`. */
|
|
27
|
-
find(code) {
|
|
28
|
-
return this.items.find((bank) => bank.code === code);
|
|
29
|
-
}
|
|
30
|
-
[Symbol.iterator]() {
|
|
31
|
-
return this.items[Symbol.iterator]();
|
|
32
|
-
}
|
|
33
|
-
toJSON() {
|
|
34
|
-
return this.items;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.BankList = BankList;
|
|
38
|
-
/** Known values of {@link BankAccount.type}. */
|
|
39
|
-
exports.BankAccountType = {
|
|
40
|
-
Natural: 'NATURAL',
|
|
41
|
-
Juristic: 'JURISTIC',
|
|
42
|
-
};
|
|
43
|
-
/** Known values of {@link BankAccount.matchMode}. */
|
|
44
|
-
exports.MatchMode = {
|
|
45
|
-
Name: 'NAME',
|
|
46
|
-
Number: 'NUMBER',
|
|
47
|
-
NameNumber: 'NAME_NUMBER',
|
|
48
|
-
};
|
|
49
|
-
/** Known values of {@link Job.status}. */
|
|
50
|
-
exports.JobStatus = {
|
|
51
|
-
Queued: 'queued',
|
|
52
|
-
Processing: 'processing',
|
|
53
|
-
Retrying: 'retrying',
|
|
54
|
-
Done: 'done',
|
|
55
|
-
Failed: 'failed',
|
|
56
|
-
};
|
|
57
|
-
function pick(spec, raw) {
|
|
58
|
-
if (spec === 0 || raw === null || typeof raw !== 'object')
|
|
59
|
-
return raw;
|
|
60
|
-
if (Array.isArray(spec)) {
|
|
61
|
-
const item = spec[0];
|
|
62
|
-
return Array.isArray(raw) ? raw.map((value) => pick(item, value)) : raw;
|
|
63
|
-
}
|
|
64
|
-
if (Array.isArray(raw))
|
|
65
|
-
return raw;
|
|
66
|
-
const shape = spec;
|
|
67
|
-
const out = {};
|
|
68
|
-
for (const [key, value] of Object.entries(raw)) {
|
|
69
|
-
const child = shape[key];
|
|
70
|
-
if (child !== undefined && Object.hasOwn(shape, key))
|
|
71
|
-
out[key] = pick(child, value);
|
|
72
|
-
}
|
|
73
|
-
return out;
|
|
74
|
-
}
|
|
75
|
-
const autoRenew = { expired: 0, quota: 0, createdAt: 0, expiresAt: 0 };
|
|
76
|
-
const applicationQuota = { used: 0, max: 0, remaining: 0, totalUsed: 0 };
|
|
77
|
-
const infoShape = {
|
|
78
|
-
application: { name: 0, autoRenew, quota: applicationQuota },
|
|
79
|
-
branch: {
|
|
80
|
-
name: 0,
|
|
81
|
-
isActive: 0,
|
|
82
|
-
quota: { used: 0, totalUsed: 0 },
|
|
83
|
-
},
|
|
84
|
-
account: { email: 0, credit: 0 },
|
|
85
|
-
product: { name: 0 },
|
|
86
|
-
};
|
|
87
|
-
const accountNumber = { type: 0, account: 0 };
|
|
88
|
-
const slipAccount = {
|
|
89
|
-
name: { th: 0, en: 0 },
|
|
90
|
-
bank: accountNumber,
|
|
91
|
-
proxy: accountNumber,
|
|
92
|
-
};
|
|
93
|
-
const slipBank = { id: 0, name: 0, short: 0 };
|
|
94
|
-
const slipParty = { bank: slipBank, account: slipAccount };
|
|
95
|
-
const bankSlipShape = {
|
|
96
|
-
payload: 0,
|
|
97
|
-
transRef: 0,
|
|
98
|
-
date: 0,
|
|
99
|
-
countryCode: 0,
|
|
100
|
-
amount: {
|
|
101
|
-
amount: 0,
|
|
102
|
-
local: { amount: 0, currency: 0 },
|
|
103
|
-
},
|
|
104
|
-
fee: 0,
|
|
105
|
-
ref1: 0,
|
|
106
|
-
ref2: 0,
|
|
107
|
-
ref3: 0,
|
|
108
|
-
sender: slipParty,
|
|
109
|
-
receiver: { ...slipParty, merchantId: 0 },
|
|
110
|
-
};
|
|
111
|
-
const matchedAccount = {
|
|
112
|
-
bank: { nameTh: 0, nameEn: 0, code: 0, shortCode: 0 },
|
|
113
|
-
nameTh: 0,
|
|
114
|
-
nameEn: 0,
|
|
115
|
-
type: 0,
|
|
116
|
-
bankNumber: 0,
|
|
117
|
-
};
|
|
118
|
-
const bankSlipResultShape = {
|
|
119
|
-
remark: 0,
|
|
120
|
-
isDuplicate: 0,
|
|
121
|
-
matchedAccount,
|
|
122
|
-
amountInOrder: 0,
|
|
123
|
-
amountInSlip: 0,
|
|
124
|
-
isAmountMatched: 0,
|
|
125
|
-
rawSlip: bankSlipShape,
|
|
126
|
-
};
|
|
127
|
-
const trueWalletSlipShape = {
|
|
128
|
-
transactionId: 0,
|
|
129
|
-
date: 0,
|
|
130
|
-
amount: 0,
|
|
131
|
-
sender: { name: 0 },
|
|
132
|
-
receiver: { name: 0, phone: 0 },
|
|
133
|
-
};
|
|
134
|
-
const trueWalletResultShape = {
|
|
135
|
-
...bankSlipResultShape,
|
|
136
|
-
rawSlip: trueWalletSlipShape,
|
|
137
|
-
};
|
|
138
|
-
const bankShape = {
|
|
139
|
-
code: 0,
|
|
140
|
-
nameTh: 0,
|
|
141
|
-
nameEn: 0,
|
|
142
|
-
shortCode: 0,
|
|
143
|
-
swiftCode: 0,
|
|
144
|
-
extraVerify: [{ value: 0, label: 0 }],
|
|
145
|
-
};
|
|
146
|
-
const bankAccountShape = {
|
|
147
|
-
id: 0,
|
|
148
|
-
bankCode: 0,
|
|
149
|
-
bankNumber: 0,
|
|
150
|
-
nameTh: 0,
|
|
151
|
-
nameEn: 0,
|
|
152
|
-
type: 0,
|
|
153
|
-
extraVerify: 0,
|
|
154
|
-
matchMode: 0,
|
|
155
|
-
createdAt: 0,
|
|
156
|
-
updatedAt: 0,
|
|
157
|
-
deletedAt: 0,
|
|
158
|
-
};
|
|
159
|
-
const bankAccountPageShape = {
|
|
160
|
-
items: [bankAccountShape],
|
|
161
|
-
total: 0,
|
|
162
|
-
page: 0,
|
|
163
|
-
limit: 0,
|
|
164
|
-
};
|
|
165
|
-
const jobShape = {
|
|
166
|
-
jobId: 0,
|
|
167
|
-
batchId: 0,
|
|
168
|
-
status: 0,
|
|
169
|
-
result: { status: 0, data: bankSlipResultShape },
|
|
170
|
-
error: {
|
|
171
|
-
code: 0,
|
|
172
|
-
message: 0,
|
|
173
|
-
webhook: 0,
|
|
174
|
-
url: 0,
|
|
175
|
-
status: 0,
|
|
176
|
-
at: 0,
|
|
177
|
-
},
|
|
178
|
-
attempts: 0,
|
|
179
|
-
createdAt: 0,
|
|
180
|
-
updatedAt: 0,
|
|
181
|
-
branchId: 0,
|
|
182
|
-
serviceId: 0,
|
|
183
|
-
callbackEventId: 0,
|
|
184
|
-
callbackProtocol: 0,
|
|
185
|
-
callbackDelivery: { state: 0, httpStatus: 0 },
|
|
186
|
-
};
|
|
187
|
-
const webhookEventShape = {
|
|
188
|
-
jobId: 0,
|
|
189
|
-
batchId: 0,
|
|
190
|
-
status: 0,
|
|
191
|
-
data: bankSlipResultShape,
|
|
192
|
-
error: { code: 0, message: 0 },
|
|
193
|
-
timestamp: 0,
|
|
194
|
-
};
|
|
195
|
-
/** Model name to shape, for every model a response can decode into. */
|
|
196
|
-
exports.shapes = {
|
|
197
|
-
Info: infoShape,
|
|
198
|
-
BankSlip: bankSlipShape,
|
|
199
|
-
BankSlipResult: bankSlipResultShape,
|
|
200
|
-
TrueWalletSlip: trueWalletSlipShape,
|
|
201
|
-
TrueWalletResult: trueWalletResultShape,
|
|
202
|
-
BankAccount: bankAccountShape,
|
|
203
|
-
BankAccountPage: bankAccountPageShape,
|
|
204
|
-
LinkResult: { linked: 0 },
|
|
205
|
-
UnlinkResult: { unlinked: 0 },
|
|
206
|
-
JobSubmission: { jobId: 0 },
|
|
207
|
-
BatchSubmission: {
|
|
208
|
-
batchId: 0,
|
|
209
|
-
jobs: [{ jobId: 0, index: 0 }],
|
|
210
|
-
},
|
|
211
|
-
Job: jobShape,
|
|
212
|
-
WebhookEvent: webhookEventShape,
|
|
213
|
-
V1Me: {
|
|
214
|
-
application: 0,
|
|
215
|
-
usedQuota: 0,
|
|
216
|
-
maxQuota: 0,
|
|
217
|
-
remainingQuota: 0,
|
|
218
|
-
expiredAt: 0,
|
|
219
|
-
currentCredit: 0,
|
|
220
|
-
},
|
|
221
|
-
QrCode: { image: 0, mime: 0, payload: 0 },
|
|
222
|
-
};
|
|
223
|
-
/** Builds a model from decoded JSON, keeping only the fields the model knows. */
|
|
224
|
-
function parseModel(name, raw) {
|
|
225
|
-
if (name === 'BankList') {
|
|
226
|
-
const items = Array.isArray(raw) ? pick([bankShape], raw) : [];
|
|
227
|
-
return new BankList(items);
|
|
228
|
-
}
|
|
229
|
-
const value = pick(exports.shapes[name], raw);
|
|
230
|
-
if (value === null || typeof value !== 'object') {
|
|
231
|
-
return {};
|
|
232
|
-
}
|
|
233
|
-
return value;
|
|
234
|
-
}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BankAccounts = void 0;
|
|
4
|
-
const call_js_1 = require("../core/call.js");
|
|
5
|
-
const CREATE_KEYS = [
|
|
6
|
-
'bankCode',
|
|
7
|
-
'bankNumber',
|
|
8
|
-
'nameTh',
|
|
9
|
-
'nameEn',
|
|
10
|
-
'type',
|
|
11
|
-
'extraVerify',
|
|
12
|
-
'matchMode',
|
|
13
|
-
];
|
|
14
|
-
function listQuery(params) {
|
|
15
|
-
return {
|
|
16
|
-
type: params?.type,
|
|
17
|
-
bankCode: params?.bankCode,
|
|
18
|
-
page: params?.page === undefined ? undefined : String(params.page),
|
|
19
|
-
limit: params?.limit === undefined ? undefined : String(params.limit),
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
/** Receiving bank accounts used by `matchAccount` (`client.bankAccounts`). */
|
|
23
|
-
class BankAccounts {
|
|
24
|
-
#t;
|
|
25
|
-
constructor(transport) {
|
|
26
|
-
this.#t = transport;
|
|
27
|
-
}
|
|
28
|
-
/** One page of the accounts linked to this branch. */
|
|
29
|
-
async list(params, options) {
|
|
30
|
-
return (0, call_js_1.call)(this.#t, 'BankAccountPage', {
|
|
31
|
-
...(0, call_js_1.requestOptions)(options),
|
|
32
|
-
api: 'v2',
|
|
33
|
-
method: 'GET',
|
|
34
|
-
path: '/bank-accounts',
|
|
35
|
-
query: listQuery(params),
|
|
36
|
-
retry: 'safe',
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
/** One page of every active account of the service, linked to this branch or not. */
|
|
40
|
-
async listAll(params, options) {
|
|
41
|
-
return (0, call_js_1.call)(this.#t, 'BankAccountPage', {
|
|
42
|
-
...(0, call_js_1.requestOptions)(options),
|
|
43
|
-
api: 'v2',
|
|
44
|
-
method: 'GET',
|
|
45
|
-
path: '/bank-accounts/all',
|
|
46
|
-
query: listQuery(params),
|
|
47
|
-
retry: 'safe',
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
/** Gets one account linked to this branch. */
|
|
51
|
-
async get(id, options) {
|
|
52
|
-
(0, call_js_1.requireId)(id);
|
|
53
|
-
return (0, call_js_1.call)(this.#t, 'BankAccount', {
|
|
54
|
-
...(0, call_js_1.requestOptions)(options),
|
|
55
|
-
api: 'v2',
|
|
56
|
-
method: 'GET',
|
|
57
|
-
path: `/bank-accounts/${id}`,
|
|
58
|
-
retry: 'safe',
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
/** Registers an account on the service and links it to this branch. */
|
|
62
|
-
async create(params, options) {
|
|
63
|
-
return (0, call_js_1.call)(this.#t, 'BankAccount', {
|
|
64
|
-
...(0, call_js_1.requestOptions)(options),
|
|
65
|
-
api: 'v2',
|
|
66
|
-
method: 'POST',
|
|
67
|
-
path: '/bank-accounts',
|
|
68
|
-
json: (0, call_js_1.defined)(params, CREATE_KEYS),
|
|
69
|
-
retry: 'write',
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
/** Changes the fields you pass. Pass `extraVerify: null` to clear it. */
|
|
73
|
-
async update(id, params, options) {
|
|
74
|
-
(0, call_js_1.requireId)(id);
|
|
75
|
-
return (0, call_js_1.call)(this.#t, 'BankAccount', {
|
|
76
|
-
...(0, call_js_1.requestOptions)(options),
|
|
77
|
-
api: 'v2',
|
|
78
|
-
method: 'PATCH',
|
|
79
|
-
path: `/bank-accounts/${id}`,
|
|
80
|
-
json: (0, call_js_1.defined)(params, CREATE_KEYS),
|
|
81
|
-
retry: 'write',
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
/** Links an existing service account to this branch. Linking twice is fine. */
|
|
85
|
-
async link(id, options) {
|
|
86
|
-
(0, call_js_1.requireId)(id);
|
|
87
|
-
return (0, call_js_1.call)(this.#t, 'LinkResult', {
|
|
88
|
-
...(0, call_js_1.requestOptions)(options),
|
|
89
|
-
api: 'v2',
|
|
90
|
-
method: 'POST',
|
|
91
|
-
path: `/bank-accounts/${id}/link`,
|
|
92
|
-
retry: 'safe',
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
/** Unlinks an account from this branch. The account stays on the service. */
|
|
96
|
-
async unlink(id, options) {
|
|
97
|
-
(0, call_js_1.requireId)(id);
|
|
98
|
-
return (0, call_js_1.call)(this.#t, 'UnlinkResult', {
|
|
99
|
-
...(0, call_js_1.requestOptions)(options),
|
|
100
|
-
api: 'v2',
|
|
101
|
-
method: 'DELETE',
|
|
102
|
-
path: `/bank-accounts/${id}/link`,
|
|
103
|
-
retry: 'write',
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
/** Walks every page of {@link list}, one request per page (100 accounts by default). */
|
|
107
|
-
iterate(params, options) {
|
|
108
|
-
return this.#walk((p) => this.list(p, options), params);
|
|
109
|
-
}
|
|
110
|
-
/** Walks every page of {@link listAll}. */
|
|
111
|
-
iterateAll(params, options) {
|
|
112
|
-
return this.#walk((p) => this.listAll(p, options), params);
|
|
113
|
-
}
|
|
114
|
-
async *#walk(fetchPage, params) {
|
|
115
|
-
let page = params?.page ?? 1;
|
|
116
|
-
const limit = params?.limit ?? 100;
|
|
117
|
-
while (true) {
|
|
118
|
-
const result = await fetchPage({ ...params, page, limit });
|
|
119
|
-
yield* result.items;
|
|
120
|
-
if (result.items.length === 0 || page * limit >= result.total)
|
|
121
|
-
return;
|
|
122
|
-
page++;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
exports.BankAccounts = BankAccounts;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Banks = void 0;
|
|
4
|
-
const call_js_1 = require("../core/call.js");
|
|
5
|
-
/** Supported banks and receiving kinds (`client.banks`). */
|
|
6
|
-
class Banks {
|
|
7
|
-
#t;
|
|
8
|
-
constructor(transport) {
|
|
9
|
-
this.#t = transport;
|
|
10
|
-
}
|
|
11
|
-
/** Lists the bank codes you can register accounts with, and their `extraVerify` options. */
|
|
12
|
-
async list(options) {
|
|
13
|
-
return (0, call_js_1.call)(this.#t, 'BankList', {
|
|
14
|
-
...(0, call_js_1.requestOptions)(options),
|
|
15
|
-
api: 'v2',
|
|
16
|
-
method: 'GET',
|
|
17
|
-
path: '/banks',
|
|
18
|
-
retry: 'safe',
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.Banks = Banks;
|