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 ADDED
@@ -0,0 +1,332 @@
1
+ # Changelog
2
+
3
+ Notable changes to the Unitpost Node.js SDK. Changes to the API itself (new
4
+ operations, new fields, behavior changes) are in the API changelog:
5
+ https://www.unitpost.com/docs/changelog.
6
+
7
+ To release, move the `Unreleased` items under a `## X.Y.Z` heading in the same
8
+ change that bumps the version (docs/sdk/RELEASING.md).
9
+
10
+ ## Unreleased
11
+
12
+ ## 0.6.0
13
+
14
+ - Set one custom field on many contacts: `contacts.setField(body, { idempotencyKey })` (`ContactSetField`: `key`, `value`, (exactly one of `contact_ids` or `emails`, up to 1,000, or `segment_id`; `only_empty` keeps the values contacts already have). It answers the job (202); follow it with `jobs.get(id)`. The SDK mints an idempotency key when you pass none, so a retry answers the same job. Needs `contacts:write` (a segment also `segments:read`).
15
+ - `segments.addMember` also takes a list (`{ contact_ids }` or `{ emails }`, up to 1,000), which answers `SegmentMembersAdded` (each listed contact's membership and `added`); `{ contact }` and a body typed as `Models.SegmentMemberAdd` (still the single-contact body, `contact` required) answer `SegmentMember`, so code written before lists compiles unchanged. The list body is `Models.SegmentMembersAdd`; a body that could be either (`Models.SegmentMemberAddBody`, the request's combined shape) answers the union.
16
+
17
+ ## 0.5.0
18
+
19
+ - `UnitpostOrganization` gains `sharedPlan`: `get`, `listWorkspaces`, `addWorkspace`, `updateWorkspace`, `removeWorkspace` (the organization's shared plan; adding and removing take an optional idempotency key, or the SDK mints one). Reads need `organizations:read`; the three writes need `organizations:billing`. Buying, upgrading or ending the shared plan stays in the dashboard.
20
+ - `UnitpostOrganization` iterators: `webhooks.listAll()`, `webhooks.listAllDeliveries(webhookId)` and `usage.listAll()` (pages by `workspace_id`). The delivery log needs `organizations:write`.
21
+ - SMS tags: `sms.send({ …, tags: [{ name, value }] })` (up to 10) and `sms.list({ tag })` / `sms.listAll({ tag })`, where `tag` is `"name:value"`, several comma-separated, or an array; texts carrying all of them. The SMS object carries `tags`.
22
+ - `spendCaps` (new, ADR-0172): the workspace's monthly spend caps. `get()` reads the SMS-purchase cap, its `max_cents` and what it counted this UTC month; `update(body)` sets or clears it and needs `spend_caps:write`, which no key preset includes. A workspace its organization pays for answers `403 billed_by_organization`.
23
+ - `UnitpostOrganization` (new, ADR-0171): the client for an organization key
24
+ (`ok_live_…`), made with the key and the organization's id
25
+ (`UNITPOST_ORG_KEY` and `UNITPOST_ORGANIZATION_ID` when left out). It has
26
+ `workspaces` (`list`, `listAll`, `create` with an idempotency key, `get`,
27
+ `update`, `close`, `restore`), `workspaceKeys.create`, `webhooks` (the
28
+ organization's endpoints), `usage.list` and `planQuotes` (`create`, `get`,
29
+ `confirm` with an idempotency key). The workspace client `Unitpost` doesn't
30
+ carry them.
31
+ - `sms.addContact(id)`, `sms.listJoinKeywords(numberId)`, `sms.addJoinKeyword(numberId, body)`, `sms.removeJoinKeyword(numberId, keywordId)`: add a texter as a contact and manage text-to-join keywords.
32
+ - `SmsFailureCode` gains `sms_not_in_plan`: SMS wasn't on the plan when a text was due (the paid plan ended after its grace, or the plan is 100% discounted). Not charged.
33
+ - SMS numbers and registrations, start to finish (ADR-0160, 2026-11-12):
34
+ `sms.getNumber(id)`, `sms.releaseNumber(id, { force }, { idempotencyKey })`
35
+ (permanent), `sms.registrations.get(id)`, `sms.registrations.remove(id)` (a
36
+ 10DLC setup with no number) and `sms.registrations.replace(id)` (an approved
37
+ brand registration). Every new write mints an Idempotency-Key when you
38
+ don't pass one.
39
+ - Files and SMS onboarding by API (ADR-0159, 2026-11-12):
40
+ - `files` (new): `list({ purpose })`, `create(body, { idempotencyKey })`,
41
+ `get(id)`, `delete(id)`. A file (`file_` id) is bytes handed to the API
42
+ for one `purpose` (`sms_opt_in_evidence`, `sms_document`, `image`) from a
43
+ `url`, base64 `data`, or an upload session, used by `file_id` and
44
+ expiring after 24 hours.
45
+ - `files.upload({ path | data, purpose, contentType, filename? })`: sends a
46
+ file up to 3 MB inline, and a larger one through an upload session (the
47
+ create, a PUT of the bytes with exactly `upload.headers`, then `get`).
48
+ - `sms`: a brand's documents (`listBrandDocuments(brandId)`,
49
+ `addBrandDocument(brandId, body, { idempotencyKey })`,
50
+ `getBrandDocument`, `removeBrandDocument`, and `brandDocumentUrl`, a
51
+ 5-minute signed link), and `resubmitNumber(numberId, body, {
52
+ idempotencyKey })` for a toll-free verification carriers sent back.
53
+ - `sms.registrations`: `resubmit(id, body, { idempotencyKey })` for a 10DLC
54
+ campaign carriers sent back, and `requestNumber(id, {}, {
55
+ idempotencyKey })` to retry a failed number whose fee is committed.
56
+ - Every new write generates an Idempotency-Key when you don't pass one.
57
+ - `error.docUrl`: the page the API links for an error, when it links one (today `sending_paused`, a paused sending stream; ADR-0156). `null`/`None` otherwise. The `Campaign.pause_reason.code` union adds `sending_paused`.
58
+ - A result carries `warning`, the response's `Unitpost-Warning` header, when a
59
+ successful call had one: something it left out or ignored without failing,
60
+ for example a recipient on a reserved domain (example.com) that wasn't sent
61
+ to, or a body field the operation ignored. Absent otherwise. The new
62
+ `ApiResult` type names the `{ data, error, warning? }` shape. Before this
63
+ the header was dropped, so an SDK caller couldn't tell a recipient was left
64
+ out (verifier on #1217).
65
+ - `ApiFieldError` (an entry of `UnitpostError.details`) declares the optional
66
+ `code`, a machine-readable reason for the entry, such as the SMS skip word
67
+ on `to` (`out_of_reach`). The type is now exported.
68
+ - The SMS list takes `sender_id`, a number's `snum_…` id: that number's
69
+ texts, both directions. A value it can't apply is ignored and named in the
70
+ `Unitpost-Warning` response header; `Unitpost-Strict: true` refuses it.
71
+ - `sms.quotes` (new): `create(body)`, `get(id)` and `confirm(id, {
72
+ confirm_token }, { idempotencyKey })` buy SMS carrier resources (`squote_`
73
+ ids): register a 10DLC brand, vet it, register a campaign, order a number.
74
+ `confirm` generates an Idempotency-Key when you don't pass one, so a retry
75
+ can't buy twice. `create` prices the order and binds what it buys (the
76
+ brand's and program's content, the price) and returns `due_now_cents`,
77
+ `monthly_cents`, `line_items` and a single-use `confirm_token` (`sqct_`),
78
+ only in that response; a quote lasts 10 minutes and charges nothing. The
79
+ confirm places the order at that price, or answers `409` when the price or
80
+ content changed. It needs `sms:purchase`, which no key preset includes, and
81
+ the workspace owner's monthly cap for SMS purchases by API (no cap set
82
+ refuses it). Show the person the price and get their yes before confirming.
83
+ - `logs.list(params)` (new `logs` resource): the workspace's API request
84
+ log, newest first and cursor-paginated (`rlog_` ids). Each row is one call:
85
+ `method`, `path`, `status`, `duration_ms`, `api_key_id` and its
86
+ `request_id` (the `x-request-id`), never the caller's IP or a body; rows are
87
+ kept 30 days. Filters (`LogListParams`): `status` (a code or `2xx`…`5xx`),
88
+ `api_key_id`, `method`, `path_prefix`, `request_id`, `created_after`,
89
+ `created_before`. It needs `apikeys:read`, which no key preset includes.
90
+ - Opt many contacts out of a topic at once: `email.topics.optOut(id, body, { idempotencyKey })`
91
+ and `sms.topics.optOut(id, body, { idempotencyKey })` (`TopicOptOut`: exactly
92
+ one of `contact_ids` or `emails`, up to 1,000, or `segment_id`). They answer
93
+ a `Job` (202); follow it with `jobs.get(id)`. The SDK mints an idempotency
94
+ key when you pass none, so a retry answers the same job. There is no bulk
95
+ opt-in. Needs `topics:write` (a segment also `segments:read`).
96
+ - `sms.registrations.list`, `sms.testDestinations.list`,
97
+ `sms.consentSetups.list`, `sms.billing.listResources` and
98
+ `sms.messagingPrograms.list` take `limit`, `after` and `before`
99
+ (`ListParams`): the five lists are cursor-paginated, newest first.
100
+ - New response fields are optional in the models (the API always sends
101
+ them), so a value typed as a model with only its 0.4.0 fields still
102
+ type-checks.
103
+ - The activity log, an API key's usage, several topic preferences at once and
104
+ list search. `workspace.listActivity(params)` / `listAllActivity`: the
105
+ workspace's activity log, newest first (cursor-paginated on `act_` ids):
106
+ what changed, when, who (`actor.name`) and, for a change over the API, MCP
107
+ or Ask Unit, how (`actor.via`, with the API key). Narrow it with `subject`
108
+ (and `subject_id`), `contact_id`, `campaign_id`, `q` and `channel: "email"`
109
+ (`ActivityListParams`; an unknown key is a `422`). It needs `activity:read`.
110
+ `apiKeys.usage(id)` returns `ApiKeyUsage`: a key's requests in the last 24
111
+ hours (`requests_24h`, `client_errors_24h`, `server_errors_24h`,
112
+ `rate_limited_24h`) and `last_used_at`. `apiKeys.list` now also works with
113
+ an API key or an MCP sign-in (it was dashboard-session only); with one,
114
+ `list` and `usage` need `apikeys:read`. Creating and revoking keys stay in
115
+ the dashboard. No key preset includes `activity:read` or `apikeys:read`.
116
+ `email.topics.updateTopics(contactId, { topics: [{ topic_id, subscribed }] })`
117
+ (`PATCH /contacts/{id}/topics`, up to 50) changes several of a contact's
118
+ preferences at once, leaves the others as they are, and returns
119
+ `ContactTopicList`; `setTopic` is unchanged. `email.list` /
120
+ `listAll` take `q` (an exact recipient, or part of the subject or the
121
+ sender), `source` (`api` | `smtp` | `test` | `batch` | `campaign` | `reply`)
122
+ and `outcome` (`delivered` | `opened` | `clicked` | `unsubscribed` |
123
+ `bounced` | `complained` | `failed` | `pending`; with `campaign_id`, who
124
+ opened or clicked it). `sms.list` / `listAll` take `q` (the message text, or
125
+ 3 or more digits of either number) and `type` (`transactional` |
126
+ `marketing`). A `q`, `source`, `outcome` or `type` value the API can't apply
127
+ is ignored and named in the `Unitpost-Warning` response header;
128
+ `Unitpost-Strict: true` refuses it.
129
+ - List filters and a stats period. `suppressions.list` / `listAll` take `q`
130
+ (part of the address), `reason` and `created_after` / `created_before`
131
+ (`SuppressionListParams`; `scope` stays, deprecated).
132
+ `webhooks.listDeliveries` / `listAllDeliveries` take `status`
133
+ (comma-separated, e.g. `"failed,exhausted"`) and `event_type`
134
+ (`WebhookDeliveryListParams`). `email.stats` keeps `days` and takes a period
135
+ instead: `from` / `to`, with `grain` (`5m` | `1h` | `1d`) and `tz` for
136
+ `series`, the send volume per bucket, and `domain_id` for one sending domain
137
+ (`EmailStatsParams`). These lists ignored the filters before, so a value the
138
+ API can't apply is ignored and named in the `Unitpost-Warning` response
139
+ header; `Unitpost-Strict: true` refuses it. `webhooks.get` still returns
140
+ `Webhook`, which adds an optional `backlog: { queued, failed }` (what a flush
141
+ would send; only `get` fills it). `EmailStats` adds the permanent and transient bounces,
142
+ `suppressed`, `unsubscribed`, `rates.unsubscribe`, `domain_id`, `from`, `to`
143
+ and `series`; `Topic` adds `subscriber_count` and `unsubscribed_count`;
144
+ `Usage` adds the plan's `limits` and `features`.
145
+ - Who is calling, an email's events, a received email's original and
146
+ template rendering. `workspace.whoami()`: the workspace, the credential (an
147
+ API key or an OAuth sign-in, never its secret), its `capabilities` and the
148
+ workspace's rate limit; any valid credential may call it, so call it first
149
+ to see what a key may do. `email.listEvents(id, { limit, after, before })`:
150
+ one email's delivery events, oldest first, with each event's detail under
151
+ the webhook's names (cursor-paginated on `emev_` ids; no `listAll`).
152
+ `email.receivedRaw(id)`: a signed URL (about 5 minutes) to a received
153
+ message's original `.eml`, the way to read a body over 256 KB; a copy of
154
+ your own send is a `403`.
155
+ `email.templates.render(id, { variables, subject, contact_id })`: the
156
+ subject, HTML and text a send would carry, and its `missing_variables`; it
157
+ sends and stores nothing, so it takes no idempotency key, and the body is
158
+ optional. `listEvents` and `receivedRaw` need `emails:read`; `render` needs
159
+ `templates:read`. `email.get` still returns `Email`, which adds optional
160
+ `cc`, `bcc`, `reply_to` and `tags` (only `get` fills them).
161
+ - SMS brands and registrations. On `sms`:
162
+ `createBrand(body, { idempotencyKey })`, `getBrand(id)` and
163
+ `updateBrand(id, body)` (send `{ archived }` alone to archive or restore).
164
+ A new resource on `sms`: `sms.registrations.list(params)`, cursor-paginated
165
+ (no `listAll`). Creating a brand is free and makes
166
+ no carrier call; its tax id is write-only (read back as `tax_id_on_file`),
167
+ and a locked brand refuses carrier-field edits with `409 brand_locked`.
168
+ The reads need `sms:read`; the brand writes need `sms:manage`. Registering
169
+ a brand with carriers (a paid step), ordering numbers and a brand's
170
+ documents stay in the dashboard.
171
+ - SMS setup. On `sms.templates`: `usage(id)` and
172
+ `testSend(id, { to, variables, sender_id }, { idempotencyKey })`. Four new
173
+ resources on `sms`: `sms.messagingPrograms.list({ archived })`,
174
+ `create(body, { idempotencyKey })`, `get(id)`, `update(id, body)`,
175
+ `delete(id)` (it archives) and `duplicate(id, { idempotencyKey })`;
176
+ `sms.testDestinations.list()` and `delete(id)`; `sms.consentSetups.list()`;
177
+ and `sms.billing.listResources()`. These four lists are cursor-paginated
178
+ (no `listAll`). A test text goes only to the simulator or a
179
+ verified test number, and is billed like any text. The reads need `sms:read`
180
+ (`usage` needs `templates:read`); the test send needs `sms:send`; the
181
+ program writes and removing a test number need `sms:manage` (FULL keys have
182
+ it, SENDING keys don't). Ordering numbers, sender
183
+ registrations and payments stay in the dashboard.
184
+ - Brand Kit writes and imports on `brandKits`:
185
+ `brandKits.create({ name, make_default })`, `brandKits.update(id, body)`,
186
+ `brandKits.delete(id)`, `brandKits.reset(id)`, `brandKits.setDefault(id)`
187
+ and `brandKits.addGraphic(id, { url, role, label })`;
188
+ `brandKits.import({ url | text, website_url, brand_kit_id, review, sync_visual })`,
189
+ `brandKits.getImport(id)`,
190
+ `brandKits.acceptImport(id, { brand_kit_id, name, sync_visual })` (the body
191
+ is optional) and `brandKits.cancelImport(id)`. An import builds a profile
192
+ from a website (`url`) or the brand's own words (`text`) in the background
193
+ (`202`; follow it with `getImport`). By default it is applied when it lands;
194
+ with `review: true` it stops at a proposal for `acceptImport`. Deleting the
195
+ last profile is a `409` (reset it instead). `addGraphic` brings an image
196
+ from a public https URL into the image library and pins it. The writes, and
197
+ starting, accepting or canceling an import, need the `branding:write`
198
+ capability, which no key preset grants: tick it on the key. The reads stay
199
+ `templates:read`.
200
+ - Three new resources. Image library:
201
+ `libraryImages.list({ limit, after, before })`, `libraryImages.listAll()`,
202
+ `libraryImages.create({ url | data, content_type, filename, alt }, { idempotencyKey })`,
203
+ `libraryImages.get(id)`, `libraryImages.update(id, { alt })` and
204
+ `libraryImages.delete(id, { force })`. Branding: `branding.get()`,
205
+ `branding.update(body)`,
206
+ `branding.setLogo({ url | data, content_type, filename })` and
207
+ `branding.removeLogo()`. Workspace:
208
+ `workspace.update({ name })`, `workspace.setImage(body)` and
209
+ `workspace.removeImage()`. The library holds the images a template embeds:
210
+ an image's `path` (`/img/…`) goes in a template's `<Image src>`. `create`
211
+ uploads from a public https `url` or base64 `data` (PNG, JPEG, GIF or
212
+ WebP, up to 5 MB) and takes an idempotency key, minted when you don't pass
213
+ one, so a retried upload stores one image. Deleting an image that a
214
+ template, a campaign or sent mail uses is a `409` `resource_in_use` unless
215
+ you pass `{ force: true }` (sent as `?force=true`). `branding` is the look
216
+ of marketing emails' footer and the hosted unsubscribe page, as Settings →
217
+ Brand shows it (`null` restores a default). `workspace` renames the
218
+ workspace and sets its image. `removeLogo` and `removeImage` answer the
219
+ updated object. The branding writes and every `workspace` call need the
220
+ `branding:write` capability, which no key preset grants: tick it on the key.
221
+ - Jobs: `jobs.list({ status, kind, limit, after, before })`,
222
+ `jobs.cancel(id)`, `jobs.retry(id)` and `jobs.download(id)`. Contacts:
223
+ `contacts.export({ q, status, phone, segment_id, segment_subscription })`.
224
+ Segments: `segments.preview(id)`, `segments.previewFilter({ filter })`,
225
+ `segments.allContacts()` and
226
+ `segments.updateMember(id, contact, { subscribed })`.
227
+ `export` starts a background job that writes a CSV of every contact, or
228
+ of the ones the filters match (one export at a time: another while it runs
229
+ is a `409`); follow it with `jobs.get`, then `jobs.download` gives a signed URL to
230
+ the file that expires in 5 minutes. `jobs.list` lists your background jobs;
231
+ `cancel` stops a queued or running one, and `retry` resumes a `FAILED`
232
+ one from where it stopped. `preview` and `previewFilter`
233
+ count who a saved segment or an unsaved filter reaches and how many of them
234
+ a campaign would mail; nothing is saved. `allContacts` returns the
235
+ managed "All subscribed contacts" segment, made the first time you ask.
236
+ `updateMember` opts a member out of a static segment's sends, or back
237
+ in, without removing it. None of these takes an idempotency key.
238
+ - Webhooks: `webhooks.replayDelivery(id, deliveryId)` and
239
+ `webhooks.flush(id, { include_failed })`. Email:
240
+ `email.retry(id, { idempotencyKey })` and
241
+ `email.listBatches({ limit, after, before })`. Domains: sender addresses
242
+ with `email.domains.listSenders({ domain_id, limit, after, before })`,
243
+ `createSender({ address, display_name })`, `getSender(id)`,
244
+ `updateSender(id, { display_name })` and `deleteSender(id)`.
245
+ `replayDelivery` delivers one event again with the same event id, and `flush`
246
+ delivers the deliveries held while a webhook was suspended (with
247
+ `include_failed`, also the ones that failed for good); both need the
248
+ webhook enabled (`409` otherwise). `retry` sends a failed email again on
249
+ the same id (an email that can't be retried is a `409` saying why); it
250
+ sends real email, so it takes an idempotency key and generates one when you
251
+ don't pass it. `listBatches` lists your batch sends with the same
252
+ rollup as `getBatch`. A
253
+ sender is a saved From address on one of your domains; saving a mailbox
254
+ that is already saved there is a `409`.
255
+ - Email templates:
256
+ `email.templates.duplicate(id, { name }, { idempotencyKey })`,
257
+ `email.templates.fromLibrary({ slug, name }, { idempotencyKey })`,
258
+ `email.templates.usage(id)`,
259
+ `email.templates.listVersions(id, { limit, after })` and
260
+ `email.templates.restoreVersion(id, version)`.
261
+ `duplicate` copies a template into a new draft, and `fromLibrary` adds a
262
+ gallery email as a draft Design template (the ones marked for paid plans are
263
+ `403 limit_reached` on the free plan); both take an idempotency key and
264
+ generate one when you don't pass it. `usage` says what uses a template and
265
+ whether an edit would be accepted now. `listVersions` pages by version
266
+ number: pass the last row's `version` as `after`. `restoreVersion` puts a
267
+ version back and is refused with `409` while a live campaign renders the
268
+ template.
269
+ - Inbox conversations: a new `email.threads` resource with
270
+ `list({ q, limit, after })`, `get(id)`, `delete(id)` and
271
+ `reply(id, body, { idempotencyKey })`. A conversation is a received message
272
+ plus the replies and forwards sent from it, as Emails → Received shows them.
273
+ `list` pages with `next_cursor` (pass it as `after`; it is not a row id);
274
+ `delete` erases the received messages for good. `reply` replies, replies all or forwards one received
275
+ message and sends real email, so it takes an idempotency key and generates
276
+ one when you don't pass it.
277
+ - Email campaigns: `email.campaigns.stats(id)`,
278
+ `email.campaigns.listStats(ids)`,
279
+ `email.campaigns.listRecipients(id, { status, limit, after })`,
280
+ `email.campaigns.listAffected(id)`, `email.campaigns.removeAffected(id)` and
281
+ `email.campaigns.requestReview(id)`. SMS campaigns:
282
+ `sms.campaigns.listRecipients(id, { limit, after, before, q })`. `stats`
283
+ reads a campaign's results: delivered, unique opens and clicks,
284
+ unsubscribes, bounces, complaints and their rates. `listStats` reads them
285
+ for up to 100 campaigns at once. On an email campaign, `listRecipients`
286
+ lists who a send now would reach and why any other member would be left out;
287
+ pass the page's `next_cursor` as `after` for the next page. After an
288
+ automatic quality pause, `listAffected` lists the hard-bounced and
289
+ complained addresses, `removeAffected` takes them out of the campaign's
290
+ static segment, and `requestReview` asks for the review a repeat pause needs
291
+ before `resume`. Both are safe to repeat: a second call removes no one and
292
+ notifies no one. On an SMS campaign, `listRecipients` lists how each
293
+ recipient fared, with `skipped_by_reason` counts for the whole campaign.
294
+ - Contacts: `contacts.addresses(idOrEmail)`,
295
+ `contacts.activity(idOrEmail, { limit })`,
296
+ `contacts.listSegments(idOrEmail)` and `contacts.retryImport(id)`. SMS:
297
+ `sms.requestSmsOptIn(contactId, { phone }, { idempotencyKey })`.
298
+ `requestSmsOptIn` texts the contact a request to reply
299
+ YES to confirm marketing texts. It sends a real text, so it sends the
300
+ idempotency key you pass, or one it makes up, and a retry returns the same
301
+ text instead of sending another.
302
+ - Contacts carry `phone`, their SMS number in E.164, on create, update and
303
+ read. `null` on update removes the number only with the `Unitpost-Strict: true` header; without it the number is kept and the response warns. Setting it records no SMS
304
+ consent: record that with `sms.recordSmsConsent`.
305
+ - `contacts.list` / `contacts.listAll` take `q`, `status` (`subscribed` |
306
+ `unsubscribed`), `phone` (`has` | `none`), `segment_id` and
307
+ `segment_subscription` (`subscribed` | `opted_out`); `email.list` /
308
+ `email.listAll` take `to` and `contact_id`.
309
+ - Email and SMS campaigns: `unschedule(id)` and `duplicate(id, { name }, { idempotencyKey })`. Unschedule moves a scheduled campaign
310
+ back to a draft; duplicate copies a campaign into a new draft. Duplicate
311
+ sends the idempotency key you pass, or one it makes up, so a retry returns
312
+ the same copy instead of making a second one.
313
+ - The campaign update model takes `name`, `subject`, `from`, `preview_text`,
314
+ `template_id` and `segment_id`: the API now edits these on a draft.
315
+ - The email campaign and segment lists take the optional `archived` query
316
+ parameter (`archived=true` lists archived rows).
317
+ - The API now answers `422` for a misnamed send time (`send_at`,
318
+ `scheduledAt` on SMS, …) on sends and campaign writes, instead of sending at
319
+ once or dropping it. Use `scheduled_at`.
320
+ - Campaign create's `403` now says which refusal it is: `limit_reached` for
321
+ the plan's contact limit, `domain_not_found` / `domain_blocked` /
322
+ `domain_not_verified` for the sender (it was always `domain_not_verified`).
323
+ Read `error.code` to tell them apart.
324
+ - Domains: the update model takes `capabilities` (`{ receiving: "enabled" |
325
+ "disabled" }` turns receiving on or off), and domain reads carry
326
+ `capabilities` and a `receiving` object (status, the MX record to publish,
327
+ the last checks).
328
+
329
+ ## 0.4.0
330
+
331
+ The release this changelog starts from. Earlier changes are in the git history
332
+ (tags `sdk-node-v*`).
package/README.md CHANGED
@@ -36,6 +36,15 @@ Every method returns `{ data, error }` — an API-level failure populates `error
36
36
  (a typed `UnitpostError`) instead of throwing, so you never need a `try/catch`
37
37
  around a normal request.
38
38
 
39
+ A success can also carry `warning`: the API's note about something it left out
40
+ or ignored without failing the call, such as a recipient on a reserved domain
41
+ (example.com) that wasn't sent to. Log it or show it:
42
+
43
+ ```ts
44
+ const { data, error, warning } = await unitpost.email.send({ ... });
45
+ if (warning) console.warn(warning);
46
+ ```
47
+
39
48
  ## Authentication
40
49
 
41
50
  Pass the key directly, or set `UNITPOST_API_KEY` and construct with no argument:
@@ -47,24 +56,75 @@ const unitpost = new Unitpost(); // reads process.env.UNITPOST_API_KEY
47
56
  Create a key at [unitpost.com → Settings → API keys](https://www.unitpost.com).
48
57
  Options: `new Unitpost({ apiKey, baseUrl, timeout, fetch, headers, maxRetries, retryBaseDelay, maxRetryDelay })`.
49
58
 
59
+ ## Organization keys
60
+
61
+ A platform that gives each of its customers a workspace uses an organization
62
+ key (`ok_live_…`) with the second client, `UnitpostOrganization`. It takes the
63
+ key and the organization's id (`org_…`), and reads `UNITPOST_ORG_KEY` and
64
+ `UNITPOST_ORGANIZATION_ID` when you leave them out:
65
+
66
+ ```ts
67
+ import { Unitpost, UnitpostOrganization } from "unitpost";
68
+
69
+ const org = new UnitpostOrganization({
70
+ apiKey: process.env.UNITPOST_ORG_KEY,
71
+ organizationId: process.env.UNITPOST_ORGANIZATION_ID,
72
+ });
73
+
74
+ const { data: workspace } = await org.workspaces.create({ name: "Acme Bakery", external_id: "cust_42" });
75
+ const { data: minted } = await org.workspaceKeys.create(workspace!.id, { name: "Production", scope: "sending" });
76
+
77
+ // Work inside that workspace with its own key.
78
+ const acme = new Unitpost(minted!.key);
79
+ ```
80
+
81
+ | Accessor | Covers |
82
+ | --- | --- |
83
+ | `workspaces` | `list()` (`external_id` filter), `listAll()`, `create()` (takes an idempotency key), `get()`, `update()`, `close()`, `restore()` |
84
+ | `workspaceKeys` | `create(workspaceId, body)`: mint a workspace key; the secret is in that answer only |
85
+ | `webhooks` | The organization's endpoints (events from every workspace, each with `workspace_id` and `external_id`): `list()`, `listAll()`, `create()`, `get()`, `update()`, `delete()`, `rotateSecret()`, `test()`, `listDeliveries()` (needs `organizations:write`), `listAllDeliveries()`, `replayDelivery()`, `flush()`, `verify()` |
86
+ | `usage` | `list({ period })`, `listAll()`: usage per workspace for its billing period |
87
+ | `planQuotes` | Change a workspace's plan: `create()` prices it, `get()`, `confirm()` applies and charges it (takes an idempotency key) |
88
+ | `sharedPlan` | The organization's shared plan: `get()`, `listWorkspaces()`, `addWorkspace()`, `updateWorkspace()` (its cap), `removeWorkspace()` (adding and removing take an idempotency key) |
89
+
90
+ Each client takes one kind of key: the organization client only calls
91
+ `/organizations/{id}/…` routes, and the API answers `401` to an organization
92
+ key on any other route. An Owner or Admin makes the key in the dashboard under
93
+ Organization → API.
94
+
50
95
  ## Client surface
51
96
 
52
97
  | Accessor | Covers |
53
98
  | --- | --- |
54
- | `email` | Send, batch, list, get, update, stats, inbound (`received*`) |
99
+ | `email` | Send, batch, list, get, update, stats, one email's delivery events (`listEvents()`), inbound (`received*`; the original `.eml` with `receivedRaw()`), retry a failed email (`retry()`, takes an idempotency key), batches (`listBatches()`, `getBatch()`, `cancelBatch()`) |
55
100
  | `email.topics` | Topics + contact topic prefs |
56
- | `email.campaigns` | Draft, schedule, send, pause/resume |
57
- | `email.templates` | Template CRUD |
58
- | `email.domains` | Domains + verify |
59
- | `sms` | Send, get, list, `brands()`, `numbers()`, contact SMS consent. Available on paid plans: on the free plan `send` returns a `403` with code `limit_reached`, while the reads keep working. |
60
- | `contacts` | CRUD, import jobs |
101
+ | `email.campaigns` | Draft, schedule, send, pause/resume, results (`stats()`, `listStats()`), who a send would reach (`listRecipients()`), quality-pause recovery (`listAffected()`, `removeAffected()`, `requestReview()`) |
102
+ | `email.templates` | Template CRUD, `duplicate()`, add from the gallery (`fromLibrary()`), what uses it (`usage()`), history (`listVersions()`, `restoreVersion()`), render it without sending (`render()`, which lists `missing_variables`) |
103
+ | `email.domains` | Domains + verify, `diagnose()`, saved From addresses (`listSenders()`, `createSender()`, `getSender()`, `updateSender()`, `deleteSender()`) |
104
+ | `email.threads` | Inbox conversations: `list()` (`q`; page with `next_cursor`), `get()`, `delete()`, `reply()` (reply, reply all or forward; takes an idempotency key) |
105
+ | `sms` | Send, get, list, make the sender of a received text a contact (`addContact()`, which needs `contacts:write`), `brands()`, a brand (`createBrand()`, which takes an idempotency key, `getBrand()`, `updateBrand()`; the writes need `sms:manage`), `numbers()`, one number (`getNumber()`), a toll-free verification carriers sent back (`resubmitNumber()`, takes an idempotency key), release a number (`releaseNumber()`, PERMANENT: its fee ends and it can't be had back; `{ force: true }` releases it although campaigns are scheduled on it or texts are queued through it; takes an idempotency key and needs `sms:manage`), a number's text-to-join keywords (`listJoinKeywords()`, `addJoinKeyword()`, `removeJoinKeyword()`; the writes need `sms:manage`), a brand's documents (`listBrandDocuments()`, `addBrandDocument()` with a `file_id` or `text` (takes an idempotency key), `getBrandDocument()`, `removeBrandDocument()`, `brandDocumentUrl()`, a 5-minute signed link), contact SMS consent, `requestSmsOptIn()` (reply-YES confirmation). Available on paid plans: on the free plan `send` returns a `403` with code `limit_reached`, while the reads keep working. |
106
+ | `sms.templates` | Template CRUD, what uses it (`usage()`), one test text to a simulator number or a verified number from `sms.testDestinations` (`testSend()`, billed like any text; takes an idempotency key) |
107
+ | `sms.messagingPrograms` | What a sender registration says your texts are for: `list()` (`{ archived: true }` includes archived ones), `create()` and `duplicate()` (each takes an idempotency key), `get()`, `update()`, `delete()` (archives). The writes need `sms:manage` |
108
+ | `sms.testDestinations` | Verified test numbers: `list()`, `delete()` (needs `sms:manage`). Adding and verifying one stays in the dashboard |
109
+ | `sms.consentSetups` | Where and how people opt in to your texts: `list()` |
110
+ | `sms.billing` | Recurring SMS charges: `listResources()` |
111
+ | `sms.registrations` | Carrier registrations and their review state: `list()`, `get()`, a 10DLC campaign carriers sent back (`resubmit()`), a failed number whose fee is committed (`requestNumber()`), take down a 10DLC setup with no number (`remove()`), archive an approved brand registration to register it again (`replace()`); the writes take an idempotency key and need `sms:manage` |
112
+ | `sms.quotes` | Buy carrier resources (register a 10DLC brand, vet it, register a campaign, order a number): `create()` prices the order and returns a single-use `confirm_token`; `confirm()` places it (takes an idempotency key; one is generated when you don't pass one). The confirm needs `sms:purchase`, which no key preset includes, and the owner's monthly cap for SMS purchases by API. Show the person the price first. Release a number with `sms.releaseNumber()` |
113
+ | `contacts` | CRUD, list filters, import jobs (start, cancel, retry), addresses, recent activity, the segments it is in (`listSegments()`; add or remove it with `segments.addMember()` / `segments.removeMember()`), export to CSV (`export()`, a background job) |
61
114
  | `contactFields` | Custom field definitions |
62
- | `segments` | Segments + membership |
63
- | `brandKits` | Brand kit |
64
- | `webhooks` | Endpoints + `verify()` |
65
- | `apiKeys` | API key management |
115
+ | `segments` | Segments + membership, opt a member in or out (`updateMember()`), who it reaches (`preview()`, and `previewFilter()` for an unsaved filter), the managed all-contacts segment (`allContacts()`) |
116
+ | `brandKits` | Brand Kit profiles: `list()`, `get()`, `create()`, `update()`, `delete()`, `reset()`, `setDefault()`, `addGraphic()`, and imports from a website or the brand's own words (`import()`, `getImport()`, `acceptImport()`, `cancelImport()`). The writes and starting, accepting or canceling an import need the `branding:write` capability, which no key preset grants |
117
+ | `libraryImages` | The image library templates embed (`/img/…` paths): `list()`, `listAll()`, `create()` (takes an idempotency key), `get()`, `update()`, `delete()` (`{ force: true }` deletes an image in use) |
118
+ | `files` | Files handed to the API for one purpose and used by `file_id` (a brand document, SMS opt-in evidence, an image): `list()` (`purpose` filters), `create()` (a `url`, base64 `data`, or an upload session; takes an idempotency key), `get()`, `delete()`, and `upload({ path or data, purpose, contentType })`, which sends up to 3 MB inline and a larger file through an upload session. A file expires 24 hours after it is created |
119
+ | `branding` | The email footer and unsubscribe page look: `get()`, `update()`, `setLogo()`, `removeLogo()`. The writes need the `branding:write` capability, which no key preset grants |
120
+ | `workspace` | Who is calling and what it may do (`whoami()`, any credential), the activity log (`listActivity()`, `listAllActivity()`; needs `activity:read`), and the workspace's name and image: `update()`, `setImage()`, `removeImage()`. Those three need `branding:write`. No key preset grants either capability |
121
+ | `webhooks` | Endpoints + `verify()`, the delivery log (`listDeliveries()`), replay one delivery (`replayDelivery()`), deliver the backlog (`flush()`) |
122
+ | `apiKeys` | `list()` and a key's last 24 hours (`usage()`), which need `apikeys:read` (on no key preset); `create()` and `delete()` need a dashboard session |
123
+ | `logs` | The API request log, newest first: `list()` (each call's method, path, status, duration, key and request id; never the IP or a body; kept 30 days). Filters: `status`, `api_key_id`, `method`, `path_prefix`, `request_id`, `created_after` / `created_before`. Needs `apikeys:read` (on no key preset) |
66
124
  | `suppressions` | Suppression list |
125
+ | `jobs` | Background jobs: `list()`, `get()`, `cancel()`, `retry()`, a finished job's file (`download()`) |
67
126
  | `usage` | Billing-period usage snapshot |
127
+ | `spendCaps` | `get()`, `update()`: the monthly spend cap on SMS purchases made with a key or an app and what it counted this month; `update()` needs `spend_caps:write`, which no key preset grants |
68
128
 
69
129
  ## Pagination
70
130
 
@@ -113,7 +173,7 @@ const event = verifyWebhook({
113
173
  });
114
174
  ```
115
175
 
116
- You can also call it from the client (Resend-style alias):
176
+ You can also call it from the client:
117
177
 
118
178
  ```ts
119
179
  const event = unitpost.webhooks.verify({ payload: rawBody, secret, headers: req.headers });