@prezly/sdk 15.7.0 → 15.9.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/dist/Client.cjs CHANGED
@@ -23,6 +23,7 @@ function createClient({
23
23
  billing: new _index2.Billing.Client(apiClient),
24
24
  campaigns: new _index2.Campaigns.Client(apiClient),
25
25
  campaignRecipients: new _index2.CampaignRecipients.Client(apiClient),
26
+ contacts: new _index2.Contacts.Client(apiClient),
26
27
  contactsExports: new _index2.ContactsExports.Client(apiClient),
27
28
  coverage: new _index2.Coverage.Client(apiClient),
28
29
  jobs: new _index2.Jobs.Client(apiClient),
package/dist/Client.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { DeferredJobsApiClient } from './api';
2
+ import { Contacts } from './endpoints';
2
3
  import { Accounts, Billing, Campaigns, CampaignRecipients, ContactsExports, Coverage, Jobs, Licenses, Newsrooms, NewsroomCategories, NewsroomContacts, NewsroomLanguages, NewsroomThemes, NewsroomWebhooks, NewsroomPrivacyRequests, NewsroomDomains, NewsroomGalleries, NewsroomHub, PricingTables, SenderAddresses, Signup, Stories, Snippets, Subscriptions, NotificationSubscriptions } from './endpoints';
3
4
  import type { HeadersMap } from './http';
4
5
  export interface ClientOptions {
@@ -12,6 +13,7 @@ export interface Client {
12
13
  billing: Billing.Client;
13
14
  campaigns: Campaigns.Client;
14
15
  campaignRecipients: CampaignRecipients.Client;
16
+ contacts: Contacts.Client;
15
17
  contactsExports: ContactsExports.Client;
16
18
  coverage: Coverage.Client;
17
19
  jobs: Jobs.Client;
package/dist/Client.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ApiClient, DeferredJobsApiClient } from "./api/index.js";
2
+ import { Contacts } from "./endpoints/index.js";
2
3
  import { Accounts, Billing, Campaigns, CampaignRecipients, ContactsExports, Coverage, Jobs, Licenses, Newsrooms, NewsroomCategories, NewsroomContacts, NewsroomLanguages, NewsroomThemes, NewsroomWebhooks, NewsroomPrivacyRequests, NewsroomDomains, NewsroomGalleries, NewsroomHub, PricingTables, SenderAddresses, Signup, Stories, Snippets, Subscriptions, NotificationSubscriptions } from "./endpoints/index.js";
3
4
  const DEFAULT_BASE_URL = 'https://api.prezly.com';
4
5
  export function createClient({
@@ -17,6 +18,7 @@ export function createClient({
17
18
  billing: new Billing.Client(apiClient),
18
19
  campaigns: new Campaigns.Client(apiClient),
19
20
  campaignRecipients: new CampaignRecipients.Client(apiClient),
21
+ contacts: new Contacts.Client(apiClient),
20
22
  contactsExports: new ContactsExports.Client(apiClient),
21
23
  coverage: new Coverage.Client(apiClient),
22
24
  jobs: new Jobs.Client(apiClient),
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.DEFAULT_USER_AGENT = void 0;
7
- const VERSION = "15.6.0";
7
+ const VERSION = "15.8.0";
8
8
  const URL = 'https://github.com/prezly/javascript-sdk';
9
9
  const DEFAULT_USER_AGENT = `prezly-javascript-sdk/${VERSION} (+${URL})`;
10
10
  exports.DEFAULT_USER_AGENT = DEFAULT_USER_AGENT;
@@ -1,3 +1,3 @@
1
- const VERSION = "15.6.0";
1
+ const VERSION = "15.8.0";
2
2
  const URL = 'https://github.com/prezly/javascript-sdk';
3
3
  export const DEFAULT_USER_AGENT = `prezly-javascript-sdk/${VERSION} (+${URL})`;
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Client = void 0;
7
+ var _routing = require("../../routing.cjs");
8
+ var _index = require("../../types/index.cjs");
9
+ class Client {
10
+ constructor(apiClient) {
11
+ this.apiClient = apiClient;
12
+ }
13
+
14
+ /**
15
+ * List Contacts Exports with sorting, and pagination.
16
+ */
17
+ async list(options) {
18
+ const {
19
+ limit,
20
+ offset,
21
+ sortOrder
22
+ } = options;
23
+ const {
24
+ contacts,
25
+ pagination,
26
+ sort
27
+ } = await this.apiClient.get(_routing.routing.contactsUrl, {
28
+ query: {
29
+ limit,
30
+ offset,
31
+ sort: _index.SortOrder.stringify(sortOrder)
32
+ }
33
+ });
34
+ return {
35
+ contacts,
36
+ pagination,
37
+ sortOrder: _index.SortOrder.parse(sort)
38
+ };
39
+ }
40
+
41
+ /**
42
+ * List Contacts Exports with sorting, pagination, and filtering.
43
+ */
44
+ async search(options) {
45
+ const {
46
+ limit,
47
+ offset,
48
+ query,
49
+ sortOrder
50
+ } = options;
51
+ const url = `${_routing.routing.contactsUrl}/search`;
52
+ const {
53
+ contacts,
54
+ pagination,
55
+ sort
56
+ } = await this.apiClient.post(url, {
57
+ payload: {
58
+ limit,
59
+ offset,
60
+ sort: _index.SortOrder.stringify(sortOrder),
61
+ query
62
+ }
63
+ });
64
+ return {
65
+ contacts,
66
+ pagination,
67
+ sortOrder: _index.SortOrder.parse(sort)
68
+ };
69
+ }
70
+ async get(id) {
71
+ const url = `${_routing.routing.contactsUrl}/${id}`;
72
+ const {
73
+ contact
74
+ } = await this.apiClient.get(url);
75
+ return contact;
76
+ }
77
+ async getMany(ids) {
78
+ const {
79
+ contacts
80
+ } = await this.search({
81
+ query: {
82
+ id: {
83
+ $in: ids
84
+ }
85
+ },
86
+ limit: ids.length
87
+ });
88
+ // Reorder results to match the order of `ids`.
89
+ return contacts.sort((a, b) => ids.indexOf(a.id) - ids.indexOf(b.id));
90
+ }
91
+ async create(payload) {
92
+ const {
93
+ contact
94
+ } = await this.apiClient.post(_routing.routing.contactsUrl, {
95
+ payload
96
+ });
97
+ return contact;
98
+ }
99
+ async update(id, payload) {
100
+ const url = `${_routing.routing.contactsUrl}/${id}`;
101
+ const {
102
+ contact
103
+ } = await this.apiClient.patch(url, {
104
+ payload
105
+ });
106
+ return contact;
107
+ }
108
+ async tag(id, tags) {
109
+ const url = `${_routing.routing.contactsUrl}/${id}`;
110
+ const {
111
+ contact
112
+ } = await this.apiClient.patch(url, {
113
+ payload: {
114
+ '+tags': tags
115
+ }
116
+ });
117
+ return contact;
118
+ }
119
+ async untag(id, tags) {
120
+ const url = `${_routing.routing.contactsUrl}/${id}`;
121
+ const {
122
+ contact
123
+ } = await this.apiClient.patch(url, {
124
+ payload: {
125
+ '-tags': tags
126
+ }
127
+ });
128
+ return contact;
129
+ }
130
+ async bulkTag(selector, tags) {
131
+ return this.apiClient.patch(_routing.routing.contactsUrl, {
132
+ payload: {
133
+ scope: selector.scope,
134
+ query: selector.query,
135
+ '+tags': tags
136
+ }
137
+ });
138
+ }
139
+ async bulkUntag(selector, tags) {
140
+ return this.apiClient.patch(_routing.routing.contactsUrl, {
141
+ payload: {
142
+ scope: selector.scope,
143
+ query: selector.query,
144
+ '-tags': tags
145
+ }
146
+ });
147
+ }
148
+ }
149
+ exports.Client = Client;
@@ -0,0 +1,28 @@
1
+ import type { ProgressPromise } from '@prezly/progress-promise';
2
+ import type { DeferredJobsApiClient } from '../../api';
3
+ import type { Contact } from '../../types';
4
+ import type { ContactsBulkSelector } from '../ContactsExports';
5
+ import type { CreateRequest, ListOptions, ListResponse, SearchOptions, SearchResponse, UpdateRequest } from './types';
6
+ declare type TagId = number;
7
+ declare type TagName = string;
8
+ export declare class Client {
9
+ private readonly apiClient;
10
+ constructor(apiClient: DeferredJobsApiClient);
11
+ /**
12
+ * List Contacts Exports with sorting, and pagination.
13
+ */
14
+ list(options: ListOptions): Promise<ListResponse>;
15
+ /**
16
+ * List Contacts Exports with sorting, pagination, and filtering.
17
+ */
18
+ search(options: SearchOptions): Promise<SearchResponse>;
19
+ get(id: Contact['id']): Promise<Contact>;
20
+ getMany(ids: Contact['id'][]): Promise<Contact[]>;
21
+ create(payload: CreateRequest): Promise<Contact>;
22
+ update(id: Contact['id'], payload: UpdateRequest): Promise<Contact>;
23
+ tag(id: Contact['id'], tags: (TagId | TagName)[]): Promise<Contact>;
24
+ untag(id: Contact['id'], tags: (TagId | TagName)[]): Promise<Contact>;
25
+ bulkTag(selector: ContactsBulkSelector, tags: (TagId | TagName)[]): ProgressPromise<undefined>;
26
+ bulkUntag(selector: ContactsBulkSelector, tags: (TagId | TagName)[]): ProgressPromise<undefined>;
27
+ }
28
+ export {};
@@ -0,0 +1,142 @@
1
+ import { routing } from "../../routing.js";
2
+ import { SortOrder } from "../../types/index.js";
3
+ export class Client {
4
+ constructor(apiClient) {
5
+ this.apiClient = apiClient;
6
+ }
7
+
8
+ /**
9
+ * List Contacts Exports with sorting, and pagination.
10
+ */
11
+ async list(options) {
12
+ const {
13
+ limit,
14
+ offset,
15
+ sortOrder
16
+ } = options;
17
+ const {
18
+ contacts,
19
+ pagination,
20
+ sort
21
+ } = await this.apiClient.get(routing.contactsUrl, {
22
+ query: {
23
+ limit,
24
+ offset,
25
+ sort: SortOrder.stringify(sortOrder)
26
+ }
27
+ });
28
+ return {
29
+ contacts,
30
+ pagination,
31
+ sortOrder: SortOrder.parse(sort)
32
+ };
33
+ }
34
+
35
+ /**
36
+ * List Contacts Exports with sorting, pagination, and filtering.
37
+ */
38
+ async search(options) {
39
+ const {
40
+ limit,
41
+ offset,
42
+ query,
43
+ sortOrder
44
+ } = options;
45
+ const url = `${routing.contactsUrl}/search`;
46
+ const {
47
+ contacts,
48
+ pagination,
49
+ sort
50
+ } = await this.apiClient.post(url, {
51
+ payload: {
52
+ limit,
53
+ offset,
54
+ sort: SortOrder.stringify(sortOrder),
55
+ query
56
+ }
57
+ });
58
+ return {
59
+ contacts,
60
+ pagination,
61
+ sortOrder: SortOrder.parse(sort)
62
+ };
63
+ }
64
+ async get(id) {
65
+ const url = `${routing.contactsUrl}/${id}`;
66
+ const {
67
+ contact
68
+ } = await this.apiClient.get(url);
69
+ return contact;
70
+ }
71
+ async getMany(ids) {
72
+ const {
73
+ contacts
74
+ } = await this.search({
75
+ query: {
76
+ id: {
77
+ $in: ids
78
+ }
79
+ },
80
+ limit: ids.length
81
+ });
82
+ // Reorder results to match the order of `ids`.
83
+ return contacts.sort((a, b) => ids.indexOf(a.id) - ids.indexOf(b.id));
84
+ }
85
+ async create(payload) {
86
+ const {
87
+ contact
88
+ } = await this.apiClient.post(routing.contactsUrl, {
89
+ payload
90
+ });
91
+ return contact;
92
+ }
93
+ async update(id, payload) {
94
+ const url = `${routing.contactsUrl}/${id}`;
95
+ const {
96
+ contact
97
+ } = await this.apiClient.patch(url, {
98
+ payload
99
+ });
100
+ return contact;
101
+ }
102
+ async tag(id, tags) {
103
+ const url = `${routing.contactsUrl}/${id}`;
104
+ const {
105
+ contact
106
+ } = await this.apiClient.patch(url, {
107
+ payload: {
108
+ '+tags': tags
109
+ }
110
+ });
111
+ return contact;
112
+ }
113
+ async untag(id, tags) {
114
+ const url = `${routing.contactsUrl}/${id}`;
115
+ const {
116
+ contact
117
+ } = await this.apiClient.patch(url, {
118
+ payload: {
119
+ '-tags': tags
120
+ }
121
+ });
122
+ return contact;
123
+ }
124
+ async bulkTag(selector, tags) {
125
+ return this.apiClient.patch(routing.contactsUrl, {
126
+ payload: {
127
+ scope: selector.scope,
128
+ query: selector.query,
129
+ '+tags': tags
130
+ }
131
+ });
132
+ }
133
+ async bulkUntag(selector, tags) {
134
+ return this.apiClient.patch(routing.contactsUrl, {
135
+ payload: {
136
+ scope: selector.scope,
137
+ query: selector.query,
138
+ '-tags': tags
139
+ }
140
+ });
141
+ }
142
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ ContactsScope: true
8
+ };
9
+ Object.defineProperty(exports, "ContactsScope", {
10
+ enumerable: true,
11
+ get: function () {
12
+ return _index.ContactsScope;
13
+ }
14
+ });
15
+ var _Client = require("./Client.cjs");
16
+ Object.keys(_Client).forEach(function (key) {
17
+ if (key === "default" || key === "__esModule") return;
18
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
19
+ Object.defineProperty(exports, key, {
20
+ enumerable: true,
21
+ get: function () {
22
+ return _Client[key];
23
+ }
24
+ });
25
+ });
26
+ var _types = require("./types.cjs");
27
+ Object.keys(_types).forEach(function (key) {
28
+ if (key === "default" || key === "__esModule") return;
29
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
30
+ Object.defineProperty(exports, key, {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _types[key];
34
+ }
35
+ });
36
+ });
37
+ var _index = require("../../types/index.cjs");
@@ -0,0 +1,4 @@
1
+ export * from './Client';
2
+ export * from './types';
3
+ export { ContactsScope } from '../../types';
4
+ export type { ContactsBulkSelector } from '../ContactsExports';
@@ -0,0 +1,4 @@
1
+ export * from "./Client.js";
2
+ export * from "./types.js";
3
+ export { ContactsScope } from "../../types/index.js"; // convenience shortcut
4
+ // convenience shortcut
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,58 @@
1
+ import type { Contact, Pagination, Query } from '../../types';
2
+ import type { SortOrder } from '../../types';
3
+ export interface ListOptions {
4
+ limit?: number;
5
+ offset?: number;
6
+ sortOrder?: SortOrder | string;
7
+ }
8
+ export interface SearchOptions extends ListOptions {
9
+ query?: Query;
10
+ }
11
+ export interface ListResponse {
12
+ contacts: Contact[];
13
+ pagination: Pagination;
14
+ sortOrder: SortOrder;
15
+ }
16
+ export declare type SearchResponse = ListResponse;
17
+ export declare type CreateRequest = OrganisationCreateRequest | PersonCreateRequest;
18
+ export declare type UpdateRequest = OrganisationUpdateRequest | PersonUpdateRequest;
19
+ interface BaseContactPayload {
20
+ avatar_image?: string | null;
21
+ languages?: string[];
22
+ emails?: string[];
23
+ phone_numbers?: Contact.PhoneNumber[];
24
+ urls?: string[];
25
+ social_accounts?: {
26
+ type: Contact.SocialNetwork;
27
+ username: string;
28
+ }[];
29
+ tags?: (number | string)[];
30
+ periodicity?: Contact.Periodicity | null;
31
+ medium_types?: Contact.MediumType[];
32
+ salutation?: string;
33
+ address?: {
34
+ street?: string;
35
+ zip?: string;
36
+ city?: string;
37
+ region?: string;
38
+ country?: string | null;
39
+ };
40
+ }
41
+ export interface OrganisationUpdateRequest extends BaseContactPayload {
42
+ company_name?: string;
43
+ }
44
+ export interface OrganisationCreateRequest extends BaseContactPayload {
45
+ contact_type: `${Contact.Type.ORGANISATION}`;
46
+ company_name: string;
47
+ }
48
+ export interface PersonUpdateRequest extends BaseContactPayload {
49
+ first_name?: string;
50
+ last_name?: string;
51
+ gender?: Contact.Gender;
52
+ function_name?: string;
53
+ organisations?: (number | string)[];
54
+ }
55
+ export interface PersonCreateRequest extends PersonUpdateRequest {
56
+ contact_type: `${Contact.Type.PERSON}`;
57
+ }
58
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.NotificationSubscriptions = exports.Subscriptions = exports.Stories = exports.Snippets = exports.Signup = exports.SenderAddresses = exports.PricingTables = exports.NewsroomWebhooks = exports.NewsroomThemes = exports.NewsroomSubscriptions = exports.Newsrooms = exports.NewsroomPrivacyRequests = exports.NewsroomLanguages = exports.NewsroomHub = exports.NewsroomGalleries = exports.NewsroomDomains = exports.NewsroomContacts = exports.NewsroomCategories = exports.Licenses = exports.Jobs = exports.Coverage = exports.ContactsExports = exports.Campaigns = exports.CampaignRecipients = exports.Billing = exports.Accounts = void 0;
6
+ exports.NotificationSubscriptions = exports.Subscriptions = exports.Stories = exports.Snippets = exports.Signup = exports.SenderAddresses = exports.PricingTables = exports.NewsroomWebhooks = exports.NewsroomThemes = exports.NewsroomSubscriptions = exports.Newsrooms = exports.NewsroomPrivacyRequests = exports.NewsroomLanguages = exports.NewsroomHub = exports.NewsroomGalleries = exports.NewsroomDomains = exports.NewsroomContacts = exports.NewsroomCategories = exports.Licenses = exports.Jobs = exports.Coverage = exports.ContactsExports = exports.Contacts = exports.Campaigns = exports.CampaignRecipients = exports.Billing = exports.Accounts = void 0;
7
7
  var _Accounts = _interopRequireWildcard(require("./Accounts/index.cjs"));
8
8
  exports.Accounts = _Accounts;
9
9
  var _Billing = _interopRequireWildcard(require("./Billing/index.cjs"));
@@ -12,6 +12,8 @@ var _CampaignRecipients = _interopRequireWildcard(require("./CampaignRecipients/
12
12
  exports.CampaignRecipients = _CampaignRecipients;
13
13
  var _Campaigns = _interopRequireWildcard(require("./Campaigns/index.cjs"));
14
14
  exports.Campaigns = _Campaigns;
15
+ var _Contacts = _interopRequireWildcard(require("./Contacts/index.cjs"));
16
+ exports.Contacts = _Contacts;
15
17
  var _ContactsExports = _interopRequireWildcard(require("./ContactsExports/index.cjs"));
16
18
  exports.ContactsExports = _ContactsExports;
17
19
  var _Coverage = _interopRequireWildcard(require("./Coverage/index.cjs"));
@@ -2,6 +2,7 @@ export * as Accounts from './Accounts';
2
2
  export * as Billing from './Billing';
3
3
  export * as CampaignRecipients from './CampaignRecipients';
4
4
  export * as Campaigns from './Campaigns';
5
+ export * as Contacts from './Contacts';
5
6
  export * as ContactsExports from './ContactsExports';
6
7
  export * as Coverage from './Coverage';
7
8
  export * as Jobs from './Jobs';
@@ -2,6 +2,7 @@ export * as Accounts from "./Accounts/index.js";
2
2
  export * as Billing from "./Billing/index.js";
3
3
  export * as CampaignRecipients from "./CampaignRecipients/index.js";
4
4
  export * as Campaigns from "./Campaigns/index.js";
5
+ export * as Contacts from "./Contacts/index.js";
5
6
  export * as ContactsExports from "./ContactsExports/index.js";
6
7
  export * as Coverage from "./Coverage/index.js";
7
8
  export * as Jobs from "./Jobs/index.js";
package/dist/routing.cjs CHANGED
@@ -10,6 +10,7 @@ const routing = {
10
10
  campaignsUrl: '/v2/campaigns',
11
11
  campaignRecipientsUrl: '/v2/campaigns/:campaign_id/recipients',
12
12
  contactsExportsUrl: '/v2/contacts/exports',
13
+ contactsUrl: '/v2/contacts',
13
14
  coverageUrl: '/v2/coverage',
14
15
  jobsUrl: '/v2/jobs',
15
16
  licenseUrl: '/v2/licenses',
package/dist/routing.d.ts CHANGED
@@ -4,6 +4,7 @@ export declare const routing: {
4
4
  campaignsUrl: string;
5
5
  campaignRecipientsUrl: string;
6
6
  contactsExportsUrl: string;
7
+ contactsUrl: string;
7
8
  coverageUrl: string;
8
9
  jobsUrl: string;
9
10
  licenseUrl: string;
package/dist/routing.js CHANGED
@@ -4,6 +4,7 @@ export const routing = {
4
4
  campaignsUrl: '/v2/campaigns',
5
5
  campaignRecipientsUrl: '/v2/campaigns/:campaign_id/recipients',
6
6
  contactsExportsUrl: '/v2/contacts/exports',
7
+ contactsUrl: '/v2/contacts',
7
8
  coverageUrl: '/v2/coverage',
8
9
  jobsUrl: '/v2/jobs',
9
10
  licenseUrl: '/v2/licenses',
@@ -1,5 +1,6 @@
1
1
  import type { Limit } from '../endpoints/PricingTables';
2
2
  import type { OptionId } from '../endpoints/PricingTables';
3
+ import type { TableId } from '../endpoints/PricingTables';
3
4
  import type { BillingCycle } from './BillingCycle';
4
5
  import type { Currency } from './Currency';
5
6
  export interface PlanReference {
@@ -10,6 +11,7 @@ export interface PlanReference {
10
11
  is_superior: boolean;
11
12
  is_trial: boolean;
12
13
  can_upgrade: boolean;
14
+ pricing_table_id: TableId | null;
13
15
  pricing_table_option_id: OptionId | null;
14
16
  }
15
17
  export interface Plan extends PlanReference {
@@ -28,6 +30,7 @@ export interface Usage {
28
30
  used: number;
29
31
  }
30
32
  export interface Change {
33
+ pricing_table_id: TableId;
31
34
  pricing_table_option_id: OptionId;
32
35
  can_self_change: boolean;
33
36
  type: ChangeType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prezly/sdk",
3
- "version": "15.7.0",
3
+ "version": "15.9.0",
4
4
  "description": "Prezly API SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",