samva 0.29.0 → 0.30.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 (185) hide show
  1. package/AGENTS.md +23 -5
  2. package/README.md +166 -133
  3. package/dist/_virtual/_rolldown/runtime.js +1 -2
  4. package/dist/client/client/client.gen.js +1 -2
  5. package/dist/client/client/utils.gen.js +1 -2
  6. package/dist/client/client.gen.js +1 -2
  7. package/dist/client/core/auth.gen.js +1 -2
  8. package/dist/client/core/bodySerializer.gen.js +1 -2
  9. package/dist/client/core/params.gen.js +1 -2
  10. package/dist/client/core/pathSerializer.gen.js +1 -2
  11. package/dist/client/core/serverSentEvents.gen.js +1 -2
  12. package/dist/client/core/utils.gen.js +1 -2
  13. package/dist/client/sdk.gen.d.ts +216 -191
  14. package/dist/client/sdk.gen.js +2392 -1153
  15. package/dist/client/types.gen.d.ts +766 -376
  16. package/dist/client-attribution.js +1 -2
  17. package/dist/effect/agents.d.ts +33 -11
  18. package/dist/effect/agents.js +1 -2
  19. package/dist/effect/analytics.d.ts +6 -6
  20. package/dist/effect/analytics.js +1 -2
  21. package/dist/effect/api-keys.d.ts +8 -8
  22. package/dist/effect/api-keys.js +1 -2
  23. package/dist/effect/attachments.d.ts +4 -4
  24. package/dist/effect/attachments.js +1 -2
  25. package/dist/effect/brands.d.ts +6 -6
  26. package/dist/effect/brands.js +1 -2
  27. package/dist/effect/campaigns.d.ts +15 -16
  28. package/dist/effect/campaigns.js +1 -2
  29. package/dist/effect/categories.js +1 -2
  30. package/dist/effect/client.js +1 -2
  31. package/dist/effect/contact-groups.d.ts +10 -10
  32. package/dist/effect/contact-groups.js +1 -2
  33. package/dist/effect/contacts.d.ts +23 -24
  34. package/dist/effect/contacts.js +1 -2
  35. package/dist/effect/conversations.d.ts +13 -13
  36. package/dist/effect/conversations.js +1 -2
  37. package/dist/effect/custom-fields.d.ts +4 -4
  38. package/dist/effect/custom-fields.js +1 -2
  39. package/dist/effect/email.d.ts +61 -63
  40. package/dist/effect/email.js +1 -2
  41. package/dist/effect/events.d.ts +2 -4
  42. package/dist/effect/events.js +1 -2
  43. package/dist/effect/extension-installations.d.ts +9 -9
  44. package/dist/effect/extension-installations.js +1 -2
  45. package/dist/effect/extensions.d.ts +5 -5
  46. package/dist/effect/extensions.js +1 -2
  47. package/dist/effect/feedback.d.ts +1 -1
  48. package/dist/effect/feedback.js +1 -2
  49. package/dist/effect/generated/agents.d.ts +264 -22
  50. package/dist/effect/generated/agents.js +2 -3
  51. package/dist/effect/generated/analytics.js +1 -2
  52. package/dist/effect/generated/api-keys.js +1 -2
  53. package/dist/effect/generated/attachments.js +1 -2
  54. package/dist/effect/generated/brands.js +1 -2
  55. package/dist/effect/generated/campaigns.d.ts +160 -155
  56. package/dist/effect/generated/campaigns.js +7 -9
  57. package/dist/effect/generated/contact-events.js +1 -2
  58. package/dist/effect/generated/contact-groups.d.ts +26 -26
  59. package/dist/effect/generated/contact-groups.js +22 -19
  60. package/dist/effect/generated/contacts.d.ts +119 -90
  61. package/dist/effect/generated/contacts.js +32 -32
  62. package/dist/effect/generated/conversations.d.ts +22 -22
  63. package/dist/effect/generated/conversations.js +7 -8
  64. package/dist/effect/generated/custom-fields.d.ts +6 -6
  65. package/dist/effect/generated/custom-fields.js +3 -4
  66. package/dist/effect/generated/email.d.ts +38 -38
  67. package/dist/effect/generated/email.js +13 -14
  68. package/dist/effect/generated/events.d.ts +18 -9
  69. package/dist/effect/generated/events.js +8 -6
  70. package/dist/effect/generated/extension-installations.d.ts +2 -2
  71. package/dist/effect/generated/extension-installations.js +6 -3
  72. package/dist/effect/generated/extensions.js +1 -2
  73. package/dist/effect/generated/feedback.js +1 -2
  74. package/dist/effect/generated/index.d.ts +7 -5
  75. package/dist/effect/generated/journeys.js +1 -2
  76. package/dist/effect/generated/mailboxes.d.ts +44 -44
  77. package/dist/effect/generated/mailboxes.js +17 -18
  78. package/dist/effect/generated/media.js +1 -2
  79. package/dist/effect/generated/messages.d.ts +42 -42
  80. package/dist/effect/generated/messages.js +3 -4
  81. package/dist/effect/generated/namespaces.js +1 -2
  82. package/dist/effect/generated/{publication-domains.d.ts → newsletter-domains.d.ts} +304 -80
  83. package/dist/effect/generated/newsletter-domains.js +218 -0
  84. package/dist/effect/generated/{topic-issues.d.ts → newsletter-issues.d.ts} +330 -288
  85. package/dist/effect/generated/{topic-issues.js → newsletter-issues.js} +255 -246
  86. package/dist/effect/generated/newsletters.d.ts +741 -0
  87. package/dist/effect/generated/newsletters.js +143 -0
  88. package/dist/effect/generated/operations.js +1 -2
  89. package/dist/effect/generated/organizations.d.ts +9 -9
  90. package/dist/effect/generated/organizations.js +4 -5
  91. package/dist/effect/generated/scheduled-messages.d.ts +174 -169
  92. package/dist/effect/generated/scheduled-messages.js +7 -7
  93. package/dist/effect/generated/shared.d.ts +276 -208
  94. package/dist/effect/generated/shared.js +50 -36
  95. package/dist/effect/generated/subscriptions.js +1 -2
  96. package/dist/effect/generated/templates.d.ts +118 -67
  97. package/dist/effect/generated/templates.js +43 -35
  98. package/dist/effect/generated/topic-forms.d.ts +79 -19
  99. package/dist/effect/generated/topic-forms.js +13 -14
  100. package/dist/effect/generated/topics.d.ts +27 -65
  101. package/dist/effect/generated/topics.js +13 -20
  102. package/dist/effect/generated/webhooks.d.ts +9 -9
  103. package/dist/effect/generated/webhooks.js +4 -5
  104. package/dist/effect/generated/whoami.js +1 -2
  105. package/dist/effect/generated-metadata.d.ts +475 -70
  106. package/dist/effect/generated-metadata.js +642 -432
  107. package/dist/effect/index.d.ts +3 -2
  108. package/dist/effect/index.js +4 -3
  109. package/dist/effect/internal/client.d.ts +5 -0
  110. package/dist/effect/internal/client.js +9 -5
  111. package/dist/effect/internal/email-sender.d.ts +1 -1
  112. package/dist/effect/internal/email-sender.js +4 -3
  113. package/dist/effect/internal/mailbox-events.js +1 -2
  114. package/dist/effect/internal/operation.d.ts +4 -15
  115. package/dist/effect/internal/operation.js +21 -33
  116. package/dist/effect/internal/send.js +2 -3
  117. package/dist/effect/journeys.d.ts +14 -14
  118. package/dist/effect/journeys.js +1 -2
  119. package/dist/effect/mailboxes.d.ts +60 -70
  120. package/dist/effect/mailboxes.js +1 -2
  121. package/dist/effect/media.d.ts +5 -5
  122. package/dist/effect/media.js +1 -2
  123. package/dist/effect/messages.d.ts +9 -9
  124. package/dist/effect/messages.js +1 -2
  125. package/dist/effect/namespaces.d.ts +8 -8
  126. package/dist/effect/namespaces.js +1 -2
  127. package/dist/effect/newsletter-domains.d.ts +71 -0
  128. package/dist/effect/newsletter-domains.js +18 -0
  129. package/dist/effect/{topic-issues.d.ts → newsletter-issues.d.ts} +11 -15
  130. package/dist/effect/newsletter-issues.js +32 -0
  131. package/dist/effect/newsletters.d.ts +22 -0
  132. package/dist/effect/newsletters.js +20 -0
  133. package/dist/effect/operations.d.ts +3 -3
  134. package/dist/effect/operations.js +1 -2
  135. package/dist/effect/organizations.d.ts +8 -10
  136. package/dist/effect/organizations.js +1 -2
  137. package/dist/effect/pagination.js +1 -2
  138. package/dist/effect/retry.d.ts +4 -4
  139. package/dist/effect/retry.js +5 -6
  140. package/dist/effect/runtime.js +1 -2
  141. package/dist/effect/scheduled-messages.d.ts +5 -6
  142. package/dist/effect/scheduled-messages.js +1 -2
  143. package/dist/effect/subscriptions.d.ts +1 -1
  144. package/dist/effect/subscriptions.js +1 -2
  145. package/dist/effect/templates.d.ts +34 -43
  146. package/dist/effect/templates.js +1 -2
  147. package/dist/effect/topic-forms.d.ts +5 -5
  148. package/dist/effect/topic-forms.js +1 -2
  149. package/dist/effect/topics.d.ts +9 -13
  150. package/dist/effect/topics.js +1 -2
  151. package/dist/effect/webhooks.d.ts +11 -11
  152. package/dist/effect/webhooks.js +1 -2
  153. package/dist/effect/whoami.d.ts +1 -1
  154. package/dist/effect/whoami.js +1 -2
  155. package/dist/index.js +2 -2
  156. package/dist/inline-attachments.js +1 -2
  157. package/dist/mailbox/dispatch.d.ts +10 -0
  158. package/dist/mailbox/dispatch.js +66 -0
  159. package/dist/mailbox/index.d.ts +17 -0
  160. package/dist/mailbox/index.js +30 -0
  161. package/dist/mailbox/test.d.ts +25 -0
  162. package/dist/mailbox/test.js +174 -0
  163. package/dist/mailbox/types.d.ts +184 -0
  164. package/dist/mailbox/webhook.d.ts +10 -0
  165. package/dist/mailbox/webhook.js +41 -0
  166. package/dist/mailbox-events.js +1 -2
  167. package/dist/normalize.js +1 -2
  168. package/dist/package.js +2 -3
  169. package/dist/promises/client.d.ts +215 -0
  170. package/dist/promises/client.js +324 -0
  171. package/dist/promises/errors.gen.js +1 -2
  172. package/dist/promises/index.d.ts +2 -196
  173. package/dist/promises/index.js +3 -295
  174. package/dist/promises/request.d.ts +15 -0
  175. package/dist/promises/request.js +75 -0
  176. package/dist/promises/types.gen.d.ts +1 -1
  177. package/dist/request-policy.d.ts +3 -0
  178. package/dist/request-policy.js +16 -0
  179. package/dist/service-map.d.ts +78 -47
  180. package/dist/service-map.js +52 -32
  181. package/package.json +34 -18
  182. package/dist/effect/generated/publication-domains.js +0 -163
  183. package/dist/effect/publication-domains.d.ts +0 -14
  184. package/dist/effect/publication-domains.js +0 -17
  185. package/dist/effect/topic-issues.js +0 -33
