@bernierllc/nevarmail 0.9.0 → 0.11.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
@@ -149,8 +149,8 @@ Bounces, spam complaints and manual suppressions block every category regardless
149
149
  | `listScheduledEmails` | `GET /api/v1/email/schedule` | `email:send` |
150
150
  | `cancelScheduledEmail` | `DELETE /api/v1/email/schedule/{id}` | `email:send` |
151
151
  | `checkSuppression` | `GET /api/v1/suppressions/check` | `org:read` |
152
- | `getPreferences` | `GET /api/v1/preferences` | `contacts:read` |
153
- | `setPreferences` | `PUT /api/v1/preferences` | `contacts:write` |
152
+ | `getPreferences(email, projectId?)` — one address's lists in one project; `projectId` required when the org has more than one | `GET /api/v1/preferences` | `contacts:read` |
153
+ | `setPreferences(email, { subscribedListIds, unsubscribeAll, projectId? })` — the complete set of lists to stay on | `PUT /api/v1/preferences` | `contacts:write` |
154
154
  | `listTemplates` / `createTemplate` / `getTemplate` / `updateTemplate` / `deleteTemplate` | `/api/v1/templates` | `templates:read` / `templates:write` |
155
155
  | `renderTemplate` | `POST /api/v1/templates/{id}/render` | `templates:read` |
156
156
  | `listLists` / `createList` / `getList` | `/api/v1/lists` | `contacts:read` / `contacts:write` |
package/dist/index.d.ts CHANGED
@@ -89,18 +89,36 @@ export interface SuppressionCheck {
89
89
  /** Absent when nothing is suppressed. */
90
90
  reason?: SuppressionReason;
91
91
  }
