@bernierllc/nevarmail 0.16.0 → 0.18.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/README.md CHANGED
@@ -139,6 +139,11 @@ suppression blocks only its own.
139
139
  Bounces, spam complaints and manual suppressions block every category regardless. Only a
140
140
  `use_case_id` you passed yourself can narrow a block; a default the server resolves cannot.
141
141
 
142
+ `sendEmail` also takes the use case by slug — `useCase: "receipts"` — instead of its id (one of
143
+ the two, not both). The slug must exist in exactly one project the key can open: unknown is a
144
+ 404, the same slug in several projects is `400 USE_CASE_AMBIGUOUS` (pass `use_case_id` then).
145
+ `listUseCases` shows the slugs.
146
+
142
147
  ## Methods
143
148
 
144
149
  | Method | Route | Scope |
@@ -160,11 +165,14 @@ Bounces, spam complaints and manual suppressions block every category regardless
160
165
  | `listContacts` / `upsertContacts` / `updateContact` / `deleteContact` | `/api/v1/contacts` | `contacts:read` / `contacts:write` |
161
166
  | `listSenders` / `createSender(input)` — `input.projectId?` targets a project when the org has more than one | `/api/v1/senders` | `senders:read` / `senders:write` |
162
167
  | `getSender` / `updateSender` / `deleteSender` | `/api/v1/senders/{id}` | `senders:read` / `senders:write` |
168
+ | `listUseCases({ projectId?, includeArchived? })` / `createUseCase(input)` — `input.projectId?` as for `createSender` | `/api/v1/use-cases` | `use-cases:read` / `use-cases:write` |
169
+ | `getUseCase` / `updateUseCase` / `archiveUseCase` / `restoreUseCase` — delete archives; restore undoes it | `/api/v1/use-cases/{id}` | `use-cases:read` / `use-cases:write` |
163
170
  | `importSenders({ projectId? })` — adopts the project's provider-account identities; re-run to pick up provider verification | `POST /api/v1/senders/import` | `senders:write` |
164
171
  | `listDomains` / `createDomain(domain, { projectId })` / `getDomain` / `deleteDomain` | `/api/v1/domains` | `domains:read` / `domains:write` |
165
172
  | `getDomainDnsRecords` / `verifyDomain` | `/api/v1/domains/{id}/…` | `domains:read` / `domains:write` |
166
173
  | `listSuppressions` / `addSuppressions` | `/api/v1/suppressions` | `org:read` / `org:write` |
167
174
  | `getProjectAddress(projectId)` / `setProjectAddress(projectId, { physicalAddress, addressComponents? })` | `GET` / `PUT /api/v1/projects/{id}/address` | `org:read` / `org:write` |
175
+ | `getProjectMarketing(projectId)` / `setProjectMarketing(projectId, { marketingEnabled })` | `GET` / `PUT /api/v1/projects/{id}/marketing` | `org:read` / `org:write` |
168
176
  | `getInboxDbStatus` | `GET /api/v1/inbox-db/status` | `org:read` |
169
177
  | `connectInboxDb({ connectionString, provider? })` / `testInboxDbConnection` | `POST /api/v1/inbox-db/connection` / `…/connection/test` | `org:write` |
170
178
 
package/dist/index.d.ts CHANGED
@@ -33,6 +33,12 @@ export interface SendEmailInput {
33
33
  * omit it and every active suppression row applies. See the README.
34
34
  */
35
35
  use_case_id?: string;
36
+ /**
37
+ * The use case by SLUG instead of id (sent as `use_case`; pass one of the
38
+ * two, not both). The slug must exist in exactly one project the key can
39
+ * open: 404 when none, 400 `USE_CASE_AMBIGUOUS` when several.
40
+ */
41
+ useCase?: string;
36
42
  }
