samva 0.10.0 → 0.12.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.
Files changed (71) hide show
  1. package/README.md +59 -9
  2. package/dist/client/sdk.gen.d.ts +1126 -219
  3. package/dist/client/types.gen.d.ts +11655 -6311
  4. package/dist/{client-mI4S99Ts.js → client-Cj1bqIEe.js} +5169 -1639
  5. package/dist/{client-attribution-Bl4nTEsE.js → client-attribution-BTWYSXxo.js} +2 -2
  6. package/dist/effect/analytics.d.ts +18 -18
  7. package/dist/effect/analytics.js +1 -1
  8. package/dist/effect/api-keys.d.ts +99 -43
  9. package/dist/effect/api-keys.js +2 -4
  10. package/dist/effect/attachments.d.ts +5 -6
  11. package/dist/effect/attachments.js +1 -1
  12. package/dist/effect/brands.d.ts +4 -4
  13. package/dist/effect/brands.js +2 -2
  14. package/dist/effect/campaigns.d.ts +30 -60
  15. package/dist/effect/campaigns.js +1 -1
  16. package/dist/effect/client.js +1 -1
  17. package/dist/effect/contact-groups.d.ts +29 -46
  18. package/dist/effect/contact-groups.js +1 -1
  19. package/dist/effect/contacts.d.ts +324 -726
  20. package/dist/effect/contacts.js +10 -2
  21. package/dist/effect/conversations.d.ts +575 -1130
  22. package/dist/effect/conversations.js +14 -2
  23. package/dist/effect/custom-fields.d.ts +3 -53
  24. package/dist/effect/custom-fields.js +1 -1
  25. package/dist/effect/email.d.ts +349 -298
  26. package/dist/effect/email.js +9 -3
  27. package/dist/effect/extension-installations.d.ts +218 -0
  28. package/dist/effect/extension-installations.js +25 -0
  29. package/dist/effect/extensions.d.ts +192 -0
  30. package/dist/effect/extensions.js +19 -0
  31. package/dist/effect/feedback.d.ts +12 -0
  32. package/dist/effect/feedback.js +13 -0
  33. package/dist/effect/generated.d.ts +33011 -15519
  34. package/dist/effect/index.d.ts +6 -1
  35. package/dist/effect/index.js +7 -2
  36. package/dist/effect/internal/client.d.ts +3 -0
  37. package/dist/effect/internal/mailbox-events.d.ts +11 -0
  38. package/dist/effect/internal/operation.d.ts +20 -374
  39. package/dist/effect/mailboxes.d.ts +1676 -0
  40. package/dist/effect/mailboxes.js +3 -0
  41. package/dist/effect/media.d.ts +5 -5
  42. package/dist/effect/media.js +1 -1
  43. package/dist/effect/messages.d.ts +171 -938
  44. package/dist/effect/messages.js +6 -2
  45. package/dist/effect/namespaces.d.ts +82 -0
  46. package/dist/effect/namespaces.js +19 -0
  47. package/dist/effect/operations.d.ts +68 -12
  48. package/dist/effect/operations.js +1 -1
  49. package/dist/effect/organizations.d.ts +5 -4
  50. package/dist/effect/organizations.js +1 -1
  51. package/dist/effect/pagination.d.ts +16 -21
  52. package/dist/effect/scheduled-messages.d.ts +13 -23
  53. package/dist/effect/scheduled-messages.js +1 -1
  54. package/dist/effect/templates.d.ts +204 -281
  55. package/dist/effect/templates.js +2 -2
  56. package/dist/effect/unsubscribe-groups.d.ts +21 -75
  57. package/dist/effect/unsubscribe-groups.js +1 -1
  58. package/dist/effect/webhooks.d.ts +117 -39
  59. package/dist/effect/webhooks.js +2 -2
  60. package/dist/index.js +3 -2
  61. package/dist/mailbox-events-CsbF35vH.js +629 -0
  62. package/dist/mailbox-events.d.ts +178 -0
  63. package/dist/mailboxes-BtcktcNB.js +147 -0
  64. package/dist/{operation-DQWJO4jY.js → operation-BEghYyLu.js} +411 -67
  65. package/dist/promises/errors.gen.d.ts +5 -0
  66. package/dist/promises/index.d.ts +23 -1
  67. package/dist/promises/index.js +3 -2
  68. package/dist/promises/types.gen.d.ts +1 -1
  69. package/dist/{promises-C7D4oaHn.js → promises-BzrwhHEW.js} +3273 -547
  70. package/dist/service-map.d.ts +468 -36
  71. package/package.json +22 -2
