@isnap/sdk 0.1.0 → 1.1.0-next.38

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.
Files changed (104) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +173 -167
  3. package/dist/client.d.ts +48 -50
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/client.js +258 -89
  6. package/dist/client.js.map +1 -1
  7. package/dist/config.d.ts +43 -0
  8. package/dist/config.d.ts.map +1 -0
  9. package/dist/config.js +55 -0
  10. package/dist/config.js.map +1 -0
  11. package/dist/errors.d.ts +53 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +100 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/generated/openapi.d.ts +10924 -0
  16. package/dist/idempotency.d.ts +2 -0
  17. package/dist/idempotency.d.ts.map +1 -0
  18. package/dist/idempotency.js +4 -0
  19. package/dist/idempotency.js.map +1 -0
  20. package/dist/index.d.ts +26 -8
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +12 -6
  23. package/dist/index.js.map +1 -1
  24. package/dist/internal/sleep.d.ts +10 -0
  25. package/dist/internal/sleep.d.ts.map +1 -0
  26. package/dist/internal/sleep.js +37 -0
  27. package/dist/internal/sleep.js.map +1 -0
  28. package/dist/pagination.d.ts +10 -0
  29. package/dist/pagination.d.ts.map +1 -0
  30. package/dist/pagination.js +16 -0
  31. package/dist/pagination.js.map +1 -0
  32. package/dist/resources/attachments.d.ts +45 -0
  33. package/dist/resources/attachments.d.ts.map +1 -0
  34. package/dist/resources/attachments.js +120 -0
  35. package/dist/resources/attachments.js.map +1 -0
  36. package/dist/resources/base.d.ts +6 -0
  37. package/dist/resources/base.d.ts.map +1 -0
  38. package/dist/resources/base.js +7 -0
  39. package/dist/resources/base.js.map +1 -0
  40. package/dist/resources/byod.d.ts +15 -0
  41. package/dist/resources/byod.d.ts.map +1 -0
  42. package/dist/resources/byod.js +13 -0
  43. package/dist/resources/byod.js.map +1 -0
  44. package/dist/resources/chats.d.ts +29 -0
  45. package/dist/resources/chats.d.ts.map +1 -0
  46. package/dist/resources/chats.js +28 -0
  47. package/dist/resources/chats.js.map +1 -0
  48. package/dist/resources/lines.d.ts +64 -27
  49. package/dist/resources/lines.d.ts.map +1 -1
  50. package/dist/resources/lines.js +77 -37
  51. package/dist/resources/lines.js.map +1 -1
  52. package/dist/resources/lookup.d.ts +15 -0
  53. package/dist/resources/lookup.d.ts.map +1 -0
  54. package/dist/resources/lookup.js +13 -0
  55. package/dist/resources/lookup.js.map +1 -0
  56. package/dist/resources/messages.d.ts +36 -67
  57. package/dist/resources/messages.d.ts.map +1 -1
  58. package/dist/resources/messages.js +37 -94
  59. package/dist/resources/messages.js.map +1 -1
  60. package/dist/resources/trial.d.ts +28 -0
  61. package/dist/resources/trial.d.ts.map +1 -0
  62. package/dist/resources/trial.js +31 -0
  63. package/dist/resources/trial.js.map +1 -0
  64. package/dist/resources/webhooks.d.ts +49 -39
  65. package/dist/resources/webhooks.d.ts.map +1 -1
  66. package/dist/resources/webhooks.js +52 -39
  67. package/dist/resources/webhooks.js.map +1 -1
  68. package/dist/retry.d.ts +14 -0
  69. package/dist/retry.d.ts.map +1 -0
  70. package/dist/retry.js +47 -0
  71. package/dist/retry.js.map +1 -0
  72. package/dist/types.d.ts +30 -196
  73. package/dist/types.d.ts.map +1 -1
  74. package/dist/types.js +1 -28
  75. package/dist/types.js.map +1 -1
  76. package/dist/version.d.ts +3 -0
  77. package/dist/version.d.ts.map +1 -0
  78. package/dist/version.js +20 -0
  79. package/dist/version.js.map +1 -0
  80. package/dist/webhooks/parse.d.ts +15 -0
  81. package/dist/webhooks/parse.d.ts.map +1 -0
  82. package/dist/webhooks/parse.js +47 -0
  83. package/dist/webhooks/parse.js.map +1 -0
  84. package/dist/webhooks/types.d.ts +93 -0
  85. package/dist/webhooks/types.d.ts.map +1 -0
  86. package/dist/webhooks/types.js +20 -0
  87. package/dist/webhooks/types.js.map +1 -0
  88. package/dist/webhooks/verify.d.ts +41 -0
  89. package/dist/webhooks/verify.d.ts.map +1 -0
  90. package/dist/webhooks/verify.js +110 -0
  91. package/dist/webhooks/verify.js.map +1 -0
  92. package/package.json +45 -30
  93. package/dist/paginate.d.ts +0 -33
  94. package/dist/paginate.d.ts.map +0 -1
  95. package/dist/paginate.js +0 -40
  96. package/dist/paginate.js.map +0 -1
  97. package/dist/webhook-events.d.ts +0 -61
  98. package/dist/webhook-events.d.ts.map +0 -1
  99. package/dist/webhook-events.js +0 -44
  100. package/dist/webhook-events.js.map +0 -1
  101. package/dist/webhook-verify.d.ts +0 -27
  102. package/dist/webhook-verify.d.ts.map +0 -1
  103. package/dist/webhook-verify.js +0 -42
  104. package/dist/webhook-verify.js.map +0 -1