92
- export interface UseCasePreference {
93
- useCaseId: string;
92
+ export interface ListPreference {
93
+ listId: string;
94
94
  name: string;
95
95
  description: string | null;
96
- category: string | null;
97
96
  subscribed: boolean;
97
+ /**
98
+ * The sender suppressed this list for the address (a list-scoped manual
99
+ * suppression): off, and not the recipient's to turn on. Including it in
100
+ * `subscribedListIds` is a 409 LIST_BLOCKED.
101
+ */
102
+ blocked: boolean;
98
103
  }
104
+ /**
105
+ * One address's lists in one project: only the lists it is on or has left —
106
+ * an address never mailed gets `lists: []`, not the project's whole catalogue.
107
+ */
99
108
  export interface RecipientPreferences {
100
109
  email: string;
110
+ senderName: string;
101
111
  unsubscribedAll: boolean;
102
112
  deliverable: boolean;
103
- useCases: UseCasePreference[];
113
+ lists: ListPreference[];
114
+ }
115
+ export interface SetPreferencesInput {
116
+ /** COMPLETE set of the shown lists to stay on; every other shown list is left. */
117
+ subscribedListIds: string[];
118
+ /** Stop all email from the project. Cannot be combined with list ids. */
119
+ unsubscribeAll: boolean;
120
+ /** Required when the org has more than one project. */
121
+ projectId?: string;
104
122
  }
105
123
  /** Accepted by every list method. The server clamps `perPage` to 1–100 (default 25). */
106
124
  export interface PageOptions {
@@ -153,6 +171,12 @@ export interface SubscriberList {
153
171
  orgId: string;
154
172
  name: string;
155
173
  description: string | null;
174
+ /**
175
+ * @deprecated since 0.10.0; removed in 1.0.0; no replacement. A list
176
+ * opt-out applies to that list; a project-wide opt-out is its own
177
+ * suppression. The API no longer returns this field; the client fills it
178
+ * with `"list"` when the server leaves it out.
179
+ */
156
180
  unsubScope: string;
157
181
  unsubHandler: string;
158
182
  customUnsubHtml: string | null;
@@ -181,6 +205,10 @@ export interface SubscriberList {
181
205
  export interface CreateListInput {
182
206
  name: string;
183
207
  description?: string;
208
+ /**
209
+ * @deprecated since 0.10.0; removed in 1.0.0; no replacement. The API
210
+ * ignores it: a list opt-out always applies to that list.
211
+ */
184
212
  unsubScope?: "list" | "global";
185
213
  unsubHandler?: "provider" | "hosted" | "custom_html";
186
214
  storageTier?: "provider" | "byo_database" | "local";
@@ -438,13 +466,18 @@ export declare class NevarMail {
438
466
  * opt-out of the project counts.
439
467
  */
440
468
  checkSuppression(email: string, useCaseId?: string, projectId?: string): Promise<SuppressionCheck>;
441
- /** GET /api/v1/preferences — one recipient's per-category subscriptions. */
442
- getPreferences(email: string): Promise<RecipientPreferences>;
443
469
  /**
444
- * PUT /api/v1/preferences — a COMPLETE set, not a delta: any suppressable
445
- * category missing from `subscribedUseCaseIds` is treated as opted out.
470
+ * GET /api/v1/preferences — one recipient's lists in one project. `projectId`
471
+ * is required when the org has more than one project (400 PROJECT_REQUIRED).
472
+ */
473
+ getPreferences(email: string, projectId?: string): Promise<RecipientPreferences>;
474
+ /**
475
+ * PUT /api/v1/preferences — a COMPLETE set, not a delta: any shown list
476
+ * missing from `subscribedListIds` is left. Turning a list back on releases
477
+ * the opt-out but does not re-add the address to the list. A `blocked`
478
+ * list cannot be turned on: 409 LIST_BLOCKED.
446
479
  */
447
- setPreferences(email: string, subscribedUseCaseIds: string[]): Promise<RecipientPreferences>;
480
+ setPreferences(email: string, input: SetPreferencesInput): Promise<RecipientPreferences>;
448
481
  /** GET /api/v1/templates — paged; the route ignores search/category filters today. */
449
482
  listTemplates(options?: PageOptions): Promise<Paginated<Template>>;
450
483
  /** POST /api/v1/templates */
package/dist/index.js CHANGED
@@ -34,13 +34,15 @@ function sleep(ms) {
34
34
  }
35
35
  /**
36
36
  * Fills `useCaseId` and the deprecated `campaignId` from whichever the server
37
- * sent, so a pre-rename server still works; delete in 1.0.0.
37
+ * sent, so a pre-rename server still works, and the deprecated `unsubScope`
38
+ * the server no longer sends; delete in 1.0.0.
38
39
  */
40
+ let warnedUnsubScope = false;
39
41
  function withListAliases(list) {
40
42
  if (!list || typeof list !== "object")
41
43
  return list;
42
44
  const useCaseId = list.useCaseId ?? list.campaignId ?? null;
43
- return { ...list, useCaseId, campaignId: useCaseId };
45
+ return { ...list, useCaseId, campaignId: useCaseId, unsubScope: list.unsubScope ?? "list" };
44
46
  }
45
47
  export class NevarMail {
46
48
  baseUrl;
@@ -227,17 +229,35 @@ export class NevarMail {
227
229
  query: { email, use_case_id: useCaseId, project_id: projectId },
228
230
  });
229
231
  }
230
- /** GET /api/v1/preferences — one recipient's per-category subscriptions. */
231
- getPreferences(email) {
232
- return this.request("GET", "/api/v1/preferences", { query: { email } });
232
+ /**
233
+ * GET /api/v1/preferences — one recipient's lists in one project. `projectId`
234
+ * is required when the org has more than one project (400 PROJECT_REQUIRED).
235
+ */
236
+ getPreferences(email, projectId) {
237
+ return this.request("GET", "/api/v1/preferences", {
238
+ query: { email, project_id: projectId },
239
+ });
233
240
  }
234
241
  /**
235
- * PUT /api/v1/preferences — a COMPLETE set, not a delta: any suppressable
236
- * category missing from `subscribedUseCaseIds` is treated as opted out.
242
+ * PUT /api/v1/preferences — a COMPLETE set, not a delta: any shown list
243
+ * missing from `subscribedListIds` is left. Turning a list back on releases
244
+ * the opt-out but does not re-add the address to the list. A `blocked`
245
+ * list cannot be turned on: 409 LIST_BLOCKED.
237
246
  */
238
- setPreferences(email, subscribedUseCaseIds) {
247
+ setPreferences(email, input) {
248
+ // The pre-list form took a use-case id array. The server contract it
249
+ // targeted is gone, so no alias can keep it working; fail loudly instead
250
+ // of sending `{ email }` alone.
251
+ if (Array.isArray(input)) {
252
+ return Promise.reject(new NevarMailError("setPreferences(email, useCaseIds[]) was removed: pass { subscribedListIds, unsubscribeAll, projectId? }.", { status: 0, code: "PREFERENCES_INPUT_CHANGED" }));
253
+ }
239
254
  return this.request("PUT", "/api/v1/preferences", {
240
- body: { email, subscribed_use_case_ids: subscribedUseCaseIds },
255
+ body: {
256
+ email,
257
+ project_id: input.projectId,
258
+ subscribed_list_ids: input.subscribedListIds,
259
+ unsubscribe_all: input.unsubscribeAll,
260
+ },
241
261
  });
242
262
  }
243
263
  // ── Templates ──────────────────────────────────────────────────────────
@@ -281,6 +301,11 @@ export class NevarMail {
281
301
  }
282
302
  /** POST /api/v1/lists — 409 DUPLICATE_NAME on a name the org already uses. */
283
303
  async createList(input) {
304
+ if (input.unsubScope !== undefined && !warnedUnsubScope) {
305
+ warnedUnsubScope = true;
306
+ console.warn("@bernierllc/nevarmail: createList unsubScope is deprecated and ignored by the API; " +
307
+ "an unsubscribe is scoped to its list and project. It is removed in 1.0.0.");
308
+ }
284
309
  return withListAliases(await this.request("POST", "/api/v1/lists", { body: input }));
285
310
  }
286
311
  /** GET /api/v1/lists/{id} — the v1 surface has no list update/delete routes. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bernierllc/nevarmail",
3
- "version": "0.9.0",
3
+ "version": "0.11.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",