@easyslip/sdk 1.0.0 → 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 +14 -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/models.d.ts
CHANGED
|
@@ -143,21 +143,30 @@ export interface BankSlipResult {
|
|
|
143
143
|
isAmountMatched?: boolean;
|
|
144
144
|
rawSlip: BankSlip;
|
|
145
145
|
}
|
|
146
|
-
/**
|
|
146
|
+
/**
|
|
147
|
+
* A TrueMoney Wallet slip. v2 `rawSlip`, v1 TrueMoney `data`.
|
|
148
|
+
*
|
|
149
|
+
* `sender` and `receiver` are absent when the API has no phone for that side, so a slip can come
|
|
150
|
+
* back with neither. Newer answers carry no names.
|
|
151
|
+
*/
|
|
147
152
|
export interface TrueWalletSlip {
|
|
148
153
|
transactionId: string;
|
|
149
154
|
date: string;
|
|
150
155
|
amount: number;
|
|
151
|
-
sender
|
|
152
|
-
receiver
|
|
156
|
+
sender?: TrueWalletSender;
|
|
157
|
+
receiver?: TrueWalletReceiver;
|
|
153
158
|
}
|
|
154
159
|
export interface TrueWalletSender {
|
|
155
|
-
name
|
|
160
|
+
/** @deprecated Newer answers carry no name. */
|
|
161
|
+
name?: string;
|
|
162
|
+
/** Masked phone number, for example `08-xxx-2345`. */
|
|
163
|
+
phone?: string;
|
|
156
164
|
}
|
|
157
165
|
export interface TrueWalletReceiver {
|
|
158
|
-
name
|
|
159
|
-
|
|
160
|
-
phone
|
|
166
|
+
/** @deprecated Newer answers carry no name. */
|
|
167
|
+
name?: string;
|
|
168
|
+
/** Masked phone number, for example `08-xxx-2345`. */
|
|
169
|
+
phone?: string;
|
|
161
170
|
}
|
|
162
171
|
/** v2 TrueMoney Wallet verification result. Same options as {@link BankSlipResult}. */
|
|
163
172
|
export interface TrueWalletResult {
|
|
@@ -80,6 +80,8 @@ export declare class V1 {
|
|
|
80
80
|
verifyBankByBase64(base64: string, options?: V1VerifyOptions): Promise<WithMeta<BankSlip>>;
|
|
81
81
|
/** Verifies a bank slip image the API downloads from a public URL. */
|
|
82
82
|
verifyBankByUrl(url: string, options?: V1VerifyOptions): Promise<WithMeta<BankSlip>>;
|
|
83
|
+
/** Verifies a TrueMoney Wallet transfer from its QR text (up to 256 characters). */
|
|
84
|
+
verifyTruemoneyByPayload(payload: string, options?: V1VerifyOptions): Promise<WithMeta<TrueWalletSlip>>;
|
|
83
85
|
/** Verifies a TrueMoney Wallet slip image. */
|
|
84
86
|
verifyTruemoneyByImage(file: FileInput, options?: V1VerifyOptions): Promise<WithMeta<TrueWalletSlip>>;
|
|
85
87
|
/** Generates a payment QR image. No quota is used. */
|
|
@@ -30,6 +30,8 @@ export declare class Verify {
|
|
|
30
30
|
bankByBase64(base64: string, options?: VerifyCallOptions): Promise<WithMeta<BankSlipResult>>;
|
|
31
31
|
/** Verifies a bank slip image the API downloads from a public http(s) URL. */
|
|
32
32
|
bankByUrl(url: string, options?: VerifyCallOptions): Promise<WithMeta<BankSlipResult>>;
|
|
33
|
+
/** Verifies a TrueMoney Wallet transfer from its QR text (up to 256 characters). */
|
|
34
|
+
truewalletByPayload(payload: string, options?: VerifyCallOptions): Promise<WithMeta<TrueWalletResult>>;
|
|
33
35
|
/** Verifies a TrueMoney Wallet slip image. */
|
|
34
36
|
truewalletByImage(file: FileInput, options?: VerifyCallOptions): Promise<WithMeta<TrueWalletResult>>;
|
|
35
37
|
/** Verifies a base64 TrueMoney Wallet slip image. */
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** SDK version, sent in the User-Agent header. */
|
|
2
|
-
export declare const VERSION = "1.
|
|
2
|
+
export declare const VERSION = "1.1.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easyslip/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Official EasySlip SDK for JavaScript and TypeScript: verify Thai bank and TrueMoney Wallet slips, generate payment QR codes and check webhook signatures.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"easyslip",
|
|
@@ -55,27 +55,25 @@
|
|
|
55
55
|
"provenance": true
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
|
-
"clean": "
|
|
59
|
-
"build": "
|
|
60
|
-
"build:esm": "tsc -p tsconfig.esm.json &&
|
|
61
|
-
"build:cjs": "tsc -p tsconfig.cjs.json &&
|
|
58
|
+
"clean": "bun -e \"fs.rmSync('dist', { recursive: true, force: true })\"",
|
|
59
|
+
"build": "bun run clean && bun run build:esm && bun run build:cjs",
|
|
60
|
+
"build:esm": "bun build src/index.ts --target=node --format=esm --outdir=dist/esm && tsc -p tsconfig.esm.json && bun -e \"fs.writeFileSync('dist/esm/package.json', JSON.stringify({ type: 'module' }))\"",
|
|
61
|
+
"build:cjs": "bun build src/index.ts --target=node --format=cjs --banner='\"use strict\";' --outdir=dist/cjs && tsc -p tsconfig.cjs.json && bun -e \"fs.writeFileSync('dist/cjs/package.json', JSON.stringify({ type: 'commonjs' }))\"",
|
|
62
62
|
"lint": "biome ci .",
|
|
63
63
|
"format": "biome format --write .",
|
|
64
64
|
"typecheck": "tsc -p tsconfig.json",
|
|
65
|
-
"test": "
|
|
66
|
-
"test:coverage": "
|
|
67
|
-
"test:integration": "
|
|
68
|
-
"check:package": "
|
|
69
|
-
"prepack": "
|
|
65
|
+
"test": "bun test test/unit test/conformance.test.ts test/readme.test.ts",
|
|
66
|
+
"test:coverage": "bun test --coverage test/unit test/conformance.test.ts test/readme.test.ts",
|
|
67
|
+
"test:integration": "bun test --timeout=180000 test/integration",
|
|
68
|
+
"check:package": "bun pm pack --dry-run && publint run --strict && bun pm pack --filename=check-package.tgz && attw check-package.tgz; status=$?; rm -f check-package.tgz; exit $status",
|
|
69
|
+
"prepack": "bun run build"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@arethetypeswrong/cli": "0.18.5",
|
|
73
73
|
"@biomejs/biome": "2.6.4",
|
|
74
|
+
"@types/bun": "1.4.4",
|
|
74
75
|
"@types/node": "26.6.6",
|
|
75
|
-
"@vitest/coverage-v8": "5.0.5",
|
|
76
76
|
"publint": "0.3.25",
|
|
77
|
-
"typescript": "7.0.2"
|
|
78
|
-
"vite": "8.3.5",
|
|
79
|
-
"vitest": "5.0.5"
|
|
77
|
+
"typescript": "7.0.2"
|
|
80
78
|
}
|
|
81
79
|
}
|
package/dist/cjs/client.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Client = void 0;
|
|
4
|
-
const call_js_1 = require("./core/call.js");
|
|
5
|
-
const errors_js_1 = require("./core/errors.js");
|
|
6
|
-
const http_js_1 = require("./core/http.js");
|
|
7
|
-
const runtime_js_1 = require("./core/runtime.js");
|
|
8
|
-
const settings_js_1 = require("./core/settings.js");
|
|
9
|
-
const bank_accounts_js_1 = require("./resources/bank-accounts.js");
|
|
10
|
-
const banks_js_1 = require("./resources/banks.js");
|
|
11
|
-
const jobs_js_1 = require("./resources/jobs.js");
|
|
12
|
-
const v1_js_1 = require("./resources/v1.js");
|
|
13
|
-
const verify_js_1 = require("./resources/verify.js");
|
|
14
|
-
const version_js_1 = require("./version.js");
|
|
15
|
-
function keyFromFile(path) {
|
|
16
|
-
let cached;
|
|
17
|
-
return () => {
|
|
18
|
-
cached ??= (async () => {
|
|
19
|
-
const fs = await (0, runtime_js_1.loadFs)();
|
|
20
|
-
if (!fs) {
|
|
21
|
-
throw new errors_js_1.InputError('FILE_NOT_READABLE', `${settings_js_1.settings.env.apiKeyFile} needs a runtime with a file system`);
|
|
22
|
-
}
|
|
23
|
-
let text;
|
|
24
|
-
try {
|
|
25
|
-
text = new TextDecoder().decode(await fs.readFile(path));
|
|
26
|
-
}
|
|
27
|
-
catch (cause) {
|
|
28
|
-
throw new errors_js_1.InputError('FILE_NOT_READABLE', `cannot read ${settings_js_1.settings.env.apiKeyFile}`, {
|
|
29
|
-
cause,
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
const key = text.trim();
|
|
33
|
-
if (!key)
|
|
34
|
-
throw new errors_js_1.InputError('INVALID_ARGUMENT', `${settings_js_1.settings.env.apiKeyFile} is empty`);
|
|
35
|
-
return key;
|
|
36
|
-
})();
|
|
37
|
-
cached.catch(() => {
|
|
38
|
-
cached = undefined;
|
|
39
|
-
});
|
|
40
|
-
return cached;
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function checkNumber(value, name, min) {
|
|
44
|
-
if (value !== undefined && (!Number.isFinite(value) || value < min)) {
|
|
45
|
-
throw new errors_js_1.InputError('INVALID_ARGUMENT', `${name} must be a number >= ${min}`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* API client. Create one and reuse it.
|
|
50
|
-
*
|
|
51
|
-
* ```ts
|
|
52
|
-
* const client = new Client({ apiKey: 'YOUR_API_KEY' })
|
|
53
|
-
* const result = await client.verify.bankByPayload(payload, { checkDuplicate: true })
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
class Client {
|
|
57
|
-
/** v2 slip verification. */
|
|
58
|
-
verify;
|
|
59
|
-
/** Supported banks. */
|
|
60
|
-
banks;
|
|
61
|
-
/** Registered receiving accounts. */
|
|
62
|
-
bankAccounts;
|
|
63
|
-
/** Async verification jobs. */
|
|
64
|
-
jobs;
|
|
65
|
-
/** The v1 API. */
|
|
66
|
-
v1;
|
|
67
|
-
/** v2 base URL in use. */
|
|
68
|
-
v2BaseUrl;
|
|
69
|
-
/** v1 base URL in use. */
|
|
70
|
-
v1BaseUrl;
|
|
71
|
-
/** Per-attempt timeout in milliseconds. */
|
|
72
|
-
timeout;
|
|
73
|
-
/** Retries after the first attempt. */
|
|
74
|
-
maxRetries;
|
|
75
|
-
#transport;
|
|
76
|
-
constructor(options = {}) {
|
|
77
|
-
checkNumber(options.timeout, 'timeout', 1);
|
|
78
|
-
checkNumber(options.maxRetries, 'maxRetries', 0);
|
|
79
|
-
let apiKey;
|
|
80
|
-
const key = options.apiKey ?? (0, runtime_js_1.readEnv)(settings_js_1.settings.env.apiKey);
|
|
81
|
-
if (key !== undefined) {
|
|
82
|
-
if (typeof key !== 'string' || key.trim() === '') {
|
|
83
|
-
throw new errors_js_1.InputError('INVALID_ARGUMENT', 'apiKey must be a non-empty string');
|
|
84
|
-
}
|
|
85
|
-
const value = key.trim();
|
|
86
|
-
apiKey = () => Promise.resolve(value);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
const file = (0, runtime_js_1.readEnv)(settings_js_1.settings.env.apiKeyFile);
|
|
90
|
-
if (!file) {
|
|
91
|
-
throw new errors_js_1.InputError('INVALID_ARGUMENT', `no API key: pass apiKey or set ${settings_js_1.settings.env.apiKey} or ${settings_js_1.settings.env.apiKeyFile}`);
|
|
92
|
-
}
|
|
93
|
-
apiKey = keyFromFile(file);
|
|
94
|
-
}
|
|
95
|
-
if (!options.fetch && typeof globalThis.fetch !== 'function') {
|
|
96
|
-
throw new errors_js_1.InputError('INVALID_ARGUMENT', 'no fetch: pass options.fetch');
|
|
97
|
-
}
|
|
98
|
-
this.v2BaseUrl =
|
|
99
|
-
options.v2BaseUrl ?? (0, runtime_js_1.readEnv)(settings_js_1.settings.env.v2BaseUrl) ?? settings_js_1.settings.baseUrls.v2;
|
|
100
|
-
this.v1BaseUrl =
|
|
101
|
-
options.v1BaseUrl ?? (0, runtime_js_1.readEnv)(settings_js_1.settings.env.v1BaseUrl) ?? settings_js_1.settings.baseUrls.v1;
|
|
102
|
-
this.timeout = options.timeout ?? 30_000;
|
|
103
|
-
this.maxRetries = Math.floor(options.maxRetries ?? 2);
|
|
104
|
-
this.#transport = new http_js_1.Transport({
|
|
105
|
-
v1BaseUrl: this.v1BaseUrl,
|
|
106
|
-
v2BaseUrl: this.v2BaseUrl,
|
|
107
|
-
timeout: this.timeout,
|
|
108
|
-
maxRetries: this.maxRetries,
|
|
109
|
-
userAgent: `${settings_js_1.settings.userAgentProduct}/${version_js_1.VERSION} ${(0, runtime_js_1.runtimeToken)()}`,
|
|
110
|
-
fetch: options.fetch ?? ((input, init) => globalThis.fetch(input, init)),
|
|
111
|
-
sleep: options.sleep ?? runtime_js_1.sleep,
|
|
112
|
-
random: options.random ?? Math.random,
|
|
113
|
-
apiKey,
|
|
114
|
-
});
|
|
115
|
-
this.verify = new verify_js_1.Verify(this.#transport);
|
|
116
|
-
this.banks = new banks_js_1.Banks(this.#transport);
|
|
117
|
-
this.bankAccounts = new bank_accounts_js_1.BankAccounts(this.#transport);
|
|
118
|
-
this.jobs = new jobs_js_1.Jobs(this.#transport);
|
|
119
|
-
this.v1 = new v1_js_1.V1(this.#transport);
|
|
120
|
-
}
|
|
121
|
-
/** The User-Agent header this client sends. */
|
|
122
|
-
get userAgent() {
|
|
123
|
-
return this.#transport.config.userAgent;
|
|
124
|
-
}
|
|
125
|
-
/** Application, branch, quota and account details of the API key. */
|
|
126
|
-
async getInfo(options) {
|
|
127
|
-
return (0, call_js_1.call)(this.#transport, 'Info', {
|
|
128
|
-
...(0, call_js_1.requestOptions)(options),
|
|
129
|
-
api: 'v2',
|
|
130
|
-
method: 'GET',
|
|
131
|
-
path: '/info',
|
|
132
|
-
retry: 'safe',
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
toJSON() {
|
|
136
|
-
return {
|
|
137
|
-
v2BaseUrl: this.v2BaseUrl,
|
|
138
|
-
v1BaseUrl: this.v1BaseUrl,
|
|
139
|
-
timeout: this.timeout,
|
|
140
|
-
maxRetries: this.maxRetries,
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
toString() {
|
|
144
|
-
return `Client(${this.v2BaseUrl})`;
|
|
145
|
-
}
|
|
146
|
-
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
147
|
-
return `Client ${JSON.stringify(this.toJSON())}`;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
exports.Client = Client;
|
package/dist/cjs/core/call.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.call = call;
|
|
4
|
-
exports.requestOptions = requestOptions;
|
|
5
|
-
exports.defined = defined;
|
|
6
|
-
exports.imageForm = imageForm;
|
|
7
|
-
exports.requireString = requireString;
|
|
8
|
-
exports.requireId = requireId;
|
|
9
|
-
const models_js_1 = require("../models.js");
|
|
10
|
-
const errors_js_1 = require("./errors.js");
|
|
11
|
-
const meta_js_1 = require("./meta.js");
|
|
12
|
-
/** Sends `spec` and decodes `data` into the named model, with `meta` attached. */
|
|
13
|
-
async function call(transport, model, spec) {
|
|
14
|
-
const { data, meta } = await transport.request(spec);
|
|
15
|
-
return (0, meta_js_1.attachMeta)((0, models_js_1.parseModel)(model, data), meta);
|
|
16
|
-
}
|
|
17
|
-
/** Copies the per-call request options out of a merged options object. */
|
|
18
|
-
function requestOptions(options) {
|
|
19
|
-
if (!options)
|
|
20
|
-
return {};
|
|
21
|
-
const out = {};
|
|
22
|
-
if (options.signal !== undefined)
|
|
23
|
-
out.signal = options.signal;
|
|
24
|
-
if (options.timeout !== undefined)
|
|
25
|
-
out.timeout = options.timeout;
|
|
26
|
-
if (options.maxRetries !== undefined)
|
|
27
|
-
out.maxRetries = options.maxRetries;
|
|
28
|
-
return out;
|
|
29
|
-
}
|
|
30
|
-
/** Copies the listed keys that are set (not undefined). Explicit nulls are kept. */
|
|
31
|
-
function defined(source, keys) {
|
|
32
|
-
const out = {};
|
|
33
|
-
if (!source)
|
|
34
|
-
return out;
|
|
35
|
-
for (const key of keys) {
|
|
36
|
-
if (source[key] !== undefined)
|
|
37
|
-
out[key] = source[key];
|
|
38
|
-
}
|
|
39
|
-
return out;
|
|
40
|
-
}
|
|
41
|
-
/** Multipart form with the image part and string fields (`true`/`false`, plain numbers). */
|
|
42
|
-
function imageForm(field, file, fields) {
|
|
43
|
-
const form = new FormData();
|
|
44
|
-
for (const [key, value] of Object.entries(fields))
|
|
45
|
-
form.append(key, String(value));
|
|
46
|
-
form.append(field, new Blob([file.bytes], { type: file.contentType }), file.filename);
|
|
47
|
-
return form;
|
|
48
|
-
}
|
|
49
|
-
function requireString(value, name) {
|
|
50
|
-
if (typeof value !== 'string' || value.trim() === '') {
|
|
51
|
-
throw new errors_js_1.InputError('INVALID_ARGUMENT', `${name} must be a non-empty string`);
|
|
52
|
-
}
|
|
53
|
-
return value;
|
|
54
|
-
}
|
|
55
|
-
function requireId(value, name = 'id') {
|
|
56
|
-
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 1) {
|
|
57
|
-
throw new errors_js_1.InputError('INVALID_ARGUMENT', `${name} must be a positive integer`);
|
|
58
|
-
}
|
|
59
|
-
return value;
|
|
60
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.statusFallback = exports.errorCodes = void 0;
|
|
4
|
-
/** API error code to error class, per API version. */
|
|
5
|
-
exports.errorCodes = {
|
|
6
|
-
v1: {
|
|
7
|
-
unauthorized: 'AuthenticationError',
|
|
8
|
-
access_denied: 'PermissionDeniedError',
|
|
9
|
-
account_not_verified: 'PermissionDeniedError',
|
|
10
|
-
application_expired: 'PermissionDeniedError',
|
|
11
|
-
application_deactivated: 'PermissionDeniedError',
|
|
12
|
-
quota_exceeded: 'QuotaExceededError',
|
|
13
|
-
invalid_payload: 'InvalidRequestError',
|
|
14
|
-
invalid_check_duplicate: 'InvalidRequestError',
|
|
15
|
-
invalid_request: 'InvalidRequestError',
|
|
16
|
-
invalid_type: 'InvalidRequestError',
|
|
17
|
-
invalid_transaction_id: 'InvalidRequestError',
|
|
18
|
-
invalid_sender_name: 'InvalidRequestError',
|
|
19
|
-
invalid_receiver_name: 'InvalidRequestError',
|
|
20
|
-
invalid_receiver_phone: 'InvalidRequestError',
|
|
21
|
-
invalid_date: 'InvalidRequestError',
|
|
22
|
-
invalid_amount: 'InvalidRequestError',
|
|
23
|
-
invalid_image: 'InvalidImageError',
|
|
24
|
-
invalid_wallet_qr: 'InvalidImageError',
|
|
25
|
-
invalid_base64: 'InvalidImageError',
|
|
26
|
-
image_size_too_large: 'InvalidImageError',
|
|
27
|
-
invalid_url: 'InvalidUrlError',
|
|
28
|
-
url_unreachable: 'InvalidUrlError',
|
|
29
|
-
duplicate_slip: 'DuplicateSlipError',
|
|
30
|
-
slip_not_found: 'SlipNotFoundError',
|
|
31
|
-
qrcode_not_found: 'SlipNotFoundError',
|
|
32
|
-
slip_pending: 'SlipPendingError',
|
|
33
|
-
not_found: 'NotFoundError',
|
|
34
|
-
rate_limit_exceeded: 'RateLimitError',
|
|
35
|
-
server_error: 'ServerError',
|
|
36
|
-
api_server_error: 'ServerError',
|
|
37
|
-
renewal_temporarily_unavailable: 'ServiceUnavailableError',
|
|
38
|
-
},
|
|
39
|
-
v2: {
|
|
40
|
-
MISSING_API_KEY: 'AuthenticationError',
|
|
41
|
-
INVALID_API_KEY: 'AuthenticationError',
|
|
42
|
-
BRANCH_INACTIVE: 'PermissionDeniedError',
|
|
43
|
-
SERVICE_BANNED: 'PermissionDeniedError',
|
|
44
|
-
SERVICE_DELETED: 'PermissionDeniedError',
|
|
45
|
-
USER_BANNED: 'PermissionDeniedError',
|
|
46
|
-
IP_NOT_ALLOWED: 'PermissionDeniedError',
|
|
47
|
-
SERVICE_EXPIRED: 'PermissionDeniedError',
|
|
48
|
-
QUOTA_EXCEEDED: 'QuotaExceededError',
|
|
49
|
-
VALIDATION_ERROR: 'InvalidRequestError',
|
|
50
|
-
INVALID_BANK_CODE: 'InvalidRequestError',
|
|
51
|
-
INVALID_EXTRA_VERIFY: 'InvalidRequestError',
|
|
52
|
-
INVALID_MATCH_MODE: 'InvalidRequestError',
|
|
53
|
-
IMAGE_SIZE_TOO_LARGE: 'InvalidImageError',
|
|
54
|
-
INVALID_IMAGE_FORMAT: 'InvalidImageError',
|
|
55
|
-
INVALID_IMAGE_TYPE: 'InvalidImageError',
|
|
56
|
-
INVALID_IMAGE: 'InvalidImageError',
|
|
57
|
-
INVALID_WALLET_QR: 'InvalidImageError',
|
|
58
|
-
URL_PROTOCOL_NOT_ALLOWED: 'InvalidUrlError',
|
|
59
|
-
URL_INVALID_IP_RANGE: 'InvalidUrlError',
|
|
60
|
-
IMAGE_URL_UNREACHABLE: 'InvalidUrlError',
|
|
61
|
-
INVALID_CALLBACK_URL: 'InvalidUrlError',
|
|
62
|
-
SLIP_NOT_FOUND: 'SlipNotFoundError',
|
|
63
|
-
SLIP_PENDING: 'SlipPendingError',
|
|
64
|
-
BANK_ACCOUNT_NOT_FOUND: 'NotFoundError',
|
|
65
|
-
JOB_NOT_FOUND: 'NotFoundError',
|
|
66
|
-
NOT_FOUND: 'NotFoundError',
|
|
67
|
-
BANK_ACCOUNT_DUPLICATE: 'ConflictError',
|
|
68
|
-
RATE_LIMIT_EXCEEDED: 'RateLimitError',
|
|
69
|
-
API_SERVER_ERROR: 'ServerError',
|
|
70
|
-
INTERNAL_SERVER_ERROR: 'ServerError',
|
|
71
|
-
RENEWAL_TEMPORARILY_UNAVAILABLE: 'ServiceUnavailableError',
|
|
72
|
-
CALLBACK_UNAVAILABLE: 'ServiceUnavailableError',
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
/** Error class by HTTP status when the code is unknown. */
|
|
76
|
-
exports.statusFallback = {
|
|
77
|
-
400: 'InvalidRequestError',
|
|
78
|
-
401: 'AuthenticationError',
|
|
79
|
-
403: 'PermissionDeniedError',
|
|
80
|
-
404: 'NotFoundError',
|
|
81
|
-
409: 'ConflictError',
|
|
82
|
-
429: 'RateLimitError',
|
|
83
|
-
500: 'ServerError',
|
|
84
|
-
502: 'ServerError',
|
|
85
|
-
503: 'ServiceUnavailableError',
|
|
86
|
-
504: 'ServerError',
|
|
87
|
-
};
|
package/dist/cjs/core/errors.js
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BatchSubmitError = exports.JobWaitTimeoutError = exports.WebhookSignatureError = exports.InputError = exports.RequestTimeoutError = exports.NetworkError = exports.ServiceUnavailableError = exports.ServerError = exports.RateLimitError = exports.ConflictError = exports.SlipPendingError = exports.SlipNotFoundError = exports.NotFoundError = exports.DuplicateSlipError = exports.InvalidUrlError = exports.InvalidImageError = exports.InvalidRequestError = exports.QuotaExceededError = exports.PermissionDeniedError = exports.AuthenticationError = exports.ApiError = exports.EasySlipError = void 0;
|
|
4
|
-
exports.apiErrorClass = apiErrorClass;
|
|
5
|
-
/** Base class of every error this SDK throws. */
|
|
6
|
-
class EasySlipError extends Error {
|
|
7
|
-
constructor(message, options) {
|
|
8
|
-
super(message, options);
|
|
9
|
-
this.name = new.target.name;
|
|
10
|
-
}
|
|
11
|
-
toString() {
|
|
12
|
-
return `${this.name}: ${this.message}`;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.EasySlipError = EasySlipError;
|
|
16
|
-
/**
|
|
17
|
-
* The API answered with an error status. Subclasses tell the kind of error; `code` holds the
|
|
18
|
-
* exact API error code (for example `SLIP_NOT_FOUND` on v2, `slip_not_found` on v1).
|
|
19
|
-
*
|
|
20
|
-
* If the server echoed your API key back, the SDK has replaced it with `[REDACTED]` in the
|
|
21
|
-
* message, `rawBody`, `headers` and `details`, and `Authorization` header values are always
|
|
22
|
-
* `[REDACTED]`. Only {@link sensitiveRawBody} returns the body as received.
|
|
23
|
-
*/
|
|
24
|
-
class ApiError extends EasySlipError {
|
|
25
|
-
/** HTTP status code. */
|
|
26
|
-
status;
|
|
27
|
-
/** API error code, or null when the body was not JSON. */
|
|
28
|
-
code;
|
|
29
|
-
/** `x-request-id` header, else `cf-ray`, else null. */
|
|
30
|
-
requestId;
|
|
31
|
-
/** The response body, with the API key replaced by `[REDACTED]` if the server echoed it. */
|
|
32
|
-
rawBody;
|
|
33
|
-
/** Response headers with lower-case names, redacted like `rawBody`. */
|
|
34
|
-
headers;
|
|
35
|
-
/** v1 `details`, when present. */
|
|
36
|
-
details;
|
|
37
|
-
/** Seconds from the `Retry-After` header, when present. */
|
|
38
|
-
retryAfter;
|
|
39
|
-
/** Rate limit counters, when the API sent them. */
|
|
40
|
-
rateLimit;
|
|
41
|
-
#sensitiveRawBody;
|
|
42
|
-
constructor(init) {
|
|
43
|
-
super(init.message);
|
|
44
|
-
this.status = init.status;
|
|
45
|
-
this.code = init.code;
|
|
46
|
-
this.requestId = init.requestId;
|
|
47
|
-
this.rawBody = init.rawBody;
|
|
48
|
-
this.#sensitiveRawBody = init.sensitiveRawBody ?? init.rawBody;
|
|
49
|
-
this.headers = init.headers;
|
|
50
|
-
this.details = init.details ?? null;
|
|
51
|
-
this.retryAfter = init.retryAfter ?? null;
|
|
52
|
-
this.rateLimit = init.rateLimit ?? null;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* The response body exactly as received, without redaction. It can contain your API key if
|
|
56
|
-
* the server echoed the request: treat it as a secret and never log it.
|
|
57
|
-
*/
|
|
58
|
-
sensitiveRawBody() {
|
|
59
|
-
return this.#sensitiveRawBody;
|
|
60
|
-
}
|
|
61
|
-
toString() {
|
|
62
|
-
return `${this.name}: [${this.status}${this.code ? ` ${this.code}` : ''}] ${this.message}`;
|
|
63
|
-
}
|
|
64
|
-
/** The redacted fields, for `JSON.stringify(error)`. */
|
|
65
|
-
toJSON() {
|
|
66
|
-
return {
|
|
67
|
-
name: this.name,
|
|
68
|
-
message: this.message,
|
|
69
|
-
status: this.status,
|
|
70
|
-
code: this.code,
|
|
71
|
-
requestId: this.requestId,
|
|
72
|
-
details: this.details,
|
|
73
|
-
retryAfter: this.retryAfter,
|
|
74
|
-
rateLimit: this.rateLimit,
|
|
75
|
-
headers: this.headers,
|
|
76
|
-
rawBody: this.rawBody,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
exports.ApiError = ApiError;
|
|
81
|
-
/** The API key is missing, malformed or unknown. */
|
|
82
|
-
class AuthenticationError extends ApiError {
|
|
83
|
-
}
|
|
84
|
-
exports.AuthenticationError = AuthenticationError;
|
|
85
|
-
/** The key is valid but the account, branch or IP may not call this endpoint. */
|
|
86
|
-
class PermissionDeniedError extends ApiError {
|
|
87
|
-
}
|
|
88
|
-
exports.PermissionDeniedError = PermissionDeniedError;
|
|
89
|
-
/** The service quota is used up. Nothing was charged. */
|
|
90
|
-
class QuotaExceededError extends PermissionDeniedError {
|
|
91
|
-
}
|
|
92
|
-
exports.QuotaExceededError = QuotaExceededError;
|
|
93
|
-
/** The API rejected the request body, query or parameters. */
|
|
94
|
-
class InvalidRequestError extends ApiError {
|
|
95
|
-
}
|
|
96
|
-
exports.InvalidRequestError = InvalidRequestError;
|
|
97
|
-
/** The image is missing, too large, not an image, or not a slip of the right kind. */
|
|
98
|
-
class InvalidImageError extends InvalidRequestError {
|
|
99
|
-
}
|
|
100
|
-
exports.InvalidImageError = InvalidImageError;
|
|
101
|
-
/** An image URL or callback URL was refused. */
|
|
102
|
-
class InvalidUrlError extends InvalidRequestError {
|
|
103
|
-
}
|
|
104
|
-
exports.InvalidUrlError = InvalidUrlError;
|
|
105
|
-
/** v1 only: the slip was verified before. `slip` holds the original slip. */
|
|
106
|
-
class DuplicateSlipError extends InvalidRequestError {
|
|
107
|
-
/** The original slip the API sent with the error. */
|
|
108
|
-
slip;
|
|
109
|
-
constructor(init) {
|
|
110
|
-
super(init);
|
|
111
|
-
this.slip = init.slip ?? null;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
exports.DuplicateSlipError = DuplicateSlipError;
|
|
115
|
-
/** The resource does not exist or is not visible to this branch. */
|
|
116
|
-
class NotFoundError extends ApiError {
|
|
117
|
-
}
|
|
118
|
-
exports.NotFoundError = NotFoundError;
|
|
119
|
-
/** The bank or wallet could not find the slip, or the image has no QR code. */
|
|
120
|
-
class SlipNotFoundError extends NotFoundError {
|
|
121
|
-
}
|
|
122
|
-
exports.SlipNotFoundError = SlipNotFoundError;
|
|
123
|
-
/** Bangkok Bank slip from the last few minutes. Try again later. */
|
|
124
|
-
class SlipPendingError extends NotFoundError {
|
|
125
|
-
}
|
|
126
|
-
exports.SlipPendingError = SlipPendingError;
|
|
127
|
-
/** The request conflicts with existing data, such as a duplicate bank account. */
|
|
128
|
-
class ConflictError extends ApiError {
|
|
129
|
-
}
|
|
130
|
-
exports.ConflictError = ConflictError;
|
|
131
|
-
/** Too many requests. `retryAfter` says how long to wait. */
|
|
132
|
-
class RateLimitError extends ApiError {
|
|
133
|
-
}
|
|
134
|
-
exports.RateLimitError = RateLimitError;
|
|
135
|
-
/** 5xx from the API or an upstream bank service. */
|
|
136
|
-
class ServerError extends ApiError {
|
|
137
|
-
}
|
|
138
|
-
exports.ServerError = ServerError;
|
|
139
|
-
/** 503: a dependency is briefly unavailable. Usually sent with `retryAfter`. */
|
|
140
|
-
class ServiceUnavailableError extends ServerError {
|
|
141
|
-
}
|
|
142
|
-
exports.ServiceUnavailableError = ServiceUnavailableError;
|
|
143
|
-
/** No HTTP response arrived (DNS, connect, TLS, connection reset). */
|
|
144
|
-
class NetworkError extends EasySlipError {
|
|
145
|
-
}
|
|
146
|
-
exports.NetworkError = NetworkError;
|
|
147
|
-
/** The client timeout fired before a response arrived. */
|
|
148
|
-
class RequestTimeoutError extends NetworkError {
|
|
149
|
-
}
|
|
150
|
-
exports.RequestTimeoutError = RequestTimeoutError;
|
|
151
|
-
/** The SDK rejected an argument before sending anything. */
|
|
152
|
-
class InputError extends EasySlipError {
|
|
153
|
-
/** Why the argument was rejected. */
|
|
154
|
-
code;
|
|
155
|
-
constructor(code, message, options) {
|
|
156
|
-
super(message, options);
|
|
157
|
-
this.code = code;
|
|
158
|
-
}
|
|
159
|
-
toString() {
|
|
160
|
-
return `${this.name}: [${this.code}] ${this.message}`;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
exports.InputError = InputError;
|
|
164
|
-
/** A webhook signature header is missing, malformed or does not match the raw body. */
|
|
165
|
-
class WebhookSignatureError extends EasySlipError {
|
|
166
|
-
}
|
|
167
|
-
exports.WebhookSignatureError = WebhookSignatureError;
|
|
168
|
-
/** `waitForJob` gave up before the job finished. */
|
|
169
|
-
class JobWaitTimeoutError extends EasySlipError {
|
|
170
|
-
/** The last job state seen. */
|
|
171
|
-
lastJob;
|
|
172
|
-
constructor(message, lastJob) {
|
|
173
|
-
super(message);
|
|
174
|
-
this.lastJob = lastJob;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
exports.JobWaitTimeoutError = JobWaitTimeoutError;
|
|
178
|
-
/** `submitBankMany` failed part way. Batches already accepted keep running. */
|
|
179
|
-
class BatchSubmitError extends EasySlipError {
|
|
180
|
-
/** Batches the API accepted before the failure. */
|
|
181
|
-
submitted;
|
|
182
|
-
/** 0-based index of the chunk of 100 that failed. */
|
|
183
|
-
failedChunk;
|
|
184
|
-
constructor(submitted, failedChunk, cause) {
|
|
185
|
-
super(`batch chunk ${failedChunk} failed after ${submitted.length} accepted: ${String(cause instanceof Error ? cause.message : cause)}`, { cause });
|
|
186
|
-
this.submitted = submitted;
|
|
187
|
-
this.failedChunk = failedChunk;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
exports.BatchSubmitError = BatchSubmitError;
|
|
191
|
-
const apiErrorClasses = {
|
|
192
|
-
ApiError,
|
|
193
|
-
AuthenticationError,
|
|
194
|
-
PermissionDeniedError,
|
|
195
|
-
QuotaExceededError,
|
|
196
|
-
InvalidRequestError,
|
|
197
|
-
InvalidImageError,
|
|
198
|
-
InvalidUrlError,
|
|
199
|
-
DuplicateSlipError,
|
|
200
|
-
NotFoundError,
|
|
201
|
-
SlipNotFoundError,
|
|
202
|
-
SlipPendingError,
|
|
203
|
-
ConflictError,
|
|
204
|
-
RateLimitError,
|
|
205
|
-
ServerError,
|
|
206
|
-
ServiceUnavailableError,
|
|
207
|
-
};
|
|
208
|
-
function apiErrorClass(name) {
|
|
209
|
-
return apiErrorClasses[name];
|
|
210
|
-
}
|