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