package/README.md CHANGED
@@ -54,10 +54,8 @@ const message = await client.messages.send({
54
54
  },
55
55
  });
56
56
 
57
- const messages = await client.messages.list({
58
- page: "1",
59
- limit: "20",
60
- });
57
+ const messages = await client.messages.list({ limit: "20" });
58
+ // Pass `messages.nextCursor` back as `cursor` for the next page; it is null on the last page.
61
59
  ```
62
60
 
63
61
  ## Effect Quick Start
@@ -118,6 +116,26 @@ The Promise and Effect clients identify their public SDK surface and package ver
118
116
  advisory `x-samva-client` request header. Supply your own value in `headers`, or set the header to
119
117
  `null` in Promise request options or `undefined` in Effect client configuration to omit it.
120
118
 
119
+ ## Send a Published Template
120
+
121
+ Author a template as TSX with `samva templates init`, then publish an exact commit with
122
+ `samva templates publish --commit HEAD` (see [`@samva/cli`](https://www.npmjs.com/package/@samva/cli)).
123
+ A published template is addressed by its slug, which is the `id` in its `defineTemplate`:
124
+
125
+ ```typescript
126
+ await client.messages.send({
127
+ to: [{ email: "ada@example.com" }],
128
+ channel: "email",
129
+ email: {
130
+ templateSlug: "order-shipped",
131
+ templateData: { name: "Ada", orderId: "A-1042" },
132
+ },
133
+ });
134
+ ```
135
+
136
+ A template send omits `subject`, `html`, and `text`; the request fails if `templateData` does not
137
+ match the template's input schema. `samva templates types` generates TypeScript types for that input.
138
+
121
139
  ## Service Surface
122
140
 
123
141
  The Promise client exposes:
@@ -132,8 +150,13 @@ The Promise client exposes:
132
150
  - `conversations`
133
151
  - `customFields`
134
152
  - `email`
153
+ - `extensionInstallations`
154
+ - `extensions`
155
+ - `feedback`
156
+ - `mailboxes`
135
157
  - `media`
136
158
  - `messages`
159
+ - `namespaces`
137
160
  - `operations`
138
161
  - `organizations`
139
162
  - `scheduledMessages`
@@ -153,8 +176,13 @@ The Effect SDK exposes Pascal-cased domain modules with lower-camel operations:
153
176
  - `Conversations`
154
177
  - `CustomFields`
155
178
  - `Email`
179
+ - `ExtensionInstallations`
180
+ - `Extensions`
181
+ - `Feedback`
182
+ - `Mailboxes`
156
183
  - `Media`
157
184
  - `Messages`
185
+ - `Namespaces`
158
186
  - `Operations`
159
187
  - `Organizations`
160
188
  - `ScheduledMessages`
@@ -205,7 +233,7 @@ Reusing a key with identical content replays the original response; reusing it w
205
233
 
206
234
  ### Stream pagination
207
235
 
208
- Every list operation that returns the uniform `{ items, pagination: { page, limit, total, totalPages } }` envelope carries two `Stream` companions, so you traverse pages without hand-rolling a `page` loop:
236
+ Every list answers `{ items, nextCursor }`: pass `nextCursor` back as `cursor` for the next page, and stop when it is null. Every list operation that pages carries two `Stream` companions, so you traverse pages without hand-rolling a cursor loop:
209
237
 
210
238
  - **`list.items(input?)`** — a `Stream` of individual items across all pages.
211
239
  - **`list.pages(input?)`** — a `Stream` of raw page envelopes.
@@ -220,11 +248,11 @@ const allContacts = Stream.runCollect(Contacts.list.items());
220
248
  // Bounded consumption is lazy — this fetches only as many pages as it needs:
221
249
  const firstFifty = Stream.runCollect(Contacts.list.items().pipe(Stream.take(50)));
222
250
 
223
- // Caller params (start page, limit, filters) are respected:
224
- const activeFrom2 = Contacts.list.items({ page: "2", limit: "100", status: "active" });
251
+ // Caller params (start cursor, limit, filters) are respected:
252
+ const recent = Contacts.list.items({ limit: "100", after: "2026-01-01T00:00:00Z" });
225
253
  ```
