@isnap/sdk 0.1.0 → 1.1.0-next.49
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/README.md +173 -167
- package/dist/client.d.ts +48 -50
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +258 -89
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +43 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +55 -0
- package/dist/config.js.map +1 -0
- package/dist/errors.d.ts +53 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +100 -0
- package/dist/errors.js.map +1 -0
- package/dist/generated/openapi.d.ts +10924 -0
- package/dist/idempotency.d.ts +2 -0
- package/dist/idempotency.d.ts.map +1 -0
- package/dist/idempotency.js +4 -0
- package/dist/idempotency.js.map +1 -0
- package/dist/index.d.ts +26 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -6
- package/dist/index.js.map +1 -1
- package/dist/internal/sleep.d.ts +10 -0
- package/dist/internal/sleep.d.ts.map +1 -0
- package/dist/internal/sleep.js +37 -0
- package/dist/internal/sleep.js.map +1 -0
- package/dist/pagination.d.ts +10 -0
- package/dist/pagination.d.ts.map +1 -0
- package/dist/pagination.js +16 -0
- package/dist/pagination.js.map +1 -0
- package/dist/resources/attachments.d.ts +45 -0
- package/dist/resources/attachments.d.ts.map +1 -0
- package/dist/resources/attachments.js +120 -0
- package/dist/resources/attachments.js.map +1 -0
- package/dist/resources/base.d.ts +6 -0
- package/dist/resources/base.d.ts.map +1 -0
- package/dist/resources/base.js +7 -0
- package/dist/resources/base.js.map +1 -0
- package/dist/resources/byod.d.ts +15 -0
- package/dist/resources/byod.d.ts.map +1 -0
- package/dist/resources/byod.js +13 -0
- package/dist/resources/byod.js.map +1 -0
- package/dist/resources/chats.d.ts +29 -0
- package/dist/resources/chats.d.ts.map +1 -0
- package/dist/resources/chats.js +28 -0
- package/dist/resources/chats.js.map +1 -0
- package/dist/resources/lines.d.ts +64 -27
- package/dist/resources/lines.d.ts.map +1 -1
- package/dist/resources/lines.js +77 -37
- package/dist/resources/lines.js.map +1 -1
- package/dist/resources/lookup.d.ts +15 -0
- package/dist/resources/lookup.d.ts.map +1 -0
- package/dist/resources/lookup.js +13 -0
- package/dist/resources/lookup.js.map +1 -0
- package/dist/resources/messages.d.ts +36 -67
- package/dist/resources/messages.d.ts.map +1 -1
- package/dist/resources/messages.js +37 -94
- package/dist/resources/messages.js.map +1 -1
- package/dist/resources/trial.d.ts +28 -0
- package/dist/resources/trial.d.ts.map +1 -0
- package/dist/resources/trial.js +31 -0
- package/dist/resources/trial.js.map +1 -0
- package/dist/resources/webhooks.d.ts +49 -39
- package/dist/resources/webhooks.d.ts.map +1 -1
- package/dist/resources/webhooks.js +52 -39
- package/dist/resources/webhooks.js.map +1 -1
- package/dist/retry.d.ts +14 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +47 -0
- package/dist/retry.js.map +1 -0
- package/dist/types.d.ts +30 -196
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -28
- package/dist/types.js.map +1 -1
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +20 -0
- package/dist/version.js.map +1 -0
- package/dist/webhooks/parse.d.ts +15 -0
- package/dist/webhooks/parse.d.ts.map +1 -0
- package/dist/webhooks/parse.js +47 -0
- package/dist/webhooks/parse.js.map +1 -0
- package/dist/webhooks/types.d.ts +93 -0
- package/dist/webhooks/types.d.ts.map +1 -0
- package/dist/webhooks/types.js +20 -0
- package/dist/webhooks/types.js.map +1 -0
- package/dist/webhooks/verify.d.ts +41 -0
- package/dist/webhooks/verify.d.ts.map +1 -0
- package/dist/webhooks/verify.js +110 -0
- package/dist/webhooks/verify.js.map +1 -0
- package/package.json +45 -30
- package/dist/paginate.d.ts +0 -33
- package/dist/paginate.d.ts.map +0 -1
- package/dist/paginate.js +0 -40
- package/dist/paginate.js.map +0 -1
- package/dist/webhook-events.d.ts +0 -61
- package/dist/webhook-events.d.ts.map +0 -1
- package/dist/webhook-events.js +0 -44
- package/dist/webhook-events.js.map +0 -1
- package/dist/webhook-verify.d.ts +0 -27
- package/dist/webhook-verify.d.ts.map +0 -1
- package/dist/webhook-verify.js +0 -42
- package/dist/webhook-verify.js.map +0 -1
|
@@ -1,48 +1,58 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type { components, paths } from '../generated/openapi.js';
|
|
2
|
+
import type { RequestOptions } from '../types.js';
|
|
3
|
+
import { BaseResource } from './base.js';
|
|
4
|
+
export type Webhook = components['schemas']['WebhookV1'];
|
|
5
|
+
export type WebhookList = components['schemas']['WebhookList'];
|
|
6
|
+
export type WebhookRotateSecret = components['schemas']['WebhookRotateSecret'];
|
|
7
|
+
export type WebhookDelivery = components['schemas']['WebhookDeliveryV1'];
|
|
8
|
+
export type WebhookDeliveryReplay = components['schemas']['WebhookDeliveryReplay'];
|
|
9
|
+
export type WebhookEventItem = components['schemas']['WebhookEventItem'];
|
|
10
|
+
export type CreateWebhookBody = NonNullable<paths['/v1/webhooks']['post']['requestBody']>['content']['application/json'];
|
|
11
|
+
export type UpdateWebhookBody = NonNullable<paths['/v1/webhooks/{id}']['patch']['requestBody']>['content']['application/json'];
|
|
12
|
+
export type ListDeliveriesQuery = NonNullable<paths['/v1/webhooks/{id}/deliveries']['get']['parameters']['query']>;
|
|
13
|
+
export type ListEventsQuery = paths['/v1/webhooks/events']['get']['parameters']['query'];
|
|
14
|
+
export declare class WebhooksResource extends BaseResource {
|
|
15
|
+
/** `GET /v1/webhooks` — list all webhook subscriptions for the calling account. */
|
|
16
|
+
list(opts?: RequestOptions): Promise<WebhookList>;
|
|
6
17
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @returns The created webhook (includes the `secret` for signature verification)
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* const wh = await client.webhooks.create({
|
|
15
|
-
* url: 'https://example.com/webhooks/isnap',
|
|
16
|
-
* events: ['message.sent', 'message.delivered'],
|
|
17
|
-
* });
|
|
18
|
-
* console.log(wh.secret); // save this for verification
|
|
19
|
-
* ```
|
|
18
|
+
* `POST /v1/webhooks` — create a subscription. Plaintext `secret` is
|
|
19
|
+
* returned ONCE in the create response; persist it then. Subsequent
|
|
20
|
+
* GETs do not include it.
|
|
20
21
|
*/
|
|
21
|
-
create(
|
|
22
|
+
create(body: CreateWebhookBody, opts?: RequestOptions): Promise<Webhook>;
|
|
23
|
+
/** `GET /v1/webhooks/{id}` — fetch a single webhook subscription. */
|
|
24
|
+
get(id: string, opts?: RequestOptions): Promise<Webhook>;
|
|
25
|
+
/** `PATCH /v1/webhooks/{id}` — partial update of url / events / line_ids / active flag. */
|
|
26
|
+
update(id: string, body: UpdateWebhookBody, opts?: RequestOptions): Promise<Webhook>;
|
|
27
|
+
/** `DELETE /v1/webhooks/{id}` — delete a subscription. Returns 204. */
|
|
28
|
+
delete(id: string, opts?: RequestOptions): Promise<void>;
|
|
22
29
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```ts
|
|
29
|
-
* const { webhooks } = await client.webhooks.list();
|
|
30
|
-
* ```
|
|
30
|
+
* `POST /v1/webhooks/{id}/rotate-secret` — mint a new `whs_*` secret.
|
|
31
|
+
* Old secret stays valid for 5 minutes (`old_secret_expires_at`) so the
|
|
32
|
+
* caller can roll their verification code without dropping events.
|
|
33
|
+
* Plaintext secret is returned ONCE.
|
|
31
34
|
*/
|
|
32
|
-
|
|
33
|
-
webhooks: Webhook[];
|
|
34
|
-
}>;
|
|
35
|
+
rotateSecret(id: string, opts?: RequestOptions): Promise<WebhookRotateSecret>;
|
|
35
36
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
|
|
37
|
+
* `GET /v1/webhooks/{id}/deliveries` — cursor-paginated AsyncIterable
|
|
38
|
+
* over delivery attempts for a subscription. Filters: status (pending/
|
|
39
|
+
* success/failed), event type, since/until timestamps.
|
|
40
|
+
*/
|
|
41
|
+
deliveries(id: string, filters?: Omit<ListDeliveriesQuery, 'cursor'>, opts?: RequestOptions): AsyncIterable<WebhookDelivery>;
|
|
42
|
+
/**
|
|
43
|
+
* `POST /v1/webhooks/{id}/deliveries/{delivery_id}/replay` — re-fire a
|
|
44
|
+
* past delivery. Server preserves the original `event_id` so consumers
|
|
45
|
+
* still dedupe.
|
|
46
|
+
*/
|
|
47
|
+
replay(webhookId: string, deliveryId: string, opts?: RequestOptions): Promise<WebhookDeliveryReplay>;
|
|
48
|
+
/**
|
|
49
|
+
* `GET /v1/webhooks/events` — cursor-paginated reconciliation pull.
|
|
50
|
+
* Returns events that would have been delivered to the caller's
|
|
51
|
+
* subscriptions within the 72h retention window. Used to recover from
|
|
52
|
+
* webhook outages without missing signal.
|
|
40
53
|
*
|
|
41
|
-
*
|
|
42
|
-
* ```ts
|
|
43
|
-
* await client.webhooks.delete('wh-abc123');
|
|
44
|
-
* ```
|
|
54
|
+
* `since` is required by the contract.
|
|
45
55
|
*/
|
|
46
|
-
|
|
56
|
+
events(filters: Omit<NonNullable<ListEventsQuery>, 'cursor'>, opts?: RequestOptions): AsyncIterable<WebhookEventItem>;
|
|
47
57
|
}
|
|
48
58
|
//# sourceMappingURL=webhooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../../src/resources/webhooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../../src/resources/webhooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,yBAAyB,C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|
2
|
+
import { BaseResource } from './base.js';
|
|
3
|
+
export class WebhooksResource extends BaseResource {
|
|
4
|
+
/** `GET /v1/webhooks` — list all webhook subscriptions for the calling account. */
|
|
5
|
+
list(opts) {
|
|
6
|
+
return this.client.request('GET', '/v1/webhooks', undefined, opts);
|
|
5
7
|
}
|
|
6
8
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @returns The created webhook (includes the `secret` for signature verification)
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* const wh = await client.webhooks.create({
|
|
15
|
-
* url: 'https://example.com/webhooks/isnap',
|
|
16
|
-
* events: ['message.sent', 'message.delivered'],
|
|
17
|
-
* });
|
|
18
|
-
* console.log(wh.secret); // save this for verification
|
|
19
|
-
* ```
|
|
9
|
+
* `POST /v1/webhooks` — create a subscription. Plaintext `secret` is
|
|
10
|
+
* returned ONCE in the create response; persist it then. Subsequent
|
|
11
|
+
* GETs do not include it.
|
|
20
12
|
*/
|
|
21
|
-
|
|
22
|
-
return this.client.request('POST', '/v1/webhooks',
|
|
13
|
+
create(body, opts) {
|
|
14
|
+
return this.client.request('POST', '/v1/webhooks', body, opts);
|
|
15
|
+
}
|
|
16
|
+
/** `GET /v1/webhooks/{id}` — fetch a single webhook subscription. */
|
|
17
|
+
get(id, opts) {
|
|
18
|
+
return this.client.request('GET', `/v1/webhooks/${encodeURIComponent(id)}`, undefined, opts);
|
|
19
|
+
}
|
|
20
|
+
/** `PATCH /v1/webhooks/{id}` — partial update of url / events / line_ids / active flag. */
|
|
21
|
+
update(id, body, opts) {
|
|
22
|
+
return this.client.request('PATCH', `/v1/webhooks/${encodeURIComponent(id)}`, body, opts);
|
|
23
|
+
}
|
|
24
|
+
/** `DELETE /v1/webhooks/{id}` — delete a subscription. Returns 204. */
|
|
25
|
+
delete(id, opts) {
|
|
26
|
+
return this.client.request('DELETE', `/v1/webhooks/${encodeURIComponent(id)}`, undefined, opts);
|
|
23
27
|
}
|
|
24
28
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```ts
|
|
31
|
-
* const { webhooks } = await client.webhooks.list();
|
|
32
|
-
* ```
|
|
29
|
+
* `POST /v1/webhooks/{id}/rotate-secret` — mint a new `whs_*` secret.
|
|
30
|
+
* Old secret stays valid for 5 minutes (`old_secret_expires_at`) so the
|
|
31
|
+
* caller can roll their verification code without dropping events.
|
|
32
|
+
* Plaintext secret is returned ONCE.
|
|
33
33
|
*/
|
|
34
|
-
|
|
35
|
-
return this.client.request('
|
|
34
|
+
rotateSecret(id, opts) {
|
|
35
|
+
return this.client.request('POST', `/v1/webhooks/${encodeURIComponent(id)}/rotate-secret`, undefined, opts);
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
|
|
38
|
+
* `GET /v1/webhooks/{id}/deliveries` — cursor-paginated AsyncIterable
|
|
39
|
+
* over delivery attempts for a subscription. Filters: status (pending/
|
|
40
|
+
* success/failed), event type, since/until timestamps.
|
|
41
|
+
*/
|
|
42
|
+
deliveries(id, filters = {}, opts) {
|
|
43
|
+
return paginate((cursor) => this.client.request('GET', `/v1/webhooks/${encodeURIComponent(id)}/deliveries`, undefined, { ...opts, query: { ...filters, cursor } }), { signal: opts?.signal });
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* `POST /v1/webhooks/{id}/deliveries/{delivery_id}/replay` — re-fire a
|
|
47
|
+
* past delivery. Server preserves the original `event_id` so consumers
|
|
48
|
+
* still dedupe.
|
|
49
|
+
*/
|
|
50
|
+
replay(webhookId, deliveryId, opts) {
|
|
51
|
+
return this.client.request('POST', `/v1/webhooks/${encodeURIComponent(webhookId)}/deliveries/${encodeURIComponent(deliveryId)}/replay`, undefined, opts);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* `GET /v1/webhooks/events` — cursor-paginated reconciliation pull.
|
|
55
|
+
* Returns events that would have been delivered to the caller's
|
|
56
|
+
* subscriptions within the 72h retention window. Used to recover from
|
|
57
|
+
* webhook outages without missing signal.
|
|
42
58
|
*
|
|
43
|
-
*
|
|
44
|
-
* ```ts
|
|
45
|
-
* await client.webhooks.delete('wh-abc123');
|
|
46
|
-
* ```
|
|
59
|
+
* `since` is required by the contract.
|
|
47
60
|
*/
|
|
48
|
-
|
|
49
|
-
return this.client.request('
|
|
61
|
+
events(filters, opts) {
|
|
62
|
+
return paginate((cursor) => this.client.request('GET', '/v1/webhooks/events', undefined, { ...opts, query: { ...filters, cursor } }), { signal: opts?.signal });
|
|
50
63
|
}
|
|
51
64
|
}
|
|
52
65
|
//# sourceMappingURL=webhooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../../src/resources/webhooks.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../../src/resources/webhooks.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAoBxC,MAAM,OAAO,gBAAiB,SAAQ,YAAY;IAChD,mFAAmF;IACnF,IAAI,CAAC,IAAqB;QACxB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAc,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,IAAI,CAAC,CAAA;IACjF,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,IAAuB,EAAE,IAAqB;QACnD,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAU,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;IACzE,CAAC;IAED,qEAAqE;IACrE,GAAG,CAAC,EAAU,EAAE,IAAqB;QACnC,OAAO,IAAI,CAAC,MAAM,CAAC,OAA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,CAAC,SAAS,CAAC,eAAe,kBAAkB,CAAC,UAAU,CAAC,SAAS,EACnG,SAAS,EACT,IAAI,CACL,CAAA;IACH,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CACJ,OAAqD,EACrD,IAAqB;QAErB,OAAO,QAAQ,CACb,CAAC,MAAM,EAAE,EAAE,CACT,IAAI,CAAC,MAAM,CAAC,OAAO,CACjB,KAAK,EACL,qBAAqB,EACrB,SAAS,EACT,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,EAAE,CAC3C,EACH,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CACzB,CAAA;IACH,CAAC;CACF"}
|
package/dist/retry.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface RetryInfo {
|
|
2
|
+
attempt: number;
|
|
3
|
+
nextDelayMs: number;
|
|
4
|
+
error: unknown;
|
|
5
|
+
}
|
|
6
|
+
export interface RetryConfig {
|
|
7
|
+
maxRetries: number;
|
|
8
|
+
onRetry?: (info: RetryInfo) => void;
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
}
|
|
11
|
+
export declare function isRetryable(err: unknown): boolean;
|
|
12
|
+
export declare function computeBackoff(attempt: number, err: unknown): number;
|
|
13
|
+
export declare function withRetries<T>(fn: () => Promise<T>, config: RetryConfig): Promise<T>;
|
|
14
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,OAAO,CAAA;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAA;IACnC,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAKD,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAOjD;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,MAAM,CAKpE;AAED,wBAAsB,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAoB1F"}
|
package/dist/retry.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { APIConnectionError, InternalServerError, QuotaExceededError, RateLimitError, ServiceUnavailableError } from './errors.js';
|
|
2
|
+
import { sleep } from './internal/sleep.js';
|
|
3
|
+
const BASE_DELAY_MS = 250;
|
|
4
|
+
const JITTER_MS = 100;
|
|
5
|
+
export function isRetryable(err) {
|
|
6
|
+
if (err instanceof QuotaExceededError)
|
|
7
|
+
return false;
|
|
8
|
+
if (err instanceof APIConnectionError)
|
|
9
|
+
return true;
|
|
10
|
+
if (err instanceof InternalServerError)
|
|
11
|
+
return true;
|
|
12
|
+
if (err instanceof ServiceUnavailableError)
|
|
13
|
+
return true;
|
|
14
|
+
if (err instanceof RateLimitError)
|
|
15
|
+
return true;
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
export function computeBackoff(attempt, err) {
|
|
19
|
+
if (err instanceof RateLimitError && typeof err.retryAfter === 'number' && err.retryAfter > 0) {
|
|
20
|
+
return err.retryAfter * 1000;
|
|
21
|
+
}
|
|
22
|
+
return BASE_DELAY_MS * Math.pow(2, attempt) + Math.random() * JITTER_MS;
|
|
23
|
+
}
|
|
24
|
+
export async function withRetries(fn, config) {
|
|
25
|
+
let lastError;
|
|
26
|
+
for (let attempt = 0; attempt <= config.maxRetries; attempt++) {
|
|
27
|
+
if (config.signal?.aborted) {
|
|
28
|
+
throw new APIConnectionError('Request aborted before attempt', {
|
|
29
|
+
cause: config.signal.reason
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
return await fn();
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
lastError = err;
|
|
37
|
+
const isLast = attempt === config.maxRetries;
|
|
38
|
+
if (isLast || !isRetryable(err))
|
|
39
|
+
throw err;
|
|
40
|
+
const nextDelayMs = computeBackoff(attempt, err);
|
|
41
|
+
config.onRetry?.({ attempt, nextDelayMs, error: err });
|
|
42
|
+
await sleep(nextDelayMs, config.signal, 'Request aborted during retry backoff');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
throw lastError;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,uBAAuB,EACxB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAc3C,MAAM,aAAa,GAAG,GAAG,CAAA;AACzB,MAAM,SAAS,GAAG,GAAG,CAAA;AAErB,MAAM,UAAU,WAAW,CAAC,GAAY;IACtC,IAAI,GAAG,YAAY,kBAAkB;QAAE,OAAO,KAAK,CAAA;IACnD,IAAI,GAAG,YAAY,kBAAkB;QAAE,OAAO,IAAI,CAAA;IAClD,IAAI,GAAG,YAAY,mBAAmB;QAAE,OAAO,IAAI,CAAA;IACnD,IAAI,GAAG,YAAY,uBAAuB;QAAE,OAAO,IAAI,CAAA;IACvD,IAAI,GAAG,YAAY,cAAc;QAAE,OAAO,IAAI,CAAA;IAC9C,OAAO,KAAK,CAAA;AACd,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAe,EAAE,GAAY;IAC1D,IAAI,GAAG,YAAY,cAAc,IAAI,OAAO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.d.ts
CHANGED
|
@@ -1,199 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
export interface
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
line_id: string;
|
|
25
|
-
/** Recipient phone number in E.164 format. */
|
|
26
|
-
to: string;
|
|
27
|
-
/** Message body text. */
|
|
28
|
-
body: string;
|
|
29
|
-
/** Messaging channel. Defaults to `'auto'`. */
|
|
30
|
-
channel?: 'auto' | 'imessage' | 'sms' | 'whatsapp';
|
|
31
|
-
/** Optional webhook URL to receive delivery status updates. */
|
|
32
|
-
webhook_url?: string;
|
|
33
|
-
/** Arbitrary key-value metadata attached to the message. */
|
|
34
|
-
metadata?: Record<string, unknown>;
|
|
35
|
-
}
|
|
36
|
-
/** Filter/pagination parameters for listing messages. */
|
|
37
|
-
export interface ListMessagesParams {
|
|
38
|
-
line_id?: string;
|
|
39
|
-
status?: 'queued' | 'sent' | 'delivered' | 'read' | 'failed';
|
|
40
|
-
direction?: 'outbound' | 'inbound';
|
|
41
|
-
page?: number;
|
|
42
|
-
limit?: number;
|
|
43
|
-
}
|
|
44
|
-
/** Paginated list of messages. */
|
|
45
|
-
export interface ListMessagesResponse {
|
|
46
|
-
messages: Message[];
|
|
47
|
-
total: number;
|
|
48
|
-
page: number;
|
|
49
|
-
limit: number;
|
|
50
|
-
}
|
|
51
|
-
/** A conversation thread between a line and a contact. */
|
|
52
|
-
export interface Conversation {
|
|
53
|
-
id: string;
|
|
54
|
-
line_id: string;
|
|
55
|
-
contact_number: string;
|
|
56
|
-
last_message_at: string;
|
|
57
|
-
message_count: number;
|
|
58
|
-
created_at: string;
|
|
59
|
-
}
|
|
60
|
-
/** Filter/pagination parameters for listing conversations. */
|
|
61
|
-
export interface ListConversationsParams {
|
|
62
|
-
line_id?: string;
|
|
63
|
-
page?: number;
|
|
64
|
-
limit?: number;
|
|
65
|
-
}
|
|
66
|
-
/** Paginated list of conversations. */
|
|
67
|
-
export interface ListConversationsResponse {
|
|
68
|
-
conversations: Conversation[];
|
|
69
|
-
total: number;
|
|
70
|
-
page: number;
|
|
71
|
-
limit: number;
|
|
72
|
-
}
|
|
73
|
-
/** Pagination parameters for retrieving a conversation thread. */
|
|
74
|
-
export interface ConversationThreadParams {
|
|
75
|
-
/** Page number (1-based). */
|
|
76
|
-
page?: number;
|
|
77
|
-
/** Number of messages per page. */
|
|
78
|
-
limit?: number;
|
|
79
|
-
}
|
|
80
|
-
/** A conversation thread with its messages. */
|
|
81
|
-
export interface ConversationThreadResponse {
|
|
82
|
-
conversation: Conversation;
|
|
83
|
-
messages: Message[];
|
|
84
|
-
total: number;
|
|
85
|
-
page: number;
|
|
86
|
-
limit: number;
|
|
87
|
-
}
|
|
88
|
-
/** A phone line (iPhone or Android). */
|
|
89
|
-
export interface Line {
|
|
90
|
-
id: string;
|
|
91
|
-
phone_number: string;
|
|
92
|
-
area_code: string;
|
|
93
|
-
type: string;
|
|
94
|
-
capabilities: unknown;
|
|
95
|
-
status: string;
|
|
96
|
-
monthly_price: number;
|
|
97
|
-
activated_at: string | null;
|
|
98
|
-
created_at: string;
|
|
99
|
-
}
|
|
100
|
-
/** Paginated list of lines. */
|
|
101
|
-
export interface ListLinesResponse {
|
|
102
|
-
lines: Line[];
|
|
103
|
-
total: number;
|
|
104
|
-
page: number;
|
|
105
|
-
limit: number;
|
|
106
|
-
}
|
|
107
|
-
/** Filter/pagination parameters for listing lines. */
|
|
108
|
-
export interface ListLinesParams {
|
|
109
|
-
type?: string;
|
|
110
|
-
area_code?: string;
|
|
111
|
-
page?: number;
|
|
112
|
-
limit?: number;
|
|
113
|
-
}
|
|
114
|
-
/** A registered webhook endpoint. */
|
|
115
|
-
export interface Webhook {
|
|
116
|
-
id: string;
|
|
117
|
-
url: string;
|
|
118
|
-
events: string[];
|
|
119
|
-
active: boolean;
|
|
120
|
-
failure_count: number;
|
|
121
|
-
last_success_at: string | null;
|
|
122
|
-
last_failure_at: string | null;
|
|
123
|
-
created_at: string;
|
|
124
|
-
secret?: string;
|
|
125
|
-
}
|
|
126
|
-
/** Parameters for creating a webhook. */
|
|
127
|
-
export interface CreateWebhookParams {
|
|
128
|
-
/** The URL to receive webhook events. */
|
|
129
|
-
url: string;
|
|
130
|
-
/** Event types to subscribe to. Defaults to all events. */
|
|
131
|
-
events?: string[];
|
|
132
|
-
}
|
|
133
|
-
/** All supported webhook event types. */
|
|
134
|
-
export type WebhookEventType = 'message.sent' | 'message.delivered' | 'message.read' | 'message.failed' | 'message.received';
|
|
135
|
-
/** Base shape shared by all webhook events. */
|
|
136
|
-
interface WebhookEventBase {
|
|
137
|
-
webhook_id: string;
|
|
138
|
-
timestamp: string;
|
|
139
|
-
}
|
|
140
|
-
/** Fired when a message is successfully sent. */
|
|
141
|
-
export interface MessageSentEvent extends WebhookEventBase {
|
|
142
|
-
event: 'message.sent';
|
|
143
|
-
data: Message;
|
|
144
|
-
}
|
|
145
|
-
/** Fired when a message is delivered to the recipient. */
|
|
146
|
-
export interface MessageDeliveredEvent extends WebhookEventBase {
|
|
147
|
-
event: 'message.delivered';
|
|
148
|
-
data: Message;
|
|
149
|
-
}
|
|
150
|
-
/** Fired when a message is read by the recipient. */
|
|
151
|
-
export interface MessageReadEvent extends WebhookEventBase {
|
|
152
|
-
event: 'message.read';
|
|
153
|
-
data: Message;
|
|
154
|
-
}
|
|
155
|
-
/** Fired when a message fails to send. */
|
|
156
|
-
export interface MessageFailedEvent extends WebhookEventBase {
|
|
157
|
-
event: 'message.failed';
|
|
158
|
-
data: Message;
|
|
159
|
-
}
|
|
160
|
-
/** Fired when an inbound message is received. */
|
|
161
|
-
export interface MessageReceivedEvent extends WebhookEventBase {
|
|
162
|
-
event: 'message.received';
|
|
163
|
-
data: Message;
|
|
164
|
-
}
|
|
165
|
-
/** Discriminated union of all webhook event types. Switch on `event.event` for type narrowing. */
|
|
166
|
-
export type WebhookEvent = MessageSentEvent | MessageDeliveredEvent | MessageReadEvent | MessageFailedEvent | MessageReceivedEvent;
|
|
167
|
-
/** Configuration for the iSnap SDK client. */
|
|
168
|
-
export interface iSnapConfig {
|
|
169
|
-
/** Your iSnap API key (starts with `isnap_`). */
|
|
170
|
-
apiKey: string;
|
|
171
|
-
/** Override the base API URL. Defaults to `https://api.isnap.dev`. */
|
|
172
|
-
baseUrl?: string;
|
|
173
|
-
/** Maximum number of automatic retries on 429 responses. Defaults to `3`. */
|
|
1
|
+
export type HttpMethod = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
|
|
2
|
+
export interface ErrorIssue {
|
|
3
|
+
path: string;
|
|
4
|
+
message: string;
|
|
5
|
+
code: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ErrorEnvelope {
|
|
8
|
+
status: number;
|
|
9
|
+
code: string;
|
|
10
|
+
message: string;
|
|
11
|
+
retry_after?: number;
|
|
12
|
+
issues?: ErrorIssue[];
|
|
13
|
+
}
|
|
14
|
+
export interface ResponseEnvelope<T = unknown> {
|
|
15
|
+
success: boolean;
|
|
16
|
+
data: T | null;
|
|
17
|
+
error: ErrorEnvelope | null;
|
|
18
|
+
trace_id?: string;
|
|
19
|
+
request_id?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface RequestOptions {
|
|
22
|
+
idempotencyKey?: string;
|
|
23
|
+
signal?: AbortSignal;
|
|
174
24
|
maxRetries?: number;
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
/** Machine-readable error code (e.g. `'RATE_LIMITED'`). */
|
|
183
|
-
code?: string | undefined;
|
|
184
|
-
constructor(message: string,
|
|
185
|
-
/** HTTP status code. */
|
|
186
|
-
statusCode: number,
|
|
187
|
-
/** Machine-readable error code (e.g. `'RATE_LIMITED'`). */
|
|
188
|
-
code?: string | undefined);
|
|
189
|
-
}
|
|
190
|
-
/** Thrown when the API returns 429 Too Many Requests after exhausting retries. */
|
|
191
|
-
export declare class RateLimitError extends iSnapError {
|
|
192
|
-
/** Seconds to wait before retrying. */
|
|
193
|
-
retryAfter: number;
|
|
194
|
-
constructor(message: string,
|
|
195
|
-
/** Seconds to wait before retrying. */
|
|
196
|
-
retryAfter: number);
|
|
25
|
+
query?: Record<string, string | number | boolean | undefined | null>;
|
|
26
|
+
/**
|
|
27
|
+
* Extra headers to merge into the request. SDK defaults (User-Agent,
|
|
28
|
+
* Accept, Content-Type) can be overridden; SDK-managed Authorization and
|
|
29
|
+
* Idempotency-Key always win regardless of what is set here.
|
|
30
|
+
*/
|
|
31
|
+
headers?: HeadersInit;
|
|
197
32
|
}
|
|
198
|
-
export {};
|
|
199
33
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,QAAQ,CAAA;AAEpE,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,UAAU,EAAE,CAAA;CACtB;AAED,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,OAAO;IAC3C,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,EAAE,CAAC,GAAG,IAAI,CAAA;IACd,KAAK,EAAE,aAAa,GAAG,IAAI,CAAA;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,IAAI,CAAC,CAAA;IACpE;;;;OAIG;IACH,OAAO,CAAC,EAAE,WAAW,CAAA;CACtB"}
|
package/dist/types.js
CHANGED
|
@@ -1,29 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
// ── Errors ───────────────────────────────────────────────────────────────────
|
|
3
|
-
/** Error returned by the iSnap API. */
|
|
4
|
-
export class iSnapError extends Error {
|
|
5
|
-
statusCode;
|
|
6
|
-
code;
|
|
7
|
-
constructor(message,
|
|
8
|
-
/** HTTP status code. */
|
|
9
|
-
statusCode,
|
|
10
|
-
/** Machine-readable error code (e.g. `'RATE_LIMITED'`). */
|
|
11
|
-
code) {
|
|
12
|
-
super(message);
|
|
13
|
-
this.statusCode = statusCode;
|
|
14
|
-
this.code = code;
|
|
15
|
-
this.name = 'iSnapError';
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
/** Thrown when the API returns 429 Too Many Requests after exhausting retries. */
|
|
19
|
-
export class RateLimitError extends iSnapError {
|
|
20
|
-
retryAfter;
|
|
21
|
-
constructor(message,
|
|
22
|
-
/** Seconds to wait before retrying. */
|
|
23
|
-
retryAfter) {
|
|
24
|
-
super(message, 429, 'RATE_LIMITED');
|
|
25
|
-
this.retryAfter = retryAfter;
|
|
26
|
-
this.name = 'RateLimitError';
|
|
27
|
-
}
|
|
28
|
-
}
|
|
1
|
+
export {};
|
|
29
2
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW,UAAU,CAAA;AAelC,eAAO,MAAM,eAAe,UAAU,CAAA"}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// SDK version. Bumped INDEPENDENTLY of the API contract version per
|
|
2
|
+
// industry standard (Stripe, Twilio, OpenAI, AWS): SDK semver tracks SDK
|
|
3
|
+
// changes (new methods, retry logic, type fixes), API semver tracks the
|
|
4
|
+
// contract surface. Synced with `package.json` by the release flow.
|
|
5
|
+
export const SDK_VERSION = '1.0.0';
|
|
6
|
+
// Minimum API version the SDK considers compatible. Reference-only
|
|
7
|
+
// today: the client does NOT yet fetch `/v1/version` at first request,
|
|
8
|
+
// and there is no `IncompatibleApiVersionError` thrown on a lower
|
|
9
|
+
// backend. The runtime precheck (and the corresponding error type) is a
|
|
10
|
+
// follow-up — until it ships, this constant is documentation that
|
|
11
|
+
// downstream tooling can read but the client itself does not enforce.
|
|
12
|
+
//
|
|
13
|
+
// Bump this when the SDK starts using a feature that requires a specific
|
|
14
|
+
// backend version (e.g. a new endpoint added in API minor X.Y.0 — the
|
|
15
|
+
// SDK that wraps it sets MIN_API_VERSION to X.Y.0). Within a major
|
|
16
|
+
// version (1.x), the API stays additive (oasdiff
|
|
17
|
+
// `--deprecation-days-stable 30` enforced in CI), so a 1.0.0 SDK keeps
|
|
18
|
+
// working against any 1.x backend without raising the floor.
|
|
19
|
+
export const MIN_API_VERSION = '1.0.0';
|
|
20
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,yEAAyE;AACzE,wEAAwE;AACxE,oEAAoE;AACpE,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAA;AAElC,mEAAmE;AACnE,uEAAuE;AACvE,kEAAkE;AAClE,wEAAwE;AACxE,kEAAkE;AAClE,sEAAsE;AACtE,EAAE;AACF,yEAAyE;AACzE,sEAAsE;AACtE,mEAAmE;AACnE,iDAAiD;AACjD,uEAAuE;AACvE,6DAA6D;AAC7D,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { WebhookEventBase } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parse a raw webhook delivery body into a typed envelope. Throws
|
|
4
|
+
* `WebhookSignatureError` if the body is not valid JSON or doesn't carry
|
|
5
|
+
* the §4.1 envelope shape (`event_id`, `event_type`, `data`). Use
|
|
6
|
+
* `verifyWebhook` for the full HMAC + replay-window verification — this
|
|
7
|
+
* is the parsing-only half for cases where verification happened
|
|
8
|
+
* out-of-band (e.g. behind a trusted gateway).
|
|
9
|
+
*
|
|
10
|
+
* **Consumers MUST dedupe by `event.event_id`** — webhook delivery is
|
|
11
|
+
* at-least-once, so retries replay the same envelope. Without dedup,
|
|
12
|
+
* processing the same event twice produces duplicate side-effects.
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseWebhookEvent(rawBody: string): WebhookEventBase;
|
|
15
|
+
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/webhooks/parse.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAiCnE"}
|