@onesim.global/sdk 0.0.0-stage → 0.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.
@@ -0,0 +1,306 @@
1
+ import { APIError, OnesimError, PollTimeoutError } from './errors.js';
2
+ import { Http, sleep, throwIfAborted } from './http.js';
3
+ const API_KEY_ENV = 'ONESIM_API_KEY';
4
+ const DEFAULT_BASE_URL = 'https://api.onesim.global';
5
+ const DEFAULT_TIMEOUT = 60_000;
6
+ const DEFAULT_MAX_RETRIES = 2;
7
+ const DEFAULT_POLL_TIMEOUT = 660_000;
8
+ const DEFAULT_POLL_INTERVAL = 3_000;
9
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
10
+ const id = (value) => encodeURIComponent(value);
11
+ /**
12
+ * The onesim partner API.
13
+ *
14
+ * ```ts
15
+ * import OnesimClient from '@onesim.global/sdk';
16
+ *
17
+ * const onesim = new OnesimClient(); // reads ONESIM_API_KEY
18
+ * const catalogue = await onesim.packages.list();
19
+ * ```
20
+ */
21
+ export class OnesimClient {
22
+ /** Your catalogue: what you can buy and what it costs you. */
23
+ packages;
24
+ /** Buying blank eSIMs, packages and bundles. */
25
+ orders;
26
+ /** The eSIMs you own, with their packages and usage. */
27
+ esims;
28
+ /** Your partner balance. */
29
+ balance;
30
+ constructor(options = {}) {
31
+ const apiKey = options.apiKey ?? readEnv(API_KEY_ENV);
32
+ if (typeof apiKey !== 'string' || apiKey === '') {
33
+ throw new TypeError(`OnesimClient: no API key. Pass apiKey, or set the ${API_KEY_ENV} environment variable.`);
34
+ }
35
+ const timeout = options.timeout ?? DEFAULT_TIMEOUT;
36
+ if (!(timeout > 0))
37
+ throw new TypeError('OnesimClient: timeout must be a positive number.');
38
+ const maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
39
+ if (!Number.isInteger(maxRetries) || maxRetries < 0) {
40
+ throw new TypeError('OnesimClient: maxRetries must be a whole number, 0 or more.');
41
+ }
42
+ let fetch = options.fetch;
43
+ if (!fetch) {
44
+ if (typeof globalThis.fetch !== 'function') {
45
+ throw new TypeError('OnesimClient: this runtime has no global fetch; pass one as `fetch`.');
46
+ }
47
+ // Looked up on each call, so a fetch replaced later (e.g. by a test) is used.
48
+ fetch = (url, init) => globalThis.fetch(url, init);
49
+ }
50
+ const http = new Http({
51
+ apiKey,
52
+ baseURL: (options.baseURL ?? DEFAULT_BASE_URL).replace(/\/+$/, ''),
53
+ timeout,
54
+ maxRetries,
55
+ fetch
56
+ });
57
+ this.packages = new Packages(http);
58
+ this.orders = new Orders(http);
59
+ this.esims = new Esims(http);
60
+ this.balance = new BalanceResource(http);
61
+ }
62
+ }
63
+ // process.env where there is one (Node.js, Bun, Deno); never throws where
64
+ // there is not (Workers, browsers) or where reading it is not allowed.
65
+ function readEnv(name) {
66
+ try {
67
+ const env = globalThis.process?.env;
68
+ return env?.[name]?.trim() || undefined;
69
+ }
70
+ catch {
71
+ return undefined;
72
+ }
73
+ }
74
+ export class Packages {
75
+ #http;
76
+ constructor(http) {
77
+ this.#http = http;
78
+ }
79
+ /** `GET /v1/packages`: your packages and the price of a blank eSIM. A `null` price means "not offered that way". */
80
+ list(options = {}) {
81
+ return this.#http.request({
82
+ method: 'GET',
83
+ path: '/v1/packages',
84
+ signal: options.signal
85
+ });
86
+ }
87
+ /** `GET /v1/packages/{id}`. */
88
+ retrieve(packageId, options = {}) {
89
+ return this.#http.request({
90
+ method: 'GET',
91
+ path: `/v1/packages/${id(packageId)}`,
92
+ signal: options.signal
93
+ });
94
+ }
95
+ }
96
+ export class Orders {
97
+ #http;
98
+ constructor(http) {
99
+ this.#http = http;
100
+ }
101
+ /**
102
+ * `POST /v1/orders`: buy a blank eSIM (`type: 'esim'`), a package on an eSIM
103
+ * you own (`type: 'package'`) or a new eSIM with a package (`type: 'bundle'`).
104
+ * Resolves with the order as the API answers it: `completed`, or `pending`
105
+ * (follow it with `orders.poll`, or use `orders.createAndPoll`).
106
+ *
107
+ * Every attempt of this call sends the same Idempotency-Key, so a retry
108
+ * never buys twice. Pass your own `idempotencyKey`, stored with your
109
+ * booking, to make retries across restarts safe too. Any `OnesimError`
110
+ * thrown carries the key it used as `error.idempotencyKey`.
111
+ */
112
+ async create(body, options = {}) {
113
+ const idempotencyKey = idempotencyKeyOf(options);
114
+ try {
115
+ return await this.#create(body, idempotencyKey, options.signal);
116
+ }
117
+ catch (error) {
118
+ if (error instanceof OnesimError)
119
+ error.idempotencyKey = idempotencyKey;
120
+ throw error;
121
+ }
122
+ }
123
+ /**
124
+ * `orders.create`, then `orders.poll` while the order is pending. Resolves
125
+ * with the final order whatever its status (`completed`, `failed` or
126
+ * `refunded`): a `502 provisioning_failed` is not thrown but resolves with
127
+ * its failed order, so check `order.status`. Other errors are thrown, with
128
+ * the Idempotency-Key as `error.idempotencyKey`; `PollTimeoutError` when
129
+ * `timeout` runs out first.
130
+ */
131
+ async createAndPoll(body, options = {}) {
132
+ const { signal } = options;
133
+ // Checked before buying, not after.
134
+ const settings = pollSettings(options);
135
+ const idempotencyKey = idempotencyKeyOf(options);
136
+ try {
137
+ let order;
138
+ try {
139
+ order = await this.#create(body, idempotencyKey, signal);
140
+ }
141
+ catch (error) {
142
+ // A failed order is an answer like any other here.
143
+ if (error instanceof APIError &&
144
+ error.code === 'provisioning_failed' &&
145
+ error.order) {
146
+ return error.order;
147
+ }
148
+ throw error;
149
+ }
150
+ if (order.status !== 'pending')
151
+ return order;
152
+ return await this.#poll(order.id, order, settings, signal);
153
+ }
154
+ catch (error) {
155
+ if (error instanceof OnesimError)
156
+ error.idempotencyKey = idempotencyKey;
157
+ throw error;
158
+ }
159
+ }
160
+ /** `GET /v1/orders/{id}`. Reading a pending order also moves it forward. */
161
+ retrieve(orderId, options = {}) {
162
+ return this.#http.request({
163
+ method: 'GET',
164
+ path: `/v1/orders/${id(orderId)}`,
165
+ signal: options.signal
166
+ });
167
+ }
168
+ /** `GET /v1/orders`: one page of your orders, newest first. */
169
+ list(params = {}, options = {}) {
170
+ return this.#http.request({
171
+ method: 'GET',
172
+ path: '/v1/orders',
173
+ query: { ...params },
174
+ signal: options.signal
175
+ });
176
+ }
177
+ /** Every order matching `params`, newest first, following `next_cursor` page after page. */
178
+ async *listAll(params = {}, options = {}) {
179
+ let cursor = params.cursor;
180
+ do {
181
+ const page = await this.list({ ...params, cursor }, options);
182
+ yield* page.data;
183
+ cursor = page.next_cursor ?? undefined;
184
+ } while (cursor);
185
+ }
186
+ /**
187
+ * Reads the order until it is no longer `pending`, and resolves with it:
188
+ * `completed`, `failed` or `refunded`. A pending order completes or fails
189
+ * within about ten minutes. `timeout` bounds the whole poll, reads and
190
+ * their retries included: when it runs out, throws `PollTimeoutError` with
191
+ * the order as last read.
192
+ */
193
+ async poll(orderId, options = {}) {
194
+ return this.#poll(orderId, undefined, pollSettings(options), options.signal);
195
+ }
196
+ #create(body, idempotencyKey, signal) {
197
+ return this.#http.request({
198
+ method: 'POST',
199
+ path: '/v1/orders',
200
+ body,
201
+ idempotencyKey,
202
+ signal
203
+ });
204
+ }
205
+ // Reads and their retries share the timeout: the deadline aborts a read in
206
+ // flight, and no read starts once it has passed.
207
+ async #poll(orderId, current, { timeout, pollInterval }, signal) {
208
+ throwIfAborted(signal);
209
+ const deadline = Date.now() + timeout;
210
+ const budget = new AbortController();
211
+ const timer = setTimeout(() => budget.abort(), timeout);
212
+ const onAbort = () => budget.abort();
213
+ signal?.addEventListener('abort', onAbort, { once: true });
214
+ let order = current;
215
+ try {
216
+ for (;;) {
217
+ if (order) {
218
+ if (order.status !== 'pending')
219
+ return order;
220
+ const remaining = deadline - Date.now();
221
+ if (remaining <= 0)
222
+ break;
223
+ await sleep(Math.min(pollInterval, remaining), budget.signal);
224
+ }
225
+ if (deadline - Date.now() <= 0)
226
+ break;
227
+ order = await this.retrieve(orderId, { signal: budget.signal });
228
+ }
229
+ }
230
+ catch (error) {
231
+ // The caller's own abort ends the poll with its reason.
232
+ throwIfAborted(signal);
233
+ if (!budget.signal.aborted)
234
+ throw error;
235
+ }
236
+ finally {
237
+ clearTimeout(timer);
238
+ signal?.removeEventListener('abort', onAbort);
239
+ }
240
+ throw new PollTimeoutError(orderId, order, timeout);
241
+ }
242
+ }
243
+ function idempotencyKeyOf(options) {
244
+ if (options.idempotencyKey !== undefined &&
245
+ !UUID.test(options.idempotencyKey)) {
246
+ throw new TypeError('OnesimClient: idempotencyKey must be a UUID.');
247
+ }
248
+ return options.idempotencyKey ?? crypto.randomUUID();
249
+ }
250
+ function pollSettings(options) {
251
+ const { timeout = DEFAULT_POLL_TIMEOUT, pollInterval = DEFAULT_POLL_INTERVAL } = options;
252
+ if (!(timeout >= 0) || !(pollInterval >= 0)) {
253
+ throw new TypeError('Poll: timeout and pollInterval must be 0 or more.');
254
+ }
255
+ return { timeout, pollInterval };
256
+ }
257
+ export class Esims {
258
+ #http;
259
+ constructor(http) {
260
+ this.#http = http;
261
+ }
262
+ /**
263
+ * `GET /v1/esims/{id}`: the eSIM with its packages and usage, read live from
264
+ * the network. When the network does not answer, the last known values with
265
+ * `refreshed_at: null`.
266
+ */
267
+ retrieve(esimId, options = {}) {
268
+ return this.#http.request({
269
+ method: 'GET',
270
+ path: `/v1/esims/${id(esimId)}`,
271
+ signal: options.signal
272
+ });
273
+ }
274
+ /** `GET /v1/esims`: one page of your eSIMs, newest first. */
275
+ list(params = {}, options = {}) {
276
+ return this.#http.request({
277
+ method: 'GET',
278
+ path: '/v1/esims',
279
+ query: { ...params },
280
+ signal: options.signal
281
+ });
282
+ }
283
+ /** Every eSIM matching `params`, newest first, following `next_cursor` page after page. */
284
+ async *listAll(params = {}, options = {}) {
285
+ let cursor = params.cursor;
286
+ do {
287
+ const page = await this.list({ ...params, cursor }, options);
288
+ yield* page.data;
289
+ cursor = page.next_cursor ?? undefined;
290
+ } while (cursor);
291
+ }
292
+ }
293
+ export class BalanceResource {
294
+ #http;
295
+ constructor(http) {
296
+ this.#http = http;
297
+ }
298
+ /** `GET /v1/balance`: your balance, overdraft and what you can spend now, in cents. */
299
+ retrieve(options = {}) {
300
+ return this.#http.request({
301
+ method: 'GET',
302
+ path: '/v1/balance',
303
+ signal: options.signal
304
+ });
305
+ }
306
+ }
@@ -0,0 +1,126 @@
1
+ import type { ErrorCode, Order } from './types.js';
2
+ /** The base class of every error the SDK throws for the API. */
3
+ export declare class OnesimError extends Error {
4
+ /**
5
+ * On an error from `orders.create` or `orders.createAndPoll`: the
6
+ * Idempotency-Key it sent. Retry the purchase with this key and it is never
7
+ * bought twice.
8
+ */
9
+ idempotencyKey?: string;
10
+ constructor(message: string, options?: {
11
+ cause?: unknown;
12
+ });
13
+ }
14
+ export interface APIErrorInit {
15
+ status: number;
16
+ code: ErrorCode | (string & {}) | null;
17
+ message: string;
18
+ requestId: string | null;
19
+ amount?: number;
20
+ limit?: 'blank' | 'daily' | (string & {});
21
+ order?: Order;
22
+ retryAfter?: number;
23
+ idempotencyKey?: string;
24
+ body: unknown;
25
+ }
26
+ /**
27
+ * The API answered with a status other than 2xx. Act on `code`. A subclass
28
+ * names the common statuses: `BadRequestError` (400), `AuthenticationError`
29
+ * (401), `PermissionDeniedError` (403), `NotFoundError` (404), `ConflictError`
30
+ * (409), `RateLimitError` (429) and `InternalServerError` (5xx); any other
31
+ * status (e.g. 402 `insufficient_balance`) is an `APIError` itself.
32
+ */
33
+ export declare class APIError extends OnesimError {
34
+ /** The HTTP status. */
35
+ readonly status: number;
36
+ /**
37
+ * The error code, e.g. `insufficient_balance`. New codes may be added: handle
38
+ * one you do not know by `status`. `null` when the body is not the API's
39
+ * error shape (e.g. an HTML page from a proxy).
40
+ */
41
+ readonly code: ErrorCode | (string & {}) | null;
42
+ /** Quote it when you contact onesim. */
43
+ readonly requestId: string | null;
44
+ /** `price_changed`: the current amount, in cents. */
45
+ readonly amount?: number;
46
+ /** `esim_limit_reached`: `blank` or `daily`. */
47
+ readonly limit?: 'blank' | 'daily' | (string & {});
48
+ /** `provisioning_failed`: the failed order. Its amount is back on your balance. */
49
+ readonly order?: Order;
50
+ /** The `Retry-After` header, in seconds. */
51
+ readonly retryAfter?: number;
52
+ /** The response body: the parsed JSON, or the text when it is not JSON. */
53
+ readonly body: unknown;
54
+ constructor(init: APIErrorInit);
55
+ }
56
+ /** 400: `invalid_request` or `idempotency_key_required`. */
57
+ export declare class BadRequestError extends APIError {
58
+ constructor(init: APIErrorInit);
59
+ }
60
+ /** 401 `unauthorized`: a missing, unknown or revoked key. */
61
+ export declare class AuthenticationError extends APIError {
62
+ constructor(init: APIErrorInit);
63
+ }
64
+ /** 403 `not_offered`: your agreement does not include this way of buying. */
65
+ export declare class PermissionDeniedError extends APIError {
66
+ constructor(init: APIErrorInit);
67
+ }
68
+ /** 404 `not_found`. */
69
+ export declare class NotFoundError extends APIError {
70
+ constructor(init: APIErrorInit);
71
+ }
72
+ /**
73
+ * 409: `idempotency_conflict`, `esim_busy`, `price_changed`,
74
+ * `esim_limit_reached` or `esim_unusable`.
75
+ */
76
+ export declare class ConflictError extends APIError {
77
+ constructor(init: APIErrorInit);
78
+ }
79
+ /** 429 `rate_limited`: `retryAfter` says how many seconds to wait. */
80
+ export declare class RateLimitError extends APIError {
81
+ constructor(init: APIErrorInit);
82
+ }
83
+ /**
84
+ * 5xx: `internal_error`, `provisioning_failed` (final; the failed order is in
85
+ * `order`), `esims_unavailable`, or an error page from the network on the way.
86
+ */
87
+ export declare class InternalServerError extends APIError {
88
+ constructor(init: APIErrorInit);
89
+ }
90
+ /** The `APIError` subclass for an answer's status. */
91
+ export declare function makeAPIError(init: APIErrorInit): APIError;
92
+ /**
93
+ * No answer from the API after every retry: the network failed or the last
94
+ * attempt timed out. A purchase may or may not have happened: retry it with
95
+ * `idempotencyKey`.
96
+ */
97
+ export declare class APIConnectionError extends OnesimError {
98
+ constructor(message: string, options: {
99
+ cause: unknown;
100
+ idempotencyKey?: string;
101
+ });
102
+ }
103
+ /** An `APIConnectionError` whose last attempt ran out of the client's `timeout`. */
104
+ export declare class APIConnectionTimeoutError extends APIConnectionError {
105
+ constructor(message: string, options: {
106
+ cause: unknown;
107
+ idempotencyKey?: string;
108
+ });
109
+ }
110
+ /** Polling an order ran out of time while it was still pending. */
111
+ export declare class PollTimeoutError extends OnesimError {
112
+ /** The order polled. */
113
+ readonly orderId: string;
114
+ /**
115
+ * The order as last read: still `pending`. Absent only when the time ran
116
+ * out before the first read answered.
117
+ */
118
+ readonly order?: Order;
119
+ constructor(orderId: string, order: Order | undefined, timeout: number);
120
+ }
121
+ export type WebhookErrorReason = 'missing_signature' | 'malformed_signature' | 'timestamp_out_of_tolerance' | 'invalid_signature' | 'invalid_payload';
122
+ /** A webhook delivery failed verification. Answer it with a 400 and do not act on it. */
123
+ export declare class WebhookVerificationError extends OnesimError {
124
+ readonly reason: WebhookErrorReason;
125
+ constructor(reason: WebhookErrorReason, message: string);
126
+ }
@@ -0,0 +1,182 @@
1
+ /** The base class of every error the SDK throws for the API. */
2
+ export class OnesimError extends Error {
3
+ /**
4
+ * On an error from `orders.create` or `orders.createAndPoll`: the
5
+ * Idempotency-Key it sent. Retry the purchase with this key and it is never
6
+ * bought twice.
7
+ */
8
+ idempotencyKey;
9
+ constructor(message, options) {
10
+ super(message, options);
11
+ this.name = 'OnesimError';
12
+ }
13
+ }
14
+ /**
15
+ * The API answered with a status other than 2xx. Act on `code`. A subclass
16
+ * names the common statuses: `BadRequestError` (400), `AuthenticationError`
17
+ * (401), `PermissionDeniedError` (403), `NotFoundError` (404), `ConflictError`
18
+ * (409), `RateLimitError` (429) and `InternalServerError` (5xx); any other
19
+ * status (e.g. 402 `insufficient_balance`) is an `APIError` itself.
20
+ */
21
+ export class APIError extends OnesimError {
22
+ /** The HTTP status. */
23
+ status;
24
+ /**
25
+ * The error code, e.g. `insufficient_balance`. New codes may be added: handle
26
+ * one you do not know by `status`. `null` when the body is not the API's
27
+ * error shape (e.g. an HTML page from a proxy).
28
+ */
29
+ code;
30
+ /** Quote it when you contact onesim. */
31
+ requestId;
32
+ /** `price_changed`: the current amount, in cents. */
33
+ amount;
34
+ /** `esim_limit_reached`: `blank` or `daily`. */
35
+ limit;
36
+ /** `provisioning_failed`: the failed order. Its amount is back on your balance. */
37
+ order;
38
+ /** The `Retry-After` header, in seconds. */
39
+ retryAfter;
40
+ /** The response body: the parsed JSON, or the text when it is not JSON. */
41
+ body;
42
+ constructor(init) {
43
+ super(init.message);
44
+ this.name = 'APIError';
45
+ this.status = init.status;
46
+ this.code = init.code;
47
+ this.requestId = init.requestId;
48
+ if (init.amount !== undefined)
49
+ this.amount = init.amount;
50
+ if (init.limit !== undefined)
51
+ this.limit = init.limit;
52
+ if (init.order !== undefined)
53
+ this.order = init.order;
54
+ if (init.retryAfter !== undefined)
55
+ this.retryAfter = init.retryAfter;
56
+ if (init.idempotencyKey !== undefined)
57
+ this.idempotencyKey = init.idempotencyKey;
58
+ this.body = init.body;
59
+ }
60
+ }
61
+ /** 400: `invalid_request` or `idempotency_key_required`. */
62
+ export class BadRequestError extends APIError {
63
+ constructor(init) {
64
+ super(init);
65
+ this.name = 'BadRequestError';
66
+ }
67
+ }
68
+ /** 401 `unauthorized`: a missing, unknown or revoked key. */
69
+ export class AuthenticationError extends APIError {
70
+ constructor(init) {
71
+ super(init);
72
+ this.name = 'AuthenticationError';
73
+ }
74
+ }
75
+ /** 403 `not_offered`: your agreement does not include this way of buying. */
76
+ export class PermissionDeniedError extends APIError {
77
+ constructor(init) {
78
+ super(init);
79
+ this.name = 'PermissionDeniedError';
80
+ }
81
+ }
82
+ /** 404 `not_found`. */
83
+ export class NotFoundError extends APIError {
84
+ constructor(init) {
85
+ super(init);
86
+ this.name = 'NotFoundError';
87
+ }
88
+ }
89
+ /**
90
+ * 409: `idempotency_conflict`, `esim_busy`, `price_changed`,
91
+ * `esim_limit_reached` or `esim_unusable`.
92
+ */
93
+ export class ConflictError extends APIError {
94
+ constructor(init) {
95
+ super(init);
96
+ this.name = 'ConflictError';
97
+ }
98
+ }
99
+ /** 429 `rate_limited`: `retryAfter` says how many seconds to wait. */
100
+ export class RateLimitError extends APIError {
101
+ constructor(init) {
102
+ super(init);
103
+ this.name = 'RateLimitError';
104
+ }
105
+ }
106
+ /**
107
+ * 5xx: `internal_error`, `provisioning_failed` (final; the failed order is in
108
+ * `order`), `esims_unavailable`, or an error page from the network on the way.
109
+ */
110
+ export class InternalServerError extends APIError {
111
+ constructor(init) {
112
+ super(init);
113
+ this.name = 'InternalServerError';
114
+ }
115
+ }
116
+ /** The `APIError` subclass for an answer's status. */
117
+ export function makeAPIError(init) {
118
+ switch (init.status) {
119
+ case 400:
120
+ return new BadRequestError(init);
121
+ case 401:
122
+ return new AuthenticationError(init);
123
+ case 403:
124
+ return new PermissionDeniedError(init);
125
+ case 404:
126
+ return new NotFoundError(init);
127
+ case 409:
128
+ return new ConflictError(init);
129
+ case 429:
130
+ return new RateLimitError(init);
131
+ default:
132
+ return init.status >= 500
133
+ ? new InternalServerError(init)
134
+ : new APIError(init);
135
+ }
136
+ }
137
+ /**
138
+ * No answer from the API after every retry: the network failed or the last
139
+ * attempt timed out. A purchase may or may not have happened: retry it with
140
+ * `idempotencyKey`.
141
+ */
142
+ export class APIConnectionError extends OnesimError {
143
+ constructor(message, options) {
144
+ super(message, { cause: options.cause });
145
+ this.name = 'APIConnectionError';
146
+ if (options.idempotencyKey !== undefined)
147
+ this.idempotencyKey = options.idempotencyKey;
148
+ }
149
+ }
150
+ /** An `APIConnectionError` whose last attempt ran out of the client's `timeout`. */
151
+ export class APIConnectionTimeoutError extends APIConnectionError {
152
+ constructor(message, options) {
153
+ super(message, options);
154
+ this.name = 'APIConnectionTimeoutError';
155
+ }
156
+ }
157
+ /** Polling an order ran out of time while it was still pending. */
158
+ export class PollTimeoutError extends OnesimError {
159
+ /** The order polled. */
160
+ orderId;
161
+ /**
162
+ * The order as last read: still `pending`. Absent only when the time ran
163
+ * out before the first read answered.
164
+ */
165
+ order;
166
+ constructor(orderId, order, timeout) {
167
+ super(`Order ${orderId} was still pending after ${timeout} ms.`);
168
+ this.name = 'PollTimeoutError';
169
+ this.orderId = orderId;
170
+ if (order !== undefined)
171
+ this.order = order;
172
+ }
173
+ }
174
+ /** A webhook delivery failed verification. Answer it with a 400 and do not act on it. */
175
+ export class WebhookVerificationError extends OnesimError {
176
+ reason;
177
+ constructor(reason, message) {
178
+ super(message);
179
+ this.name = 'WebhookVerificationError';
180
+ this.reason = reason;
181
+ }
182
+ }