shipmail 0.4.12 → 0.4.14

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
@@ -3,6 +3,8 @@ var API_KEY_SCOPES = [
3
3
  "*",
4
4
  "audiences:read",
5
5
  "audiences:write",
6
+ "automations:read",
7
+ "automations:write",
6
8
  "booking_pages:read",
7
9
  "booking_pages:write",
8
10
  "calendar:read",
@@ -39,6 +41,8 @@ var API_KEY_SCOPE_DESCRIPTIONS = {
39
41
  "*": "All non-partner API endpoints in this organization.",
40
42
  "audiences:read": "List and retrieve newsletter audiences and their subscribers.",
41
43
  "audiences:write": "Create audiences and add, update, or remove their subscribers.",
44
+ "automations:read": "List and retrieve assistant automations.",
45
+ "automations:write": "Create, update, and manually run assistant automations.",
42
46
  "booking_pages:read": "List and retrieve booking pages.",
43
47
  "booking_pages:write": "Create, update, and delete booking pages.",
44
48
  "calendar:read": "List and retrieve calendar events and open availability.",
@@ -81,29 +85,29 @@ function apiKeyScopesGrant(grantedScopes, requiredScope) {
81
85
  }
82
86
 
83
87
  // src/errors.ts
84
- var ShipMailError = class extends Error {
88
+ var ShipmailError = class extends Error {
85
89
  constructor(message, options) {
86
90
  super(message);
87
- this.name = "ShipMailError";
91
+ this.name = "ShipmailError";
88
92
  this.status = options?.status;
89
93
  this.type = options?.type;
90
94
  this.requestId = options?.requestId;
91
95
  this.retryable = options?.retryable ?? false;
92
96
  }
93
97
  };
94
- var AuthenticationError = class extends ShipMailError {
98
+ var AuthenticationError = class extends ShipmailError {
95
99
  constructor(message, requestId) {
96
100
  super(message, { status: 401, type: "authentication_error", requestId, retryable: false });
97
101
  this.name = "AuthenticationError";
98
102
  }
99
103
  };
100
- var AuthorizationError = class extends ShipMailError {
104
+ var AuthorizationError = class extends ShipmailError {
101
105
  constructor(message, requestId) {
102
106
  super(message, { status: 403, type: "authorization_error", requestId, retryable: false });
103
107
  this.name = "AuthorizationError";
104
108
  }
105
109
  };
106
- var ValidationError = class extends ShipMailError {
110
+ var ValidationError = class extends ShipmailError {
107
111
  constructor(message, options) {
108
112
  super(message, {
109
113
  status: 422,
@@ -115,19 +119,19 @@ var ValidationError = class extends ShipMailError {
115
119
  this.details = options?.details;
116
120
  }
117
121
  };
118
- var QuotaExceededError = class extends ShipMailError {
122
+ var QuotaExceededError = class extends ShipmailError {
119
123
  constructor(message, requestId) {
120
124
  super(message, { status: 403, type: "quota_exceeded", requestId, retryable: false });
121
125
  this.name = "QuotaExceededError";
122
126
  }
123
127
  };
124
- var NotFoundError = class extends ShipMailError {
128
+ var NotFoundError = class extends ShipmailError {
125
129
  constructor(message, requestId) {
126
130
  super(message, { status: 404, type: "not_found", requestId, retryable: false });
127
131
  this.name = "NotFoundError";
128
132
  }
129
133
  };
130
- var RateLimitError = class extends ShipMailError {
134
+ var RateLimitError = class extends ShipmailError {
131
135
  constructor(message, options) {
132
136
  super(message, {
133
137
  status: 429,
@@ -139,25 +143,25 @@ var RateLimitError = class extends ShipMailError {
139
143
  this.retryAfter = options?.retryAfter;
140
144
  }
141
145
  };
142
- var ConflictError = class extends ShipMailError {
146
+ var ConflictError = class extends ShipmailError {
143
147
  constructor(message, requestId) {
144
148
  super(message, { status: 409, type: "conflict", requestId, retryable: false });
145
149
  this.name = "ConflictError";
146
150
  }
147
151
  };
148
- var InternalServerError = class extends ShipMailError {
152
+ var InternalServerError = class extends ShipmailError {
149
153
  constructor(message, requestId) {
150
154
  super(message, { status: 500, type: "internal_error", requestId, retryable: true });
151
155
  this.name = "InternalServerError";
152
156
  }
153
157
  };
154
- var ConnectionError = class extends ShipMailError {
158
+ var ConnectionError = class extends ShipmailError {
155
159
  constructor(message) {
156
160
  super(message, { retryable: true });
157
161
  this.name = "ConnectionError";
158
162
  }
159
163
  };
160
- var WebhookVerificationError = class extends ShipMailError {
164
+ var WebhookVerificationError = class extends ShipmailError {
161
165
  constructor(message) {
162
166
  super(message, { retryable: false });
163
167
  this.name = "WebhookVerificationError";
@@ -184,7 +188,7 @@ function mapErrorFromResponse(status, body, requestId) {
184
188
  case "internal_error":
185
189
  return new InternalServerError(error.message, rid);
186
190
  default:
187
- return new ShipMailError(error.message, {
191
+ return new ShipmailError(error.message, {
188
192
  status,
189
193
  type: error.type,
190
194
  requestId: rid,
@@ -393,6 +397,47 @@ var Audiences = class extends ApiResource {
393
397
  }
394
398
  };
395
399
 
400
+ // src/resources/automations.ts
401
+ var Automations = class extends ApiResource {
402
+ list(options) {
403
+ return this.client.request({
404
+ method: "GET",
405
+ path: "/automations",
406
+ methodOptions: options
407
+ });
408
+ }
409
+ create(params, options) {
410
+ return this.client.request({
411
+ method: "POST",
412
+ path: "/automations",
413
+ body: params,
414
+ methodOptions: options
415
+ });
416
+ }
417
+ get(id, options) {
418
+ return this.client.request({
419
+ method: "GET",
420
+ path: `/automations/${encodeURIComponent(id)}`,
421
+ methodOptions: options
422
+ });
423
+ }
424
+ update(id, params, options) {
425
+ return this.client.request({
426
+ method: "PATCH",
427
+ path: `/automations/${encodeURIComponent(id)}`,
428
+ body: params,
429
+ methodOptions: options
430
+ });
431
+ }
432
+ run(id, options) {
433
+ return this.client.request({
434
+ method: "POST",
435
+ path: `/automations/${encodeURIComponent(id)}/run`,
436
+ methodOptions: options
437
+ });
438
+ }
439
+ };
440
+
396
441
  // src/resources/booking-pages.ts
397
442
  var BookingPages = class extends ApiResource {
398
443
  create(params, options) {
@@ -1564,7 +1609,7 @@ var Webhooks = class extends ApiResource {
1564
1609
  };
1565
1610
 
1566
1611
  // src/version.ts
1567
- var VERSION = "0.4.12";
1612
+ var VERSION = "0.4.14";
1568
1613
 
1569
1614
  // src/client.ts
1570
1615
  var DEFAULT_BASE_URL = "https://shipmail.to/api/v1";
@@ -1594,9 +1639,9 @@ function rawBodyToBlobPart(rawBody) {
1594
1639
  new Uint8Array(buffer).set(rawBody);
1595
1640
  return buffer;
1596
1641
  }
1597
- var ShipMailClient = class {
1642
+ var ShipmailClient = class {
1598
1643
  /**
1599
- * Create a new ShipMail client.
1644
+ * Create a new Shipmail client.
1600
1645
  * @param config - API key string or full configuration object.
1601
1646
  */
1602
1647
  constructor(config) {
@@ -1618,6 +1663,7 @@ var ShipMailClient = class {
1618
1663
  this.organizationId = config.organizationId;
1619
1664
  }
1620
1665
  this.audiences = new Audiences(this);
1666
+ this.automations = new Automations(this);
1621
1667
  this.bookingPages = new BookingPages(this);
1622
1668
  this.capabilities = new Capabilities(this);
1623
1669
  this.calendar = new Calendar(this);
@@ -1670,7 +1716,7 @@ var ShipMailClient = class {
1670
1716
  }
1671
1717
  const targetOrganizationId = methodOpts?.organizationId ?? this.organizationId;
1672
1718
  if (targetOrganizationId) {
1673
- headers["X-ShipMail-Organization-Id"] = targetOrganizationId;
1719
+ headers["X-Shipmail-Organization-Id"] = targetOrganizationId;
1674
1720
  }
1675
1721
  let body = null;
1676
1722
  if (options.rawBody !== void 0) {
@@ -1704,7 +1750,7 @@ var ShipMailClient = class {
1704
1750
  if (isApiErrorBody(errorBody)) {
1705
1751
  lastError = mapErrorFromResponse(response.status, errorBody);
1706
1752
  } else {
1707
- lastError = new ShipMailError(`Request failed with status ${response.status}`, {
1753
+ lastError = new ShipmailError(`Request failed with status ${response.status}`, {
1708
1754
  status: response.status,
1709
1755
  retryable: isRetryableStatus(response.status)
1710
1756
  });
@@ -1713,7 +1759,7 @@ var ShipMailClient = class {
1713
1759
  throw lastError;
1714
1760
  }
1715
1761
  }
1716
- throw lastError ?? new ShipMailError("Request failed after retries");
1762
+ throw lastError ?? new ShipmailError("Request failed after retries");
1717
1763
  }
1718
1764
  buildUrl(path2, query) {
1719
1765
  const url = new URL(`${this.baseUrl}${path2}`);
@@ -1788,14 +1834,14 @@ async function verifyWebhook(body, headers, secret, options) {
1788
1834
  const signature = getHeader(headers, "x-shipmail-signature");
1789
1835
  const timestampStr = getHeader(headers, "x-shipmail-timestamp");
1790
1836
  if (!signature) {
1791
- throw new WebhookVerificationError("Missing X-ShipMail-Signature header");
1837
+ throw new WebhookVerificationError("Missing X-Shipmail-Signature header");
1792
1838
  }
1793
1839
  if (!timestampStr) {
1794
- throw new WebhookVerificationError("Missing X-ShipMail-Timestamp header");
1840
+ throw new WebhookVerificationError("Missing X-Shipmail-Timestamp header");
1795
1841
  }
1796
1842
  const timestamp = parseInt(timestampStr, 10);
1797
1843
  if (isNaN(timestamp)) {
1798
- throw new WebhookVerificationError("Invalid X-ShipMail-Timestamp header");
1844
+ throw new WebhookVerificationError("Invalid X-Shipmail-Timestamp header");
1799
1845
  }
1800
1846
  const tolerance = options?.toleranceInSeconds ?? DEFAULT_TOLERANCE_SECONDS;
1801
1847
  const now = Math.floor(Date.now() / 1e3);
@@ -1818,6 +1864,6 @@ async function verifyWebhook(body, headers, secret, options) {
1818
1864
  return parsed;
1819
1865
  }
1820
1866
 
1821
- export { API_KEY_SCOPES, API_KEY_SCOPE_DESCRIPTIONS, AuthenticationError, AuthorizationError, CONFERENCING_PROVIDER_IDS, ConflictError, ConnectionError, DOMAIN_STATUSES, InternalServerError, MESSAGE_SOURCES, MESSAGE_STATUSES, NotFoundError, Page, QuotaExceededError, RateLimitError, ShipMailClient, ShipMailError, ValidationError, WEBHOOK_DELIVERY_EVENT_TYPES, WEBHOOK_DELIVERY_STATUSES, WEBHOOK_EVENT_TYPES, WebhookVerificationError, apiKeyScopesGrant, ShipMailClient as default, isApiKeyScope, verifyWebhook };
1867
+ export { API_KEY_SCOPES, API_KEY_SCOPE_DESCRIPTIONS, AuthenticationError, AuthorizationError, CONFERENCING_PROVIDER_IDS, ConflictError, ConnectionError, DOMAIN_STATUSES, InternalServerError, MESSAGE_SOURCES, MESSAGE_STATUSES, NotFoundError, Page, QuotaExceededError, RateLimitError, ShipmailClient, ShipmailError, ValidationError, WEBHOOK_DELIVERY_EVENT_TYPES, WEBHOOK_DELIVERY_STATUSES, WEBHOOK_EVENT_TYPES, WebhookVerificationError, apiKeyScopesGrant, ShipmailClient as default, isApiKeyScope, verifyWebhook };
1822
1868
  //# sourceMappingURL=index.js.map
1823
1869
  //# sourceMappingURL=index.js.map