smswire 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.
- package/LICENSE +21 -0
- package/README.md +115 -2
- package/dist/index.cjs +309 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +819 -0
- package/dist/index.d.ts +819 -0
- package/dist/index.js +277 -0
- package/dist/index.js.map +1 -0
- package/package.json +34 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,819 @@
|
|
|
1
|
+
/** A request that failed: the API's answer (status, code, message) or a network problem (status null). */
|
|
2
|
+
declare class SMSWireError extends Error {
|
|
3
|
+
/** HTTP status, or null when no answer arrived. */
|
|
4
|
+
readonly status: number | null;
|
|
5
|
+
/** Stable machine code, e.g. `invalid_request`, `rate_limited`, `network_error`, `timeout`. */
|
|
6
|
+
readonly code: string;
|
|
7
|
+
/** Seconds until trying again makes sense (from Retry-After), when the API said. */
|
|
8
|
+
readonly retryAfter: number | null;
|
|
9
|
+
readonly name: string;
|
|
10
|
+
constructor(
|
|
11
|
+
/** HTTP status, or null when no answer arrived. */
|
|
12
|
+
status: number | null,
|
|
13
|
+
/** Stable machine code, e.g. `invalid_request`, `rate_limited`, `network_error`, `timeout`. */
|
|
14
|
+
code: string, message: string,
|
|
15
|
+
/** Seconds until trying again makes sense (from Retry-After), when the API said. */
|
|
16
|
+
retryAfter?: number | null, options?: {
|
|
17
|
+
cause?: unknown;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/** A webhook whose signature is missing, wrong or too old. Answer it with 400. */
|
|
21
|
+
declare class SMSWireSignatureError extends Error {
|
|
22
|
+
readonly name = "SMSWireSignatureError";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface Request {
|
|
26
|
+
method: 'GET' | 'POST' | 'PATCH' | 'DELETE';
|
|
27
|
+
path: string;
|
|
28
|
+
query?: Record<string, unknown>;
|
|
29
|
+
body?: unknown;
|
|
30
|
+
headers?: Record<string, string>;
|
|
31
|
+
/** Safe to repeat after a 5xx or a dropped connection (GET, PATCH, DELETE, or a POST with an Idempotency-Key). */
|
|
32
|
+
idempotent: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface components {
|
|
36
|
+
schemas: {
|
|
37
|
+
AlertWebhookPayload: {
|
|
38
|
+
alert: {
|
|
39
|
+
created_at: string;
|
|
40
|
+
device: {
|
|
41
|
+
id: string;
|
|
42
|
+
name: string;
|
|
43
|
+
};
|
|
44
|
+
id: string;
|
|
45
|
+
kind: string;
|
|
46
|
+
message: string;
|
|
47
|
+
resolved_at?: string | null;
|
|
48
|
+
};
|
|
49
|
+
/** @enum {string} */
|
|
50
|
+
event: "alert.raised" | "alert.resolved" | "alert.test";
|
|
51
|
+
};
|
|
52
|
+
BulkItem: {
|
|
53
|
+
body?: string | null;
|
|
54
|
+
metadata?: components["schemas"]["Metadata"] | null;
|
|
55
|
+
tags?: components["schemas"]["Tags"] | null;
|
|
56
|
+
to: string;
|
|
57
|
+
type?: components["schemas"]["MessageType"] | null;
|
|
58
|
+
variables?: components["schemas"]["Variables"] | null;
|
|
59
|
+
};
|
|
60
|
+
BulkSendRequest: {
|
|
61
|
+
body?: string | null;
|
|
62
|
+
messages: components["schemas"]["BulkItem"][];
|
|
63
|
+
metadata?: components["schemas"]["Metadata"] | null;
|
|
64
|
+
name?: string | null;
|
|
65
|
+
rate?: number | null;
|
|
66
|
+
send_at?: string | null;
|
|
67
|
+
sim?: number | null;
|
|
68
|
+
tags?: components["schemas"]["Tags"] | null;
|
|
69
|
+
template?: string | null;
|
|
70
|
+
type?: components["schemas"]["MessageType"] | null;
|
|
71
|
+
};
|
|
72
|
+
BulkSendResponse: {
|
|
73
|
+
accepted: number;
|
|
74
|
+
batch_id: string;
|
|
75
|
+
/** @default [] */
|
|
76
|
+
rejected: components["schemas"]["RejectedItem"][];
|
|
77
|
+
};
|
|
78
|
+
Error: {
|
|
79
|
+
error: string;
|
|
80
|
+
message: string;
|
|
81
|
+
};
|
|
82
|
+
InboundWebhookPayload: {
|
|
83
|
+
body: string;
|
|
84
|
+
/** @constant */
|
|
85
|
+
event: "message.received";
|
|
86
|
+
from: string;
|
|
87
|
+
id: string;
|
|
88
|
+
project_id?: string | null;
|
|
89
|
+
received_at: string;
|
|
90
|
+
sim?: number | null;
|
|
91
|
+
};
|
|
92
|
+
MessagePage: {
|
|
93
|
+
data: components["schemas"]["MessageView"][];
|
|
94
|
+
next_cursor?: string | null;
|
|
95
|
+
};
|
|
96
|
+
/** @enum {string} */
|
|
97
|
+
MessageStatus: "queued" | "sending" | "sent" | "delivered" | "failed" | "cancelled";
|
|
98
|
+
/** @enum {string} */
|
|
99
|
+
MessageType: "otp" | "transactional" | "notification" | "marketing";
|
|
100
|
+
MessageView: {
|
|
101
|
+
batch_id?: string | null;
|
|
102
|
+
delivered_at?: string | null;
|
|
103
|
+
error?: string | null;
|
|
104
|
+
id: string;
|
|
105
|
+
metadata?: {
|
|
106
|
+
[key: string]: unknown;
|
|
107
|
+
} | null;
|
|
108
|
+
received_at: string;
|
|
109
|
+
redacted?: boolean;
|
|
110
|
+
scheduled_at?: string | null;
|
|
111
|
+
segments: number;
|
|
112
|
+
sent_at?: string | null;
|
|
113
|
+
status: components["schemas"]["MessageStatus"];
|
|
114
|
+
/** @default [] */
|
|
115
|
+
tags: string[];
|
|
116
|
+
to: string;
|
|
117
|
+
/** @default transactional */
|
|
118
|
+
type: components["schemas"]["MessageType"];
|
|
119
|
+
};
|
|
120
|
+
Metadata: {
|
|
121
|
+
[key: string]: unknown;
|
|
122
|
+
};
|
|
123
|
+
/** @enum {string} */
|
|
124
|
+
OtpFailure: "invalid" | "expired" | "too_many_attempts" | "already_used";
|
|
125
|
+
OtpRequest: {
|
|
126
|
+
body?: string | null;
|
|
127
|
+
/** @default 6 */
|
|
128
|
+
length?: number;
|
|
129
|
+
sim?: number | null;
|
|
130
|
+
template?: string | null;
|
|
131
|
+
to: string;
|
|
132
|
+
/** @default 300 */
|
|
133
|
+
ttl?: number;
|
|
134
|
+
};
|
|
135
|
+
OtpResponse: {
|
|
136
|
+
expires_at: string;
|
|
137
|
+
id: string;
|
|
138
|
+
message_id: string;
|
|
139
|
+
to: string;
|
|
140
|
+
};
|
|
141
|
+
OtpVerifyRequest: {
|
|
142
|
+
code: string;
|
|
143
|
+
id: string;
|
|
144
|
+
};
|
|
145
|
+
OtpVerifyResponse: {
|
|
146
|
+
reason?: components["schemas"]["OtpFailure"] | null;
|
|
147
|
+
valid: boolean;
|
|
148
|
+
};
|
|
149
|
+
RejectedItem: {
|
|
150
|
+
index: number;
|
|
151
|
+
reason: string;
|
|
152
|
+
to: string;
|
|
153
|
+
};
|
|
154
|
+
SchedulePage: {
|
|
155
|
+
data: components["schemas"]["ScheduleView"][];
|
|
156
|
+
};
|
|
157
|
+
ScheduleRecipient: {
|
|
158
|
+
to: string;
|
|
159
|
+
variables?: components["schemas"]["Variables"] | null;
|
|
160
|
+
};
|
|
161
|
+
ScheduleRequest: {
|
|
162
|
+
body?: string | null;
|
|
163
|
+
cron: string;
|
|
164
|
+
/** @default true */
|
|
165
|
+
enabled?: boolean;
|
|
166
|
+
ends_at?: string | null;
|
|
167
|
+
group_ids?: string[] | null;
|
|
168
|
+
max_runs?: number | null;
|
|
169
|
+
messages?: components["schemas"]["ScheduleRecipient"][] | null;
|
|
170
|
+
metadata?: components["schemas"]["Metadata"] | null;
|
|
171
|
+
name?: string | null;
|
|
172
|
+
rate?: number | null;
|
|
173
|
+
sim?: number | null;
|
|
174
|
+
tags?: components["schemas"]["Tags"] | null;
|
|
175
|
+
template?: string | null;
|
|
176
|
+
/** @default UTC */
|
|
177
|
+
timezone?: string;
|
|
178
|
+
to?: string | null;
|
|
179
|
+
type?: components["schemas"]["MessageType"] | null;
|
|
180
|
+
variables?: components["schemas"]["Variables"] | null;
|
|
181
|
+
};
|
|
182
|
+
ScheduleRunView: {
|
|
183
|
+
accepted: number;
|
|
184
|
+
at: string;
|
|
185
|
+
batch_id?: string | null;
|
|
186
|
+
error?: string | null;
|
|
187
|
+
message_id?: string | null;
|
|
188
|
+
rejected: number;
|
|
189
|
+
/** @enum {string} */
|
|
190
|
+
status: "sent" | "failed" | "skipped";
|
|
191
|
+
};
|
|
192
|
+
ScheduleUpdate: {
|
|
193
|
+
body?: string | null;
|
|
194
|
+
cron?: string | null;
|
|
195
|
+
enabled?: boolean | null;
|
|
196
|
+
ends_at?: string | null;
|
|
197
|
+
max_runs?: number | null;
|
|
198
|
+
name?: string | null;
|
|
199
|
+
template?: string | null;
|
|
200
|
+
timezone?: string | null;
|
|
201
|
+
type?: components["schemas"]["MessageType"] | null;
|
|
202
|
+
};
|
|
203
|
+
ScheduleView: {
|
|
204
|
+
body?: string | null;
|
|
205
|
+
created_at: string;
|
|
206
|
+
cron: string;
|
|
207
|
+
enabled: boolean;
|
|
208
|
+
ends_at?: string | null;
|
|
209
|
+
id: string;
|
|
210
|
+
last_run?: components["schemas"]["ScheduleRunView"] | null;
|
|
211
|
+
last_run_at?: string | null;
|
|
212
|
+
max_runs?: number | null;
|
|
213
|
+
name: string;
|
|
214
|
+
next_run_at?: string | null;
|
|
215
|
+
recipients: {
|
|
216
|
+
/** @default [] */
|
|
217
|
+
group_ids: string[];
|
|
218
|
+
numbers: number;
|
|
219
|
+
};
|
|
220
|
+
run_count: number;
|
|
221
|
+
runs?: components["schemas"]["ScheduleRunView"][] | null;
|
|
222
|
+
/** @default [] */
|
|
223
|
+
tags: string[];
|
|
224
|
+
template_id?: string | null;
|
|
225
|
+
timezone: string;
|
|
226
|
+
type?: components["schemas"]["MessageType"] | null;
|
|
227
|
+
};
|
|
228
|
+
SendMessageRequest: {
|
|
229
|
+
body?: string | null;
|
|
230
|
+
metadata?: components["schemas"]["Metadata"] | null;
|
|
231
|
+
send_at?: string | null;
|
|
232
|
+
sim?: number | null;
|
|
233
|
+
tags?: components["schemas"]["Tags"] | null;
|
|
234
|
+
template?: string | null;
|
|
235
|
+
to: string;
|
|
236
|
+
type?: components["schemas"]["MessageType"] | null;
|
|
237
|
+
variables?: components["schemas"]["Variables"] | null;
|
|
238
|
+
};
|
|
239
|
+
StatusWebhookPayload: {
|
|
240
|
+
batch_id?: string | null;
|
|
241
|
+
delivered_at?: string | null;
|
|
242
|
+
error?: string | null;
|
|
243
|
+
/**
|
|
244
|
+
* @default message.status
|
|
245
|
+
* @constant
|
|
246
|
+
*/
|
|
247
|
+
event: "message.status";
|
|
248
|
+
id: string;
|
|
249
|
+
metadata?: {
|
|
250
|
+
[key: string]: unknown;
|
|
251
|
+
} | null;
|
|
252
|
+
project_id?: string | null;
|
|
253
|
+
segments: number;
|
|
254
|
+
sent_at?: string | null;
|
|
255
|
+
status: components["schemas"]["MessageStatus"];
|
|
256
|
+
/** @default [] */
|
|
257
|
+
tags: string[];
|
|
258
|
+
to: string;
|
|
259
|
+
/** @default transactional */
|
|
260
|
+
type: components["schemas"]["MessageType"];
|
|
261
|
+
};
|
|
262
|
+
Tags: string[];
|
|
263
|
+
Variables: {
|
|
264
|
+
[key: string]: string | number | boolean;
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
responses: {
|
|
268
|
+
/** @description Invalid request (`invalid_request`, …). */
|
|
269
|
+
BadRequest: {
|
|
270
|
+
headers: {
|
|
271
|
+
[name: string]: unknown;
|
|
272
|
+
};
|
|
273
|
+
content: {
|
|
274
|
+
"application/json": components["schemas"]["Error"];
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
/** @description No such project, message or schedule. */
|
|
278
|
+
NotFound: {
|
|
279
|
+
headers: {
|
|
280
|
+
[name: string]: unknown;
|
|
281
|
+
};
|
|
282
|
+
content: {
|
|
283
|
+
"application/json": components["schemas"]["Error"];
|
|
284
|
+
};
|
|
285
|
+
};
|
|
286
|
+
/** @description `rate_limited`, `daily_limit_reached`, `monthly_limit_reached` or `too_many_otp_requests`. */
|
|
287
|
+
TooManyRequests: {
|
|
288
|
+
headers: {
|
|
289
|
+
/** @description Seconds until trying again makes sense. */
|
|
290
|
+
"Retry-After"?: number;
|
|
291
|
+
[name: string]: unknown;
|
|
292
|
+
};
|
|
293
|
+
content: {
|
|
294
|
+
"application/json": components["schemas"]["Error"];
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
/** @description Missing or wrong API key. */
|
|
298
|
+
Unauthorized: {
|
|
299
|
+
headers: {
|
|
300
|
+
[name: string]: unknown;
|
|
301
|
+
};
|
|
302
|
+
content: {
|
|
303
|
+
"application/json": components["schemas"]["Error"];
|
|
304
|
+
};
|
|
305
|
+
};
|
|
306
|
+
};
|
|
307
|
+
parameters: {
|
|
308
|
+
/** @description The project's slug. */
|
|
309
|
+
Project: string;
|
|
310
|
+
};
|
|
311
|
+
requestBodies: never;
|
|
312
|
+
headers: never;
|
|
313
|
+
pathItems: never;
|
|
314
|
+
}
|
|
315
|
+
interface operations {
|
|
316
|
+
listMessages: {
|
|
317
|
+
parameters: {
|
|
318
|
+
query?: {
|
|
319
|
+
/** @description Only this batch. */
|
|
320
|
+
batch_id?: string;
|
|
321
|
+
/** @description `next_cursor` from the previous page. */
|
|
322
|
+
cursor?: string;
|
|
323
|
+
/** @description Received at or after (ISO 8601). */
|
|
324
|
+
from?: string;
|
|
325
|
+
/** @description Page size. */
|
|
326
|
+
limit?: number;
|
|
327
|
+
/** @description Only this status. */
|
|
328
|
+
status?: components["schemas"]["MessageStatus"];
|
|
329
|
+
/** @description Only messages with this tag. */
|
|
330
|
+
tag?: string;
|
|
331
|
+
/** @description Recipient number, or part of it. */
|
|
332
|
+
to?: string;
|
|
333
|
+
/** @description Only this type. */
|
|
334
|
+
type?: components["schemas"]["MessageType"];
|
|
335
|
+
/** @description Received before (ISO 8601). */
|
|
336
|
+
until?: string;
|
|
337
|
+
};
|
|
338
|
+
header?: never;
|
|
339
|
+
path: {
|
|
340
|
+
/** @description The project's slug. */
|
|
341
|
+
project: components["parameters"]["Project"];
|
|
342
|
+
};
|
|
343
|
+
cookie?: never;
|
|
344
|
+
};
|
|
345
|
+
requestBody?: never;
|
|
346
|
+
responses: {
|
|
347
|
+
/** @description One page. */
|
|
348
|
+
200: {
|
|
349
|
+
headers: {
|
|
350
|
+
[name: string]: unknown;
|
|
351
|
+
};
|
|
352
|
+
content: {
|
|
353
|
+
"application/json": components["schemas"]["MessagePage"];
|
|
354
|
+
};
|
|
355
|
+
};
|
|
356
|
+
400: components["responses"]["BadRequest"];
|
|
357
|
+
401: components["responses"]["Unauthorized"];
|
|
358
|
+
404: components["responses"]["NotFound"];
|
|
359
|
+
429: components["responses"]["TooManyRequests"];
|
|
360
|
+
};
|
|
361
|
+
};
|
|
362
|
+
sendMessage: {
|
|
363
|
+
parameters: {
|
|
364
|
+
query?: never;
|
|
365
|
+
header?: {
|
|
366
|
+
/** @description Repeating a request with the same key returns the first message instead of sending again. */
|
|
367
|
+
"Idempotency-Key"?: string;
|
|
368
|
+
};
|
|
369
|
+
path: {
|
|
370
|
+
/** @description The project's slug. */
|
|
371
|
+
project: components["parameters"]["Project"];
|
|
372
|
+
};
|
|
373
|
+
cookie?: never;
|
|
374
|
+
};
|
|
375
|
+
requestBody: {
|
|
376
|
+
content: {
|
|
377
|
+
"application/json": components["schemas"]["SendMessageRequest"];
|
|
378
|
+
};
|
|
379
|
+
};
|
|
380
|
+
responses: {
|
|
381
|
+
/** @description Queued for the phone. */
|
|
382
|
+
202: {
|
|
383
|
+
headers: {
|
|
384
|
+
/** @description `true` when this is a replay of an earlier request. */
|
|
385
|
+
"Idempotent-Replayed"?: string;
|
|
386
|
+
[name: string]: unknown;
|
|
387
|
+
};
|
|
388
|
+
content: {
|
|
389
|
+
"application/json": components["schemas"]["MessageView"];
|
|
390
|
+
};
|
|
391
|
+
};
|
|
392
|
+
400: components["responses"]["BadRequest"];
|
|
393
|
+
401: components["responses"]["Unauthorized"];
|
|
394
|
+
404: components["responses"]["NotFound"];
|
|
395
|
+
429: components["responses"]["TooManyRequests"];
|
|
396
|
+
};
|
|
397
|
+
};
|
|
398
|
+
getMessage: {
|
|
399
|
+
parameters: {
|
|
400
|
+
query?: never;
|
|
401
|
+
header?: never;
|
|
402
|
+
path: {
|
|
403
|
+
/** @description Message id (`msg_…`). */
|
|
404
|
+
id: string;
|
|
405
|
+
/** @description The project's slug. */
|
|
406
|
+
project: components["parameters"]["Project"];
|
|
407
|
+
};
|
|
408
|
+
cookie?: never;
|
|
409
|
+
};
|
|
410
|
+
requestBody?: never;
|
|
411
|
+
responses: {
|
|
412
|
+
/** @description The message. */
|
|
413
|
+
200: {
|
|
414
|
+
headers: {
|
|
415
|
+
[name: string]: unknown;
|
|
416
|
+
};
|
|
417
|
+
content: {
|
|
418
|
+
"application/json": components["schemas"]["MessageView"];
|
|
419
|
+
};
|
|
420
|
+
};
|
|
421
|
+
400: components["responses"]["BadRequest"];
|
|
422
|
+
401: components["responses"]["Unauthorized"];
|
|
423
|
+
404: components["responses"]["NotFound"];
|
|
424
|
+
429: components["responses"]["TooManyRequests"];
|
|
425
|
+
};
|
|
426
|
+
};
|
|
427
|
+
cancelMessage: {
|
|
428
|
+
parameters: {
|
|
429
|
+
query?: never;
|
|
430
|
+
header?: never;
|
|
431
|
+
path: {
|
|
432
|
+
/** @description Message id (`msg_…`). */
|
|
433
|
+
id: string;
|
|
434
|
+
/** @description The project's slug. */
|
|
435
|
+
project: components["parameters"]["Project"];
|
|
436
|
+
};
|
|
437
|
+
cookie?: never;
|
|
438
|
+
};
|
|
439
|
+
requestBody?: never;
|
|
440
|
+
responses: {
|
|
441
|
+
/** @description The cancelled message. */
|
|
442
|
+
200: {
|
|
443
|
+
headers: {
|
|
444
|
+
[name: string]: unknown;
|
|
445
|
+
};
|
|
446
|
+
content: {
|
|
447
|
+
"application/json": components["schemas"]["MessageView"];
|
|
448
|
+
};
|
|
449
|
+
};
|
|
450
|
+
400: components["responses"]["BadRequest"];
|
|
451
|
+
401: components["responses"]["Unauthorized"];
|
|
452
|
+
404: components["responses"]["NotFound"];
|
|
453
|
+
429: components["responses"]["TooManyRequests"];
|
|
454
|
+
};
|
|
455
|
+
};
|
|
456
|
+
sendBulk: {
|
|
457
|
+
parameters: {
|
|
458
|
+
query?: never;
|
|
459
|
+
header?: never;
|
|
460
|
+
path: {
|
|
461
|
+
/** @description The project's slug. */
|
|
462
|
+
project: components["parameters"]["Project"];
|
|
463
|
+
};
|
|
464
|
+
cookie?: never;
|
|
465
|
+
};
|
|
466
|
+
requestBody: {
|
|
467
|
+
content: {
|
|
468
|
+
"application/json": components["schemas"]["BulkSendRequest"];
|
|
469
|
+
};
|
|
470
|
+
};
|
|
471
|
+
responses: {
|
|
472
|
+
/** @description Batch queued. */
|
|
473
|
+
202: {
|
|
474
|
+
headers: {
|
|
475
|
+
[name: string]: unknown;
|
|
476
|
+
};
|
|
477
|
+
content: {
|
|
478
|
+
"application/json": components["schemas"]["BulkSendResponse"];
|
|
479
|
+
};
|
|
480
|
+
};
|
|
481
|
+
400: components["responses"]["BadRequest"];
|
|
482
|
+
401: components["responses"]["Unauthorized"];
|
|
483
|
+
404: components["responses"]["NotFound"];
|
|
484
|
+
429: components["responses"]["TooManyRequests"];
|
|
485
|
+
};
|
|
486
|
+
};
|
|
487
|
+
sendOtp: {
|
|
488
|
+
parameters: {
|
|
489
|
+
query?: never;
|
|
490
|
+
header?: never;
|
|
491
|
+
path: {
|
|
492
|
+
/** @description The project's slug. */
|
|
493
|
+
project: components["parameters"]["Project"];
|
|
494
|
+
};
|
|
495
|
+
cookie?: never;
|
|
496
|
+
};
|
|
497
|
+
requestBody: {
|
|
498
|
+
content: {
|
|
499
|
+
"application/json": components["schemas"]["OtpRequest"];
|
|
500
|
+
};
|
|
501
|
+
};
|
|
502
|
+
responses: {
|
|
503
|
+
/** @description Code sent. */
|
|
504
|
+
202: {
|
|
505
|
+
headers: {
|
|
506
|
+
[name: string]: unknown;
|
|
507
|
+
};
|
|
508
|
+
content: {
|
|
509
|
+
"application/json": components["schemas"]["OtpResponse"];
|
|
510
|
+
};
|
|
511
|
+
};
|
|
512
|
+
400: components["responses"]["BadRequest"];
|
|
513
|
+
401: components["responses"]["Unauthorized"];
|
|
514
|
+
404: components["responses"]["NotFound"];
|
|
515
|
+
429: components["responses"]["TooManyRequests"];
|
|
516
|
+
};
|
|
517
|
+
};
|
|
518
|
+
verifyOtp: {
|
|
519
|
+
parameters: {
|
|
520
|
+
query?: never;
|
|
521
|
+
header?: never;
|
|
522
|
+
path: {
|
|
523
|
+
/** @description The project's slug. */
|
|
524
|
+
project: components["parameters"]["Project"];
|
|
525
|
+
};
|
|
526
|
+
cookie?: never;
|
|
527
|
+
};
|
|
528
|
+
requestBody: {
|
|
529
|
+
content: {
|
|
530
|
+
"application/json": components["schemas"]["OtpVerifyRequest"];
|
|
531
|
+
};
|
|
532
|
+
};
|
|
533
|
+
responses: {
|
|
534
|
+
/** @description Whether the code is right, and why not. */
|
|
535
|
+
200: {
|
|
536
|
+
headers: {
|
|
537
|
+
[name: string]: unknown;
|
|
538
|
+
};
|
|
539
|
+
content: {
|
|
540
|
+
"application/json": components["schemas"]["OtpVerifyResponse"];
|
|
541
|
+
};
|
|
542
|
+
};
|
|
543
|
+
400: components["responses"]["BadRequest"];
|
|
544
|
+
401: components["responses"]["Unauthorized"];
|
|
545
|
+
404: components["responses"]["NotFound"];
|
|
546
|
+
429: components["responses"]["TooManyRequests"];
|
|
547
|
+
};
|
|
548
|
+
};
|
|
549
|
+
listSchedules: {
|
|
550
|
+
parameters: {
|
|
551
|
+
query?: never;
|
|
552
|
+
header?: never;
|
|
553
|
+
path: {
|
|
554
|
+
/** @description The project's slug. */
|
|
555
|
+
project: components["parameters"]["Project"];
|
|
556
|
+
};
|
|
557
|
+
cookie?: never;
|
|
558
|
+
};
|
|
559
|
+
requestBody?: never;
|
|
560
|
+
responses: {
|
|
561
|
+
/** @description All of them. */
|
|
562
|
+
200: {
|
|
563
|
+
headers: {
|
|
564
|
+
[name: string]: unknown;
|
|
565
|
+
};
|
|
566
|
+
content: {
|
|
567
|
+
"application/json": components["schemas"]["SchedulePage"];
|
|
568
|
+
};
|
|
569
|
+
};
|
|
570
|
+
400: components["responses"]["BadRequest"];
|
|
571
|
+
401: components["responses"]["Unauthorized"];
|
|
572
|
+
404: components["responses"]["NotFound"];
|
|
573
|
+
429: components["responses"]["TooManyRequests"];
|
|
574
|
+
};
|
|
575
|
+
};
|
|
576
|
+
createSchedule: {
|
|
577
|
+
parameters: {
|
|
578
|
+
query?: never;
|
|
579
|
+
header?: never;
|
|
580
|
+
path: {
|
|
581
|
+
/** @description The project's slug. */
|
|
582
|
+
project: components["parameters"]["Project"];
|
|
583
|
+
};
|
|
584
|
+
cookie?: never;
|
|
585
|
+
};
|
|
586
|
+
requestBody: {
|
|
587
|
+
content: {
|
|
588
|
+
"application/json": components["schemas"]["ScheduleRequest"];
|
|
589
|
+
};
|
|
590
|
+
};
|
|
591
|
+
responses: {
|
|
592
|
+
/** @description Created. */
|
|
593
|
+
201: {
|
|
594
|
+
headers: {
|
|
595
|
+
[name: string]: unknown;
|
|
596
|
+
};
|
|
597
|
+
content: {
|
|
598
|
+
"application/json": components["schemas"]["ScheduleView"];
|
|
599
|
+
};
|
|
600
|
+
};
|
|
601
|
+
400: components["responses"]["BadRequest"];
|
|
602
|
+
401: components["responses"]["Unauthorized"];
|
|
603
|
+
404: components["responses"]["NotFound"];
|
|
604
|
+
429: components["responses"]["TooManyRequests"];
|
|
605
|
+
};
|
|
606
|
+
};
|
|
607
|
+
getSchedule: {
|
|
608
|
+
parameters: {
|
|
609
|
+
query?: never;
|
|
610
|
+
header?: never;
|
|
611
|
+
path: {
|
|
612
|
+
/** @description Schedule id. */
|
|
613
|
+
id: string;
|
|
614
|
+
/** @description The project's slug. */
|
|
615
|
+
project: components["parameters"]["Project"];
|
|
616
|
+
};
|
|
617
|
+
cookie?: never;
|
|
618
|
+
};
|
|
619
|
+
requestBody?: never;
|
|
620
|
+
responses: {
|
|
621
|
+
/** @description The schedule. */
|
|
622
|
+
200: {
|
|
623
|
+
headers: {
|
|
624
|
+
[name: string]: unknown;
|
|
625
|
+
};
|
|
626
|
+
content: {
|
|
627
|
+
"application/json": components["schemas"]["ScheduleView"];
|
|
628
|
+
};
|
|
629
|
+
};
|
|
630
|
+
400: components["responses"]["BadRequest"];
|
|
631
|
+
401: components["responses"]["Unauthorized"];
|
|
632
|
+
404: components["responses"]["NotFound"];
|
|
633
|
+
429: components["responses"]["TooManyRequests"];
|
|
634
|
+
};
|
|
635
|
+
};
|
|
636
|
+
deleteSchedule: {
|
|
637
|
+
parameters: {
|
|
638
|
+
query?: never;
|
|
639
|
+
header?: never;
|
|
640
|
+
path: {
|
|
641
|
+
/** @description Schedule id. */
|
|
642
|
+
id: string;
|
|
643
|
+
/** @description The project's slug. */
|
|
644
|
+
project: components["parameters"]["Project"];
|
|
645
|
+
};
|
|
646
|
+
cookie?: never;
|
|
647
|
+
};
|
|
648
|
+
requestBody?: never;
|
|
649
|
+
responses: {
|
|
650
|
+
/** @description Deleted. */
|
|
651
|
+
204: {
|
|
652
|
+
headers: {
|
|
653
|
+
[name: string]: unknown;
|
|
654
|
+
};
|
|
655
|
+
content?: never;
|
|
656
|
+
};
|
|
657
|
+
400: components["responses"]["BadRequest"];
|
|
658
|
+
401: components["responses"]["Unauthorized"];
|
|
659
|
+
404: components["responses"]["NotFound"];
|
|
660
|
+
429: components["responses"]["TooManyRequests"];
|
|
661
|
+
};
|
|
662
|
+
};
|
|
663
|
+
updateSchedule: {
|
|
664
|
+
parameters: {
|
|
665
|
+
query?: never;
|
|
666
|
+
header?: never;
|
|
667
|
+
path: {
|
|
668
|
+
/** @description Schedule id. */
|
|
669
|
+
id: string;
|
|
670
|
+
/** @description The project's slug. */
|
|
671
|
+
project: components["parameters"]["Project"];
|
|
672
|
+
};
|
|
673
|
+
cookie?: never;
|
|
674
|
+
};
|
|
675
|
+
requestBody: {
|
|
676
|
+
content: {
|
|
677
|
+
"application/json": components["schemas"]["ScheduleUpdate"];
|
|
678
|
+
};
|
|
679
|
+
};
|
|
680
|
+
responses: {
|
|
681
|
+
/** @description The updated schedule. */
|
|
682
|
+
200: {
|
|
683
|
+
headers: {
|
|
684
|
+
[name: string]: unknown;
|
|
685
|
+
};
|
|
686
|
+
content: {
|
|
687
|
+
"application/json": components["schemas"]["ScheduleView"];
|
|
688
|
+
};
|
|
689
|
+
};
|
|
690
|
+
400: components["responses"]["BadRequest"];
|
|
691
|
+
401: components["responses"]["Unauthorized"];
|
|
692
|
+
404: components["responses"]["NotFound"];
|
|
693
|
+
429: components["responses"]["TooManyRequests"];
|
|
694
|
+
};
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
type S = components['schemas'];
|
|
699
|
+
type MessageType = S['MessageType'];
|
|
700
|
+
type MessageStatus = S['MessageStatus'];
|
|
701
|
+
type SendMessageParams = S['SendMessageRequest'];
|
|
702
|
+
type BulkItem = S['BulkItem'];
|
|
703
|
+
type SendBulkParams = S['BulkSendRequest'];
|
|
704
|
+
type Message = S['MessageView'];
|
|
705
|
+
type MessagePage = S['MessagePage'];
|
|
706
|
+
type BulkResult = S['BulkSendResponse'];
|
|
707
|
+
type RejectedItem = S['RejectedItem'];
|
|
708
|
+
type ListMessagesParams = NonNullable<operations['listMessages']['parameters']['query']>;
|
|
709
|
+
type SendOtpParams = S['OtpRequest'];
|
|
710
|
+
type Otp = S['OtpResponse'];
|
|
711
|
+
type VerifyOtpParams = S['OtpVerifyRequest'];
|
|
712
|
+
type OtpVerification = S['OtpVerifyResponse'];
|
|
713
|
+
type OtpFailure = S['OtpFailure'];
|
|
714
|
+
type CreateScheduleParams = S['ScheduleRequest'];
|
|
715
|
+
type UpdateScheduleParams = S['ScheduleUpdate'];
|
|
716
|
+
type Schedule = S['ScheduleView'];
|
|
717
|
+
type ScheduleRun = S['ScheduleRunView'];
|
|
718
|
+
type SchedulePage = S['SchedulePage'];
|
|
719
|
+
type StatusEvent = S['StatusWebhookPayload'];
|
|
720
|
+
type ReceivedEvent = S['InboundWebhookPayload'];
|
|
721
|
+
type AlertEvent = S['AlertWebhookPayload'];
|
|
722
|
+
/** Anything POSTed to a webhook; narrow on `event`. */
|
|
723
|
+
type WebhookEvent = StatusEvent | ReceivedEvent | AlertEvent;
|
|
724
|
+
|
|
725
|
+
type Call = <T>(req: Request) => Promise<T>;
|
|
726
|
+
interface SendOptions {
|
|
727
|
+
/**
|
|
728
|
+
* Repeating a send with the same key returns the first message instead of sending again.
|
|
729
|
+
* Defaults to a fresh random key, so the SDK's own retries never send twice; pass your own
|
|
730
|
+
* (an order id, say) to make your retries safe too.
|
|
731
|
+
*/
|
|
732
|
+
idempotencyKey?: string;
|
|
733
|
+
}
|
|
734
|
+
declare class Messages {
|
|
735
|
+
private readonly call;
|
|
736
|
+
private readonly base;
|
|
737
|
+
constructor(call: Call, base: string);
|
|
738
|
+
/** Queues one SMS for the project's phone. */
|
|
739
|
+
send(params: SendMessageParams, options?: SendOptions): Promise<Message>;
|
|
740
|
+
/** Queues a batch. Invalid or opted-out items come back in `rejected`; the rest go out as one batch. */
|
|
741
|
+
sendBulk(params: SendBulkParams): Promise<BulkResult>;
|
|
742
|
+
get(id: string): Promise<Message>;
|
|
743
|
+
/** Stops a message that hasn't reached a phone yet. */
|
|
744
|
+
cancel(id: string): Promise<Message>;
|
|
745
|
+
/** One page, newest first. Pass `next_cursor` back as `cursor` for the next. */
|
|
746
|
+
list(params?: ListMessagesParams): Promise<MessagePage>;
|
|
747
|
+
/** Every matching message, newest first, fetching pages as you go. */
|
|
748
|
+
listAll(params?: Omit<ListMessagesParams, 'cursor'>): AsyncGenerator<Message>;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
declare class OneTimeCodes {
|
|
752
|
+
private readonly call;
|
|
753
|
+
private readonly base;
|
|
754
|
+
constructor(call: Call, base: string);
|
|
755
|
+
/** Texts a fresh code to `to`. Keep the returned `id` for verify(). */
|
|
756
|
+
send(params: SendOtpParams): Promise<Otp>;
|
|
757
|
+
/** Checks what the user typed. `valid` is false with a `reason` when it's wrong, expired or used. */
|
|
758
|
+
verify(params: VerifyOtpParams): Promise<OtpVerification>;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
declare class Schedules {
|
|
762
|
+
private readonly call;
|
|
763
|
+
private readonly base;
|
|
764
|
+
constructor(call: Call, base: string);
|
|
765
|
+
/** A message (or batch) sent again and again on a cron schedule. */
|
|
766
|
+
create(params: CreateScheduleParams): Promise<Schedule>;
|
|
767
|
+
list(): Promise<SchedulePage>;
|
|
768
|
+
/** One schedule, with its recent runs. */
|
|
769
|
+
get(id: string): Promise<Schedule>;
|
|
770
|
+
/** Absent fields stay as they are; recipients can't change. */
|
|
771
|
+
update(id: string, params: UpdateScheduleParams): Promise<Schedule>;
|
|
772
|
+
delete(id: string): Promise<void>;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
interface VerifyOptions {
|
|
776
|
+
/** Oldest (and furthest in the future) signature accepted, in seconds. Default 300. */
|
|
777
|
+
tolerance?: number;
|
|
778
|
+
/** The current time in unix seconds; for tests. */
|
|
779
|
+
now?: number;
|
|
780
|
+
}
|
|
781
|
+
/** The header the signature arrives in. */
|
|
782
|
+
declare const SIGNATURE_HEADER = "X-SMSWire-Signature";
|
|
783
|
+
/**
|
|
784
|
+
* Checks a webhook's X-SMSWire-Signature against the **raw** request body (not re-serialised JSON)
|
|
785
|
+
* and returns the parsed event. Throws SMSWireSignatureError when the signature is missing,
|
|
786
|
+
* wrong, or more than `tolerance` seconds off.
|
|
787
|
+
*/
|
|
788
|
+
declare function verifyWebhook(rawBody: string | Uint8Array | ArrayBuffer, signature: string | null | undefined, secret: string, options?: VerifyOptions): Promise<WebhookEvent>;
|
|
789
|
+
|
|
790
|
+
declare const VERSION = "0.1.0";
|
|
791
|
+
interface ClientOptions {
|
|
792
|
+
/** The project's API key (`smswire_live_…`). Defaults to SMSWIRE_KEY. */
|
|
793
|
+
apiKey?: string;
|
|
794
|
+
/** The project's slug, the part after /p/ in its endpoint. Defaults to SMSWIRE_PROJECT. */
|
|
795
|
+
project?: string;
|
|
796
|
+
/** Defaults to SMSWIRE_URL, then https://api.smswire.app. */
|
|
797
|
+
baseUrl?: string;
|
|
798
|
+
/** Signing secret (`whsec_…`) for webhooks.verify(). Defaults to SMSWIRE_WEBHOOK_SECRET. */
|
|
799
|
+
webhookSecret?: string;
|
|
800
|
+
/** Retries after a 429, a 5xx or a network error (see the README for which calls). Default 2. */
|
|
801
|
+
maxRetries?: number;
|
|
802
|
+
/** Longest Retry-After worth waiting for, in seconds; longer ones throw at once. Default 60. */
|
|
803
|
+
maxRetryWait?: number;
|
|
804
|
+
/** Per-attempt timeout in milliseconds. Default 30 000. */
|
|
805
|
+
timeout?: number;
|
|
806
|
+
/** A fetch implementation, for runtimes or tests that need their own. */
|
|
807
|
+
fetch?: typeof fetch;
|
|
808
|
+
}
|
|
809
|
+
declare class SMSWire {
|
|
810
|
+
readonly messages: Messages;
|
|
811
|
+
readonly otp: OneTimeCodes;
|
|
812
|
+
readonly schedules: Schedules;
|
|
813
|
+
readonly webhooks: {
|
|
814
|
+
verify(rawBody: string | Uint8Array | ArrayBuffer, signature: string | null | undefined, options?: VerifyOptions): Promise<WebhookEvent>;
|
|
815
|
+
};
|
|
816
|
+
constructor(options?: ClientOptions);
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
export { type AlertEvent, type BulkItem, type BulkResult, type ClientOptions, type CreateScheduleParams, type ListMessagesParams, type Message, type MessagePage, type MessageStatus, type MessageType, type Otp, type OtpFailure, type OtpVerification, type ReceivedEvent, type RejectedItem, SIGNATURE_HEADER, SMSWire, SMSWireError, SMSWireSignatureError, type Schedule, type SchedulePage, type ScheduleRun, type SendBulkParams, type SendMessageParams, type SendOptions, type SendOtpParams, type StatusEvent, type UpdateScheduleParams, VERSION, type VerifyOptions, type VerifyOtpParams, type WebhookEvent, SMSWire as default, verifyWebhook };
|