unitpost 0.3.0 → 0.5.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.
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import { createHmac, timingSafeEqual, randomUUID } from 'crypto';
4
4
  var API_VERSION = "v1";
5
5
 
6
6
  // src/http.ts
7
- var SDK_VERSION = "0.3.0";
7
+ var SDK_VERSION = "0.5.0";
8
8
  var DEFAULT_BASE_URL = "https://www.unitpost.com";
9
9
  var UnitpostError = class extends Error {
10
10
  code;
@@ -12,6 +12,8 @@ var UnitpostError = class extends Error {
12
12
  requestId;
13
13
  /** Per-field validation problems (present on 422 validation_error). */
14
14
  details;
15
+ /** A page that explains this error, when the API links one (e.g. `sending_paused`). */
16
+ docUrl;
15
17
  constructor(args) {
16
18
  super(args.message);
17
19
  this.name = "UnitpostError";
@@ -19,6 +21,7 @@ var UnitpostError = class extends Error {
19
21
  this.status = args.status;
20
22
  this.requestId = args.requestId;
21
23
  this.details = args.details ?? [];
24
+ this.docUrl = args.docUrl ?? null;
22
25
  }
23
26
  };
24
27
  function isRetryableStatus(status) {
@@ -32,6 +35,7 @@ function parseRetryAfter(value) {
32
35
  if (!Number.isNaN(date)) return Math.max(0, date - Date.now());
33
36
  return null;
34
37
  }
38
+ var WARNING_HEADER = "unitpost-warning";
35
39
  var HttpClient = class {
36
40
  apiKey;
37
41
  baseUrl;
@@ -128,7 +132,9 @@ var HttpClient = class {
128
132
  signal: controller.signal
129
133
  });
130
134
  const requestId = res.headers.get("x-request-id");
131
- if (res.status === 204) return { result: { data: null, error: null }, retryAfterMs: null };
135
+ const warning = res.ok ? res.headers.get(WARNING_HEADER) : null;
136
+ const noted = warning ? { warning } : {};
137
+ if (res.status === 204) return { result: { data: null, error: null, ...noted }, retryAfterMs: null };
132
138
  const raw = await res.text();
133
139
  const parsed = raw ? safeJsonParse(raw) : null;
134
140
  if (!res.ok) {
@@ -141,13 +147,14 @@ var HttpClient = class {
141
147
  message: errBody?.error?.message ?? `Request failed with status ${res.status}.`,
142
148
  status: res.status,
143
149
  requestId,
144
- details: errBody?.error?.details
150
+ details: errBody?.error?.details,
151
+ docUrl: errBody?.error?.doc_url ?? null
145
152
  })
146
153
  },
147
154
  retryAfterMs: parseRetryAfter(res.headers.get("retry-after"))
148
155
  };
149
156
  }
