@unboundcx/sdk 2.7.7 → 2.8.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.
@@ -0,0 +1,109 @@
1
+ export class EmailAnalyticsService {
2
+ constructor(sdk) {
3
+ this.sdk = sdk;
4
+ }
5
+
6
+ /**
7
+ * Get email queue time series analytics
8
+ * @param {Object} [params] - Analytics parameters
9
+ * @param {string} [params.period='24h'] - Time period: '1h', '6h', '24h', '7d', '30d'
10
+ * @param {string} [params.granularity='hour'] - Data granularity: 'minute', 'hour', 'day'
11
+ * @param {string} [params.timezone='UTC'] - Timezone for data grouping (e.g., 'America/New_York', 'UTC')
12
+ * @returns {Promise<Object>} Time series data with summary statistics
13
+ * @example
14
+ * // Get hourly analytics for last 24 hours in EST
15
+ * const analytics = await sdk.messaging.email.analytics.timeSeries({
16
+ * period: '24h',
17
+ * granularity: 'hour',
18
+ * timezone: 'America/New_York'
19
+ * });
20
+ * // Returns: { period, granularity, timezone, data: [{ timestamp, sent, delivered, failed, queued }], summary }
21
+ */
22
+ async timeSeries({ period, granularity, timezone } = {}) {
23
+ const options = { query: {} };
24
+ if (period) options.query.period = period;
25
+ if (granularity) options.query.granularity = granularity;
26
+ if (timezone) options.query.timezone = timezone;
27
+
28
+ const result = await this.sdk._fetch(
29
+ '/messaging/email/analytics/timeseries',
30
+ 'GET',
31
+ options,
32
+ );
33
+ return result;
34
+ }
35
+
36
+ /**
37
+ * Get email queue summary statistics including engagement metrics
38
+ * @param {Object} [params] - Summary parameters
39
+ * @param {string} [params.period='24h'] - Time period: '1h', '6h', '24h', '7d', '30d'
40
+ * @param {string} [params.timezone='UTC'] - Timezone for data calculation (e.g., 'America/New_York', 'UTC')
41
+ * @returns {Promise<Object>} Summary statistics with engagement metrics
42
+ * @example
43
+ * // Get comprehensive summary stats for last 24 hours in PST
44
+ * const summary = await sdk.messaging.email.analytics.summary({
45
+ * period: '24h',
46
+ * timezone: 'America/Los_Angeles'
47
+ * });
48
+ * // Returns: {
49
+ * // totalSent, totalDelivered, totalFailed, totalQueued,
50
+ * // deliveryRate, errorRate, avgProcessingSeconds, avgEmailsPerHour, avgEmailsPerMinute,
51
+ * // totalReceived, avgReceivedPerHour, avgReceivedPerMinute,
52
+ * // totalOpened, totalOpenEvents, openRate,
53
+ * // totalClicked, totalClickEvents, clickRate,
54
+ * // totalBounced, totalBounceEvents, bounceRate,
55
+ * // totalComplained, totalComplaintEvents, complaintRate,
56
+ * // outboundErrors: [{ id, errorMessage, toEmail, createdAt }]
57
+ * // }
58
+ */
59
+ async summary({ period, timezone } = {}) {
60
+ const options = { query: {} };
61
+ if (period) options.query.period = period;
62
+ if (timezone) options.query.timezone = timezone;
63
+
64
+ const result = await this.sdk._fetch(
65
+ '/messaging/email/analytics/summary',
66
+ 'GET',
67
+ options,
68
+ );
69
+ return result;
70
+ }
71
+
72
+ /**
73
+ * Get real-time email queue metrics
74
+ * @returns {Promise<Object>} Real-time queue statistics
75
+ * @example
76
+ * // Get current queue status
77
+ * const realtime = await sdk.messaging.email.analytics.realtime();
78
+ * // Returns: { queueDepth, currentSendRatePerMinute, last5Minutes: { sent, delivered, failed } }
79
+ */
80
+ async realtime() {
81
+ const result = await this.sdk._fetch(
82
+ '/messaging/email/analytics/realtime',
83
+ 'GET',
84
+ );
85
+ return result;
86
+ }
87
+
88
+ /**
89
+ * Get email error analysis by domain
90
+ * @param {Object} [params] - Error analysis parameters
91
+ * @param {string} [params.period='7d'] - Time period: '24h', '7d', '30d'
92
+ * @returns {Promise<Object>} Error analysis with domain breakdown
93
+ * @example
94
+ * // Get error analysis for last 7 days
95
+ * const errors = await sdk.messaging.email.analytics.errors({ period: '7d' });
96
+ * // Returns: { overallErrorRate, topErrorDomains: [{ domain, errorRate, totalErrors }] }
97
+ */
98
+ async errors({ period } = {}) {
99
+ const options = { query: {} };
100
+ if (period) options.query.period = period;
101
+
102
+ const result = await this.sdk._fetch(
103
+ '/messaging/email/analytics/errors',
104
+ 'GET',
105
+ options,
106
+ );
107
+ return result;
108
+ }
109
+ }
@@ -0,0 +1,252 @@
1
+ export class EmailDomainsService {
2
+ constructor(sdk) {
3
+ this.sdk = sdk;
4
+ }
5
+
6
+ /**
7
+ * Create domain verification
8
+ * @param {Object} params - Domain parameters
9
+ * @param {string} params.domain - Domain name (required)
10
+ * @param {string} [params.primaryRegion] - Primary AWS region
11
+ * @param {string} [params.secondaryRegion] - Secondary AWS region
12
+ * @param {string} [params.mailFromSubdomain='mail'] - Mail-from subdomain
13
+ * @returns {Promise<Object>} Created domain with DNS records to configure
14
+ */
15
+ async create({ domain, primaryRegion, secondaryRegion, mailFromSubdomain }) {
16
+ this.sdk.validateParams(
17
+ { domain },
18
+ {
19
+ domain: { type: 'string', required: true },
20
+ primaryRegion: { type: 'string', required: false },
21
+ secondaryRegion: { type: 'string', required: false },
22
+ mailFromSubdomain: { type: 'string', required: false },
23
+ },
24
+ );
25
+
26
+ const domainData = { domain };
27
+ if (primaryRegion) domainData.primaryRegion = primaryRegion;
28
+ if (secondaryRegion) domainData.secondaryRegion = secondaryRegion;
29
+ if (mailFromSubdomain) domainData.mailFromSubdomain = mailFromSubdomain;
30
+
31
+ const options = {
32
+ body: domainData,
33
+ };
34
+
35
+ const result = await this.sdk._fetch(
36
+ '/messaging/email/validate/domain',
37
+ 'POST',
38
+ options,
39
+ );
40
+ return result;
41
+ }
42
+
43
+ /**
44
+ * Delete domain verification
45
+ * @param {string} domainId - Domain ID (required)
46
+ * @returns {Promise<Object>} Deletion confirmation
47
+ */
48
+ async delete(domainId) {
49
+ this.sdk.validateParams(
50
+ { domainId },
51
+ {
52
+ domainId: { type: 'string', required: true },
53
+ },
54
+ );
55
+
56
+ const options = {
57
+ body: { domainId },
58
+ };
59
+
60
+ const result = await this.sdk._fetch(
61
+ '/messaging/email/validate/domain',
62
+ 'DELETE',
63
+ options,
64
+ );
65
+ return result;
66
+ }
67
+
68
+ /**
69
+ * List all verified domains
70
+ * @returns {Promise<Array>} List of verified domains with status, regions, and portal information
71
+ * @example
72
+ * // Returns array of domain objects:
73
+ * // {
74
+ * // id: 'domain-id',
75
+ * // domain: 'mydomain.com',
76
+ * // primaryRegion: 'us-east-1',
77
+ * // secondaryRegion: 'us-west-2',
78
+ * // primaryRegionStatus: 'active',
79
+ * // secondaryRegionStatus: 'active',
80
+ * // portalId: 'portal-id',
81
+ * // portalName: 'My Portal',
82
+ * // recordTypeId: 'record-type-id',
83
+ * // isDeleted: false,
84
+ * // createdAt: '2023-...'
85
+ * // }
86
+ */
87
+ async list() {
88
+ const result = await this.sdk._fetch(
89
+ '/messaging/email/validate/domain',
90
+ 'GET',
91
+ );
92
+ return result;
93
+ }
94
+
95
+ /**
96
+ * Get domain details by ID including DNS configuration
97
+ * @param {string} domainId - Domain ID (required)
98
+ * @returns {Promise<Object>} Domain details with DNS records to configure
99
+ * @example
100
+ * // Returns domain object with DNS records:
101
+ * // {
102
+ * // id: 'domain-id',
103
+ * // domain: 'mydomain.com',
104
+ * // primaryRegion: 'us-east-1',
105
+ * // secondaryRegion: 'us-west-2',
106
+ * // primaryRegionStatus: 'active',
107
+ * // secondaryRegionStatus: 'active',
108
+ * // mailFrom: 'mail.mydomain.com',
109
+ * // portalId: 'portal-id',
110
+ * // portalName: 'My Portal',
111
+ * // brandId: 'brand-id',
112
+ * // recordTypeId: 'record-type-id',
113
+ * // createdAt: '2023-...',
114
+ * // dns: [
115
+ * // {
116
+ * // type: 'CNAME',
117
+ * // name: 'domainid._domainkey.mydomain.com',
118
+ * // value: 'domainid.dkim.example.com',
119
+ * // description: 'DKIM signature verification'
120
+ * // },
121
+ * // {
122
+ * // type: 'CNAME',
123
+ * // name: 'mail.mydomain.com',
124
+ * // value: 'mail.ses.amazonaws.com',
125
+ * // description: 'MAIL FROM domain routing'
126
+ * // },
127
+ * // {
128
+ * // type: 'TXT',
129
+ * // name: 'mydomain.com',
130
+ * // value: '"v=spf1 include:mail.mydomain.com ~all"',
131
+ * // description: 'SPF record for email authentication'
132
+ * // },
133
+ * // {
134
+ * // type: 'TXT',
135
+ * // name: '_dmarc.mydomain.com',
136
+ * // value: '"v=DMARC1; p=quarantine; rua=mailto:dmarc@...',
137
+ * // description: 'DMARC policy for email authentication and reporting'
138
+ * // }
139
+ * // ]
140
+ * // }
141
+ */
142
+ async get(domainId) {
143
+ this.sdk.validateParams(
144
+ { domainId },
145
+ {
146
+ domainId: { type: 'string', required: true },
147
+ },
148
+ );
149
+
150
+ const result = await this.sdk._fetch(
151
+ `/messaging/email/validate/domain/${domainId}`,
152
+ 'GET',
153
+ );
154
+ return result;
155
+ }
156
+
157
+ /**
158
+ * Validate DNS records for domain
159
+ * @param {string} domain - Domain name (required)
160
+ * @returns {Promise<Object>} DNS validation results
161
+ */
162
+ async validateDns(domain) {
163
+ this.sdk.validateParams(
164
+ { domain },
165
+ {
166
+ domain: { type: 'string', required: true },
167
+ },
168
+ );
169
+
170
+ const options = {
171
+ query: { domain },
172
+ };
173
+
174
+ const result = await this.sdk._fetch(
175
+ '/messaging/email/validate/domain/dns',
176
+ 'GET',
177
+ options,
178
+ );
179
+ return result;
180
+ }
181
+
182
+ /**
183
+ * Check domain verification status
184
+ * @param {string} domain - Domain name (required)
185
+ * @returns {Promise<Object>} Domain verification status
186
+ */
187
+ async checkStatus(domain) {
188
+ this.sdk.validateParams(
189
+ { domain },
190
+ {
191
+ domain: { type: 'string', required: true },
192
+ },
193
+ );
194
+
195
+ const options = {
196
+ query: { domain },
197
+ };
198
+
199
+ const result = await this.sdk._fetch(
200
+ '/messaging/email/validate/domain/status',
201
+ 'GET',
202
+ options,
203
+ );
204
+ return result;
205
+ }
206
+
207
+ /**
208
+ * Update domain settings
209
+ * @param {Object} params - Update parameters
210
+ * @param {string} params.domainId - Domain ID (required)
211
+ * @param {string} [params.primaryRegion] - Primary AWS region
212
+ * @param {string} [params.secondaryRegion] - Secondary AWS region
213
+ * @param {boolean} [params.dkimEnabled] - Enable DKIM signing
214
+ * @param {Object} [params.customDkim] - Custom DKIM configuration
215
+ * @returns {Promise<Object>} Updated domain details
216
+ */
217
+ async update({
218
+ domainId,
219
+ primaryRegion,
220
+ secondaryRegion,
221
+ dkimEnabled,
222
+ customDkim,
223
+ }) {
224
+ this.sdk.validateParams(
225
+ { domainId },
226
+ {
227
+ domainId: { type: 'string', required: true },
228
+ primaryRegion: { type: 'string', required: false },
229
+ secondaryRegion: { type: 'string', required: false },
230
+ dkimEnabled: { type: 'boolean', required: false },
231
+ customDkim: { type: 'object', required: false },
232
+ },
233
+ );
234
+
235
+ const updateData = { domainId };
236
+ if (primaryRegion) updateData.primaryRegion = primaryRegion;
237
+ if (secondaryRegion) updateData.secondaryRegion = secondaryRegion;
238
+ if (dkimEnabled !== undefined) updateData.dkimEnabled = dkimEnabled;
239
+ if (customDkim) updateData.customDkim = customDkim;
240
+
241
+ const options = {
242
+ body: updateData,
243
+ };
244
+
245
+ const result = await this.sdk._fetch(
246
+ '/messaging/email/validate/domain',
247
+ 'PUT',
248
+ options,
249
+ );
250
+ return result;
251
+ }
252
+ }