package/AGENTS.md CHANGED
@@ -6,8 +6,8 @@ required.
6
6
 
7
7
  Effect applications should import Pascal-cased domain modules from focused subpaths such as
8
8
  `samva/effect/email` and provide `Client.layerFetch` from `samva/effect/client`. Install the optional
9
- peer `effect` at the exact version this package's `peerDependencies` names when using those
10
- entrypoints; a different release candidate is unsupported. Tagged API failures remain in the
9
+ peer `effect` from the `^4.0.4` range this package's `peerDependencies` names when using those
10
+ entrypoints. Prerelease tags fall outside that range. Tagged API failures remain in the
11
11
  Effect error channel and can be handled with `Effect.catchTag`. In Cloudflare Workers and Lambda,
12
12
  import focused entrypoints rather than the `samva/effect` barrel, which loads every domain. In a
13
13
  Worker, provide the client Layer per request with the request's abort signal; in Lambda or another
@@ -38,9 +38,27 @@ does not create a confirmed contact or subscription. Campaigns require `audience
38
38
  email content accepts `topicId`.
39
39
 
40
40
  Newsletter issue authoring is Preview and available only to selected organizations. Use
41
- `client.topicIssues` (Promise) or `TopicIssues` from `samva/effect/topic-issues` (Effect) to read and
42
- edit topic-owned Markdown issues, check and render fixtures, and save a commit. After the first create, mutations carry
41
+ `client.newsletters.issues` (Promise) or `NewsletterIssues` from `samva/effect/newsletter-issues` (Effect) to read and
42
+ edit newsletter-owned Markdown issues, check and render fixtures, and save a commit. After the first create, mutations carry
43
43
  `expectedRevision`; Save also carries `expectedHead`. Keep mutation idempotency keys stable on
44
44
  retries. Campaigns select saved content with `content.issue: { path, commit }` and
45
45
  `audience.topicId`. Web rendering produces a preview, not a published page. See
46
- https://samva.dev/docs/channels/email/issues.
46
+ https://samva.dev/docs/channels/email/newsletters.
47
+
48
+ Every idempotent operation generates one key per logical call and reuses it across built-in
49
+ retries. Override only through the second options argument, `{ idempotencyKey }`. Both clients
50
+ retry reads and contract-marked idempotent mutations. Promise clients accept `maxRetries` at
51
+ client and call level. `contacts.startImport` retries only `mode: "new"`; a resume uses
52
+ a generation fence and must be followed by `getImportJob` after an ambiguous response. Promise cursor lists expose lazy `.pages(params)` and `.items(params)`
53
+ async iterators. `orgSlug` selects an organization when paired with `authToken`.
54
+
55
+ Mailbox extensions import `samva/mailbox`, `samva/mailbox/test`, or `samva/mailbox/webhook`.
56
+ Handlers receive the normal client and use flat calls such as
57
+ `ctx.samva.mailboxes.reply({ id, messageId, text })`. Keep sends in stable order so dispatch
58
+ reuses deterministic event keys.
59
+
60
+ Use `client.newsletters` for newsletter management and `client.newsletters.domains` for custom archive domains. Effect entrypoints are `samva/effect/newsletters`, `samva/effect/newsletter-issues`, and `samva/effect/newsletter-domains`. A newsletter’s `topicId` names its consent and campaign audience.
61
+
62
+ `client.newsletters.domains.list({ id, cursor, limit })` returns a hostname-ordered page with
63
+ `items` and `nextCursor`. Pass the cursor back unchanged. Use `domains.get` to recheck one domain's
64
+ DNS and certificate status.
package/README.md CHANGED
@@ -16,7 +16,7 @@ The root entrypoint is Promise-based:
16
16
  import { createClient } from "samva";
17
17
  ```
