@bernierllc/nevarmail 0.14.0 → 0.16.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
@@ -153,6 +153,8 @@ Bounces, spam complaints and manual suppressions block every category regardless
153
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
+ | `listCampaigns({ projectId?, page?, perPage? })` / `getCampaign(id, { projectId? })` — read-only | `GET /api/v1/campaigns`, `GET /api/v1/campaigns/{id}` | `campaigns:read` |
157
+ | `getCampaignAnalytics(id, { projectId? })` — counts plus delivery/open/click/bounce/unsubscribe rates (0 to 1) | `GET /api/v1/campaigns/{id}/analytics` | `analytics:read` |
156
158
  | `listLists` / `createList` / `getList` | `/api/v1/lists` | `contacts:read` / `contacts:write` |
157
159
  | `addListContacts` | `POST /api/v1/lists/{id}/contacts` | `contacts:write` |
158
160
  | `listContacts` / `upsertContacts` / `updateContact` / `deleteContact` | `/api/v1/contacts` | `contacts:read` / `contacts:write` |
@@ -162,6 +164,7 @@ Bounces, spam complaints and manual suppressions block every category regardless
162
164
  | `listDomains` / `createDomain(domain, { projectId })` / `getDomain` / `deleteDomain` | `/api/v1/domains` | `domains:read` / `domains:write` |
163
165
  | `getDomainDnsRecords` / `verifyDomain` | `/api/v1/domains/{id}/…` | `domains:read` / `domains:write` |
164
166
  | `listSuppressions` / `addSuppressions` | `/api/v1/suppressions` | `org:read` / `org:write` |
167
+ | `getProjectAddress(projectId)` / `setProjectAddress(projectId, { physicalAddress, addressComponents? })` | `GET` / `PUT /api/v1/projects/{id}/address` | `org:read` / `org:write` |
165
168
  | `getInboxDbStatus` | `GET /api/v1/inbox-db/status` | `org:read` |
166
169
  | `connectInboxDb({ connectionString, provider? })` / `testInboxDbConnection` | `POST /api/v1/inbox-db/connection` / `…/connection/test` | `org:write` |
167
170
 
@@ -172,6 +175,12 @@ Application-level details worth knowing before you hit them:
172
175
  calling a list route, so it is not unwrapped away. Single-resource methods return the payload
173
176
  directly, same as the send methods.
174
177
  - **Updates are `PATCH`, and partial.** Send only the fields you are changing.
178
+ - **Campaign reads take an optional `projectId`.** Omit it only when the org has one project;
179
+ otherwise the server answers 400 `PROJECT_REQUIRED`. A campaign in another project is a 404
180
+ `NOT_FOUND`, same as a missing one. An org with no project gets 422 `NO_PROJECT`; one with no
181
+ marketing provider gets 404 `NO_MARKETING_PROVIDER`. `listCampaigns` filters after the provider's page, so a page
182
+ can hold fewer than `perPage` rows. The analytics route needs `analytics:read`, not
183
+ `campaigns:read`.
175
184
  - **`renderTemplate(id, variables)` sends the variables map as the whole body** — not wrapped in
176
185
  a `variables` key.
177
186
  - **`deleteTemplate` never 404s**: an unknown id resolves `{ deleted: false }` on a 200. Every
@@ -183,7 +192,7 @@ Application-level details worth knowing before you hit them:
183
192
  - **Managed accounts cannot delete domains** — `deleteDomain` throws `403 MANAGED_ACCOUNT`.
184
193
  - **The inbox-db connection string is sent once and never echoed.** `connectInboxDb` stores it encrypted; `InboxDbStatus` omits it. `schemaName` is the Postgres schema NevarMail owns in your database.
185
194
 
186
- Anything still not covered — analytics, campaigns, webhook endpoints — goes through
195
+ Anything still not covered — analytics summaries, webhook endpoints — goes through
187
196
  `request()` (or `requestPaginated()` for list routes), which applies the same auth, envelope
188
197
  unwrapping, throwing, and retries:
189
198
 
package/dist/index.d.ts CHANGED
@@ -130,6 +130,53 @@ export interface Paginated<T> {
130
130
  data: T[];
131
131
  pagination: V1Pagination;
132
132
  }
