@bernierllc/nevarmail 0.20.0 → 0.22.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
@@ -166,6 +166,12 @@ the two, not both). The slug must exist in exactly one project the key can open:
166
166
  | `listLists` / `createList` / `getList` | `/api/v1/lists` | `contacts:read` / `contacts:write` |
167
167
  | `addListContacts` | `POST /api/v1/lists/{id}/contacts` | `contacts:write` |
168
168
  | `listContacts` / `upsertContacts` / `updateContact` / `deleteContact` | `/api/v1/contacts` | `contacts:read` / `contacts:write` |
169
+ | `listBusinesses({ projectId?, page?, perPage? })` / `getBusiness(id, { projectId? })` | `GET /api/v1/businesses`, `GET /api/v1/businesses/{id}` | `contacts:read` |
170
+ | `createBusiness(input)` / `updateBusiness(id, input)` / `deleteBusiness(id, { projectId? })` — update replaces `domains`, merges `attributes`; delete keeps the contacts | `POST /api/v1/businesses`, `PATCH` / `DELETE /api/v1/businesses/{id}` | `contacts:write` |
171
+ | `upsertBusinessByExternalRef(system, ref, input)` — idempotent; returns `{ business, created }` | `PUT /api/v1/businesses/by-ref/{system}/{ref}` | `contacts:write` |
172
+ | `listBusinessMembers(id, { projectId?, page?, perPage? })` | `GET /api/v1/businesses/{id}/members` | `contacts:read` |
173
+ | `addBusinessMembers(id, members, { addedBy?, projectId? })` (max 100) / `removeBusinessMembers(id, { contactIds?, emails?, projectId? })` — memberships only | `POST` / `DELETE /api/v1/businesses/{id}/members` | `contacts:write` |
174
+ | `addBusinessMembersByDomain(id, { projectId? })` — adds contacts at the business's domains | `POST /api/v1/businesses/{id}/members/by-domain` | `contacts:write` |
169
175
  | `listSenders` / `createSender(input)` — `input.projectId?` targets a project when the org has more than one | `/api/v1/senders` | `senders:read` / `senders:write` |
170
176
  | `getSender` / `updateSender` / `deleteSender` | `/api/v1/senders/{id}` | `senders:read` / `senders:write` |
171
177
  | `listUseCases({ projectId?, includeArchived? })` / `createUseCase(input)` — `input.projectId?` as for `createSender` | `/api/v1/use-cases` | `use-cases:read` / `use-cases:write` |
@@ -185,6 +191,11 @@ Application-level details worth knowing before you hit them:
185
191
  `{ data, pagination: { page, perPage, total } }` — the envelope's pagination is the point of
186
192
  calling a list route, so it is not unwrapped away. Single-resource methods return the payload
187
193
  directly, same as the send methods.
194
+ - **Businesses.** `client.businesses` groups the ten business methods: `list`, `get`, `create`,
195
+ `update`, `delete`, `upsertByExternalRef`, `addByDomain` and `members.{list, add, remove}`, each
196
+ delegating to the flat method above. Tenancy: `projectId` goes in the query for `get`, `delete`
197
+ and `addByDomain`, and in the body for `update`, `createBusiness` and the member writes. Omit it
198
+ only when the org has one project.
188
199
  - **Updates are `PATCH`, and partial.** Send only the fields you are changing.
189
200
  - **Campaign reads take an optional `projectId`.** Omit it only when the org has one project;
190
201
  otherwise the server answers 400 `PROJECT_REQUIRED`. A campaign in another project is a 404
package/dist/index.d.ts CHANGED
@@ -139,6 +139,55 @@ export interface Paginated<T> {
139
139
  data: T[];
140
140
  pagination: V1Pagination;
141
141
  }
