samva 0.50.0 → 0.52.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 (121) hide show
  1. package/AGENTS.md +49 -5
  2. package/README.md +137 -7
  3. package/dist/client/sdk.gen.d.ts +78 -38
  4. package/dist/client/sdk.gen.js +1554 -967
  5. package/dist/client/types.gen.d.ts +541 -291
  6. package/dist/effect/agents.d.ts +4 -4
  7. package/dist/effect/api-keys.d.ts +4 -6
  8. package/dist/effect/campaigns.d.ts +222 -230
  9. package/dist/effect/categories.d.ts +2 -2
  10. package/dist/effect/categories.js +6 -4
  11. package/dist/effect/contact-groups.d.ts +4 -4
  12. package/dist/effect/contacts.d.ts +8 -8
  13. package/dist/effect/conversations.d.ts +4 -4
  14. package/dist/effect/descriptors/integrations-catalog.d.ts +1 -1
  15. package/dist/effect/descriptors/integrations-catalog.js +1 -1
  16. package/dist/effect/descriptors/integrations.d.ts +1 -1
  17. package/dist/effect/descriptors/integrations.js +1 -1
  18. package/dist/effect/descriptors/logs.d.ts +21 -0
  19. package/dist/effect/descriptors/logs.js +23 -0
  20. package/dist/effect/descriptors/whats-app.d.ts +1 -1
  21. package/dist/effect/descriptors/whats-app.js +1 -1
  22. package/dist/effect/email.d.ts +17 -16
  23. package/dist/effect/errors.d.ts +1 -0
  24. package/dist/effect/errors.js +2 -1
  25. package/dist/effect/generated/agents.js +4 -4
  26. package/dist/effect/generated/api-keys.d.ts +0 -15
  27. package/dist/effect/generated/api-keys.js +1 -2
  28. package/dist/effect/generated/campaigns.d.ts +18 -68
  29. package/dist/effect/generated/campaigns.js +5 -15
  30. package/dist/effect/generated/email.d.ts +10 -3
  31. package/dist/effect/generated/email.js +6 -5
  32. package/dist/effect/generated/index.d.ts +3 -1
  33. package/dist/effect/generated/integrations-catalog.d.ts +93 -49
  34. package/dist/effect/generated/integrations-catalog.js +17 -28
  35. package/dist/effect/generated/integrations.d.ts +20 -40
  36. package/dist/effect/generated/integrations.js +9 -13
  37. package/dist/effect/generated/journeys.d.ts +61 -13
  38. package/dist/effect/generated/journeys.js +5 -5
  39. package/dist/effect/generated/logs.d.ts +2311 -0
  40. package/dist/effect/generated/logs.js +312 -0
  41. package/dist/effect/generated/mailboxes.d.ts +30 -24
  42. package/dist/effect/generated/mailboxes.js +25 -25
  43. package/dist/effect/generated/messages.d.ts +1 -882
  44. package/dist/effect/generated/messages.js +4 -243
  45. package/dist/effect/generated/namespaces.js +1 -1
  46. package/dist/effect/generated/newsletter-domains.d.ts +61 -13
  47. package/dist/effect/generated/newsletter-domains.js +5 -5
  48. package/dist/effect/generated/newsletter-issues.d.ts +166 -34
  49. package/dist/effect/generated/newsletter-issues.js +12 -12
  50. package/dist/effect/generated/newsletters.d.ts +76 -16
  51. package/dist/effect/generated/newsletters.js +6 -6
  52. package/dist/effect/generated/organizations.js +1 -1
  53. package/dist/effect/generated/policies.js +2 -2
  54. package/dist/effect/generated/scheduled-messages.d.ts +0 -26
  55. package/dist/effect/generated/scheduled-messages.js +2 -4
  56. package/dist/effect/generated/shared.d.ts +1139 -257
  57. package/dist/effect/generated/shared.js +323 -83
  58. package/dist/effect/generated/subscriptions.d.ts +4 -4
  59. package/dist/effect/generated/subscriptions.js +2 -6
  60. package/dist/effect/generated/template-registrations.d.ts +46 -10
  61. package/dist/effect/generated/template-registrations.js +4 -4
  62. package/dist/effect/generated/templates.js +2 -2
  63. package/dist/effect/generated/whats-app-flows.d.ts +151 -31
  64. package/dist/effect/generated/whats-app-flows.js +11 -11
  65. package/dist/effect/generated/whats-app-setup-links.d.ts +61 -13
  66. package/dist/effect/generated/whats-app-setup-links.js +5 -5
  67. package/dist/effect/generated/whats-app.d.ts +187 -65
  68. package/dist/effect/generated/whats-app.js +18 -24
  69. package/dist/effect/generated-metadata.d.ts +15 -3
  70. package/dist/effect/generated-metadata.js +375 -349
  71. package/dist/effect/index.d.ts +1 -0
  72. package/dist/effect/index.js +3 -1
  73. package/dist/effect/integrations-catalog.d.ts +92 -4
  74. package/dist/effect/integrations.d.ts +42 -10
  75. package/dist/effect/internal/client.d.ts +19 -2
  76. package/dist/effect/internal/client.js +35 -5
  77. package/dist/effect/internal/email-sender.d.ts +4 -4
  78. package/dist/effect/internal/email-sender.js +5 -3
  79. package/dist/effect/internal/log-events.d.ts +19 -0
  80. package/dist/effect/internal/log-events.js +53 -0
  81. package/dist/effect/internal/mailbox-events.d.ts +6 -2
  82. package/dist/effect/internal/mailbox-events.js +4 -3
  83. package/dist/effect/internal/operation.d.ts +11 -0
  84. package/dist/effect/internal/operation.js +10 -6
  85. package/dist/effect/internal/send.d.ts +4 -0
  86. package/dist/effect/internal/send.js +11 -8
  87. package/dist/effect/internal/timeout.d.ts +16 -0
  88. package/dist/effect/internal/timeout.js +20 -0
  89. package/dist/effect/journeys.d.ts +4 -4
  90. package/dist/effect/logs.d.ts +149 -0
  91. package/dist/effect/logs.js +18 -0
  92. package/dist/effect/mailboxes.d.ts +184 -178
  93. package/dist/effect/mailboxes.js +1 -1
  94. package/dist/effect/messages.d.ts +5 -5
  95. package/dist/effect/namespaces.d.ts +4 -4
  96. package/dist/effect/newsletter-domains.d.ts +2 -2
  97. package/dist/effect/operations.d.ts +2 -2
  98. package/dist/effect/scheduled-messages.d.ts +2 -6
  99. package/dist/effect/templates.d.ts +6 -6
  100. package/dist/effect/topics.d.ts +4 -4
  101. package/dist/effect/webhooks.d.ts +4 -4
  102. package/dist/effect/whatsapp-setup-links.d.ts +2 -2
  103. package/dist/effect/whatsapp.d.ts +73 -3
  104. package/dist/index.js +2 -2
  105. package/dist/mailbox-events.d.ts +50 -3
  106. package/dist/mailbox-events.js +38 -19
  107. package/dist/package.js +1 -1
  108. package/dist/promises/client.d.ts +8 -1
  109. package/dist/promises/client.js +15 -9
  110. package/dist/promises/errors.gen.d.ts +14 -1
  111. package/dist/promises/errors.gen.js +158 -36
  112. package/dist/promises/index.js +2 -2
  113. package/dist/promises/request.d.ts +31 -2
  114. package/dist/promises/request.js +42 -7
  115. package/dist/promises/types.gen.d.ts +1 -1
  116. package/dist/request-id.d.ts +3 -0
  117. package/dist/request-id.js +7 -0
  118. package/dist/request-policy.d.ts +9 -0
  119. package/dist/request-policy.js +16 -1
  120. package/dist/service-map.d.ts +14 -3
  121. package/package.json +6 -2