18
18
 
19
- The same Promise SDK is also available at `samva/promises`. Native Effect users import domain modules such as `samva/effect/email` and provide `samva/effect/client`. Both clients are generated from Samva's public OpenAPI document, while the Effect runtime does not wrap or execute the Promise client. Effect is an optional peer dependency, so Promise-only applications do not install or load it.
19
+ The same Promise SDK is also available at `samva/promises`. Native Effect users import domain modules such as `samva/effect/email` and provide `samva/effect/client`. Both clients are generated from Samva's public OpenAPI document, while the Effect runtime does not wrap or execute the Promise samva. Effect is an optional peer dependency, so Promise-only applications do not install or load it.
20
20
 
21
21
  ## Installation
22
22
 
@@ -33,31 +33,29 @@ yarn add samva
33
33
  ```typescript
34
34
  import { createClient } from "samva";
35
35
 
36
- const client = createClient({
36
+ const samva = createClient({
37
37
  baseUrl: "https://api.samva.dev",
38
- apiKey: "<samva-api-key>",
38
+ apiKey: process.env.SAMVA_API_KEY!,
39
39
  });
40
40
 
41
- const { contact } = await client.contacts.findOrCreate({
41
+ const { contact } = await samva.contacts.findOrCreate({
42
42
  lookup: { type: "email", value: "ada@example.com" },
43
43
  create: { name: "Ada Lovelace" },
44
44
  });
45
45
 
46
- const message = await client.messages.send({
46
+ const message = await samva.email.send({
47
47
  to: [contact],
48
- channel: "email",
49
- email: {
50
- subject: "Hello",
51
- html: "<p>Hello World</p>",
52
- text: "Hello World",
53
- },
48
+ subject: "Hello",
49
+ html: "<p>Hello World</p>",
50
+ text: "Hello World",
54
51
  metadata: {
55
52
  externalUserId: "user_123",
56
53
  },
57
54
  });
58
55
 
59
- const messages = await client.messages.list({ limit: 20 });
60
- // Pass `messages.nextCursor` back as `cursor` for the next page; it is null on the last page.
56
+ for await (const message of samva.messages.list.items({ limit: 20 })) {
57
+ console.log(message.id);
58
+ }
61
59
  ```