226
254
 
227
- The companions are attached uniformly to every paginated list, including `Messages.list`, `Contacts.list`, `Campaigns.list`, `Email.listDomains`, and `Webhooks.list`. Each page fetch reuses the ambient `Retry` policy. Reads retry per page; pagination does not nest retries. Page and limit inputs retain their OpenAPI wire-string representation. The Promise client is unchanged; stream pagination is Effect-only.
255
+ The companions are attached uniformly to every paginated list, including `Messages.list`, `Contacts.list`, `Campaigns.list`, `Email.listDomains`, and `Webhooks.list`. Each page fetch reuses the ambient `Retry` policy. Reads retry per page; pagination does not nest retries. The `limit` input retains its OpenAPI wire-string representation. A list bounded by design, such as `CustomFields.list`, answers `{ items }` in one response and carries no companions. The Promise client is unchanged; stream pagination is Effect-only.
228
256
 
229
257
  ### Redacted secrets
230
258
 
@@ -298,7 +326,6 @@ const message =
298
326
 
299
327
  ```typescript
300
328
  const response = await client.conversations.list({
301
- page: "1",
302
329
  limit: "20",
303
330
  status: "active",
304
331
  });
@@ -344,6 +371,29 @@ const recipients = await client.campaigns.listRecipients({
344
371
  });
345
372
  ```
346
373
 
374
+ ### Read Mailbox Events
375
+
376
+ `mailboxes.events` reads the `mailbox.*` events over a WebSocket, for a program without a public
377
+ URL for webhooks. Asking for the next event marks the previous one handled; the stream reconnects
378
+ after transient closes from the last event it holds and throws `MailboxEventStreamError` when the
379
+ caller has to act. Its `_tag` is the API error tag the host refused with (`UnauthorizedError`,
380
+ `ForbiddenError`, `ResourceNotFoundError`, `CursorExpiredError`, `ValidationError`, and the
381
+ rest), with the host's `message`, `status`, `fields`, and `retryAfterSeconds`. A `429`, `5xx`, or
382
+ `408` refusal is retried after the delay the host asked for; every other refusal ends the stream.
383
+ It needs a runtime whose `WebSocket` accepts request headers, such as Node or Bun, or one passed
384
+ as the `WebSocket` option.
385
+
386
+ ```typescript
387
+ const events = client.mailboxes.events({ cursor: savedCursor, mailboxIds: ["mbx_..."] });
388
+ for await (const event of events) {
389
+ await handle(event.type, event.data);
390
+ await saveCursor(event.cursor);
391
+ }
392
+ ```
393
+
394
+ With Effect, `Mailboxes.events(options)` is a `Stream` of the same events that fails with a
395
+ `MailboxEventStreamFailure`, so `Effect.catchTag("CursorExpiredError", ...)` handles one cause.
396
+
347
397
  ### Custom Headers
348
398
 
349
399
  ```typescript