package/dist/client.js CHANGED
@@ -1,115 +1,284 @@
1
- import { iSnapError, RateLimitError } from './types.js';
2
- import { MessagesResource } from './resources/messages.js';
1
+ import { resolveConfig, validateMaxRetries } from './config.js';
2
+ import { APIConnectionError, APIError, ServiceUnavailableError, fromEnvelope } from './errors.js';
3
+ import { generateIdempotencyKey } from './idempotency.js';
4
+ import { AttachmentsResource } from './resources/attachments.js';
5
+ import { ByodResource } from './resources/byod.js';
6
+ import { ChatsResource } from './resources/chats.js';
3
7
  import { LinesResource } from './resources/lines.js';
8
+ import { LookupResource } from './resources/lookup.js';
9
+ import { MessagesResource } from './resources/messages.js';
10
+ import { TrialResource } from './resources/trial.js';
4
11
  import { WebhooksResource } from './resources/webhooks.js';
12
+ import { withRetries } from './retry.js';
13
+ import { SDK_VERSION } from './version.js';
14
+ const MUTATING = new Set(['POST', 'PATCH', 'PUT', 'DELETE']);
15
+ const NON_JSON_PREVIEW = 200;
16
+ // Hard cap on response body size. Server-side limits are stricter in
17
+ // practice; this is defense-in-depth against a misbehaving proxy or test
18
+ // harness streaming an unbounded body.
19
+ const MAX_RESPONSE_BYTES = 10 * 1024 * 1024;
20
+ const USER_AGENT = `@isnap/sdk/${SDK_VERSION}`;
21
+ // Per-process dedup set for deprecation warnings. Key is
22
+ // `<METHOD> <pathname>|<sunset>` — including the sunset means we re-warn
23
+ // if the backend extends or moves the deadline. Process-wide (not
24
+ // per-client-instance) so spawning multiple ISnapClient objects in tests
25
+ // doesn't multiply the noise.
26
+ const WARNED_DEPRECATIONS = new Set();
5
27
  /**
6
- * The iSnap SDK client. Provides access to all API resources.
28
+ * Test-only escape hatch to clear the per-process dedup set between test
29
+ * cases. Not part of the public stability contract — flagged @internal so
30
+ * IDE auto-import doesn't surface it to consumers.
7
31
  *
8
- * @example
9
- * ```ts
10
- * import { init } from '@isnap/sdk';
11
- *
12
- * const client = init({ apiKey: 'isnap_your_key' });
13
- * const msg = await client.messages.send({ line_id: 'ln-1', to: '+15551234567', body: 'Hello' });
14
- * ```
32
+ * @internal
15
33
  */