142
+ export interface Business {
143
+ id: string;
144
+ name: string;
145
+ attributes: Record<string, unknown>;
146
+ domains: string[];
147
+ externalRefs: {
148
+ system: string;
149
+ ref: string;
150
+ }[];
151
+ defaultGroupId: string;
152
+ peopleCount: number;
153
+ createdAt: string;
154
+ updatedAt: string;
155
+ }
156
+ export interface BusinessMember {
157
+ contactId: string;
158
+ email: string;
159
+ name: string | null;
160
+ firstName: string | null;
161
+ lastName: string | null;
162
+ role: string | null;
163
+ addedBy: "manual" | "domain_rule" | "import" | "sync";
164
+ createdAt: string;
165
+ }
166
+ /** Fields for create/update/upsert. `attributes` merges on update; a null value deletes the key. */
167
+ export interface BusinessInput {
168
+ name: string;
169
+ domains?: string[];
170
+ attributes?: Record<string, unknown>;
171
+ /** Required when the org has more than one project and the key is not project-bound. */
172
+ projectId?: string;
173
+ }
174
+ export type BusinessMemberInput = ({
175
+ contactId: string;
176
+ } | {
177
+ email: string;
178
+ firstName?: string;
179
+ lastName?: string;
180
+ }) & {
181
+ role?: string;
182
+ };
183
+ export interface AddBusinessMembersResult {
184
+ added: number;
185
+ updated: number;
186
+ members: {
187
+ contactId: string;
188
+ email: string;
189
+ }[];
190
+ }
142
191
  /** Delivery counters for one campaign, as the provider reports them. */
