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