16
- export class iSnapClient {
17
- apiKey;
18
- baseUrl;
19
- maxRetries;
20
- retryDelayMs;
21
- /** Message sending, retrieval, and conversation management. */
22
- messages;
23
- /** Phone line listing and lookup. */
34
+ export function _resetDeprecationWarnings() {
35
+ WARNED_DEPRECATIONS.clear();
36
+ }
37
+ export class ISnapClient {
38
+ config;
39
+ attachments;
40
+ byod;
41
+ chats;
24
42
  lines;
25
- /** Webhook endpoint management. */
43
+ lookup;
44
+ messages;
45
+ trial;
26
46
  webhooks;
27
47
  constructor(config) {
28
- this.apiKey = config.apiKey;
29
- this.baseUrl = (config.baseUrl ?? 'https://api.isnap.dev').replace(/\/$/, '');
30
- this.maxRetries = config.maxRetries ?? 3;
31
- this.retryDelayMs = config.retryDelayMs ?? 5000;
32
- this.messages = new MessagesResource(this);
48
+ this.config = resolveConfig(config);
49
+ this.attachments = new AttachmentsResource(this);
50
+ this.byod = new ByodResource(this);
51
+ this.chats = new ChatsResource(this);
33
52
  this.lines = new LinesResource(this);
53
+ this.lookup = new LookupResource(this);
54
+ this.messages = new MessagesResource(this);
55
+ this.trial = new TrialResource(this);
34
56
  this.webhooks = new WebhooksResource(this);
35
57
  }
36
58
  /**
37
- * Send an HTTP request to the iSnap API.
59
+ * Direct fetch with no SDK auth, no envelope parsing, no retry — used
60
+ * internally by resource methods that must call URLs OUTSIDE the iSnap
61
+ * API surface (e.g. presigned R2 PUTs during `attachments.upload`).
62
+ *
63
+ * The leading underscore signals "internal but unavoidably public": it
64
+ * lives on the public class because resource classes cannot reach the
65
+ * private `config.fetch` otherwise. SDK consumers should use the typed
66
+ * resource methods or `request()` for everything in `/v1/*` — calling
67
+ * this directly bypasses the SDK contract.
38
68
  *
39
- * Handles authorization, JSON serialization, rate-limit retries, and error mapping.
69
+ * Applies the same `config.timeoutMs` ceiling as `request()` so a
70
+ * stalled R2 PUT cannot hang the upload indefinitely.
40
71
  *
41
- * @param method - HTTP method (GET, POST, DELETE, etc.)
42
- * @param path - API path (e.g. `/v1/messages`)
43
- * @param body - Optional request body (will be JSON-stringified)
44
- * @param query - Optional query parameters
45
- * @returns Parsed JSON response
46
- * @throws {iSnapError} On non-2xx responses
47
- * @throws {RateLimitError} When rate-limited after exhausting retries
72
+ * @internal
73
+ */
74
+ async _externalFetch(url, init = {}) {
75
+ const controller = new AbortController();
76
+ const timeoutId = setTimeout(() => controller.abort(), this.config.timeoutMs);
77
+ const callerSignal = init.signal;
78
+ let abortListener;
79
+ if (callerSignal) {
80
+ if (callerSignal.aborted)
81
+ controller.abort(callerSignal.reason);
82
+ else {
83
+ abortListener = () => controller.abort(callerSignal.reason);
84
+ callerSignal.addEventListener('abort', abortListener, { once: true });
85
+ }
86
+ }
87
+ try {
88
+ return await this.config.fetch(url, { ...init, signal: controller.signal });
89
+ }
90
+ finally {
91
+ clearTimeout(timeoutId);
92
+ if (abortListener)
93
+ callerSignal?.removeEventListener('abort', abortListener);
94
+ }
95
+ }
96
+ /**
97
+ * Low-level request method. Resource classes wrap this with typed
98
+ * camelCase signatures; advanced users can call it directly for
99
+ * endpoints not yet covered by a resource.
48
100
  */
49
- async request(method, path, body, query) {
50
- let url = `${this.baseUrl}${path}`;
101
+ async request(method, path, body, opts = {}) {
102
+ const url = this.buildUrl(path, opts.query);
103
+ const idempotencyKey = opts.idempotencyKey ??
104
+ (this.config.idempotencyKey === 'auto' && MUTATING.has(method)
105
+ ? generateIdempotencyKey()
106
+ : undefined);
107
+ const headers = this.buildHeaders(idempotencyKey, body !== undefined, opts.headers);
108
+ const init = {
109
+ method,
110
+ headers,
111
+ body: body !== undefined ? JSON.stringify(body) : undefined
112
+ };
113
+ const maxRetries = opts.maxRetries !== undefined ? validateMaxRetries(opts.maxRetries) : this.config.maxRetries;
114
+ return withRetries(() => this.dispatch(url, init, opts), {
115
+ maxRetries,
116
+ onRetry: this.config.onRetry,
117
+ signal: opts.signal
118
+ });
119
+ }
120
+ async dispatch(url, init, opts) {
121
+ const controller = new AbortController();
122
+ const timeoutId = setTimeout(() => controller.abort(), this.config.timeoutMs);
123
+ // Track the abort listener so we can detach it in `finally`. Without
124
+ // detachment, a long-lived caller signal (e.g. a Node process-wide
125
+ // shutdown signal) accumulates one closure per request — leaking the
126
+ // per-attempt AbortController, the caller's `opts`, and any captured
127
+ // closure state until the signal eventually fires. Detaching at the
128
+ // end of the dispatch resolves the leak immediately.
129
+ const callerSignal = opts.signal;
130
+ let abortListener;
131
+ if (callerSignal) {
132
+ if (callerSignal.aborted)
133
+ controller.abort(callerSignal.reason);
134
+ else {
135
+ abortListener = () => controller.abort(callerSignal.reason);
136
+ callerSignal.addEventListener('abort', abortListener, { once: true });
137
+ }
138
+ }
139
+ let response;
140
+ try {
141
+ response = await this.config.fetch(url, { ...init, signal: controller.signal });
142
+ }
143
+ catch (err) {
144
+ throw new APIConnectionError(this.connectionErrorMessage(err), { cause: err });
145
+ }
146
+ finally {
147
+ clearTimeout(timeoutId);
148
+ if (abortListener)
149
+ callerSignal?.removeEventListener('abort', abortListener);
150
+ }
151
+ // Surface RFC 9745 / RFC 8594 deprecation signals once per (route ×
152
+ // sunset) per process. Runs before status-based branches so a 410 Gone
153
+ // response (which throws below) still emits the warning.
154
+ this.warnIfDeprecated(url, init.method ?? 'GET', response.headers);
155
+ if (response.status === 204) {
156
+ return undefined;
157
+ }
158
+ const headerTrace = response.headers.get('x-trace-id') ?? '';
159
+ const headerRequest = response.headers.get('x-request-id') ?? '';
160
+ const declaredLength = response.headers.get('content-length');
161
+ if (declaredLength) {
162
+ const n = Number.parseInt(declaredLength, 10);
163
+ if (Number.isFinite(n) && n > MAX_RESPONSE_BYTES) {
164
+ throw new APIError({
165
+ status: response.status,
166
+ code: 'response_too_large',
167
+ message: `Response body exceeds ${MAX_RESPONSE_BYTES} bytes (Content-Length: ${n})`,
168
+ traceId: headerTrace,
169
+ requestId: headerRequest
170
+ });
171
+ }
172
+ }
173
+ const text = await response.text();
174
+ const payload = (() => {
175
+ if (!text)
176
+ return null;
177
+ try {
178
+ return JSON.parse(text);
179
+ }
180
+ catch {
181
+ return null;
182
+ }
183
+ })();
184
+ if (!payload) {
185
+ const message = `Server returned non-JSON response (HTTP ${response.status})${text ? `: ${text.slice(0, NON_JSON_PREVIEW)}` : ''}`;
186
+ // 5xx without an envelope is still transient infra (Cloudflare HTML, LB
187
+ // 502 page) — surface as ServiceUnavailableError so the retry loop
188
+ // kicks in. 4xx without an envelope is a misbehaving proxy; surface
189
+ // immediately as base APIError so the caller sees the raw response.
190
+ if (response.status >= 500) {
191
+ throw new ServiceUnavailableError({
192
+ status: response.status,
193
+ code: 'invalid_response',
194
+ message,
195
+ traceId: headerTrace,
196
+ requestId: headerRequest
197
+ });
198
+ }
199
+ throw new APIError({
200
+ status: response.status,
201
+ code: 'invalid_response',
202
+ message,
203
+ traceId: headerTrace,
204
+ requestId: headerRequest
205
+ });
206
+ }
207
+ const traceId = payload.trace_id ?? headerTrace;
208
+ const requestId = payload.request_id ?? headerRequest;
209
+ if (!response.ok || payload.success === false || payload.error) {
210
+ const envelope = payload.error ?? {
211
+ status: response.status,
212
+ code: 'unknown_error',
213
+ message: `HTTP ${response.status} (no error envelope)`
214
+ };
215
+ throw fromEnvelope(envelope, traceId, requestId);
216
+ }
217
+ return payload.data;
218
+ }
219
+ buildUrl(path, query) {
220
+ const fullPath = path.startsWith('/') ? path : `/${path}`;
221
+ let url = this.config.baseUrl + fullPath;
51
222
  if (query) {
52
223
  const params = new URLSearchParams();
53
224
  for (const [key, value] of Object.entries(query)) {
54
- if (value !== undefined && value !== '')
55
- params.set(key, value);
225
+ if (value === undefined || value === null)
226
+ continue;
227
+ params.append(key, String(value));
56
228
  }
57
229
  const qs = params.toString();
58
230
  if (qs)
59
- url += `?${qs}`;
231
+ url += (url.includes('?') ? '&' : '?') + qs;
60
232
  }
61
- const headers = {
62
- Authorization: this.apiKey,
63
- };
64
- if (body !== undefined) {
65
- headers['Content-Type'] = 'application/json';
66
- }
67
- for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
68
- const res = await fetch(url, {
69
- method,
70
- headers,
71
- body: body ? JSON.stringify(body) : undefined,
72
- });
73
- if (res.status === 429) {
74
- const retryAfterHeader = res.headers.get('Retry-After');
75
- const retryAfter = retryAfterHeader !== null
76
- ? parseInt(retryAfterHeader, 10)
77
- : this.retryDelayMs / 1000;
78
- if (attempt < this.maxRetries) {
79
- await new Promise((resolve) => setTimeout(resolve, retryAfter * 1000));
80
- continue;
81
- }
82
- throw new RateLimitError(`Rate limit exceeded`, retryAfter);
83
- }
84
- if (!res.ok) {
85
- const err = await res.json().catch(() => ({ message: `HTTP ${res.status}` }));
86
- throw new iSnapError(err.message || `HTTP ${res.status}`, res.status, err.code);
87
- }
88
- if (res.status === 204)
89
- return undefined;
90
- return res.json();
233
+ return url;
234
+ }
235
+ buildHeaders(idempotencyKey, hasBody, custom) {
236
+ const headers = new Headers();
237
+ // Defaults set first so caller-supplied headers can override them.
238
+ headers.set('User-Agent', USER_AGENT);
239
+ headers.set('Accept', 'application/json');
240
+ if (hasBody)
241
+ headers.set('Content-Type', 'application/json');
242
+ if (custom) {
243
+ const merged = new Headers(custom);
244
+ merged.forEach((value, key) => headers.set(key, value));
91
245
  }
92
- throw new iSnapError('Max retries exceeded', 429);
246
+ // Locked headers set last so caller-supplied custom values cannot
247
+ // override the SDK-managed authentication or idempotency contract.
248
+ headers.set('Authorization', `Bearer ${this.config.apiKey}`);
249
+ if (idempotencyKey)
250
+ headers.set('Idempotency-Key', idempotencyKey);
251
+ return headers;
252
+ }
253
+ warnIfDeprecated(url, method, headers) {
254
+ const deprecation = headers.get('Deprecation');
255
+ if (!deprecation || deprecation === 'false')
256
+ return;
257
+ const sunset = headers.get('Sunset');
258
+ let pathname;
259
+ try {
260
+ pathname = new URL(url).pathname;
261
+ }
262
+ catch {
263
+ pathname = url;
264
+ }
265
+ const key = `${method.toUpperCase()} ${pathname}|${sunset ?? ''}`;
266
+ if (WARNED_DEPRECATIONS.has(key))
267
+ return;
268
+ WARNED_DEPRECATIONS.add(key);
269
+ const link = headers.get('Link');
270
+ const successor = link?.match(/<([^>]+)>;\s*rel="successor-version"/)?.[1];
271
+ const sunsetClause = sunset ? ` and will be removed on ${sunset}` : '';
272
+ const successorClause = successor ? ` Use ${successor} instead.` : '';
273
+ console.warn(`[@isnap/sdk] WARNING: ${method.toUpperCase()} ${pathname} is deprecated${sunsetClause}.${successorClause} (RFC 9745)`);
274
+ }
275
+ connectionErrorMessage(err) {
276
+ if (err instanceof DOMException && err.name === 'AbortError') {
277
+ return `Request aborted after ${this.config.timeoutMs}ms`;
278
+ }
279
+ if (err instanceof Error)
280
+ return `Network error: ${err.message}`;
281
+ return 'Network error';
93
282
  }
94
- }
95
- /**
96
- * Create a new iSnap SDK client.
97
- *
98
- * @param config - API key and optional settings
99
- * @returns A configured {@link iSnapClient} instance
100
- *
101
- * @example
102
- * ```ts
103
- * import { init } from '@isnap/sdk';
104
- *
105
- * const client = init({
106
- * apiKey: 'isnap_your_key',
107
- * maxRetries: 5,
108
- * retryDelayMs: 2000,
109
- * });
110
- * ```
111
- */
112
- export function init(config) {
113
- return new iSnapClient(config);
114
283
  }
115
284
  //# sourceMappingURL=client.js.map
@@ -1 +1 @@
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AAE,IAAI,QAAQ,IAAI,MAAM,IAAI,EAAE,EAAE,CAAA;QACjE,IAAI,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,OAAM;QACxC,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC5B,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QAChC,MAAM,SAAS,GAAG,IAAI,EAAE,KAAK,CAAC,sCAAsC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAC1E,MAAM,YAAY,GAAG,MAAM,CAAC,CAAC,CAAC,2BAA2B,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;QACtE,MAAM,eAAe,GAAG,SAAS,CAAC,CAAC,CAAC,QAAQ,SAAS,WAAW,CAAC,CAAC,CAAC,EAAE,CAAA;QACrE,OAAO,CAAC,IAAI,CACV,yBAAyB,MAAM,CAAC,WAAW,EAAE,IAAI,QAAQ,iBAAiB,YAAY,IAAI,eAAe,aAAa,CACvH,CAAA;IACH,CAAC;IAEO,sBAAsB,CAAC,GAAY;QACzC,IAAI,GAAG,YAAY,YAAY,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YAC7D,OAAO,yBAAyB,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,CAAA;QAC3D,CAAC;QACD,IAAI,GAAG,YAAY,KAAK;YAAE,OAAO,kBAAkB,GAAG,CAAC,OAAO,EAAE,CAAA;QAChE,OAAO,eAAe,CAAA;IACxB,CAAC;CACF"}
@@ -0,0 +1,43 @@
1
+ import type { RetryInfo } from './retry.js';
2
+ export interface ClientConfig {
3
+ apiKey: string;
4
+ baseUrl?: string;
5
+ maxRetries?: number;
6
+ timeoutMs?: number;
7
+ idempotencyKey?: 'auto' | 'manual';
8
+ fetch?: typeof fetch;
9
+ onRetry?: (info: RetryInfo) => void;
10
+ }
11
+ export interface ResolvedConfig {
12
+ apiKey: string;
13
+ baseUrl: string;
14
+ maxRetries: number;
15
+ timeoutMs: number;
16
+ idempotencyKey: 'auto' | 'manual';
17
+ fetch: typeof fetch;
18
+ onRetry?: (info: RetryInfo) => void;
19
+ }
20
+ export declare const DEFAULTS: {
21
+ baseUrl: string;
22
+ maxRetries: number;
23
+ timeoutMs: number;
24
+ idempotencyKey: "auto";
25
+ };
26
+ export declare function resolveConfig(config: ClientConfig): ResolvedConfig;
27
+ /**
28
+ * Validate `maxRetries` — must be a non-negative integer. NaN, negatives,
29
+ * or non-integers (e.g. `Infinity`, `2.5`) would silently break the
30
+ * `for (let attempt = 0; attempt <= config.maxRetries; attempt++)` loop in
31
+ * `withRetries` and produce confusing failure modes (zero attempts, or
32
+ * fractional comparisons). Validate at the boundary so the error surfaces
33
+ * at construction, not on the first request. Exported for reuse from
34
+ * per-call `RequestOptions.maxRetries` overrides.
35
+ */
36
+ export declare function validateMaxRetries(value: number | undefined): number;
37
+ /**
38
+ * Validate `timeoutMs` — must be a finite positive number. NaN, zero,
39
+ * negative, or `Infinity` would either abort every request immediately or
40
+ * never time out at all.
41
+ */
42
+ export declare function validateTimeoutMs(value: number | undefined): number;
43
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAE3C,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,cAAc,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAA;IAClC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;IACpB,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAA;CACpC;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,cAAc,EAAE,MAAM,GAAG,QAAQ,CAAA;IACjC,KAAK,EAAE,OAAO,KAAK,CAAA;IACnB,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAA;CACpC;AAED,eAAO,MAAM,QAAQ;;;;;CAKpB,CAAA;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,cAAc,CAiBlE;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAQpE;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAQnE"}
package/dist/config.js ADDED
@@ -0,0 +1,55 @@
1
+ export const DEFAULTS = {
2
+ baseUrl: 'https://api.isnap.ai',
3
+ maxRetries: 3,
4
+ timeoutMs: 30_000,
5
+ idempotencyKey: 'auto'
6
+ };
7
+ export function resolveConfig(config) {
8
+ if (!config || typeof config.apiKey !== 'string') {
9
+ throw new Error('iSnap SDK: apiKey is required');
10
+ }
11
+ const apiKey = config.apiKey.trim();
12
+ if (apiKey.length === 0) {
13
+ throw new Error('iSnap SDK: apiKey cannot be empty or whitespace');
14
+ }
15
+ return {
16
+ apiKey,
17
+ baseUrl: (config.baseUrl ?? DEFAULTS.baseUrl).replace(/\/+$/, ''),
18
+ maxRetries: validateMaxRetries(config.maxRetries),
19
+ timeoutMs: validateTimeoutMs(config.timeoutMs),
20
+ idempotencyKey: config.idempotencyKey ?? DEFAULTS.idempotencyKey,
21
+ fetch: config.fetch ?? fetch,
22
+ onRetry: config.onRetry
23
+ };
24
+ }
25
+ /**
26
+ * Validate `maxRetries` — must be a non-negative integer. NaN, negatives,
27
+ * or non-integers (e.g. `Infinity`, `2.5`) would silently break the
28
+ * `for (let attempt = 0; attempt <= config.maxRetries; attempt++)` loop in
29
+ * `withRetries` and produce confusing failure modes (zero attempts, or
30
+ * fractional comparisons). Validate at the boundary so the error surfaces
31
+ * at construction, not on the first request. Exported for reuse from
32
+ * per-call `RequestOptions.maxRetries` overrides.
33
+ */
34
+ export function validateMaxRetries(value) {
35
+ if (value === undefined)
36
+ return DEFAULTS.maxRetries;
37
+ if (!Number.isInteger(value) || value < 0) {
38
+ throw new Error(`iSnap SDK: maxRetries must be a non-negative integer (got ${String(value)})`);
39
+ }
40
+ return value;
41
+ }
42
+ /**
43
+ * Validate `timeoutMs` — must be a finite positive number. NaN, zero,
44
+ * negative, or `Infinity` would either abort every request immediately or
45
+ * never time out at all.
46
+ */
47
+ export function validateTimeoutMs(value) {
48
+ if (value === undefined)
49
+ return DEFAULTS.timeoutMs;
50
+ if (!Number.isFinite(value) || value <= 0) {
51
+ throw new Error(`iSnap SDK: timeoutMs must be a finite positive number (got ${String(value)})`);
52
+ }
53
+ return value;
54
+ }
55
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAsBA,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,OAAO,EAAE,sBAAsB;IAC/B,UAAU,EAAE,CAAC;IACb,SAAS,EAAE,MAAM;IACjB,cAAc,EAAE,MAAe;CAChC,CAAA;AAED,MAAM,UAAU,aAAa,CAAC,MAAoB;IAChD,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QACjD,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAA;IAClD,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAA;IACnC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAA;IACpE,CAAC;IACD,OAAO;QACL,MAAM;QACN,OAAO,EAAE,CAAC,MAAM,CAAC,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;QACjE,UAAU,EAAE,kBAAkB,CAAC,MAAM,CAAC,UAAU,CAAC;QACjD,SAAS,EAAE,iBAAiB,CAAC,MAAM,CAAC,SAAS,CAAC;QAC9C,cAAc,EAAE,MAAM,CAAC,cAAc,IAAI,QAAQ,CAAC,cAAc;QAChE,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,KAAK;QAC5B,OAAO,EAAE,MAAM,CAAC,OAAO;KACxB,CAAA;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAyB;IAC1D,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC,UAAU,CAAA;IACnD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CACb,6DAA6D,MAAM,CAAC,KAAK,CAAC,GAAG,CAC9E,CAAA;IACH,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAyB;IACzD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC,SAAS,CAAA;IAClD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CACb,8DAA8D,MAAM,CAAC,KAAK,CAAC,GAAG,CAC/E,CAAA;IACH,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -0,0 +1,53 @@
1
+ import type { ErrorEnvelope, ErrorIssue } from './types.js';
2
+ export interface APIErrorMeta {
3
+ status: number;
4
+ code: string;
5
+ message: string;
6
+ traceId: string;
7
+ requestId: string;
8
+ retryAfter?: number;
9
+ issues?: ErrorIssue[];
10
+ }
11
+ export declare class APIError extends Error {
12
+ readonly status: number;
13
+ readonly code: string;
14
+ readonly traceId: string;
15
+ readonly requestId: string;
16
+ readonly retryAfter?: number;
17
+ readonly issues?: ErrorIssue[];
18
+ constructor(meta: APIErrorMeta);
19
+ }
20
+ export declare class BadRequestError extends APIError {
21
+ }
22
+ export declare class AuthenticationError extends APIError {
23
+ }
24
+ export declare class PaymentRequiredError extends APIError {
25
+ }
26
+ export declare class PermissionDeniedError extends APIError {
27
+ }
28
+ export declare class NotFoundError extends APIError {
29
+ }
30
+ export declare class ConflictError extends APIError {
31
+ }
32
+ export declare class GoneError extends APIError {
33
+ }
34
+ export declare class UnprocessableEntityError extends APIError {
35
+ }
36
+ export declare class RateLimitError extends APIError {
37
+ }
38
+ export declare class QuotaExceededError extends APIError {
39
+ }
40
+ export declare class InternalServerError extends APIError {
41
+ }
42
+ export declare class ServiceUnavailableError extends APIError {
43
+ }
44
+ export declare class APIConnectionError extends Error {
45
+ constructor(message: string, options?: {
46
+ cause?: unknown;
47
+ });
48
+ }
49
+ export declare class WebhookSignatureError extends Error {
50
+ constructor(message: string);
51
+ }
52
+ export declare function fromEnvelope(envelope: ErrorEnvelope, traceId: string, requestId: string): APIError;
53
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE3D,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAA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