143
192
  export interface CampaignStats {
144
193
  sent: number;
@@ -605,17 +654,30 @@ export interface AddressComponent {
605
654
  export interface ProjectAddress {
606
655
  physicalAddress: string;
607
656
  addressComponents: AddressComponent[] | null;
657
+ /**
658
+ * The Google Places place the address was picked from, or null. Optional in the
659
+ * type only so existing fixtures keep compiling; the server always sends it.
660
+ */
661
+ placeId?: string | null;
608
662
  }
609
663
  /** `getProjectAddress`: the project's address plus the org's as a suggestion. */
610
664
  export interface ProjectAddressWithOrg extends ProjectAddress {
611
665
  /** Empty when the org has no address set. */
612
666
  orgPhysicalAddress: string;
613
667
  orgAddressComponents: AddressComponent[] | null;
668
+ /** Same as `placeId`, for the org address. */
669
+ orgPlaceId?: string | null;
614
670
  }
615
671
  export interface SetProjectAddressInput {
616
672
  /** Never blank: 422 `PHYSICAL_ADDRESS_REQUIRED`. Trimmed; max 500 chars. */
617
673
  physicalAddress: string;
618
- /** Omitted or null clears any stored parts. Max 30. */
674
+ /**
675
+ * A Google Places place id (`^[A-Za-z0-9_-]{1,512}$`). When set, the server
676
+ * looks the parts up from Google and ignores `addressComponents`; 502
677
+ * `PLACES_UNAVAILABLE` if Google cannot be reached.
678
+ */
679
+ placeId?: string;
680
+ /** Omitted or null stores no parts. Max 30. Ignored when `placeId` is set. */
619
681
  addressComponents?: AddressComponent[] | null;
620
682
  }
621
683
  export interface NevarMailOptions {
@@ -780,6 +842,110 @@ export declare class NevarMail {
780
842
  email: string;
781
843
  localMembershipsRemoved: number;
782
844
  }>;
845
+ /** GET /api/v1/businesses — paged, sorted by name. */
846
+ listBusinesses(options?: PageOptions & {
847
+ projectId?: string;
848
+ }): Promise<Paginated<Business>>;
849
+ /** POST /api/v1/businesses — consumer mail domains are refused (400 CONSUMER_DOMAIN). */
850
+ createBusiness(input: BusinessInput & {
851
+ externalRef?: {
852
+ system: string;
853
+ ref: string;
854
+ };
855
+ }): Promise<Business>;
856
+ /** GET /api/v1/businesses/{id} */
857
+ getBusiness(id: string, opts?: {
858
+ projectId?: string;
859
+ }): Promise<Business>;
860
+ /** PATCH /api/v1/businesses/{id} — domains replaces the set. */
861
+ updateBusiness(id: string, input: Partial<BusinessInput>): Promise<Business>;
862
+ /** DELETE /api/v1/businesses/{id} — the contacts stay. */
863
+ deleteBusiness(id: string, opts?: {
864
+ projectId?: string;
865
+ }): Promise<{
866
+ deleted: true;
867
+ id: string;
868
+ }>;
869
+ /** PUT /api/v1/businesses/by-ref/{system}/{ref} — idempotent upsert by your system's id. */
870
+ upsertBusinessByExternalRef(system: string, ref: string, input: BusinessInput): Promise<{
871
+ business: Business;
872
+ created: boolean;
873
+ }>;
874
+ /** GET /api/v1/businesses/{id}/members */
875
+ listBusinessMembers(id: string, options?: PageOptions & {
876
+ projectId?: string;
877
+ }): Promise<Paginated<BusinessMember>>;
878
+ /** POST /api/v1/businesses/{id}/members — max 100; re-adding is a no-op, a given role replaces the role. */
879
+ addBusinessMembers(id: string, members: BusinessMemberInput[], opts?: {
880
+ addedBy?: "manual" | "import" | "sync";
881
+ projectId?: string;
882
+ }): Promise<AddBusinessMembersResult>;
883
+ /** DELETE /api/v1/businesses/{id}/members — memberships only; the contacts stay. */
884
+ removeBusinessMembers(id: string, who: {
885
+ contactIds?: string[];
886
+ emails?: string[];
887
+ projectId?: string;
888
+ }): Promise<{
889
+ removed: number;
890
+ }>;
891
+ /** POST /api/v1/businesses/{id}/members/by-domain — adds contacts at the business's domains. */
892
+ addBusinessMembersByDomain(id: string, opts?: {
893
+ projectId?: string;
894
+ }): Promise<{
895
+ added: number;
896
+ }>;
897
+ /** Grouped view of the business methods; each delegates to a flat method above. */
898
+ get businesses(): {
899
+ list: (o?: PageOptions & {
900
+ projectId?: string;
901
+ }) => Promise<Paginated<Business>>;
902
+ get: (id: string, o?: {
903
+ projectId?: string;
904
+ }) => Promise<Business>;
905
+ create: (input: BusinessInput & {
906
+ externalRef?: {
907
+ system: string;
908
+ ref: string;
909
+ };
910
+ }) => Promise<Business>;
911
+ update: (id: string, input: Partial<BusinessInput>) => Promise<Business>;
912
+ delete: (id: string, o?: {
913
+ projectId?: string;
914
+ }) => Promise<{
915
+ deleted: true;
916
+ id: string;
917
+ }>;
918
+ upsertByExternalRef: (system: string, ref: string, input: BusinessInput) => Promise<{
919
+ business: Business;
920
+ created: boolean;
921
+ }>;
922
+ addByDomain: (id: string, o?: {
923
+ projectId?: string;
924
+ }) => Promise<{
925
+ added: number;
926
+ }>;
927
+ members: {
928
+ list: (id: string, o?: PageOptions & {
929
+ projectId?: string;
930
+ }) => Promise<Paginated<BusinessMember>>;
931
+ add: (id: string, member: string | {
932
+ email: string;
933
+ firstName?: string;
934
+ lastName?: string;
935
+ }, opts?: {
936
+ role?: string;
937
+ addedBy?: "manual" | "import" | "sync";
938
+ projectId?: string;
939
+ }) => Promise<AddBusinessMembersResult>;
940
+ remove: (id: string, member: string | {
941
+ email: string;
942
+ }, opts?: {
943
+ projectId?: string;
944
+ }) => Promise<{
945
+ removed: number;
946
+ }>;
947
+ };
948
+ };
783
949
  /** GET /api/v1/senders — paged. */
784
950
  listSenders(options?: PageOptions): Promise<Paginated<Sender>>;
785
951
  /** POST /api/v1/senders */
package/dist/index.js CHANGED
@@ -411,6 +411,67 @@ export class NevarMail {
411
411
  deleteContact(email) {
412
412
  return this.request("DELETE", "/api/v1/contacts", { query: { email } });
413
413
  }
414
+ /** GET /api/v1/businesses — paged, sorted by name. */
415
+ listBusinesses(options = {}) {
416
+ return this.requestPaginated("GET", "/api/v1/businesses", { query: { ...options } });
417
+ }
418
+ /** POST /api/v1/businesses — consumer mail domains are refused (400 CONSUMER_DOMAIN). */
419
+ createBusiness(input) {
420
+ return this.request("POST", "/api/v1/businesses", { body: input });
421
+ }
422
+ /** GET /api/v1/businesses/{id} */
423
+ getBusiness(id, opts = {}) {
424
+ return this.request("GET", `/api/v1/businesses/${encodeURIComponent(id)}`, { query: { ...opts } });
425
+ }
426
+ /** PATCH /api/v1/businesses/{id} — domains replaces the set. */
427
+ updateBusiness(id, input) {
428
+ return this.request("PATCH", `/api/v1/businesses/${encodeURIComponent(id)}`, { body: input });
429
+ }
430
+ /** DELETE /api/v1/businesses/{id} — the contacts stay. */
431
+ deleteBusiness(id, opts = {}) {
432
+ return this.request("DELETE", `/api/v1/businesses/${encodeURIComponent(id)}`, { query: { ...opts } });
433
+ }
434
+ /** PUT /api/v1/businesses/by-ref/{system}/{ref} — idempotent upsert by your system's id. */
435
+ upsertBusinessByExternalRef(system, ref, input) {
436
+ return this.request("PUT", `/api/v1/businesses/by-ref/${encodeURIComponent(system)}/${encodeURIComponent(ref)}`, { body: input });
437
+ }
438
+ /** GET /api/v1/businesses/{id}/members */
439
+ listBusinessMembers(id, options = {}) {
440
+ return this.requestPaginated("GET", `/api/v1/businesses/${encodeURIComponent(id)}/members`, { query: { ...options } });
441
+ }
442
+ /** POST /api/v1/businesses/{id}/members — max 100; re-adding is a no-op, a given role replaces the role. */
443
+ addBusinessMembers(id, members, opts = {}) {
444
+ return this.request("POST", `/api/v1/businesses/${encodeURIComponent(id)}/members`, { body: { members, ...opts } });
445
+ }
446
+ /** DELETE /api/v1/businesses/{id}/members — memberships only; the contacts stay. */
447
+ removeBusinessMembers(id, who) {
448
+ return this.request("DELETE", `/api/v1/businesses/${encodeURIComponent(id)}/members`, { body: who });
449
+ }
450
+ /** POST /api/v1/businesses/{id}/members/by-domain — adds contacts at the business's domains. */
451
+ addBusinessMembersByDomain(id, opts = {}) {
452
+ return this.request("POST", `/api/v1/businesses/${encodeURIComponent(id)}/members/by-domain`, { query: { ...opts } });
453
+ }
454
+ /** Grouped view of the business methods; each delegates to a flat method above. */
455
+ get businesses() {
456
+ return {
457
+ list: (o) => this.listBusinesses(o),
458
+ get: (id, o) => this.getBusiness(id, o),
459
+ create: (input) => this.createBusiness(input),
460
+ update: (id, input) => this.updateBusiness(id, input),
461
+ delete: (id, o) => this.deleteBusiness(id, o),
462
+ upsertByExternalRef: (system, ref, input) => this.upsertBusinessByExternalRef(system, ref, input),
463
+ addByDomain: (id, o) => this.addBusinessMembersByDomain(id, o),
464
+ members: {
465
+ list: (id, o) => this.listBusinessMembers(id, o),
466
+ add: (id, member, opts = {}) => {
467
+ const { role, ...rest } = opts;
468
+ const m = typeof member === "string" ? { contactId: member } : member;
469
+ return this.addBusinessMembers(id, [role === undefined ? m : { ...m, role }], rest);
470
+ },
471
+ remove: (id, member, opts = {}) => this.removeBusinessMembers(id, typeof member === "string" ? { contactIds: [member], ...opts } : { emails: [member.email], ...opts }),
472
+ },
473
+ };
474
+ }
414
475
  // ── Senders ────────────────────────────────────────────────────────────
415
476
  /** GET /api/v1/senders — paged. */
416
477
  listSenders(options = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bernierllc/nevarmail",
3
- "version": "0.20.0",
3
+ "version": "0.22.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",