@suqo/sdk 1.0.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/LICENSE +21 -0
- package/README.md +65 -0
- package/dist/index.cjs +876 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1045 -0
- package/dist/index.d.ts +1045 -0
- package/dist/index.js +858 -0
- package/dist/index.js.map +1 -0
- package/package.json +75 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,876 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var crypto = require('crypto');
|
|
4
|
+
|
|
5
|
+
// src/errors/SuqoError.ts
|
|
6
|
+
var SuqoError = class extends Error {
|
|
7
|
+
constructor(message, options = {}) {
|
|
8
|
+
super(message, options.cause !== void 0 ? { cause: options.cause } : void 0);
|
|
9
|
+
this.name = new.target.name;
|
|
10
|
+
this.rawBody = options.rawBody;
|
|
11
|
+
if (options.status !== void 0) this.status = options.status;
|
|
12
|
+
if (options.requestId !== void 0) this.requestId = options.requestId;
|
|
13
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var SuqoConfigError = class extends SuqoError {
|
|
17
|
+
constructor(message, options = {}) {
|
|
18
|
+
super(message, options);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var AuthenticationError = class extends SuqoError {
|
|
22
|
+
};
|
|
23
|
+
var KycRequiredError = class extends SuqoError {
|
|
24
|
+
constructor(message, options = {}) {
|
|
25
|
+
super(message, options);
|
|
26
|
+
if (options.kycStatus !== void 0) this.kycStatus = options.kycStatus;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var ValidationError = class extends SuqoError {
|
|
30
|
+
constructor(message, options = {}) {
|
|
31
|
+
super(message, options);
|
|
32
|
+
this.fieldErrors = options.fieldErrors ?? {};
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var NotFoundError = class extends SuqoError {
|
|
36
|
+
};
|
|
37
|
+
var RateLimitError = class extends SuqoError {
|
|
38
|
+
constructor(message, options = {}) {
|
|
39
|
+
super(message, options);
|
|
40
|
+
if (options.retryAfter !== void 0) this.retryAfter = options.retryAfter;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var ServerError = class extends SuqoError {
|
|
44
|
+
};
|
|
45
|
+
var NetworkError = class extends SuqoError {
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/utils/isRecord.ts
|
|
49
|
+
function isRecord(value) {
|
|
50
|
+
return typeof value === "object" && value !== null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/errors/mapHttpError.ts
|
|
54
|
+
function isDetailShaped(body) {
|
|
55
|
+
return isRecord(body) && typeof body.detail === "string" && body.detail.length > 0;
|
|
56
|
+
}
|
|
57
|
+
function fieldErrorsFrom(body, pathPrefix = "") {
|
|
58
|
+
if (!isRecord(body)) return {};
|
|
59
|
+
const fieldErrors = {};
|
|
60
|
+
for (const [rawKey, value] of Object.entries(body)) {
|
|
61
|
+
const key = pathPrefix === "" && rawKey === "client" ? "customer" : rawKey;
|
|
62
|
+
const path = pathPrefix === "" ? key : `${pathPrefix}.${key}`;
|
|
63
|
+
if (typeof value === "string") {
|
|
64
|
+
fieldErrors[path] = [value];
|
|
65
|
+
} else if (Array.isArray(value) && value.every((item) => typeof item === "string")) {
|
|
66
|
+
fieldErrors[path] = value;
|
|
67
|
+
} else if (isRecord(value) && !Array.isArray(value)) {
|
|
68
|
+
Object.assign(fieldErrors, fieldErrorsFrom(value, path));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return fieldErrors;
|
|
72
|
+
}
|
|
73
|
+
function messageFrom(body, fallback) {
|
|
74
|
+
if (isRecord(body)) {
|
|
75
|
+
if (typeof body.detail === "string" && body.detail.length > 0) return body.detail;
|
|
76
|
+
if (typeof body.message === "string" && body.message.length > 0) return body.message;
|
|
77
|
+
}
|
|
78
|
+
return fallback;
|
|
79
|
+
}
|
|
80
|
+
function mapHttpError(input) {
|
|
81
|
+
const { status, statusText, body, requestId, retryAfter } = input;
|
|
82
|
+
const fallbackMessage = `Request failed with status ${status}${statusText ? ` (${statusText})` : ""}`;
|
|
83
|
+
const base = { status, rawBody: body, ...requestId !== void 0 ? { requestId } : {} };
|
|
84
|
+
switch (status) {
|
|
85
|
+
case 401:
|
|
86
|
+
return new AuthenticationError(messageFrom(body, fallbackMessage), base);
|
|
87
|
+
case 403: {
|
|
88
|
+
const kycStatus = isRecord(body) && typeof body.status_code === "string" ? body.status_code : void 0;
|
|
89
|
+
const message = messageFrom(body, "KYC verification needed to perform this action.");
|
|
90
|
+
return new KycRequiredError(message, { ...base, ...kycStatus !== void 0 ? { kycStatus } : {} });
|
|
91
|
+
}
|
|
92
|
+
case 400: {
|
|
93
|
+
if (isDetailShaped(body)) {
|
|
94
|
+
return new ValidationError(body.detail, base);
|
|
95
|
+
}
|
|
96
|
+
return new ValidationError("Validation failed.", { ...base, fieldErrors: fieldErrorsFrom(body) });
|
|
97
|
+
}
|
|
98
|
+
case 404:
|
|
99
|
+
return new NotFoundError(messageFrom(body, "Not found."), base);
|
|
100
|
+
case 429:
|
|
101
|
+
return new RateLimitError(messageFrom(body, fallbackMessage), {
|
|
102
|
+
...base,
|
|
103
|
+
...retryAfter !== void 0 ? { retryAfter } : {}
|
|
104
|
+
});
|
|
105
|
+
default:
|
|
106
|
+
return new ServerError(messageFrom(body, fallbackMessage), base);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/config/environments.ts
|
|
111
|
+
var SANDBOX_BASE_URL = "https://test-be.suqo.ai";
|
|
112
|
+
var LIVE_BASE_URL = "https://be.suqo.ai";
|
|
113
|
+
var KEY_PREFIXES = [
|
|
114
|
+
{ prefix: "su_test_key_", environment: "sandbox", baseUrl: SANDBOX_BASE_URL },
|
|
115
|
+
{ prefix: "su_key_", environment: "live", baseUrl: LIVE_BASE_URL }
|
|
116
|
+
];
|
|
117
|
+
function resolveEnvironment(apiKey, override) {
|
|
118
|
+
if (typeof apiKey !== "string" || apiKey.length === 0) {
|
|
119
|
+
throw new SuqoConfigError("A SUQO API key is required.");
|
|
120
|
+
}
|
|
121
|
+
const match = KEY_PREFIXES.find(({ prefix }) => apiKey.startsWith(prefix));
|
|
122
|
+
if (!match) {
|
|
123
|
+
throw new SuqoConfigError(
|
|
124
|
+
'Malformed SUQO API key: expected prefix "su_key_" (live) or "su_test_key_" (sandbox).'
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
if (override !== void 0 && override !== match.baseUrl) {
|
|
128
|
+
throw new SuqoConfigError(
|
|
129
|
+
`Environment mismatch: key implies ${match.baseUrl} but baseUrl was set to ${override}. Remove baseUrl or use a matching key.`
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
return { environment: match.environment, baseUrl: override ?? match.baseUrl };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// src/config/SdkConfig.ts
|
|
136
|
+
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
137
|
+
var DEFAULT_MAX_RETRIES = 2;
|
|
138
|
+
var NODE_INSPECT_CUSTOM = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
139
|
+
var SdkConfig = class {
|
|
140
|
+
#apiKey;
|
|
141
|
+
constructor(input) {
|
|
142
|
+
const { environment, baseUrl } = resolveEnvironment(input.apiKey, input.baseUrl);
|
|
143
|
+
this.environment = environment;
|
|
144
|
+
this.baseUrl = baseUrl;
|
|
145
|
+
this.timeout = input.timeout ?? DEFAULT_TIMEOUT_MS;
|
|
146
|
+
this.maxRetries = input.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
147
|
+
this.dispatcher = input.dispatcher;
|
|
148
|
+
this.#apiKey = input.apiKey;
|
|
149
|
+
}
|
|
150
|
+
/** The raw API key, for building the `Authorization: Bearer <key>` header (`http.ts`, Ticket 2). Never logged. */
|
|
151
|
+
get apiKey() {
|
|
152
|
+
return this.#apiKey;
|
|
153
|
+
}
|
|
154
|
+
/** Redacts the key so it never appears in `JSON.stringify` output (SDK-SPEC.md §4). */
|
|
155
|
+
toJSON() {
|
|
156
|
+
return {
|
|
157
|
+
environment: this.environment,
|
|
158
|
+
baseUrl: this.baseUrl,
|
|
159
|
+
timeout: this.timeout,
|
|
160
|
+
maxRetries: this.maxRetries,
|
|
161
|
+
apiKey: "[redacted]"
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
/** Redacts the key so it never appears in `util.inspect`/`console.log` output (SDK-SPEC.md §4). */
|
|
165
|
+
[NODE_INSPECT_CUSTOM]() {
|
|
166
|
+
return this.toJSON();
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// src/http/urlBuilder.ts
|
|
171
|
+
function buildUrl(baseUrl, path, query) {
|
|
172
|
+
const url = new URL(path, baseUrl);
|
|
173
|
+
if (!url.pathname.endsWith("/")) {
|
|
174
|
+
url.pathname = `${url.pathname}/`;
|
|
175
|
+
}
|
|
176
|
+
if (query) {
|
|
177
|
+
for (const [key, value] of Object.entries(query)) {
|
|
178
|
+
if (value !== void 0) url.searchParams.set(key, String(value));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return url.toString();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// src/http/retry.ts
|
|
185
|
+
var RETRYABLE_METHODS = /* @__PURE__ */ new Set(["GET"]);
|
|
186
|
+
function isRetryableMethod(method) {
|
|
187
|
+
return RETRYABLE_METHODS.has(method);
|
|
188
|
+
}
|
|
189
|
+
function isRetryableFailure(input) {
|
|
190
|
+
if (input.networkError) return true;
|
|
191
|
+
if (input.status === void 0) return false;
|
|
192
|
+
return input.status === 429 || input.status >= 500 && input.status <= 599;
|
|
193
|
+
}
|
|
194
|
+
var BASE_DELAY_MS = 500;
|
|
195
|
+
var MAX_DELAY_MS = 8e3;
|
|
196
|
+
function backoffDelayMs(attempt) {
|
|
197
|
+
const cap = Math.min(MAX_DELAY_MS, BASE_DELAY_MS * 2 ** attempt);
|
|
198
|
+
return Math.random() * cap;
|
|
199
|
+
}
|
|
200
|
+
var MAX_RETRY_AFTER_MS = 6e4;
|
|
201
|
+
function parseRetryAfterMs(headerValue, now = Date.now()) {
|
|
202
|
+
if (headerValue === null) return void 0;
|
|
203
|
+
const trimmed = headerValue.trim();
|
|
204
|
+
if (trimmed.length === 0) return void 0;
|
|
205
|
+
const seconds = Number(trimmed);
|
|
206
|
+
if (Number.isFinite(seconds)) {
|
|
207
|
+
if (seconds < 0) return void 0;
|
|
208
|
+
return Math.min(seconds * 1e3, MAX_RETRY_AFTER_MS);
|
|
209
|
+
}
|
|
210
|
+
const dateMs = Date.parse(trimmed);
|
|
211
|
+
if (Number.isNaN(dateMs)) return void 0;
|
|
212
|
+
const delta = Math.max(dateMs - now, 0);
|
|
213
|
+
return Math.min(delta, MAX_RETRY_AFTER_MS);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// src/http/signals.ts
|
|
217
|
+
function combineSignals(signals) {
|
|
218
|
+
const controller = new AbortController();
|
|
219
|
+
const cleanupFns = [];
|
|
220
|
+
for (const signal of signals) {
|
|
221
|
+
if (!signal) continue;
|
|
222
|
+
if (signal.aborted) {
|
|
223
|
+
controller.abort(signal.reason);
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
const onAbort = () => controller.abort(signal.reason);
|
|
227
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
228
|
+
cleanupFns.push(() => signal.removeEventListener("abort", onAbort));
|
|
229
|
+
}
|
|
230
|
+
return {
|
|
231
|
+
signal: controller.signal,
|
|
232
|
+
cleanup: () => {
|
|
233
|
+
for (const fn of cleanupFns) fn();
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// src/http/HttpClient.ts
|
|
239
|
+
function defaultSleep(ms) {
|
|
240
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
241
|
+
}
|
|
242
|
+
async function parseJsonBody(response) {
|
|
243
|
+
const text = await response.text();
|
|
244
|
+
if (text.length === 0) return void 0;
|
|
245
|
+
try {
|
|
246
|
+
return JSON.parse(text);
|
|
247
|
+
} catch {
|
|
248
|
+
return void 0;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
function toNetworkError(cause, timeoutMs, callerCancelled) {
|
|
252
|
+
if (callerCancelled) {
|
|
253
|
+
return new NetworkError("Request cancelled", { cause });
|
|
254
|
+
}
|
|
255
|
+
if (cause instanceof Error && cause.name === "TimeoutError") {
|
|
256
|
+
return new NetworkError(`Request timed out after ${timeoutMs}ms`, { cause });
|
|
257
|
+
}
|
|
258
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
259
|
+
return new NetworkError(`Network request failed: ${message}`, { cause });
|
|
260
|
+
}
|
|
261
|
+
var HttpClient = class {
|
|
262
|
+
#config;
|
|
263
|
+
#sleep;
|
|
264
|
+
constructor(config, options = {}) {
|
|
265
|
+
this.#config = config;
|
|
266
|
+
this.#sleep = options.sleep ?? defaultSleep;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Sends a request and returns the parsed 2xx body, or throws the `SuqoError` subclass
|
|
270
|
+
* `mapHttpError` maps a non-2xx response to. Writes are never retried (SDK-SPEC.md §8, §12);
|
|
271
|
+
* reads retry on network failure, `429`, or `5xx`, bounded by `SdkConfig.maxRetries`.
|
|
272
|
+
*
|
|
273
|
+
* Generic on both `TResponse` and `TBody` — e.g.
|
|
274
|
+
* `request<CreateSubscriptionResponse, CreateSubscriptionParams>({ body, ... })` — so a
|
|
275
|
+
* resource method (Ticket 4) gets its request body checked against the exact shape it means to
|
|
276
|
+
* send, not just `unknown`.
|
|
277
|
+
*/
|
|
278
|
+
async request(options) {
|
|
279
|
+
if (options.method === "GET" && options.body !== void 0) {
|
|
280
|
+
throw new TypeError("HttpClient.request: a GET request cannot carry a body.");
|
|
281
|
+
}
|
|
282
|
+
let url;
|
|
283
|
+
try {
|
|
284
|
+
url = buildUrl(this.#config.baseUrl, options.path, options.query);
|
|
285
|
+
if (new URL(url).origin !== new URL(this.#config.baseUrl).origin) {
|
|
286
|
+
throw new Error(
|
|
287
|
+
`Refusing to send a request to ${new URL(url).origin} \u2014 it does not match the configured origin ${new URL(this.#config.baseUrl).origin}. This SDK never sends its API key to a different host.`
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
} catch (cause) {
|
|
291
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
292
|
+
throw new NetworkError(`Invalid request URL: ${message}`, { cause });
|
|
293
|
+
}
|
|
294
|
+
const retryable = isRetryableMethod(options.method);
|
|
295
|
+
const maxAttempts = retryable ? this.#config.maxRetries + 1 : 1;
|
|
296
|
+
const timeoutMs = options.timeoutMs ?? this.#config.timeout;
|
|
297
|
+
for (let attempt = 1; ; attempt++) {
|
|
298
|
+
const isLastAttempt = attempt >= maxAttempts;
|
|
299
|
+
try {
|
|
300
|
+
const response = await this.#doFetch(url, options, timeoutMs);
|
|
301
|
+
if (response.ok) {
|
|
302
|
+
return await parseJsonBody(response);
|
|
303
|
+
}
|
|
304
|
+
const body = await parseJsonBody(response);
|
|
305
|
+
const retryAfter = parseRetryAfterMs(response.headers.get("Retry-After"));
|
|
306
|
+
if (!isLastAttempt && retryable && isRetryableFailure({ networkError: false, status: response.status })) {
|
|
307
|
+
await this.#sleepOrAbort(retryAfter ?? backoffDelayMs(attempt - 1), options.signal, timeoutMs);
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
throw mapHttpError({
|
|
311
|
+
status: response.status,
|
|
312
|
+
statusText: response.statusText,
|
|
313
|
+
body,
|
|
314
|
+
...retryAfter !== void 0 ? { retryAfter } : {}
|
|
315
|
+
});
|
|
316
|
+
} catch (cause) {
|
|
317
|
+
if (cause instanceof SuqoError) throw cause;
|
|
318
|
+
const callerCancelled = options.signal?.aborted === true;
|
|
319
|
+
if (!callerCancelled && !isLastAttempt && retryable && isRetryableFailure({ networkError: true })) {
|
|
320
|
+
await this.#sleepOrAbort(backoffDelayMs(attempt - 1), options.signal, timeoutMs);
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
throw toNetworkError(cause, timeoutMs, callerCancelled);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Sleeps for `ms`, but rejects immediately with a "cancelled" `NetworkError` if `signal` aborts
|
|
329
|
+
* *during* the wait — a caller cancelling mid-backoff doesn't have to wait for the sleep to
|
|
330
|
+
* finish first (found in review: the previous version ignored `signal` here entirely).
|
|
331
|
+
*/
|
|
332
|
+
async #sleepOrAbort(ms, signal, timeoutMs) {
|
|
333
|
+
if (!signal) {
|
|
334
|
+
await this.#sleep(ms);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (signal.aborted) {
|
|
338
|
+
throw toNetworkError(signal.reason, timeoutMs, true);
|
|
339
|
+
}
|
|
340
|
+
await new Promise((resolve, reject) => {
|
|
341
|
+
const onAbort = () => reject(toNetworkError(signal.reason, timeoutMs, true));
|
|
342
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
343
|
+
this.#sleep(ms).then(
|
|
344
|
+
() => {
|
|
345
|
+
signal.removeEventListener("abort", onAbort);
|
|
346
|
+
resolve();
|
|
347
|
+
},
|
|
348
|
+
(sleepError) => {
|
|
349
|
+
signal.removeEventListener("abort", onAbort);
|
|
350
|
+
reject(sleepError);
|
|
351
|
+
}
|
|
352
|
+
);
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
async #doFetch(url, options, timeoutMs) {
|
|
356
|
+
const isWrite = options.method !== "GET";
|
|
357
|
+
const headers = {
|
|
358
|
+
Authorization: `Bearer ${this.#config.apiKey}`
|
|
359
|
+
};
|
|
360
|
+
if (isWrite) {
|
|
361
|
+
headers["Content-Type"] = "application/json";
|
|
362
|
+
}
|
|
363
|
+
const body = options.method === "POST" ? options.body : void 0;
|
|
364
|
+
const { signal, cleanup } = combineSignals([AbortSignal.timeout(timeoutMs), options.signal]);
|
|
365
|
+
try {
|
|
366
|
+
const init = {
|
|
367
|
+
method: options.method,
|
|
368
|
+
headers,
|
|
369
|
+
signal,
|
|
370
|
+
...body !== void 0 ? { body: JSON.stringify(body) } : {},
|
|
371
|
+
...this.#config.dispatcher !== void 0 ? { dispatcher: this.#config.dispatcher } : {}
|
|
372
|
+
};
|
|
373
|
+
return await fetch(url, init);
|
|
374
|
+
} finally {
|
|
375
|
+
cleanup();
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
// src/pagination.ts
|
|
381
|
+
function toPageQuery(params) {
|
|
382
|
+
return {
|
|
383
|
+
page: params?.page,
|
|
384
|
+
page_size: params?.pageSize
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
function deserializePage(wire, deserializeItem) {
|
|
388
|
+
return {
|
|
389
|
+
count: wire.count,
|
|
390
|
+
next: wire.next,
|
|
391
|
+
previous: wire.previous,
|
|
392
|
+
results: wire.results.map(deserializeItem)
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
async function* listAll(firstPage, fetchNext, maxPages = 1e4) {
|
|
396
|
+
let page = firstPage;
|
|
397
|
+
let pagesSeen = 0;
|
|
398
|
+
while (true) {
|
|
399
|
+
pagesSeen++;
|
|
400
|
+
if (pagesSeen > maxPages) {
|
|
401
|
+
throw new Error(
|
|
402
|
+
`listAll exceeded ${maxPages} pages without reaching next: null. This usually means the server or the fetchNext callback isn't advancing \u2014 check for a stuck loop.`
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
for (const item of page.results) {
|
|
406
|
+
yield item;
|
|
407
|
+
}
|
|
408
|
+
if (page.next === null) {
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
page = await fetchNext(page.next);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
function bridgeAutoPaging(fetchFirstPage, fetchNext, maxPages = 1e4) {
|
|
415
|
+
return (async function* () {
|
|
416
|
+
yield* listAll(await fetchFirstPage(), fetchNext, maxPages);
|
|
417
|
+
})();
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// src/resources/products.ts
|
|
421
|
+
var PRODUCTS_PATH = "/api/v1/products";
|
|
422
|
+
function deserializeBillingPeriod(wire) {
|
|
423
|
+
return {
|
|
424
|
+
pbpId: wire.pbp_id,
|
|
425
|
+
intervalType: wire.interval_type,
|
|
426
|
+
intervalCount: wire.interval_count,
|
|
427
|
+
label: wire.label,
|
|
428
|
+
price: wire.price,
|
|
429
|
+
currency: wire.currency,
|
|
430
|
+
isCurrent: wire.is_current,
|
|
431
|
+
isLimited: wire.is_limited,
|
|
432
|
+
isArchived: wire.is_archived,
|
|
433
|
+
offers: wire.offers
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
function deserializePlan(wire) {
|
|
437
|
+
return {
|
|
438
|
+
planId: wire.plan_id,
|
|
439
|
+
planName: wire.plan_name,
|
|
440
|
+
description: wire.description,
|
|
441
|
+
// `openapi.yaml`'s Product schema has no `required` list at all, so `billing_periods` being
|
|
442
|
+
// omitted entirely (not just an empty array) is spec-legal — `?? []` degrades to an empty
|
|
443
|
+
// list instead of `.map` throwing on `undefined` (found in review, reproduced).
|
|
444
|
+
billingPeriods: (wire.billing_periods ?? []).map(deserializeBillingPeriod)
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
function deserializeProductVat(wire) {
|
|
448
|
+
return {
|
|
449
|
+
isVatActive: wire.is_vat_active,
|
|
450
|
+
vatType: wire.vat_type,
|
|
451
|
+
vatPercentage: wire.vat_percentage
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
function deserializeProduct(wire) {
|
|
455
|
+
return {
|
|
456
|
+
productId: wire.product_id,
|
|
457
|
+
name: wire.name,
|
|
458
|
+
description: wire.description,
|
|
459
|
+
type: wire.type,
|
|
460
|
+
isActive: wire.is_active,
|
|
461
|
+
termsAndConditions: wire.terms_and_conditions,
|
|
462
|
+
featuresAndBenefits: wire.features_and_benefits,
|
|
463
|
+
// `== null` (not `=== null`) is deliberate — it catches both an explicit `null` and an
|
|
464
|
+
// entirely omitted `vat` key. `openapi.yaml` has no `required` list for Product, so omitting
|
|
465
|
+
// `vat` is spec-legal, and the old `=== null` check crashed on `deserializeProductVat(undefined)`
|
|
466
|
+
// when that happened (found in review, reproduced).
|
|
467
|
+
vat: wire.vat == null ? null : deserializeProductVat(wire.vat),
|
|
468
|
+
productImage: wire.product_image,
|
|
469
|
+
// Same reasoning as `billingPeriods` above — `plan` being omitted entirely is spec-legal.
|
|
470
|
+
plan: (wire.plan ?? []).map(deserializePlan),
|
|
471
|
+
totalSubscribers: wire.total_subscribers,
|
|
472
|
+
createdAt: wire.created_at,
|
|
473
|
+
updatedAt: wire.updated_at
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
var ProductsResource = class {
|
|
477
|
+
#http;
|
|
478
|
+
constructor(http) {
|
|
479
|
+
this.#http = http;
|
|
480
|
+
}
|
|
481
|
+
/** Lists the authenticated seller's active products. Paginated (SDK-SPEC.md §6). */
|
|
482
|
+
async list(params) {
|
|
483
|
+
const wire = await this.#http.request({
|
|
484
|
+
method: "GET",
|
|
485
|
+
path: PRODUCTS_PATH,
|
|
486
|
+
query: toPageQuery(params)
|
|
487
|
+
});
|
|
488
|
+
return deserializePage(wire, deserializeProduct);
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Auto-iterates every product across every page, following `next` until it's `null`
|
|
492
|
+
* (SDK-SPEC.md §6). Manual `list({ page, pageSize })` remains available independently — this is
|
|
493
|
+
* additive, not a replacement.
|
|
494
|
+
*/
|
|
495
|
+
autoPaging(params) {
|
|
496
|
+
return bridgeAutoPaging(() => this.list(params), async (nextUrl) => {
|
|
497
|
+
const wire = await this.#http.request({ method: "GET", path: nextUrl });
|
|
498
|
+
return deserializePage(wire, deserializeProduct);
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
// src/models/Subscription.ts
|
|
504
|
+
var SubscriptionStatus = {
|
|
505
|
+
/** Newly created; the buyer hasn't paid yet. */
|
|
506
|
+
PendingCheckout: "pending_checkout",
|
|
507
|
+
/** Currently active. */
|
|
508
|
+
Active: "active",
|
|
509
|
+
/** `nextBillingCycle` passed with no payment yet. */
|
|
510
|
+
Due: "due",
|
|
511
|
+
/** Cancelled immediately (user-prompted). */
|
|
512
|
+
Cancelled: "cancelled",
|
|
513
|
+
/** Scheduled to cancel at the end of the current billing cycle — see SDK-SPEC.md §5's `cancel` note. */
|
|
514
|
+
PendingCancellation: "pending_cancellation",
|
|
515
|
+
/** Auto-ended after a grace period without payment. */
|
|
516
|
+
Inactive: "inactive"
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
// src/resources/serialization.ts
|
|
520
|
+
function serializeCustomerInput(customer) {
|
|
521
|
+
const wire = {
|
|
522
|
+
phone: customer.phone,
|
|
523
|
+
full_name: customer.fullName,
|
|
524
|
+
email: customer.email,
|
|
525
|
+
address: customer.address
|
|
526
|
+
};
|
|
527
|
+
if (customer.billing) {
|
|
528
|
+
const billing = {
|
|
529
|
+
billing_business_name: customer.billing.businessName,
|
|
530
|
+
billing_email: customer.billing.email,
|
|
531
|
+
billing_address: customer.billing.address
|
|
532
|
+
};
|
|
533
|
+
if (customer.billing.panVat !== void 0) billing.billing_pan_vat = customer.billing.panVat;
|
|
534
|
+
wire.billing = billing;
|
|
535
|
+
}
|
|
536
|
+
if (customer.shipping) {
|
|
537
|
+
const shipping = {
|
|
538
|
+
phone: customer.shipping.phone,
|
|
539
|
+
full_name: customer.shipping.fullName,
|
|
540
|
+
email: customer.shipping.email
|
|
541
|
+
};
|
|
542
|
+
if (customer.shipping.address !== void 0) shipping.address = customer.shipping.address;
|
|
543
|
+
wire.shipping = shipping;
|
|
544
|
+
}
|
|
545
|
+
return wire;
|
|
546
|
+
}
|
|
547
|
+
function deserializeSubscriptionCustomer(wire) {
|
|
548
|
+
if (!isRecord(wire)) return {};
|
|
549
|
+
const customer = {};
|
|
550
|
+
if (typeof wire.phone === "string") customer.phone = wire.phone;
|
|
551
|
+
if (typeof wire.full_name === "string") customer.fullName = wire.full_name;
|
|
552
|
+
if (typeof wire.email === "string") customer.email = wire.email;
|
|
553
|
+
if (typeof wire.address === "string") customer.address = wire.address;
|
|
554
|
+
if (isRecord(wire.billing)) {
|
|
555
|
+
customer.billing = {
|
|
556
|
+
...typeof wire.billing.business_name === "string" ? { businessName: wire.billing.business_name } : {},
|
|
557
|
+
...typeof wire.billing.email === "string" ? { email: wire.billing.email } : {},
|
|
558
|
+
...typeof wire.billing.address === "string" ? { address: wire.billing.address } : {},
|
|
559
|
+
...typeof wire.billing.pan_vat === "string" ? { panVat: wire.billing.pan_vat } : {}
|
|
560
|
+
};
|
|
561
|
+
} else if (wire.billing === null) {
|
|
562
|
+
customer.billing = null;
|
|
563
|
+
}
|
|
564
|
+
if (isRecord(wire.shipping)) {
|
|
565
|
+
customer.shipping = {
|
|
566
|
+
...typeof wire.shipping.phone === "string" ? { phone: wire.shipping.phone } : {},
|
|
567
|
+
...typeof wire.shipping.full_name === "string" ? { fullName: wire.shipping.full_name } : {},
|
|
568
|
+
...typeof wire.shipping.email === "string" ? { email: wire.shipping.email } : {},
|
|
569
|
+
...typeof wire.shipping.address === "string" ? { address: wire.shipping.address } : {}
|
|
570
|
+
};
|
|
571
|
+
} else if (wire.shipping === null) {
|
|
572
|
+
customer.shipping = null;
|
|
573
|
+
}
|
|
574
|
+
return customer;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
// src/resources/subscriptions.ts
|
|
578
|
+
var SUBSCRIPTIONS_PATH = "/api/v1/subscriptions";
|
|
579
|
+
function deserializeSubscriptionProduct(wire) {
|
|
580
|
+
return {
|
|
581
|
+
productId: wire.product_id,
|
|
582
|
+
name: wire.name,
|
|
583
|
+
planName: wire.plan_name,
|
|
584
|
+
pbpId: wire.pbp_id,
|
|
585
|
+
label: wire.label,
|
|
586
|
+
price: wire.price,
|
|
587
|
+
currency: wire.currency
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
function deserializeSubscription(wire) {
|
|
591
|
+
return {
|
|
592
|
+
subscriptionId: wire.subscription_id,
|
|
593
|
+
status: wire.status,
|
|
594
|
+
isActive: wire.is_active,
|
|
595
|
+
// Renamed from the wire's `client` — SDK Naming Map v1.1 §11 "Customer boundary".
|
|
596
|
+
customer: deserializeSubscriptionCustomer(wire.client),
|
|
597
|
+
// `== null` (not `=== null`) is deliberate — same reasoning as Product's `vat` field: catches
|
|
598
|
+
// both an explicit `null` and an entirely omitted `product` key, either of which is spec-legal
|
|
599
|
+
// since `openapi.yaml`'s Subscription schema has no `required` list. The old unconditional call
|
|
600
|
+
// crashed on `deserializeSubscriptionProduct(undefined)` when the key was omitted (found in
|
|
601
|
+
// review, reproduced).
|
|
602
|
+
product: wire.product == null ? null : deserializeSubscriptionProduct(wire.product),
|
|
603
|
+
currentPeriodStart: wire.current_period_start,
|
|
604
|
+
currentPeriodEnd: wire.current_period_end,
|
|
605
|
+
nextBillingCycle: wire.next_billing_cycle,
|
|
606
|
+
createdAt: wire.created_at
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
function deserializeSubscriptionPage(wire) {
|
|
610
|
+
return {
|
|
611
|
+
count: wire.count,
|
|
612
|
+
next: wire.next,
|
|
613
|
+
previous: wire.previous,
|
|
614
|
+
totalSubscriptions: wire.total_subscriptions,
|
|
615
|
+
activeSubscriptions: wire.active_subscriptions,
|
|
616
|
+
dueSubscriptions: wire.due_subscriptions,
|
|
617
|
+
inactiveSubscriptions: wire.inactive_subscriptions,
|
|
618
|
+
results: wire.results.map(deserializeSubscription)
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
function deserializeCreateSubscriptionResponse(wire) {
|
|
622
|
+
return {
|
|
623
|
+
subscriptionId: wire.subscription_id,
|
|
624
|
+
pbpId: wire.pbp_id,
|
|
625
|
+
status: wire.status,
|
|
626
|
+
checkoutUrl: wire.checkout_url,
|
|
627
|
+
nextBillingCycle: wire.next_billing_cycle,
|
|
628
|
+
createdAt: wire.created_at
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
var SubscriptionsResource = class {
|
|
632
|
+
#http;
|
|
633
|
+
constructor(http) {
|
|
634
|
+
this.#http = http;
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Lists the seller's subscriptions. Paginated, with four extra status counts alongside the
|
|
638
|
+
* common envelope (SDK-SPEC.md §6).
|
|
639
|
+
*/
|
|
640
|
+
async list(params) {
|
|
641
|
+
const wire = await this.#http.request({
|
|
642
|
+
method: "GET",
|
|
643
|
+
path: SUBSCRIPTIONS_PATH,
|
|
644
|
+
query: toPageQuery(params)
|
|
645
|
+
});
|
|
646
|
+
return deserializeSubscriptionPage(wire);
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Auto-iterates every subscription across every page, following `next` until it's `null`
|
|
650
|
+
* (SDK-SPEC.md §6). Manual `list({ page, pageSize })` remains available independently.
|
|
651
|
+
*/
|
|
652
|
+
autoPaging(params) {
|
|
653
|
+
return bridgeAutoPaging(() => this.list(params), async (nextUrl) => {
|
|
654
|
+
const wire = await this.#http.request({ method: "GET", path: nextUrl });
|
|
655
|
+
return deserializeSubscriptionPage(wire);
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* Creates a subscription in `pending_checkout` state and returns a checkout URL for the buyer
|
|
660
|
+
* to pay (SDK-SPEC.md §5). Redirect the buyer to `checkoutUrl`; the return is **not** proof of
|
|
661
|
+
* payment — learn the real outcome via the `checkout.succeeded`/`checkout.failed` webhooks.
|
|
662
|
+
*
|
|
663
|
+
* Reuse behavior: an inactive/expired subscription for the same buyer + product + billing
|
|
664
|
+
* period is reactivated rather than duplicated; only a currently `active` one triggers the
|
|
665
|
+
* duplicate-subscription `ValidationError`.
|
|
666
|
+
*
|
|
667
|
+
* Not auto-retryable — writes never retry until idempotency ships (SDK-SPEC.md §8, §12).
|
|
668
|
+
*/
|
|
669
|
+
async create(params) {
|
|
670
|
+
const wire = await this.#http.request({
|
|
671
|
+
method: "POST",
|
|
672
|
+
path: SUBSCRIPTIONS_PATH,
|
|
673
|
+
body: {
|
|
674
|
+
pbp_id: params.pbpId,
|
|
675
|
+
return_url: params.returnUrl,
|
|
676
|
+
// Renamed from the wire's `client` — SDK Naming Map v1.1 §11 "Customer boundary".
|
|
677
|
+
client: serializeCustomerInput(params.customer)
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
return deserializeCreateSubscriptionResponse(wire);
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* Schedules cancellation for the end of the current billing period — **not** immediate
|
|
684
|
+
* (confirmed with backend 2026-08-17; immediate cancellation is a future capability). Status
|
|
685
|
+
* moves to `pending_cancellation`; the subscription stays active until the period ends.
|
|
686
|
+
*
|
|
687
|
+
* Not auto-retryable — writes never retry until idempotency ships (SDK-SPEC.md §8, §12).
|
|
688
|
+
*/
|
|
689
|
+
async cancel(id) {
|
|
690
|
+
return this.#http.request({
|
|
691
|
+
method: "POST",
|
|
692
|
+
path: `${SUBSCRIPTIONS_PATH}/${encodeURIComponent(id)}/cancel`
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Sets a subscription's next billing date. Collection-level action — the subscription id
|
|
697
|
+
* travels in the body, not the path, mirroring the wire (SDK Naming Map v1.1 §04).
|
|
698
|
+
*
|
|
699
|
+
* Not auto-retryable — writes never retry until idempotency ships (SDK-SPEC.md §8, §12).
|
|
700
|
+
*/
|
|
701
|
+
async updateBillingCycle(params) {
|
|
702
|
+
return this.#http.request({
|
|
703
|
+
method: "POST",
|
|
704
|
+
path: `${SUBSCRIPTIONS_PATH}/update-billing-cycle`,
|
|
705
|
+
body: {
|
|
706
|
+
subscription_id: params.subscriptionId,
|
|
707
|
+
next_billing_cycle: params.nextBillingCycle
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Resumes a subscription. Confirmed public with backend (2026-08-18); the response shape
|
|
713
|
+
* follows Swagger's `{ message }` example but — unlike Customers — isn't independently
|
|
714
|
+
* confirmed, so treat it as likely-correct-but-unverified (docs/implementation-plan.md Ticket 4).
|
|
715
|
+
*
|
|
716
|
+
* Not auto-retryable — writes never retry until idempotency ships (SDK-SPEC.md §8, §12).
|
|
717
|
+
*/
|
|
718
|
+
async resume(id) {
|
|
719
|
+
return this.#http.request({
|
|
720
|
+
method: "POST",
|
|
721
|
+
path: `${SUBSCRIPTIONS_PATH}/${encodeURIComponent(id)}/resume`
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
// src/resources/customers.ts
|
|
727
|
+
var CUSTOMERS_PATH = "/api/v1/customers";
|
|
728
|
+
function deserializeCustomer(wire) {
|
|
729
|
+
return {
|
|
730
|
+
id: wire.id,
|
|
731
|
+
buyerPhone: wire.buyer_phone,
|
|
732
|
+
buyerEmail: wire.buyer_email,
|
|
733
|
+
fullName: wire.full_name,
|
|
734
|
+
createdAt: wire.created_at
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
var CustomersResource = class {
|
|
738
|
+
#http;
|
|
739
|
+
constructor(http) {
|
|
740
|
+
this.#http = http;
|
|
741
|
+
}
|
|
742
|
+
/** Lists the authenticated seller's customers. Paginated (SDK-SPEC.md §6). */
|
|
743
|
+
async list(params) {
|
|
744
|
+
const wire = await this.#http.request({
|
|
745
|
+
method: "GET",
|
|
746
|
+
path: CUSTOMERS_PATH,
|
|
747
|
+
query: toPageQuery(params)
|
|
748
|
+
});
|
|
749
|
+
return deserializePage(wire, deserializeCustomer);
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* Auto-iterates every customer across every page, following `next` until it's `null`
|
|
753
|
+
* (SDK-SPEC.md §6). Manual `list({ page, pageSize })` remains available independently — this is
|
|
754
|
+
* additive, not a replacement.
|
|
755
|
+
*/
|
|
756
|
+
autoPaging(params) {
|
|
757
|
+
return bridgeAutoPaging(() => this.list(params), async (nextUrl) => {
|
|
758
|
+
const wire = await this.#http.request({ method: "GET", path: nextUrl });
|
|
759
|
+
return deserializePage(wire, deserializeCustomer);
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* Retrieves a single customer by id. Unlike every other resource in this API, `id` is an
|
|
764
|
+
* **integer**, not a UUID (SDK-SPEC.md §5 naming note; `openapi.yaml` `Customer.id`).
|
|
765
|
+
*/
|
|
766
|
+
async retrieve(id) {
|
|
767
|
+
const wire = await this.#http.request({
|
|
768
|
+
method: "GET",
|
|
769
|
+
path: `${CUSTOMERS_PATH}/${encodeURIComponent(id)}`
|
|
770
|
+
});
|
|
771
|
+
return deserializeCustomer(wire);
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
var DEFAULT_TOLERANCE_SEC = 300;
|
|
775
|
+
var SIGNATURE_PREFIX = "sha256=";
|
|
776
|
+
var HEX_DIGEST_RE = /^[0-9a-f]{64}$/i;
|
|
777
|
+
var WebhooksResource = class {
|
|
778
|
+
/**
|
|
779
|
+
* Verifies an inbound webhook delivery's signature. Returns `false` for any failure mode —
|
|
780
|
+
* malformed signature, expired timestamp, or a genuine mismatch — never throws, so a caller
|
|
781
|
+
* never needs a `try`/`catch` just to check a delivery.
|
|
782
|
+
*
|
|
783
|
+
* @example
|
|
784
|
+
* ```ts
|
|
785
|
+
* // Express: mount express.raw() on this route so req.body is a Buffer, not parsed JSON.
|
|
786
|
+
* const ok = suqo.webhooks.verify({
|
|
787
|
+
* rawBody: req.body,
|
|
788
|
+
* signature: req.header("X-SUQO-Signature")!,
|
|
789
|
+
* timestamp: req.header("X-SUQO-Timestamp")!,
|
|
790
|
+
* secret: process.env.SUQO_WEBHOOK_SECRET!,
|
|
791
|
+
* });
|
|
792
|
+
* ```
|
|
793
|
+
*/
|
|
794
|
+
verify(options) {
|
|
795
|
+
const { rawBody, signature, timestamp, secret, toleranceSec = DEFAULT_TOLERANCE_SEC } = options;
|
|
796
|
+
if (typeof signature !== "string" || typeof timestamp !== "string" || typeof secret !== "string") {
|
|
797
|
+
return false;
|
|
798
|
+
}
|
|
799
|
+
if (typeof rawBody !== "string" && !Buffer.isBuffer(rawBody)) {
|
|
800
|
+
return false;
|
|
801
|
+
}
|
|
802
|
+
if (!signature.startsWith(SIGNATURE_PREFIX)) return false;
|
|
803
|
+
const providedHex = signature.slice(SIGNATURE_PREFIX.length);
|
|
804
|
+
if (!HEX_DIGEST_RE.test(providedHex)) return false;
|
|
805
|
+
if (timestamp.trim().length === 0) return false;
|
|
806
|
+
const timestampSeconds = Number(timestamp);
|
|
807
|
+
if (!Number.isFinite(timestampSeconds)) return false;
|
|
808
|
+
const nowSeconds = Date.now() / 1e3;
|
|
809
|
+
if (Math.abs(nowSeconds - timestampSeconds) > toleranceSec) return false;
|
|
810
|
+
const expectedHex = crypto.createHmac("sha256", secret).update(`${timestamp}.`).update(rawBody).digest("hex");
|
|
811
|
+
const provided = Buffer.from(providedHex, "hex");
|
|
812
|
+
const expected = Buffer.from(expectedHex, "hex");
|
|
813
|
+
if (provided.length !== expected.length) return false;
|
|
814
|
+
return crypto.timingSafeEqual(provided, expected);
|
|
815
|
+
}
|
|
816
|
+
};
|
|
817
|
+
|
|
818
|
+
// src/client.ts
|
|
819
|
+
var SuqoClient = class {
|
|
820
|
+
#config;
|
|
821
|
+
constructor(options) {
|
|
822
|
+
this.#config = new SdkConfig(options);
|
|
823
|
+
const http = new HttpClient(this.#config);
|
|
824
|
+
this.products = new ProductsResource(http);
|
|
825
|
+
this.subscriptions = new SubscriptionsResource(http);
|
|
826
|
+
this.customers = new CustomersResource(http);
|
|
827
|
+
this.webhooks = new WebhooksResource();
|
|
828
|
+
}
|
|
829
|
+
/** `"sandbox" | "live"` — inferred from the key prefix, never selected explicitly (SDK-SPEC.md §2). */
|
|
830
|
+
get environment() {
|
|
831
|
+
return this.#config.environment;
|
|
832
|
+
}
|
|
833
|
+
/** The resolved base URL this client sends requests to. */
|
|
834
|
+
get baseUrl() {
|
|
835
|
+
return this.#config.baseUrl;
|
|
836
|
+
}
|
|
837
|
+
/** The effective request timeout in milliseconds (default 30_000). */
|
|
838
|
+
get timeout() {
|
|
839
|
+
return this.#config.timeout;
|
|
840
|
+
}
|
|
841
|
+
/** The effective max retry count for idempotent reads (default 2). */
|
|
842
|
+
get maxRetries() {
|
|
843
|
+
return this.#config.maxRetries;
|
|
844
|
+
}
|
|
845
|
+
/** Redacts the key so it never appears in `JSON.stringify` output (SDK-SPEC.md §4). */
|
|
846
|
+
toJSON() {
|
|
847
|
+
return this.#config.toJSON();
|
|
848
|
+
}
|
|
849
|
+
/** Redacts the key so it never appears in `util.inspect`/`console.log` output (SDK-SPEC.md §4). */
|
|
850
|
+
[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
|
|
851
|
+
return this.toJSON();
|
|
852
|
+
}
|
|
853
|
+
};
|
|
854
|
+
|
|
855
|
+
// src/index.ts
|
|
856
|
+
var VERSION = "1.0.0";
|
|
857
|
+
|
|
858
|
+
exports.AuthenticationError = AuthenticationError;
|
|
859
|
+
exports.KycRequiredError = KycRequiredError;
|
|
860
|
+
exports.NetworkError = NetworkError;
|
|
861
|
+
exports.NotFoundError = NotFoundError;
|
|
862
|
+
exports.RateLimitError = RateLimitError;
|
|
863
|
+
exports.ServerError = ServerError;
|
|
864
|
+
exports.SubscriptionStatus = SubscriptionStatus;
|
|
865
|
+
exports.SuqoClient = SuqoClient;
|
|
866
|
+
exports.SuqoConfigError = SuqoConfigError;
|
|
867
|
+
exports.SuqoError = SuqoError;
|
|
868
|
+
exports.VERSION = VERSION;
|
|
869
|
+
exports.ValidationError = ValidationError;
|
|
870
|
+
exports.bridgeAutoPaging = bridgeAutoPaging;
|
|
871
|
+
exports.deserializePage = deserializePage;
|
|
872
|
+
exports.listAll = listAll;
|
|
873
|
+
exports.mapHttpError = mapHttpError;
|
|
874
|
+
exports.toPageQuery = toPageQuery;
|
|
875
|
+
//# sourceMappingURL=index.cjs.map
|
|
876
|
+
//# sourceMappingURL=index.cjs.map
|