@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.
- package/CHANGELOG.md +15 -0
- package/LICENSE +21 -0
- package/README.md +595 -2
- package/README.th.md +610 -0
- package/dist/cjs/client.d.ts +59 -0
- package/dist/cjs/client.js +150 -0
- package/dist/cjs/core/call.d.ts +18 -0
- package/dist/cjs/core/call.js +60 -0
- package/dist/cjs/core/error-codes.d.ts +8 -0
- package/dist/cjs/core/error-codes.js +87 -0
- package/dist/cjs/core/errors.d.ts +162 -0
- package/dist/cjs/core/errors.js +210 -0
- package/dist/cjs/core/files.d.ts +20 -0
- package/dist/cjs/core/files.js +131 -0
- package/dist/cjs/core/http.d.ts +65 -0
- package/dist/cjs/core/http.js +242 -0
- package/dist/cjs/core/meta.d.ts +33 -0
- package/dist/cjs/core/meta.js +52 -0
- package/dist/cjs/core/redact.d.ts +43 -0
- package/dist/cjs/core/redact.js +208 -0
- package/dist/cjs/core/runtime.d.ts +16 -0
- package/dist/cjs/core/runtime.js +86 -0
- package/dist/cjs/core/settings.d.ts +19 -0
- package/dist/cjs/core/settings.js +22 -0
- package/dist/cjs/core/sha256.d.ts +6 -0
- package/dist/cjs/core/sha256.js +101 -0
- package/dist/cjs/index.d.ts +13 -0
- package/dist/cjs/index.js +55 -0
- package/dist/cjs/models.d.ts +398 -0
- package/dist/cjs/models.js +234 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/resources/bank-accounts.d.ts +63 -0
- package/dist/cjs/resources/bank-accounts.js +126 -0
- package/dist/cjs/resources/banks.d.ts +10 -0
- package/dist/cjs/resources/banks.js +22 -0
- package/dist/cjs/resources/jobs.d.ts +64 -0
- package/dist/cjs/resources/jobs.js +177 -0
- package/dist/cjs/resources/v1.d.ts +88 -0
- package/dist/cjs/resources/v1.js +137 -0
- package/dist/cjs/resources/verify.d.ts +39 -0
- package/dist/cjs/resources/verify.js +105 -0
- package/dist/cjs/version.d.ts +2 -0
- package/dist/cjs/version.js +5 -0
- package/dist/cjs/webhooks.d.ts +26 -0
- package/dist/cjs/webhooks.js +92 -0
- package/dist/esm/client.d.ts +59 -0
- package/dist/esm/client.js +146 -0
- package/dist/esm/core/call.d.ts +18 -0
- package/dist/esm/core/call.js +52 -0
- package/dist/esm/core/error-codes.d.ts +8 -0
- package/dist/esm/core/error-codes.js +84 -0
- package/dist/esm/core/errors.d.ts +162 -0
- package/dist/esm/core/errors.js +184 -0
- package/dist/esm/core/files.d.ts +20 -0
- package/dist/esm/core/files.js +126 -0
- package/dist/esm/core/http.d.ts +65 -0
- package/dist/esm/core/http.js +235 -0
- package/dist/esm/core/meta.d.ts +33 -0
- package/dist/esm/core/meta.js +45 -0
- package/dist/esm/core/redact.d.ts +43 -0
- package/dist/esm/core/redact.js +198 -0
- package/dist/esm/core/runtime.d.ts +16 -0
- package/dist/esm/core/runtime.js +47 -0
- package/dist/esm/core/settings.d.ts +19 -0
- package/dist/esm/core/settings.js +19 -0
- package/dist/esm/core/sha256.d.ts +6 -0
- package/dist/esm/core/sha256.js +96 -0
- package/dist/esm/index.d.ts +13 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/models.d.ts +398 -0
- package/dist/esm/models.js +228 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/resources/bank-accounts.d.ts +63 -0
- package/dist/esm/resources/bank-accounts.js +122 -0
- package/dist/esm/resources/banks.d.ts +10 -0
- package/dist/esm/resources/banks.js +18 -0
- package/dist/esm/resources/jobs.d.ts +64 -0
- package/dist/esm/resources/jobs.js +173 -0
- package/dist/esm/resources/v1.d.ts +88 -0
- package/dist/esm/resources/v1.js +133 -0
- package/dist/esm/resources/verify.d.ts +39 -0
- package/dist/esm/resources/verify.js +100 -0
- package/dist/esm/version.d.ts +2 -0
- package/dist/esm/version.js +2 -0
- package/dist/esm/webhooks.d.ts +26 -0
- package/dist/esm/webhooks.js +86 -0
- package/package.json +80 -5
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type FetchLike, type RequestOptions } from './core/http.js';
|
|
2
|
+
import type { WithMeta } from './core/meta.js';
|
|
3
|
+
import type { Info } from './models.js';
|
|
4
|
+
import { BankAccounts } from './resources/bank-accounts.js';
|
|
5
|
+
import { Banks } from './resources/banks.js';
|
|
6
|
+
import { Jobs } from './resources/jobs.js';
|
|
7
|
+
import { V1 } from './resources/v1.js';
|
|
8
|
+
import { Verify } from './resources/verify.js';
|
|
9
|
+
/** Client settings. Every field is optional when the matching env variable is set. */
|
|
10
|
+
export interface ClientOptions {
|
|
11
|
+
/** API key. Defaults to the API key env variable, then the file named by the key file env variable. */
|
|
12
|
+
apiKey?: string;
|
|
13
|
+
/** v2 base URL. Defaults to the v2 base URL env variable, then the production host. */
|
|
14
|
+
v2BaseUrl?: string;
|
|
15
|
+
/** v1 base URL. Defaults to the v1 base URL env variable, then the production host. */
|
|
16
|
+
v1BaseUrl?: string;
|
|
17
|
+
/** Per-attempt timeout in milliseconds. Default 30000. */
|
|
18
|
+
timeout?: number;
|
|
19
|
+
/** Retries after the first attempt, following each call's retry class. Default 2. */
|
|
20
|
+
maxRetries?: number;
|
|
21
|
+
/** A fetch implementation, for proxies, custom agents or tests. Default: global fetch. */
|
|
22
|
+
fetch?: FetchLike;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* API client. Create one and reuse it.
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* const client = new Client({ apiKey: 'YOUR_API_KEY' })
|
|
29
|
+
* const result = await client.verify.bankByPayload(payload, { checkDuplicate: true })
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare class Client {
|
|
33
|
+
#private;
|
|
34
|
+
/** v2 slip verification. */
|
|
35
|
+
readonly verify: Verify;
|
|
36
|
+
/** Supported banks. */
|
|
37
|
+
readonly banks: Banks;
|
|
38
|
+
/** Registered receiving accounts. */
|
|
39
|
+
readonly bankAccounts: BankAccounts;
|
|
40
|
+
/** Async verification jobs. */
|
|
41
|
+
readonly jobs: Jobs;
|
|
42
|
+
/** The v1 API. */
|
|
43
|
+
readonly v1: V1;
|
|
44
|
+
/** v2 base URL in use. */
|
|
45
|
+
readonly v2BaseUrl: string;
|
|
46
|
+
/** v1 base URL in use. */
|
|
47
|
+
readonly v1BaseUrl: string;
|
|
48
|
+
/** Per-attempt timeout in milliseconds. */
|
|
49
|
+
readonly timeout: number;
|
|
50
|
+
/** Retries after the first attempt. */
|
|
51
|
+
readonly maxRetries: number;
|
|
52
|
+
constructor(options?: ClientOptions);
|
|
53
|
+
/** The User-Agent header this client sends. */
|
|
54
|
+
get userAgent(): string;
|
|
55
|
+
/** Application, branch, quota and account details of the API key. */
|
|
56
|
+
getInfo(options?: RequestOptions): Promise<WithMeta<Info>>;
|
|
57
|
+
toJSON(): Record<string, unknown>;
|
|
58
|
+
toString(): string;
|
|
59
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
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;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ModelName, parseModel } from '../models.js';
|
|
2
|
+
import type { PreparedFile } from './files.js';
|
|
3
|
+
import type { RequestOptions, RequestSpec, Transport } from './http.js';
|
|
4
|
+
import { type WithMeta } from './meta.js';
|
|
5
|
+
type Models = {
|
|
6
|
+
[N in ModelName]: ReturnType<typeof parseModel<N>>;
|
|
7
|
+
};
|
|
8
|
+
/** Sends `spec` and decodes `data` into the named model, with `meta` attached. */
|
|
9
|
+
export declare function call<N extends ModelName>(transport: Transport, model: N, spec: RequestSpec): Promise<WithMeta<Models[N]>>;
|
|
10
|
+
/** Copies the per-call request options out of a merged options object. */
|
|
11
|
+
export declare function requestOptions(options: RequestOptions | undefined): RequestOptions;
|
|
12
|
+
/** Copies the listed keys that are set (not undefined). Explicit nulls are kept. */
|
|
13
|
+
export declare function defined<T extends object, K extends keyof T>(source: T | undefined, keys: readonly K[]): Partial<Pick<T, K>>;
|
|
14
|
+
/** Multipart form with the image part and string fields (`true`/`false`, plain numbers). */
|
|
15
|
+
export declare function imageForm(field: string, file: PreparedFile, fields: Record<string, string | number | boolean>): FormData;
|
|
16
|
+
export declare function requireString(value: unknown, name: string): string;
|
|
17
|
+
export declare function requireId(value: unknown, name?: string): number;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ApiErrorClassName } from './errors.js';
|
|
2
|
+
/** API error code to error class, per API version. */
|
|
3
|
+
export declare const errorCodes: {
|
|
4
|
+
readonly v1: Readonly<Record<string, ApiErrorClassName>>;
|
|
5
|
+
readonly v2: Readonly<Record<string, ApiErrorClassName>>;
|
|
6
|
+
};
|
|
7
|
+
/** Error class by HTTP status when the code is unknown. */
|
|
8
|
+
export declare const statusFallback: Readonly<Record<number, ApiErrorClassName>>;
|
|
@@ -0,0 +1,87 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import type { BankSlip, BatchSubmission, Job, TrueWalletSlip } from '../models.js';
|
|
2
|
+
import type { RateLimit } from './meta.js';
|
|
3
|
+
/** Base class of every error this SDK throws. */
|
|
4
|
+
export declare class EasySlipError extends Error {
|
|
5
|
+
constructor(message: string, options?: ErrorOptions);
|
|
6
|
+
toString(): string;
|
|
7
|
+
}
|
|
8
|
+
/** v1 `details`: a message, or one entry per rejected field. */
|
|
9
|
+
export type ErrorDetails = string | ReadonlyArray<{
|
|
10
|
+
readonly field: string;
|
|
11
|
+
readonly message: string;
|
|
12
|
+
}>;
|
|
13
|
+
/** Everything known about an HTTP error response. */
|
|
14
|
+
export interface ApiErrorInit {
|
|
15
|
+
status: number;
|
|
16
|
+
code: string | null;
|
|
17
|
+
message: string;
|
|
18
|
+
requestId: string | null;
|
|
19
|
+
/** The body as it may be shown: with the API key redacted. */
|
|
20
|
+
rawBody: string;
|
|
21
|
+
/** The body exactly as received, for {@link ApiError.sensitiveRawBody}. Defaults to `rawBody`. */
|
|
22
|
+
sensitiveRawBody?: string;
|
|
23
|
+
headers: Readonly<Record<string, string>>;
|
|
24
|
+
details?: ErrorDetails | null;
|
|
25
|
+
retryAfter?: number | null;
|
|
26
|
+
rateLimit?: RateLimit | null;
|
|
27
|
+
slip?: BankSlip | TrueWalletSlip | null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The API answered with an error status. Subclasses tell the kind of error; `code` holds the
|
|
31
|
+
* exact API error code (for example `SLIP_NOT_FOUND` on v2, `slip_not_found` on v1).
|
|
32
|
+
*
|
|
33
|
+
* If the server echoed your API key back, the SDK has replaced it with `[REDACTED]` in the
|
|
34
|
+
* message, `rawBody`, `headers` and `details`, and `Authorization` header values are always
|
|
35
|
+
* `[REDACTED]`. Only {@link sensitiveRawBody} returns the body as received.
|
|
36
|
+
*/
|
|
37
|
+
export declare class ApiError extends EasySlipError {
|
|
38
|
+
#private;
|
|
39
|
+
/** HTTP status code. */
|
|
40
|
+
readonly status: number;
|
|
41
|
+
/** API error code, or null when the body was not JSON. */
|
|
42
|
+
readonly code: string | null;
|
|
43
|
+
/** `x-request-id` header, else `cf-ray`, else null. */
|
|
44
|
+
readonly requestId: string | null;
|
|
45
|
+
/** The response body, with the API key replaced by `[REDACTED]` if the server echoed it. */
|
|
46
|
+
readonly rawBody: string;
|
|
47
|
+
/** Response headers with lower-case names, redacted like `rawBody`. */
|
|
48
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
49
|
+
/** v1 `details`, when present. */
|
|
50
|
+
readonly details: ErrorDetails | null;
|
|
51
|
+
/** Seconds from the `Retry-After` header, when present. */
|
|
52
|
+
readonly retryAfter: number | null;
|
|
53
|
+
/** Rate limit counters, when the API sent them. */
|
|
54
|
+
readonly rateLimit: RateLimit | null;
|
|
55
|
+
constructor(init: ApiErrorInit);
|
|
56
|
+
/**
|
|
57
|
+
* The response body exactly as received, without redaction. It can contain your API key if
|
|
58
|
+
* the server echoed the request: treat it as a secret and never log it.
|
|
59
|
+
*/
|
|
60
|
+
sensitiveRawBody(): string;
|
|
61
|
+
toString(): string;
|
|
62
|
+
/** The redacted fields, for `JSON.stringify(error)`. */
|
|
63
|
+
toJSON(): Record<string, unknown>;
|
|
64
|
+
}
|
|
65
|
+
/** The API key is missing, malformed or unknown. */
|
|
66
|
+
export declare class AuthenticationError extends ApiError {
|
|
67
|
+
}
|
|
68
|
+
/** The key is valid but the account, branch or IP may not call this endpoint. */
|
|
69
|
+
export declare class PermissionDeniedError extends ApiError {
|
|
70
|
+
}
|
|
71
|
+
/** The service quota is used up. Nothing was charged. */
|
|
72
|
+
export declare class QuotaExceededError extends PermissionDeniedError {
|
|
73
|
+
}
|
|
74
|
+
/** The API rejected the request body, query or parameters. */
|
|
75
|
+
export declare class InvalidRequestError extends ApiError {
|
|
76
|
+
}
|
|
77
|
+
/** The image is missing, too large, not an image, or not a slip of the right kind. */
|
|
78
|
+
export declare class InvalidImageError extends InvalidRequestError {
|
|
79
|
+
}
|
|
80
|
+
/** An image URL or callback URL was refused. */
|
|
81
|
+
export declare class InvalidUrlError extends InvalidRequestError {
|
|
82
|
+
}
|
|
83
|
+
/** v1 only: the slip was verified before. `slip` holds the original slip. */
|
|
84
|
+
export declare class DuplicateSlipError extends InvalidRequestError {
|
|
85
|
+
/** The original slip the API sent with the error. */
|
|
86
|
+
readonly slip: BankSlip | TrueWalletSlip | null;
|
|
87
|
+
constructor(init: ApiErrorInit);
|
|
88
|
+
}
|
|
89
|
+
/** The resource does not exist or is not visible to this branch. */
|
|
90
|
+
export declare class NotFoundError extends ApiError {
|
|
91
|
+
}
|
|
92
|
+
/** The bank or wallet could not find the slip, or the image has no QR code. */
|
|
93
|
+
export declare class SlipNotFoundError extends NotFoundError {
|
|
94
|
+
}
|
|
95
|
+
/** Bangkok Bank slip from the last few minutes. Try again later. */
|
|
96
|
+
export declare class SlipPendingError extends NotFoundError {
|
|
97
|
+
}
|
|
98
|
+
/** The request conflicts with existing data, such as a duplicate bank account. */
|
|
99
|
+
export declare class ConflictError extends ApiError {
|
|
100
|
+
}
|
|
101
|
+
/** Too many requests. `retryAfter` says how long to wait. */
|
|
102
|
+
export declare class RateLimitError extends ApiError {
|
|
103
|
+
}
|
|
104
|
+
/** 5xx from the API or an upstream bank service. */
|
|
105
|
+
export declare class ServerError extends ApiError {
|
|
106
|
+
}
|
|
107
|
+
/** 503: a dependency is briefly unavailable. Usually sent with `retryAfter`. */
|
|
108
|
+
export declare class ServiceUnavailableError extends ServerError {
|
|
109
|
+
}
|
|
110
|
+
/** No HTTP response arrived (DNS, connect, TLS, connection reset). */
|
|
111
|
+
export declare class NetworkError extends EasySlipError {
|
|
112
|
+
}
|
|
113
|
+
/** The client timeout fired before a response arrived. */
|
|
114
|
+
export declare class RequestTimeoutError extends NetworkError {
|
|
115
|
+
}
|
|
116
|
+
/** Codes of {@link InputError}. */
|
|
117
|
+
export type InputErrorCode = 'FILE_TOO_LARGE' | 'UNSUPPORTED_FILE_TYPE' | 'EMPTY_FILE' | 'FILE_NOT_READABLE' | 'BATCH_TOO_LARGE' | 'EMPTY_BATCH' | 'INVALID_ARGUMENT';
|
|
118
|
+
/** The SDK rejected an argument before sending anything. */
|
|
119
|
+
export declare class InputError extends EasySlipError {
|
|
120
|
+
/** Why the argument was rejected. */
|
|
121
|
+
readonly code: InputErrorCode;
|
|
122
|
+
constructor(code: InputErrorCode, message: string, options?: ErrorOptions);
|
|
123
|
+
toString(): string;
|
|
124
|
+
}
|
|
125
|
+
/** A webhook signature header is missing, malformed or does not match the raw body. */
|
|
126
|
+
export declare class WebhookSignatureError extends EasySlipError {
|
|
127
|
+
}
|
|
128
|
+
/** `waitForJob` gave up before the job finished. */
|
|
129
|
+
export declare class JobWaitTimeoutError extends EasySlipError {
|
|
130
|
+
/** The last job state seen. */
|
|
131
|
+
readonly lastJob: Job | null;
|
|
132
|
+
constructor(message: string, lastJob: Job | null);
|
|
133
|
+
}
|
|
134
|
+
/** `submitBankMany` failed part way. Batches already accepted keep running. */
|
|
135
|
+
export declare class BatchSubmitError extends EasySlipError {
|
|
136
|
+
/** Batches the API accepted before the failure. */
|
|
137
|
+
readonly submitted: readonly BatchSubmission[];
|
|
138
|
+
/** 0-based index of the chunk of 100 that failed. */
|
|
139
|
+
readonly failedChunk: number;
|
|
140
|
+
constructor(submitted: readonly BatchSubmission[], failedChunk: number, cause: unknown);
|
|
141
|
+
}
|
|
142
|
+
declare const apiErrorClasses: {
|
|
143
|
+
ApiError: typeof ApiError;
|
|
144
|
+
AuthenticationError: typeof AuthenticationError;
|
|
145
|
+
PermissionDeniedError: typeof PermissionDeniedError;
|
|
146
|
+
QuotaExceededError: typeof QuotaExceededError;
|
|
147
|
+
InvalidRequestError: typeof InvalidRequestError;
|
|
148
|
+
InvalidImageError: typeof InvalidImageError;
|
|
149
|
+
InvalidUrlError: typeof InvalidUrlError;
|
|
150
|
+
DuplicateSlipError: typeof DuplicateSlipError;
|
|
151
|
+
NotFoundError: typeof NotFoundError;
|
|
152
|
+
SlipNotFoundError: typeof SlipNotFoundError;
|
|
153
|
+
SlipPendingError: typeof SlipPendingError;
|
|
154
|
+
ConflictError: typeof ConflictError;
|
|
155
|
+
RateLimitError: typeof RateLimitError;
|
|
156
|
+
ServerError: typeof ServerError;
|
|
157
|
+
ServiceUnavailableError: typeof ServiceUnavailableError;
|
|
158
|
+
};
|
|
159
|
+
/** Names of the error classes an HTTP error can map to. */
|
|
160
|
+
export type ApiErrorClassName = keyof typeof apiErrorClasses;
|
|
161
|
+
export declare function apiErrorClass(name: ApiErrorClassName): typeof ApiError;
|
|
162
|
+
export {};
|