37
43
  export interface SendToListResult {
38
44
  id: string;
@@ -62,7 +68,7 @@ export interface SendToListInput {
62
68
  tags?: string[];
63
69
  use_case_id?: string;
64
70
  }
65
- export interface ScheduleEmailInput extends Omit<SendEmailInput, "templateId" | "variables"> {
71
+ export interface ScheduleEmailInput extends Omit<SendEmailInput, "templateId" | "variables" | "useCase"> {
66
72
  /**
67
73
  * An instant, not a wall-clock guess: the offset is mandatory (`Z` or
68
74
  * `±HH:MM`). The API rejects a bare local time rather than guessing a zone.
@@ -327,6 +333,7 @@ export interface Sender {
327
333
  }
328
334
  export interface CreateSenderInput {
329
335
  name: string;
336
+ /** Must be on a verified sending domain of the sender's project, else 400 `VALIDATION_ERROR`. */
330
337
  fromEmail: string;
331
338
  fromName?: string;
332
339
  replyToEmail?: string;
@@ -341,8 +348,69 @@ export interface CreateSenderInput {
341
348
  */
342
349
  projectId?: string;
343
350
  }
344
- /** A sender stays in the project it was created in, so `projectId` is create-only. */
345
- export type UpdateSenderInput = Partial<Omit<CreateSenderInput, "projectId">>;
351
+ /**
352
+ * A sender stays in the project it was created in, so `projectId` is create-only.
353
+ * `isActive: false` switches the sender off: it is never resolved for a send, and if
354
+ * it was the project default the default passes to the oldest usable sender.
355
+ * A sender linked to a provider identity (`providerSenderId`) keeps its `fromEmail`:
356
+ * changing it returns 400 `VALIDATION_ERROR` unless the same update relinks it (new `providerSenderId`).
357
+ * An omitted field is left as it is; `null` clears `fromName`, `replyToEmail` or `provider`.
358
+ */
359
+ export type UpdateSenderInput = Partial<Omit<CreateSenderInput, "projectId" | "fromName" | "replyToEmail" | "provider">> & {
360
+ fromName?: string | null;
361
+ replyToEmail?: string | null;
362
+ provider?: string | null;
363
+ isActive?: boolean;
364
+ };
365
+ /** A use case: the message category a project files mail under (`use_case_id` / `useCase` on a send). */
366
+ export interface UseCase {
367
+ id: string;
368
+ orgId: string;
369
+ projectId: string;
370
+ name: string;
371
+ /** Unique within the project; what `sendEmail({ useCase })` names. */
372
+ slug: string | null;
373
+ description: string | null;
374
+ /** Whether recipients may opt out of this use case. */
375
+ suppressable: boolean;
376
+ category: string | null;
377
+ /** The project's default: sends that name no use case file under it. Never settable through the API. */
378
+ isDefault: boolean;
379
+ isSystem: boolean;
380
+ domainId: string | null;
381
+ senderId: string | null;
382
+ archivedAt: string | null;
383
+ createdAt: string;
384
+ updatedAt: string;
385
+ /** Linked lists; present on `getUseCase` and `updateUseCase`. */
386
+ lists?: {
387
+ id: string;
388
+ name: string;
389
+ }[];
390
+ }
391
+ export interface ListUseCasesOptions extends PageOptions {
392
+ /** Only this project's use cases. */
393
+ projectId?: string;
394
+ /** Include archived use cases. */
395
+ includeArchived?: boolean;
396
+ }
397
+ export interface CreateUseCaseInput {
398
+ name: string;
399
+ /** Same rule as `createSender`: omit it only when the org has one project (400 `PROJECT_REQUIRED` otherwise). */
400
+ projectId?: string;
401
+ description?: string;
402
+ /** Defaults to true. */
403
+ suppressable?: boolean;
404
+ category?: string;
405
+ }
406
+ export interface UpdateUseCaseInput {
407
+ name?: string;
408
+ description?: string;
409
+ suppressable?: boolean;
410
+ category?: string;
411
+ /** The complete set of lists to link; lists not named are unlinked. */
412
+ listIds?: string[];
413
+ }
346
414
  /** Result of `importSenders`: counts per outcome, then the project's senders. */
347
415
  export interface ImportSendersResult {
348
416
  /** Provider identities with no NevarMail sender yet — created. */
@@ -352,6 +420,8 @@ export interface ImportSendersResult {
352
420
  /** Already-imported senders whose address or verification changed at the provider. */
353
421
  refreshed: number;
354
422
  unchanged: number;
423
+ /** Linked senders whose identity is gone from the provider — marked `not_at_provider`, never selected. */
424
+ missing: number;
355
425
  senders: Sender[];
356
426
  }
357
427
  export interface DnsRecord {
@@ -529,6 +599,10 @@ export interface SetProjectAddressInput {
529
599
  /** Omitted or null clears any stored parts. Max 30. */
530
600
  addressComponents?: AddressComponent[] | null;
531
601
  }
602
+ /** A project's marketing switch: while off, every marketing send from the project is refused. */
603
+ export interface ProjectMarketing {
604
+ marketingEnabled: boolean;
605
+ }
532
606
  export interface NevarMailOptions {
533
607
  /**
534
608
  * A REST API key (`nvm_api_live_…` / `nvm_api_test_…`). An MCP key is
@@ -711,10 +785,30 @@ export declare class NevarMail {
711
785
  getSender(id: string): Promise<Sender>;
712
786
  /** PATCH /api/v1/senders/{id} — a partial update; the route has no PUT. */
713
787
  updateSender(id: string, input: UpdateSenderInput): Promise<Sender>;
714
- /** DELETE /api/v1/senders/{id} — 404 NOT_FOUND. */
788
+ /**
789
+ * DELETE /api/v1/senders/{id} — 404 NOT_FOUND. A sender linked to a provider identity
790
+ * (`providerSenderId`) returns 400 `VALIDATION_ERROR`: a re-sync would bring it back, so
791
+ * switch it off (`isActive: false`), or delete the identity at the provider and call
792
+ * `importSenders`, which marks it `not_at_provider`; after that it can be deleted.
793
+ */
715
794
  deleteSender(id: string): Promise<{
716
795
  deleted: boolean;
717
796
  }>;
797
+ /** GET /api/v1/use-cases — paged; every project the key can open, or `projectId`'s. */
798
+ listUseCases(options?: ListUseCasesOptions): Promise<Paginated<UseCase>>;
799
+ /** POST /api/v1/use-cases — 409 DUPLICATE_NAME when the name is taken in the project. */
800
+ createUseCase(input: CreateUseCaseInput): Promise<UseCase>;
801
+ /** GET /api/v1/use-cases/{id} — 404 NOT_FOUND; archived rows are returned too. */
802
+ getUseCase(id: string): Promise<UseCase>;
803
+ /** PATCH /api/v1/use-cases/{id} — partial; 409 USE_CASE_ARCHIVED until restored. */
804
+ updateUseCase(id: string, input: UpdateUseCaseInput): Promise<UseCase>;
805
+ /**
806
+ * DELETE /api/v1/use-cases/{id} — ARCHIVES (nothing is deleted; `restoreUseCase`
807
+ * undoes it). 409 IS_DEFAULT for the project default.
808
+ */
809
+ archiveUseCase(id: string): Promise<UseCase>;
810
+ /** POST /api/v1/use-cases/{id}/restore — idempotent on an active use case. */
811
+ restoreUseCase(id: string): Promise<UseCase>;
718
812
  /** GET /api/v1/domains — paged; list rows carry extras single reads do not. */
719
813
  listDomains(options?: PageOptions): Promise<Paginated<Domain>>;
720
814
  /**
@@ -754,6 +848,14 @@ export declare class NevarMail {
754
848
  * marketing send is refused without one. Blank: 422 `PHYSICAL_ADDRESS_REQUIRED`.
755
849
  */
756
850
  setProjectAddress(projectId: string, input: SetProjectAddressInput): Promise<ProjectAddress>;
851
+ /** GET /api/v1/projects/{id}/marketing — scope `org:read`; 404 NOT_FOUND for a project the key's user can't open. */
852
+ getProjectMarketing(projectId: string): Promise<ProjectMarketing>;
853
+ /**
854
+ * PUT /api/v1/projects/{id}/marketing — scope `org:write`. Turns marketing
855
+ * mail on or off for the project. Turning it on while the project's postal
856
+ * address is blank: 422 `PHYSICAL_ADDRESS_REQUIRED` (set it with `setProjectAddress`).
857
+ */
858
+ setProjectMarketing(projectId: string, input: ProjectMarketing): Promise<ProjectMarketing>;
757
859
  /** GET /api/v1/inbox-db/status — scope `org:read`; 404 when no connection is stored. */
758
860
  getInboxDbStatus(): Promise<InboxDbStatus>;
759
861
  /**
package/dist/index.js CHANGED
@@ -203,7 +203,10 @@ export class NevarMail {
203
203
  * a 409 LIST_UNSUB_PAGE_MISSING; the message names where to save one.
204
204
  */
205
205
  sendEmail(input) {
206
- return this.request("POST", "/api/v1/email/send", { body: input });
206
+ const { useCase, ...body } = input;
207
+ return this.request("POST", "/api/v1/email/send", {
208
+ body: useCase === undefined ? body : { ...body, use_case: useCase },
209
+ });
207
210
  }
208
211
  /**
209
212
  * POST /api/v1/email/send-to-list — one message to every contact on a list.
@@ -420,10 +423,48 @@ export class NevarMail {
420
423
  body: input,
421
424
  });
422
425
  }
423
- /** DELETE /api/v1/senders/{id} — 404 NOT_FOUND. */
426
+ /**
427
+ * DELETE /api/v1/senders/{id} — 404 NOT_FOUND. A sender linked to a provider identity
428
+ * (`providerSenderId`) returns 400 `VALIDATION_ERROR`: a re-sync would bring it back, so
429
+ * switch it off (`isActive: false`), or delete the identity at the provider and call
430
+ * `importSenders`, which marks it `not_at_provider`; after that it can be deleted.
431
+ */
424
432
  deleteSender(id) {
425
433
  return this.request("DELETE", `/api/v1/senders/${encodeURIComponent(id)}`);
426
434
  }
435
+ // ── Use cases ──────────────────────────────────────────────────────────
436
+ /** GET /api/v1/use-cases — paged; every project the key can open, or `projectId`'s. */
437
+ listUseCases(options = {}) {
438
+ const { includeArchived, ...rest } = options;
439
+ return this.requestPaginated("GET", "/api/v1/use-cases", {
440
+ query: { ...rest, includeArchived: includeArchived ? "1" : undefined },
441
+ });
442
+ }
443
+ /** POST /api/v1/use-cases — 409 DUPLICATE_NAME when the name is taken in the project. */
444
+ createUseCase(input) {
445
+ return this.request("POST", "/api/v1/use-cases", { body: input });
446
+ }
447
+ /** GET /api/v1/use-cases/{id} — 404 NOT_FOUND; archived rows are returned too. */
448
+ getUseCase(id) {
449
+ return this.request("GET", `/api/v1/use-cases/${encodeURIComponent(id)}`);
450
+ }
451
+ /** PATCH /api/v1/use-cases/{id} — partial; 409 USE_CASE_ARCHIVED until restored. */
452
+ updateUseCase(id, input) {
453
+ return this.request("PATCH", `/api/v1/use-cases/${encodeURIComponent(id)}`, {
454
+ body: input,
455
+ });
456
+ }
457
+ /**
458
+ * DELETE /api/v1/use-cases/{id} — ARCHIVES (nothing is deleted; `restoreUseCase`
459
+ * undoes it). 409 IS_DEFAULT for the project default.
460
+ */
461
+ archiveUseCase(id) {
462
+ return this.request("DELETE", `/api/v1/use-cases/${encodeURIComponent(id)}`);
463
+ }
464
+ /** POST /api/v1/use-cases/{id}/restore — idempotent on an active use case. */
465
+ restoreUseCase(id) {
466
+ return this.request("POST", `/api/v1/use-cases/${encodeURIComponent(id)}/restore`);
467
+ }
427
468
  // ── Domains ────────────────────────────────────────────────────────────
428
469
  /** GET /api/v1/domains — paged; list rows carry extras single reads do not. */
429
470
  listDomains(options = {}) {
@@ -489,6 +530,18 @@ export class NevarMail {
489
530
  setProjectAddress(projectId, input) {
490
531
  return this.request("PUT", `/api/v1/projects/${encodeURIComponent(projectId)}/address`, { body: input });
491
532
  }
533
+ /** GET /api/v1/projects/{id}/marketing — scope `org:read`; 404 NOT_FOUND for a project the key's user can't open. */
534
+ getProjectMarketing(projectId) {
535
+ return this.request("GET", `/api/v1/projects/${encodeURIComponent(projectId)}/marketing`);
536
+ }
537
+ /**
538
+ * PUT /api/v1/projects/{id}/marketing — scope `org:write`. Turns marketing
539
+ * mail on or off for the project. Turning it on while the project's postal
540
+ * address is blank: 422 `PHYSICAL_ADDRESS_REQUIRED` (set it with `setProjectAddress`).
541
+ */
542
+ setProjectMarketing(projectId, input) {
543
+ return this.request("PUT", `/api/v1/projects/${encodeURIComponent(projectId)}/marketing`, { body: input });
544
+ }
492
545
  // ── Inbox database ─────────────────────────────────────────────────────
493
546
  /** GET /api/v1/inbox-db/status — scope `org:read`; 404 when no connection is stored. */
494
547
  getInboxDbStatus() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bernierllc/nevarmail",
3
- "version": "0.16.0",
3
+ "version": "0.18.0",
4
4
  "description": "Official client for the NevarMail v1 API. Typed, retries 429/5xx, throws NevarMailError on every non-2xx.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",