@unsent/sdk 1.0.2 → 1.0.3

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.js CHANGED
@@ -20,8 +20,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ analytics: () => Analytics,
23
24
  campaigns: () => Campaigns,
24
- unsent: () => unsent
25
+ contactBooks: () => ContactBooks,
26
+ templates: () => Templates,
27
+ unsent: () => unsent,
28
+ webhooks: () => Webhooks
25
29
  });
26
30
  module.exports = __toCommonJS(index_exports);
27
31
 
@@ -31,6 +35,9 @@ var Contacts = class {
31
35
  this.unsent = unsent2;
32
36
  this.unsent = unsent2;
33
37
  }
38
+ async list(contactBookId) {
39
+ return this.unsent.get(`/contactBooks/${contactBookId}/contacts`);
40
+ }
34
41
  async create(contactBookId, payload) {
35
42
  const data = await this.unsent.post(
36
43
  `/contactBooks/${contactBookId}/contacts`,
@@ -105,6 +112,71 @@ var Emails = class {
105
112
  error: response.error
106
113
  };
107
114
  }
115
+ async list(query) {
116
+ const params = new URLSearchParams();
117
+ if (query?.page) params.append("page", query.page.toString());
118
+ if (query?.limit) params.append("limit", query.limit.toString());
119
+ if (query?.startDate) params.append("startDate", query.startDate);
120
+ if (query?.endDate) params.append("endDate", query.endDate);
121
+ if (query?.domainId) {
122
+ if (Array.isArray(query.domainId)) {
123
+ query.domainId.forEach((id) => params.append("domainId", id));
124
+ } else {
125
+ params.append("domainId", query.domainId);
126
+ }
127
+ }
128
+ const queryString = params.toString() ? `?${params.toString()}` : "";
129
+ const response = await this.unsent.get(
130
+ `/emails${queryString}`
131
+ );
132
+ return {
133
+ data: response.data?.data ?? null,
134
+ count: response.data?.count ?? null,
135
+ error: response.error
136
+ };
137
+ }
138
+ async getComplaints(query) {
139
+ const params = new URLSearchParams();
140
+ if (query?.page) params.append("page", query.page.toString());
141
+ if (query?.limit) params.append("limit", query.limit.toString());
142
+ const queryString = params.toString() ? `?${params.toString()}` : "";
143
+ const response = await this.unsent.get(
144
+ `/emails/complaints${queryString}`
145
+ );
146
+ return {
147
+ data: response.data?.data ?? null,
148
+ count: response.data?.count ?? null,
149
+ error: response.error
150
+ };
151
+ }
152
+ async getBounces(query) {
153
+ const params = new URLSearchParams();
154
+ if (query?.page) params.append("page", query.page.toString());
155
+ if (query?.limit) params.append("limit", query.limit.toString());
156
+ const queryString = params.toString() ? `?${params.toString()}` : "";
157
+ const response = await this.unsent.get(
158
+ `/emails/bounces${queryString}`
159
+ );
160
+ return {
161
+ data: response.data?.data ?? null,
162
+ count: response.data?.count ?? null,
163
+ error: response.error
164
+ };
165
+ }
166
+ async getUnsubscribes(query) {
167
+ const params = new URLSearchParams();
168
+ if (query?.page) params.append("page", query.page.toString());
169
+ if (query?.limit) params.append("limit", query.limit.toString());
170
+ const queryString = params.toString() ? `?${params.toString()}` : "";
171
+ const response = await this.unsent.get(
172
+ `/emails/unsubscribes${queryString}`
173
+ );
174
+ return {
175
+ data: response.data?.data ?? null,
176
+ count: response.data?.count ?? null,
177
+ error: response.error
178
+ };
179
+ }
108
180
  async get(id) {
109
181
  const data = await this.unsent.get(
110
182
  `/emails/${id}`
@@ -165,12 +237,109 @@ var Domains = class {
165
237
  }
166
238
  };
167
239
 
240
+ // src/contact-book.ts
241
+ var ContactBooks = class {
242
+ constructor(unsent2) {
243
+ this.unsent = unsent2;
244
+ this.unsent = unsent2;
245
+ }
246
+ async list() {
247
+ return this.unsent.get("/contactBooks");
248
+ }
249
+ async create(payload) {
250
+ return this.unsent.post("/contactBooks", payload);
251
+ }
252
+ async get(id) {
253
+ return this.unsent.get(`/contactBooks/${id}`);
254
+ }
255
+ async update(id, payload) {
256
+ return this.unsent.patch(`/contactBooks/${id}`, payload);
257
+ }
258
+ async delete(id) {
259
+ return this.unsent.delete(`/contactBooks/${id}`);
260
+ }
261
+ };
262
+
263
+ // src/template.ts
264
+ var Templates = class {
265
+ constructor(unsent2) {
266
+ this.unsent = unsent2;
267
+ this.unsent = unsent2;
268
+ }
269
+ async list() {
270
+ return this.unsent.get("/templates");
271
+ }
272
+ async create(payload) {
273
+ return this.unsent.post("/templates", payload);
274
+ }
275
+ async get(id) {
276
+ return this.unsent.get(`/templates/${id}`);
277
+ }
278
+ async update(id, payload) {
279
+ return this.unsent.patch(`/templates/${id}`, payload);
280
+ }
281
+ async delete(id) {
282
+ return this.unsent.delete(`/templates/${id}`);
283
+ }
284
+ };
285
+
286
+ // src/webhook.ts
287
+ var Webhooks = class {
288
+ constructor(unsent2) {
289
+ this.unsent = unsent2;
290
+ this.unsent = unsent2;
291
+ }
292
+ async list() {
293
+ return this.unsent.get("/webhooks");
294
+ }
295
+ async create(payload) {
296
+ return this.unsent.post("/webhooks", payload);
297
+ }
298
+ async update(id, payload) {
299
+ return this.unsent.patch(`/webhooks/${id}`, payload);
300
+ }
301
+ async delete(id) {
302
+ return this.unsent.delete(`/webhooks/${id}`);
303
+ }
304
+ };
305
+
306
+ // src/analytics.ts
307
+ var Analytics = class {
308
+ constructor(unsent2) {
309
+ this.unsent = unsent2;
310
+ this.unsent = unsent2;
311
+ }
312
+ async get(query) {
313
+ return this.unsent.get("/analytics");
314
+ }
315
+ async getTimeSeries(query) {
316
+ const params = new URLSearchParams();
317
+ if (query?.days) params.append("days", query.days.toString());
318
+ if (query?.domain) params.append("domain", query.domain);
319
+ const queryString = params.toString() ? `?${params.toString()}` : "";
320
+ return this.unsent.get(
321
+ `/analytics/time-series${queryString}`
322
+ );
323
+ }
324
+ async getReputation(query) {
325
+ const params = new URLSearchParams();
326
+ if (query?.domain) params.append("domain", query.domain);
327
+ const queryString = params.toString() ? `?${params.toString()}` : "";
328
+ return this.unsent.get(
329
+ `/analytics/reputation${queryString}`
330
+ );
331
+ }
332
+ };
333
+
168
334
  // src/campaign.ts
169
335
  var Campaigns = class {
170
336
  constructor(unsent2) {
171
337
  this.unsent = unsent2;
172
338
  this.unsent = unsent2;
173
339
  }
340
+ async list() {
341
+ return this.unsent.get("/campaigns");
342
+ }
174
343
  async create(payload) {
175
344
  const data = await this.unsent.post(
176
345
  `/campaigns`,
@@ -207,6 +376,55 @@ var Campaigns = class {
207
376
  }
208
377
  };
209
378
 
379
+ // src/suppression.ts
380
+ var Suppressions = class {
381
+ constructor(unsent2) {
382
+ this.unsent = unsent2;
383
+ this.unsent = unsent2;
384
+ }
385
+ async list(query) {
386
+ const params = new URLSearchParams();
387
+ if (query?.page) params.append("page", query.page.toString());
388
+ if (query?.limit) params.append("limit", query.limit.toString());
389
+ const queryString = params.toString() ? `?${params.toString()}` : "";
390
+ return this.unsent.get(`/suppressions${queryString}`);
391
+ }
392
+ async add(payload) {
393
+ return this.unsent.post("/suppressions", payload);
394
+ }
395
+ async delete(email) {
396
+ return this.unsent.delete(`/suppressions/email/${email}`);
397
+ }
398
+ };
399
+
400
+ // src/api-key.ts
401
+ var ApiKeys = class {
402
+ constructor(unsent2) {
403
+ this.unsent = unsent2;
404
+ this.unsent = unsent2;
405
+ }
406
+ async list() {
407
+ return this.unsent.get("/api-keys");
408
+ }
409
+ async create(payload) {
410
+ return this.unsent.post("/api-keys", payload);
411
+ }
412
+ async delete(id) {
413
+ return this.unsent.delete(`/api-keys/${id}`);
414
+ }
415
+ };
416
+
417
+ // src/settings.ts
418
+ var Settings = class {
419
+ constructor(unsent2) {
420
+ this.unsent = unsent2;
421
+ this.unsent = unsent2;
422
+ }
423
+ async get() {
424
+ return this.unsent.get("/settings");
425
+ }
426
+ };
427
+
210
428
  // src/unsent.ts
211
429
  var defaultBaseUrl = "https://api.unsent.dev";
212
430
  var baseUrl = `${process?.env?.UNSENT_BASE_URL ?? process?.env?.UNSENT_BASE_URL ?? defaultBaseUrl}/v1`;
@@ -238,7 +456,14 @@ var unsent = class {
238
456
  domains = new Domains(this);
239
457
  emails = new Emails(this);
240
458
  contacts = new Contacts(this);
459
+ contactBooks = new ContactBooks(this);
460
+ templates = new Templates(this);
461
+ webhooks = new Webhooks(this);
462
+ analytics = new Analytics(this);
241
463
  campaigns = new Campaigns(this);
464
+ suppressions = new Suppressions(this);
465
+ apiKeys = new ApiKeys(this);
466
+ settings = new Settings(this);
242
467
  url = baseUrl;
243
468
  async fetchRequest(path, options = {}) {
244
469
  const fullUrl = `${this.url}${path}`;
@@ -328,6 +553,10 @@ var unsent = class {
328
553
  };
329
554
  // Annotate the CommonJS export names for ESM import in node:
330
555
  0 && (module.exports = {
556
+ analytics,
331
557
  campaigns,
332
- unsent
558
+ contactBooks,
559
+ templates,
560
+ unsent,
561
+ webhooks
333
562
  });
package/dist/index.mjs CHANGED
@@ -4,6 +4,9 @@ var Contacts = class {
4
4
  this.unsent = unsent2;
5
5
  this.unsent = unsent2;
6
6
  }
7
+ async list(contactBookId) {
8
+ return this.unsent.get(`/contactBooks/${contactBookId}/contacts`);
9
+ }
7
10
  async create(contactBookId, payload) {
8
11
  const data = await this.unsent.post(
9
12
  `/contactBooks/${contactBookId}/contacts`,
@@ -78,6 +81,71 @@ var Emails = class {
78
81
  error: response.error
79
82
  };
80
83
  }
84
+ async list(query) {
85
+ const params = new URLSearchParams();
86
+ if (query?.page) params.append("page", query.page.toString());
87
+ if (query?.limit) params.append("limit", query.limit.toString());
88
+ if (query?.startDate) params.append("startDate", query.startDate);
89
+ if (query?.endDate) params.append("endDate", query.endDate);
90
+ if (query?.domainId) {
91
+ if (Array.isArray(query.domainId)) {
92
+ query.domainId.forEach((id) => params.append("domainId", id));
93
+ } else {
94
+ params.append("domainId", query.domainId);
95
+ }
96
+ }
97
+ const queryString = params.toString() ? `?${params.toString()}` : "";
98
+ const response = await this.unsent.get(
99
+ `/emails${queryString}`
100
+ );
101
+ return {
102
+ data: response.data?.data ?? null,
103
+ count: response.data?.count ?? null,
104
+ error: response.error
105
+ };
106
+ }
107
+ async getComplaints(query) {
108
+ const params = new URLSearchParams();
109
+ if (query?.page) params.append("page", query.page.toString());
110
+ if (query?.limit) params.append("limit", query.limit.toString());
111
+ const queryString = params.toString() ? `?${params.toString()}` : "";
112
+ const response = await this.unsent.get(
113
+ `/emails/complaints${queryString}`
114
+ );
115
+ return {
116
+ data: response.data?.data ?? null,
117
+ count: response.data?.count ?? null,
118
+ error: response.error
119
+ };
120
+ }
121
+ async getBounces(query) {
122
+ const params = new URLSearchParams();
123
+ if (query?.page) params.append("page", query.page.toString());
124
+ if (query?.limit) params.append("limit", query.limit.toString());
125
+ const queryString = params.toString() ? `?${params.toString()}` : "";
126
+ const response = await this.unsent.get(
127
+ `/emails/bounces${queryString}`
128
+ );
129
+ return {
130
+ data: response.data?.data ?? null,
131
+ count: response.data?.count ?? null,
132
+ error: response.error
133
+ };
134
+ }
135
+ async getUnsubscribes(query) {
136
+ const params = new URLSearchParams();
137
+ if (query?.page) params.append("page", query.page.toString());
138
+ if (query?.limit) params.append("limit", query.limit.toString());
139
+ const queryString = params.toString() ? `?${params.toString()}` : "";
140
+ const response = await this.unsent.get(
141
+ `/emails/unsubscribes${queryString}`
142
+ );
143
+ return {
144
+ data: response.data?.data ?? null,
145
+ count: response.data?.count ?? null,
146
+ error: response.error
147
+ };
148
+ }
81
149
  async get(id) {
82
150
  const data = await this.unsent.get(
83
151
  `/emails/${id}`
@@ -138,12 +206,109 @@ var Domains = class {
138
206
  }
139
207
  };
140
208
 
209
+ // src/contact-book.ts
210
+ var ContactBooks = class {
211
+ constructor(unsent2) {
212
+ this.unsent = unsent2;
213
+ this.unsent = unsent2;
214
+ }
215
+ async list() {
216
+ return this.unsent.get("/contactBooks");
217
+ }
218
+ async create(payload) {
219
+ return this.unsent.post("/contactBooks", payload);
220
+ }
221
+ async get(id) {
222
+ return this.unsent.get(`/contactBooks/${id}`);
223
+ }
224
+ async update(id, payload) {
225
+ return this.unsent.patch(`/contactBooks/${id}`, payload);
226
+ }
227
+ async delete(id) {
228
+ return this.unsent.delete(`/contactBooks/${id}`);
229
+ }
230
+ };
231
+
232
+ // src/template.ts
233
+ var Templates = class {
234
+ constructor(unsent2) {
235
+ this.unsent = unsent2;
236
+ this.unsent = unsent2;
237
+ }
238
+ async list() {
239
+ return this.unsent.get("/templates");
240
+ }
241
+ async create(payload) {
242
+ return this.unsent.post("/templates", payload);
243
+ }
244
+ async get(id) {
245
+ return this.unsent.get(`/templates/${id}`);
246
+ }
247
+ async update(id, payload) {
248
+ return this.unsent.patch(`/templates/${id}`, payload);
249
+ }
250
+ async delete(id) {
251
+ return this.unsent.delete(`/templates/${id}`);
252
+ }
253
+ };
254
+
255
+ // src/webhook.ts
256
+ var Webhooks = class {
257
+ constructor(unsent2) {
258
+ this.unsent = unsent2;
259
+ this.unsent = unsent2;
260
+ }
261
+ async list() {
262
+ return this.unsent.get("/webhooks");
263
+ }
264
+ async create(payload) {
265
+ return this.unsent.post("/webhooks", payload);
266
+ }
267
+ async update(id, payload) {
268
+ return this.unsent.patch(`/webhooks/${id}`, payload);
269
+ }
270
+ async delete(id) {
271
+ return this.unsent.delete(`/webhooks/${id}`);
272
+ }
273
+ };
274
+
275
+ // src/analytics.ts
276
+ var Analytics = class {
277
+ constructor(unsent2) {
278
+ this.unsent = unsent2;
279
+ this.unsent = unsent2;
280
+ }
281
+ async get(query) {
282
+ return this.unsent.get("/analytics");
283
+ }
284
+ async getTimeSeries(query) {
285
+ const params = new URLSearchParams();
286
+ if (query?.days) params.append("days", query.days.toString());
287
+ if (query?.domain) params.append("domain", query.domain);
288
+ const queryString = params.toString() ? `?${params.toString()}` : "";
289
+ return this.unsent.get(
290
+ `/analytics/time-series${queryString}`
291
+ );
292
+ }
293
+ async getReputation(query) {
294
+ const params = new URLSearchParams();
295
+ if (query?.domain) params.append("domain", query.domain);
296
+ const queryString = params.toString() ? `?${params.toString()}` : "";
297
+ return this.unsent.get(
298
+ `/analytics/reputation${queryString}`
299
+ );
300
+ }
301
+ };
302
+
141
303
  // src/campaign.ts
142
304
  var Campaigns = class {
143
305
  constructor(unsent2) {
144
306
  this.unsent = unsent2;
145
307
  this.unsent = unsent2;
146
308
  }
309
+ async list() {
310
+ return this.unsent.get("/campaigns");
311
+ }
147
312
  async create(payload) {
148
313
  const data = await this.unsent.post(
149
314
  `/campaigns`,
@@ -180,6 +345,55 @@ var Campaigns = class {
180
345
  }
181
346
  };
182
347
 
348
+ // src/suppression.ts
349
+ var Suppressions = class {
350
+ constructor(unsent2) {
351
+ this.unsent = unsent2;
352
+ this.unsent = unsent2;
353
+ }
354
+ async list(query) {
355
+ const params = new URLSearchParams();
356
+ if (query?.page) params.append("page", query.page.toString());
357
+ if (query?.limit) params.append("limit", query.limit.toString());
358
+ const queryString = params.toString() ? `?${params.toString()}` : "";
359
+ return this.unsent.get(`/suppressions${queryString}`);
360
+ }
361
+ async add(payload) {
362
+ return this.unsent.post("/suppressions", payload);
363
+ }
364
+ async delete(email) {
365
+ return this.unsent.delete(`/suppressions/email/${email}`);
366
+ }
367
+ };
368
+
369
+ // src/api-key.ts
370
+ var ApiKeys = class {
371
+ constructor(unsent2) {
372
+ this.unsent = unsent2;
373
+ this.unsent = unsent2;
374
+ }
375
+ async list() {
376
+ return this.unsent.get("/api-keys");
377
+ }
378
+ async create(payload) {
379
+ return this.unsent.post("/api-keys", payload);
380
+ }
381
+ async delete(id) {
382
+ return this.unsent.delete(`/api-keys/${id}`);
383
+ }
384
+ };
385
+
386
+ // src/settings.ts
387
+ var Settings = class {
388
+ constructor(unsent2) {
389
+ this.unsent = unsent2;
390
+ this.unsent = unsent2;
391
+ }
392
+ async get() {
393
+ return this.unsent.get("/settings");
394
+ }
395
+ };
396
+
183
397
  // src/unsent.ts
184
398
  var defaultBaseUrl = "https://api.unsent.dev";
185
399
  var baseUrl = `${process?.env?.UNSENT_BASE_URL ?? process?.env?.UNSENT_BASE_URL ?? defaultBaseUrl}/v1`;
@@ -211,7 +425,14 @@ var unsent = class {
211
425
  domains = new Domains(this);
212
426
  emails = new Emails(this);
213
427
  contacts = new Contacts(this);
428
+ contactBooks = new ContactBooks(this);
429
+ templates = new Templates(this);
430
+ webhooks = new Webhooks(this);
431
+ analytics = new Analytics(this);
214
432
  campaigns = new Campaigns(this);
433
+ suppressions = new Suppressions(this);
434
+ apiKeys = new ApiKeys(this);
435
+ settings = new Settings(this);
215
436
  url = baseUrl;
216
437
  async fetchRequest(path, options = {}) {
217
438
  const fullUrl = `${this.url}${path}`;
@@ -300,6 +521,10 @@ var unsent = class {
300
521
  }
301
522
  };
302
523
  export {
524
+ Analytics as analytics,
303
525
  Campaigns as campaigns,
304
- unsent
526
+ ContactBooks as contactBooks,
527
+ Templates as templates,
528
+ unsent,
529
+ Webhooks as webhooks
305
530
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unsent/sdk",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "TypeScript SDK for the Unsent API - Send transactional emails with ease",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -42,6 +42,6 @@
42
42
  "scripts": {
43
43
  "build": "rm -rf dist && tsup index.ts --format esm,cjs --dts",
44
44
  "publish-sdk": "pnpm run build && pnpm publish --no-git-checks --access public",
45
- "openapi-typegen": "openapi-typescript ../../apps/docs/api-reference/openapi.json -o types/schema.d.ts"
45
+ "openapi:generate": "openapi-typescript ../../apps/docs/public/api-reference.json -o types/schema.d.ts"
46
46
  }
47
47
  }