package/AGENTS.md CHANGED
@@ -25,14 +25,57 @@ Mailbox send operations return asynchronous action receipts. Interpret `state`,
25
25
  and read `mailboxes.getAction` (or `Mailboxes.getAction`) to follow progress. Narrow on action `type`
26
26
  before reading send-specific `send` receipt and frozen `intent`. `queued` is not a sent confirmation;
27
27
  `accepted` supplies `messageId` and `acceptedAt`, while `completed` records mailbox projection,
28
- not recipient delivery. A timeout preserves the original idempotency key and body; a new key can
28
+ not recipient delivery. Each request attempt fails with `SamvaTimeoutError` after 30 000 ms; set
29
+ `timeoutMs` on the client (`createClient`, `Client.layerFetch`) or per call, and `null` disables
30
+ the bound. A retry after a timeout preserves the original idempotency key and body; a new key can
29
31
  send another email. `uncertain` requires reconciliation. Only a permitted person can cancel before
30
32
  acceptance or retry an eligible original action without extending its deadline. Approval is also
31
33
  asynchronous. See https://samva.dev/docs/mailboxes/approvals for the receipt contract.
32
34
 
35
+ `email.send` takes `from` as `{ email, name? }`, never a string. Without `from` it falls back to the
36
+ template's `fromDefault`, then the organization default sender, then the only verified sender; a new
37
+ organization whose only sending identity is a hosted mailbox address has none, so the send fails with
38
+ `FromAddressRequiredError` (`422`, with `verifiedDomains` and `addresses`) and the example must pass `from`.
39
+ `mailboxes.sendMessage` takes plain address strings and sends from the mailbox's default email
40
+ endpoint; it has no `from` or template fields. `mailboxes.create` takes a full address on
41
+ `whoami.get()`'s `organization.hostedMailDomain`; a slug is not an address.
42
+
43
+ A thread id is not a message id: `mailboxes.getThread` returns no messages, so read a thread's
44
+ `msg_` ids from `listThreadMessages({ id, threadId })` (or `getThreadContent`) and pass an item's
45
+ `id` as `messageId` to `reply`, `replyAll`, and `forward`. A thread's folder is set when it is
46
+ created and does not move on later replies: a thread a send started stays in `sent`, so
47
+ `listThreads({ folder: "inbox" })` omits it; omit `folder` and pass `unread: true` for replies.
48
+ To confirm a send landed, poll `getAction` until `state` is `completed`, `notSent`, or `uncertain`
49
+ within `executeUntil`, then read `action.send.messageId` and `action.send.threadId`.
50
+
51
+ A mailbox email endpoint's `sendingStatus` (`mailboxes.get`) reports the address's setup: `pending`,
52
+ `ready`, or `failed`. While the organization's email onboarding review is undecided, a send from a
53
+ `ready` address stays `queued`; read `email.getOnboardingReview()` for the cause.
54
+
55
+ Each SDK method is named for its API operation, so a REST `DELETE` is `remove` (`mailboxes.remove`,
56
+ `namespaces.remove`, `webhooks.remove`, `email.removeDomain`, `newsletters.domains.remove`). The
57
+ exceptions are `apiKeys.revoke`, `whatsappSetupLinks.revoke`, `campaigns.archive`,
58
+ `templates.delete`, `templates.deleteProject`, and `templateShareLinks.delete`. The identity call is
59
+ `whoami.get()`. `apiKeys.create` and `apiKeys.rotate` return the secret in `key`; destructure it and
60
+ keep the response out of logs.
61
+
62
+ Email domain methods are flat on `client.email`: `addDomain`, `getDomainVerification`,
63
+ `advanceDomainVerification` (checks DNS now; repeat until `phase` is `ready`), `enableReceiving`
64
+ (takes `id` and optional `catchAll`, `endpointId`, `addresses`; the domain must be
65
+ verified), `getReceivingStatus`, and `removeDomain`. Only newsletter domains nest, under
66
+ `client.newsletters.domains`.
67
+
68
+ Create and publish a template from code with `templates.create({ name, slug })`, `openWorkspace`,
69
+ `patchWorkspace`, `checkWorkspace`, `saveWorkspace`, `publish`, and `renderPublication`; every
70
+ workspace call carries the workspace `revision` as `expectedRevision`, and Save also carries
71
+ `expectedHead`. See https://samva.dev/docs/sml/create-and-publish-from-code.
72
+
33
73
  Use `client.policies` or `Policies` from `samva/effect/policies` to read, replace, or clear an
