@unboundcx/sdk 2.7.5 → 2.7.7
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/base.js +6 -4
- package/package.json +1 -1
- package/services/messaging.js +124 -10
package/base.js
CHANGED
|
@@ -324,12 +324,14 @@ export class BaseSDK {
|
|
|
324
324
|
responseHeaders?.get?.('x-request-id') ||
|
|
325
325
|
responseHeaders?.['x-request-id'] || '';
|
|
326
326
|
|
|
327
|
+
const contentType = responseHeaders?.get?.('content-type') || response.headers['content-type'];
|
|
328
|
+
|
|
327
329
|
if (!response.ok) {
|
|
328
330
|
let errorBody;
|
|
329
331
|
if (response?.body) {
|
|
330
332
|
errorBody = response.body;
|
|
331
333
|
} else if (response?.headers?.['content-type']) {
|
|
332
|
-
|
|
334
|
+
|
|
333
335
|
try {
|
|
334
336
|
if (typeof response?.json === 'function' || typeof response?.text === 'function') {
|
|
335
337
|
if (contentType.includes('application/json')) {
|
|
@@ -372,10 +374,10 @@ export class BaseSDK {
|
|
|
372
374
|
}
|
|
373
375
|
|
|
374
376
|
let responseBody;
|
|
375
|
-
if (response?.body) {
|
|
377
|
+
if (response?.body && !contentType) {
|
|
376
378
|
responseBody = response.body;
|
|
377
|
-
} else if (
|
|
378
|
-
|
|
379
|
+
} else if (contentType) {
|
|
380
|
+
|
|
379
381
|
try {
|
|
380
382
|
if (transport === 'https') {
|
|
381
383
|
if (contentType.includes('application/json')) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unboundcx/sdk",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.7",
|
|
4
4
|
"description": "Official JavaScript SDK for the Unbound API - A comprehensive toolkit for integrating with Unbound's communication, AI, and data management services",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
package/services/messaging.js
CHANGED
|
@@ -213,6 +213,7 @@ export class EmailService {
|
|
|
213
213
|
this.domains = new EmailDomainsService(sdk);
|
|
214
214
|
this.addresses = new EmailAddressesService(sdk);
|
|
215
215
|
this.analytics = new EmailAnalyticsService(sdk);
|
|
216
|
+
this.queue = new EmailQueueService(sdk);
|
|
216
217
|
}
|
|
217
218
|
|
|
218
219
|
/**
|
|
@@ -1920,34 +1921,54 @@ export class EmailAnalyticsService {
|
|
|
1920
1921
|
* @param {Object} [params] - Analytics parameters
|
|
1921
1922
|
* @param {string} [params.period='24h'] - Time period: '1h', '6h', '24h', '7d', '30d'
|
|
1922
1923
|
* @param {string} [params.granularity='hour'] - Data granularity: 'minute', 'hour', 'day'
|
|
1924
|
+
* @param {string} [params.timezone='UTC'] - Timezone for data grouping (e.g., 'America/New_York', 'UTC')
|
|
1923
1925
|
* @returns {Promise<Object>} Time series data with summary statistics
|
|
1924
1926
|
* @example
|
|
1925
|
-
* // Get hourly analytics for last 24 hours
|
|
1926
|
-
* const analytics = await sdk.messaging.email.analytics.timeSeries({
|
|
1927
|
-
*
|
|
1927
|
+
* // Get hourly analytics for last 24 hours in EST
|
|
1928
|
+
* const analytics = await sdk.messaging.email.analytics.timeSeries({
|
|
1929
|
+
* period: '24h',
|
|
1930
|
+
* granularity: 'hour',
|
|
1931
|
+
* timezone: 'America/New_York'
|
|
1932
|
+
* });
|
|
1933
|
+
* // Returns: { period, granularity, timezone, data: [{ timestamp, sent, delivered, failed, queued }], summary }
|
|
1928
1934
|
*/
|
|
1929
|
-
async timeSeries({ period, granularity } = {}) {
|
|
1935
|
+
async timeSeries({ period, granularity, timezone } = {}) {
|
|
1930
1936
|
const options = { query: {} };
|
|
1931
1937
|
if (period) options.query.period = period;
|
|
1932
1938
|
if (granularity) options.query.granularity = granularity;
|
|
1939
|
+
if (timezone) options.query.timezone = timezone;
|
|
1933
1940
|
|
|
1934
1941
|
const result = await this.sdk._fetch('/messaging/email/analytics/timeseries', 'GET', options);
|
|
1935
1942
|
return result;
|
|
1936
1943
|
}
|
|
1937
1944
|
|
|
1938
1945
|
/**
|
|
1939
|
-
* Get email queue summary statistics
|
|
1946
|
+
* Get email queue summary statistics including engagement metrics
|
|
1940
1947
|
* @param {Object} [params] - Summary parameters
|
|
1941
1948
|
* @param {string} [params.period='24h'] - Time period: '1h', '6h', '24h', '7d', '30d'
|
|
1942
|
-
* @
|
|
1949
|
+
* @param {string} [params.timezone='UTC'] - Timezone for data calculation (e.g., 'America/New_York', 'UTC')
|
|
1950
|
+
* @returns {Promise<Object>} Summary statistics with engagement metrics
|
|
1943
1951
|
* @example
|
|
1944
|
-
* // Get summary stats for last 24 hours
|
|
1945
|
-
* const summary = await sdk.messaging.email.analytics.summary({
|
|
1946
|
-
*
|
|
1952
|
+
* // Get comprehensive summary stats for last 24 hours in PST
|
|
1953
|
+
* const summary = await sdk.messaging.email.analytics.summary({
|
|
1954
|
+
* period: '24h',
|
|
1955
|
+
* timezone: 'America/Los_Angeles'
|
|
1956
|
+
* });
|
|
1957
|
+
* // Returns: {
|
|
1958
|
+
* // totalSent, totalDelivered, totalFailed, totalQueued,
|
|
1959
|
+
* // deliveryRate, errorRate, avgProcessingSeconds, avgEmailsPerHour, avgEmailsPerMinute,
|
|
1960
|
+
* // totalReceived, avgReceivedPerHour, avgReceivedPerMinute,
|
|
1961
|
+
* // totalOpened, totalOpenEvents, openRate,
|
|
1962
|
+
* // totalClicked, totalClickEvents, clickRate,
|
|
1963
|
+
* // totalBounced, totalBounceEvents, bounceRate,
|
|
1964
|
+
* // totalComplained, totalComplaintEvents, complaintRate,
|
|
1965
|
+
* // outboundErrors: [{ id, errorMessage, toEmail, createdAt }]
|
|
1966
|
+
* // }
|
|
1947
1967
|
*/
|
|
1948
|
-
async summary({ period } = {}) {
|
|
1968
|
+
async summary({ period, timezone } = {}) {
|
|
1949
1969
|
const options = { query: {} };
|
|
1950
1970
|
if (period) options.query.period = period;
|
|
1971
|
+
if (timezone) options.query.timezone = timezone;
|
|
1951
1972
|
|
|
1952
1973
|
const result = await this.sdk._fetch('/messaging/email/analytics/summary', 'GET', options);
|
|
1953
1974
|
return result;
|
|
@@ -1984,3 +2005,96 @@ export class EmailAnalyticsService {
|
|
|
1984
2005
|
return result;
|
|
1985
2006
|
}
|
|
1986
2007
|
}
|
|
2008
|
+
|
|
2009
|
+
export class EmailQueueService {
|
|
2010
|
+
constructor(sdk) {
|
|
2011
|
+
this.sdk = sdk;
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
/**
|
|
2015
|
+
* Get email queue items with pagination and status filtering
|
|
2016
|
+
* @param {Object} [params] - Queue query parameters
|
|
2017
|
+
* @param {number} [params.page=1] - Page number (1-based)
|
|
2018
|
+
* @param {number} [params.limit=50] - Number of items per page (max 100)
|
|
2019
|
+
* @param {string} [params.status='queued'] - Filter by status: 'queued', 'sent', 'delivered', 'failed'
|
|
2020
|
+
* @returns {Promise<Object>} Paginated queue items with metadata
|
|
2021
|
+
* @example
|
|
2022
|
+
* // Get first page of queued emails
|
|
2023
|
+
* const queue = await sdk.messaging.email.queue.list({ page: 1, limit: 25, status: 'queued' });
|
|
2024
|
+
* // Returns: {
|
|
2025
|
+
* // items: [{
|
|
2026
|
+
* // id, status, to, from, subject, carrier, carrierId,
|
|
2027
|
+
* // createdAt, lastStatusUpdatedAt, processingTimeSeconds
|
|
2028
|
+
* // }],
|
|
2029
|
+
* // pagination: {
|
|
2030
|
+
* // page, limit, totalItems, totalPages, hasNextPage, hasPreviousPage
|
|
2031
|
+
* // },
|
|
2032
|
+
* // filter: { status }
|
|
2033
|
+
* // }
|
|
2034
|
+
*/
|
|
2035
|
+
async list({ page, limit, status } = {}) {
|
|
2036
|
+
const options = { query: {} };
|
|
2037
|
+
if (page !== undefined) options.query.page = page;
|
|
2038
|
+
if (limit !== undefined) options.query.limit = limit;
|
|
2039
|
+
if (status) options.query.status = status;
|
|
2040
|
+
|
|
2041
|
+
const result = await this.sdk._fetch('/messaging/email/queue', 'GET', options);
|
|
2042
|
+
return result;
|
|
2043
|
+
}
|
|
2044
|
+
|
|
2045
|
+
/**
|
|
2046
|
+
* Get queued emails only (convenience method)
|
|
2047
|
+
* @param {Object} [params] - Query parameters
|
|
2048
|
+
* @param {number} [params.page=1] - Page number (1-based)
|
|
2049
|
+
* @param {number} [params.limit=50] - Number of items per page (max 100)
|
|
2050
|
+
* @returns {Promise<Object>} Paginated queued emails
|
|
2051
|
+
* @example
|
|
2052
|
+
* // Get pending emails waiting to be sent
|
|
2053
|
+
* const pending = await sdk.messaging.email.queue.getQueued({ page: 1, limit: 50 });
|
|
2054
|
+
*/
|
|
2055
|
+
async getQueued({ page, limit } = {}) {
|
|
2056
|
+
return this.list({ page, limit, status: 'queued' });
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
/**
|
|
2060
|
+
* Get failed emails only (convenience method)
|
|
2061
|
+
* @param {Object} [params] - Query parameters
|
|
2062
|
+
* @param {number} [params.page=1] - Page number (1-based)
|
|
2063
|
+
* @param {number} [params.limit=50] - Number of items per page (max 100)
|
|
2064
|
+
* @returns {Promise<Object>} Paginated failed emails
|
|
2065
|
+
* @example
|
|
2066
|
+
* // Get emails that failed to send
|
|
2067
|
+
* const failed = await sdk.messaging.email.queue.getFailed({ page: 1, limit: 50 });
|
|
2068
|
+
*/
|
|
2069
|
+
async getFailed({ page, limit } = {}) {
|
|
2070
|
+
return this.list({ page, limit, status: 'failed' });
|
|
2071
|
+
}
|
|
2072
|
+
|
|
2073
|
+
/**
|
|
2074
|
+
* Get sent emails only (convenience method)
|
|
2075
|
+
* @param {Object} [params] - Query parameters
|
|
2076
|
+
* @param {number} [params.page=1] - Page number (1-based)
|
|
2077
|
+
* @param {number} [params.limit=50] - Number of items per page (max 100)
|
|
2078
|
+
* @returns {Promise<Object>} Paginated sent emails
|
|
2079
|
+
* @example
|
|
2080
|
+
* // Get emails that have been sent successfully
|
|
2081
|
+
* const sent = await sdk.messaging.email.queue.getSent({ page: 1, limit: 50 });
|
|
2082
|
+
*/
|
|
2083
|
+
async getSent({ page, limit } = {}) {
|
|
2084
|
+
return this.list({ page, limit, status: 'sent' });
|
|
2085
|
+
}
|
|
2086
|
+
|
|
2087
|
+
/**
|
|
2088
|
+
* Get delivered emails only (convenience method)
|
|
2089
|
+
* @param {Object} [params] - Query parameters
|
|
2090
|
+
* @param {number} [params.page=1] - Page number (1-based)
|
|
2091
|
+
* @param {number} [params.limit=50] - Number of items per page (max 100)
|
|
2092
|
+
* @returns {Promise<Object>} Paginated delivered emails
|
|
2093
|
+
* @example
|
|
2094
|
+
* // Get emails that have been delivered to recipients
|
|
2095
|
+
* const delivered = await sdk.messaging.email.queue.getDelivered({ page: 1, limit: 50 });
|
|
2096
|
+
*/
|
|
2097
|
+
async getDelivered({ page, limit } = {}) {
|
|
2098
|
+
return this.list({ page, limit, status: 'delivered' });
|
|
2099
|
+
}
|
|
2100
|
+
}
|