62
60
 
63
61
  Creation fails with `ConflictError` (HTTP 409) when an external ID or address belongs to another
@@ -68,7 +66,7 @@ contact. The error names the conflicting field and the creation is rolled back.
68
66
  Install `effect` next to `samva` when using the Effect entrypoint:
69
67
 
70
68
  ```bash
71
- bun add samva effect@4.0.4
69
+ bun add samva effect@4.0.6
72
70
  ```
73
71
 
74
72
  ```typescript
@@ -80,7 +78,7 @@ const program = Email.send({
80
78
  to: "ada@example.com",
81
79
  subject: "Welcome",
82
80
  html: "<h1>Welcome to Samva</h1>",
83
- }).pipe(Effect.provide(Client.layerFetch({ apiKey: "<samva-api-key>" })));
81
+ }).pipe(Effect.provide(Client.layerFetch({ apiKey: process.env.SAMVA_API_KEY! })));
84
82
 
85
83
  const message = await Effect.runPromise(program);
86
84
  ```
@@ -137,8 +135,10 @@ Samva supports two client auth modes. Use one per `createClient` instance.
137
135
  ### API key (automation, CI, single org)
138
136
 
139
137
  ```typescript
140
- const client = createClient({
141
- apiKey: "samva_sk_live_...",
138
+ import { createClient } from "samva";
139
+
140
+ const samva = createClient({
141
+ apiKey: process.env.SAMVA_API_KEY!,
142
142
  baseUrl: "https://api.samva.dev",
143
143
  });
144
144
  ```