150
- return { result: { data: parsed, error: null }, retryAfterMs: null };
157
+ return { result: { data: parsed, error: null, ...noted }, retryAfterMs: null };
151
158
  } catch (err) {
152
159
  const aborted = err instanceof Error && err.name === "AbortError";
153
160
  return {
@@ -166,6 +173,36 @@ var HttpClient = class {
166
173
  clearTimeout(timer);
167
174
  }
168
175
  }
176
+ /**
177
+ * PUT bytes to a file's presigned upload URL (`files.upload`), with exactly
178
+ * the headers it was signed with: no API key, and no retries (storage
179
+ * refuses any other length or type). Returns the error, or `null` when
180
+ * storage took the bytes.
181
+ */
182
+ async putBytes(url, headers, body) {
183
+ const controller = new AbortController();
184
+ const timer = setTimeout(() => controller.abort(), this.timeout);
185
+ try {
186
+ const res = await this.fetchImpl(url, { method: "PUT", headers, body, signal: controller.signal });
187
+ if (res.ok) return null;
188
+ return new UnitpostError({
189
+ code: "upload_failed",
190
+ message: `Storage refused the upload with status ${res.status}.`,
191
+ status: res.status,
192
+ requestId: null
193
+ });
194
+ } catch (err) {
195
+ const aborted = err instanceof Error && err.name === "AbortError";
196
+ return new UnitpostError({
197
+ code: aborted ? "timeout" : "network_error",
198
+ message: aborted ? `The upload timed out after ${this.timeout}ms.` : err instanceof Error ? err.message : "The upload failed.",
199
+ status: 0,
200
+ requestId: null
201
+ });
202
+ } finally {
203
+ clearTimeout(timer);
204
+ }
205
+ }
169
206
  buildUrl(path, query) {
170
207
  const url = new URL(`${this.baseUrl}/api/${API_VERSION}${path}`);
171
208
  if (query) {
@@ -189,19 +226,27 @@ function safeJsonParse(text) {
189
226
  }
190
227
 
191
228
  // src/pagination.ts
192
- async function* paginate(client, path, params = {}) {
229
+ var FORWARD_ONLY_MESSAGE = "listAll pages forward only: `before` is not supported (use list() to page backward).";
230
+ function paginate(client, path, params = {}, cursor = "id") {
231
+ if (params.before) throw new TypeError(FORWARD_ONLY_MESSAGE);
232
+ return pages(client, path, params, cursor);
233
+ }
234
+ async function* pages(client, path, params, cursor) {
193
235
  let after = params.after;
194
236
  for (; ; ) {
195
237
  const { data, error } = await client.request({
196
238
  method: "GET",
197
239
  path,
198
- query: { limit: params.limit, after, before: params.before }
240
+ // Filters ride along on every page; only the cursor moves.
241
+ query: { ...params, after }
199
242
  });
200
243
  if (error) throw error;
201
244
  const page = data;
202
245
  for (const row of page.data) yield row;
203
246
  if (!page.has_more || page.data.length === 0) return;
204
- after = page.data[page.data.length - 1].id;
247
+ const next = page.data[page.data.length - 1][cursor];
248
+ if (typeof next !== "string" || next === "") return;
249
+ after = next;
205
250
  }
206
251
  }
207
252
  var SECRET_PREFIX = "whsec_";
@@ -259,203 +304,1104 @@ var Resource = class {
259
304
  }
260
305
  http;
261
306
  };
262
- var Email = class extends Resource {
263
- topics;
264
- campaigns;
307
+ var Sms = class extends Resource {
308
+ /** SMS templates: plain-text bodies with `{{variable}}` placeholders. */
265
309
  templates;
266
- domains;
310
+ /** SMS campaigns: a published SMS template sent to a segment. */
311
+ campaigns;
312
+ /** SMS subscription topics (independent from email topics). */
313
+ topics;
314
+ // SMS setup. Carrier purchases go through `quotes` (a price, then a
315
+ // confirm with the opt-in `sms:purchase` scope); a brand's documents and
316
+ // the carrier send-backs work here too (ADR-0159), and so do releasing a
317
+ // number, removing a 10DLC setup and replacing a brand registration
318
+ // (ADR-0160).
319
+ /** Messaging programs: what a sender registration says your texts are for. */
320
+ messagingPrograms;
321
+ /** The verified numbers a template test may text. */
322
+ testDestinations;
323
+ /** Where and how people opt in to your texts. */
324
+ consentSetups;
325
+ /** What the workspace pays for SMS every month. */
326
+ billing;
327
+ /** Carrier registrations, their review state, and fixing what carriers sent back. */
328
+ registrations;
329
+ /** Buy carrier resources: price an order, then confirm it. */
330
+ quotes;
267
331
  constructor(http) {
268
332
  super(http);
269
- this.topics = new Topics(http);
270
- this.campaigns = new Campaigns(http);
271
- this.templates = new Templates(http);
272
- this.domains = new Domains(http);
333
+ this.templates = new SmsTemplates(http);
334
+ this.campaigns = new SmsCampaigns(http);
335
+ this.topics = new SmsTopics(http);
336
+ this.messagingPrograms = new SmsMessagingPrograms(http);
337
+ this.testDestinations = new SmsTestDestinations(http);
338
+ this.consentSetups = new SmsConsentSetups(http);
339
+ this.billing = new SmsBilling(http);
340
+ this.registrations = new SmsRegistrations(http);
341
+ this.quotes = new SmsQuotes(http);
273
342
  }
274
343
  /**
275
- * Send or schedule a transactional email.
344
+ * Send or schedule an SMS message.
276
345
  *
277
- * If you don't pass `idempotencyKey`, the SDK generates one automatically so
278
- * the request is safe to auto-retry (a network blip can't double-send). Pass
279
- * your own to dedupe across separate `send()` calls.
346
+ * The recipient must be E.164 (`+15551234567`). Marketing sends require the
347
+ * recipient's prior express consent on record and honor recipient-local
348
+ * quiet hours (deferred, never dropped). Billing is per segment. An
349
+ * `Idempotency-Key` is generated automatically when you don't pass one.
280
350
  */
281
351
  send(body, opts = {}) {
282
352
  return this.http.request({
283
353
  method: "POST",
284
- path: "/email",
354
+ path: "/sms",
285
355
  body,
286
356
  idempotencyKey: opts.idempotencyKey ?? randomUUID()
287
357
  });
288
358
  }
359
+ /** Retrieve one SMS message's status and delivery state. */
360
+ get(id) {
361
+ return this.http.request({ method: "GET", path: `/sms/${enc(id)}` });
362
+ }
289
363
  /**
290
- * Send up to 100 emails in one request (all-or-nothing validation).
364
+ * Make the sender of a received text a contact, or file the text under the
365
+ * contact that already has the number. Phone only: no name and no consent
366
+ * (texting a number isn't consent to marketing). Every earlier text with
367
+ * that number that no contact holds is filed under the contact too, so
368
+ * `contact_id` reads it from then on. Answers the contact: `201` when it is
369
+ * new, `200` when it existed, so a retry is safe. It counts against the
370
+ * plan's contacts (`403 limit_reached` when full), and a number that texted
371
+ * STOP stays opted out. A text you sent is refused (`409`). Needs
372
+ * `contacts:write` and `sms:read`.
373
+ */
374
+ addContact(id) {
375
+ return this.http.request({ method: "POST", path: `/sms/${enc(id)}/contact`, body: {} });
376
+ }
377
+ /**
378
+ * Cancel a queued/scheduled SMS (`{ cancel: true }` — its reserved credit is
379
+ * refunded) or move a scheduled one (`{ scheduled_at }`).
380
+ */
381
+ update(id, body) {
382
+ return this.http.request({ method: "PATCH", path: `/sms/${enc(id)}`, body });
383
+ }
384
+ /**
385
+ * List SMS messages (cursor-paginated, newest first). `participant` returns
386
+ * the whole conversation with one number: texts you sent them and their
387
+ * replies.
388
+ */
389
+ list(params = {}) {
390
+ return this.http.request({ method: "GET", path: "/sms", query: params });
391
+ }
392
+ /** Async-iterate every SMS message (same filters as `list`). */
393
+ listAll(params = {}) {
394
+ return paginate(this.http, "/sms", params);
395
+ }
396
+ /**
397
+ * List SMS brands and their setup status.
291
398
  *
292
- * Like `send()`, if you don't pass `idempotencyKey` the SDK generates one so a
293
- * transient failure can be safely auto-retried (the server dedupes the batch
294
- * on the key and replays the original result instead of re-sending). Pass your
295
- * own to dedupe across separate `batch()` calls.
399
+ * A brand is the business identity carriers register before they approve a
400
+ * phone number, so this is what to poll to answer "is SMS ready yet?":
401
+ * `status` says whether you or the carrier is the blocker, and `missing`
402
+ * lists exactly what is still required.
403
+ *
404
+ * Create and edit a brand with `createBrand` / `updateBrand` (free).
405
+ * Registering it with carriers is a paid order: `sms.quotes.create` prices
406
+ * it, `sms.quotes.confirm` places it. Needs `sms:read`.
296
407
  */
297
- batch(body, opts = {}) {
408
+ brands(params = {}) {
409
+ return this.http.request({
410
+ method: "GET",
411
+ path: "/sms/brands",
412
+ query: params
413
+ });
414
+ }
415
+ /**
416
+ * Create a brand (201): the business identity carriers register before
417
+ * they approve a number. A draft may be partial (only `name` is required);
418
+ * `missing` says what is still needed. Free, with no carrier call; one brand
419
+ * per website domain (`409`). The tax id is write-only: stored encrypted,
420
+ * read back as `tax_id_on_file`. Registering the brand with carriers is a
421
+ * paid order through `sms.quotes`. Needs `sms:manage`. Pass an
422
+ * `idempotencyKey` so a retry never makes a second brand; one is generated
423
+ * when you don't.
424
+ */
425
+ createBrand(body, opts = {}) {
298
426
  return this.http.request({
299
427
  method: "POST",
300
- path: "/email/batch",
428
+ path: "/sms/brands",
301
429
  body,
302
430
  idempotencyKey: opts.idempotencyKey ?? randomUUID()
303
431
  });
304
432
  }
305
- /** Retrieve a batch by id. */
306
- getBatch(id) {
307
- return this.http.request({ method: "GET", path: `/email/batches/${enc(id)}` });
433
+ /** One brand with every field you can edit, its `status` and `missing` list. Needs `sms:read`. */
434
+ getBrand(id) {
435
+ return this.http.request({ method: "GET", path: `/sms/brands/${enc(id)}` });
308
436
  }
309
- /** Cancel every still-cancelable message in a batch. */
310
- cancelBatch(id) {
311
- return this.http.request({ method: "POST", path: `/email/batches/${enc(id)}/cancel` });
437
+ /**
438
+ * Edit a brand: only the fields you send change, `null` clears an optional
439
+ * one; send `{ archived }` alone to archive or restore it. The tax id is
440
+ * write-only. A locked brand (`editable: false`: carriers are reviewing or
441
+ * approved it, or it has numbers) refuses carrier-field edits with
442
+ * `409 brand_locked`, `details` naming each field, except those a
443
+ * correction request opened. Needs `sms:manage`.
444
+ */
445
+ updateBrand(id, body) {
446
+ return this.http.request({ method: "PATCH", path: `/sms/brands/${enc(id)}`, body });
312
447
  }
313
- /** List sent/scheduled emails (cursor-paginated). */
314
- list(params = {}) {
315
- return this.http.request({ method: "GET", path: "/email", query: params });
448
+ /**
449
+ * A brand's documents (`sdoc_` ids): the files and numbers a country's
450
+ * carriers ask for, one per slot (`kind`, plus `carrier` / `country` for a
451
+ * variant). Needs `sms:read`.
452
+ */
453
+ listBrandDocuments(brandId) {
454
+ return this.http.request({ method: "GET", path: `/sms/brands/${enc(brandId)}/documents` });
316
455
  }
317
- /** Async-iterate every sent/scheduled email. */
318
- listAll(params = {}) {
319
- return paginate(this.http, "/email", params);
456
+ /**
457
+ * Add a document to a brand's slot (201): a file kind takes `file_id` (a
458
+ * file from `files.create` / `files.upload`, purpose `sms_document`, or
459
+ * `sms_opt_in_evidence` for `opt_in_screenshot`), a text kind takes `text`.
460
+ * A document in an occupied slot replaces the current one. Needs
461
+ * `sms:manage`. Pass an `idempotencyKey` so a retry adds one document; one
462
+ * is generated when you don't.
463
+ */
464
+ addBrandDocument(brandId, body, opts = {}) {
465
+ return this.http.request({
466
+ method: "POST",
467
+ path: `/sms/brands/${enc(brandId)}/documents`,
468
+ body,
469
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
470
+ });
320
471
  }
321
- /** Retrieve a sent or scheduled email. */
322
- get(id) {
323
- return this.http.request({ method: "GET", path: `/email/${enc(id)}` });
472
+ /** One brand document. Needs `sms:read`. */
473
+ getBrandDocument(brandId, documentId) {
474
+ return this.http.request({
475
+ method: "GET",
476
+ path: `/sms/brands/${enc(brandId)}/documents/${enc(documentId)}`
477
+ });
324
478
  }
325
- /** Cancel or reschedule a scheduled/queued email. */
326
- update(id, body) {
327
- return this.http.request({ method: "PATCH", path: `/email/${enc(id)}`, body });
479
+ /** Remove a brand document from its slot. Needs `sms:manage`. */
480
+ removeBrandDocument(brandId, documentId) {
481
+ return this.http.request({
482
+ method: "DELETE",
483
+ path: `/sms/brands/${enc(brandId)}/documents/${enc(documentId)}`
484
+ });
328
485
  }
329
486
  /**
330
- * Deliverability / engagement stats over a rolling window.
331
- *
332
- * `days` is the window size (1–365); defaults to 30 server-side.
487
+ * A 5-minute signed link to a file document's bytes. The link is a bearer
488
+ * credential: fetch it yourself, don't log or share it. An identity
489
+ * document needs `sms:manage`; the rest `sms:read`.
333
490
  */
334
- stats(params = {}) {
335
- return this.http.request({ method: "GET", path: "/email/stats", query: params });
336
- }
337
- // --- Inbound (received) emails ---
338
- receivedList(params = {}) {
339
- return this.http.request({ method: "GET", path: "/email/received", query: params });
491
+ brandDocumentUrl(brandId, documentId) {
492
+ return this.http.request({
493
+ method: "GET",
494
+ path: `/sms/brands/${enc(brandId)}/documents/${enc(documentId)}/url`
495
+ });
340
496
  }
341
- receivedGet(id) {
342
- return this.http.request({ method: "GET", path: `/email/received/${enc(id)}` });
497
+ /**
498
+ * List SMS phone numbers.
499
+ *
500
+ * Only numbers with `status: "active"` can send. A `ten_dlc` number has no
501
+ * `phone_number` until carriers approve it, and a `simulator` number only
502
+ * reaches verified test destinations.
503
+ *
504
+ * Order a number through `sms.quotes`; release one with `releaseNumber`.
505
+ */
506
+ numbers(params = {}) {
507
+ return this.http.request({
508
+ method: "GET",
509
+ path: "/sms/numbers",
510
+ query: params
511
+ });
343
512
  }
344
- receivedAttachmentUrl(id, attachmentId) {
345
- return this.http.request({ method: "GET", path: `/email/received/${enc(id)}/attachments/${enc(attachmentId)}` });
513
+ /**
514
+ * One number, or one country of a Sender ID (`snum_…`), as `numbers()`
515
+ * reads it: its status, what carriers sent back (`feedback`) and its use
516
+ * case. Read a resubmit, a retry or a release back with it. Needs
517
+ * `sms:read`.
518
+ */
519
+ getNumber(numberId) {
520
+ return this.http.request({ method: "GET", path: `/sms/numbers/${enc(numberId)}` });
346
521
  }
347
- };
348
- var Contacts = class extends Resource {
349
- list(params = {}) {
350
- return this.http.request({ method: "GET", path: "/contacts", query: params });
522
+ /**
523
+ * Release a number, or one country of a Sender ID, back to the carrier.
524
+ * PERMANENT: it stops sending at once, reads `released` from then on and
525
+ * can't be had back; its monthly fee ends with it (no proration), and a
526
+ * 10DLC number's campaign registration goes with it. Refused while an
527
+ * automation uses it (`409 resource_in_use`) and, unless `force: true`,
528
+ * while campaigns are scheduled on it or texts are queued through it
529
+ * (`409 sender_release_blocked`, counts in `error.blockers`). Releasing a
530
+ * released number answers it. Needs `sms:manage`. Pass an `idempotencyKey`
531
+ * so a retry releases once; one is generated when you don't.
532
+ */
533
+ releaseNumber(numberId, body = {}, opts = {}) {
534
+ return this.http.request({
535
+ method: "POST",
536
+ path: `/sms/numbers/${enc(numberId)}/release`,
537
+ body,
538
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
539
+ });
351
540
  }
352
- listAll(params = {}) {
353
- return paginate(this.http, "/contacts", params);
541
+ /**
542
+ * Resubmit a toll-free verification carriers sent back (free): fix what
543
+ * the number's `feedback` names, then send the new evidence
544
+ * (`opt_in_evidence_file_id`, or `reuse_opt_in_evidence`), a
545
+ * `business_registration_document_file_id`, `consent_source_url`, or
546
+ * `acknowledge_unchanged`. Needs `sms:manage`. Pass an `idempotencyKey` so
547
+ * a retry resubmits once; one is generated when you don't.
548
+ */
549
+ resubmitNumber(numberId, body, opts = {}) {
550
+ return this.http.request({
551
+ method: "POST",
552
+ path: `/sms/numbers/${enc(numberId)}/resubmit`,
553
+ body,
554
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
555
+ });
354
556
  }
355
- create(body) {
356
- return this.http.request({ method: "POST", path: "/contacts", body });
557
+ /**
558
+ * Text-to-join: the words people can text this number (`snum_…`) to sign
559
+ * up. `registration_warning` is set when the number's carrier registration
560
+ * doesn't list keyword opt-in, so carriers could flag the sign-ups. Needs
561
+ * `sms:read`.
562
+ */
563
+ listJoinKeywords(numberId) {
564
+ return this.http.request({ method: "GET", path: `/sms/numbers/${enc(numberId)}/join-keywords` });
357
565
  }
358
- /** Retrieve by contact id or email. */
359
- get(idOrEmail) {
360
- return this.http.request({ method: "GET", path: `/contacts/${enc(idOrEmail)}` });
566
+ /**
567
+ * Add a join keyword to a number. A text that is exactly this word (any
568
+ * case) gets the double opt-in request ("Reply YES to get … texts"); the
569
+ * YES records marketing consent, makes the texter a contact if they aren't
570
+ * one, and adds them to `segment_id` (a static segment) and/or `topic_id`
571
+ * (an SMS topic). A keyword is never consent by itself and never lifts a
572
+ * STOP. STOP, HELP, START, YES and their variants are refused; at most 10
573
+ * per number, and only on numbers people can text back. Answers the keyword
574
+ * with `registration_warning`: `201` when added, `200` when the same keyword
575
+ * with the same settings is already there, so a retry is safe (the same
576
+ * word with other settings is `409`). Needs `sms:manage`.
577
+ */
578
+ addJoinKeyword(numberId, body) {
579
+ return this.http.request({
580
+ method: "POST",
581
+ path: `/sms/numbers/${enc(numberId)}/join-keywords`,
582
+ body
583
+ });
361
584
  }
362
- update(idOrEmail, body) {
363
- return this.http.request({ method: "PATCH", path: `/contacts/${enc(idOrEmail)}`, body });
585
+ /**
586
+ * Remove a join keyword (`sjk_…`): it stops answering. People who already
587
+ * joined keep their consent, contact and memberships. Needs `sms:manage`.
588
+ */
589
+ removeJoinKeyword(numberId, keywordId) {
590
+ return this.http.request({
591
+ method: "DELETE",
592
+ path: `/sms/numbers/${enc(numberId)}/join-keywords/${enc(keywordId)}`
593
+ });
364
594
  }
365
- delete(idOrEmail) {
366
- return this.http.request({ method: "DELETE", path: `/contacts/${enc(idOrEmail)}` });
595
+ /**
596
+ * SMS delivery stats over a rolling window: queued, sent, delivered,
597
+ * failed, suppressed, canceled, inbound and segments billed, with delivery,
598
+ * failure and suppression rates. No opens or clicks on SMS.
599
+ *
600
+ * `days` is the window size (1–365); defaults to 30 server-side.
601
+ */
602
+ stats(params = {}) {
603
+ return this.http.request({ method: "GET", path: "/sms/stats", query: params });
367
604
  }
368
- /** Start an async contact import. */
369
- import(body) {
370
- return this.http.request({ method: "POST", path: "/contacts/imports", body });
605
+ /** Read a contact's SMS consent state and immutable consent history. */
606
+ smsConsent(contactId) {
607
+ return this.http.request({
608
+ method: "GET",
609
+ path: `/contacts/${enc(contactId)}/sms-consent`
610
+ });
371
611
  }
372
- listImports(params = {}) {
373
- return this.http.request({ method: "GET", path: "/contacts/imports", query: params });
612
+ /** Record an SMS consent change (opt-in or opt-out) for a contact. */
613
+ recordSmsConsent(contactId, body) {
614
+ return this.http.request({
615
+ method: "POST",
616
+ path: `/contacts/${enc(contactId)}/sms-consent`,
617
+ body
618
+ });
374
619
  }
375
- getImport(id) {
376
- return this.http.request({ method: "GET", path: `/contacts/imports/${enc(id)}` });
620
+ /**
621
+ * Text the contact a request to reply YES to confirm marketing texts. It
622
+ * sends a real text, so pass an `idempotencyKey` to make a retry safe; one is
623
+ * generated when you don't.
624
+ */
625
+ requestSmsOptIn(contactIdOrEmail, body = {}, opts = {}) {
626
+ return this.http.request({
627
+ method: "POST",
628
+ path: `/contacts/${enc(contactIdOrEmail)}/sms-opt-in-request`,
629
+ body,
630
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
631
+ });
377
632
  }
378
633
  };
379
- var ContactFields = class extends Resource {
634
+ var SmsTemplates = class extends Resource {
380
635
  list(params = {}) {
381
- return this.http.request({ method: "GET", path: "/contact-fields", query: params });
636
+ return this.http.request({ method: "GET", path: "/sms/templates", query: params });
382
637
  }
383
638
  listAll(params = {}) {
384
- return paginate(this.http, "/contact-fields", params);
639
+ return paginate(this.http, "/sms/templates", params);
385
640
  }
386
641
  create(body) {
387
- return this.http.request({ method: "POST", path: "/contact-fields", body });
642
+ return this.http.request({ method: "POST", path: "/sms/templates", body });
388
643
  }
389
644
  get(id) {
390
- return this.http.request({ method: "GET", path: `/contact-fields/${enc(id)}` });
645
+ return this.http.request({ method: "GET", path: `/sms/templates/${enc(id)}` });
391
646
  }
392
647
  update(id, body) {
393
- return this.http.request({ method: "PATCH", path: `/contact-fields/${enc(id)}`, body });
648
+ return this.http.request({ method: "PATCH", path: `/sms/templates/${enc(id)}`, body });
394
649
  }
395
650
  delete(id) {
396
- return this.http.request({ method: "DELETE", path: `/contact-fields/${enc(id)}` });
651
+ return this.http.request({ method: "DELETE", path: `/sms/templates/${enc(id)}` });
397
652
  }
398
- rename(id, body) {
399
- return this.http.request({ method: "POST", path: `/contact-fields/${enc(id)}/rename`, body });
653
+ /**
654
+ * What uses the template, and whether a change would be accepted now: its
655
+ * live campaigns and automations, queued texts, and `can_edit_content` /
656
+ * `can_unpublish` with the reason when not. Read it before an edit or a
657
+ * delete. Needs `templates:read`.
658
+ */
659
+ usage(id) {
660
+ return this.http.request({ method: "GET", path: `/sms/templates/${enc(id)}/usage` });
661
+ }
662
+ /**
663
+ * Send ONE test text of the template to `to`, which must be a simulator
664
+ * number (`+14254147755` delivers, `+14254147167` fails) or a verified
665
+ * number from `sms.testDestinations.list()` (any other is a `403`). Every `{{variable}}`
666
+ * needs a value in `variables` (`422`). It goes from `sender_id`, or is
667
+ * routed by the destination's country. It is a real text, billed like any.
668
+ * Needs `sms:send`. Pass an `idempotencyKey` so a retry never texts twice;
669
+ * one is generated when you don't.
670
+ */
671
+ testSend(id, body, opts = {}) {
672
+ return this.http.request({
673
+ method: "POST",
674
+ path: `/sms/templates/${enc(id)}/test-send`,
675
+ body,
676
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
677
+ });
400
678
  }
401
679
  };
402
- var Segments = class extends Resource {
680
+ var SmsCampaigns = class extends Resource {
403
681
  list(params = {}) {
404
- return this.http.request({ method: "GET", path: "/segments", query: params });
682
+ return this.http.request({ method: "GET", path: "/sms/campaigns", query: params });
405
683
  }
406
684
  listAll(params = {}) {
407
- return paginate(this.http, "/segments", params);
685
+ return paginate(this.http, "/sms/campaigns", params);
408
686
  }
687
+ /** Create a draft. Omit `sender_id` for automatic routing. */
409
688
  create(body) {
410
- return this.http.request({ method: "POST", path: "/segments", body });
689
+ return this.http.request({ method: "POST", path: "/sms/campaigns", body });
411
690
  }
412
691
  get(id) {
413
- return this.http.request({ method: "GET", path: `/segments/${enc(id)}` });
692
+ return this.http.request({ method: "GET", path: `/sms/campaigns/${enc(id)}` });
414
693
  }
694
+ /** Edit a draft (409 once sent or scheduled). */
415
695
  update(id, body) {
416
- return this.http.request({ method: "PATCH", path: `/segments/${enc(id)}`, body });
696
+ return this.http.request({ method: "PATCH", path: `/sms/campaigns/${enc(id)}`, body });
417
697
  }
698
+ /** Archive a draft or finished campaign (cancel an in-flight one first). */
418
699
  delete(id) {
419
- return this.http.request({ method: "DELETE", path: `/segments/${enc(id)}` });
700
+ return this.http.request({ method: "DELETE", path: `/sms/campaigns/${enc(id)}` });
420
701
  }
421
- listMembers(id, params = {}) {
422
- return this.http.request({ method: "GET", path: `/segments/${enc(id)}/contacts`, query: params });
702
+ /**
703
+ * Send now, or pass `{ scheduled_at }` to schedule. A large audience whose
704
+ * recipient check is still running is refused with `409 preflight_pending`:
705
+ * poll `validate(id)` until it returns the report, then send again.
706
+ */
707
+ send(id, body = {}) {
708
+ return this.http.request({ method: "POST", path: `/sms/campaigns/${enc(id)}/send`, body });
423
709
  }
424
- /** Add a contact (by id or email) to the segment. Idempotent. */
425
- addMember(id, body) {
426
- return this.http.request({ method: "POST", path: `/segments/${enc(id)}/contacts`, body });
710
+ /**
711
+ * The campaign, already `canceled`. With more than 500 queued texts (202)
712
+ * they are canceled and refunded in the background.
713
+ */
714
+ cancel(id) {
715
+ return this.http.request({ method: "POST", path: `/sms/campaigns/${enc(id)}/cancel` });
427
716
  }
428
- /** Remove a contact (by id or email) from the segment. */
429
- removeMember(id, contact) {
430
- return this.http.request({ method: "DELETE", path: `/segments/${enc(id)}/contacts/${enc(contact)}` });
717
+ pause(id) {
718
+ return this.http.request({ method: "POST", path: `/sms/campaigns/${enc(id)}/pause` });
719
+ }
720
+ resume(id) {
721
+ return this.http.request({ method: "POST", path: `/sms/campaigns/${enc(id)}/resume` });
722
+ }
723
+ /** Move a scheduled campaign back to draft so it can be edited; clears its send time. */
724
+ unschedule(id) {
725
+ return this.http.request({ method: "POST", path: `/sms/campaigns/${enc(id)}/unschedule` });
726
+ }
727
+ /**
728
+ * Copy a campaign into a new draft (201). Pass an `idempotencyKey` so a
729
+ * retry returns the same copy; one is generated when you don't.
730
+ */
731
+ duplicate(id, body = {}, opts = {}) {
732
+ return this.http.request({
733
+ method: "POST",
734
+ path: `/sms/campaigns/${enc(id)}/duplicate`,
735
+ body,
736
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
737
+ });
738
+ }
739
+ reschedule(id, body) {
740
+ return this.http.request({ method: "POST", path: `/sms/campaigns/${enc(id)}/reschedule`, body });
741
+ }
742
+ /**
743
+ * Who the campaign would reach if sent now (non-mutating). A large audience
744
+ * is counted in the background: the first call returns that `Job` (202).
745
+ * Call again until it returns the report; tell them apart with `object`
746
+ * (`"job"`).
747
+ */
748
+ validate(id) {
749
+ return this.http.request({ method: "GET", path: `/sms/campaigns/${enc(id)}/validate` });
750
+ }
751
+ /**
752
+ * How each recipient fared: the carrier's answer for a text that went out
753
+ * (`delivered`, `sent`, `failed`, …), or why none was sent (`skipped`, with
754
+ * `reason_code`). Newest first, cursor-paginated on `id`; `q` matches digits
755
+ * of the number. `skipped_by_reason` counts skipped recipients over the
756
+ * whole campaign.
757
+ */
758
+ listRecipients(id, params = {}) {
759
+ return this.http.request({ method: "GET", path: `/sms/campaigns/${enc(id)}/recipients`, query: params });
431
760
  }
432
761
  };
433
- var Topics = class extends Resource {
762
+ var SmsTopics = class extends Resource {
434
763
  list(params = {}) {
435
- return this.http.request({ method: "GET", path: "/email/topics", query: params });
764
+ return this.http.request({ method: "GET", path: "/sms/topics", query: params });
436
765
  }
437
766
  listAll(params = {}) {
438
- return paginate(this.http, "/email/topics", params);
767
+ return paginate(this.http, "/sms/topics", params);
439
768
  }
440
769
  create(body) {
441
- return this.http.request({ method: "POST", path: "/email/topics", body });
770
+ return this.http.request({ method: "POST", path: "/sms/topics", body });
442
771
  }
443
772
  get(id) {
444
- return this.http.request({ method: "GET", path: `/email/topics/${enc(id)}` });
773
+ return this.http.request({ method: "GET", path: `/sms/topics/${enc(id)}` });
445
774
  }
446
775
  update(id, body) {
447
- return this.http.request({ method: "PATCH", path: `/email/topics/${enc(id)}`, body });
776
+ return this.http.request({ method: "PATCH", path: `/sms/topics/${enc(id)}`, body });
448
777
  }
449
778
  delete(id) {
450
- return this.http.request({ method: "DELETE", path: `/email/topics/${enc(id)}` });
451
- }
452
- /** List a contact's effective topic subscriptions. */
453
- listTopics(contactId, params = {}) {
454
- return this.http.request({ method: "GET", path: `/contacts/${enc(contactId)}/topics`, query: params });
779
+ return this.http.request({ method: "DELETE", path: `/sms/topics/${enc(id)}` });
455
780
  }
456
- /** Set a contact's preference for one topic. */
457
- setTopic(contactId, body) {
458
- return this.http.request({ method: "POST", path: `/contacts/${enc(contactId)}/topics`, body });
781
+ /**
782
+ * Opt many contacts out of this SMS topic as a background job (202, the
783
+ * `Job`): `{ contact_ids }` or `{ emails }` (up to 1,000) or
784
+ * `{ segment_id }` (every member). Follow it with `jobs.get(id)`. Pass an
785
+ * `idempotencyKey` so a retry answers the same job; one is generated when
786
+ * you don't. There is no bulk opt-in.
787
+ */
788
+ optOut(id, body, opts = {}) {
789
+ return this.http.request({
790
+ method: "POST",
791
+ path: `/sms/topics/${enc(id)}/opt-out`,
792
+ body,
793
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
794
+ });
795
+ }
796
+ };
797
+ var SmsMessagingPrograms = class extends Resource {
798
+ /**
799
+ * Your programs, newest first, cursor-paginated (`limit`, `after`,
800
+ * `before`); `{ archived: true }` includes archived ones.
801
+ */
802
+ list(params = {}) {
803
+ const { archived, ...page } = params;
804
+ return this.http.request({
805
+ method: "GET",
806
+ path: "/sms/messaging-programs",
807
+ query: { ...page, archived: archived === void 0 ? void 0 : archived ? "true" : "false" }
808
+ });
809
+ }
810
+ /**
811
+ * Create a program (201; `name` is required). Each field is checked by the
812
+ * carriers' rules: lengths, help and stop replies that are a sentence and
813
+ * not just a keyword, links to a real web address. Pass an
814
+ * `idempotencyKey` so a retry never makes a second one; one is generated
815
+ * when you don't.
816
+ */
817
+ create(body, opts = {}) {
818
+ return this.http.request({
819
+ method: "POST",
820
+ path: "/sms/messaging-programs",
821
+ body,
822
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
823
+ });
824
+ }
825
+ /** One program, archived ones too. */
826
+ get(id) {
827
+ return this.http.request({ method: "GET", path: `/sms/messaging-programs/${enc(id)}` });
828
+ }
829
+ /**
830
+ * Edit a program: only the fields you send change, `null` clears one, and
831
+ * the result must still pass the carriers' rules. `revision` moves on a
832
+ * material change. An archived program is a `409`: `duplicate` it to keep
833
+ * editing.
834
+ */
835
+ update(id, body) {
836
+ return this.http.request({ method: "PATCH", path: `/sms/messaging-programs/${enc(id)}`, body });
837
+ }
838
+ /** Archive a program. Registrations that copied it keep their copy. */
839
+ delete(id) {
840
+ return this.http.request({ method: "DELETE", path: `/sms/messaging-programs/${enc(id)}` });
841
+ }
842
+ /**
843
+ * Copy a program (an archived one too) into a new editable one named
844
+ * "… (copy)" at revision 1 (201). It sends no body. Pass an
845
+ * `idempotencyKey` so a retry returns the same copy; one is generated when
846
+ * you don't.
847
+ */
848
+ duplicate(id, opts = {}) {
849
+ const body = void 0;
850
+ return this.http.request({
851
+ method: "POST",
852
+ path: `/sms/messaging-programs/${enc(id)}/duplicate`,
853
+ body,
854
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
855
+ });
856
+ }
857
+ };
858
+ var SmsTestDestinations = class extends Resource {
859
+ /** Your test numbers, newest first, cursor-paginated (`limit`, `after`, `before`). */
860
+ list(params = {}) {
861
+ return this.http.request({ method: "GET", path: "/sms/test-destinations", query: params });
862
+ }
863
+ /** Remove a test number; template tests can no longer text it. */
864
+ delete(id) {
865
+ return this.http.request({ method: "DELETE", path: `/sms/test-destinations/${enc(id)}` });
866
+ }
867
+ };
868
+ var SmsConsentSetups = class extends Resource {
869
+ /**
870
+ * Your consent setups except archived ones, newest first, cursor-paginated
871
+ * (`limit`, `after`, `before`).
872
+ */
873
+ list(params = {}) {
874
+ return this.http.request({ method: "GET", path: "/sms/consent-setups", query: params });
875
+ }
876
+ };
877
+ var SmsBilling = class extends Resource {
878
+ /**
879
+ * What the workspace pays for SMS every month: each number and 10DLC
880
+ * campaign, its monthly price, status and next charge, and for a past-due
881
+ * number the date it is released (`grace_until`). Newest first,
882
+ * cursor-paginated (`limit`, `after`, `before`).
883
+ */
884
+ listResources(params = {}) {
885
+ return this.http.request({ method: "GET", path: "/sms/billing/resources", query: params });
886
+ }
887
+ };
888
+ var SmsQuotes = class extends Resource {
889
+ /**
890
+ * Price an order (201). The quote binds the action and what it buys, and
891
+ * returns `due_now_cents`, `monthly_cents`, `line_items` and a single-use
892
+ * `confirm_token` (only in this response). It lasts 10 minutes and charges
893
+ * nothing. Needs `sms:manage`.
894
+ */
895
+ create(body) {
896
+ return this.http.request({ method: "POST", path: "/sms/quotes", body });
897
+ }
898
+ /** One quote: its price, status and, once confirmed, what the order made. Needs `sms:read`. */
899
+ get(id) {
900
+ return this.http.request({ method: "GET", path: `/sms/quotes/${enc(id)}` });
901
+ }
902
+ /**
903
+ * Place the quoted order and charge it. Show the person the quote's price
904
+ * and get their yes first. Needs `sms:purchase`, which a key or app has
905
+ * only when a member who holds it ticked it, and the owner's monthly cap for
906
+ * SMS purchases by API. A changed price or content answers `409`: quote
907
+ * again. If you don't pass `idempotencyKey`, one is generated so a retry
908
+ * can't buy twice; pass your own to replay the same answer later.
909
+ */
910
+ confirm(id, body, opts = {}) {
911
+ return this.http.request({
912
+ method: "POST",
913
+ path: `/sms/quotes/${enc(id)}/confirm`,
914
+ body,
915
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
916
+ });
917
+ }
918
+ };
919
+ var SmsRegistrations = class extends Resource {
920
+ /**
921
+ * Your registrations, newest first, cursor-paginated (`limit`, `after`,
922
+ * `before`). A 10DLC campaign also carries the number it backs (`sender`)
923
+ * and one `setup_state`.
924
+ */
925
+ list(params = {}) {
926
+ return this.http.request({ method: "GET", path: "/sms/registrations", query: params });
927
+ }
928
+ /**
929
+ * One registration (`sreg_…`), as `list()` reads it. Read a resubmit, a
930
+ * removal or a replacement back with it.
931
+ */
932
+ get(registrationId) {
933
+ return this.http.request({ method: "GET", path: `/sms/registrations/${enc(registrationId)}` });
934
+ }
935
+ /**
936
+ * Remove a 10DLC setup: take down a campaign registration
937
+ * (`us_ten_dlc_campaign`) that has no active number. The carrier
938
+ * registration is deleted, the campaign's monthly fee ends (no proration)
939
+ * and the registration reads `archived_at` from then on. A campaign with a
940
+ * number answers `409 resource_in_use` (release the number first with
941
+ * `sms.releaseNumber`); one under carrier review answers `409 conflict`.
942
+ * Pass an `idempotencyKey` so a retry removes once; one is generated when
943
+ * you don't.
944
+ */
945
+ remove(registrationId, body = {}, opts = {}) {
946
+ return this.http.request({
947
+ method: "POST",
948
+ path: `/sms/registrations/${enc(registrationId)}/remove`,
949
+ body,
950
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
951
+ });
952
+ }
953
+ /**
954
+ * Replace an approved 10DLC brand registration (`us_ten_dlc_brand`):
955
+ * archive it so the brand can be registered again (corrected legal
956
+ * details, a new owner of the EIN). The brand unlocks for
957
+ * `sms.updateBrand`, and the new registration is a quote and its confirm
958
+ * (`ten_dlc_brand_registration`). Nothing changes at the carrier and
959
+ * nothing is charged here. Refused while a number on the brand isn't
960
+ * released or a 10DLC setup on it isn't removed (`409 resource_in_use`,
961
+ * with `dependents`). Pass an `idempotencyKey` so a retry replaces once;
962
+ * one is generated when you don't.
963
+ */
964
+ replace(registrationId, body = {}, opts = {}) {
965
+ return this.http.request({
966
+ method: "POST",
967
+ path: `/sms/registrations/${enc(registrationId)}/replace`,
968
+ body,
969
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
970
+ });
971
+ }
972
+ /**
973
+ * Resubmit a 10DLC campaign carriers sent back (free), after fixing what
974
+ * its feedback names: an optional `opt_in_screenshot_file_id`, or
975
+ * `acknowledge_unchanged` when the fix was made outside Unitpost. Pass an
976
+ * `idempotencyKey` so a retry resubmits once; one is generated when you
977
+ * don't.
978
+ */
979
+ resubmit(registrationId, body, opts = {}) {
980
+ return this.http.request({
981
+ method: "POST",
982
+ path: `/sms/registrations/${enc(registrationId)}/resubmit`,
983
+ body,
984
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
985
+ });
986
+ }
987
+ /**
988
+ * Request a campaign's number again after it failed, when its fee is
989
+ * already committed (free). A number the fee doesn't cover answers `409
990
+ * quote_required`: order it through `sms.quotes` (`ten_dlc_number`). Pass
991
+ * an `idempotencyKey` so a retry requests one number; one is generated when
992
+ * you don't.
993
+ */
994
+ requestNumber(registrationId, body = {}, opts = {}) {
995
+ return this.http.request({
996
+ method: "POST",
997
+ path: `/sms/registrations/${enc(registrationId)}/number`,
998
+ body,
999
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
1000
+ });
1001
+ }
1002
+ };
1003
+ var Email = class extends Resource {
1004
+ topics;
1005
+ campaigns;
1006
+ templates;
1007
+ domains;
1008
+ /** Inbox conversations: list, read, delete and reply. */
1009
+ threads;
1010
+ constructor(http) {
1011
+ super(http);
1012
+ this.topics = new Topics(http);
1013
+ this.campaigns = new Campaigns(http);
1014
+ this.templates = new Templates(http);
1015
+ this.domains = new Domains(http);
1016
+ this.threads = new EmailThreads(http);
1017
+ }
1018
+ /**
1019
+ * Send or schedule a transactional email.
1020
+ *
1021
+ * If you don't pass `idempotencyKey`, the SDK generates one automatically so
1022
+ * the request is safe to auto-retry (a network blip can't double-send). Pass
1023
+ * your own to dedupe across separate `send()` calls.
1024
+ */
1025
+ send(body, opts = {}) {
1026
+ return this.http.request({
1027
+ method: "POST",
1028
+ path: "/email",
1029
+ body,
1030
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
1031
+ });
1032
+ }
1033
+ /**
1034
+ * Send up to 100 emails in one request (all-or-nothing validation).
1035
+ *
1036
+ * Like `send()`, if you don't pass `idempotencyKey` the SDK generates one so a
1037
+ * transient failure can be safely auto-retried (the server dedupes the batch
1038
+ * on the key and replays the original result instead of re-sending). Pass your
1039
+ * own to dedupe across separate `batch()` calls.
1040
+ */
1041
+ batch(body, opts = {}) {
1042
+ return this.http.request({
1043
+ method: "POST",
1044
+ path: "/email/batch",
1045
+ body,
1046
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
1047
+ });
1048
+ }
1049
+ /** Retrieve a batch by id. */
1050
+ getBatch(id) {
1051
+ return this.http.request({ method: "GET", path: `/email/batches/${enc(id)}` });
1052
+ }
1053
+ /** Cancel every still-cancelable message in a batch. */
1054
+ cancelBatch(id) {
1055
+ return this.http.request({ method: "POST", path: `/email/batches/${enc(id)}/cancel` });
1056
+ }
1057
+ /**
1058
+ * Your batch sends, newest first (cursor-paginated), as the dashboard's
1059
+ * Batches tab lists them. Each row is the same live rollup `getBatch`
1060
+ * returns: how many emails it holds, when it's scheduled, a count per
1061
+ * delivery status and how many are still cancelable.
1062
+ */
1063
+ listBatches(params = {}) {
1064
+ return this.http.request({ method: "GET", path: "/email/batches", query: params });
1065
+ }
1066
+ /** List sent/scheduled emails (cursor-paginated). */
1067
+ list(params = {}) {
1068
+ return this.http.request({ method: "GET", path: "/email", query: params });
1069
+ }
1070
+ /** Async-iterate every sent/scheduled email (same filters as `list`). */
1071
+ listAll(params = {}) {
1072
+ return paginate(this.http, "/email", params);
1073
+ }
1074
+ /** Retrieve a sent or scheduled email, with its `cc`, `bcc`, `reply_to` and `tags`. */
1075
+ get(id) {
1076
+ return this.http.request({ method: "GET", path: `/email/${enc(id)}` });
1077
+ }
1078
+ /**
1079
+ * One sent email's delivery events, oldest first, as the dashboard's email
1080
+ * detail shows the timeline. Each event carries its detail in `data` under
1081
+ * the webhook's names (`data.bounce.diagnostic_code`, `data.click.link`,
1082
+ * `data.complaint.feedback_type`, ...). Cursor-paginated: `after` /
1083
+ * `before` take an `emev_` id. Needs `emails:read`.
1084
+ */
1085
+ listEvents(id, params = {}) {
1086
+ return this.http.request({ method: "GET", path: `/email/${enc(id)}/events`, query: params });
1087
+ }
1088
+ /** Cancel or reschedule a scheduled/queued email. */
1089
+ update(id, body) {
1090
+ return this.http.request({ method: "PATCH", path: `/email/${enc(id)}`, body });
1091
+ }
1092
+ /**
1093
+ * Send a `failed` email again on the same `id`, as the dashboard's Retry
1094
+ * does. Only a one-off send whose failure was temporary is retried: a
1095
+ * campaign recipient, a template test, a suppressed or rejected send, or a
1096
+ * content error is a `409` saying why (send a new email instead). It passes
1097
+ * the same checks as a new send: the sending domain, your plan and quota.
1098
+ * It sends no body; follow the email with `get`.
1099
+ *
1100
+ * It sends real email, so if you don't pass `idempotencyKey` the SDK
1101
+ * generates one, which makes an auto-retry safe. Pass your own to dedupe
1102
+ * across separate `retry()` calls.
1103
+ */
1104
+ retry(id, opts = {}) {
1105
+ const body = void 0;
1106
+ return this.http.request({
1107
+ method: "POST",
1108
+ path: `/email/${enc(id)}/retry`,
1109
+ body,
1110
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
1111
+ });
1112
+ }
1113
+ /**
1114
+ * Deliverability / engagement stats over a rolling window or a period.
1115
+ *
1116
+ * `days` is the window size (1–365); defaults to 30 server-side. Or count a
1117
+ * period with `from` and `to`; add `grain` (and `tz`) for `series`, the send
1118
+ * volume per bucket. `domain_id` counts one sending domain. A value the API
1119
+ * can't apply is ignored and named in the `Unitpost-Warning` response
1120
+ * header; `Unitpost-Strict: true` refuses it instead.
1121
+ */
1122
+ stats(params = {}) {
1123
+ return this.http.request({ method: "GET", path: "/email/stats", query: params });
1124
+ }
1125
+ // --- Inbound (received) emails ---
1126
+ receivedList(params = {}) {
1127
+ return this.http.request({ method: "GET", path: "/email/received", query: params });
1128
+ }
1129
+ receivedGet(id) {
1130
+ return this.http.request({ method: "GET", path: `/email/received/${enc(id)}` });
1131
+ }
1132
+ receivedAttachmentUrl(id, attachmentId) {
1133
+ return this.http.request({ method: "GET", path: `/email/received/${enc(id)}/attachments/${enc(attachmentId)}` });
1134
+ }
1135
+ /**
1136
+ * A signed URL to download the received message's original MIME (`.eml`),
1137
+ * valid for about 5 minutes (`expires_at`), with its `size_bytes`. A body
1138
+ * over 256 KB isn't inlined on `receivedGet` (its `text` and `html` are
1139
+ * `null`), so this is how to read it. A copy of one of your own sends
1140
+ * (`sent_by_us`) is a `403`. Needs `emails:read`.
1141
+ */
1142
+ receivedRaw(id) {
1143
+ return this.http.request({ method: "GET", path: `/email/received/${enc(id)}/raw` });
1144
+ }
1145
+ };
1146
+ var Contacts = class extends Resource {
1147
+ list(params = {}) {
1148
+ return this.http.request({ method: "GET", path: "/contacts", query: params });
1149
+ }
1150
+ listAll(params = {}) {
1151
+ return paginate(this.http, "/contacts", params);
1152
+ }
1153
+ create(body) {
1154
+ return this.http.request({ method: "POST", path: "/contacts", body });
1155
+ }
1156
+ /** Retrieve by contact id or email. */
1157
+ get(idOrEmail) {
1158
+ return this.http.request({ method: "GET", path: `/contacts/${enc(idOrEmail)}` });
1159
+ }
1160
+ update(idOrEmail, body) {
1161
+ return this.http.request({ method: "PATCH", path: `/contacts/${enc(idOrEmail)}`, body });
1162
+ }
1163
+ delete(idOrEmail) {
1164
+ return this.http.request({ method: "DELETE", path: `/contacts/${enc(idOrEmail)}` });
1165
+ }
1166
+ /** Start an async contact import. */
1167
+ import(body) {
1168
+ return this.http.request({ method: "POST", path: "/contacts/imports", body });
1169
+ }
1170
+ listImports(params = {}) {
1171
+ return this.http.request({ method: "GET", path: "/contacts/imports", query: params });
1172
+ }
1173
+ getImport(id) {
1174
+ return this.http.request({ method: "GET", path: `/contacts/imports/${enc(id)}` });
1175
+ }
1176
+ cancelImport(id) {
1177
+ return this.http.request({ method: "POST", path: `/contacts/imports/${enc(id)}/cancel` });
1178
+ }
1179
+ /** Re-run a failed import from its stored rows (202); rows already added are skipped. */
1180
+ retryImport(id) {
1181
+ return this.http.request({ method: "POST", path: `/contacts/imports/${enc(id)}/retry` });
1182
+ }
1183
+ /** The contact's email addresses and phone numbers, with each one's status (one page, never `has_more`). */
1184
+ addresses(idOrEmail) {
1185
+ return this.http.request({ method: "GET", path: `/contacts/${enc(idOrEmail)}/addresses` });
1186
+ }
1187
+ /** The contact's most recent emails and texts, newest first (`limit` 1–100, default 25; no cursor). */
1188
+ activity(idOrEmail, params = {}) {
1189
+ return this.http.request({ method: "GET", path: `/contacts/${enc(idOrEmail)}/activity`, query: params });
1190
+ }
1191
+ /**
1192
+ * The segments the contact is in, with its per-segment opt-out (not
1193
+ * paginated). To add the contact to a static segment or remove it, use
1194
+ * `segments.addMember` / `segments.removeMember`.
1195
+ */
1196
+ listSegments(idOrEmail) {
1197
+ return this.http.request({ method: "GET", path: `/contacts/${enc(idOrEmail)}/segments` });
1198
+ }
1199
+ /**
1200
+ * Export contacts to a CSV file (202), as the Contacts page's Export does:
1201
+ * every contact, or the ones the filters match (`q`, `status`, `phone`,
1202
+ * `segment_id`, `segment_subscription`, as on `list`). It runs as a
1203
+ * background job: follow it with `jobs.get(job.id)`, then fetch the file
1204
+ * with `jobs.download(job.id)`. One export runs at a time: another while it
1205
+ * runs is a `409` `job_in_progress`. `segment_id` also needs `segments:read`.
1206
+ */
1207
+ export(body = {}) {
1208
+ return this.http.request({ method: "POST", path: "/contacts/export", body });
1209
+ }
1210
+ };
1211
+ var ContactFields = class extends Resource {
1212
+ list(params = {}) {
1213
+ return this.http.request({ method: "GET", path: "/contact-fields", query: params });
1214
+ }
1215
+ listAll(params = {}) {
1216
+ return paginate(this.http, "/contact-fields", params);
1217
+ }
1218
+ create(body) {
1219
+ return this.http.request({ method: "POST", path: "/contact-fields", body });
1220
+ }
1221
+ get(id) {
1222
+ return this.http.request({ method: "GET", path: `/contact-fields/${enc(id)}` });
1223
+ }
1224
+ update(id, body) {
1225
+ return this.http.request({ method: "PATCH", path: `/contact-fields/${enc(id)}`, body });
1226
+ }
1227
+ /**
1228
+ * `null` (204) when the field was deleted at once; a `Job` (202) when it
1229
+ * held a value on more than 5,000 contacts and the delete runs in the
1230
+ * background — follow it with `jobs.get(job.id)`.
1231
+ */
1232
+ delete(id) {
1233
+ return this.http.request({ method: "DELETE", path: `/contact-fields/${enc(id)}` });
1234
+ }
1235
+ /**
1236
+ * The renamed `ContactField` (200), or a `Job` (202) when more than 5,000
1237
+ * contacts hold the field: the key is already renamed and the values move in
1238
+ * the background — follow it with `jobs.get(job.id)`. Tell them apart with
1239
+ * `object` (`"contact_field"` / `"job"`).
1240
+ */
1241
+ rename(id, body) {
1242
+ return this.http.request({ method: "POST", path: `/contact-fields/${enc(id)}/rename`, body });
1243
+ }
1244
+ };
1245
+ var Jobs = class extends Resource {
1246
+ /**
1247
+ * Your background jobs, newest first (cursor-paginated), as Settings → Bulk
1248
+ * operations lists them: the kinds an API operation starts that your key
1249
+ * may read. Filter with `status` or `kind` (`"contacts.export"`,
1250
+ * `"contact_field.delete"`, …).
1251
+ */
1252
+ list(params = {}) {
1253
+ return this.http.request({ method: "GET", path: "/jobs", query: params });
1254
+ }
1255
+ /**
1256
+ * Retrieve a background job — the `202` answer of an operation too large for
1257
+ * one request. Poll until `status` is `COMPLETED`, `FAILED` or `CANCELED`.
1258
+ */
1259
+ get(id) {
1260
+ return this.http.request({ method: "GET", path: `/jobs/${enc(id)}` });
1261
+ }
1262
+ /**
1263
+ * Stop a queued or running job. A running job stops after the part in
1264
+ * flight; the work already done stays. A kind that can't stop half-way (a
1265
+ * custom-field rename) is a `409` saying why. It sends no body.
1266
+ */
1267
+ cancel(id) {
1268
+ return this.http.request({ method: "POST", path: `/jobs/${enc(id)}/cancel` });
1269
+ }
1270
+ /**
1271
+ * Resume a `FAILED` job from where it stopped (202): nothing it already
1272
+ * processed runs again. Any other status is a `409`. It sends no body.
1273
+ */
1274
+ retry(id) {
1275
+ return this.http.request({ method: "POST", path: `/jobs/${enc(id)}/retry` });
1276
+ }
1277
+ /**
1278
+ * A finished job's file (a contacts export's CSV) as a signed `url` that
1279
+ * expires in 5 minutes: fetch it right away, and call `download` again for a
1280
+ * fresh one. A job that isn't `COMPLETED`, or a kind with no file, is a `409`.
1281
+ */
1282
+ download(id) {
1283
+ return this.http.request({ method: "GET", path: `/jobs/${enc(id)}/download` });
1284
+ }
1285
+ };
1286
+ var Segments = class extends Resource {
1287
+ list(params = {}) {
1288
+ return this.http.request({ method: "GET", path: "/segments", query: params });
1289
+ }
1290
+ listAll(params = {}) {
1291
+ return paginate(this.http, "/segments", params);
1292
+ }
1293
+ create(body) {
1294
+ return this.http.request({ method: "POST", path: "/segments", body });
1295
+ }
1296
+ get(id) {
1297
+ return this.http.request({ method: "GET", path: `/segments/${enc(id)}` });
1298
+ }
1299
+ update(id, body) {
1300
+ return this.http.request({ method: "PATCH", path: `/segments/${enc(id)}`, body });
1301
+ }
1302
+ delete(id) {
1303
+ return this.http.request({ method: "DELETE", path: `/segments/${enc(id)}` });
1304
+ }
1305
+ listMembers(id, params = {}) {
1306
+ return this.http.request({ method: "GET", path: `/segments/${enc(id)}/contacts`, query: params });
1307
+ }
1308
+ /** Add a contact (by id or email) to the segment. Idempotent. */
1309
+ addMember(id, body) {
1310
+ return this.http.request({ method: "POST", path: `/segments/${enc(id)}/contacts`, body });
1311
+ }
1312
+ /** Remove a contact (by id or email) from the segment. */
1313
+ removeMember(id, contact) {
1314
+ return this.http.request({ method: "DELETE", path: `/segments/${enc(id)}/contacts/${enc(contact)}` });
1315
+ }
1316
+ /**
1317
+ * Opt a member (by id or email) out of this segment's sends without
1318
+ * removing it (`{ subscribed: false }`), or back in, as the members table's
1319
+ * toggle does. It stays a member. A dynamic segment has no per-segment
1320
+ * opt-out (`422`).
1321
+ */
1322
+ updateMember(id, contact, body) {
1323
+ return this.http.request({ method: "PATCH", path: `/segments/${enc(id)}/contacts/${enc(contact)}`, body });
1324
+ }
1325
+ /**
1326
+ * How many contacts a saved segment reaches: its members, the subscribed
1327
+ * set a campaign would mail (`0` means a campaign would send nothing), and a
1328
+ * sample (which also needs `contacts:read`).
1329
+ */
1330
+ preview(id) {
1331
+ return this.http.request({ method: "GET", path: `/segments/${enc(id)}/preview` });
1332
+ }
1333
+ /**
1334
+ * Count an unsaved dynamic filter before you create the segment, as the
1335
+ * segment dialog's live count does: how many contacts match, how many of
1336
+ * them a campaign would mail, and a sample (which also needs
1337
+ * `contacts:read`). Nothing is saved.
1338
+ */
1339
+ previewFilter(body) {
1340
+ return this.http.request({ method: "POST", path: "/segments/preview", body });
1341
+ }
1342
+ /**
1343
+ * The workspace's managed "All subscribed contacts" segment, the
1344
+ * dashboard's "Everyone subscribed" campaign target: made the first time you
1345
+ * ask (201), the same segment after that (200). It sends no body.
1346
+ */
1347
+ allContacts() {
1348
+ return this.http.request({ method: "POST", path: "/segments/all-contacts" });
1349
+ }
1350
+ };
1351
+ var Topics = class extends Resource {
1352
+ list(params = {}) {
1353
+ return this.http.request({ method: "GET", path: "/email/topics", query: params });
1354
+ }
1355
+ listAll(params = {}) {
1356
+ return paginate(this.http, "/email/topics", params);
1357
+ }
1358
+ create(body) {
1359
+ return this.http.request({ method: "POST", path: "/email/topics", body });
1360
+ }
1361
+ get(id) {
1362
+ return this.http.request({ method: "GET", path: `/email/topics/${enc(id)}` });
1363
+ }
1364
+ update(id, body) {
1365
+ return this.http.request({ method: "PATCH", path: `/email/topics/${enc(id)}`, body });
1366
+ }
1367
+ delete(id) {
1368
+ return this.http.request({ method: "DELETE", path: `/email/topics/${enc(id)}` });
1369
+ }
1370
+ /**
1371
+ * Opt many contacts out of this topic as a background job (202, the `Job`):
1372
+ * `{ contact_ids }` or `{ emails }` (up to 1,000, each a contact of this
1373
+ * workspace) or `{ segment_id }` (every member, however many). Each is
1374
+ * opted out as `setTopic` would, with its webhook only when it was
1375
+ * subscribed. Follow it with `jobs.get(id)`. Pass an `idempotencyKey` so a
1376
+ * retry answers the same job; one is generated when you don't. There is no
1377
+ * bulk opt-in.
1378
+ */
1379
+ optOut(id, body, opts = {}) {
1380
+ return this.http.request({
1381
+ method: "POST",
1382
+ path: `/email/topics/${enc(id)}/opt-out`,
1383
+ body,
1384
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
1385
+ });
1386
+ }
1387
+ /** List a contact's effective topic subscriptions. */
1388
+ listTopics(contactId, params = {}) {
1389
+ return this.http.request({ method: "GET", path: `/contacts/${enc(contactId)}/topics`, query: params });
1390
+ }
1391
+ /** Set a contact's preference for one topic. */
1392
+ setTopic(contactId, body) {
1393
+ return this.http.request({ method: "POST", path: `/contacts/${enc(contactId)}/topics`, body });
1394
+ }
1395
+ /**
1396
+ * Change a contact's preferences for several topics in one call
1397
+ * (`{ topics: [{ topic_id, subscribed }] }`, up to 50, each topic once);
1398
+ * topics left out keep theirs. Every topic is checked before any is set (an
1399
+ * unknown one is a 404 and nothing changes). Answers the resolved
1400
+ * preferences in the order sent (`{ object: "list", has_more: false, data }`).
1401
+ * Idempotent.
1402
+ */
1403
+ updateTopics(contactId, body) {
1404
+ return this.http.request({ method: "PATCH", path: `/contacts/${enc(contactId)}/topics`, body });
459
1405
  }
460
1406
  };
461
1407
  var Campaigns = class extends Resource {
@@ -477,8 +1423,13 @@ var Campaigns = class extends Resource {
477
1423
  delete(id) {
478
1424
  return this.http.request({ method: "DELETE", path: `/email/campaigns/${enc(id)}` });
479
1425
  }
480
- send(id) {
481
- return this.http.request({ method: "POST", path: `/email/campaigns/${enc(id)}/send` });
1426
+ /**
1427
+ * Send a draft. `{}` (the default) arms its saved `scheduled_at` while that
1428
+ * is still ahead, otherwise sends NOW; `{ scheduled_at: "<ISO 8601>" }`
1429
+ * schedules it; `{ scheduled_at: null }` sends now.
1430
+ */
1431
+ send(id, body = {}) {
1432
+ return this.http.request({ method: "POST", path: `/email/campaigns/${enc(id)}/send`, body });
482
1433
  }
483
1434
  cancel(id) {
484
1435
  return this.http.request({ method: "POST", path: `/email/campaigns/${enc(id)}/cancel` });
@@ -491,13 +1442,82 @@ var Campaigns = class extends Resource {
491
1442
  resume(id) {
492
1443
  return this.http.request({ method: "POST", path: `/email/campaigns/${enc(id)}/resume` });
493
1444
  }
1445
+ /** Move a scheduled campaign back to draft so it can be edited; clears its send time. */
1446
+ unschedule(id) {
1447
+ return this.http.request({ method: "POST", path: `/email/campaigns/${enc(id)}/unschedule` });
1448
+ }
1449
+ /**
1450
+ * Copy a campaign into a new draft (201). Pass an `idempotencyKey` so a
1451
+ * retry returns the same copy; one is generated when you don't.
1452
+ */
1453
+ duplicate(id, body = {}, opts = {}) {
1454
+ return this.http.request({
1455
+ method: "POST",
1456
+ path: `/email/campaigns/${enc(id)}/duplicate`,
1457
+ body,
1458
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
1459
+ });
1460
+ }
494
1461
  reschedule(id, body) {
495
1462
  return this.http.request({ method: "POST", path: `/email/campaigns/${enc(id)}/reschedule`, body });
496
1463
  }
497
- /** Non-mutating pre-send validation report. */
1464
+ /**
1465
+ * Non-mutating pre-send validation report. A large audience is counted in
1466
+ * the background: the first call returns that `Job` (202). Call again until
1467
+ * it returns the report.
1468
+ */
498
1469
  validate(id) {
499
1470
  return this.http.request({ method: "GET", path: `/email/campaigns/${enc(id)}/validate` });
500
1471
  }
1472
+ /**
1473
+ * The campaign's results: delivered, unique opens and clicks, unsubscribes,
1474
+ * bounces, complaints and their rates. Every rate is `null` until something
1475
+ * was sent; open and click rates are `null` when that tracking was off.
1476
+ */
1477
+ stats(id) {
1478
+ return this.http.request({ method: "GET", path: `/email/campaigns/${enc(id)}/stats` });
1479
+ }
1480
+ /**
1481
+ * `stats` for up to 100 campaigns in one read (1–100 ids). An id that isn't
1482
+ * one of this workspace's email campaigns is left out of `data`, never an
1483
+ * error; `has_more` is always false.
1484
+ */
1485
+ listStats(ids) {
1486
+ return this.http.request({ method: "GET", path: "/email/campaigns/stats", query: { ids: ids.join(",") } });
1487
+ }
1488
+ /**
1489
+ * Who the campaign would reach if sent now, member by member: `sendable`,
1490
+ * `missing_data`, `suppressed` or `excluded`, with the reason. Pass the
1491
+ * page's `next_cursor` as `after` for the next page (rows carry no `id`).
1492
+ * A page can hold fewer rows than `limit` while `has_more` is true.
1493
+ */
1494
+ listRecipients(id, params = {}) {
1495
+ return this.http.request({ method: "GET", path: `/email/campaigns/${enc(id)}/recipients`, query: params });
1496
+ }
1497
+ /**
1498
+ * After an automatic quality pause: the recipients whose message
1499
+ * hard-bounced or drew a spam complaint. They're already suppressed; this is
1500
+ * for cleaning the source list. Up to 10,000; `has_more` says it was cut there.
1501
+ */
1502
+ listAffected(id) {
1503
+ return this.http.request({ method: "GET", path: `/email/campaigns/${enc(id)}/quality/affected` });
1504
+ }
1505
+ /**
1506
+ * After an automatic quality pause: take the flagged contacts out of the
1507
+ * campaign's static segment (needs `segments:write` too; a filter segment is
1508
+ * a `409`). A repeat removes nothing. It doesn't resume the campaign.
1509
+ */
1510
+ removeAffected(id) {
1511
+ return this.http.request({ method: "POST", path: `/email/campaigns/${enc(id)}/quality/remove-affected` });
1512
+ }
1513
+ /**
1514
+ * Ask for the review a campaign needs before it can resume after a repeat
1515
+ * quality pause (`resume` answers `409 review_required` until then). A
1516
+ * repeat answers `already_requested: true` and notifies no one.
1517
+ */
1518
+ requestReview(id) {
1519
+ return this.http.request({ method: "POST", path: `/email/campaigns/${enc(id)}/quality/request-review` });
1520
+ }
501
1521
  };
502
1522
  var Templates = class extends Resource {
503
1523
  list(params = {}) {
@@ -518,15 +1538,213 @@ var Templates = class extends Resource {
518
1538
  delete(id) {
519
1539
  return this.http.request({ method: "DELETE", path: `/email/templates/${enc(id)}` });
520
1540
  }
1541
+ /**
1542
+ * Send ONE test of the template to `to`, rendered with sample `variables`
1543
+ * exactly as a recipient gets it. Once a sending domain is verified it may
1544
+ * go to anyone; until then only to a member of your workspace.
1545
+ */
1546
+ testSend(id, body) {
1547
+ return this.http.request({ method: "POST", path: `/email/templates/${enc(id)}/test-send`, body });
1548
+ }
1549
+ /**
1550
+ * The `subject`, `html` and `text` a send of this template would carry,
1551
+ * with your footer and branding, filled from `variables` (and from a
1552
+ * contact's fields with `contact_id`). It sends and stores nothing, so it
1553
+ * takes no idempotency key. `missing_variables` lists the variables left
1554
+ * without a value: they render as a literal `{{token}}`, and a real send
1555
+ * would refuse them. The body is optional: `{}` renders with no variables.
1556
+ * Needs `templates:read`, and has its own per-workspace rate limit.
1557
+ */
1558
+ render(id, body = {}) {
1559
+ return this.http.request({ method: "POST", path: `/email/templates/${enc(id)}/render`, body });
1560
+ }
1561
+ /**
1562
+ * Copy a template into a new draft (201): its name (with " (copy)", or your
1563
+ * `name`), subject, editor and body carry over; its status, versions and
1564
+ * usage don't. Pass an `idempotencyKey` so a retry returns the same copy;
1565
+ * one is generated when you don't.
1566
+ */
1567
+ duplicate(id, body = {}, opts = {}) {
1568
+ return this.http.request({
1569
+ method: "POST",
1570
+ path: `/email/templates/${enc(id)}/duplicate`,
1571
+ body,
1572
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
1573
+ });
1574
+ }
1575
+ /**
1576
+ * Add one of the gallery's ready-made emails (unitpost.com/templates) to
1577
+ * your workspace as a draft Design template (201). `slug` names it; the ones
1578
+ * marked for paid plans answer `403 limit_reached` on the free plan. Pass an
1579
+ * `idempotencyKey` so a retry returns the same template; one is generated
1580
+ * when you don't.
1581
+ */
1582
+ fromLibrary(body, opts = {}) {
1583
+ return this.http.request({
1584
+ method: "POST",
1585
+ path: "/email/templates/from-library",
1586
+ body,
1587
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
1588
+ });
1589
+ }
1590
+ /**
1591
+ * What uses the template, and whether a change would be accepted now: the
1592
+ * campaigns that reference it, its live campaigns and automations, queued
1593
+ * sends, and `can_edit_content` / `can_unpublish` with the reason when not.
1594
+ * Read it before an edit or a delete: a content edit is refused while a
1595
+ * live campaign renders the template, and a delete while any campaign uses
1596
+ * it.
1597
+ */
1598
+ usage(id) {
1599
+ return this.http.request({ method: "GET", path: `/email/templates/${enc(id)}/usage` });
1600
+ }
1601
+ /**
1602
+ * The template's history, newest first: a version is added on every publish
1603
+ * and on every content save while it's published. It pages by version
1604
+ * number: pass the last row's `version` (an integer, not an id) as `after`.
1605
+ * There is no `before`.
1606
+ */
1607
+ listVersions(id, params = {}) {
1608
+ return this.http.request({ method: "GET", path: `/email/templates/${enc(id)}/versions`, query: params });
1609
+ }
1610
+ /**
1611
+ * Put a version's subject and body back, as the editor's History → Restore
1612
+ * does. It is an update, so a system template, or one a live campaign
1613
+ * renders, is refused with a `409` naming why (`usage` says so up front).
1614
+ * On a published template the restore adds a new version; history is never
1615
+ * rewritten. It sends no body.
1616
+ */
1617
+ restoreVersion(id, version) {
1618
+ return this.http.request({
1619
+ method: "POST",
1620
+ path: `/email/templates/${enc(id)}/versions/${enc(String(version))}/restore`
1621
+ });
1622
+ }
1623
+ };
1624
+ var EmailThreads = class extends Resource {
1625
+ /**
1626
+ * Every conversation (Spam included), newest activity first. `q` searches
1627
+ * the subject, the sender and the opening words. Pass the page's
1628
+ * `next_cursor` as `after` for the next page (not the last row's `id`).
1629
+ */
1630
+ list(params = {}) {
1631
+ return this.http.request({ method: "GET", path: "/email/threads", query: params });
1632
+ }
1633
+ /**
1634
+ * One conversation, oldest message first: what you received (with bodies)
1635
+ * and what you sent from it (status and recipients, no body).
1636
+ */
1637
+ get(id) {
1638
+ return this.http.request({ method: "GET", path: `/email/threads/${enc(id)}` });
1639
+ }
1640
+ /**
1641
+ * Delete a conversation for good: its received messages are erased; replies
1642
+ * and forwards sent from it stay on your sent emails. It can't be undone.
1643
+ */
1644
+ delete(id) {
1645
+ return this.http.request({ method: "DELETE", path: `/email/threads/${enc(id)}` });
1646
+ }
1647
+ /**
1648
+ * Reply, reply all or forward one received message of the conversation
1649
+ * (`received_email_id`): your `text`/`html` go on top and the original is
1650
+ * quoted under them. It sends now and marks the conversation read.
1651
+ *
1652
+ * It sends real email, so if you don't pass `idempotencyKey` the SDK
1653
+ * generates one, which makes an auto-retry safe. Pass your own to dedupe
1654
+ * across separate `reply()` calls.
1655
+ */
1656
+ reply(id, body, opts = {}) {
1657
+ return this.http.request({
1658
+ method: "POST",
1659
+ path: `/email/threads/${enc(id)}/reply`,
1660
+ body,
1661
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
1662
+ });
1663
+ }
521
1664
  };
522
1665
  var BrandKits = class extends Resource {
523
1666
  /** List profiles (max 5). Optional `name` filters by display name. */
524
1667
  list(params = {}) {
525
1668
  return this.http.request({ method: "GET", path: "/brand-kits", query: params });
526
1669
  }
527
- /** Retrieve one profile by `bk_…` id. */
528
- get(id) {
529
- return this.http.request({ method: "GET", path: `/brand-kits/${enc(id)}` });
1670
+ /** Retrieve one profile by `bk_…` id. */
1671
+ get(id) {
1672
+ return this.http.request({ method: "GET", path: `/brand-kits/${enc(id)}` });
1673
+ }
1674
+ /**
1675
+ * Create an empty profile (201); `name` is unique in the workspace. The
1676
+ * first profile, or one with `make_default`, becomes the default. At most
1677
+ * five profiles (`403 limit_reached`). Fill it with `update` or `import`.
1678
+ */
1679
+ create(body) {
1680
+ return this.http.request({ method: "POST", path: "/brand-kits", body });
1681
+ }
1682
+ /**
1683
+ * Edit a profile: only the fields you send change, a list replaces the
1684
+ * list, and `null` or `""` clears a text field. `graphics` pins library
1685
+ * images by `image_id` (`img_…`). `sync_visual` on the default profile also
1686
+ * sets the email branding's accent from its colors.
1687
+ */
1688
+ update(id, body) {
1689
+ return this.http.request({ method: "PATCH", path: `/brand-kits/${enc(id)}`, body });
1690
+ }
1691
+ /**
1692
+ * Delete a profile. When it was the default, the oldest remaining profile
1693
+ * becomes the default. The last profile can't be deleted (`409`): `reset`
1694
+ * it instead. Its pinned images stay in the library.
1695
+ */
1696
+ delete(id) {
1697
+ return this.http.request({ method: "DELETE", path: `/brand-kits/${enc(id)}` });
1698
+ }
1699
+ /**
1700
+ * Clear a profile's content (voice, colors, graphics, pages), keeping its
1701
+ * name and whether it's the default. It sends no body.
1702
+ */
1703
+ reset(id) {
1704
+ return this.http.request({ method: "POST", path: `/brand-kits/${enc(id)}/reset` });
1705
+ }
1706
+ /** Make a profile the default: the one agents write with unless told otherwise. It sends no body. */
1707
+ setDefault(id) {
1708
+ return this.http.request({ method: "POST", path: `/brand-kits/${enc(id)}/set-default` });
1709
+ }
1710
+ /**
1711
+ * Add a graphic (201) from a public https image `url` (fetched once, no
1712
+ * redirects): it goes into the image library, counted against its storage,
1713
+ * and is pinned with its `role` (default `logo`). To pin an image already in
1714
+ * the library, `update` the profile's `graphics`.
1715
+ */
1716
+ addGraphic(id, body) {
1717
+ return this.http.request({ method: "POST", path: `/brand-kits/${enc(id)}/graphics`, body });
1718
+ }
1719
+ /**
1720
+ * Build a profile from a website (`url`, or a bare domain) or the brand's
1721
+ * own words (`text`). It runs in the background, usually under a minute
1722
+ * (202): follow it with `getImport`. By default the result is applied when
1723
+ * it lands, to `brand_kit_id`, else the default profile, or a new one when
1724
+ * the default already has content. With `review: true` it stops at a
1725
+ * proposal (`preview_ready`) for `acceptImport`; one review import is open
1726
+ * at a time, and a new one replaces it.
1727
+ */
1728
+ import(body) {
1729
+ return this.http.request({ method: "POST", path: "/brand-kits/imports", body });
1730
+ }
1731
+ /** One import: its status, the proposal once it's ready, warnings and any error. */
1732
+ getImport(id) {
1733
+ return this.http.request({ method: "GET", path: `/brand-kits/imports/${enc(id)}` });
1734
+ }
1735
+ /**
1736
+ * Apply a review import's proposal (`preview_ready`) to a profile: voice,
1737
+ * colors and pages, and its logos and backgrounds brought into the image
1738
+ * library and pinned. The body is optional: `brand_kit_id` applies it to
1739
+ * another profile, `name` names it. To change other fields, accept and then
1740
+ * `update`.
1741
+ */
1742
+ acceptImport(id, body = {}) {
1743
+ return this.http.request({ method: "POST", path: `/brand-kits/imports/${enc(id)}/accept`, body });
1744
+ }
1745
+ /** Discard a review import's proposal or stop its crawl. It sends no body. */
1746
+ cancelImport(id) {
1747
+ return this.http.request({ method: "POST", path: `/brand-kits/imports/${enc(id)}/cancel` });
530
1748
  }
531
1749
  };
532
1750
  var Domains = class extends Resource {
@@ -552,6 +1770,46 @@ var Domains = class extends Resource {
552
1770
  verify(id) {
553
1771
  return this.http.request({ method: "POST", path: `/email/domains/${enc(id)}/verify` });
554
1772
  }
1773
+ /** Explain the domain's DNS: every nameserver's answer per record, and ranked findings with fixes. Read-only. */
1774
+ diagnose(id) {
1775
+ return this.http.request({ method: "GET", path: `/email/domains/${enc(id)}/diagnose` });
1776
+ }
1777
+ // --- Sender addresses (`/email/senders`, `sndr_…`): saved From addresses ---
1778
+ /**
1779
+ * Your saved From addresses, as the domain page lists them and the
1780
+ * dashboard's From pickers offer them: each a mailbox on one of your
1781
+ * domains, with its display name and `from`, the value to send with.
1782
+ * `domain_id` keeps one domain's. A sender can send once its domain can.
1783
+ */
1784
+ listSenders(params = {}) {
1785
+ return this.http.request({ method: "GET", path: "/email/senders", query: params });
1786
+ }
1787
+ /**
1788
+ * Save a From address on one of your domains (201); the domain may still be
1789
+ * verifying. A mailbox already saved on that domain is a `409`, so a retry
1790
+ * never saves it twice.
1791
+ */
1792
+ createSender(body) {
1793
+ return this.http.request({ method: "POST", path: "/email/senders", body });
1794
+ }
1795
+ /** One saved From address. */
1796
+ getSender(id) {
1797
+ return this.http.request({ method: "GET", path: `/email/senders/${enc(id)}` });
1798
+ }
1799
+ /**
1800
+ * Change a sender's display name (`null` or `""` clears it), the only field
1801
+ * that changes: a different mailbox is a new sender.
1802
+ */
1803
+ updateSender(id, body) {
1804
+ return this.http.request({ method: "PATCH", path: `/email/senders/${enc(id)}`, body });
1805
+ }
1806
+ /**
1807
+ * Remove a saved From address from the pickers. Templates and campaigns that
1808
+ * send from it keep their From.
1809
+ */
1810
+ deleteSender(id) {
1811
+ return this.http.request({ method: "DELETE", path: `/email/senders/${enc(id)}` });
1812
+ }
555
1813
  };
556
1814
  var Webhooks = class extends Resource {
557
1815
  list(params = {}) {
@@ -564,6 +1822,10 @@ var Webhooks = class extends Resource {
564
1822
  create(body) {
565
1823
  return this.http.request({ method: "POST", path: "/webhooks", body });
566
1824
  }
1825
+ /**
1826
+ * One endpoint, with its `backlog`: the deliveries `flush` would send
1827
+ * (`queued` while it was paused, and `failed`).
1828
+ */
567
1829
  get(id) {
568
1830
  return this.http.request({ method: "GET", path: `/webhooks/${enc(id)}` });
569
1831
  }
@@ -577,16 +1839,65 @@ var Webhooks = class extends Resource {
577
1839
  test(id) {
578
1840
  return this.http.request({ method: "POST", path: `/webhooks/${enc(id)}/test` });
579
1841
  }
1842
+ /**
1843
+ * Mint a new signing secret. The response carries it exactly once; the old
1844
+ * secret co-signs deliveries until `previous_secret_expires_at` (24 h).
1845
+ */
1846
+ rotateSecret(id) {
1847
+ return this.http.request({ method: "POST", path: `/webhooks/${enc(id)}/rotate-secret` });
1848
+ }
1849
+ /**
1850
+ * The endpoint's delivery log, newest first (cursor-paginated). Narrow it
1851
+ * with `status` (comma-separated, e.g. `"failed,exhausted"`) and
1852
+ * `event_type` (e.g. `email.bounced`).
1853
+ */
1854
+ listDeliveries(id, params = {}) {
1855
+ return this.http.request({ method: "GET", path: `/webhooks/${enc(id)}/deliveries`, query: params });
1856
+ }
1857
+ /** Async-iterate every delivery of the endpoint (same filters as `listDeliveries`). */
1858
+ listAllDeliveries(id, params = {}) {
1859
+ return paginate(this.http, `/webhooks/${enc(id)}/deliveries`, params);
1860
+ }
1861
+ /**
1862
+ * Deliver one event to the endpoint again (202), as the dashboard's Replay
1863
+ * does. The same event goes out with the same id, so a receiver that
1864
+ * dedupes on it treats the replay as the delivery it already has. The
1865
+ * webhook must be enabled: a disabled or suspended one is a `409`
1866
+ * (re-enable it with `update` first). Find deliveries with
1867
+ * `listDeliveries`. It sends no body.
1868
+ */
1869
+ replayDelivery(id, deliveryId) {
1870
+ return this.http.request({
1871
+ method: "POST",
1872
+ path: `/webhooks/${enc(id)}/deliveries/${enc(deliveryId)}/replay`
1873
+ });
1874
+ }
1875
+ /**
1876
+ * Deliver the backlog (202): the deliveries held while the webhook was
1877
+ * suspended (`queued`), as the dashboard's "Retry queued" does. With
1878
+ * `include_failed: true`, also the ones that failed for good (`failed`,
1879
+ * `exhausted`). The webhook must be enabled: a disabled or suspended one is
1880
+ * a `409` (re-enable it with `update` first); re-enabling never delivers the
1881
+ * backlog on its own. `flushed` counts the deliveries handed back.
1882
+ */
1883
+ flush(id, body = {}) {
1884
+ return this.http.request({ method: "POST", path: `/webhooks/${enc(id)}/flush`, body });
1885
+ }
580
1886
  /**
581
1887
  * Verify a webhook delivery's signature and return the parsed event. Throws
582
1888
  * `WebhookVerificationError` on a missing/invalid/stale signature. Alias of the
583
- * top-level `verifyWebhook` for a Resend-style `unitpost.webhooks.verify(...)`.
1889
+ * top-level `verifyWebhook`, callable as `unitpost.webhooks.verify(...)`.
584
1890
  */
585
1891
  verify(args) {
586
1892
  return verifyWebhook(args);
587
1893
  }
588
1894
  };
589
1895
  var ApiKeys = class extends Resource {
1896
+ /**
1897
+ * The workspace's API keys (prefix, scope, capabilities, last use; never
1898
+ * the secret). With an API key or an MCP sign-in it needs `apikeys:read`,
1899
+ * which no key preset includes.
1900
+ */
590
1901
  list(params = {}) {
591
1902
  return this.http.request({ method: "GET", path: "/api-keys", query: params });
592
1903
  }
@@ -600,13 +1911,44 @@ var ApiKeys = class extends Resource {
600
1911
  delete(id) {
601
1912
  return this.http.request({ method: "DELETE", path: `/api-keys/${enc(id)}` });
602
1913
  }
1914
+ /**
1915
+ * One key's last 24 hours: how many requests it made, how many were
1916
+ * answered 4xx, 5xx or 429, and when it was last used. Check it before you
1917
+ * revoke a key (is anything still calling with it?) or when an
1918
+ * integration's calls fail. Needs `apikeys:read`, which no key preset
1919
+ * includes.
1920
+ */
1921
+ usage(id) {
1922
+ return this.http.request({ method: "GET", path: `/api-keys/${enc(id)}/usage` });
1923
+ }
1924
+ };
1925
+ var Logs = class extends Resource {
1926
+ /**
1927
+ * Your workspace's API request log, newest first (cursor-paginated, `rlog_`
1928
+ * ids): each call's `method`, `path`, `status`, time taken (`duration_ms`),
1929
+ * the API key that made it (`api_key_id`) and its `x-request-id`
1930
+ * (`request_id`: quote it to support). Never the caller's IP and never a
1931
+ * body. Narrow it with `status` (a code, or a class such as `4xx`),
1932
+ * `api_key_id`, `method`, `path_prefix` (e.g. `/email`), `request_id` and a
1933
+ * `created_after` / `created_before` range; an unknown filter is a `422`.
1934
+ * Rows are kept 30 days. Needs `apikeys:read`, which no key preset
1935
+ * includes, and has its own per-workspace rate limit.
1936
+ */
1937
+ list(params = {}) {
1938
+ return this.http.request({ method: "GET", path: "/logs", query: params });
1939
+ }
603
1940
  };
604
1941
  var Suppressions = class extends Resource {
605
- /** List suppressed addresses (your own + read-only platform rows). */
1942
+ /**
1943
+ * List your workspace's suppressed addresses. Unitpost-wide (platform)
1944
+ * blocks are enforced at send time but not listed — `get(email)` explains one.
1945
+ * Narrow it with `q` (part of the address), `reason` and a `created_after`
1946
+ * / `created_before` range.
1947
+ */
606
1948
  list(params = {}) {
607
1949
  return this.http.request({ method: "GET", path: "/suppressions", query: params });
608
1950
  }
609
- /** Async-iterate every suppressed address. */
1951
+ /** Async-iterate every suppressed address (same filters as `list`). */
610
1952
  listAll(params = {}) {
611
1953
  return paginate(this.http, "/suppressions", params);
612
1954
  }
@@ -627,6 +1969,226 @@ var Suppressions = class extends Resource {
627
1969
  return this.http.request({ method: "DELETE", path: `/suppressions/${enc(idOrEmail)}` });
628
1970
  }
629
1971
  };
1972
+ var INLINE_UPLOAD_MAX_BYTES = 3 * 1024 * 1024;
1973
+ var Files = class extends Resource {
1974
+ /** The workspace's unexpired files, newest first (cursor-paginated; `purpose` filters). */
1975
+ list(params = {}) {
1976
+ return this.http.request({ method: "GET", path: "/files", query: params });
1977
+ }
1978
+ /**
1979
+ * Create a file (201) one of three ways: a public https `url` (fetched
1980
+ * once, no redirects, no private addresses), base64 `data` with its
1981
+ * `content_type` (up to about 4 MB), or neither, with `content_type` and
1982
+ * `size_bytes`: an upload session, whose `upload` says where to PUT the
1983
+ * bytes (`files.upload` does all of this for a local file). The bytes
1984
+ * decide the type. Pass an `idempotencyKey` so a retry makes one file; one
1985
+ * is generated when you don't.
1986
+ */
1987
+ create(body, opts = {}) {
1988
+ return this.http.request({
1989
+ method: "POST",
1990
+ path: "/files",
1991
+ body,
1992
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
1993
+ });
1994
+ }
1995
+ /**
1996
+ * One file's metadata (never its bytes). Reading an `awaiting_upload` file
1997
+ * checks its upload, which makes it `ready` or `failed`.
1998
+ */
1999
+ get(id) {
2000
+ return this.http.request({ method: "GET", path: `/files/${enc(id)}` });
2001
+ }
2002
+ /** Delete a file before it expires. What already used it keeps its copy. */
2003
+ delete(id) {
2004
+ return this.http.request({ method: "DELETE", path: `/files/${enc(id)}` });
2005
+ }
2006
+ /**
2007
+ * Upload a local file or bytes and return the file, checked. Up to 3 MB it
2008
+ * is sent inline (base64 `data`); a larger one opens an upload session,
2009
+ * PUTs the bytes to its `upload.url` with exactly `upload.headers`, then
2010
+ * reads the file back, so the answer is `ready` or `failed`. The
2011
+ * `idempotencyKey` (generated when you don't pass one) is the create's.
2012
+ */
2013
+ async upload(input, opts = {}) {
2014
+ let bytes = input.data;
2015
+ if (!bytes) {
2016
+ if (!input.path) throw new TypeError("files.upload needs a `path` or `data`.");
2017
+ const { readFile } = await import('fs/promises');
2018
+ bytes = await readFile(input.path);
2019
+ }
2020
+ const filename = input.filename ?? (input.path ? input.path.split(/[\\/]/).pop() : void 0);
2021
+ const base = {
2022
+ purpose: input.purpose,
2023
+ content_type: input.contentType,
2024
+ ...filename ? { filename } : {}
2025
+ };
2026
+ if (bytes.byteLength <= INLINE_UPLOAD_MAX_BYTES) {
2027
+ const data = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("base64");
2028
+ return this.create({ ...base, data }, opts);
2029
+ }
2030
+ const created = await this.create({ ...base, size_bytes: bytes.byteLength }, opts);
2031
+ if (created.error || !created.data) return created;
2032
+ const session = created.data.upload;
2033
+ if (!session) {
2034
+ return {
2035
+ data: null,
2036
+ error: new UnitpostError({
2037
+ code: "upload_session_unavailable",
2038
+ message: "This idempotency key already made a file whose upload URL isn't returned again. Upload with a new key.",
2039
+ status: 409,
2040
+ requestId: null
2041
+ })
2042
+ };
2043
+ }
2044
+ const error = await this.http.putBytes(session.url, session.headers, bytes);
2045
+ if (error) return { data: null, error };
2046
+ const read = await this.get(created.data.id);
2047
+ if (read.error || !read.data || read.data.status === "ready") return read;
2048
+ return {
2049
+ data: null,
2050
+ error: new UnitpostError({
2051
+ code: "upload_failed",
2052
+ message: read.data.failure_reason ?? `The file is ${read.data.status}, not ready.`,
2053
+ status: 422,
2054
+ requestId: null
2055
+ })
2056
+ };
2057
+ }
2058
+ };
2059
+ var LibraryImages = class extends Resource {
2060
+ /** The library, newest first (cursor-paginated). */
2061
+ list(params = {}) {
2062
+ return this.http.request({ method: "GET", path: "/library-images", query: params });
2063
+ }
2064
+ /** Async-iterate every image in the library. */
2065
+ listAll(params = {}) {
2066
+ return paginate(this.http, "/library-images", params);
2067
+ }
2068
+ /**
2069
+ * Add an image (201) from a public https `url` (fetched once, no redirects,
2070
+ * no private addresses) or base64 `data` with its `content_type`: PNG,
2071
+ * JPEG, GIF or WebP up to 5 MB, counted against the plan's image storage
2072
+ * (`403 limit_reached`). Pass an `idempotencyKey` so a retried upload stores
2073
+ * one image; one is generated when you don't.
2074
+ */
2075
+ create(body, opts = {}) {
2076
+ return this.http.request({
2077
+ method: "POST",
2078
+ path: "/library-images",
2079
+ body,
2080
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
2081
+ });
2082
+ }
2083
+ get(id) {
2084
+ return this.http.request({ method: "GET", path: `/library-images/${enc(id)}` });
2085
+ }
2086
+ /** Change the alt text the image suggests when it's inserted (`null` or `""` clears it). */
2087
+ update(id, body) {
2088
+ return this.http.request({ method: "PATCH", path: `/library-images/${enc(id)}`, body });
2089
+ }
2090
+ /**
2091
+ * Remove an image from the library. While a template, a campaign or sent
2092
+ * mail uses it, the answer is a `409` `resource_in_use` naming them
2093
+ * (`details`). `{ force: true }` (sent as `?force=true`) deletes it anyway:
2094
+ * those emails then show a broken image wherever it isn't cached yet.
2095
+ */
2096
+ delete(id, params = {}) {
2097
+ return this.http.request({
2098
+ method: "DELETE",
2099
+ path: `/library-images/${enc(id)}`,
2100
+ query: params.force ? { force: "true" } : void 0
2101
+ });
2102
+ }
2103
+ };
2104
+ var Branding = class extends Resource {
2105
+ /** Colors, font, company name and postal address, the unsubscribe page, the footer, the logo; `null` means the default. */
2106
+ get() {
2107
+ return this.http.request({ method: "GET", path: "/branding" });
2108
+ }
2109
+ /**
2110
+ * Change branding: only the fields you send change, and `null` restores a
2111
+ * default. Hiding the "Sent with Unitpost" mark needs a paid plan
2112
+ * (`403 limit_reached`).
2113
+ */
2114
+ update(body) {
2115
+ return this.http.request({ method: "PATCH", path: "/branding", body });
2116
+ }
2117
+ /** Replace the logo, from a public https `url` or base64 `data` (PNG, JPEG, GIF or WebP, up to 5 MB). */
2118
+ setLogo(body) {
2119
+ return this.http.request({ method: "PUT", path: "/branding/logo", body });
2120
+ }
2121
+ /** Clear the brand logo (the workspace image shows instead, else none). It sends no body and answers the branding. */
2122
+ removeLogo() {
2123
+ return this.http.request({ method: "DELETE", path: "/branding/logo" });
2124
+ }
2125
+ };
2126
+ var Workspace = class extends Resource {
2127
+ /**
2128
+ * Who is calling: the workspace, the credential (an API key or an OAuth
2129
+ * sign-in, never its secret), its `capabilities` and the workspace's rate
2130
+ * limit. Call it first to see what the credential may do: a call that needs
2131
+ * a capability it lacks answers `403 insufficient_scope`. It needs no
2132
+ * capability: any valid credential may read it.
2133
+ */
2134
+ whoami() {
2135
+ return this.http.request({ method: "GET", path: "/whoami" });
2136
+ }
2137
+ /**
2138
+ * The workspace activity log, newest first (cursor-paginated, `act_` ids):
2139
+ * what changed, when, who changed it (`actor.name`: a teammate, `System`,
2140
+ * `Ask Unit`) and, for a change made over the API, MCP or Ask Unit, how
2141
+ * (`actor.via`, with the API key). The rows the dashboard's Activity page
2142
+ * and each record's timeline show. Narrow it with `subject` (and
2143
+ * `subject_id`), `contact_id`, `campaign_id`, `q` and `channel: "email"`;
2144
+ * an unknown filter is a `422`. Needs `activity:read`, which no key preset
2145
+ * includes: the log names your teammates.
2146
+ */
2147
+ listActivity(params = {}) {
2148
+ return this.http.request({ method: "GET", path: "/activity", query: params });
2149
+ }
2150
+ /** Async-iterate every activity row (same filters as `listActivity`). */
2151
+ listAllActivity(params = {}) {
2152
+ return paginate(this.http, "/activity", params);
2153
+ }
2154
+ /** Rename the workspace. */
2155
+ update(body) {
2156
+ return this.http.request({ method: "PATCH", path: "/workspace", body });
2157
+ }
2158
+ /**
2159
+ * Replace the workspace image (its avatar in the dashboard, and the email
2160
+ * logo when there's no brand logo), from a public https `url` or base64
2161
+ * `data` (PNG, JPEG, GIF or WebP, up to 5 MB).
2162
+ */
2163
+ setImage(body) {
2164
+ return this.http.request({ method: "PUT", path: "/workspace/image", body });
2165
+ }
2166
+ /** Clear the workspace image. It sends no body and answers the workspace. */
2167
+ removeImage() {
2168
+ return this.http.request({ method: "DELETE", path: "/workspace/image" });
2169
+ }
2170
+ };
2171
+ var SpendCaps = class extends Resource {
2172
+ /**
2173
+ * `{ object: "spend_caps", sms_purchases: { cap_cents, max_cents,
2174
+ * spent_cents, period_start, period_end } }`. A `cap_cents` of `null` means
2175
+ * none, so every API purchase is refused with `403 api_spend_cap_not_set`;
2176
+ * the cap that applies is the lower of `cap_cents` and `max_cents`.
2177
+ */
2178
+ get() {
2179
+ return this.http.request({ method: "GET", path: "/spend-caps" });
2180
+ }
2181
+ /**
2182
+ * Set caps: `{ sms_purchases: { cap_cents } }` in whole cents (>= 0), or
2183
+ * `null` to clear it. Only the caps you send change. A workspace its
2184
+ * organization pays for answers `403 billed_by_organization`: its
2185
+ * organization sets the cap with `sms_purchases_cap_cents` on the
2186
+ * organization's workspace update.
2187
+ */
2188
+ update(body) {
2189
+ return this.http.request({ method: "PATCH", path: "/spend-caps", body });
2190
+ }
2191
+ };
630
2192
  var Usage = class extends Resource {
631
2193
  /**
632
2194
  * Retrieve the current billing-period usage snapshot: plan, period window,
@@ -644,31 +2206,343 @@ function enc(segment) {
644
2206
  // src/client.ts
645
2207
  var Unitpost = class {
646
2208
  email;
2209
+ /**
2210
+ * SMS channel. Available on paid plans: on the free plan `send` returns a
2211
+ * 403 with code `limit_reached`; reads keep working.
2212
+ */
2213
+ sms;
647
2214
  contacts;
648
2215
  contactFields;
2216
+ jobs;
649
2217
  segments;
650
2218
  brandKits;
2219
+ /** The image library templates embed (`/img/…` paths). */
2220
+ libraryImages;
2221
+ /** Files handed to the API for one purpose, used by `file_id` (`upload()` sends a local file). */
2222
+ files;
2223
+ /** The email footer and unsubscribe page look. Writes need `branding:write` (on no key preset). */
2224
+ branding;
2225
+ /** Who is calling (`whoami`, any credential), the activity log (`listActivity`, needs `activity:read`, on no key preset), and the workspace's name and image; the writes need `branding:write` (on no key preset). */
2226
+ workspace;
651
2227
  webhooks;
652
2228
  apiKeys;
2229
+ /** The API request log (`list()`, needs `apikeys:read`, on no key preset). */
2230
+ logs;
653
2231
  suppressions;
654
2232
  // NOTE (pre-launch): `events` (POST /v1/events) is intentionally absent
655
2233
  // while the custom-events surface is behind the launch gate.
656
2234
  usage;
2235
+ /** Monthly spend caps (`get()`, `update()`); `update()` needs `spend_caps:write`, on no key preset. */
2236
+ spendCaps;
657
2237
  constructor(apiKeyOrOptions) {
658
2238
  const options = typeof apiKeyOrOptions === "string" ? { apiKey: apiKeyOrOptions } : apiKeyOrOptions ?? {};
659
2239
  const http = new HttpClient(options);
660
2240
  this.email = new Email(http);
2241
+ this.sms = new Sms(http);
661
2242
  this.contacts = new Contacts(http);
662
2243
  this.contactFields = new ContactFields(http);
2244
+ this.jobs = new Jobs(http);
663
2245
  this.segments = new Segments(http);
664
2246
  this.brandKits = new BrandKits(http);
2247
+ this.libraryImages = new LibraryImages(http);
2248
+ this.files = new Files(http);
2249
+ this.branding = new Branding(http);
2250
+ this.workspace = new Workspace(http);
665
2251
  this.webhooks = new Webhooks(http);
666
2252
  this.apiKeys = new ApiKeys(http);
2253
+ this.logs = new Logs(http);
667
2254
  this.suppressions = new Suppressions(http);
668
2255
  this.usage = new Usage(http);
2256
+ this.spendCaps = new SpendCaps(http);
669
2257
  }
670
2258
  };
2259
+ function env(name) {
2260
+ return typeof process !== "undefined" && process.env ? process.env[name] : void 0;
2261
+ }
2262
+ var UnitpostOrganization = class {
2263
+ /** The organization every call acts on (`org_…`). */
2264
+ organizationId;
2265
+ /** The organization's workspaces: list, create, get, update, close, restore. */
2266
+ workspaces;
2267
+ /** Keys for one of the organization's workspaces: `create` mints one (the secret is in that answer only). */
2268
+ workspaceKeys;
2269
+ /** The organization's webhook endpoints: events from every workspace it owns, each with `workspace_id` and `external_id`. */
2270
+ webhooks;
2271
+ /** Usage per workspace for a billing period (`list`). */
2272
+ usage;
2273
+ /** A plan change for one workspace the organization pays for: quote, read, confirm. */
2274
+ planQuotes;
2275
+ /** The organization's shared plan: read it, and add, cap or remove the workspaces on it. */
2276
+ sharedPlan;
2277
+ constructor(options = {}) {
2278
+ const apiKey = options.apiKey ?? env("UNITPOST_ORG_KEY");
2279
+ if (!apiKey) {
2280
+ throw new UnitpostError({
2281
+ code: "missing_api_key",
2282
+ message: "No organization key provided. Pass `new UnitpostOrganization({ apiKey })` or set the UNITPOST_ORG_KEY environment variable. An Owner or Admin makes one in the dashboard under Organization \u2192 API.",
2283
+ status: 0,
2284
+ requestId: null
2285
+ });
2286
+ }
2287
+ const organizationId = options.organizationId ?? env("UNITPOST_ORGANIZATION_ID");
2288
+ if (!organizationId) {
2289
+ throw new UnitpostError({
2290
+ code: "missing_organization_id",
2291
+ message: "No organization id provided. Pass `new UnitpostOrganization({ organizationId })` (`org_\u2026`) or set the UNITPOST_ORGANIZATION_ID environment variable.",
2292
+ status: 0,
2293
+ requestId: null
2294
+ });
2295
+ }
2296
+ const { organizationId: _id, ...transport } = options;
2297
+ const http = new HttpClient({ ...transport, apiKey });
2298
+ this.organizationId = organizationId;
2299
+ this.workspaces = new OrganizationWorkspaces(http, organizationId);
2300
+ this.workspaceKeys = new OrganizationWorkspaceKeys(http, organizationId);
2301
+ this.webhooks = new OrganizationWebhooks(http, organizationId);
2302
+ this.usage = new OrganizationUsage(http, organizationId);
2303
+ this.planQuotes = new OrganizationPlanQuotes(http, organizationId);
2304
+ this.sharedPlan = new OrganizationSharedPlan(http, organizationId);
2305
+ }
2306
+ };
2307
+ var OrganizationResource = class {
2308
+ constructor(http, organizationId) {
2309
+ this.http = http;
2310
+ this.organizationId = organizationId;
2311
+ }
2312
+ http;
2313
+ organizationId;
2314
+ };
2315
+ var OrganizationWorkspaces = class extends OrganizationResource {
2316
+ /** The organization's workspaces, newest first (cursor-paginated). Needs `organizations:read`. */
2317
+ list(params = {}) {
2318
+ return this.http.request({ method: "GET", path: `/organizations/${enc2(this.organizationId)}/workspaces`, query: params });
2319
+ }
2320
+ /** Async-iterate every workspace of the organization (same filters as `list`). */
2321
+ listAll(params = {}) {
2322
+ return paginate(this.http, `/organizations/${enc2(this.organizationId)}/workspaces`, params);
2323
+ }
2324
+ /**
2325
+ * Create a workspace (201). Its Owner is the key's creator. An
2326
+ * Idempotency-Key is generated when you don't pass one, so a retry can't
2327
+ * make two. Needs `organizations:write`.
2328
+ */
2329
+ create(body, opts = {}) {
2330
+ return this.http.request({
2331
+ method: "POST",
2332
+ path: `/organizations/${enc2(this.organizationId)}/workspaces`,
2333
+ body,
2334
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
2335
+ });
2336
+ }
2337
+ /** One workspace (`ws_…`). Needs `organizations:read`. */
2338
+ get(workspaceId) {
2339
+ return this.http.request({ method: "GET", path: `/organizations/${enc2(this.organizationId)}/workspaces/${enc2(workspaceId)}` });
2340
+ }
2341
+ /** Rename it, set its `external_id` or its SMS purchases cap. Needs `organizations:write`. */
2342
+ update(workspaceId, body) {
2343
+ return this.http.request({ method: "PATCH", path: `/organizations/${enc2(this.organizationId)}/workspaces/${enc2(workspaceId)}`, body });
2344
+ }
2345
+ /**
2346
+ * Close it: it stops sending at once. It can be restored for 30 days
2347
+ * (`restorable_until`); unless restored, it is deleted once those 30 days
2348
+ * are over and 7 days have passed since the end of the billing period it
2349
+ * closed in, whichever is later (`deletes_at`). Closing twice changes
2350
+ * nothing. Needs `organizations:write`.
2351
+ */
2352
+ close(workspaceId) {
2353
+ return this.http.request({ method: "POST", path: `/organizations/${enc2(this.organizationId)}/workspaces/${enc2(workspaceId)}/close` });
2354
+ }
2355
+ /** Restore a closed workspace within its 30 days. Needs `organizations:write`. */
2356
+ restore(workspaceId) {
2357
+ return this.http.request({ method: "POST", path: `/organizations/${enc2(this.organizationId)}/workspaces/${enc2(workspaceId)}/restore` });
2358
+ }
2359
+ };
2360
+ var OrganizationWorkspaceKeys = class extends OrganizationResource {
2361
+ /**
2362
+ * Mint a workspace key (201) for one of the organization's workspaces. The
2363
+ * answer holds the secret (`key`) once; use it with `new Unitpost(key)`.
2364
+ * Needs `organizations:write`.
2365
+ */
2366
+ create(workspaceId, body) {
2367
+ return this.http.request({
2368
+ method: "POST",
2369
+ path: `/organizations/${enc2(this.organizationId)}/workspaces/${enc2(workspaceId)}/api-keys`,
2370
+ body
2371
+ });
2372
+ }
2373
+ };
2374
+ var OrganizationWebhooks = class extends OrganizationResource {
2375
+ /** The organization's webhook endpoints. Needs `organizations:read`. */
2376
+ list(params = {}) {
2377
+ return this.http.request({ method: "GET", path: `/organizations/${enc2(this.organizationId)}/webhooks`, query: params });
2378
+ }
2379
+ /** Async-iterate every webhook endpoint of the organization. Needs `organizations:read`. */
2380
+ listAll(params = {}) {
2381
+ return paginate(this.http, `/organizations/${enc2(this.organizationId)}/webhooks`, params);
2382
+ }
2383
+ /** Create an endpoint. The answer has `signing_secret` exactly once. Needs `organizations:write`. */
2384
+ create(body) {
2385
+ return this.http.request({ method: "POST", path: `/organizations/${enc2(this.organizationId)}/webhooks`, body });
2386
+ }
2387
+ /** One endpoint (`wh_…`). Needs `organizations:read`. */
2388
+ get(webhookId) {
2389
+ return this.http.request({ method: "GET", path: `/organizations/${enc2(this.organizationId)}/webhooks/${enc2(webhookId)}` });
2390
+ }
2391
+ update(webhookId, body) {
2392
+ return this.http.request({ method: "PATCH", path: `/organizations/${enc2(this.organizationId)}/webhooks/${enc2(webhookId)}`, body });
2393
+ }
2394
+ delete(webhookId) {
2395
+ return this.http.request({ method: "DELETE", path: `/organizations/${enc2(this.organizationId)}/webhooks/${enc2(webhookId)}` });
2396
+ }
2397
+ /** Mint a new signing secret; the answer carries it exactly once. */
2398
+ rotateSecret(webhookId) {
2399
+ return this.http.request({ method: "POST", path: `/organizations/${enc2(this.organizationId)}/webhooks/${enc2(webhookId)}/rotate-secret` });
2400
+ }
2401
+ /** Fire a sample event at the endpoint. */
2402
+ test(webhookId) {
2403
+ return this.http.request({ method: "POST", path: `/organizations/${enc2(this.organizationId)}/webhooks/${enc2(webhookId)}/test` });
2404
+ }
2405
+ /**
2406
+ * The endpoint's delivery log, newest first; each row names its
2407
+ * `workspace_id` and `external_id`. Needs `organizations:write` (the rows
2408
+ * carry each event's data, so `organizations:read` alone is a 403).
2409
+ */
2410
+ listDeliveries(webhookId, params = {}) {
2411
+ return this.http.request({
2412
+ method: "GET",
2413
+ path: `/organizations/${enc2(this.organizationId)}/webhooks/${enc2(webhookId)}/deliveries`,
2414
+ query: params
2415
+ });
2416
+ }
2417
+ /** Async-iterate the endpoint's whole delivery log (same filters as `listDeliveries`). Needs `organizations:write`. */
2418
+ listAllDeliveries(webhookId, params = {}) {
2419
+ return paginate(this.http, `/organizations/${enc2(this.organizationId)}/webhooks/${enc2(webhookId)}/deliveries`, params);
2420
+ }
2421
+ /** Deliver one event to the endpoint again (202). */
2422
+ replayDelivery(webhookId, deliveryId) {
2423
+ return this.http.request({
2424
+ method: "POST",
2425
+ path: `/organizations/${enc2(this.organizationId)}/webhooks/${enc2(webhookId)}/deliveries/${enc2(deliveryId)}/replay`
2426
+ });
2427
+ }
2428
+ /** Deliver the backlog (202); `include_failed: true` adds the ones that failed for good. */
2429
+ flush(webhookId, body = {}) {
2430
+ return this.http.request({ method: "POST", path: `/organizations/${enc2(this.organizationId)}/webhooks/${enc2(webhookId)}/flush`, body });
2431
+ }
2432
+ /** Verify a delivery's signature and return the parsed event (the top-level `verifyWebhook`). */
2433
+ verify(args) {
2434
+ return verifyWebhook(args);
2435
+ }
2436
+ };
2437
+ var OrganizationUsage = class extends OrganizationResource {
2438
+ /**
2439
+ * Usage per workspace (`workspace_usage` rows), each for that workspace's
2440
+ * own billing period containing `period`. Paged by workspace. Needs
2441
+ * `organizations:read`.
2442
+ */
2443
+ list(params = {}) {
2444
+ return this.http.request({ method: "GET", path: `/organizations/${enc2(this.organizationId)}/usage`, query: params });
2445
+ }
2446
+ /**
2447
+ * Async-iterate the usage row of every workspace (same filters as `list`),
2448
+ * paging by the last row's `workspace_id`. Needs `organizations:read`.
2449
+ */
2450
+ listAll(params = {}) {
2451
+ return paginate(this.http, `/organizations/${enc2(this.organizationId)}/usage`, params, "workspace_id");
2452
+ }
2453
+ };
2454
+ var OrganizationPlanQuotes = class extends OrganizationResource {
2455
+ /**
2456
+ * Price a plan change for one workspace the organization pays for (201).
2457
+ * Charges nothing; the quote lasts 10 minutes and holds a single-use
2458
+ * `confirm_token` (only in this answer). Its `pending_change` is a
2459
+ * downgrade already scheduled for the period end, or null; with one, a
2460
+ * quote for the current plan and tier is a `noop` whose confirm cancels
2461
+ * it. Needs `organizations:billing`.
2462
+ */
2463
+ create(workspaceId, body) {
2464
+ return this.http.request({
2465
+ method: "POST",
2466
+ path: `/organizations/${enc2(this.organizationId)}/workspaces/${enc2(workspaceId)}/plan-quotes`,
2467
+ body
2468
+ });
2469
+ }
2470
+ /** One quote (`pq_…`). Needs `organizations:read`. */
2471
+ get(workspaceId, quoteId) {
2472
+ return this.http.request({
2473
+ method: "GET",
2474
+ path: `/organizations/${enc2(this.organizationId)}/workspaces/${enc2(workspaceId)}/plan-quotes/${enc2(quoteId)}`
2475
+ });
2476
+ }
2477
+ /**
2478
+ * Apply the quoted change and charge it. An Idempotency-Key is generated
2479
+ * when you don't pass one, so a retry can't charge twice. Needs
2480
+ * `organizations:billing`.
2481
+ */
2482
+ confirm(workspaceId, quoteId, body, opts = {}) {
2483
+ return this.http.request({
2484
+ method: "POST",
2485
+ path: `/organizations/${enc2(this.organizationId)}/workspaces/${enc2(workspaceId)}/plan-quotes/${enc2(quoteId)}/confirm`,
2486
+ body,
2487
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
2488
+ });
2489
+ }
2490
+ };
2491
+ var OrganizationSharedPlan = class extends OrganizationResource {
2492
+ /**
2493
+ * The organization's shared plan (one plan whose allowance its workspaces
2494
+ * share): whether it's turned on (`approved`), its `status` (`none` until
2495
+ * one is bought), plan, price and period, and this period's
2496
+ * `used_cents`, `overage_cents`, `paused`. Buying, upgrading and ending it
2497
+ * are done in the dashboard. Needs `organizations:read`.
2498
+ */
2499
+ get() {
2500
+ return this.http.request({ method: "GET", path: `/organizations/${enc2(this.organizationId)}/shared-plan` });
2501
+ }
2502
+ /** Every workspace on the shared plan, with its cap and what it drew this period (one page). Needs `organizations:read`. */
2503
+ listWorkspaces() {
2504
+ return this.http.request({ method: "GET", path: `/organizations/${enc2(this.organizationId)}/shared-plan/workspaces` });
2505
+ }
2506
+ /**
2507
+ * Put a workspace on the shared plan (it moves onto the organization's
2508
+ * card), or set its cap when it's already on it. Refusals carry the reason
2509
+ * in `error.details[0].code` (`own_plan`, `limit_reached`, …). An
2510
+ * Idempotency-Key is generated when you don't pass one, so a retry answers
2511
+ * what the first call did. Needs `organizations:billing`.
2512
+ */
2513
+ addWorkspace(workspaceId, body = {}, opts = {}) {
2514
+ return this.http.request({
2515
+ method: "PUT",
2516
+ path: `/organizations/${enc2(this.organizationId)}/shared-plan/workspaces/${enc2(workspaceId)}`,
2517
+ body,
2518
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
2519
+ });
2520
+ }
2521
+ /** Set a workspace's cap (`cap_cents`; null removes it). Needs `organizations:billing`. */
2522
+ updateWorkspace(workspaceId, body) {
2523
+ return this.http.request({
2524
+ method: "PATCH",
2525
+ path: `/organizations/${enc2(this.organizationId)}/shared-plan/workspaces/${enc2(workspaceId)}`,
2526
+ body
2527
+ });
2528
+ }
2529
+ /**
2530
+ * Take a workspace off the shared plan: `drops_to` is `free` or
2531
+ * `needs_plan`; one not on it answers `left: false`. An Idempotency-Key is
2532
+ * generated when you don't pass one. Needs `organizations:billing`.
2533
+ */
2534
+ removeWorkspace(workspaceId, opts = {}) {
2535
+ return this.http.request({
2536
+ method: "DELETE",
2537
+ path: `/organizations/${enc2(this.organizationId)}/shared-plan/workspaces/${enc2(workspaceId)}`,
2538
+ idempotencyKey: opts.idempotencyKey ?? randomUUID()
2539
+ });
2540
+ }
2541
+ };
2542
+ function enc2(segment) {
2543
+ return encodeURIComponent(segment);
2544
+ }
671
2545
 
672
- export { SDK_VERSION, Unitpost, UnitpostError, WebhookVerificationError, verifyWebhook };
2546
+ export { SDK_VERSION, Unitpost, UnitpostError, UnitpostOrganization, WebhookVerificationError, verifyWebhook };
673
2547
  //# sourceMappingURL=index.js.map
674
2548
  //# sourceMappingURL=index.js.map