unitpost 0.4.0 → 0.6.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 +332 -0
- package/README.md +71 -11
- package/dist/index.cjs +1638 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3683 -111
- package/dist/index.d.ts +3683 -111
- package/dist/index.js +1638 -31
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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.6.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) {
|
|
@@ -192,11 +229,11 @@ function safeJsonParse(text) {
|
|
|
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).";
|
|
195
|
-
function paginate(client, path, params = {}) {
|
|
232
|
+
function paginate(client, path, params = {}, cursor = "id") {
|
|
196
233
|
if (params.before) throw new TypeError(FORWARD_ONLY_MESSAGE);
|
|
197
|
-
return pages(client, path, params);
|
|
234
|
+
return pages(client, path, params, cursor);
|
|
198
235
|
}
|
|
199
|
-
async function* pages(client, path, params) {
|
|
236
|
+
async function* pages(client, path, params, cursor) {
|
|
200
237
|
let after = params.after;
|
|
201
238
|
for (; ; ) {
|
|
202
239
|
const { data, error } = await client.request({
|
|
@@ -209,7 +246,9 @@ async function* pages(client, path, params) {
|
|
|
209
246
|
const page = data;
|
|
210
247
|
for (const row of page.data) yield row;
|
|
211
248
|
if (!page.has_more || page.data.length === 0) return;
|
|
212
|
-
|
|
249
|
+
const next = page.data[page.data.length - 1][cursor];
|
|
250
|
+
if (typeof next !== "string" || next === "") return;
|
|
251
|
+
after = next;
|
|
213
252
|
}
|
|
214
253
|
}
|
|
215
254
|
var SECRET_PREFIX = "whsec_";
|
|
@@ -274,11 +313,34 @@ var Sms = class extends Resource {
|
|
|
274
313
|
campaigns;
|
|
275
314
|
/** SMS subscription topics (independent from email topics). */
|
|
276
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;
|
|
277
333
|
constructor(http) {
|
|
278
334
|
super(http);
|
|
279
335
|
this.templates = new SmsTemplates(http);
|
|
280
336
|
this.campaigns = new SmsCampaigns(http);
|
|
281
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);
|
|
282
344
|
}
|
|
283
345
|
/**
|
|
284
346
|
* Send or schedule an SMS message.
|
|
@@ -300,6 +362,20 @@ var Sms = class extends Resource {
|
|
|
300
362
|
get(id) {
|
|
301
363
|
return this.http.request({ method: "GET", path: `/sms/${enc(id)}` });
|
|
302
364
|
}
|
|
365
|
+
/**
|
|
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
|
+
}
|
|
303
379
|
/**
|
|
304
380
|
* Cancel a queued/scheduled SMS (`{ cancel: true }` — its reserved credit is
|
|
305
381
|
* refunded) or move a scheduled one (`{ scheduled_at }`).
|
|
@@ -327,8 +403,9 @@ var Sms = class extends Resource {
|
|
|
327
403
|
* `status` says whether you or the carrier is the blocker, and `missing`
|
|
328
404
|
* lists exactly what is still required.
|
|
329
405
|
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
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`.
|
|
332
409
|
*/
|
|
333
410
|
brands(params = {}) {
|
|
334
411
|
return this.http.request({
|
|
@@ -337,6 +414,88 @@ var Sms = class extends Resource {
|
|
|
337
414
|
query: params
|
|
338
415
|
});
|
|
339
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 = {}) {
|
|
428
|
+
return this.http.request({
|
|
429
|
+
method: "POST",
|
|
430
|
+
path: "/sms/brands",
|
|
431
|
+
body,
|
|
432
|
+
idempotencyKey: opts.idempotencyKey ?? crypto.randomUUID()
|
|
433
|
+
});
|
|
434
|
+
}
|
|
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)}` });
|
|
438
|
+
}
|
|
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 });
|
|
449
|
+
}
|
|
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` });
|
|
457
|
+
}
|
|
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
|
+
});
|
|
473
|
+
}
|
|
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
|
+
});
|
|
480
|
+
}
|
|
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
|
+
});
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
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`.
|
|
492
|
+
*/
|
|
493
|
+
brandDocumentUrl(brandId, documentId) {
|
|
494
|
+
return this.http.request({
|
|
495
|
+
method: "GET",
|
|
496
|
+
path: `/sms/brands/${enc(brandId)}/documents/${enc(documentId)}/url`
|
|
497
|
+
});
|
|
498
|
+
}
|
|
340
499
|
/**
|
|
341
500
|
* List SMS phone numbers.
|
|
342
501
|
*
|
|
@@ -344,8 +503,7 @@ var Sms = class extends Resource {
|
|
|
344
503
|
* `phone_number` until carriers approve it, and a `simulator` number only
|
|
345
504
|
* reaches verified test destinations.
|
|
346
505
|
*
|
|
347
|
-
*
|
|
348
|
-
* dashboard.
|
|
506
|
+
* Order a number through `sms.quotes`; release one with `releaseNumber`.
|
|
349
507
|
*/
|
|
350
508
|
numbers(params = {}) {
|
|
351
509
|
return this.http.request({
|
|
@@ -354,6 +512,88 @@ var Sms = class extends Resource {
|
|
|
354
512
|
query: params
|
|
355
513
|
});
|
|
356
514
|
}
|
|
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)}` });
|
|
523
|
+
}
|
|
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
|
+
});
|
|
542
|
+
}
|
|
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
|
+
});
|
|
558
|
+
}
|
|
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` });
|
|
567
|
+
}
|
|
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
|
+
});
|
|
586
|
+
}
|
|
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
|
+
});
|
|
596
|
+
}
|
|
357
597
|
/**
|
|
358
598
|
* SMS delivery stats over a rolling window: queued, sent, delivered,
|
|
359
599
|
* failed, suppressed, canceled, inbound and segments billed, with delivery,
|
|
@@ -379,6 +619,19 @@ var Sms = class extends Resource {
|
|
|
379
619
|
body
|
|
380
620
|
});
|
|
381
621
|
}
|
|
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
|
+
});
|
|
634
|
+
}
|
|
382
635
|
};
|
|
383
636
|
var SmsTemplates = class extends Resource {
|
|
384
637
|
list(params = {}) {
|
|
@@ -399,6 +652,32 @@ var SmsTemplates = class extends Resource {
|
|
|
399
652
|
delete(id) {
|
|
400
653
|
return this.http.request({ method: "DELETE", path: `/sms/templates/${enc(id)}` });
|
|
401
654
|
}
|
|
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
|
+
});
|
|
680
|
+
}
|
|
402
681
|
};
|
|
403
682
|
var SmsCampaigns = class extends Resource {
|
|
404
683
|
list(params = {}) {
|
|
@@ -443,6 +722,22 @@ var SmsCampaigns = class extends Resource {
|
|
|
443
722
|
resume(id) {
|
|
444
723
|
return this.http.request({ method: "POST", path: `/sms/campaigns/${enc(id)}/resume` });
|
|
445
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
|
+
}
|
|
446
741
|
reschedule(id, body) {
|
|
447
742
|
return this.http.request({ method: "POST", path: `/sms/campaigns/${enc(id)}/reschedule`, body });
|
|
448
743
|
}
|
|
@@ -455,6 +750,16 @@ var SmsCampaigns = class extends Resource {
|
|
|
455
750
|
validate(id) {
|
|
456
751
|
return this.http.request({ method: "GET", path: `/sms/campaigns/${enc(id)}/validate` });
|
|
457
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 });
|
|
762
|
+
}
|
|
458
763
|
};
|
|
459
764
|
var SmsTopics = class extends Resource {
|
|
460
765
|
list(params = {}) {
|
|
@@ -475,18 +780,242 @@ var SmsTopics = class extends Resource {
|
|
|
475
780
|
delete(id) {
|
|
476
781
|
return this.http.request({ method: "DELETE", path: `/sms/topics/${enc(id)}` });
|
|
477
782
|
}
|
|
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
|
+
}
|
|
478
1004
|
};
|
|
479
1005
|
var Email = class extends Resource {
|
|
480
1006
|
topics;
|
|
481
1007
|
campaigns;
|
|
482
1008
|
templates;
|
|
483
1009
|
domains;
|
|
1010
|
+
/** Inbox conversations: list, read, delete and reply. */
|
|
1011
|
+
threads;
|
|
484
1012
|
constructor(http) {
|
|
485
1013
|
super(http);
|
|
486
1014
|
this.topics = new Topics(http);
|
|
487
1015
|
this.campaigns = new Campaigns(http);
|
|
488
1016
|
this.templates = new Templates(http);
|
|
489
1017
|
this.domains = new Domains(http);
|
|
1018
|
+
this.threads = new EmailThreads(http);
|
|
490
1019
|
}
|
|
491
1020
|
/**
|
|
492
1021
|
* Send or schedule a transactional email.
|
|
@@ -527,26 +1056,70 @@ var Email = class extends Resource {
|
|
|
527
1056
|
cancelBatch(id) {
|
|
528
1057
|
return this.http.request({ method: "POST", path: `/email/batches/${enc(id)}/cancel` });
|
|
529
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
|
+
}
|
|
530
1068
|
/** List sent/scheduled emails (cursor-paginated). */
|
|
531
1069
|
list(params = {}) {
|
|
532
1070
|
return this.http.request({ method: "GET", path: "/email", query: params });
|
|
533
1071
|
}
|
|
534
|
-
/** Async-iterate every sent/scheduled email. */
|
|
1072
|
+
/** Async-iterate every sent/scheduled email (same filters as `list`). */
|
|
535
1073
|
listAll(params = {}) {
|
|
536
1074
|
return paginate(this.http, "/email", params);
|
|
537
1075
|
}
|
|
538
|
-
/** Retrieve a sent or scheduled email
|
|
1076
|
+
/** Retrieve a sent or scheduled email, with its `cc`, `bcc`, `reply_to` and `tags`. */
|
|
539
1077
|
get(id) {
|
|
540
1078
|
return this.http.request({ method: "GET", path: `/email/${enc(id)}` });
|
|
541
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
|
+
}
|
|
542
1090
|
/** Cancel or reschedule a scheduled/queued email. */
|
|
543
1091
|
update(id, body) {
|
|
544
1092
|
return this.http.request({ method: "PATCH", path: `/email/${enc(id)}`, body });
|
|
545
1093
|
}
|
|
546
1094
|
/**
|
|
547
|
-
*
|
|
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`.
|
|
548
1101
|
*
|
|
549
|
-
*
|
|
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.
|
|
550
1123
|
*/
|
|
551
1124
|
stats(params = {}) {
|
|
552
1125
|
return this.http.request({ method: "GET", path: "/email/stats", query: params });
|
|
@@ -561,6 +1134,16 @@ var Email = class extends Resource {
|
|
|
561
1134
|
receivedAttachmentUrl(id, attachmentId) {
|
|
562
1135
|
return this.http.request({ method: "GET", path: `/email/received/${enc(id)}/attachments/${enc(attachmentId)}` });
|
|
563
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
|
+
}
|
|
564
1147
|
};
|
|
565
1148
|
var Contacts = class extends Resource {
|
|
566
1149
|
list(params = {}) {
|
|
@@ -595,15 +1178,65 @@ var Contacts = class extends Resource {
|
|
|
595
1178
|
cancelImport(id) {
|
|
596
1179
|
return this.http.request({ method: "POST", path: `/contacts/imports/${enc(id)}/cancel` });
|
|
597
1180
|
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
return this.http.request({ method: "GET", path: "/contact-fields", query: params });
|
|
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` });
|
|
602
1184
|
}
|
|
603
|
-
|
|
604
|
-
|
|
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` });
|
|
605
1188
|
}
|
|
606
|
-
|
|
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
|
+
* Set one custom field to the same value on many contacts, as the Contacts
|
|
1214
|
+
* page's Set field does, as a background job (202, the `Job`): `key`,
|
|
1215
|
+
* `value` (typed against the field; `null` clears it), optional
|
|
1216
|
+
* `only_empty`, and exactly one of `contact_ids` or `emails` (up to 1,000,
|
|
1217
|
+
* each a contact of this workspace) or `segment_id` (every member, however
|
|
1218
|
+
* many; also needs `segments:read`). Each contact whose value changes gets
|
|
1219
|
+
* `contact.updated`; consent is never touched. Follow it with
|
|
1220
|
+
* `jobs.get(id)`. Pass an `idempotencyKey` so a retry answers the same job;
|
|
1221
|
+
* one is generated when you don't.
|
|
1222
|
+
*/
|
|
1223
|
+
setField(body, opts = {}) {
|
|
1224
|
+
return this.http.request({
|
|
1225
|
+
method: "POST",
|
|
1226
|
+
path: "/contacts/set-field",
|
|
1227
|
+
body,
|
|
1228
|
+
idempotencyKey: opts.idempotencyKey ?? crypto.randomUUID()
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1231
|
+
};
|
|
1232
|
+
var ContactFields = class extends Resource {
|
|
1233
|
+
list(params = {}) {
|
|
1234
|
+
return this.http.request({ method: "GET", path: "/contact-fields", query: params });
|
|
1235
|
+
}
|
|
1236
|
+
listAll(params = {}) {
|
|
1237
|
+
return paginate(this.http, "/contact-fields", params);
|
|
1238
|
+
}
|
|
1239
|
+
create(body) {
|
|
607
1240
|
return this.http.request({ method: "POST", path: "/contact-fields", body });
|
|
608
1241
|
}
|
|
609
1242
|
get(id) {
|
|
@@ -631,6 +1264,15 @@ var ContactFields = class extends Resource {
|
|
|
631
1264
|
}
|
|
632
1265
|
};
|
|
633
1266
|
var Jobs = class extends Resource {
|
|
1267
|
+
/**
|
|
1268
|
+
* Your background jobs, newest first (cursor-paginated), as Settings → Bulk
|
|
1269
|
+
* operations lists them: the kinds an API operation starts that your key
|
|
1270
|
+
* may read. Filter with `status` or `kind` (`"contacts.export"`,
|
|
1271
|
+
* `"contact_field.delete"`, …).
|
|
1272
|
+
*/
|
|
1273
|
+
list(params = {}) {
|
|
1274
|
+
return this.http.request({ method: "GET", path: "/jobs", query: params });
|
|
1275
|
+
}
|
|
634
1276
|
/**
|
|
635
1277
|
* Retrieve a background job — the `202` answer of an operation too large for
|
|
636
1278
|
* one request. Poll until `status` is `COMPLETED`, `FAILED` or `CANCELED`.
|
|
@@ -638,6 +1280,29 @@ var Jobs = class extends Resource {
|
|
|
638
1280
|
get(id) {
|
|
639
1281
|
return this.http.request({ method: "GET", path: `/jobs/${enc(id)}` });
|
|
640
1282
|
}
|
|
1283
|
+
/**
|
|
1284
|
+
* Stop a queued or running job. A running job stops after the part in
|
|
1285
|
+
* flight; the work already done stays. A kind that can't stop half-way (a
|
|
1286
|
+
* custom-field rename) is a `409` saying why. It sends no body.
|
|
1287
|
+
*/
|
|
1288
|
+
cancel(id) {
|
|
1289
|
+
return this.http.request({ method: "POST", path: `/jobs/${enc(id)}/cancel` });
|
|
1290
|
+
}
|
|
1291
|
+
/**
|
|
1292
|
+
* Resume a `FAILED` job from where it stopped (202): nothing it already
|
|
1293
|
+
* processed runs again. Any other status is a `409`. It sends no body.
|
|
1294
|
+
*/
|
|
1295
|
+
retry(id) {
|
|
1296
|
+
return this.http.request({ method: "POST", path: `/jobs/${enc(id)}/retry` });
|
|
1297
|
+
}
|
|
1298
|
+
/**
|
|
1299
|
+
* A finished job's file (a contacts export's CSV) as a signed `url` that
|
|
1300
|
+
* expires in 5 minutes: fetch it right away, and call `download` again for a
|
|
1301
|
+
* fresh one. A job that isn't `COMPLETED`, or a kind with no file, is a `409`.
|
|
1302
|
+
*/
|
|
1303
|
+
download(id) {
|
|
1304
|
+
return this.http.request({ method: "GET", path: `/jobs/${enc(id)}/download` });
|
|
1305
|
+
}
|
|
641
1306
|
};
|
|
642
1307
|
var Segments = class extends Resource {
|
|
643
1308
|
list(params = {}) {
|
|
@@ -661,7 +1326,6 @@ var Segments = class extends Resource {
|
|
|
661
1326
|
listMembers(id, params = {}) {
|
|
662
1327
|
return this.http.request({ method: "GET", path: `/segments/${enc(id)}/contacts`, query: params });
|
|
663
1328
|
}
|
|
664
|
-
/** Add a contact (by id or email) to the segment. Idempotent. */
|
|
665
1329
|
addMember(id, body) {
|
|
666
1330
|
return this.http.request({ method: "POST", path: `/segments/${enc(id)}/contacts`, body });
|
|
667
1331
|
}
|
|
@@ -669,6 +1333,40 @@ var Segments = class extends Resource {
|
|
|
669
1333
|
removeMember(id, contact) {
|
|
670
1334
|
return this.http.request({ method: "DELETE", path: `/segments/${enc(id)}/contacts/${enc(contact)}` });
|
|
671
1335
|
}
|
|
1336
|
+
/**
|
|
1337
|
+
* Opt a member (by id or email) out of this segment's sends without
|
|
1338
|
+
* removing it (`{ subscribed: false }`), or back in, as the members table's
|
|
1339
|
+
* toggle does. It stays a member. A dynamic segment has no per-segment
|
|
1340
|
+
* opt-out (`422`).
|
|
1341
|
+
*/
|
|
1342
|
+
updateMember(id, contact, body) {
|
|
1343
|
+
return this.http.request({ method: "PATCH", path: `/segments/${enc(id)}/contacts/${enc(contact)}`, body });
|
|
1344
|
+
}
|
|
1345
|
+
/**
|
|
1346
|
+
* How many contacts a saved segment reaches: its members, the subscribed
|
|
1347
|
+
* set a campaign would mail (`0` means a campaign would send nothing), and a
|
|
1348
|
+
* sample (which also needs `contacts:read`).
|
|
1349
|
+
*/
|
|
1350
|
+
preview(id) {
|
|
1351
|
+
return this.http.request({ method: "GET", path: `/segments/${enc(id)}/preview` });
|
|
1352
|
+
}
|
|
1353
|
+
/**
|
|
1354
|
+
* Count an unsaved dynamic filter before you create the segment, as the
|
|
1355
|
+
* segment dialog's live count does: how many contacts match, how many of
|
|
1356
|
+
* them a campaign would mail, and a sample (which also needs
|
|
1357
|
+
* `contacts:read`). Nothing is saved.
|
|
1358
|
+
*/
|
|
1359
|
+
previewFilter(body) {
|
|
1360
|
+
return this.http.request({ method: "POST", path: "/segments/preview", body });
|
|
1361
|
+
}
|
|
1362
|
+
/**
|
|
1363
|
+
* The workspace's managed "All subscribed contacts" segment, the
|
|
1364
|
+
* dashboard's "Everyone subscribed" campaign target: made the first time you
|
|
1365
|
+
* ask (201), the same segment after that (200). It sends no body.
|
|
1366
|
+
*/
|
|
1367
|
+
allContacts() {
|
|
1368
|
+
return this.http.request({ method: "POST", path: "/segments/all-contacts" });
|
|
1369
|
+
}
|
|
672
1370
|
};
|
|
673
1371
|
var Topics = class extends Resource {
|
|
674
1372
|
list(params = {}) {
|
|
@@ -689,6 +1387,23 @@ var Topics = class extends Resource {
|
|
|
689
1387
|
delete(id) {
|
|
690
1388
|
return this.http.request({ method: "DELETE", path: `/email/topics/${enc(id)}` });
|
|
691
1389
|
}
|
|
1390
|
+
/**
|
|
1391
|
+
* Opt many contacts out of this topic as a background job (202, the `Job`):
|
|
1392
|
+
* `{ contact_ids }` or `{ emails }` (up to 1,000, each a contact of this
|
|
1393
|
+
* workspace) or `{ segment_id }` (every member, however many). Each is
|
|
1394
|
+
* opted out as `setTopic` would, with its webhook only when it was
|
|
1395
|
+
* subscribed. Follow it with `jobs.get(id)`. Pass an `idempotencyKey` so a
|
|
1396
|
+
* retry answers the same job; one is generated when you don't. There is no
|
|
1397
|
+
* bulk opt-in.
|
|
1398
|
+
*/
|
|
1399
|
+
optOut(id, body, opts = {}) {
|
|
1400
|
+
return this.http.request({
|
|
1401
|
+
method: "POST",
|
|
1402
|
+
path: `/email/topics/${enc(id)}/opt-out`,
|
|
1403
|
+
body,
|
|
1404
|
+
idempotencyKey: opts.idempotencyKey ?? crypto.randomUUID()
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
692
1407
|
/** List a contact's effective topic subscriptions. */
|
|
693
1408
|
listTopics(contactId, params = {}) {
|
|
694
1409
|
return this.http.request({ method: "GET", path: `/contacts/${enc(contactId)}/topics`, query: params });
|
|
@@ -697,6 +1412,17 @@ var Topics = class extends Resource {
|
|
|
697
1412
|
setTopic(contactId, body) {
|
|
698
1413
|
return this.http.request({ method: "POST", path: `/contacts/${enc(contactId)}/topics`, body });
|
|
699
1414
|
}
|
|
1415
|
+
/**
|
|
1416
|
+
* Change a contact's preferences for several topics in one call
|
|
1417
|
+
* (`{ topics: [{ topic_id, subscribed }] }`, up to 50, each topic once);
|
|
1418
|
+
* topics left out keep theirs. Every topic is checked before any is set (an
|
|
1419
|
+
* unknown one is a 404 and nothing changes). Answers the resolved
|
|
1420
|
+
* preferences in the order sent (`{ object: "list", has_more: false, data }`).
|
|
1421
|
+
* Idempotent.
|
|
1422
|
+
*/
|
|
1423
|
+
updateTopics(contactId, body) {
|
|
1424
|
+
return this.http.request({ method: "PATCH", path: `/contacts/${enc(contactId)}/topics`, body });
|
|
1425
|
+
}
|
|
700
1426
|
};
|
|
701
1427
|
var Campaigns = class extends Resource {
|
|
702
1428
|
list(params = {}) {
|
|
@@ -736,6 +1462,22 @@ var Campaigns = class extends Resource {
|
|
|
736
1462
|
resume(id) {
|
|
737
1463
|
return this.http.request({ method: "POST", path: `/email/campaigns/${enc(id)}/resume` });
|
|
738
1464
|
}
|
|
1465
|
+
/** Move a scheduled campaign back to draft so it can be edited; clears its send time. */
|
|
1466
|
+
unschedule(id) {
|
|
1467
|
+
return this.http.request({ method: "POST", path: `/email/campaigns/${enc(id)}/unschedule` });
|
|
1468
|
+
}
|
|
1469
|
+
/**
|
|
1470
|
+
* Copy a campaign into a new draft (201). Pass an `idempotencyKey` so a
|
|
1471
|
+
* retry returns the same copy; one is generated when you don't.
|
|
1472
|
+
*/
|
|
1473
|
+
duplicate(id, body = {}, opts = {}) {
|
|
1474
|
+
return this.http.request({
|
|
1475
|
+
method: "POST",
|
|
1476
|
+
path: `/email/campaigns/${enc(id)}/duplicate`,
|
|
1477
|
+
body,
|
|
1478
|
+
idempotencyKey: opts.idempotencyKey ?? crypto.randomUUID()
|
|
1479
|
+
});
|
|
1480
|
+
}
|
|
739
1481
|
reschedule(id, body) {
|
|
740
1482
|
return this.http.request({ method: "POST", path: `/email/campaigns/${enc(id)}/reschedule`, body });
|
|
741
1483
|
}
|
|
@@ -747,6 +1489,55 @@ var Campaigns = class extends Resource {
|
|
|
747
1489
|
validate(id) {
|
|
748
1490
|
return this.http.request({ method: "GET", path: `/email/campaigns/${enc(id)}/validate` });
|
|
749
1491
|
}
|
|
1492
|
+
/**
|
|
1493
|
+
* The campaign's results: delivered, unique opens and clicks, unsubscribes,
|
|
1494
|
+
* bounces, complaints and their rates. Every rate is `null` until something
|
|
1495
|
+
* was sent; open and click rates are `null` when that tracking was off.
|
|
1496
|
+
*/
|
|
1497
|
+
stats(id) {
|
|
1498
|
+
return this.http.request({ method: "GET", path: `/email/campaigns/${enc(id)}/stats` });
|
|
1499
|
+
}
|
|
1500
|
+
/**
|
|
1501
|
+
* `stats` for up to 100 campaigns in one read (1–100 ids). An id that isn't
|
|
1502
|
+
* one of this workspace's email campaigns is left out of `data`, never an
|
|
1503
|
+
* error; `has_more` is always false.
|
|
1504
|
+
*/
|
|
1505
|
+
listStats(ids) {
|
|
1506
|
+
return this.http.request({ method: "GET", path: "/email/campaigns/stats", query: { ids: ids.join(",") } });
|
|
1507
|
+
}
|
|
1508
|
+
/**
|
|
1509
|
+
* Who the campaign would reach if sent now, member by member: `sendable`,
|
|
1510
|
+
* `missing_data`, `suppressed` or `excluded`, with the reason. Pass the
|
|
1511
|
+
* page's `next_cursor` as `after` for the next page (rows carry no `id`).
|
|
1512
|
+
* A page can hold fewer rows than `limit` while `has_more` is true.
|
|
1513
|
+
*/
|
|
1514
|
+
listRecipients(id, params = {}) {
|
|
1515
|
+
return this.http.request({ method: "GET", path: `/email/campaigns/${enc(id)}/recipients`, query: params });
|
|
1516
|
+
}
|
|
1517
|
+
/**
|
|
1518
|
+
* After an automatic quality pause: the recipients whose message
|
|
1519
|
+
* hard-bounced or drew a spam complaint. They're already suppressed; this is
|
|
1520
|
+
* for cleaning the source list. Up to 10,000; `has_more` says it was cut there.
|
|
1521
|
+
*/
|
|
1522
|
+
listAffected(id) {
|
|
1523
|
+
return this.http.request({ method: "GET", path: `/email/campaigns/${enc(id)}/quality/affected` });
|
|
1524
|
+
}
|
|
1525
|
+
/**
|
|
1526
|
+
* After an automatic quality pause: take the flagged contacts out of the
|
|
1527
|
+
* campaign's static segment (needs `segments:write` too; a filter segment is
|
|
1528
|
+
* a `409`). A repeat removes nothing. It doesn't resume the campaign.
|
|
1529
|
+
*/
|
|
1530
|
+
removeAffected(id) {
|
|
1531
|
+
return this.http.request({ method: "POST", path: `/email/campaigns/${enc(id)}/quality/remove-affected` });
|
|
1532
|
+
}
|
|
1533
|
+
/**
|
|
1534
|
+
* Ask for the review a campaign needs before it can resume after a repeat
|
|
1535
|
+
* quality pause (`resume` answers `409 review_required` until then). A
|
|
1536
|
+
* repeat answers `already_requested: true` and notifies no one.
|
|
1537
|
+
*/
|
|
1538
|
+
requestReview(id) {
|
|
1539
|
+
return this.http.request({ method: "POST", path: `/email/campaigns/${enc(id)}/quality/request-review` });
|
|
1540
|
+
}
|
|
750
1541
|
};
|
|
751
1542
|
var Templates = class extends Resource {
|
|
752
1543
|
list(params = {}) {
|
|
@@ -769,12 +1560,127 @@ var Templates = class extends Resource {
|
|
|
769
1560
|
}
|
|
770
1561
|
/**
|
|
771
1562
|
* Send ONE test of the template to `to`, rendered with sample `variables`
|
|
772
|
-
* exactly as a recipient gets it.
|
|
773
|
-
*
|
|
1563
|
+
* exactly as a recipient gets it. Once a sending domain is verified it may
|
|
1564
|
+
* go to anyone; until then only to a member of your workspace.
|
|
774
1565
|
*/
|
|
775
1566
|
testSend(id, body) {
|
|
776
1567
|
return this.http.request({ method: "POST", path: `/email/templates/${enc(id)}/test-send`, body });
|
|
777
1568
|
}
|
|
1569
|
+
/**
|
|
1570
|
+
* The `subject`, `html` and `text` a send of this template would carry,
|
|
1571
|
+
* with your footer and branding, filled from `variables` (and from a
|
|
1572
|
+
* contact's fields with `contact_id`). It sends and stores nothing, so it
|
|
1573
|
+
* takes no idempotency key. `missing_variables` lists the variables left
|
|
1574
|
+
* without a value: they render as a literal `{{token}}`, and a real send
|
|
1575
|
+
* would refuse them. The body is optional: `{}` renders with no variables.
|
|
1576
|
+
* Needs `templates:read`, and has its own per-workspace rate limit.
|
|
1577
|
+
*/
|
|
1578
|
+
render(id, body = {}) {
|
|
1579
|
+
return this.http.request({ method: "POST", path: `/email/templates/${enc(id)}/render`, body });
|
|
1580
|
+
}
|
|
1581
|
+
/**
|
|
1582
|
+
* Copy a template into a new draft (201): its name (with " (copy)", or your
|
|
1583
|
+
* `name`), subject, editor and body carry over; its status, versions and
|
|
1584
|
+
* usage don't. Pass an `idempotencyKey` so a retry returns the same copy;
|
|
1585
|
+
* one is generated when you don't.
|
|
1586
|
+
*/
|
|
1587
|
+
duplicate(id, body = {}, opts = {}) {
|
|
1588
|
+
return this.http.request({
|
|
1589
|
+
method: "POST",
|
|
1590
|
+
path: `/email/templates/${enc(id)}/duplicate`,
|
|
1591
|
+
body,
|
|
1592
|
+
idempotencyKey: opts.idempotencyKey ?? crypto.randomUUID()
|
|
1593
|
+
});
|
|
1594
|
+
}
|
|
1595
|
+
/**
|
|
1596
|
+
* Add one of the gallery's ready-made emails (unitpost.com/templates) to
|
|
1597
|
+
* your workspace as a draft Design template (201). `slug` names it; the ones
|
|
1598
|
+
* marked for paid plans answer `403 limit_reached` on the free plan. Pass an
|
|
1599
|
+
* `idempotencyKey` so a retry returns the same template; one is generated
|
|
1600
|
+
* when you don't.
|
|
1601
|
+
*/
|
|
1602
|
+
fromLibrary(body, opts = {}) {
|
|
1603
|
+
return this.http.request({
|
|
1604
|
+
method: "POST",
|
|
1605
|
+
path: "/email/templates/from-library",
|
|
1606
|
+
body,
|
|
1607
|
+
idempotencyKey: opts.idempotencyKey ?? crypto.randomUUID()
|
|
1608
|
+
});
|
|
1609
|
+
}
|
|
1610
|
+
/**
|
|
1611
|
+
* What uses the template, and whether a change would be accepted now: the
|
|
1612
|
+
* campaigns that reference it, its live campaigns and automations, queued
|
|
1613
|
+
* sends, and `can_edit_content` / `can_unpublish` with the reason when not.
|
|
1614
|
+
* Read it before an edit or a delete: a content edit is refused while a
|
|
1615
|
+
* live campaign renders the template, and a delete while any campaign uses
|
|
1616
|
+
* it.
|
|
1617
|
+
*/
|
|
1618
|
+
usage(id) {
|
|
1619
|
+
return this.http.request({ method: "GET", path: `/email/templates/${enc(id)}/usage` });
|
|
1620
|
+
}
|
|
1621
|
+
/**
|
|
1622
|
+
* The template's history, newest first: a version is added on every publish
|
|
1623
|
+
* and on every content save while it's published. It pages by version
|
|
1624
|
+
* number: pass the last row's `version` (an integer, not an id) as `after`.
|
|
1625
|
+
* There is no `before`.
|
|
1626
|
+
*/
|
|
1627
|
+
listVersions(id, params = {}) {
|
|
1628
|
+
return this.http.request({ method: "GET", path: `/email/templates/${enc(id)}/versions`, query: params });
|
|
1629
|
+
}
|
|
1630
|
+
/**
|
|
1631
|
+
* Put a version's subject and body back, as the editor's History → Restore
|
|
1632
|
+
* does. It is an update, so a system template, or one a live campaign
|
|
1633
|
+
* renders, is refused with a `409` naming why (`usage` says so up front).
|
|
1634
|
+
* On a published template the restore adds a new version; history is never
|
|
1635
|
+
* rewritten. It sends no body.
|
|
1636
|
+
*/
|
|
1637
|
+
restoreVersion(id, version) {
|
|
1638
|
+
return this.http.request({
|
|
1639
|
+
method: "POST",
|
|
1640
|
+
path: `/email/templates/${enc(id)}/versions/${enc(String(version))}/restore`
|
|
1641
|
+
});
|
|
1642
|
+
}
|
|
1643
|
+
};
|
|
1644
|
+
var EmailThreads = class extends Resource {
|
|
1645
|
+
/**
|
|
1646
|
+
* Every conversation (Spam included), newest activity first. `q` searches
|
|
1647
|
+
* the subject, the sender and the opening words. Pass the page's
|
|
1648
|
+
* `next_cursor` as `after` for the next page (not the last row's `id`).
|
|
1649
|
+
*/
|
|
1650
|
+
list(params = {}) {
|
|
1651
|
+
return this.http.request({ method: "GET", path: "/email/threads", query: params });
|
|
1652
|
+
}
|
|
1653
|
+
/**
|
|
1654
|
+
* One conversation, oldest message first: what you received (with bodies)
|
|
1655
|
+
* and what you sent from it (status and recipients, no body).
|
|
1656
|
+
*/
|
|
1657
|
+
get(id) {
|
|
1658
|
+
return this.http.request({ method: "GET", path: `/email/threads/${enc(id)}` });
|
|
1659
|
+
}
|
|
1660
|
+
/**
|
|
1661
|
+
* Delete a conversation for good: its received messages are erased; replies
|
|
1662
|
+
* and forwards sent from it stay on your sent emails. It can't be undone.
|
|
1663
|
+
*/
|
|
1664
|
+
delete(id) {
|
|
1665
|
+
return this.http.request({ method: "DELETE", path: `/email/threads/${enc(id)}` });
|
|
1666
|
+
}
|
|
1667
|
+
/**
|
|
1668
|
+
* Reply, reply all or forward one received message of the conversation
|
|
1669
|
+
* (`received_email_id`): your `text`/`html` go on top and the original is
|
|
1670
|
+
* quoted under them. It sends now and marks the conversation read.
|
|
1671
|
+
*
|
|
1672
|
+
* It sends real email, so if you don't pass `idempotencyKey` the SDK
|
|
1673
|
+
* generates one, which makes an auto-retry safe. Pass your own to dedupe
|
|
1674
|
+
* across separate `reply()` calls.
|
|
1675
|
+
*/
|
|
1676
|
+
reply(id, body, opts = {}) {
|
|
1677
|
+
return this.http.request({
|
|
1678
|
+
method: "POST",
|
|
1679
|
+
path: `/email/threads/${enc(id)}/reply`,
|
|
1680
|
+
body,
|
|
1681
|
+
idempotencyKey: opts.idempotencyKey ?? crypto.randomUUID()
|
|
1682
|
+
});
|
|
1683
|
+
}
|
|
778
1684
|
};
|
|
779
1685
|
var BrandKits = class extends Resource {
|
|
780
1686
|
/** List profiles (max 5). Optional `name` filters by display name. */
|
|
@@ -785,6 +1691,81 @@ var BrandKits = class extends Resource {
|
|
|
785
1691
|
get(id) {
|
|
786
1692
|
return this.http.request({ method: "GET", path: `/brand-kits/${enc(id)}` });
|
|
787
1693
|
}
|
|
1694
|
+
/**
|
|
1695
|
+
* Create an empty profile (201); `name` is unique in the workspace. The
|
|
1696
|
+
* first profile, or one with `make_default`, becomes the default. At most
|
|
1697
|
+
* five profiles (`403 limit_reached`). Fill it with `update` or `import`.
|
|
1698
|
+
*/
|
|
1699
|
+
create(body) {
|
|
1700
|
+
return this.http.request({ method: "POST", path: "/brand-kits", body });
|
|
1701
|
+
}
|
|
1702
|
+
/**
|
|
1703
|
+
* Edit a profile: only the fields you send change, a list replaces the
|
|
1704
|
+
* list, and `null` or `""` clears a text field. `graphics` pins library
|
|
1705
|
+
* images by `image_id` (`img_…`). `sync_visual` on the default profile also
|
|
1706
|
+
* sets the email branding's accent from its colors.
|
|
1707
|
+
*/
|
|
1708
|
+
update(id, body) {
|
|
1709
|
+
return this.http.request({ method: "PATCH", path: `/brand-kits/${enc(id)}`, body });
|
|
1710
|
+
}
|
|
1711
|
+
/**
|
|
1712
|
+
* Delete a profile. When it was the default, the oldest remaining profile
|
|
1713
|
+
* becomes the default. The last profile can't be deleted (`409`): `reset`
|
|
1714
|
+
* it instead. Its pinned images stay in the library.
|
|
1715
|
+
*/
|
|
1716
|
+
delete(id) {
|
|
1717
|
+
return this.http.request({ method: "DELETE", path: `/brand-kits/${enc(id)}` });
|
|
1718
|
+
}
|
|
1719
|
+
/**
|
|
1720
|
+
* Clear a profile's content (voice, colors, graphics, pages), keeping its
|
|
1721
|
+
* name and whether it's the default. It sends no body.
|
|
1722
|
+
*/
|
|
1723
|
+
reset(id) {
|
|
1724
|
+
return this.http.request({ method: "POST", path: `/brand-kits/${enc(id)}/reset` });
|
|
1725
|
+
}
|
|
1726
|
+
/** Make a profile the default: the one agents write with unless told otherwise. It sends no body. */
|
|
1727
|
+
setDefault(id) {
|
|
1728
|
+
return this.http.request({ method: "POST", path: `/brand-kits/${enc(id)}/set-default` });
|
|
1729
|
+
}
|
|
1730
|
+
/**
|
|
1731
|
+
* Add a graphic (201) from a public https image `url` (fetched once, no
|
|
1732
|
+
* redirects): it goes into the image library, counted against its storage,
|
|
1733
|
+
* and is pinned with its `role` (default `logo`). To pin an image already in
|
|
1734
|
+
* the library, `update` the profile's `graphics`.
|
|
1735
|
+
*/
|
|
1736
|
+
addGraphic(id, body) {
|
|
1737
|
+
return this.http.request({ method: "POST", path: `/brand-kits/${enc(id)}/graphics`, body });
|
|
1738
|
+
}
|
|
1739
|
+
/**
|
|
1740
|
+
* Build a profile from a website (`url`, or a bare domain) or the brand's
|
|
1741
|
+
* own words (`text`). It runs in the background, usually under a minute
|
|
1742
|
+
* (202): follow it with `getImport`. By default the result is applied when
|
|
1743
|
+
* it lands, to `brand_kit_id`, else the default profile, or a new one when
|
|
1744
|
+
* the default already has content. With `review: true` it stops at a
|
|
1745
|
+
* proposal (`preview_ready`) for `acceptImport`; one review import is open
|
|
1746
|
+
* at a time, and a new one replaces it.
|
|
1747
|
+
*/
|
|
1748
|
+
import(body) {
|
|
1749
|
+
return this.http.request({ method: "POST", path: "/brand-kits/imports", body });
|
|
1750
|
+
}
|
|
1751
|
+
/** One import: its status, the proposal once it's ready, warnings and any error. */
|
|
1752
|
+
getImport(id) {
|
|
1753
|
+
return this.http.request({ method: "GET", path: `/brand-kits/imports/${enc(id)}` });
|
|
1754
|
+
}
|
|
1755
|
+
/**
|
|
1756
|
+
* Apply a review import's proposal (`preview_ready`) to a profile: voice,
|
|
1757
|
+
* colors and pages, and its logos and backgrounds brought into the image
|
|
1758
|
+
* library and pinned. The body is optional: `brand_kit_id` applies it to
|
|
1759
|
+
* another profile, `name` names it. To change other fields, accept and then
|
|
1760
|
+
* `update`.
|
|
1761
|
+
*/
|
|
1762
|
+
acceptImport(id, body = {}) {
|
|
1763
|
+
return this.http.request({ method: "POST", path: `/brand-kits/imports/${enc(id)}/accept`, body });
|
|
1764
|
+
}
|
|
1765
|
+
/** Discard a review import's proposal or stop its crawl. It sends no body. */
|
|
1766
|
+
cancelImport(id) {
|
|
1767
|
+
return this.http.request({ method: "POST", path: `/brand-kits/imports/${enc(id)}/cancel` });
|
|
1768
|
+
}
|
|
788
1769
|
};
|
|
789
1770
|
var Domains = class extends Resource {
|
|
790
1771
|
list(params = {}) {
|
|
@@ -813,6 +1794,42 @@ var Domains = class extends Resource {
|
|
|
813
1794
|
diagnose(id) {
|
|
814
1795
|
return this.http.request({ method: "GET", path: `/email/domains/${enc(id)}/diagnose` });
|
|
815
1796
|
}
|
|
1797
|
+
// --- Sender addresses (`/email/senders`, `sndr_…`): saved From addresses ---
|
|
1798
|
+
/**
|
|
1799
|
+
* Your saved From addresses, as the domain page lists them and the
|
|
1800
|
+
* dashboard's From pickers offer them: each a mailbox on one of your
|
|
1801
|
+
* domains, with its display name and `from`, the value to send with.
|
|
1802
|
+
* `domain_id` keeps one domain's. A sender can send once its domain can.
|
|
1803
|
+
*/
|
|
1804
|
+
listSenders(params = {}) {
|
|
1805
|
+
return this.http.request({ method: "GET", path: "/email/senders", query: params });
|
|
1806
|
+
}
|
|
1807
|
+
/**
|
|
1808
|
+
* Save a From address on one of your domains (201); the domain may still be
|
|
1809
|
+
* verifying. A mailbox already saved on that domain is a `409`, so a retry
|
|
1810
|
+
* never saves it twice.
|
|
1811
|
+
*/
|
|
1812
|
+
createSender(body) {
|
|
1813
|
+
return this.http.request({ method: "POST", path: "/email/senders", body });
|
|
1814
|
+
}
|
|
1815
|
+
/** One saved From address. */
|
|
1816
|
+
getSender(id) {
|
|
1817
|
+
return this.http.request({ method: "GET", path: `/email/senders/${enc(id)}` });
|
|
1818
|
+
}
|
|
1819
|
+
/**
|
|
1820
|
+
* Change a sender's display name (`null` or `""` clears it), the only field
|
|
1821
|
+
* that changes: a different mailbox is a new sender.
|
|
1822
|
+
*/
|
|
1823
|
+
updateSender(id, body) {
|
|
1824
|
+
return this.http.request({ method: "PATCH", path: `/email/senders/${enc(id)}`, body });
|
|
1825
|
+
}
|
|
1826
|
+
/**
|
|
1827
|
+
* Remove a saved From address from the pickers. Templates and campaigns that
|
|
1828
|
+
* send from it keep their From.
|
|
1829
|
+
*/
|
|
1830
|
+
deleteSender(id) {
|
|
1831
|
+
return this.http.request({ method: "DELETE", path: `/email/senders/${enc(id)}` });
|
|
1832
|
+
}
|
|
816
1833
|
};
|
|
817
1834
|
var Webhooks = class extends Resource {
|
|
818
1835
|
list(params = {}) {
|
|
@@ -825,6 +1842,10 @@ var Webhooks = class extends Resource {
|
|
|
825
1842
|
create(body) {
|
|
826
1843
|
return this.http.request({ method: "POST", path: "/webhooks", body });
|
|
827
1844
|
}
|
|
1845
|
+
/**
|
|
1846
|
+
* One endpoint, with its `backlog`: the deliveries `flush` would send
|
|
1847
|
+
* (`queued` while it was paused, and `failed`).
|
|
1848
|
+
*/
|
|
828
1849
|
get(id) {
|
|
829
1850
|
return this.http.request({ method: "GET", path: `/webhooks/${enc(id)}` });
|
|
830
1851
|
}
|
|
@@ -845,24 +1866,58 @@ var Webhooks = class extends Resource {
|
|
|
845
1866
|
rotateSecret(id) {
|
|
846
1867
|
return this.http.request({ method: "POST", path: `/webhooks/${enc(id)}/rotate-secret` });
|
|
847
1868
|
}
|
|
848
|
-
/**
|
|
1869
|
+
/**
|
|
1870
|
+
* The endpoint's delivery log, newest first (cursor-paginated). Narrow it
|
|
1871
|
+
* with `status` (comma-separated, e.g. `"failed,exhausted"`) and
|
|
1872
|
+
* `event_type` (e.g. `email.bounced`).
|
|
1873
|
+
*/
|
|
849
1874
|
listDeliveries(id, params = {}) {
|
|
850
1875
|
return this.http.request({ method: "GET", path: `/webhooks/${enc(id)}/deliveries`, query: params });
|
|
851
1876
|
}
|
|
852
|
-
/** Async-iterate every delivery of the endpoint. */
|
|
1877
|
+
/** Async-iterate every delivery of the endpoint (same filters as `listDeliveries`). */
|
|
853
1878
|
listAllDeliveries(id, params = {}) {
|
|
854
1879
|
return paginate(this.http, `/webhooks/${enc(id)}/deliveries`, params);
|
|
855
1880
|
}
|
|
1881
|
+
/**
|
|
1882
|
+
* Deliver one event to the endpoint again (202), as the dashboard's Replay
|
|
1883
|
+
* does. The same event goes out with the same id, so a receiver that
|
|
1884
|
+
* dedupes on it treats the replay as the delivery it already has. The
|
|
1885
|
+
* webhook must be enabled: a disabled or suspended one is a `409`
|
|
1886
|
+
* (re-enable it with `update` first). Find deliveries with
|
|
1887
|
+
* `listDeliveries`. It sends no body.
|
|
1888
|
+
*/
|
|
1889
|
+
replayDelivery(id, deliveryId) {
|
|
1890
|
+
return this.http.request({
|
|
1891
|
+
method: "POST",
|
|
1892
|
+
path: `/webhooks/${enc(id)}/deliveries/${enc(deliveryId)}/replay`
|
|
1893
|
+
});
|
|
1894
|
+
}
|
|
1895
|
+
/**
|
|
1896
|
+
* Deliver the backlog (202): the deliveries held while the webhook was
|
|
1897
|
+
* suspended (`queued`), as the dashboard's "Retry queued" does. With
|
|
1898
|
+
* `include_failed: true`, also the ones that failed for good (`failed`,
|
|
1899
|
+
* `exhausted`). The webhook must be enabled: a disabled or suspended one is
|
|
1900
|
+
* a `409` (re-enable it with `update` first); re-enabling never delivers the
|
|
1901
|
+
* backlog on its own. `flushed` counts the deliveries handed back.
|
|
1902
|
+
*/
|
|
1903
|
+
flush(id, body = {}) {
|
|
1904
|
+
return this.http.request({ method: "POST", path: `/webhooks/${enc(id)}/flush`, body });
|
|
1905
|
+
}
|
|
856
1906
|
/**
|
|
857
1907
|
* Verify a webhook delivery's signature and return the parsed event. Throws
|
|
858
1908
|
* `WebhookVerificationError` on a missing/invalid/stale signature. Alias of the
|
|
859
|
-
* top-level `verifyWebhook
|
|
1909
|
+
* top-level `verifyWebhook`, callable as `unitpost.webhooks.verify(...)`.
|
|
860
1910
|
*/
|
|
861
1911
|
verify(args) {
|
|
862
1912
|
return verifyWebhook(args);
|
|
863
1913
|
}
|
|
864
1914
|
};
|
|
865
1915
|
var ApiKeys = class extends Resource {
|
|
1916
|
+
/**
|
|
1917
|
+
* The workspace's API keys (prefix, scope, capabilities, last use; never
|
|
1918
|
+
* the secret). With an API key or an MCP sign-in it needs `apikeys:read`,
|
|
1919
|
+
* which no key preset includes.
|
|
1920
|
+
*/
|
|
866
1921
|
list(params = {}) {
|
|
867
1922
|
return this.http.request({ method: "GET", path: "/api-keys", query: params });
|
|
868
1923
|
}
|
|
@@ -876,16 +1931,44 @@ var ApiKeys = class extends Resource {
|
|
|
876
1931
|
delete(id) {
|
|
877
1932
|
return this.http.request({ method: "DELETE", path: `/api-keys/${enc(id)}` });
|
|
878
1933
|
}
|
|
1934
|
+
/**
|
|
1935
|
+
* One key's last 24 hours: how many requests it made, how many were
|
|
1936
|
+
* answered 4xx, 5xx or 429, and when it was last used. Check it before you
|
|
1937
|
+
* revoke a key (is anything still calling with it?) or when an
|
|
1938
|
+
* integration's calls fail. Needs `apikeys:read`, which no key preset
|
|
1939
|
+
* includes.
|
|
1940
|
+
*/
|
|
1941
|
+
usage(id) {
|
|
1942
|
+
return this.http.request({ method: "GET", path: `/api-keys/${enc(id)}/usage` });
|
|
1943
|
+
}
|
|
1944
|
+
};
|
|
1945
|
+
var Logs = class extends Resource {
|
|
1946
|
+
/**
|
|
1947
|
+
* Your workspace's API request log, newest first (cursor-paginated, `rlog_`
|
|
1948
|
+
* ids): each call's `method`, `path`, `status`, time taken (`duration_ms`),
|
|
1949
|
+
* the API key that made it (`api_key_id`) and its `x-request-id`
|
|
1950
|
+
* (`request_id`: quote it to support). Never the caller's IP and never a
|
|
1951
|
+
* body. Narrow it with `status` (a code, or a class such as `4xx`),
|
|
1952
|
+
* `api_key_id`, `method`, `path_prefix` (e.g. `/email`), `request_id` and a
|
|
1953
|
+
* `created_after` / `created_before` range; an unknown filter is a `422`.
|
|
1954
|
+
* Rows are kept 30 days. Needs `apikeys:read`, which no key preset
|
|
1955
|
+
* includes, and has its own per-workspace rate limit.
|
|
1956
|
+
*/
|
|
1957
|
+
list(params = {}) {
|
|
1958
|
+
return this.http.request({ method: "GET", path: "/logs", query: params });
|
|
1959
|
+
}
|
|
879
1960
|
};
|
|
880
1961
|
var Suppressions = class extends Resource {
|
|
881
1962
|
/**
|
|
882
1963
|
* List your workspace's suppressed addresses. Unitpost-wide (platform)
|
|
883
1964
|
* blocks are enforced at send time but not listed — `get(email)` explains one.
|
|
1965
|
+
* Narrow it with `q` (part of the address), `reason` and a `created_after`
|
|
1966
|
+
* / `created_before` range.
|
|
884
1967
|
*/
|
|
885
1968
|
list(params = {}) {
|
|
886
1969
|
return this.http.request({ method: "GET", path: "/suppressions", query: params });
|
|
887
1970
|
}
|
|
888
|
-
/** Async-iterate every suppressed address. */
|
|
1971
|
+
/** Async-iterate every suppressed address (same filters as `list`). */
|
|
889
1972
|
listAll(params = {}) {
|
|
890
1973
|
return paginate(this.http, "/suppressions", params);
|
|
891
1974
|
}
|
|
@@ -906,6 +1989,226 @@ var Suppressions = class extends Resource {
|
|
|
906
1989
|
return this.http.request({ method: "DELETE", path: `/suppressions/${enc(idOrEmail)}` });
|
|
907
1990
|
}
|
|
908
1991
|
};
|
|
1992
|
+
var INLINE_UPLOAD_MAX_BYTES = 3 * 1024 * 1024;
|
|
1993
|
+
var Files = class extends Resource {
|
|
1994
|
+
/** The workspace's unexpired files, newest first (cursor-paginated; `purpose` filters). */
|
|
1995
|
+
list(params = {}) {
|
|
1996
|
+
return this.http.request({ method: "GET", path: "/files", query: params });
|
|
1997
|
+
}
|
|
1998
|
+
/**
|
|
1999
|
+
* Create a file (201) one of three ways: a public https `url` (fetched
|
|
2000
|
+
* once, no redirects, no private addresses), base64 `data` with its
|
|
2001
|
+
* `content_type` (up to about 4 MB), or neither, with `content_type` and
|
|
2002
|
+
* `size_bytes`: an upload session, whose `upload` says where to PUT the
|
|
2003
|
+
* bytes (`files.upload` does all of this for a local file). The bytes
|
|
2004
|
+
* decide the type. Pass an `idempotencyKey` so a retry makes one file; one
|
|
2005
|
+
* is generated when you don't.
|
|
2006
|
+
*/
|
|
2007
|
+
create(body, opts = {}) {
|
|
2008
|
+
return this.http.request({
|
|
2009
|
+
method: "POST",
|
|
2010
|
+
path: "/files",
|
|
2011
|
+
body,
|
|
2012
|
+
idempotencyKey: opts.idempotencyKey ?? crypto.randomUUID()
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
2015
|
+
/**
|
|
2016
|
+
* One file's metadata (never its bytes). Reading an `awaiting_upload` file
|
|
2017
|
+
* checks its upload, which makes it `ready` or `failed`.
|
|
2018
|
+
*/
|
|
2019
|
+
get(id) {
|
|
2020
|
+
return this.http.request({ method: "GET", path: `/files/${enc(id)}` });
|
|
2021
|
+
}
|
|
2022
|
+
/** Delete a file before it expires. What already used it keeps its copy. */
|
|
2023
|
+
delete(id) {
|
|
2024
|
+
return this.http.request({ method: "DELETE", path: `/files/${enc(id)}` });
|
|
2025
|
+
}
|
|
2026
|
+
/**
|
|
2027
|
+
* Upload a local file or bytes and return the file, checked. Up to 3 MB it
|
|
2028
|
+
* is sent inline (base64 `data`); a larger one opens an upload session,
|
|
2029
|
+
* PUTs the bytes to its `upload.url` with exactly `upload.headers`, then
|
|
2030
|
+
* reads the file back, so the answer is `ready` or `failed`. The
|
|
2031
|
+
* `idempotencyKey` (generated when you don't pass one) is the create's.
|
|
2032
|
+
*/
|
|
2033
|
+
async upload(input, opts = {}) {
|
|
2034
|
+
let bytes = input.data;
|
|
2035
|
+
if (!bytes) {
|
|
2036
|
+
if (!input.path) throw new TypeError("files.upload needs a `path` or `data`.");
|
|
2037
|
+
const { readFile } = await import('fs/promises');
|
|
2038
|
+
bytes = await readFile(input.path);
|
|
2039
|
+
}
|
|
2040
|
+
const filename = input.filename ?? (input.path ? input.path.split(/[\\/]/).pop() : void 0);
|
|
2041
|
+
const base = {
|
|
2042
|
+
purpose: input.purpose,
|
|
2043
|
+
content_type: input.contentType,
|
|
2044
|
+
...filename ? { filename } : {}
|
|
2045
|
+
};
|
|
2046
|
+
if (bytes.byteLength <= INLINE_UPLOAD_MAX_BYTES) {
|
|
2047
|
+
const data = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("base64");
|
|
2048
|
+
return this.create({ ...base, data }, opts);
|
|
2049
|
+
}
|
|
2050
|
+
const created = await this.create({ ...base, size_bytes: bytes.byteLength }, opts);
|
|
2051
|
+
if (created.error || !created.data) return created;
|
|
2052
|
+
const session = created.data.upload;
|
|
2053
|
+
if (!session) {
|
|
2054
|
+
return {
|
|
2055
|
+
data: null,
|
|
2056
|
+
error: new UnitpostError({
|
|
2057
|
+
code: "upload_session_unavailable",
|
|
2058
|
+
message: "This idempotency key already made a file whose upload URL isn't returned again. Upload with a new key.",
|
|
2059
|
+
status: 409,
|
|
2060
|
+
requestId: null
|
|
2061
|
+
})
|
|
2062
|
+
};
|
|
2063
|
+
}
|
|
2064
|
+
const error = await this.http.putBytes(session.url, session.headers, bytes);
|
|
2065
|
+
if (error) return { data: null, error };
|
|
2066
|
+
const read = await this.get(created.data.id);
|
|
2067
|
+
if (read.error || !read.data || read.data.status === "ready") return read;
|
|
2068
|
+
return {
|
|
2069
|
+
data: null,
|
|
2070
|
+
error: new UnitpostError({
|
|
2071
|
+
code: "upload_failed",
|
|
2072
|
+
message: read.data.failure_reason ?? `The file is ${read.data.status}, not ready.`,
|
|
2073
|
+
status: 422,
|
|
2074
|
+
requestId: null
|
|
2075
|
+
})
|
|
2076
|
+
};
|
|
2077
|
+
}
|
|
2078
|
+
};
|
|
2079
|
+
var LibraryImages = class extends Resource {
|
|
2080
|
+
/** The library, newest first (cursor-paginated). */
|
|
2081
|
+
list(params = {}) {
|
|
2082
|
+
return this.http.request({ method: "GET", path: "/library-images", query: params });
|
|
2083
|
+
}
|
|
2084
|
+
/** Async-iterate every image in the library. */
|
|
2085
|
+
listAll(params = {}) {
|
|
2086
|
+
return paginate(this.http, "/library-images", params);
|
|
2087
|
+
}
|
|
2088
|
+
/**
|
|
2089
|
+
* Add an image (201) from a public https `url` (fetched once, no redirects,
|
|
2090
|
+
* no private addresses) or base64 `data` with its `content_type`: PNG,
|
|
2091
|
+
* JPEG, GIF or WebP up to 5 MB, counted against the plan's image storage
|
|
2092
|
+
* (`403 limit_reached`). Pass an `idempotencyKey` so a retried upload stores
|
|
2093
|
+
* one image; one is generated when you don't.
|
|
2094
|
+
*/
|
|
2095
|
+
create(body, opts = {}) {
|
|
2096
|
+
return this.http.request({
|
|
2097
|
+
method: "POST",
|
|
2098
|
+
path: "/library-images",
|
|
2099
|
+
body,
|
|
2100
|
+
idempotencyKey: opts.idempotencyKey ?? crypto.randomUUID()
|
|
2101
|
+
});
|
|
2102
|
+
}
|
|
2103
|
+
get(id) {
|
|
2104
|
+
return this.http.request({ method: "GET", path: `/library-images/${enc(id)}` });
|
|
2105
|
+
}
|
|
2106
|
+
/** Change the alt text the image suggests when it's inserted (`null` or `""` clears it). */
|
|
2107
|
+
update(id, body) {
|
|
2108
|
+
return this.http.request({ method: "PATCH", path: `/library-images/${enc(id)}`, body });
|
|
2109
|
+
}
|
|
2110
|
+
/**
|
|
2111
|
+
* Remove an image from the library. While a template, a campaign or sent
|
|
2112
|
+
* mail uses it, the answer is a `409` `resource_in_use` naming them
|
|
2113
|
+
* (`details`). `{ force: true }` (sent as `?force=true`) deletes it anyway:
|
|
2114
|
+
* those emails then show a broken image wherever it isn't cached yet.
|
|
2115
|
+
*/
|
|
2116
|
+
delete(id, params = {}) {
|
|
2117
|
+
return this.http.request({
|
|
2118
|
+
method: "DELETE",
|
|
2119
|
+
path: `/library-images/${enc(id)}`,
|
|
2120
|
+
query: params.force ? { force: "true" } : void 0
|
|
2121
|
+
});
|
|
2122
|
+
}
|
|
2123
|
+
};
|
|
2124
|
+
var Branding = class extends Resource {
|
|
2125
|
+
/** Colors, font, company name and postal address, the unsubscribe page, the footer, the logo; `null` means the default. */
|
|
2126
|
+
get() {
|
|
2127
|
+
return this.http.request({ method: "GET", path: "/branding" });
|
|
2128
|
+
}
|
|
2129
|
+
/**
|
|
2130
|
+
* Change branding: only the fields you send change, and `null` restores a
|
|
2131
|
+
* default. Hiding the "Sent with Unitpost" mark needs a paid plan
|
|
2132
|
+
* (`403 limit_reached`).
|
|
2133
|
+
*/
|
|
2134
|
+
update(body) {
|
|
2135
|
+
return this.http.request({ method: "PATCH", path: "/branding", body });
|
|
2136
|
+
}
|
|
2137
|
+
/** Replace the logo, from a public https `url` or base64 `data` (PNG, JPEG, GIF or WebP, up to 5 MB). */
|
|
2138
|
+
setLogo(body) {
|
|
2139
|
+
return this.http.request({ method: "PUT", path: "/branding/logo", body });
|
|
2140
|
+
}
|
|
2141
|
+
/** Clear the brand logo (the workspace image shows instead, else none). It sends no body and answers the branding. */
|
|
2142
|
+
removeLogo() {
|
|
2143
|
+
return this.http.request({ method: "DELETE", path: "/branding/logo" });
|
|
2144
|
+
}
|
|
2145
|
+
};
|
|
2146
|
+
var Workspace = class extends Resource {
|
|
2147
|
+
/**
|
|
2148
|
+
* Who is calling: the workspace, the credential (an API key or an OAuth
|
|
2149
|
+
* sign-in, never its secret), its `capabilities` and the workspace's rate
|
|
2150
|
+
* limit. Call it first to see what the credential may do: a call that needs
|
|
2151
|
+
* a capability it lacks answers `403 insufficient_scope`. It needs no
|
|
2152
|
+
* capability: any valid credential may read it.
|
|
2153
|
+
*/
|
|
2154
|
+
whoami() {
|
|
2155
|
+
return this.http.request({ method: "GET", path: "/whoami" });
|
|
2156
|
+
}
|
|
2157
|
+
/**
|
|
2158
|
+
* The workspace activity log, newest first (cursor-paginated, `act_` ids):
|
|
2159
|
+
* what changed, when, who changed it (`actor.name`: a teammate, `System`,
|
|
2160
|
+
* `Ask Unit`) and, for a change made over the API, MCP or Ask Unit, how
|
|
2161
|
+
* (`actor.via`, with the API key). The rows the dashboard's Activity page
|
|
2162
|
+
* and each record's timeline show. Narrow it with `subject` (and
|
|
2163
|
+
* `subject_id`), `contact_id`, `campaign_id`, `q` and `channel: "email"`;
|
|
2164
|
+
* an unknown filter is a `422`. Needs `activity:read`, which no key preset
|
|
2165
|
+
* includes: the log names your teammates.
|
|
2166
|
+
*/
|
|
2167
|
+
listActivity(params = {}) {
|
|
2168
|
+
return this.http.request({ method: "GET", path: "/activity", query: params });
|
|
2169
|
+
}
|
|
2170
|
+
/** Async-iterate every activity row (same filters as `listActivity`). */
|
|
2171
|
+
listAllActivity(params = {}) {
|
|
2172
|
+
return paginate(this.http, "/activity", params);
|
|
2173
|
+
}
|
|
2174
|
+
/** Rename the workspace. */
|
|
2175
|
+
update(body) {
|
|
2176
|
+
return this.http.request({ method: "PATCH", path: "/workspace", body });
|
|
2177
|
+
}
|
|
2178
|
+
/**
|
|
2179
|
+
* Replace the workspace image (its avatar in the dashboard, and the email
|
|
2180
|
+
* logo when there's no brand logo), from a public https `url` or base64
|
|
2181
|
+
* `data` (PNG, JPEG, GIF or WebP, up to 5 MB).
|
|
2182
|
+
*/
|
|
2183
|
+
setImage(body) {
|
|
2184
|
+
return this.http.request({ method: "PUT", path: "/workspace/image", body });
|
|
2185
|
+
}
|
|
2186
|
+
/** Clear the workspace image. It sends no body and answers the workspace. */
|
|
2187
|
+
removeImage() {
|
|
2188
|
+
return this.http.request({ method: "DELETE", path: "/workspace/image" });
|
|
2189
|
+
}
|
|
2190
|
+
};
|
|
2191
|
+
var SpendCaps = class extends Resource {
|
|
2192
|
+
/**
|
|
2193
|
+
* `{ object: "spend_caps", sms_purchases: { cap_cents, max_cents,
|
|
2194
|
+
* spent_cents, period_start, period_end } }`. A `cap_cents` of `null` means
|
|
2195
|
+
* none, so every API purchase is refused with `403 api_spend_cap_not_set`;
|
|
2196
|
+
* the cap that applies is the lower of `cap_cents` and `max_cents`.
|
|
2197
|
+
*/
|
|
2198
|
+
get() {
|
|
2199
|
+
return this.http.request({ method: "GET", path: "/spend-caps" });
|
|
2200
|
+
}
|
|
2201
|
+
/**
|
|
2202
|
+
* Set caps: `{ sms_purchases: { cap_cents } }` in whole cents (>= 0), or
|
|
2203
|
+
* `null` to clear it. Only the caps you send change. A workspace its
|
|
2204
|
+
* organization pays for answers `403 billed_by_organization`: its
|
|
2205
|
+
* organization sets the cap with `sms_purchases_cap_cents` on the
|
|
2206
|
+
* organization's workspace update.
|
|
2207
|
+
*/
|
|
2208
|
+
update(body) {
|
|
2209
|
+
return this.http.request({ method: "PATCH", path: "/spend-caps", body });
|
|
2210
|
+
}
|
|
2211
|
+
};
|
|
909
2212
|
var Usage = class extends Resource {
|
|
910
2213
|
/**
|
|
911
2214
|
* Retrieve the current billing-period usage snapshot: plan, period window,
|
|
@@ -933,12 +2236,24 @@ var Unitpost = class {
|
|
|
933
2236
|
jobs;
|
|
934
2237
|
segments;
|
|
935
2238
|
brandKits;
|
|
2239
|
+
/** The image library templates embed (`/img/…` paths). */
|
|
2240
|
+
libraryImages;
|
|
2241
|
+
/** Files handed to the API for one purpose, used by `file_id` (`upload()` sends a local file). */
|
|
2242
|
+
files;
|
|
2243
|
+
/** The email footer and unsubscribe page look. Writes need `branding:write` (on no key preset). */
|
|
2244
|
+
branding;
|
|
2245
|
+
/** 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). */
|
|
2246
|
+
workspace;
|
|
936
2247
|
webhooks;
|
|
937
2248
|
apiKeys;
|
|
2249
|
+
/** The API request log (`list()`, needs `apikeys:read`, on no key preset). */
|
|
2250
|
+
logs;
|
|
938
2251
|
suppressions;
|
|
939
2252
|
// NOTE (pre-launch): `events` (POST /v1/events) is intentionally absent
|
|
940
2253
|
// while the custom-events surface is behind the launch gate.
|
|
941
2254
|
usage;
|
|
2255
|
+
/** Monthly spend caps (`get()`, `update()`); `update()` needs `spend_caps:write`, on no key preset. */
|
|
2256
|
+
spendCaps;
|
|
942
2257
|
constructor(apiKeyOrOptions) {
|
|
943
2258
|
const options = typeof apiKeyOrOptions === "string" ? { apiKey: apiKeyOrOptions } : apiKeyOrOptions ?? {};
|
|
944
2259
|
const http = new HttpClient(options);
|
|
@@ -949,16 +2264,309 @@ var Unitpost = class {
|
|
|
949
2264
|
this.jobs = new Jobs(http);
|
|
950
2265
|
this.segments = new Segments(http);
|
|
951
2266
|
this.brandKits = new BrandKits(http);
|
|
2267
|
+
this.libraryImages = new LibraryImages(http);
|
|
2268
|
+
this.files = new Files(http);
|
|
2269
|
+
this.branding = new Branding(http);
|
|
2270
|
+
this.workspace = new Workspace(http);
|
|
952
2271
|
this.webhooks = new Webhooks(http);
|
|
953
2272
|
this.apiKeys = new ApiKeys(http);
|
|
2273
|
+
this.logs = new Logs(http);
|
|
954
2274
|
this.suppressions = new Suppressions(http);
|
|
955
2275
|
this.usage = new Usage(http);
|
|
2276
|
+
this.spendCaps = new SpendCaps(http);
|
|
2277
|
+
}
|
|
2278
|
+
};
|
|
2279
|
+
function env(name) {
|
|
2280
|
+
return typeof process !== "undefined" && process.env ? process.env[name] : void 0;
|
|
2281
|
+
}
|
|
2282
|
+
var UnitpostOrganization = class {
|
|
2283
|
+
/** The organization every call acts on (`org_…`). */
|
|
2284
|
+
organizationId;
|
|
2285
|
+
/** The organization's workspaces: list, create, get, update, close, restore. */
|
|
2286
|
+
workspaces;
|
|
2287
|
+
/** Keys for one of the organization's workspaces: `create` mints one (the secret is in that answer only). */
|
|
2288
|
+
workspaceKeys;
|
|
2289
|
+
/** The organization's webhook endpoints: events from every workspace it owns, each with `workspace_id` and `external_id`. */
|
|
2290
|
+
webhooks;
|
|
2291
|
+
/** Usage per workspace for a billing period (`list`). */
|
|
2292
|
+
usage;
|
|
2293
|
+
/** A plan change for one workspace the organization pays for: quote, read, confirm. */
|
|
2294
|
+
planQuotes;
|
|
2295
|
+
/** The organization's shared plan: read it, and add, cap or remove the workspaces on it. */
|
|
2296
|
+
sharedPlan;
|
|
2297
|
+
constructor(options = {}) {
|
|
2298
|
+
const apiKey = options.apiKey ?? env("UNITPOST_ORG_KEY");
|
|
2299
|
+
if (!apiKey) {
|
|
2300
|
+
throw new UnitpostError({
|
|
2301
|
+
code: "missing_api_key",
|
|
2302
|
+
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.",
|
|
2303
|
+
status: 0,
|
|
2304
|
+
requestId: null
|
|
2305
|
+
});
|
|
2306
|
+
}
|
|
2307
|
+
const organizationId = options.organizationId ?? env("UNITPOST_ORGANIZATION_ID");
|
|
2308
|
+
if (!organizationId) {
|
|
2309
|
+
throw new UnitpostError({
|
|
2310
|
+
code: "missing_organization_id",
|
|
2311
|
+
message: "No organization id provided. Pass `new UnitpostOrganization({ organizationId })` (`org_\u2026`) or set the UNITPOST_ORGANIZATION_ID environment variable.",
|
|
2312
|
+
status: 0,
|
|
2313
|
+
requestId: null
|
|
2314
|
+
});
|
|
2315
|
+
}
|
|
2316
|
+
const { organizationId: _id, ...transport } = options;
|
|
2317
|
+
const http = new HttpClient({ ...transport, apiKey });
|
|
2318
|
+
this.organizationId = organizationId;
|
|
2319
|
+
this.workspaces = new OrganizationWorkspaces(http, organizationId);
|
|
2320
|
+
this.workspaceKeys = new OrganizationWorkspaceKeys(http, organizationId);
|
|
2321
|
+
this.webhooks = new OrganizationWebhooks(http, organizationId);
|
|
2322
|
+
this.usage = new OrganizationUsage(http, organizationId);
|
|
2323
|
+
this.planQuotes = new OrganizationPlanQuotes(http, organizationId);
|
|
2324
|
+
this.sharedPlan = new OrganizationSharedPlan(http, organizationId);
|
|
956
2325
|
}
|
|
957
2326
|
};
|
|
2327
|
+
var OrganizationResource = class {
|
|
2328
|
+
constructor(http, organizationId) {
|
|
2329
|
+
this.http = http;
|
|
2330
|
+
this.organizationId = organizationId;
|
|
2331
|
+
}
|
|
2332
|
+
http;
|
|
2333
|
+
organizationId;
|
|
2334
|
+
};
|
|
2335
|
+
var OrganizationWorkspaces = class extends OrganizationResource {
|
|
2336
|
+
/** The organization's workspaces, newest first (cursor-paginated). Needs `organizations:read`. */
|
|
2337
|
+
list(params = {}) {
|
|
2338
|
+
return this.http.request({ method: "GET", path: `/organizations/${enc2(this.organizationId)}/workspaces`, query: params });
|
|
2339
|
+
}
|
|
2340
|
+
/** Async-iterate every workspace of the organization (same filters as `list`). */
|
|
2341
|
+
listAll(params = {}) {
|
|
2342
|
+
return paginate(this.http, `/organizations/${enc2(this.organizationId)}/workspaces`, params);
|
|
2343
|
+
}
|
|
2344
|
+
/**
|
|
2345
|
+
* Create a workspace (201). Its Owner is the key's creator. An
|
|
2346
|
+
* Idempotency-Key is generated when you don't pass one, so a retry can't
|
|
2347
|
+
* make two. Needs `organizations:write`.
|
|
2348
|
+
*/
|
|
2349
|
+
create(body, opts = {}) {
|
|
2350
|
+
return this.http.request({
|
|
2351
|
+
method: "POST",
|
|
2352
|
+
path: `/organizations/${enc2(this.organizationId)}/workspaces`,
|
|
2353
|
+
body,
|
|
2354
|
+
idempotencyKey: opts.idempotencyKey ?? crypto.randomUUID()
|
|
2355
|
+
});
|
|
2356
|
+
}
|
|
2357
|
+
/** One workspace (`ws_…`). Needs `organizations:read`. */
|
|
2358
|
+
get(workspaceId) {
|
|
2359
|
+
return this.http.request({ method: "GET", path: `/organizations/${enc2(this.organizationId)}/workspaces/${enc2(workspaceId)}` });
|
|
2360
|
+
}
|
|
2361
|
+
/** Rename it, set its `external_id` or its SMS purchases cap. Needs `organizations:write`. */
|
|
2362
|
+
update(workspaceId, body) {
|
|
2363
|
+
return this.http.request({ method: "PATCH", path: `/organizations/${enc2(this.organizationId)}/workspaces/${enc2(workspaceId)}`, body });
|
|
2364
|
+
}
|
|
2365
|
+
/**
|
|
2366
|
+
* Close it: it stops sending at once. It can be restored for 30 days
|
|
2367
|
+
* (`restorable_until`); unless restored, it is deleted once those 30 days
|
|
2368
|
+
* are over and 7 days have passed since the end of the billing period it
|
|
2369
|
+
* closed in, whichever is later (`deletes_at`). Closing twice changes
|
|
2370
|
+
* nothing. Needs `organizations:write`.
|
|
2371
|
+
*/
|
|
2372
|
+
close(workspaceId) {
|
|
2373
|
+
return this.http.request({ method: "POST", path: `/organizations/${enc2(this.organizationId)}/workspaces/${enc2(workspaceId)}/close` });
|
|
2374
|
+
}
|
|
2375
|
+
/** Restore a closed workspace within its 30 days. Needs `organizations:write`. */
|
|
2376
|
+
restore(workspaceId) {
|
|
2377
|
+
return this.http.request({ method: "POST", path: `/organizations/${enc2(this.organizationId)}/workspaces/${enc2(workspaceId)}/restore` });
|
|
2378
|
+
}
|
|
2379
|
+
};
|
|
2380
|
+
var OrganizationWorkspaceKeys = class extends OrganizationResource {
|
|
2381
|
+
/**
|
|
2382
|
+
* Mint a workspace key (201) for one of the organization's workspaces. The
|
|
2383
|
+
* answer holds the secret (`key`) once; use it with `new Unitpost(key)`.
|
|
2384
|
+
* Needs `organizations:write`.
|
|
2385
|
+
*/
|
|
2386
|
+
create(workspaceId, body) {
|
|
2387
|
+
return this.http.request({
|
|
2388
|
+
method: "POST",
|
|
2389
|
+
path: `/organizations/${enc2(this.organizationId)}/workspaces/${enc2(workspaceId)}/api-keys`,
|
|
2390
|
+
body
|
|
2391
|
+
});
|
|
2392
|
+
}
|
|
2393
|
+
};
|
|
2394
|
+
var OrganizationWebhooks = class extends OrganizationResource {
|
|
2395
|
+
/** The organization's webhook endpoints. Needs `organizations:read`. */
|
|
2396
|
+
list(params = {}) {
|
|
2397
|
+
return this.http.request({ method: "GET", path: `/organizations/${enc2(this.organizationId)}/webhooks`, query: params });
|
|
2398
|
+
}
|
|
2399
|
+
/** Async-iterate every webhook endpoint of the organization. Needs `organizations:read`. */
|
|
2400
|
+
listAll(params = {}) {
|
|
2401
|
+
return paginate(this.http, `/organizations/${enc2(this.organizationId)}/webhooks`, params);
|
|
2402
|
+
}
|
|
2403
|
+
/** Create an endpoint. The answer has `signing_secret` exactly once. Needs `organizations:write`. */
|
|
2404
|
+
create(body) {
|
|
2405
|
+
return this.http.request({ method: "POST", path: `/organizations/${enc2(this.organizationId)}/webhooks`, body });
|
|
2406
|
+
}
|
|
2407
|
+
/** One endpoint (`wh_…`). Needs `organizations:read`. */
|
|
2408
|
+
get(webhookId) {
|
|
2409
|
+
return this.http.request({ method: "GET", path: `/organizations/${enc2(this.organizationId)}/webhooks/${enc2(webhookId)}` });
|
|
2410
|
+
}
|
|
2411
|
+
update(webhookId, body) {
|
|
2412
|
+
return this.http.request({ method: "PATCH", path: `/organizations/${enc2(this.organizationId)}/webhooks/${enc2(webhookId)}`, body });
|
|
2413
|
+
}
|
|
2414
|
+
delete(webhookId) {
|
|
2415
|
+
return this.http.request({ method: "DELETE", path: `/organizations/${enc2(this.organizationId)}/webhooks/${enc2(webhookId)}` });
|
|
2416
|
+
}
|
|
2417
|
+
/** Mint a new signing secret; the answer carries it exactly once. */
|
|
2418
|
+
rotateSecret(webhookId) {
|
|
2419
|
+
return this.http.request({ method: "POST", path: `/organizations/${enc2(this.organizationId)}/webhooks/${enc2(webhookId)}/rotate-secret` });
|
|
2420
|
+
}
|
|
2421
|
+
/** Fire a sample event at the endpoint. */
|
|
2422
|
+
test(webhookId) {
|
|
2423
|
+
return this.http.request({ method: "POST", path: `/organizations/${enc2(this.organizationId)}/webhooks/${enc2(webhookId)}/test` });
|
|
2424
|
+
}
|
|
2425
|
+
/**
|
|
2426
|
+
* The endpoint's delivery log, newest first; each row names its
|
|
2427
|
+
* `workspace_id` and `external_id`. Needs `organizations:write` (the rows
|
|
2428
|
+
* carry each event's data, so `organizations:read` alone is a 403).
|
|
2429
|
+
*/
|
|
2430
|
+
listDeliveries(webhookId, params = {}) {
|
|
2431
|
+
return this.http.request({
|
|
2432
|
+
method: "GET",
|
|
2433
|
+
path: `/organizations/${enc2(this.organizationId)}/webhooks/${enc2(webhookId)}/deliveries`,
|
|
2434
|
+
query: params
|
|
2435
|
+
});
|
|
2436
|
+
}
|
|
2437
|
+
/** Async-iterate the endpoint's whole delivery log (same filters as `listDeliveries`). Needs `organizations:write`. */
|
|
2438
|
+
listAllDeliveries(webhookId, params = {}) {
|
|
2439
|
+
return paginate(this.http, `/organizations/${enc2(this.organizationId)}/webhooks/${enc2(webhookId)}/deliveries`, params);
|
|
2440
|
+
}
|
|
2441
|
+
/** Deliver one event to the endpoint again (202). */
|
|
2442
|
+
replayDelivery(webhookId, deliveryId) {
|
|
2443
|
+
return this.http.request({
|
|
2444
|
+
method: "POST",
|
|
2445
|
+
path: `/organizations/${enc2(this.organizationId)}/webhooks/${enc2(webhookId)}/deliveries/${enc2(deliveryId)}/replay`
|
|
2446
|
+
});
|
|
2447
|
+
}
|
|
2448
|
+
/** Deliver the backlog (202); `include_failed: true` adds the ones that failed for good. */
|
|
2449
|
+
flush(webhookId, body = {}) {
|
|
2450
|
+
return this.http.request({ method: "POST", path: `/organizations/${enc2(this.organizationId)}/webhooks/${enc2(webhookId)}/flush`, body });
|
|
2451
|
+
}
|
|
2452
|
+
/** Verify a delivery's signature and return the parsed event (the top-level `verifyWebhook`). */
|
|
2453
|
+
verify(args) {
|
|
2454
|
+
return verifyWebhook(args);
|
|
2455
|
+
}
|
|
2456
|
+
};
|
|
2457
|
+
var OrganizationUsage = class extends OrganizationResource {
|
|
2458
|
+
/**
|
|
2459
|
+
* Usage per workspace (`workspace_usage` rows), each for that workspace's
|
|
2460
|
+
* own billing period containing `period`. Paged by workspace. Needs
|
|
2461
|
+
* `organizations:read`.
|
|
2462
|
+
*/
|
|
2463
|
+
list(params = {}) {
|
|
2464
|
+
return this.http.request({ method: "GET", path: `/organizations/${enc2(this.organizationId)}/usage`, query: params });
|
|
2465
|
+
}
|
|
2466
|
+
/**
|
|
2467
|
+
* Async-iterate the usage row of every workspace (same filters as `list`),
|
|
2468
|
+
* paging by the last row's `workspace_id`. Needs `organizations:read`.
|
|
2469
|
+
*/
|
|
2470
|
+
listAll(params = {}) {
|
|
2471
|
+
return paginate(this.http, `/organizations/${enc2(this.organizationId)}/usage`, params, "workspace_id");
|
|
2472
|
+
}
|
|
2473
|
+
};
|
|
2474
|
+
var OrganizationPlanQuotes = class extends OrganizationResource {
|
|
2475
|
+
/**
|
|
2476
|
+
* Price a plan change for one workspace the organization pays for (201).
|
|
2477
|
+
* Charges nothing; the quote lasts 10 minutes and holds a single-use
|
|
2478
|
+
* `confirm_token` (only in this answer). Its `pending_change` is a
|
|
2479
|
+
* downgrade already scheduled for the period end, or null; with one, a
|
|
2480
|
+
* quote for the current plan and tier is a `noop` whose confirm cancels
|
|
2481
|
+
* it. Needs `organizations:billing`.
|
|
2482
|
+
*/
|
|
2483
|
+
create(workspaceId, body) {
|
|
2484
|
+
return this.http.request({
|
|
2485
|
+
method: "POST",
|
|
2486
|
+
path: `/organizations/${enc2(this.organizationId)}/workspaces/${enc2(workspaceId)}/plan-quotes`,
|
|
2487
|
+
body
|
|
2488
|
+
});
|
|
2489
|
+
}
|
|
2490
|
+
/** One quote (`pq_…`). Needs `organizations:read`. */
|
|
2491
|
+
get(workspaceId, quoteId) {
|
|
2492
|
+
return this.http.request({
|
|
2493
|
+
method: "GET",
|
|
2494
|
+
path: `/organizations/${enc2(this.organizationId)}/workspaces/${enc2(workspaceId)}/plan-quotes/${enc2(quoteId)}`
|
|
2495
|
+
});
|
|
2496
|
+
}
|
|
2497
|
+
/**
|
|
2498
|
+
* Apply the quoted change and charge it. An Idempotency-Key is generated
|
|
2499
|
+
* when you don't pass one, so a retry can't charge twice. Needs
|
|
2500
|
+
* `organizations:billing`.
|
|
2501
|
+
*/
|
|
2502
|
+
confirm(workspaceId, quoteId, body, opts = {}) {
|
|
2503
|
+
return this.http.request({
|
|
2504
|
+
method: "POST",
|
|
2505
|
+
path: `/organizations/${enc2(this.organizationId)}/workspaces/${enc2(workspaceId)}/plan-quotes/${enc2(quoteId)}/confirm`,
|
|
2506
|
+
body,
|
|
2507
|
+
idempotencyKey: opts.idempotencyKey ?? crypto.randomUUID()
|
|
2508
|
+
});
|
|
2509
|
+
}
|
|
2510
|
+
};
|
|
2511
|
+
var OrganizationSharedPlan = class extends OrganizationResource {
|
|
2512
|
+
/**
|
|
2513
|
+
* The organization's shared plan (one plan whose allowance its workspaces
|
|
2514
|
+
* share): whether it's turned on (`approved`), its `status` (`none` until
|
|
2515
|
+
* one is bought), plan, price and period, and this period's
|
|
2516
|
+
* `used_cents`, `overage_cents`, `paused`. Buying, upgrading and ending it
|
|
2517
|
+
* are done in the dashboard. Needs `organizations:read`.
|
|
2518
|
+
*/
|
|
2519
|
+
get() {
|
|
2520
|
+
return this.http.request({ method: "GET", path: `/organizations/${enc2(this.organizationId)}/shared-plan` });
|
|
2521
|
+
}
|
|
2522
|
+
/** Every workspace on the shared plan, with its cap and what it drew this period (one page). Needs `organizations:read`. */
|
|
2523
|
+
listWorkspaces() {
|
|
2524
|
+
return this.http.request({ method: "GET", path: `/organizations/${enc2(this.organizationId)}/shared-plan/workspaces` });
|
|
2525
|
+
}
|
|
2526
|
+
/**
|
|
2527
|
+
* Put a workspace on the shared plan (it moves onto the organization's
|
|
2528
|
+
* card), or set its cap when it's already on it. Refusals carry the reason
|
|
2529
|
+
* in `error.details[0].code` (`own_plan`, `limit_reached`, …). An
|
|
2530
|
+
* Idempotency-Key is generated when you don't pass one, so a retry answers
|
|
2531
|
+
* what the first call did. Needs `organizations:billing`.
|
|
2532
|
+
*/
|
|
2533
|
+
addWorkspace(workspaceId, body = {}, opts = {}) {
|
|
2534
|
+
return this.http.request({
|
|
2535
|
+
method: "PUT",
|
|
2536
|
+
path: `/organizations/${enc2(this.organizationId)}/shared-plan/workspaces/${enc2(workspaceId)}`,
|
|
2537
|
+
body,
|
|
2538
|
+
idempotencyKey: opts.idempotencyKey ?? crypto.randomUUID()
|
|
2539
|
+
});
|
|
2540
|
+
}
|
|
2541
|
+
/** Set a workspace's cap (`cap_cents`; null removes it). Needs `organizations:billing`. */
|
|
2542
|
+
updateWorkspace(workspaceId, body) {
|
|
2543
|
+
return this.http.request({
|
|
2544
|
+
method: "PATCH",
|
|
2545
|
+
path: `/organizations/${enc2(this.organizationId)}/shared-plan/workspaces/${enc2(workspaceId)}`,
|
|
2546
|
+
body
|
|
2547
|
+
});
|
|
2548
|
+
}
|
|
2549
|
+
/**
|
|
2550
|
+
* Take a workspace off the shared plan: `drops_to` is `free` or
|
|
2551
|
+
* `needs_plan`; one not on it answers `left: false`. An Idempotency-Key is
|
|
2552
|
+
* generated when you don't pass one. Needs `organizations:billing`.
|
|
2553
|
+
*/
|
|
2554
|
+
removeWorkspace(workspaceId, opts = {}) {
|
|
2555
|
+
return this.http.request({
|
|
2556
|
+
method: "DELETE",
|
|
2557
|
+
path: `/organizations/${enc2(this.organizationId)}/shared-plan/workspaces/${enc2(workspaceId)}`,
|
|
2558
|
+
idempotencyKey: opts.idempotencyKey ?? crypto.randomUUID()
|
|
2559
|
+
});
|
|
2560
|
+
}
|
|
2561
|
+
};
|
|
2562
|
+
function enc2(segment) {
|
|
2563
|
+
return encodeURIComponent(segment);
|
|
2564
|
+
}
|
|
958
2565
|
|
|
959
2566
|
exports.SDK_VERSION = SDK_VERSION;
|
|
960
2567
|
exports.Unitpost = Unitpost;
|
|
961
2568
|
exports.UnitpostError = UnitpostError;
|
|
2569
|
+
exports.UnitpostOrganization = UnitpostOrganization;
|
|
962
2570
|
exports.WebhookVerificationError = WebhookVerificationError;
|
|
963
2571
|
exports.verifyWebhook = verifyWebhook;
|
|
964
2572
|
//# sourceMappingURL=index.cjs.map
|