133
+ /** Delivery counters for one campaign, as the provider reports them. */
134
+ export interface CampaignStats {
135
+ sent: number;
136
+ delivered: number;
137
+ opens: number;
138
+ clicks: number;
139
+ bounces: number;
140
+ unsubscribes: number;
141
+ }
142
+ /** A marketing campaign as listed by `listCampaigns`. Timestamps are ISO strings. */
143
+ export interface CampaignSummary {
144
+ id: string;
145
+ name: string;
146
+ subject: string;
147
+ status: "draft" | "scheduled" | "sending" | "sent" | "cancelled" | "unknown";
148
+ listId: string | null;
149
+ sendAt: string | null;
150
+ sentAt: string | null;
151
+ createdAt: string | null;
152
+ }
153
+ /** One campaign with its body and counters. `stats` is null until the provider reports them. */
154
+ export interface Campaign extends CampaignSummary {
155
+ htmlContent: string | null;
156
+ stats: CampaignStats | null;
157
+ }
158
+ /** Counts plus derived rates (0 to 1, 0 when the denominator is 0). All numbers. */
159
+ export interface CampaignAnalytics {
160
+ campaignId: string;
161
+ campaignName: string;
162
+ status: CampaignSummary["status"];
163
+ sent: number;
164
+ delivered: number;
165
+ opens: number;
166
+ clicks: number;
167
+ bounces: number;
168
+ unsubscribes: number;
169
+ /** delivered / sent */
170
+ deliveryRate: number;
171
+ /** opens / delivered */
172
+ openRate: number;
173
+ /** clicks / delivered */
174
+ clickRate: number;
175
+ /** bounces / sent */
176
+ bounceRate: number;
177
+ /** unsubscribes / delivered */
178
+ unsubscribeRate: number;
179
+ }
133
180
  export interface TemplateVariable {
134
181
  name: string;
135
182
  type: string;
@@ -458,6 +505,30 @@ export interface ConnectInboxDbInput {
458
505
  /** Defaults to `byo`. */
459
506
  provider?: InboxDbProvider;
460
507
  }
508
+ /** One structured part of a postal address (Places-style `addressComponents`). */
509
+ export interface AddressComponent {
510
+ longText: string;
511
+ shortText: string;
512
+ types: string[];
513
+ languageCode?: string;
514
+ }
515
+ /** A project's CAN-SPAM postal address, the one its marketing mail's footer prints. */
516
+ export interface ProjectAddress {
517
+ physicalAddress: string;
518
+ addressComponents: AddressComponent[] | null;
519
+ }
520
+ /** `getProjectAddress`: the project's address plus the org's as a suggestion. */
521
+ export interface ProjectAddressWithOrg extends ProjectAddress {
522
+ /** Empty when the org has no address set. */
523
+ orgPhysicalAddress: string;
524
+ orgAddressComponents: AddressComponent[] | null;
525
+ }
526
+ export interface SetProjectAddressInput {
527
+ /** Never blank: 422 `PHYSICAL_ADDRESS_REQUIRED`. Trimmed; max 500 chars. */
528
+ physicalAddress: string;
529
+ /** Omitted or null clears any stored parts. Max 30. */
530
+ addressComponents?: AddressComponent[] | null;
531
+ }
461
532
  export interface NevarMailOptions {
462
533
  /**
463
534
  * A REST API key (`nvm_api_live_…` / `nvm_api_test_…`). An MCP key is
@@ -561,6 +632,36 @@ export declare class NevarMail {
561
632
  * no wrapper key. Unknown template: 404 NOT_FOUND.
562
633
  */
563
634
  renderTemplate(id: string, variables?: Record<string, unknown>): Promise<RenderedTemplate>;
635
+ /**
636
+ * GET /api/v1/campaigns — paged; scope `campaigns:read`. Returns the
637
+ * project's campaigns plus those in no project. `projectId` may be omitted
638
+ * only when the org has one project (else 400 `PROJECT_REQUIRED`). The
639
+ * server filters after the provider's page, so a page can hold fewer than
640
+ * `perPage` rows and `total` counts the whole provider account. 404
641
+ * `NO_MARKETING_PROVIDER` when the project has none connected.
642
+ */
643
+ listCampaigns(options?: PageOptions & {
644
+ projectId?: string;
645
+ }): Promise<Paginated<CampaignSummary>>;
646
+ /**
647
+ * GET /api/v1/campaigns/{id} — scope `campaigns:read`. `projectId` follows
648
+ * `listCampaigns` (400 `PROJECT_REQUIRED` when omitted with several
649
+ * projects). 404 `NOT_FOUND` for a missing campaign or one in another project.
650
+ * 404 `NO_MARKETING_PROVIDER` with no marketing provider; 422 `NO_PROJECT` when
651
+ * the org has no project.
652
+ */
653
+ getCampaign(id: string, options?: {
654
+ projectId?: string;
655
+ }): Promise<Campaign>;
656
+ /**
657
+ * GET /api/v1/campaigns/{id}/analytics — scope `analytics:read` (the route
658
+ * does not use `campaigns:read`). Counters are 0 while the provider has not
659
+ * reported stats. Same `projectId` rules and 400 `PROJECT_REQUIRED` /
660
+ * 404 `NOT_FOUND` / `NO_MARKETING_PROVIDER` / 422 `NO_PROJECT` as `getCampaign`.
661
+ */
662
+ getCampaignAnalytics(id: string, options?: {
663
+ projectId?: string;
664
+ }): Promise<CampaignAnalytics>;
564
665
  /** GET /api/v1/lists — paged. */
565
666
  listLists(options?: PageOptions): Promise<Paginated<SubscriberList>>;
566
667
  /** POST /api/v1/lists — 409 DUPLICATE_NAME on a name the org already uses. */
@@ -645,6 +746,14 @@ export declare class NevarMail {
645
746
  listSuppressions(options?: ListSuppressionsOptions): Promise<Paginated<Suppression>>;
646
747
  /** POST /api/v1/suppressions — bulk add; see AddSuppressionsInput for the scope rules. */
647
748
  addSuppressions(input: AddSuppressionsInput): Promise<AddSuppressionsResult>;
749
+ /** GET /api/v1/projects/{id}/address — scope `org:read`; 404 NOT_FOUND for a project the key's user can't open. */
750
+ getProjectAddress(projectId: string): Promise<ProjectAddressWithOrg>;
751
+ /**
752
+ * PUT /api/v1/projects/{id}/address — scope `org:write`. Sets the postal
753
+ * address the CAN-SPAM footer of the project's marketing mail carries; a
754
+ * marketing send is refused without one. Blank: 422 `PHYSICAL_ADDRESS_REQUIRED`.
755
+ */
756
+ setProjectAddress(projectId: string, input: SetProjectAddressInput): Promise<ProjectAddress>;
648
757
  /** GET /api/v1/inbox-db/status — scope `org:read`; 404 when no connection is stored. */
649
758
  getInboxDbStatus(): Promise<InboxDbStatus>;
650
759
  /**
package/dist/index.js CHANGED
@@ -304,6 +304,41 @@ export class NevarMail {
304
304
  renderTemplate(id, variables = {}) {
305
305
  return this.request("POST", `/api/v1/templates/${encodeURIComponent(id)}/render`, { body: variables });
306
306
  }
307
+ // ── Campaigns ──────────────────────────────────────────────────────────
308
+ /**
309
+ * GET /api/v1/campaigns — paged; scope `campaigns:read`. Returns the
310
+ * project's campaigns plus those in no project. `projectId` may be omitted
311
+ * only when the org has one project (else 400 `PROJECT_REQUIRED`). The
312
+ * server filters after the provider's page, so a page can hold fewer than
313
+ * `perPage` rows and `total` counts the whole provider account. 404
314
+ * `NO_MARKETING_PROVIDER` when the project has none connected.
315
+ */
316
+ listCampaigns(options = {}) {
317
+ return this.requestPaginated("GET", "/api/v1/campaigns", {
318
+ query: { ...options },
319
+ });
320
+ }
321
+ /**
322
+ * GET /api/v1/campaigns/{id} — scope `campaigns:read`. `projectId` follows
323
+ * `listCampaigns` (400 `PROJECT_REQUIRED` when omitted with several
324
+ * projects). 404 `NOT_FOUND` for a missing campaign or one in another project.
325
+ * 404 `NO_MARKETING_PROVIDER` with no marketing provider; 422 `NO_PROJECT` when
326
+ * the org has no project.
327
+ */
328
+ getCampaign(id, options = {}) {
329
+ return this.request("GET", `/api/v1/campaigns/${encodeURIComponent(id)}`, {
330
+ query: { projectId: options.projectId },
331
+ });
332
+ }
333
+ /**
334
+ * GET /api/v1/campaigns/{id}/analytics — scope `analytics:read` (the route
335
+ * does not use `campaigns:read`). Counters are 0 while the provider has not
336
+ * reported stats. Same `projectId` rules and 400 `PROJECT_REQUIRED` /
337
+ * 404 `NOT_FOUND` / `NO_MARKETING_PROVIDER` / 422 `NO_PROJECT` as `getCampaign`.
338
+ */
339
+ getCampaignAnalytics(id, options = {}) {
340
+ return this.request("GET", `/api/v1/campaigns/${encodeURIComponent(id)}/analytics`, { query: { projectId: options.projectId } });
341
+ }
307
342
  // ── Lists & contacts ───────────────────────────────────────────────────
308
343
  /** GET /api/v1/lists — paged. */
309
344
  async listLists(options = {}) {
@@ -441,6 +476,19 @@ export class NevarMail {
441
476
  addSuppressions(input) {
442
477
  return this.request("POST", "/api/v1/suppressions", { body: input });
443
478
  }
479
+ // ── Projects ───────────────────────────────────────────────────────────
480
+ /** GET /api/v1/projects/{id}/address — scope `org:read`; 404 NOT_FOUND for a project the key's user can't open. */
481
+ getProjectAddress(projectId) {
482
+ return this.request("GET", `/api/v1/projects/${encodeURIComponent(projectId)}/address`);
483
+ }
484
+ /**
485
+ * PUT /api/v1/projects/{id}/address — scope `org:write`. Sets the postal
486
+ * address the CAN-SPAM footer of the project's marketing mail carries; a
487
+ * marketing send is refused without one. Blank: 422 `PHYSICAL_ADDRESS_REQUIRED`.
488
+ */
489
+ setProjectAddress(projectId, input) {
490
+ return this.request("PUT", `/api/v1/projects/${encodeURIComponent(projectId)}/address`, { body: input });
491
+ }
444
492
  // ── Inbox database ─────────────────────────────────────────────────────
445
493
  /** GET /api/v1/inbox-db/status — scope `org:read`; 404 when no connection is stored. */
446
494
  getInboxDbStatus() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bernierllc/nevarmail",
3
- "version": "0.14.0",
3
+ "version": "0.16.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",