@bernierllc/nevarmail 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.
package/README.md CHANGED
@@ -20,7 +20,7 @@ org may have been mailing into a `403` for months with nothing on either side no
20
20
  npm install @bernierllc/nevarmail
21
21
  ```
22
22
 
23
- Requires Node 20+ (uses the global `fetch`). Zero dependencies.
23
+ Server-side only; requires Node 20+ (uses global `fetch` and `crypto.randomUUID`). Never expose API credentials in browser code. Zero dependencies.
24
24
 
25
25
  ## Integration status
26
26
 
@@ -310,3 +310,45 @@ new NevarMail({
310
310
  fetch: undefined, // inject one for tests or a custom runtime
311
311
  });
312
312
  ```
313
+
314
+ ### Use-case groups and inherited settings
315
+
316
+ Create reusable project defaults with `createUseCaseGroup`, then create a use case with only its name and group ID. Groups allow suppressable, transactional, or mixed use cases; mixed groups have a default kind and separate tracking defaults per kind.
317
+
318
+ ```ts
319
+ const group = await mail.createUseCaseGroup({
320
+ name: "Account emails", projectId,
321
+ allowedKind: "transactional", defaultSuppressable: false,
322
+ defaults: {
323
+ shared: { fromName: { value: "Accounts" } },
324
+ suppressable: {}, transactional: { clickTracking: { value: false } },
325
+ },
326
+ });
327
+ const login = await mail.createUseCase({ name: "Login", groupId: group.id });
328
+ await mail.updateUseCase(login.id, {
329
+ expectedRevision: login.settingsRevision,
330
+ settings: { set: { replyToEmail: null }, inherit: ["fromName"] },
331
+ });
332
+ ```
333
+
334
+ An omitted override inherits; explicit `false` disables; explicit `null` clears a nullable field. `settings` on responses includes effective/configured values, source and override status. An override equal to the group value remains an override. Group defaults stay live for inheritors.
335
+
336
+ Use `listUseCaseGroups`, `getUseCaseGroup`, and `deleteUseCaseGroup` to manage groups. Delete returns `{id, deleted: true}` and refuses a group containing any members, including archived ones. To edit defaults, call `previewUseCaseGroupUpdate(id, {changes})`, review affected members, then `updateUseCaseGroup` with those changes, the preview's revision and token.
337
+
338
+ ```ts
339
+ const target = { groupId: destinationId }; // null means Ungrouped
340
+ const preview = await mail.previewUseCaseGroupMove(login.id, target);
341
+ // Show preview.rows and both outcomes to the user before applying.
342
+ const idempotencyKey = globalThis.crypto.randomUUID();
343
+ const moved = await mail.moveUseCaseToGroup(login.id, {
344
+ ...target, previewToken: preview.previewToken,
345
+ policy: "inherit_destination", // or "preserve_effective"
346
+ idempotencyKey,
347
+ });
348
+ ```
349
+
350
+ Moves retain existing overrides. `preserve_effective` additionally snapshots inherited values as overrides. A kind change supplies `suppressable` through the same preview/apply flow, not an ordinary metadata PATCH. Tokens expire after 15 minutes and are bound to the actor/scope; use the same credential for preview and apply. A stale preview returns 409 and is not retried: fetch another comparison and obtain confirmation again.
351
+
352
+ The move key is a UUID in the request body. Omission generates one once per SDK call, preserved across automatic retries. Retain and reuse an explicit key when retrying a whole call after an ambiguous network result. A committed retry returns its original result even after token expiry; reusing the key for a different move is a conflict.
353
+
354
+ Production transitions require `confirmation: {productionSending: true}` and server permissions/readiness. Enabling tracking for transactional mail requires `transactionalTracking: "transactional-tracking-v1"` after the user sees the disclosure. Never auto-confirm these choices. Tracking is resolved server-side; `SendEmailInput` has no tracking overrides. Keep API credentials server-side: app browser components use session routes.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export { NevarMailError } from "./errors.js";
2
+ export type * from "./use-case-groups.js";
3
+ import type { UseCaseSettingOverrides, UseCaseSettingsPatch, ResolvedUseCaseSettings, UseCaseSettingsConfirmation, UseCaseGroup, ListUseCaseGroupsOptions, CreateUseCaseGroupInput, UpdateUseCaseGroupInput, PreviewUseCaseGroupUpdateInput, UseCaseGroupUpdatePreview, PreviewUseCaseGroupMoveInput, UseCaseGroupMovePreview, MoveUseCaseToGroupInput, UseCaseGroupMoveResult } from "./use-case-groups.js";
2
4
  /** The v1 success envelope. `request()` unwraps `data` and returns it. */
3
5
  export interface V1Pagination {
4
6
  page: number;
@@ -470,6 +472,10 @@ export type UpdateSenderInput = Partial<Omit<CreateSenderInput, "projectId" | "f
470
472
  };
