@messagebird/sdk 0.2.1 → 0.3.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/dist/index.d.ts +1191 -181
- package/dist/index.js +536 -15
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -468,11 +468,8 @@ var checkForExistence = (options, name) => {
|
|
|
468
468
|
}
|
|
469
469
|
return false;
|
|
470
470
|
};
|
|
471
|
-
|
|
472
|
-
security
|
|
473
|
-
...options
|
|
474
|
-
}) => {
|
|
475
|
-
for (const auth of security) {
|
|
471
|
+
async function setAuthParams(options) {
|
|
472
|
+
for (const auth of options.security ?? []) {
|
|
476
473
|
if (checkForExistence(options, auth.name)) {
|
|
477
474
|
continue;
|
|
478
475
|
}
|
|
@@ -497,7 +494,7 @@ var setAuthParams = async ({
|
|
|
497
494
|
break;
|
|
498
495
|
}
|
|
499
496
|
}
|
|
500
|
-
}
|
|
497
|
+
}
|
|
501
498
|
var buildUrl = (options) => getUrl({
|
|
502
499
|
baseUrl: options.baseUrl,
|
|
503
500
|
path: options.path,
|
|
@@ -623,10 +620,7 @@ var createClient = (config = {}) => {
|
|
|
623
620
|
serializedBody: void 0
|
|
624
621
|
};
|
|
625
622
|
if (opts.security) {
|
|
626
|
-
await setAuthParams(
|
|
627
|
-
...opts,
|
|
628
|
-
security: opts.security
|
|
629
|
-
});
|
|
623
|
+
await setAuthParams(opts);
|
|
630
624
|
}
|
|
631
625
|
if (opts.requestValidator) {
|
|
632
626
|
await opts.requestValidator(opts);
|
|
@@ -859,6 +853,8 @@ var BirdAPIError = class extends BirdError {
|
|
|
859
853
|
requestId;
|
|
860
854
|
param;
|
|
861
855
|
vendorCode;
|
|
856
|
+
remediation;
|
|
857
|
+
next;
|
|
862
858
|
constructor(fields) {
|
|
863
859
|
super(fields.message);
|
|
864
860
|
this.name = "BirdAPIError";
|
|
@@ -870,6 +866,8 @@ var BirdAPIError = class extends BirdError {
|
|
|
870
866
|
this.requestId = fields.requestId;
|
|
871
867
|
this.param = fields.param;
|
|
872
868
|
this.vendorCode = fields.vendorCode;
|
|
869
|
+
this.remediation = fields.remediation;
|
|
870
|
+
this.next = fields.next;
|
|
873
871
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
874
872
|
}
|
|
875
873
|
};
|
|
@@ -1027,7 +1025,10 @@ function mapResponseToError(status, body, headers) {
|
|
|
1027
1025
|
docUrl: b.doc_url ?? "",
|
|
1028
1026
|
requestId: b.request_id ?? headers?.get("X-Request-Id") ?? "",
|
|
1029
1027
|
param: b.param,
|
|
1030
|
-
vendorCode: b.vendor_code
|
|
1028
|
+
vendorCode: b.vendor_code,
|
|
1029
|
+
remediation: b.remediation,
|
|
1030
|
+
next: b.next ?? []
|
|
1031
|
+
// normalize a null/absent wire `next` to [] so callers can always iterate
|
|
1031
1032
|
};
|
|
1032
1033
|
switch (fields.type) {
|
|
1033
1034
|
case "auth_error":
|
|
@@ -1265,6 +1266,190 @@ var getEmailMessage = (options) => (options.client ?? client).get({
|
|
|
1265
1266
|
url: "/v1/email/messages/{message_id}",
|
|
1266
1267
|
...options
|
|
1267
1268
|
});
|
|
1269
|
+
var listSmsMessages = (options) => (options?.client ?? client).get({
|
|
1270
|
+
security: [
|
|
1271
|
+
{ scheme: "bearer", type: "http" },
|
|
1272
|
+
{
|
|
1273
|
+
in: "cookie",
|
|
1274
|
+
name: "bird_session",
|
|
1275
|
+
type: "apiKey"
|
|
1276
|
+
}
|
|
1277
|
+
],
|
|
1278
|
+
url: "/v1/sms/messages",
|
|
1279
|
+
...options
|
|
1280
|
+
});
|
|
1281
|
+
var createSmsMessage = (options) => (options.client ?? client).post({
|
|
1282
|
+
security: [
|
|
1283
|
+
{ scheme: "bearer", type: "http" },
|
|
1284
|
+
{
|
|
1285
|
+
in: "cookie",
|
|
1286
|
+
name: "bird_session",
|
|
1287
|
+
type: "apiKey"
|
|
1288
|
+
}
|
|
1289
|
+
],
|
|
1290
|
+
url: "/v1/sms/messages",
|
|
1291
|
+
...options,
|
|
1292
|
+
headers: {
|
|
1293
|
+
"Content-Type": "application/json",
|
|
1294
|
+
...options.headers
|
|
1295
|
+
}
|
|
1296
|
+
});
|
|
1297
|
+
var createSmsMessageBatch = (options) => (options.client ?? client).post({
|
|
1298
|
+
security: [
|
|
1299
|
+
{ scheme: "bearer", type: "http" },
|
|
1300
|
+
{
|
|
1301
|
+
in: "cookie",
|
|
1302
|
+
name: "bird_session",
|
|
1303
|
+
type: "apiKey"
|
|
1304
|
+
}
|
|
1305
|
+
],
|
|
1306
|
+
url: "/v1/sms/batches",
|
|
1307
|
+
...options,
|
|
1308
|
+
headers: {
|
|
1309
|
+
"Content-Type": "application/json",
|
|
1310
|
+
...options.headers
|
|
1311
|
+
}
|
|
1312
|
+
});
|
|
1313
|
+
var getSmsMessage = (options) => (options.client ?? client).get({
|
|
1314
|
+
security: [
|
|
1315
|
+
{ scheme: "bearer", type: "http" },
|
|
1316
|
+
{
|
|
1317
|
+
in: "cookie",
|
|
1318
|
+
name: "bird_session",
|
|
1319
|
+
type: "apiKey"
|
|
1320
|
+
}
|
|
1321
|
+
],
|
|
1322
|
+
url: "/v1/sms/messages/{message_id}",
|
|
1323
|
+
...options
|
|
1324
|
+
});
|
|
1325
|
+
var listSmsTemplates = (options) => (options?.client ?? client).get({
|
|
1326
|
+
security: [
|
|
1327
|
+
{ scheme: "bearer", type: "http" },
|
|
1328
|
+
{
|
|
1329
|
+
in: "cookie",
|
|
1330
|
+
name: "bird_session",
|
|
1331
|
+
type: "apiKey"
|
|
1332
|
+
}
|
|
1333
|
+
],
|
|
1334
|
+
url: "/v1/sms/templates",
|
|
1335
|
+
...options
|
|
1336
|
+
});
|
|
1337
|
+
var getSmsTemplate = (options) => (options.client ?? client).get({
|
|
1338
|
+
security: [
|
|
1339
|
+
{ scheme: "bearer", type: "http" },
|
|
1340
|
+
{
|
|
1341
|
+
in: "cookie",
|
|
1342
|
+
name: "bird_session",
|
|
1343
|
+
type: "apiKey"
|
|
1344
|
+
}
|
|
1345
|
+
],
|
|
1346
|
+
url: "/v1/sms/templates/{template_ref}",
|
|
1347
|
+
...options
|
|
1348
|
+
});
|
|
1349
|
+
var listEmailTemplates = (options) => (options?.client ?? client).get({
|
|
1350
|
+
security: [
|
|
1351
|
+
{ scheme: "bearer", type: "http" },
|
|
1352
|
+
{
|
|
1353
|
+
in: "cookie",
|
|
1354
|
+
name: "bird_session",
|
|
1355
|
+
type: "apiKey"
|
|
1356
|
+
}
|
|
1357
|
+
],
|
|
1358
|
+
url: "/v1/email/templates",
|
|
1359
|
+
...options
|
|
1360
|
+
});
|
|
1361
|
+
var createEmailTemplate = (options) => (options.client ?? client).post({
|
|
1362
|
+
security: [
|
|
1363
|
+
{ scheme: "bearer", type: "http" },
|
|
1364
|
+
{
|
|
1365
|
+
in: "cookie",
|
|
1366
|
+
name: "bird_session",
|
|
1367
|
+
type: "apiKey"
|
|
1368
|
+
}
|
|
1369
|
+
],
|
|
1370
|
+
url: "/v1/email/templates",
|
|
1371
|
+
...options,
|
|
1372
|
+
headers: {
|
|
1373
|
+
"Content-Type": "application/json",
|
|
1374
|
+
...options.headers
|
|
1375
|
+
}
|
|
1376
|
+
});
|
|
1377
|
+
var deleteEmailTemplate = (options) => (options.client ?? client).delete({
|
|
1378
|
+
security: [
|
|
1379
|
+
{ scheme: "bearer", type: "http" },
|
|
1380
|
+
{
|
|
1381
|
+
in: "cookie",
|
|
1382
|
+
name: "bird_session",
|
|
1383
|
+
type: "apiKey"
|
|
1384
|
+
}
|
|
1385
|
+
],
|
|
1386
|
+
url: "/v1/email/templates/{template_id}",
|
|
1387
|
+
...options
|
|
1388
|
+
});
|
|
1389
|
+
var getEmailTemplate = (options) => (options.client ?? client).get({
|
|
1390
|
+
security: [
|
|
1391
|
+
{ scheme: "bearer", type: "http" },
|
|
1392
|
+
{
|
|
1393
|
+
in: "cookie",
|
|
1394
|
+
name: "bird_session",
|
|
1395
|
+
type: "apiKey"
|
|
1396
|
+
}
|
|
1397
|
+
],
|
|
1398
|
+
url: "/v1/email/templates/{template_id}",
|
|
1399
|
+
...options
|
|
1400
|
+
});
|
|
1401
|
+
var updateEmailTemplate = (options) => (options.client ?? client).patch({
|
|
1402
|
+
security: [
|
|
1403
|
+
{ scheme: "bearer", type: "http" },
|
|
1404
|
+
{
|
|
1405
|
+
in: "cookie",
|
|
1406
|
+
name: "bird_session",
|
|
1407
|
+
type: "apiKey"
|
|
1408
|
+
}
|
|
1409
|
+
],
|
|
1410
|
+
url: "/v1/email/templates/{template_id}",
|
|
1411
|
+
...options,
|
|
1412
|
+
headers: {
|
|
1413
|
+
"Content-Type": "application/json",
|
|
1414
|
+
...options.headers
|
|
1415
|
+
}
|
|
1416
|
+
});
|
|
1417
|
+
var listEmailTemplateVersions = (options) => (options.client ?? client).get({
|
|
1418
|
+
security: [
|
|
1419
|
+
{ scheme: "bearer", type: "http" },
|
|
1420
|
+
{
|
|
1421
|
+
in: "cookie",
|
|
1422
|
+
name: "bird_session",
|
|
1423
|
+
type: "apiKey"
|
|
1424
|
+
}
|
|
1425
|
+
],
|
|
1426
|
+
url: "/v1/email/templates/{template_id}/versions",
|
|
1427
|
+
...options
|
|
1428
|
+
});
|
|
1429
|
+
var getEmailTemplateVersion = (options) => (options.client ?? client).get({
|
|
1430
|
+
security: [
|
|
1431
|
+
{ scheme: "bearer", type: "http" },
|
|
1432
|
+
{
|
|
1433
|
+
in: "cookie",
|
|
1434
|
+
name: "bird_session",
|
|
1435
|
+
type: "apiKey"
|
|
1436
|
+
}
|
|
1437
|
+
],
|
|
1438
|
+
url: "/v1/email/templates/{template_id}/versions/{version_id}",
|
|
1439
|
+
...options
|
|
1440
|
+
});
|
|
1441
|
+
var publishEmailTemplate = (options) => (options.client ?? client).post({
|
|
1442
|
+
security: [
|
|
1443
|
+
{ scheme: "bearer", type: "http" },
|
|
1444
|
+
{
|
|
1445
|
+
in: "cookie",
|
|
1446
|
+
name: "bird_session",
|
|
1447
|
+
type: "apiKey"
|
|
1448
|
+
}
|
|
1449
|
+
],
|
|
1450
|
+
url: "/v1/email/templates/{template_id}/publish",
|
|
1451
|
+
...options
|
|
1452
|
+
});
|
|
1268
1453
|
|
|
1269
1454
|
// src/resources/base.ts
|
|
1270
1455
|
var Resource = class {
|
|
@@ -1464,6 +1649,331 @@ var EmailResource = class extends Resource {
|
|
|
1464
1649
|
);
|
|
1465
1650
|
}
|
|
1466
1651
|
};
|
|
1652
|
+
|
|
1653
|
+
// src/resources/emailTemplates.ts
|
|
1654
|
+
var EmailTemplatesResource = class extends Resource {
|
|
1655
|
+
/**
|
|
1656
|
+
* Create a template and its initial editable draft. Pick the authoring format
|
|
1657
|
+
* with `source` (`liquid`, `handlebars`, or `html`); the name must be unique
|
|
1658
|
+
* in the workspace or the call throws a `BirdConflictError`.
|
|
1659
|
+
*
|
|
1660
|
+
* @example Create a template
|
|
1661
|
+
* const tpl = await bird.emailTemplates.create({
|
|
1662
|
+
* name: "Welcome",
|
|
1663
|
+
* category: "transactional",
|
|
1664
|
+
* source: "handlebars",
|
|
1665
|
+
* subject: "Welcome, {{ first_name }}!",
|
|
1666
|
+
* html: "<h1>Hi {{ first_name }}</h1>",
|
|
1667
|
+
* });
|
|
1668
|
+
* console.log(tpl.id, tpl.revision); // "emt_…", 0
|
|
1669
|
+
*/
|
|
1670
|
+
create(params, options) {
|
|
1671
|
+
return this.call(
|
|
1672
|
+
"POST",
|
|
1673
|
+
options,
|
|
1674
|
+
({ signal, headers }) => createEmailTemplate({
|
|
1675
|
+
client: this.client,
|
|
1676
|
+
body: params,
|
|
1677
|
+
headers,
|
|
1678
|
+
signal
|
|
1679
|
+
})
|
|
1680
|
+
);
|
|
1681
|
+
}
|
|
1682
|
+
/**
|
|
1683
|
+
* List the workspace's templates, newest first. `await` resolves the first
|
|
1684
|
+
* page; `for await` walks every template across all pages. Filter by
|
|
1685
|
+
* `category`, `source`, or a case-insensitive `name` prefix.
|
|
1686
|
+
*
|
|
1687
|
+
* @example Iterate every template, or take one page
|
|
1688
|
+
* for await (const tpl of bird.emailTemplates.list({ category: "transactional" })) {
|
|
1689
|
+
* console.log(tpl.id, tpl.name);
|
|
1690
|
+
* }
|
|
1691
|
+
* const page = await bird.emailTemplates.list({ limit: 50 }); // page.data, page.next_cursor
|
|
1692
|
+
*/
|
|
1693
|
+
list(query, options) {
|
|
1694
|
+
return this.paginated(
|
|
1695
|
+
"GET",
|
|
1696
|
+
options,
|
|
1697
|
+
({ signal, headers }, cursor) => listEmailTemplates({
|
|
1698
|
+
client: this.client,
|
|
1699
|
+
query: { ...query, starting_after: cursor ?? query?.starting_after },
|
|
1700
|
+
headers,
|
|
1701
|
+
signal
|
|
1702
|
+
})
|
|
1703
|
+
);
|
|
1704
|
+
}
|
|
1705
|
+
/**
|
|
1706
|
+
* Fetch a template with its current draft content (subject, HTML, text), the
|
|
1707
|
+
* draft `revision`, and its draft/published version ids.
|
|
1708
|
+
*
|
|
1709
|
+
* @example
|
|
1710
|
+
* const tpl = await bird.emailTemplates.get("emt_abc123");
|
|
1711
|
+
* tpl.subject;
|
|
1712
|
+
* tpl.published_version_id; // null until first publish
|
|
1713
|
+
*/
|
|
1714
|
+
get(templateId, options) {
|
|
1715
|
+
return this.call(
|
|
1716
|
+
"GET",
|
|
1717
|
+
options,
|
|
1718
|
+
({ signal, headers }) => getEmailTemplate({
|
|
1719
|
+
client: this.client,
|
|
1720
|
+
path: { template_id: templateId },
|
|
1721
|
+
headers,
|
|
1722
|
+
signal
|
|
1723
|
+
})
|
|
1724
|
+
);
|
|
1725
|
+
}
|
|
1726
|
+
/**
|
|
1727
|
+
* Update a template's metadata and draft content. Only the fields you send
|
|
1728
|
+
* change. Pass the draft `revision` you last read; if another edit landed
|
|
1729
|
+
* first the call throws a `BirdConflictError` — reload and retry.
|
|
1730
|
+
*
|
|
1731
|
+
* @example Edit the draft, guarded by the revision you read
|
|
1732
|
+
* const tpl = await bird.emailTemplates.get("emt_abc123");
|
|
1733
|
+
* const updated = await bird.emailTemplates.update("emt_abc123", {
|
|
1734
|
+
* revision: tpl.revision,
|
|
1735
|
+
* subject: "Welcome aboard, {{ first_name }}!",
|
|
1736
|
+
* });
|
|
1737
|
+
*/
|
|
1738
|
+
update(templateId, params, options) {
|
|
1739
|
+
return this.call(
|
|
1740
|
+
"PATCH",
|
|
1741
|
+
options,
|
|
1742
|
+
({ signal, headers }) => updateEmailTemplate({
|
|
1743
|
+
client: this.client,
|
|
1744
|
+
path: { template_id: templateId },
|
|
1745
|
+
body: params,
|
|
1746
|
+
headers,
|
|
1747
|
+
signal
|
|
1748
|
+
})
|
|
1749
|
+
);
|
|
1750
|
+
}
|
|
1751
|
+
/**
|
|
1752
|
+
* Delete a template and all its versions. The name becomes available for
|
|
1753
|
+
* reuse in the workspace.
|
|
1754
|
+
*
|
|
1755
|
+
* @example
|
|
1756
|
+
* await bird.emailTemplates.delete("emt_abc123");
|
|
1757
|
+
*/
|
|
1758
|
+
delete(templateId, options) {
|
|
1759
|
+
return this.call(
|
|
1760
|
+
"DELETE",
|
|
1761
|
+
options,
|
|
1762
|
+
({ signal, headers }) => deleteEmailTemplate({
|
|
1763
|
+
client: this.client,
|
|
1764
|
+
path: { template_id: templateId },
|
|
1765
|
+
headers,
|
|
1766
|
+
signal
|
|
1767
|
+
})
|
|
1768
|
+
);
|
|
1769
|
+
}
|
|
1770
|
+
/**
|
|
1771
|
+
* Publish the current draft as a new immutable, numbered version and make it
|
|
1772
|
+
* the live version used by sends. The draft stays editable. The draft must
|
|
1773
|
+
* have a subject and a body, or the call throws.
|
|
1774
|
+
*
|
|
1775
|
+
* @example Publish, then send by template
|
|
1776
|
+
* const version = await bird.emailTemplates.publish("emt_abc123");
|
|
1777
|
+
* console.log(version.version_number); // 1, 2, 3…
|
|
1778
|
+
* await bird.email.send({
|
|
1779
|
+
* from: "hello@acme.com",
|
|
1780
|
+
* to: ["alice@example.com"],
|
|
1781
|
+
* template: { id: "emt_abc123", parameters: { first_name: "Alice" } },
|
|
1782
|
+
* });
|
|
1783
|
+
*/
|
|
1784
|
+
publish(templateId, options) {
|
|
1785
|
+
return this.call(
|
|
1786
|
+
"POST",
|
|
1787
|
+
options,
|
|
1788
|
+
({ signal, headers }) => publishEmailTemplate({
|
|
1789
|
+
client: this.client,
|
|
1790
|
+
path: { template_id: templateId },
|
|
1791
|
+
headers,
|
|
1792
|
+
signal
|
|
1793
|
+
})
|
|
1794
|
+
);
|
|
1795
|
+
}
|
|
1796
|
+
/**
|
|
1797
|
+
* List every version of a template — the current draft plus all published
|
|
1798
|
+
* versions — newest first. Returns the full set in one response (`.data`);
|
|
1799
|
+
* this list is not paginated.
|
|
1800
|
+
*
|
|
1801
|
+
* @example
|
|
1802
|
+
* const { data } = await bird.emailTemplates.listVersions("emt_abc123");
|
|
1803
|
+
* for (const v of data) console.log(v.version_number, v.status);
|
|
1804
|
+
*/
|
|
1805
|
+
listVersions(templateId, options) {
|
|
1806
|
+
return this.call(
|
|
1807
|
+
"GET",
|
|
1808
|
+
options,
|
|
1809
|
+
({ signal, headers }) => listEmailTemplateVersions({
|
|
1810
|
+
client: this.client,
|
|
1811
|
+
path: { template_id: templateId },
|
|
1812
|
+
headers,
|
|
1813
|
+
signal
|
|
1814
|
+
})
|
|
1815
|
+
);
|
|
1816
|
+
}
|
|
1817
|
+
/**
|
|
1818
|
+
* Fetch a single version of a template.
|
|
1819
|
+
*
|
|
1820
|
+
* @example
|
|
1821
|
+
* const version = await bird.emailTemplates.getVersion("emt_abc123", "emv_def456");
|
|
1822
|
+
* version.status; // "draft" | "published"
|
|
1823
|
+
*/
|
|
1824
|
+
getVersion(templateId, versionId, options) {
|
|
1825
|
+
return this.call(
|
|
1826
|
+
"GET",
|
|
1827
|
+
options,
|
|
1828
|
+
({ signal, headers }) => getEmailTemplateVersion({
|
|
1829
|
+
client: this.client,
|
|
1830
|
+
path: { template_id: templateId, version_id: versionId },
|
|
1831
|
+
headers,
|
|
1832
|
+
signal
|
|
1833
|
+
})
|
|
1834
|
+
);
|
|
1835
|
+
}
|
|
1836
|
+
};
|
|
1837
|
+
|
|
1838
|
+
// src/resources/sms.ts
|
|
1839
|
+
var SmsResource = class extends Resource {
|
|
1840
|
+
/**
|
|
1841
|
+
* Send one SMS to a single recipient. Supply either `text` (with a `category`)
|
|
1842
|
+
* or a stored `template` (by `id` or `alias`, with its `parameters`). The
|
|
1843
|
+
* result is `accepted`, not yet delivered — read it back with `get` to confirm.
|
|
1844
|
+
*
|
|
1845
|
+
* @example Send free text
|
|
1846
|
+
* const msg = await bird.sms.send({
|
|
1847
|
+
* to: "+15551234567",
|
|
1848
|
+
* text: "Your verification code is 123456.",
|
|
1849
|
+
* category: "authentication",
|
|
1850
|
+
* });
|
|
1851
|
+
* console.log(msg.id, msg.status);
|
|
1852
|
+
*
|
|
1853
|
+
* @example Send by template
|
|
1854
|
+
* await bird.sms.send({
|
|
1855
|
+
* to: "+15551234567",
|
|
1856
|
+
* template: { alias: "bird_otp_verification", parameters: { code: "123456" } },
|
|
1857
|
+
* });
|
|
1858
|
+
*/
|
|
1859
|
+
send(params, options) {
|
|
1860
|
+
return this.call(
|
|
1861
|
+
"POST",
|
|
1862
|
+
options,
|
|
1863
|
+
({ signal, headers }) => createSmsMessage({ client: this.client, body: params, headers, signal })
|
|
1864
|
+
);
|
|
1865
|
+
}
|
|
1866
|
+
/**
|
|
1867
|
+
* Send up to 100 independent SMS messages in one call. Each item is a full send
|
|
1868
|
+
* (free text or template); all items are validated before any are queued.
|
|
1869
|
+
*
|
|
1870
|
+
* @example
|
|
1871
|
+
* const result = await bird.sms.sendBatch([
|
|
1872
|
+
* { to: "+15551111111", text: "Hi Alice!", category: "marketing" },
|
|
1873
|
+
* { to: "+15552222222", text: "Hi Bob!", category: "marketing" },
|
|
1874
|
+
* ]);
|
|
1875
|
+
*/
|
|
1876
|
+
sendBatch(params, options) {
|
|
1877
|
+
return this.call(
|
|
1878
|
+
"POST",
|
|
1879
|
+
options,
|
|
1880
|
+
({ signal, headers }) => createSmsMessageBatch({
|
|
1881
|
+
client: this.client,
|
|
1882
|
+
body: params,
|
|
1883
|
+
headers,
|
|
1884
|
+
signal
|
|
1885
|
+
})
|
|
1886
|
+
);
|
|
1887
|
+
}
|
|
1888
|
+
/**
|
|
1889
|
+
* Fetch a single SMS message: its current delivery status, segment breakdown,
|
|
1890
|
+
* cost, and failure detail if it failed.
|
|
1891
|
+
*
|
|
1892
|
+
* @example
|
|
1893
|
+
* const msg = await bird.sms.get("sms_abc123");
|
|
1894
|
+
* msg.status; // "accepted" | "delivered" | …
|
|
1895
|
+
*/
|
|
1896
|
+
get(messageId, options) {
|
|
1897
|
+
return this.call(
|
|
1898
|
+
"GET",
|
|
1899
|
+
options,
|
|
1900
|
+
({ signal, headers }) => getSmsMessage({
|
|
1901
|
+
client: this.client,
|
|
1902
|
+
path: { message_id: messageId },
|
|
1903
|
+
headers,
|
|
1904
|
+
signal
|
|
1905
|
+
})
|
|
1906
|
+
);
|
|
1907
|
+
}
|
|
1908
|
+
/**
|
|
1909
|
+
* List SMS messages, newest first. `await` resolves the first page; `for await`
|
|
1910
|
+
* walks every message across all pages. Filter by direction, status, category,
|
|
1911
|
+
* recipient, sender, or tag.
|
|
1912
|
+
*
|
|
1913
|
+
* @example
|
|
1914
|
+
* for await (const msg of bird.sms.list({ direction: "outbound" })) {
|
|
1915
|
+
* console.log(msg.id, msg.status);
|
|
1916
|
+
* }
|
|
1917
|
+
*/
|
|
1918
|
+
list(query, options) {
|
|
1919
|
+
return this.paginated(
|
|
1920
|
+
"GET",
|
|
1921
|
+
options,
|
|
1922
|
+
({ signal, headers }, cursor) => listSmsMessages({
|
|
1923
|
+
client: this.client,
|
|
1924
|
+
query: { ...query, starting_after: cursor ?? query?.starting_after },
|
|
1925
|
+
headers,
|
|
1926
|
+
signal
|
|
1927
|
+
})
|
|
1928
|
+
);
|
|
1929
|
+
}
|
|
1930
|
+
};
|
|
1931
|
+
|
|
1932
|
+
// src/resources/smsTemplates.ts
|
|
1933
|
+
var SmsTemplatesResource = class extends Resource {
|
|
1934
|
+
/**
|
|
1935
|
+
* List the SMS templates available to the workspace — Bird's built-in
|
|
1936
|
+
* templates plus any the workspace authored. The catalogue is small and
|
|
1937
|
+
* returned in full (`.data`); this list is not paginated. Filter by `scope`,
|
|
1938
|
+
* `category`, or `locale` (a BCP-47 language tag).
|
|
1939
|
+
*
|
|
1940
|
+
* @example List the built-in templates
|
|
1941
|
+
* const { data } = await bird.smsTemplates.list({ scope: "system" });
|
|
1942
|
+
* for (const tpl of data) console.log(tpl.id, tpl.name);
|
|
1943
|
+
*/
|
|
1944
|
+
list(query, options) {
|
|
1945
|
+
return this.call(
|
|
1946
|
+
"GET",
|
|
1947
|
+
options,
|
|
1948
|
+
({ signal, headers }) => listSmsTemplates({
|
|
1949
|
+
client: this.client,
|
|
1950
|
+
query,
|
|
1951
|
+
headers,
|
|
1952
|
+
signal
|
|
1953
|
+
})
|
|
1954
|
+
);
|
|
1955
|
+
}
|
|
1956
|
+
/**
|
|
1957
|
+
* Fetch a single SMS template by its alias or id, including its body and the
|
|
1958
|
+
* variables it expects.
|
|
1959
|
+
*
|
|
1960
|
+
* @example
|
|
1961
|
+
* const tpl = await bird.smsTemplates.get("bird_otp_verification");
|
|
1962
|
+
* console.log(tpl.body, tpl.variables);
|
|
1963
|
+
*/
|
|
1964
|
+
get(templateRef, options) {
|
|
1965
|
+
return this.call(
|
|
1966
|
+
"GET",
|
|
1967
|
+
options,
|
|
1968
|
+
({ signal, headers }) => getSmsTemplate({
|
|
1969
|
+
client: this.client,
|
|
1970
|
+
path: { template_ref: templateRef },
|
|
1971
|
+
headers,
|
|
1972
|
+
signal
|
|
1973
|
+
})
|
|
1974
|
+
);
|
|
1975
|
+
}
|
|
1976
|
+
};
|
|
1467
1977
|
var WebhooksResource = class {
|
|
1468
1978
|
#secret;
|
|
1469
1979
|
constructor(config) {
|
|
@@ -1568,6 +2078,12 @@ var BirdClient = class {
|
|
|
1568
2078
|
#headers;
|
|
1569
2079
|
/** The email channel — `bird.email.send(...)`, `.get(...)`, `.list(...)`. */
|
|
1570
2080
|
email;
|
|
2081
|
+
/** Email templates — `bird.emailTemplates.create(...)`, `.list(...)`, `.publish(...)`, … */
|
|
2082
|
+
emailTemplates;
|
|
2083
|
+
/** The SMS channel — `bird.sms.send(...)`, `.get(...)`, `.list(...)`. */
|
|
2084
|
+
sms;
|
|
2085
|
+
/** SMS templates — `bird.smsTemplates.list(...)`, `.get(...)`. */
|
|
2086
|
+
smsTemplates;
|
|
1571
2087
|
/** Webhooks — `bird.webhooks.unwrap(payload, headers)` verifies an inbound delivery. */
|
|
1572
2088
|
webhooks;
|
|
1573
2089
|
constructor(options) {
|
|
@@ -1577,12 +2093,12 @@ var BirdClient = class {
|
|
|
1577
2093
|
this.#headers = {
|
|
1578
2094
|
...opts.defaultHeaders,
|
|
1579
2095
|
Authorization: `Bearer ${opts.apiKey}`,
|
|
1580
|
-
"User-Agent": `bird-sdk-js/${"0.
|
|
1581
|
-
//
|
|
2096
|
+
"User-Agent": `bird-sdk-js/${"0.3.0"}`,
|
|
2097
|
+
// Bird-* client-identity headers (ADR-0074): the API attributes the SDK
|
|
1582
2098
|
// surface from these, not the User-Agent. Edge-safe, so no os/arch/runtime
|
|
1583
2099
|
// (those need Node globals this SDK must not touch); surface + version only.
|
|
1584
|
-
"
|
|
1585
|
-
"
|
|
2100
|
+
"Bird-Surface": "sdk-js",
|
|
2101
|
+
"Bird-Version": "0.3.0"
|
|
1586
2102
|
};
|
|
1587
2103
|
this.#client = createClient(
|
|
1588
2104
|
createConfig({
|
|
@@ -1600,6 +2116,9 @@ var BirdClient = class {
|
|
|
1600
2116
|
this.#client,
|
|
1601
2117
|
opts.email
|
|
1602
2118
|
);
|
|
2119
|
+
this.emailTemplates = new EmailTemplatesResource(this.core, this.#client);
|
|
2120
|
+
this.sms = new SmsResource(this.core, this.#client);
|
|
2121
|
+
this.smsTemplates = new SmsTemplatesResource(this.core, this.#client);
|
|
1603
2122
|
this.webhooks = new WebhooksResource(opts.webhooks);
|
|
1604
2123
|
}
|
|
1605
2124
|
/**
|
|
@@ -1664,6 +2183,7 @@ var WebhookEventType = {
|
|
|
1664
2183
|
DomainVerified: "domain.verified",
|
|
1665
2184
|
EmailAccepted: "email.accepted",
|
|
1666
2185
|
EmailBounced: "email.bounced",
|
|
2186
|
+
EmailCanceled: "email.canceled",
|
|
1667
2187
|
EmailClicked: "email.clicked",
|
|
1668
2188
|
EmailComplained: "email.complained",
|
|
1669
2189
|
EmailDeferred: "email.deferred",
|
|
@@ -1674,6 +2194,7 @@ var WebhookEventType = {
|
|
|
1674
2194
|
EmailProcessed: "email.processed",
|
|
1675
2195
|
EmailReceived: "email.received",
|
|
1676
2196
|
EmailRejected: "email.rejected",
|
|
2197
|
+
EmailScheduled: "email.scheduled",
|
|
1677
2198
|
EmailSuppressionCreated: "email_suppression.created",
|
|
1678
2199
|
EmailUnsubscribed: "email.unsubscribed",
|
|
1679
2200
|
SmsAccepted: "sms.accepted",
|