34
- organization, mailbox, or API key's decision rules. Policy writes require a person's OAuth session
35
- (`authToken` and `orgSlug`), not an API key. Each rule sets `decide` (a default) or `atLeast`
74
+ organization, mailbox, or API key's decision rules. A permitted person can write with an OAuth
75
+ session (`authToken` and `orgSlug`). A full-access, organization-wide API key owned by an
76
+ organization owner or admin can change another key's policy and can only tighten mailbox policy.
77
+ It can also change a hosted agent's definition policy and an integration tool's approval settings.
78
+ Each rule sets `decide` (a default) or `atLeast`
36
79
  (a binding floor). Scope policy reads return a flat snapshot with `version`, initially `0` when
37
80
  unset. Replacement requires the observed `ifVersion`; `deletePolicy({ kind, id, ifVersion })`
38
81
  clears the configuration. Both return the next snapshot, and clear keeps the counter. On
@@ -62,8 +105,9 @@ https://samva.dev/docs/channels/email/newsletters.
62
105
 
63
106
  Every idempotent operation generates one key per logical call and reuses it across built-in
64
107
  retries. Override only through the second options argument, `{ idempotencyKey }`. Both clients
65
- retry reads and contract-marked idempotent mutations. Promise clients accept `maxRetries` at
66
- client and call level. `contacts.startImport` retries only `mode: "new"`; a resume uses
108
+ retry reads and contract-marked idempotent mutations, after a timeout too. Promise clients accept
109
+ `maxRetries` at client and call level. Storage puts of oversized inline attachments use
110
+ `uploadTimeoutMs` (default 300 000 ms) instead of `timeoutMs`. `contacts.startImport` retries only `mode: "new"`; a resume uses
67
111
  a generation fence and must be followed by `getImportJob` after an ambiguous response. Promise cursor lists expose lazy `.pages(params)` and `.items(params)`