471
473
  /** A use case: the message category a project files mail under (`use_case_id` / `useCase` on a send). */
472
474
  export interface UseCase {
475
+ groupId?: string | null;
476
+ settingsRevision?: number;
477
+ overrides?: UseCaseSettingOverrides;
478
+ settings?: ResolvedUseCaseSettings;
473
479
  id: string;
474
480
  orgId: string;
475
481
  projectId: string;
@@ -501,17 +507,26 @@ export interface ListUseCasesOptions extends PageOptions {
501
507
  includeArchived?: boolean;
502
508
  }
503
509
  export interface CreateUseCaseInput {
510
+ /** Name plus groupId inherits its project, kind and settings. */
511
+ groupId?: string;
512
+ settings?: UseCaseSettingsPatch;
513
+ confirmation?: UseCaseSettingsConfirmation;
504
514
  name: string;
505
515
  /** Same rule as `createSender`: omit it only when the org has one project (400 `PROJECT_REQUIRED` otherwise). */
506
516
  projectId?: string;
507
517
  description?: string;
508
- /** Defaults to true. */
518
+ /** Uses the group default when grouped; otherwise defaults to true. */
509
519
  suppressable?: boolean;
510
520
  category?: string;
511
521
  }
512
522
  export interface UpdateUseCaseInput {
523
+ settings?: UseCaseSettingsPatch;
524
+ /** Required when settings is supplied. */
525
+ expectedRevision?: number;
526
+ confirmation?: UseCaseSettingsConfirmation;
513
527
  name?: string;
514
528
  description?: string;
529
+ /** Only the unchanged kind is accepted here; change kind via previewUseCaseGroupMove and moveUseCaseToGroup. */
515
530
  suppressable?: boolean;
516
531
  category?: string;
517
532
  /** The complete set of lists to link; lists not named are unlinked. */
@@ -1117,6 +1132,18 @@ export declare class NevarMail {
1117
1132
  deleteSender(id: string): Promise<{
1118
1133
  deleted: boolean;
1119
1134
  }>;
1135
+ /** List accessible groups, optionally restricted to a compatible use-case kind. */
1136
+ listUseCaseGroups(options?: ListUseCaseGroupsOptions): Promise<Paginated<UseCaseGroup>>;
1137
+ createUseCaseGroup(input: CreateUseCaseGroupInput): Promise<UseCaseGroup>;
1138
+ getUseCaseGroup(id: string): Promise<UseCaseGroup>;
1139
+ previewUseCaseGroupUpdate(id: string, input: PreviewUseCaseGroupUpdateInput): Promise<UseCaseGroupUpdatePreview>;
1140
+ updateUseCaseGroup(id: string, input: UpdateUseCaseGroupInput): Promise<UseCaseGroup>;
1141
+ deleteUseCaseGroup(id: string): Promise<{
1142
+ id: string;
1143
+ deleted: true;
1144
+ }>;
1145
+ previewUseCaseGroupMove(id: string, input: PreviewUseCaseGroupMoveInput): Promise<UseCaseGroupMovePreview>;
1146
+ moveUseCaseToGroup(id: string, input: MoveUseCaseToGroupInput): Promise<UseCaseGroupMoveResult>;
1120
1147
  /** GET /api/v1/use-cases — paged; every project the key can open, or `projectId`'s. */
1121
1148
  listUseCases(options?: ListUseCasesOptions): Promise<Paginated<UseCase>>;
1122
1149
  /** POST /api/v1/use-cases — 409 DUPLICATE_NAME when the name is taken in the project. */
package/dist/index.js CHANGED
@@ -547,6 +547,34 @@ export class NevarMail {
547
547
  deleteSender(id) {
548
548
  return this.request("DELETE", `/api/v1/senders/${encodeURIComponent(id)}`);
549
549
  }
550
+ /** List accessible groups, optionally restricted to a compatible use-case kind. */
551
+ listUseCaseGroups(options = {}) {
552
+ return this.requestPaginated("GET", "/api/v1/use-case-groups", { query: { ...options } });
553
+ }
554
+ createUseCaseGroup(input) {
555
+ return this.request("POST", "/api/v1/use-case-groups", { body: input });
556
+ }
557
+ getUseCaseGroup(id) {
558
+ return this.request("GET", `/api/v1/use-case-groups/${encodeURIComponent(id)}`);
559
+ }
560
+ previewUseCaseGroupUpdate(id, input) {
561
+ return this.request("POST", `/api/v1/use-case-groups/${encodeURIComponent(id)}/preview`, { body: input });
562
+ }
563
+ updateUseCaseGroup(id, input) {
564
+ return this.request("PATCH", `/api/v1/use-case-groups/${encodeURIComponent(id)}`, { body: input });
565
+ }
566
+ deleteUseCaseGroup(id) {
567
+ return this.request("DELETE", `/api/v1/use-case-groups/${encodeURIComponent(id)}`);
568
+ }
569
+ previewUseCaseGroupMove(id, input) {
570
+ return this.request("POST", `/api/v1/use-cases/${encodeURIComponent(id)}/group-move-preview`, { body: input });
571
+ }
572
+ moveUseCaseToGroup(id, input) {
573
+ // Construct once outside request's retry loop; callers can also retain a
574
+ // UUID across whole-call retries after an ambiguous network result.
575
+ const body = { ...input, idempotencyKey: input.idempotencyKey ?? globalThis.crypto.randomUUID() };
576
+ return this.request("POST", `/api/v1/use-cases/${encodeURIComponent(id)}/group-move`, { body });
577
+ }
550
578
  // ── Use cases ──────────────────────────────────────────────────────────
551
579
  /** GET /api/v1/use-cases — paged; every project the key can open, or `projectId`'s. */
552
580
  listUseCases(options = {}) {
@@ -0,0 +1,160 @@
1
+ /** Sending configuration resolved by NevarMail, never by the SDK. */
2
+ export interface UseCaseSettingValues {
3
+ domainId: string | null;
4
+ senderId: string | null;
5
+ fromName: string | null;
6
+ replyToEmail: string | null;
7
+ replyToName: string | null;
8
+ templateId: string | null;
9
+ sendMode: "test" | "production";
10
+ priority: "low" | "normal" | "high";
11
+ clickTracking: boolean;
12
+ openTracking: boolean;
13
+ googleAnalytics: boolean;
14
+ utmSource: string | null;
15
+ utmMedium: string | null;
16
+ utmCampaign: string | null;
17
+ utmTerm: string | null;
18
+ utmContent: string | null;
19
+ }
20
+ export type UseCaseSettingKey = keyof UseCaseSettingValues;
21
+ export type UseCaseSettingOverrides = {
22
+ [K in UseCaseSettingKey]?: {
23
+ value: UseCaseSettingValues[K];
24
+ };
25
+ };
26
+ export interface UseCaseSettingsPatch {
27
+ set?: Partial<UseCaseSettingValues>;
28
+ inherit?: UseCaseSettingKey[];
29
+ }
30
+ export type UseCaseSettingSource = "use_case" | "group" | "project" | "sender" | "product";
31
+ export type ResolvedUseCaseSetting<K extends UseCaseSettingKey = UseCaseSettingKey> = {
32
+ value: UseCaseSettingValues[K];
33
+ configuredValue: UseCaseSettingValues[K];
34
+ source: UseCaseSettingSource;
35
+ sourceId: string | null;
36
+ overridden: boolean;
37
+ constrainedBy: "project_analytics_disabled" | "test_credential" | null;
38
+ };
39
+ export type ResolvedUseCaseSettings = {
40
+ [K in UseCaseSettingKey]: ResolvedUseCaseSetting<K>;
41
+ };
42
+ export type UseCaseTrackingSettingKey = "clickTracking" | "openTracking" | "googleAnalytics" | "utmSource" | "utmMedium" | "utmCampaign" | "utmTerm" | "utmContent";
43
+ export interface UseCaseGroupDefaults {
44
+ shared: Omit<UseCaseSettingOverrides, UseCaseTrackingSettingKey>;
45
+ suppressable: Pick<UseCaseSettingOverrides, UseCaseTrackingSettingKey>;
46
+ transactional: Pick<UseCaseSettingOverrides, UseCaseTrackingSettingKey>;
47
+ }
48
+ export type UseCaseGroupKind = "suppressable" | "transactional" | "mixed";
49
+ export interface UseCaseSettingsConfirmation {
50
+ transactionalTracking?: "transactional-tracking-v1";
51
+ productionSending?: true;
52
+ }
53
+ export interface UseCaseGroupFields {
54
+ name: string;
55
+ allowedKind: UseCaseGroupKind;
56
+ defaultSuppressable: boolean;
57
+ defaults: UseCaseGroupDefaults;
58
+ }
59
+ export interface UseCaseGroup extends UseCaseGroupFields {
60
+ id: string;
61
+ orgId: string;
62
+ projectId: string;
63
+ revision: number;
64
+ createdAt: string;
65
+ updatedAt: string;
66
+ memberCount?: number;
67
+ archivedCount?: number;
68
+ members?: {
69
+ id: string;
70
+ name: string;
71
+ suppressable: boolean;
72
+ archivedAt: string | null;
73
+ }[];
74
+ }
75
+ export interface ListUseCaseGroupsOptions {
76
+ projectId?: string;
77
+ suppressable?: boolean;
78
+ page?: number;
79
+ perPage?: number;
80
+ }
81
+ export interface CreateUseCaseGroupInput extends UseCaseGroupFields {
82
+ projectId?: string;
83
+ confirmation?: UseCaseSettingsConfirmation;
84
+ }
85
+ export interface PreviewUseCaseGroupUpdateInput {
86
+ changes: Partial<UseCaseGroupFields>;
87
+ }
88
+ export interface UpdateUseCaseGroupInput extends PreviewUseCaseGroupUpdateInput {
89
+ expectedRevision: number;
90
+ /** Opaque, actor-scoped token, max 4096 characters; expires after 15 minutes. */
91
+ previewToken: string;
92
+ confirmation?: UseCaseSettingsConfirmation;
93
+ }
94
+ export interface UseCaseGroupUpdatePreview {
95
+ groupId: string;
96
+ revision: number;
97
+ changes: UseCaseGroupFields;
98
+ noOp: boolean;
99
+ projectMode: "test" | "production";
100
+ projectUpdatedAt: string;
101
+ affectedCount: number;
102
+ previewToken: string;
103
+ members: {
104
+ id: string;
105
+ name: string;
106
+ archived: boolean;
107
+ suppressable: boolean;
108
+ revision: number;
109
+ before: ResolvedUseCaseSettings;
110
+ after: ResolvedUseCaseSettings;
111
+ changedFields: UseCaseSettingKey[];
112
+ }[];
113
+ }
114
+ export interface PreviewUseCaseGroupMoveInput {
115
+ /** Null moves to Ungrouped. */
116
+ groupId: string | null;
117
+ /** A kind change uses this same comparison, even without changing groups. */
118
+ suppressable?: boolean;
119
+ }
120
+ export type UseCaseGroupMovePolicy = "inherit_destination" | "preserve_effective";
121
+ export interface MoveUseCaseToGroupInput extends PreviewUseCaseGroupMoveInput {
122
+ policy: UseCaseGroupMovePolicy;
123
+ /** Preview and apply must use the same credential. */
124
+ previewToken: string;
125
+ /** UUID. Omitted: generated once per call. Supplied values (including empty strings) are sent unchanged for server validation. Supply the same UUID for whole-call retries. */
126
+ idempotencyKey?: string;
127
+ confirmation?: UseCaseSettingsConfirmation;
128
+ }
129
+ export type UseCaseGroupMoveComparison = {
130
+ [K in UseCaseSettingKey]: {
131
+ key: K;
132
+ label: string;
133
+ current: ResolvedUseCaseSetting<K>;
134
+ destinationDefault: ResolvedUseCaseSetting<K>;
135
+ overridden: boolean;
136
+ inheritDestination: ResolvedUseCaseSetting<K>;
137
+ preserveEffective: ResolvedUseCaseSetting<K>;
138
+ };
139
+ }[UseCaseSettingKey];
140
+ export interface UseCaseGroupMovePreview {
141
+ useCaseId: string;
142
+ revision: number;
143
+ sourceGroupId: string | null;
144
+ destinationGroupId: string | null;
145
+ suppressable: boolean;
146
+ noOp: boolean;
147
+ rows: UseCaseGroupMoveComparison[];
148
+ current: ResolvedUseCaseSettings;
149
+ results: Record<UseCaseGroupMovePolicy, ResolvedUseCaseSettings>;
150
+ previewToken: string;
151
+ }
152
+ export interface UseCaseGroupMoveResult {
153
+ id: string;
154
+ groupId: string | null;
155
+ suppressable: boolean;
156
+ settingsRevision: number;
157
+ overrides: UseCaseSettingOverrides;
158
+ settings: ResolvedUseCaseSettings;
159
+ }
160
+ export type UseCaseGroupErrorCode = "GROUP_MOVE_STALE" | "GROUP_UPDATE_STALE" | "USE_CASE_SETTINGS_STALE" | "IDEMPOTENCY_KEY_CONFLICT" | "GROUP_NOT_EMPTY" | "GROUP_KIND_INCOMPATIBLE" | "GROUP_NAME_EXISTS" | "GROUP_PROJECT_MISMATCH" | "SETTING_REFERENCE_UNAVAILABLE" | "SENDER_DOMAIN_MISMATCH" | "REVISION_REQUIRED" | "USE_CASE_KIND_PREVIEW_REQUIRED" | "TRANSACTIONAL_TRACKING_CONFIRMATION_REQUIRED" | "PRODUCTION_CONFIRMATION_REQUIRED";
@@ -0,0 +1,6 @@
1
+ /*
2
+ Copyright (c) 2026 Bernier LLC
3
+ Licensed for use within the scope of the project it was delivered for.
4
+ Redistribution requires written consent from Bernier LLC.
5
+ */
6
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bernierllc/nevarmail",
3
- "version": "0.29.0",
3
+ "version": "0.30.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",