@messagebird/sdk 0.7.6 → 0.8.1
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.mts +591 -45
- package/dist/index.mjs +231 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1936,6 +1936,120 @@ const listWhatsAppTemplates = (options) => (options?.client ?? client).get({
|
|
|
1936
1936
|
url: "/v1/whatsapp/templates",
|
|
1937
1937
|
...options
|
|
1938
1938
|
});
|
|
1939
|
+
/**
|
|
1940
|
+
* List sending domains
|
|
1941
|
+
*
|
|
1942
|
+
* Returns all sending domains for the current workspace, ordered by creation date descending.
|
|
1943
|
+
*/
|
|
1944
|
+
const listDomains = (options) => (options?.client ?? client).get({
|
|
1945
|
+
security: [{
|
|
1946
|
+
scheme: "bearer",
|
|
1947
|
+
type: "http"
|
|
1948
|
+
}, {
|
|
1949
|
+
in: "cookie",
|
|
1950
|
+
name: "bird_session",
|
|
1951
|
+
type: "apiKey"
|
|
1952
|
+
}],
|
|
1953
|
+
url: "/v1/email/domains",
|
|
1954
|
+
...options
|
|
1955
|
+
});
|
|
1956
|
+
/**
|
|
1957
|
+
* Add a sending domain
|
|
1958
|
+
*
|
|
1959
|
+
* Registers a new sending domain and returns the DNS records required for verification: a DKIM TXT record, a return-path CNAME (which also covers SPF — no separate SPF record is needed), a DMARC policy, and, when a tracking domain is configured, a tracking CNAME. The domain starts in `pending` status; records are checked automatically once published, or on demand via the verify endpoint.
|
|
1960
|
+
*
|
|
1961
|
+
*/
|
|
1962
|
+
const createDomain = (options) => (options.client ?? client).post({
|
|
1963
|
+
security: [{
|
|
1964
|
+
scheme: "bearer",
|
|
1965
|
+
type: "http"
|
|
1966
|
+
}, {
|
|
1967
|
+
in: "cookie",
|
|
1968
|
+
name: "bird_session",
|
|
1969
|
+
type: "apiKey"
|
|
1970
|
+
}],
|
|
1971
|
+
url: "/v1/email/domains",
|
|
1972
|
+
...options,
|
|
1973
|
+
headers: {
|
|
1974
|
+
"Content-Type": "application/json",
|
|
1975
|
+
...options.headers
|
|
1976
|
+
}
|
|
1977
|
+
});
|
|
1978
|
+
/**
|
|
1979
|
+
* Delete a sending domain
|
|
1980
|
+
*
|
|
1981
|
+
* Removes the domain and revokes its sender authorization. New sends from a deleted domain are rejected. Historical statistics and events for past sends from this domain are preserved.
|
|
1982
|
+
*
|
|
1983
|
+
*/
|
|
1984
|
+
const deleteDomain = (options) => (options.client ?? client).delete({
|
|
1985
|
+
security: [{
|
|
1986
|
+
scheme: "bearer",
|
|
1987
|
+
type: "http"
|
|
1988
|
+
}, {
|
|
1989
|
+
in: "cookie",
|
|
1990
|
+
name: "bird_session",
|
|
1991
|
+
type: "apiKey"
|
|
1992
|
+
}],
|
|
1993
|
+
url: "/v1/email/domains/{domain_id}",
|
|
1994
|
+
...options
|
|
1995
|
+
});
|
|
1996
|
+
/**
|
|
1997
|
+
* Get a sending domain
|
|
1998
|
+
*
|
|
1999
|
+
* Returns the domain with current DNS verification status per record.
|
|
2000
|
+
*/
|
|
2001
|
+
const getDomain = (options) => (options.client ?? client).get({
|
|
2002
|
+
security: [{
|
|
2003
|
+
scheme: "bearer",
|
|
2004
|
+
type: "http"
|
|
2005
|
+
}, {
|
|
2006
|
+
in: "cookie",
|
|
2007
|
+
name: "bird_session",
|
|
2008
|
+
type: "apiKey"
|
|
2009
|
+
}],
|
|
2010
|
+
url: "/v1/email/domains/{domain_id}",
|
|
2011
|
+
...options
|
|
2012
|
+
});
|
|
2013
|
+
/**
|
|
2014
|
+
* Update a sending domain
|
|
2015
|
+
*
|
|
2016
|
+
* Updates settings and configuration on a sending domain. `settings` changes apply immediately. Changes to `return_path`, `tracking`, or `dkim` on a verified capability are staged: the current configuration keeps serving until the new one's DNS records verify, then the change is promoted automatically. Staged values are visible under `capabilities.*.pending`; the records to publish appear in `dns_records` with `state: pending`.
|
|
2017
|
+
*
|
|
2018
|
+
*/
|
|
2019
|
+
const updateDomain = (options) => (options.client ?? client).patch({
|
|
2020
|
+
security: [{
|
|
2021
|
+
scheme: "bearer",
|
|
2022
|
+
type: "http"
|
|
2023
|
+
}, {
|
|
2024
|
+
in: "cookie",
|
|
2025
|
+
name: "bird_session",
|
|
2026
|
+
type: "apiKey"
|
|
2027
|
+
}],
|
|
2028
|
+
url: "/v1/email/domains/{domain_id}",
|
|
2029
|
+
...options,
|
|
2030
|
+
headers: {
|
|
2031
|
+
"Content-Type": "application/json",
|
|
2032
|
+
...options.headers
|
|
2033
|
+
}
|
|
2034
|
+
});
|
|
2035
|
+
/**
|
|
2036
|
+
* Trigger domain verification
|
|
2037
|
+
*
|
|
2038
|
+
* Triggers an immediate DNS check and returns the updated verification result. Rate-limited to prevent DNS abuse (max 5 calls per domain per hour).
|
|
2039
|
+
*
|
|
2040
|
+
*/
|
|
2041
|
+
const verifyDomain = (options) => (options.client ?? client).post({
|
|
2042
|
+
security: [{
|
|
2043
|
+
scheme: "bearer",
|
|
2044
|
+
type: "http"
|
|
2045
|
+
}, {
|
|
2046
|
+
in: "cookie",
|
|
2047
|
+
name: "bird_session",
|
|
2048
|
+
type: "apiKey"
|
|
2049
|
+
}],
|
|
2050
|
+
url: "/v1/email/domains/{domain_id}/verify",
|
|
2051
|
+
...options
|
|
2052
|
+
});
|
|
1939
2053
|
//#endregion
|
|
1940
2054
|
//#region src/resources/base.ts
|
|
1941
2055
|
var Resource = class {
|
|
@@ -2303,6 +2417,112 @@ var AudiencesResource = class extends Resource {
|
|
|
2303
2417
|
}
|
|
2304
2418
|
};
|
|
2305
2419
|
//#endregion
|
|
2420
|
+
//#region src/resources/domains.ts
|
|
2421
|
+
var DomainsResource = class extends Resource {
|
|
2422
|
+
/**
|
|
2423
|
+
* Register a sending domain. Returns it in `pending` with the `dns_records`
|
|
2424
|
+
* to publish at your DNS provider; call `verify` once they are in place.
|
|
2425
|
+
*
|
|
2426
|
+
* @example Register a sending domain
|
|
2427
|
+
* const domain = await bird.domains.create({ domain: "mail.acme.com" });
|
|
2428
|
+
* console.log(domain.id, domain.status); // "dom_…", "pending"
|
|
2429
|
+
*/
|
|
2430
|
+
create(params, options) {
|
|
2431
|
+
return this.call("POST", options, ({ signal, headers }) => createDomain({
|
|
2432
|
+
client: this.client,
|
|
2433
|
+
body: params,
|
|
2434
|
+
headers,
|
|
2435
|
+
signal
|
|
2436
|
+
}));
|
|
2437
|
+
}
|
|
2438
|
+
/**
|
|
2439
|
+
* List the workspace's sending domains, newest first. `await` resolves the
|
|
2440
|
+
* first page; `for await` walks every domain across pages.
|
|
2441
|
+
*
|
|
2442
|
+
* @example
|
|
2443
|
+
* for await (const domain of bird.domains.list()) {
|
|
2444
|
+
* console.log(domain.id, domain.status);
|
|
2445
|
+
* }
|
|
2446
|
+
*/
|
|
2447
|
+
list(query, options) {
|
|
2448
|
+
return this.paginated("GET", options, ({ signal, headers }, cursor) => listDomains({
|
|
2449
|
+
client: this.client,
|
|
2450
|
+
query: {
|
|
2451
|
+
...query,
|
|
2452
|
+
starting_after: cursor ?? query?.starting_after
|
|
2453
|
+
},
|
|
2454
|
+
headers,
|
|
2455
|
+
signal
|
|
2456
|
+
}));
|
|
2457
|
+
}
|
|
2458
|
+
/**
|
|
2459
|
+
* Fetch a single sending domain by id, with its DNS records and their
|
|
2460
|
+
* per-record verification state.
|
|
2461
|
+
*
|
|
2462
|
+
* @example
|
|
2463
|
+
* const domain = await bird.domains.get("dom_01krdgeqcxet5s7t44vh8rt9mg");
|
|
2464
|
+
*/
|
|
2465
|
+
get(domainId, options) {
|
|
2466
|
+
return this.call("GET", options, ({ signal, headers }) => getDomain({
|
|
2467
|
+
client: this.client,
|
|
2468
|
+
path: { domain_id: domainId },
|
|
2469
|
+
headers,
|
|
2470
|
+
signal
|
|
2471
|
+
}));
|
|
2472
|
+
}
|
|
2473
|
+
/**
|
|
2474
|
+
* Update a sending domain. Only the fields you send change; `settings` apply
|
|
2475
|
+
* immediately, while `return_path`/`tracking`/`dkim` changes are staged until
|
|
2476
|
+
* their new DNS records verify.
|
|
2477
|
+
*
|
|
2478
|
+
* @example
|
|
2479
|
+
* await bird.domains.update("dom_01krdgeqcxet5s7t44vh8rt9mg", {
|
|
2480
|
+
* settings: { click_tracking: true, open_tracking: true },
|
|
2481
|
+
* tracking: { name: "links" },
|
|
2482
|
+
* });
|
|
2483
|
+
*/
|
|
2484
|
+
update(domainId, params, options) {
|
|
2485
|
+
return this.call("PATCH", options, ({ signal, headers }) => updateDomain({
|
|
2486
|
+
client: this.client,
|
|
2487
|
+
path: { domain_id: domainId },
|
|
2488
|
+
body: params,
|
|
2489
|
+
headers,
|
|
2490
|
+
signal
|
|
2491
|
+
}));
|
|
2492
|
+
}
|
|
2493
|
+
/**
|
|
2494
|
+
* Delete a sending domain. Mail already accepted still sends; you can no
|
|
2495
|
+
* longer send new mail from it.
|
|
2496
|
+
*
|
|
2497
|
+
* @example
|
|
2498
|
+
* await bird.domains.delete("dom_01krdgeqcxet5s7t44vh8rt9mg");
|
|
2499
|
+
*/
|
|
2500
|
+
delete(domainId, options) {
|
|
2501
|
+
return this.call("DELETE", options, ({ signal, headers }) => deleteDomain({
|
|
2502
|
+
client: this.client,
|
|
2503
|
+
path: { domain_id: domainId },
|
|
2504
|
+
headers,
|
|
2505
|
+
signal
|
|
2506
|
+
}));
|
|
2507
|
+
}
|
|
2508
|
+
/**
|
|
2509
|
+
* Trigger a fresh DNS check and return the refreshed domain with per-record
|
|
2510
|
+
* results. Safe to repeat while waiting for DNS to propagate.
|
|
2511
|
+
*
|
|
2512
|
+
* @example
|
|
2513
|
+
* const domain = await bird.domains.verify("dom_01krdgeqcxet5s7t44vh8rt9mg");
|
|
2514
|
+
* console.log(domain.status); // "verified" once DNS is in place
|
|
2515
|
+
*/
|
|
2516
|
+
verify(domainId, options) {
|
|
2517
|
+
return this.call("POST", options, ({ signal, headers }) => verifyDomain({
|
|
2518
|
+
client: this.client,
|
|
2519
|
+
path: { domain_id: domainId },
|
|
2520
|
+
headers,
|
|
2521
|
+
signal
|
|
2522
|
+
}));
|
|
2523
|
+
}
|
|
2524
|
+
};
|
|
2525
|
+
//#endregion
|
|
2306
2526
|
//#region src/resources/contactProperties.ts
|
|
2307
2527
|
var ContactPropertiesResource = class extends Resource {
|
|
2308
2528
|
/**
|
|
@@ -2922,6 +3142,8 @@ var BirdClient = class {
|
|
|
2922
3142
|
audiences;
|
|
2923
3143
|
/** Contact properties — `bird.contactProperties.create(...)`, `.list(...)`, `.archive(...)`, … */
|
|
2924
3144
|
contactProperties;
|
|
3145
|
+
/** Sending domains — `bird.domains.create(...)`, `.list(...)`, `.verify(...)`, … */
|
|
3146
|
+
domains;
|
|
2925
3147
|
/** Webhooks — `bird.webhooks.unwrap(payload, headers)` verifies an inbound delivery. */
|
|
2926
3148
|
webhooks;
|
|
2927
3149
|
constructor(options) {
|
|
@@ -2931,9 +3153,9 @@ var BirdClient = class {
|
|
|
2931
3153
|
this.#headers = {
|
|
2932
3154
|
...opts.defaultHeaders,
|
|
2933
3155
|
Authorization: `Bearer ${opts.apiKey}`,
|
|
2934
|
-
"User-Agent": `bird-sdk-js/0.
|
|
3156
|
+
"User-Agent": `bird-sdk-js/0.8.1`,
|
|
2935
3157
|
"Bird-Surface": "sdk-js",
|
|
2936
|
-
"Bird-Version": "0.
|
|
3158
|
+
"Bird-Version": "0.8.1"
|
|
2937
3159
|
};
|
|
2938
3160
|
const caller = detectCaller();
|
|
2939
3161
|
if (caller) this.#headers["Bird-Caller"] = caller;
|
|
@@ -2955,6 +3177,7 @@ var BirdClient = class {
|
|
|
2955
3177
|
this.contacts = new ContactsResource(this.core, this.#client);
|
|
2956
3178
|
this.audiences = new AudiencesResource(this.core, this.#client);
|
|
2957
3179
|
this.contactProperties = new ContactPropertiesResource(this.core, this.#client);
|
|
3180
|
+
this.domains = new DomainsResource(this.core, this.#client);
|
|
2958
3181
|
this.webhooks = new WebhooksResource(opts.webhooks);
|
|
2959
3182
|
}
|
|
2960
3183
|
/**
|
|
@@ -3050,7 +3273,12 @@ const WebhookEventType = {
|
|
|
3050
3273
|
SmsFailed: "sms.failed",
|
|
3051
3274
|
SmsRejected: "sms.rejected",
|
|
3052
3275
|
SmsSent: "sms.sent",
|
|
3053
|
-
SmsUndelivered: "sms.undelivered"
|
|
3276
|
+
SmsUndelivered: "sms.undelivered",
|
|
3277
|
+
WhatsappAccepted: "whatsapp.accepted",
|
|
3278
|
+
WhatsappDelivered: "whatsapp.delivered",
|
|
3279
|
+
WhatsappFailed: "whatsapp.failed",
|
|
3280
|
+
WhatsappRead: "whatsapp.read",
|
|
3281
|
+
WhatsappSent: "whatsapp.sent"
|
|
3054
3282
|
};
|
|
3055
3283
|
//#endregion
|
|
3056
3284
|
export { BirdAPIError, BirdAuthError, BirdBadRequestError, BirdBillingError, BirdClient, BirdConflictError, BirdConnectionError, BirdError, BirdInternalError, BirdMisdirectedError, BirdNotFoundError, BirdNotImplementedError, BirdPayloadTooLargeError, BirdPermissionError, BirdPreconditionError, BirdRateLimitError, BirdServiceUnavailableError, BirdTimeoutError, BirdValidationError, BirdWebhookVerificationError, WebhookEventType, baseUrlForRegion, regionFromApiKey };
|