@@ -149,16 +149,18 @@ const client = createClient({
149
149
  ### OAuth bearer (interactive, multi-org)
150
150
 
151
151
  ```typescript
152
- const client = createClient({
153
- authToken: sessionAccessToken,
152
+ import { createClient } from "samva";
153
+
154
+ const samva = createClient({
155
+ authToken: process.env.SAMVA_AUTH_TOKEN!,
154
156
  baseUrl: "https://api.samva.dev",
155
- headers: { "x-org-slug": "your-org-slug" },
157
+ orgSlug: "your-org-slug",
156
158
  });
157
159
  ```
158
160
 
159
161
  - Requests use `Authorization: Bearer <authToken>`.
160
162
  - The token is user-scoped; send the target organization slug on every request via the `x-org-slug` header.
161
- - There is no SDK `orgSlug` helper — pass the header directly.
163
+ - `orgSlug` pairs with `authToken`; API keys already select their organization.
162
164
 
163
165
  For terminal workflows (`samva login`, `samva org use`, `samva email send --dry-run`), see [`@samva/cli`](https://www.npmjs.com/package/@samva/cli).
164
166
 
@@ -173,13 +175,14 @@ Author a template as TSX with `samva templates init`, then publish an exact comm
173
175
  A published template is addressed by its slug, which is the `id` in its `defineTemplate`:
174
176
 
175
177
  ```typescript
176
- await client.messages.send({
178
+ import { createClient } from "samva";
179
+
180
+ const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });
181
+
182
+ await samva.email.send({
177
183
  to: [{ email: "ada@example.com" }],
178
- channel: "email",
179
- email: {
180
- templateSlug: "order-shipped",
181
- templateData: { name: "Ada", orderId: "A-1042" },
182
- },
184
+ templateSlug: "order-shipped",
185
+ templateData: { name: "Ada", orderId: "A-1042" },
183
186
  });
184
187
  ```
185
188
 
@@ -201,49 +204,28 @@ The Promise client exposes:
201
204
  - `conversations`
202
205
  - `customFields`
203
206
  - `email`
207
+ - `events`
204
208
  - `extensionInstallations`
205
209
  - `extensions`
206
210
  - `feedback`
211
+ - `journeys`
207
212
  - `mailboxes`
208
213
  - `media`
209
214
  - `messages`
210
215
  - `namespaces`
211
216
  - `operations`
212
217
  - `organizations`
218
+ - `raw`
213
219
  - `scheduledMessages`
220
+ - `subscriptions`
214
221
  - `templates`
215
- - `topics`
216
222
  - `topicForms`
223
+ - `newsletters` (Preview), including `newsletters.issues` and `newsletters.domains`
224
+ - `topics`
217
225
  - `webhooks`
218
226
  - `whoami`
219
227
 
220
- The Effect SDK exposes Pascal-cased domain modules with lower-camel operations:
221
-
222
- - `Agents`
223
- - `Analytics`
224
- - `ApiKeys`
225
- - `Attachments`
226
- - `Brands`
227
- - `Campaigns`
228
- - `ContactGroups`
229
- - `Contacts`
230
- - `Conversations`
231
- - `CustomFields`
232
- - `Email`
233
- - `ExtensionInstallations`
234
- - `Extensions`
235
- - `Feedback`
236
- - `Mailboxes`
237
- - `Media`
238
- - `Messages`
239
- - `Namespaces`
240
- - `Operations`
241
- - `Organizations`
242
- - `ScheduledMessages`
243
- - `Templates`
244
- - `Topics`
245
- - `Webhooks`
246
- - `Whoami`
228
+ The Effect SDK exposes Pascal-cased domain modules; see the [namespace reference](https://samva.dev/docs/developers/typescript-sdk#namespaces) for their import paths.
247
229
 
248
230
  Effect operations take direct parameter objects: body, path, and query fields are not wrapped in `payload` or `params` envelopes. Import the modules you use from `samva/effect/<lower-kebab>` and provide `Client.layerFetch` once at the program boundary.
249
231
 
@@ -271,15 +253,17 @@ error with `Effect.catchTag` does not require importing its constructor.
271
253
 
272
254
  ### Default-on retry
273
255
 
274
- The Effect client retries safe operations out of the box, so you do not wrap calls in `Effect.retry`:
256
+ Both clients retry safe operations by default:
275
257
 
276
- - **What retries** — read operations (`GET`/`HEAD`) and sends. Sends are safe because the client attaches an `Idempotency-Key` (below), so the server deduplicates a replayed attempt. Every other mutating operation (`create`, `update`, `remove`, …) is keyless and is never auto-retried.
258
+ - **What retries** — reads (`GET`/`HEAD`) and requests covered by `x-idempotent` in the OpenAPI document and its optional `x-idempotent-when` condition. Both clients attach one key per logical call and reuse it across retries. Other mutations never retry.
277
259
  - **When** — only for `isRetryable` failures: throttling (`429`), transient server errors (including a transient `BillingProviderError`), and request-transport failures. `ValidationError`, `ConflictError`, `NotFound`, auth, and billing-limit `PaymentRequiredError` failures never retry.
278
260
  - **How** — jittered exponential backoff, bounded to four attempts total. A `429` honors the server's `retryAfterSeconds` hint (capped at 60s) in place of the computed delay.
279
261
 
262
+ `contacts.startImport` retries only `mode: "new"`. Resumes use a generation fence and never retry automatically, even with an explicit key. After an ambiguous resume response, read `contacts.getImportJob` before deciding what to do next.
263
+
280
264
  Retry policy is read from context via the `Retry.Service` service. When it is absent, the default applies, so no operation gains a requirement. Override it with a Layer:
281
265
 
282
- ```typescript
266
+ ```typescript sdk-typecheck-skip="Retry configuration fragment applies to the program from the Effect quick start"
283
267
  import { Effect } from "effect";
284
268
  import { isRetryable } from "samva/effect/categories";
285
269
  import * as Retry from "samva/effect/retry";
@@ -293,15 +277,32 @@ program.pipe(Effect.provide(Retry.layer({ times: 6, while: isRetryable })));
293
277
 
294
278
  ### Idempotency keys
295
279
 
296
- Each `messages.send` / `email.send` call generates an `Idempotency-Key` per logical call — stable across the built-in retries, distinct across calls — so a retried send never delivers twice. Pass an explicit key for cross-process deduplication (safe to replay the same request from a different machine):
280
+ Each idempotent operation generates an `Idempotency-Key` per logical call — stable across the built-in retries, distinct across calls — so a retried send never delivers twice. Pass an explicit key for cross-process deduplication (safe to replay the same request from a different machine):
297
281
 
298
282
  ```typescript
299
- const send = Email.send(input, { idempotencyKey: "order-4417-receipt" });
283
+ import { createClient } from "samva";
284
+
285
+ const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });
286
+
287
+ await samva.email.send(
288
+ {
289
+ to: "ada@example.com",
290
+ subject: "Your receipt",
291
+ html: "<p>Thanks for your order.</p>",
292
+ },
293
+ { idempotencyKey: "order-4417-receipt" },
294
+ );
300
295
  ```
301
296
 
302
- Reusing a key with identical content replays the original response; reusing it with different content fails with `ConflictError`.
297
+ For sends, reusing a key with identical content replays the original response; different content fails with `ConflictError`. Other operations retain their documented replay and conflict behavior. The only override is `{ idempotencyKey }` in the second options argument; it is never part of params or request headers.
298
+
299
+ The Promise client accepts `maxRetries` in `createClient` and per-call options (zero disables retries). A client-level `idempotency: (operation) => key` hook supplies stable keys when needed; explicit options take precedence.
300
+
301
+ ### Pagination
303
302
 
304
- ### Stream pagination
303
+ Promise lists expose lazy async iterators: `samva.contacts.list.pages(params)` yields page envelopes and `.items(params)` yields individual items. Both preserve filters and fetch the next cursor only when consumed.
304
+
305
+ Effect pagination uses Streams:
305
306
 
306
307
  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:
307
308
 
@@ -309,20 +310,22 @@ Every list answers `{ items, nextCursor }`: pass `nextCursor` back as `cursor` f
309
310
  - **`list.pages(input?)`** — a `Stream` of raw page envelopes.
310
311
 
311
312
  ```typescript
312
- import { Stream } from "effect";
313
+ import { Effect, Stream } from "effect";
314
+ import * as Client from "samva/effect/client";
313
315
  import * as Contacts from "samva/effect/contacts";
314
316
 
315
- // Every contact, one page fetched at a time:
316
- const allContacts = Stream.runCollect(Contacts.list.items());
317
-
318
- // Bounded consumption is lazy — this fetches only as many pages as it needs:
319
- const firstFifty = Stream.runCollect(Contacts.list.items().pipe(Stream.take(50)));
317
+ const program = Contacts.list
318
+ .items({ limit: 100, after: "2026-01-01T00:00:00Z" })
319
+ .pipe(
320
+ Stream.take(50),
321
+ Stream.runCollect,
322
+ Effect.provide(Client.layerFetch({ apiKey: process.env.SAMVA_API_KEY! })),
323
+ );
320
324
 
321
- // Caller params (start cursor, limit, filters) are respected:
322
- const recent = Contacts.list.items({ limit: 100, after: "2026-01-01T00:00:00Z" });
325
+ const contacts = await Effect.runPromise(program);
323
326
  ```
324
327
 
325
- 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. Pass `limit` as a number; both clients serialize it as a query string. A list bounded by design, such as `CustomFields.list`, answers `{ items }` in one response and carries no companions. Stream pagination is Effect-only.
328
+ 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. Pass `limit` as a number; both clients serialize it as a query string. A list bounded by design, such as `CustomFields.list`, answers `{ items }` in one response and carries no companions. Promise pagination uses async iterators; Effect pagination uses Streams.
326
329
 
327
330
  ### Redacted secrets
328
331
 
@@ -349,33 +352,35 @@ The wire body and the Promise client keep plain strings; only the Effect surface
349
352
 
350
353
  The published `openapi.json` carries machine-readable semantics on top of the standard schema, derived from the same contract annotations the Effect SDK uses (no second taxonomy):
351
354
 
352
- | Extension | Where | Meaning |
353
- | -------------- | ----------------- | ------------------------------------------------------------------------------------------------- |
354
- | `x-category` | error schemas | The error's semantic categories (e.g. `["throttling", "transient"]`). Omitted when uncategorized. |
355
- | `x-retryable` | error schemas | `true` when the error is safe to retry. |
356
- | `x-idempotent` | operations | `true` when the operation accepts an `Idempotency-Key` header. |
357
- | `x-sensitive` | schema properties | `true` for secret-bearing fields (plain `string` on the wire; `Redacted` in the Effect SDK). |
355
+ | Extension | Where | Meaning |
356
+ | ------------------- | ----------------- | ------------------------------------------------------------------------------------------------- |
357
+ | `x-category` | error schemas | The error's semantic categories (e.g. `["throttling", "transient"]`). Omitted when uncategorized. |
358
+ | `x-retryable` | error schemas | `true` when the error is safe to retry. |
359
+ | `x-idempotent` | operations | `true` when the operation accepts an `Idempotency-Key` header. |
360
+ | `x-idempotent-when` | operations | Optional `{ field, equals }` condition on the request body that limits idempotent replay. |
361
+ | `x-sensitive` | schema properties | `true` for secret-bearing fields (plain `string` on the wire; `Redacted` in the Effect SDK). |
358
362
 
359
363
  These let MCP and third-party consumers read retry/idempotency/secret semantics straight from the spec.
360
364
 
361
365
  ## Usage Examples
362
366
 
363
- ### Send Email Through Unified Messages
367
+ ### Send Email
364
368
 
365
369
  ```typescript
366
- const { contact } = await client.contacts.findOrCreate({
370
+ import { createClient } from "samva";
371
+
372
+ const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });
373
+
374
+ const { contact } = await samva.contacts.findOrCreate({
367
375
  lookup: { type: "email", value: "ada@example.com" },
368
376
  create: { name: "Ada Lovelace" },
369
377
  });
370
378
 
371
- const response = await client.messages.send({
379
+ const response = await samva.email.send({
372
380
  to: [contact],
373
- channel: "email",
374
- email: {
375
- subject: "Welcome",
376
- html: "<h1>Welcome to Samva</h1>",
377
- text: "Welcome to Samva",
378
- },
381
+ subject: "Welcome",
382
+ html: "<h1>Welcome to Samva</h1>",
383
+ text: "Welcome to Samva",
379
384
  metadata: {
380
385
  campaign: "welcome",
381
386
  },
@@ -385,21 +390,27 @@ const response = await client.messages.send({
385
390
  ### Native Effect Send Email
386
391
 
387
392
  ```typescript
393
+ import { Effect } from "effect";
394
+ import * as Client from "samva/effect/client";
388
395
  import * as Email from "samva/effect/email";
389
396
 
390
- const message =
391
- yield *
392
- Email.send({
393
- to: "ada@example.com",
394
- subject: "Welcome",
395
- html: "<h1>Welcome to Samva</h1>",
396
- });
397
+ const program = Email.send({
398
+ to: "ada@example.com",
399
+ subject: "Welcome",
400
+ html: "<h1>Welcome to Samva</h1>",
401
+ }).pipe(Effect.provide(Client.layerFetch({ apiKey: process.env.SAMVA_API_KEY! })));
402
+
403
+ const message = await Effect.runPromise(program);
397
404
  ```
398
405
 
399
406
  ### List Conversations
400
407
 
401
408
  ```typescript
402
- const response = await client.conversations.list({
409
+ import { createClient } from "samva";
410
+
411
+ const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });
412
+
413
+ const response = await samva.conversations.list({
403
414
  limit: 20,
404
415
  status: "active",
405
416
  });
@@ -408,7 +419,11 @@ const response = await client.conversations.list({
408
419
  ### Schedule a Message
409
420
 
410
421
  ```typescript
411
- const scheduled = await client.scheduledMessages.create({
422
+ import { createClient } from "samva";
423
+
424
+ const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });
425
+
426
+ const scheduled = await samva.scheduledMessages.create({
412
427
  send: {
413
428
  to: [{ email: "ada@example.com" }],
414
429
  channel: "email",
@@ -418,13 +433,17 @@ const scheduled = await client.scheduledMessages.create({
418
433
  });
419
434
 
420
435
  // Later, cancel it before it dispatches
421
- await client.scheduledMessages.cancel({ id: scheduled.id });
436
+ await samva.scheduledMessages.cancel({ id: scheduled.id });
422
437
  ```
423
438
 
424
439
  ### Create and Run a Campaign
425
440
 
426
441
  ```typescript
427
- const campaign = await client.campaigns.create({
442
+ import { createClient } from "samva";
443
+
444
+ const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });
445
+
446
+ const campaign = await samva.campaigns.create({
428
447
  name: "August newsletter",
429
448
  channel: "email",
430
449
  content: {
@@ -438,12 +457,12 @@ const campaign = await client.campaigns.create({
438
457
  },
439
458
  });
440
459
 
441
- const run = await client.campaigns.scheduleRun({
460
+ const run = await samva.campaigns.scheduleRun({
442
461
  id: campaign.id,
443
462
  scheduledFor: "2026-08-01T09:00:00Z",
444
463
  });
445
464
 
446
- const recipients = await client.campaigns.listRecipients({
465
+ const recipients = await samva.campaigns.listRecipients({
447
466
  id: campaign.id,
448
467
  runId: run.id,
449
468
  });
@@ -455,15 +474,21 @@ Mailbox send, reply, forward, and draft send return action receipts. A successfu
455
474
  pending work; it is not a sent confirmation. Read `receipt.state` and preserve `receipt.actionId`:
456
475
 
457
476
  ```typescript
458
- const receipt = await client.mailboxes.sendMessage({
459
- id: "mbx_...",
460
- to: ["ada@example.com"],
461
- subject: "Hello",
462
- text: "Hello from Samva",
463
- "idempotency-key": "support-message-123",
464
- });
477
+ import { createClient } from "samva";
478
+
479
+ const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });
480
+
481
+ const receipt = await samva.mailboxes.sendMessage(
482
+ {
483
+ id: "mbx_...",
484
+ to: ["ada@example.com"],
485
+ subject: "Hello",
486
+ text: "Hello from Samva",
487
+ },
488
+ { idempotencyKey: "support-message-123" },
489
+ );
465
490
 
466
- const action = await client.mailboxes.getAction({ id: "mbx_...", actionId: receipt.actionId });
491
+ const action = await samva.mailboxes.getAction({ id: "mbx_...", actionId: receipt.actionId });
467
492
  if (action.type === "sendMessage" || action.type === "reply") {
468
493
  console.log(action.state, action.send.messageId);
469
494
  }
@@ -501,8 +526,8 @@ is closed by the client, and its error carries `reason: "idleTimeout"` instead o
501
526
  It needs a runtime whose `WebSocket` accepts request headers, such as Node or Bun, or one passed
502
527
  as the `WebSocket` option.
503
528
 
504
- ```typescript
505
- const events = client.mailboxes.events({ cursor: savedCursor, mailboxIds: ["mbx_..."] });
529
+ ```typescript sdk-typecheck-skip="Event loop fragment uses the application cursor store and event handler"
530
+ const events = samva.mailboxes.events({ cursor: savedCursor, mailboxIds: ["mbx_..."] });
506
531
  for await (const event of events) {
507
532
  await handle(event.type, event.data);
508
533
  await saveCursor(event.cursor);
@@ -515,8 +540,10 @@ With Effect, `Mailboxes.events(options)` is a `Stream` of the same events that f
515
540
  ### Custom Headers
516
541
 
517
542
  ```typescript
518
- const client = createClient({
519
- apiKey: "<samva-api-key>",
543
+ import { createClient } from "samva";
544
+
545
+ const samva = createClient({
546
+ apiKey: process.env.SAMVA_API_KEY!,
520
547
  headers: {
521
548
  "X-Custom-Header": "value",
522
549
  },
@@ -526,10 +553,12 @@ const client = createClient({
526
553
  ### Error Handling
527
554
 
528
555
  ```typescript
529
- import { RateLimitedError, SamvaApiError, SamvaTransportError } from "samva";
556
+ import { createClient, RateLimitedError, SamvaApiError, SamvaTransportError } from "samva";
557
+
558
+ const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });
530
559
 
531
560
  try {
532
- const message = await client.email.send({
561
+ const message = await samva.email.send({
533
562
  to: "ada@example.com",
534
563
  subject: "Test",
535
564
  html: "<p>Test</p>",
@@ -555,18 +584,16 @@ subclass for failures declared by OpenAPI. Network and malformed-response failur
555
584
  ### Raw response access
556
585
 
557
586
  ```typescript
558
- const result = await client.raw.messages.send({
559
- body: {
560
- to: [{ contactId: "contact-id" }],
561
- channel: "email",
562
- email: { subject: "Hello", text: "Hello" },
563
- },
564
- });
587
+ import { createClient } from "samva";
588
+
589
+ const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });
590
+
591
+ const result = await samva.raw.messages.get({ id: "msg_7q2xk9mvt4znw8rh" });
565
592
 
566
593
  if (result.error) console.error(result.response?.status, result.error);
567
594
  ```
568
595
 
569
- Use `client.raw` only when you need the generated `{ data, error, request, response }` envelope or
596
+ Use `samva.raw` only when you need the generated `{ data, error, request, response }` envelope or
570
597
  transport-level request options.
571
598
 
572
599
  ## Type Safety
@@ -574,18 +601,24 @@ transport-level request options.
574
601
  All request and response types are generated from OpenAPI schemas:
575
602
 
576
603
  ```typescript
577
- import type { MessagesSendData } from "samva";
604
+ import { createClient } from "samva";
578
605
 
579
- const requestData: MessagesSendData = {
580
- body: {
581
- to: [{ contactId: "contact-id" }],
582
- channel: "email",
583
- email: {
584
- subject: "Hello",
585
- html: "<p>Hello World</p>",
586
- },
587
- },
588
- };
606
+ const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });
607
+
608
+ type EmailInput = Parameters<typeof samva.email.send>[0];
589
609
 
590
- const response = await client.messages.send(requestData.body);
610
+ const input = {
611
+ to: "ada@example.com",
612
+ subject: "Hello",
613
+ html: "<p>Hello World</p>",
614
+ } satisfies EmailInput;
615
+
616
+ const response = await samva.email.send(input);
591
617
  ```
618
+
619
+ ## Mailbox extensions
620
+
621
+ Import `defineExtension` from `samva/mailbox`, test helpers from `samva/mailbox/test`, and
622
+ `createWebhookHandler` from `samva/mailbox/webhook`. Handlers receive a normal Samva client:
623
+ `ctx.samva.mailboxes.reply({ id, messageId, text })`. Event dispatch supplies deterministic
624
+ idempotency keys through the client hook, preserving the send order across retried events.
@@ -1,4 +1,4 @@
1
- //#region \0rolldown/runtime.js
1
+ // \0rolldown/runtime.js
2
2
  var __defProp = Object.defineProperty;
3
3
  var __exportAll = (all, no_symbols) => {
4
4
  let target = {};
@@ -9,5 +9,4 @@ var __exportAll = (all, no_symbols) => {
9
9
  if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
10
  return target;
11
11
  };
12
- //#endregion
13
12
  export { __exportAll };
@@ -1,7 +1,7 @@
1
1
  import { createSseClient } from "../core/serverSentEvents.gen.js";
2
2
  import { getValidRequestBody } from "../core/utils.gen.js";
3
3
  import { buildUrl, createConfig, createInterceptors, getParseAs, mergeConfigs, mergeHeaders, setAuthParams } from "./utils.gen.js";
4
- //#region src/client/client/client.gen.ts
4
+ // src/client/client/client.gen.ts
5
5
  const createClient = (config = {}) => {
6
6
  let _config = mergeConfigs(createConfig(), config);
7
7
  const getConfig = () => ({ ..._config });
@@ -168,7 +168,6 @@ const createClient = (config = {}) => {
168
168
  trace: makeMethodFn("TRACE")
169
169
  };
170
170
  };
171
- //#endregion
172
171
  export { createClient };
173
172
 
174
173
  //# sourceMappingURL=client.gen.js.map
@@ -2,7 +2,7 @@ import { jsonBodySerializer } from "../core/bodySerializer.gen.js";
2
2
  import { serializeArrayParam, serializeObjectParam, serializePrimitiveParam } from "../core/pathSerializer.gen.js";
3
3
  import { getUrl } from "../core/utils.gen.js";
4
4
  import { getAuthToken } from "../core/auth.gen.js";
5
- //#region src/client/client/utils.gen.ts
5
+ // src/client/client/utils.gen.ts
6
6
  const createQuerySerializer = ({ parameters = {}, ...args } = {}) => {
7
7
  const querySerializer = (queryParams) => {
8
8
  const search = [];
@@ -171,7 +171,6 @@ const createConfig = (override = {}) => ({
171
171
  querySerializer: defaultQuerySerializer,
172
172
  ...override
173
173
  });
174
- //#endregion
175
174
  export { buildUrl, createConfig, createInterceptors, createQuerySerializer, getParseAs, mergeConfigs, mergeHeaders, setAuthParams };
176
175
 
177
176
  //# sourceMappingURL=utils.gen.js.map
@@ -1,8 +1,7 @@
1
1
  import { createConfig } from "./client/utils.gen.js";
2
2
  import { createClient } from "./client/client.gen.js";
3
- //#region src/client/client.gen.ts
3
+ // src/client/client.gen.ts
4
4
  const client = createClient(createConfig({ baseUrl: "https://api.samva.dev" }));
5
- //#endregion
6
5
  export { client };
7
6
 
8
7
  //# sourceMappingURL=client.gen.js.map
@@ -1,4 +1,4 @@
1
- //#region src/client/core/auth.gen.ts
1
+ // src/client/core/auth.gen.ts
2
2
  const getAuthToken = async (auth, callback) => {
3
3
  const token = typeof callback === "function" ? await callback(auth) : callback;
4
4
  if (!token) return;
@@ -6,7 +6,6 @@ const getAuthToken = async (auth, callback) => {
6
6
  if (auth.scheme === "basic") return `Basic ${btoa(token)}`;
7
7
  return token;
8
8
  };
9
- //#endregion
10
9
  export { getAuthToken };
11
10
 
12
11
  //# sourceMappingURL=auth.gen.js.map
@@ -1,6 +1,5 @@
1
- //#region src/client/core/bodySerializer.gen.ts
1
+ // src/client/core/bodySerializer.gen.ts
2
2
  const jsonBodySerializer = { bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value) };
3
- //#endregion
4
3
  export { jsonBodySerializer };
5
4
 
6
5
  //# sourceMappingURL=bodySerializer.gen.js.map