68
112
  async iterators. `orgSlug` selects an organization when paired with `authToken`.
69
113
 
package/README.md CHANGED
@@ -125,6 +125,13 @@ const receipt = await samva.mailboxes.sendMessage({
125
125
  console.log(receipt.state);
126
126
  ```
127
127
 
128
+ A hosted address receives mail at once. Read each email endpoint's `sendingStatus` from
129
+ `mailboxes.get`: `pending` means sending setup is still running, and `failed` means setup failed
130
+ and support recovers the address. `ready` describes the address's setup only. While the
131
+ organization's email onboarding review is undecided, a send from a ready address returns a receipt
132
+ whose action stays `queued`; read `samva.email.getOnboardingReview()` (or run `samva email doctor`)
133
+ for the reason. See [a send that stays queued](https://samva.dev/docs/mailboxes/approvals?utm_source=readme&utm_medium=sdk#a-send-that-stays-queued).
134
+
128
135
  Replies arrive as signed webhooks or over the mailbox event stream, threaded to the conversation. Give
129
136
  the agent a key that reaches only its own mailbox, and set rules that hold a send for a person to
130
137
  approve: see [Give an agent an inbox](https://samva.dev/docs/mailboxes?utm_source=readme&utm_medium=sdk). To drive the same mailbox
@@ -143,7 +150,7 @@ The root entrypoint is Promise-based:
143
150
  import { createClient } from "samva";
144
151
  ```
145
152
 
146
- 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.
153
+ 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 SDK. Effect is an optional peer dependency, so Promise-only applications do not install or load it.
147
154
 
148
155
  ## Installation
149
156
 
@@ -171,6 +178,7 @@ const { contact } = await samva.contacts.findOrCreate({
171
178
  });
172
179
 
173
180
  const message = await samva.email.send({
181
+ from: { email: "hello@yourdomain.com" },
174
182
  to: [contact],
175
183
  subject: "Hello",
176
184
  html: "<p>Hello World</p>",
@@ -185,15 +193,22 @@ for await (const message of samva.messages.list.items({ limit: 20 })) {
185
193
  }
186
194
  ```
187
195
 
196
+ `from` is an object, `{ email, name? }`, never a string, on an address at a verified domain
197
+ (a hosted mailbox domain counts). Omit it only when the template sets `fromDefault`, the
198
+ organization has a default sender, or it has exactly one verified sender. A new organization whose
199
+ only sending identity is a hosted mailbox address has none of these, so the send fails with
200
+ `FromAddressRequiredError` (`422`) with its `verifiedDomains` and `addresses`; pass one of those
201
+ addresses as `from: { email }`, or set a default with `samva.email.setDefaultSender` (`samva email senders set-default`).
202
+
188
203
  Creation fails with `ConflictError` (HTTP 409) when an external ID or address belongs to another
189
204
  contact. The error names the conflicting field and the creation is rolled back.
190
205
 
191
206
  ## Effect Quick Start
192
207
 
193
- Install `effect` next to `samva` when using the Effect entrypoint:
208
+ Install `effect` next to `samva` when using the Effect entrypoint, at a version in the range `samva` lists in `peerDependencies`:
194
209
 
195
210
  ```bash
196
- bun add samva effect@4.0.6
211
+ bun add samva effect
197
212
  ```
198
213
 
199
214
  ```typescript
@@ -202,6 +217,7 @@ import * as Client from "samva/effect/client";
202
217
  import * as Email from "samva/effect/email";
203
218
 
204
219
  const program = Email.send({
220
+ from: { email: "hello@yourdomain.com" },
205
221
  to: "ada@example.com",
206
222
  subject: "Welcome",
207
223
  html: "<h1>Welcome to Samva</h1>",
@@ -299,7 +315,9 @@ advisory `x-samva-client` request header. Supply your own value in `headers`, or
299
315
 
300
316
  Author a template as TSX with `samva templates init`, then publish an exact commit with
301
317
  `samva templates publish --commit HEAD` (see [`@samva/cli`](https://www.npmjs.com/package/@samva/cli)).
302
- A published template is addressed by its slug, which is the `id` in its `defineTemplate`:
318
+ A published template is addressed by its slug, which is the `id` in its `defineTemplate` unless
319
+ `samva templates add --slug` chose another handle. `templateSlug` takes that slug; `templateId` takes
320
+ the template's `tmpl_...` id. A send names exactly one of them:
303
321
 
304
322
  ```typescript
305
323
  import { createClient } from "samva";
@@ -307,6 +325,7 @@ import { createClient } from "samva";
307
325
  const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });
308
326
 
309
327
  await samva.email.send({
328
+ from: { email: "hello@yourdomain.com" },
310
329
  to: [{ email: "ada@example.com" }],
311
330
  templateSlug: "order-shipped",
312
331
  templateData: { name: "Ada", orderId: "A-1042" },
@@ -314,7 +333,26 @@ await samva.email.send({
314
333
  ```
315
334
 
316
335
  A template send omits `subject`, `html`, and `text`; the request fails if `templateData` does not
317
- match the template's input schema. `samva templates types` generates TypeScript types for that input.
336
+ match the template's input schema. `from` follows the same rule as above: pass it unless the
337
+ template's `fromDefault`, the organization default sender, or a single verified sender supplies it. `samva templates types` generates TypeScript types for that input.
338
+
339
+ The SDK and CLI flatten `templateSlug`, `templateData`, `templateId`, `publicationId`, `locale`, and
340
+ `timeZone` into the call. Over REST, `POST /v1/messages` nests them under `email`:
341
+
342
+ ```json
343
+ {
344
+ "channel": "email",
345
+ "from": { "email": "hello@yourdomain.com" },
346
+ "to": [{ "email": "ada@example.com" }],
347
+ "email": {
348
+ "templateSlug": "order-shipped",
349
+ "templateData": { "name": "Ada", "orderId": "A-1042" }
350
+ }
351
+ }
352
+ ```
353
+
354
+ To create, save, and publish a template without Git or the CLI, see
355
+ [Create and publish a template from code](https://samva.dev/docs/sml/create-and-publish-from-code?utm_source=readme&utm_medium=sdk).
318
356
 
319
357
  ## Copy a Share Link
320
358
 
@@ -335,6 +373,16 @@ reuse the organization's existing copy. An unavailable share link returns `Share
335
373
  Effect applications use `Templates.create({ shareLinkSlug })` from `samva/effect/templates`.
336
374
  The CLI accepts `samva templates create --data '{"shareLinkSlug":"for-context-dev"}' --json`.
337
375
 
376
+ ## Method Names
377
+
378
+ Each method is named for its API operation. A REST `DELETE` is `remove`: `mailboxes.remove`,
379
+ `namespaces.remove`, `webhooks.remove`, `email.removeDomain`, `newsletters.domains.remove`. The
380
+ exceptions are `apiKeys.revoke`, `whatsappSetupLinks.revoke`, `campaigns.archive`,
381
+ `templates.delete`, `templates.deleteProject`, and `templateShareLinks.delete`. The identity call is `samva.whoami.get()`, listing sent mail is
382
+ `messages.list`, and sending from a mailbox is `mailboxes.sendMessage`. Hosted MCP tool names are
383
+ `<group>_<operation>` and can use a different verb for the same operation, such as
384
+ `namespaces_delete` for `namespaces.remove`.
385
+
338
386
  ## Service Surface
339
387
 
340
388
  The Promise client exposes:
@@ -357,6 +405,7 @@ The Promise client exposes:
357
405
  - `integrationCatalog`
358
406
  - `integrations`
359
407
  - `journeys`
408
+ - `logs`
360
409
  - `mailboxes`
361
410
  - `media`
362
411
  - `messages`
@@ -410,7 +459,7 @@ error with `Effect.catchTag` does not require importing its constructor.
410
459
  Both clients retry safe operations by default:
411
460
 
412
461
  - **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.
413
- - **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.
462
+ - **When**: only for `isRetryable` failures: throttling (`429`), transient server errors (including a transient `BillingProviderError`), request-transport failures, and attempt timeouts. `ValidationError`, `ConflictError`, `NotFound`, auth, and billing-limit `PaymentRequiredError` failures never retry.
414
463
  - **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.
415
464
 
416
465
  `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.
@@ -429,6 +478,39 @@ program.pipe(Effect.provide(Retry.layerDisabled));
429
478
  program.pipe(Effect.provide(Retry.layer({ times: 6, while: isRetryable })));
430
479
  ```
431
480
 
481
+ ### Timeouts
482
+
483
+ Each request attempt has a 30 000 ms bound. An attempt that outlasts it is aborted and fails with
484
+ `SamvaTimeoutError`, which carries `timeoutMs`. Every retry starts a fresh timer, and a timeout
485
+ retries exactly where a transport failure would: on reads and idempotent operations, with the same
486
+ idempotency key. Set `timeoutMs` on the client or per call; a per-call `undefined` inherits the
487
+ client's value, and `null` at either level disables the bound. A value that is not a positive,
488
+ finite number of milliseconds throws a `RangeError`.
489
+
490
+ ```typescript
491
+ import { createClient, SamvaTimeoutError } from "samva";
492
+
493
+ const samva = createClient({ apiKey: process.env.SAMVA_API_KEY!, timeoutMs: 10_000 });
494
+
495
+ try {
496
+ await samva.email.listDomains({}, { timeoutMs: 60_000 });
497
+ } catch (error) {
498
+ if (error instanceof SamvaTimeoutError) console.error(`No answer in ${error.timeoutMs} ms`);
499
+ else throw error;
500
+ }
501
+ ```
502
+
503
+ `SamvaTimeoutError` extends `SamvaTransportError`. Aborting your own `signal` is not a timeout: it
504
+ rejects with a `SamvaTransportError` whose `cause` is the abort. Storage puts of oversized inline
505
+ attachments have their own bound, `uploadTimeoutMs` (default 300 000 ms, same rules), on the client
506
+ and on `email.send` and `messages.send`; a put past it fails as `MediaUploadError` caused by
507
+ `SamvaTimeoutError`. The media and send requests around the put keep `timeoutMs`.
508
+
509
+ The Effect client takes the same options on `Client.layer` and `Client.layerFetch`, `timeoutMs` per
510
+ call in each operation's options, and `uploadTimeoutMs` per call on `Email.send` and
511
+ `Messages.send`. A timed-out attempt fails with the tagged `SamvaTimeoutError` from
512
+ `samva/effect/errors`, which `isRetryable` accepts; interrupting the fiber stays an interruption.
513
+
432
514
  ### Idempotency keys
433
515
 
434
516
  Each idempotent operation generates an `Idempotency-Key` per logical call, stable across the built-in retries and 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):
@@ -440,6 +522,7 @@ const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });
440
522
 
441
523
  await samva.email.send(
442
524
  {
525
+ from: { email: "hello@yourdomain.com" },
443
526
  to: "ada@example.com",
444
527
  subject: "Your receipt",
445
528
  html: "<p>Thanks for your order.</p>",
@@ -502,6 +585,13 @@ const inspectKey = Effect.gen(function* () {
502
585
 
503
586
  The wire body and the Promise client keep plain strings; only the Effect surface is `Redacted`.
504
587
 
588
+ `apiKeys.create` and `apiKeys.rotate` return the whole key object with the secret in `key`, and the
589
+ Promise client returns it as a plain string. Destructure the secret
590
+ (`const { key: secret } = await samva.apiKeys.create({ ... })`), write it to your secret store,
591
+ and keep the response out of request logs and agent tool output. Revoke a key that was printed.
592
+ Capture the key before any redaction filter runs; a filter that blanks the response loses the only
593
+ copy.
594
+
505
595
  ## OpenAPI vendor extensions
506
596
 
507
597
  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):
@@ -531,6 +621,7 @@ const { contact } = await samva.contacts.findOrCreate({
531
621
  });
532
622
 
533
623
  const response = await samva.email.send({
624
+ from: { email: "hello@yourdomain.com" },
534
625
  to: [contact],
535
626
  subject: "Welcome",
536
627
  html: "<h1>Welcome to Samva</h1>",
@@ -549,6 +640,7 @@ import * as Client from "samva/effect/client";
549
640
  import * as Email from "samva/effect/email";
550
641
 
551
642
  const program = Email.send({
643
+ from: { email: "hello@yourdomain.com" },
552
644
  to: "ada@example.com",
553
645
  subject: "Welcome",
554
646
  html: "<h1>Welcome to Samva</h1>",
@@ -570,6 +662,42 @@ const response = await samva.conversations.list({
570
662
  });
571
663
  ```
572
664
 
665
+ ### Add and Verify a Domain
666
+
667
+ Email domain methods are flat on `samva.email`; only newsletter domains are nested under
668
+ `samva.newsletters.domains`. There is no `samva.email.domains`.
669
+
670
+ ```typescript
671
+ import { createClient } from "samva";
672
+
673
+ const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });
674
+
675
+ // Register the domain. The response lists the DNS records to publish in `dnsRecords`.
676
+ const domain = await samva.email.addDomain({ domain: "mail.example.com" });
677
+
678
+ // Read the last observed state, then check DNS now. Repeat after publishing the records
679
+ // until `phase` is "ready".
680
+ await samva.email.getDomainVerification({ id: domain.id });
681
+ const verification = await samva.email.advanceDomainVerification({ id: domain.id });
682
+ console.log(verification.phase);
683
+
684
+ // Receive mail on a verified domain.
685
+ await samva.email.enableReceiving({ id: domain.id, catchAll: true });
686
+ const receiving = await samva.email.getReceivingStatus({ id: domain.id });
687
+ console.log(receiving.ready, receiving.mx.expected);
688
+
689
+ // Delete the domain. Removal finishes in the background: the domain reads `deleting: true`
690
+ // until teardown completes, then reads as not found.
691
+ await samva.email.removeDomain({ id: domain.id });
692
+ ```
693
+
694
+ `enableReceiving` on a domain that is not verified returns a `ValidationError`; check verification
695
+ first. The MX record `getReceivingStatus` reports is the one to publish for inbound mail. The same
696
+ steps over REST are `POST /v1/email/domains`, `GET /v1/email/domains/{id}/verification`,
697
+ `POST /v1/email/domains/{id}/verify`, `POST /v1/email/domains/{id}/enable-receiving`,
698
+ `GET /v1/email/domains/{id}/receiving-status`, and `DELETE /v1/email/domains/{id}`; authenticate
699
+ with the `X-API-Key` header.
700
+
573
701
  ### Schedule a Message
574
702
 
575
703
  ```typescript
@@ -713,6 +841,7 @@ const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });
713
841
 
714
842
  try {
715
843
  const message = await samva.email.send({
844
+ from: { email: "hello@yourdomain.com" },
716
845
  to: "ada@example.com",
717
846
  subject: "Test",
718
847
  html: "<p>Test</p>",
@@ -733,7 +862,7 @@ try {
733
862
 
734
863
  Every ergonomic method returns its decoded success value and throws a generated `SamvaApiError`
735
864
  subclass for failures declared by OpenAPI. Network and malformed-response failures throw
736
- `SamvaTransportError`.
865
+ `SamvaTransportError`; an attempt past its `timeoutMs` throws its subclass `SamvaTimeoutError`.
737
866
 
738
867
  ### Raw response access
739
868
 
@@ -762,6 +891,7 @@ const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });
762
891
  type EmailInput = Parameters<typeof samva.email.send>[0];
763
892
 
764
893
  const input = {
894
+ from: { email: "hello@yourdomain.com" },
765
895
  to: "ada@example.com",
766
896
  subject: "Hello",
767
897
  html: "<p>Hello World</p>",