@prezly/sdk 22.10.1 → 23.0.1

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.
Files changed (118) hide show
  1. package/dist/Client.cjs +4 -5
  2. package/dist/Client.d.ts +1 -1
  3. package/dist/Client.js +5 -6
  4. package/dist/api/ApiClient.cjs +10 -15
  5. package/dist/api/ApiClient.d.ts +6 -7
  6. package/dist/api/ApiClient.js +10 -15
  7. package/dist/api/DeferredJobsApiClient.cjs +39 -36
  8. package/dist/api/DeferredJobsApiClient.d.ts +7 -7
  9. package/dist/api/DeferredJobsApiClient.js +39 -36
  10. package/dist/api/constants.cjs +1 -1
  11. package/dist/api/constants.js +1 -1
  12. package/dist/endpoints/Accounts/Client.d.ts +1 -1
  13. package/dist/endpoints/Billing/types.cjs +6 -6
  14. package/dist/endpoints/Billing/types.js +6 -6
  15. package/dist/endpoints/CampaignRecipients/Client.d.ts +1 -1
  16. package/dist/endpoints/Campaigns/Client.cjs +1 -1
  17. package/dist/endpoints/Campaigns/Client.d.ts +8 -8
  18. package/dist/endpoints/Campaigns/Client.js +1 -1
  19. package/dist/endpoints/ContactTagGroups/types.cjs +3 -3
  20. package/dist/endpoints/ContactTagGroups/types.js +3 -3
  21. package/dist/endpoints/ContactTags/Client.d.ts +4 -4
  22. package/dist/endpoints/Contacts/Client.cjs +2 -2
  23. package/dist/endpoints/Contacts/Client.d.ts +6 -6
  24. package/dist/endpoints/Contacts/Client.js +2 -2
  25. package/dist/endpoints/ContactsExports/Client.d.ts +2 -2
  26. package/dist/endpoints/Coverage/Client.cjs +1 -1
  27. package/dist/endpoints/Coverage/Client.js +1 -1
  28. package/dist/endpoints/NewsroomCategories/Client.d.ts +3 -3
  29. package/dist/endpoints/NewsroomGalleries/Client.d.ts +1 -1
  30. package/dist/endpoints/NewsroomLanguages/Client.d.ts +10 -10
  31. package/dist/endpoints/NewsroomPrivacyRequests/Client.d.ts +2 -2
  32. package/dist/endpoints/NewsroomThemes/Client.d.ts +1 -1
  33. package/dist/endpoints/NewsroomWebhooks/Client.d.ts +3 -3
  34. package/dist/endpoints/PricingTables/types.cjs +12 -12
  35. package/dist/endpoints/PricingTables/types.js +12 -12
  36. package/dist/endpoints/SenderAddresses/Client.d.ts +3 -3
  37. package/dist/endpoints/Stories/Client.d.ts +102 -102
  38. package/dist/endpoints/Stories/types.d.ts +2 -4
  39. package/dist/endpoints/Subscriptions/Client.d.ts +2 -2
  40. package/dist/endpoints/Subscriptions/types.cjs +3 -3
  41. package/dist/endpoints/Subscriptions/types.js +3 -3
  42. package/dist/endpoints/index.cjs +1 -1
  43. package/dist/http/HttpClient.cjs +12 -5
  44. package/dist/http/HttpClient.d.ts +1 -0
  45. package/dist/http/HttpClient.js +12 -5
  46. package/dist/http/lib.cjs +1 -1
  47. package/dist/http/types.cjs +6 -6
  48. package/dist/http/types.js +6 -6
  49. package/dist/types/BillingCycle.cjs +3 -3
  50. package/dist/types/BillingCycle.js +3 -3
  51. package/dist/types/Campaign.cjs +18 -18
  52. package/dist/types/Campaign.js +18 -18
  53. package/dist/types/Category.cjs +1 -0
  54. package/dist/types/Category.js +1 -0
  55. package/dist/types/Contact.cjs +18 -18
  56. package/dist/types/Contact.js +18 -18
  57. package/dist/types/ContactDuplicateSuggestion.cjs +3 -3
  58. package/dist/types/ContactDuplicateSuggestion.js +4 -3
  59. package/dist/types/ContactTag.cjs +2 -1
  60. package/dist/types/ContactTag.js +2 -1
  61. package/dist/types/ContactsExport.cjs +3 -3
  62. package/dist/types/ContactsExport.js +3 -3
  63. package/dist/types/ContactsScope.cjs +3 -3
  64. package/dist/types/ContactsScope.js +3 -3
  65. package/dist/types/CoverageEntry.cjs +9 -9
  66. package/dist/types/CoverageEntry.js +9 -9
  67. package/dist/types/CoverageIntegration.cjs +3 -3
  68. package/dist/types/CoverageIntegration.js +3 -3
  69. package/dist/types/CoverageIntegrationRun.cjs +3 -3
  70. package/dist/types/CoverageIntegrationRun.js +3 -3
  71. package/dist/types/Culture.cjs +3 -3
  72. package/dist/types/Culture.js +3 -3
  73. package/dist/types/Currency.cjs +3 -3
  74. package/dist/types/Currency.js +3 -3
  75. package/dist/types/EmailRecipient.cjs +3 -3
  76. package/dist/types/EmailRecipient.js +3 -3
  77. package/dist/types/JobState.cjs +3 -3
  78. package/dist/types/JobState.js +3 -3
  79. package/dist/types/License.cjs +9 -9
  80. package/dist/types/License.js +9 -9
  81. package/dist/types/Newsroom.cjs +12 -12
  82. package/dist/types/Newsroom.js +12 -12
  83. package/dist/types/NewsroomDomain.cjs +6 -6
  84. package/dist/types/NewsroomDomain.js +6 -6
  85. package/dist/types/NewsroomGallery.cjs +6 -6
  86. package/dist/types/NewsroomGallery.js +6 -6
  87. package/dist/types/NewsroomTheme.cjs +8 -7
  88. package/dist/types/NewsroomTheme.js +8 -7
  89. package/dist/types/NewsroomWebhook.cjs +3 -3
  90. package/dist/types/NewsroomWebhook.js +3 -3
  91. package/dist/types/NotificationSubscription.cjs +3 -3
  92. package/dist/types/NotificationSubscription.js +3 -3
  93. package/dist/types/Permissions.cjs +3 -3
  94. package/dist/types/Permissions.js +3 -3
  95. package/dist/types/Plan.cjs +10 -10
  96. package/dist/types/Plan.js +11 -11
  97. package/dist/types/Price.cjs +6 -6
  98. package/dist/types/Price.js +6 -6
  99. package/dist/types/PrivacyRequest.cjs +6 -6
  100. package/dist/types/PrivacyRequest.js +6 -6
  101. package/dist/types/SenderAddress.cjs +3 -3
  102. package/dist/types/SenderAddress.js +3 -3
  103. package/dist/types/SenderDomain.cjs +3 -3
  104. package/dist/types/SenderDomain.js +3 -3
  105. package/dist/types/SortOrder.cjs +3 -3
  106. package/dist/types/SortOrder.js +3 -3
  107. package/dist/types/Story.cjs +12 -12
  108. package/dist/types/Story.js +12 -12
  109. package/dist/types/User.cjs +6 -6
  110. package/dist/types/User.js +6 -6
  111. package/dist/types/common/Notification.cjs +3 -3
  112. package/dist/types/common/Notification.js +3 -3
  113. package/dist/types/common/OEmbedInfo.cjs +3 -3
  114. package/dist/types/common/OEmbedInfo.js +3 -3
  115. package/dist/types/common/Pagination.cjs +3 -3
  116. package/dist/types/common/Pagination.js +3 -3
  117. package/dist/types/common/Query.js +1 -0
  118. package/package.json +1 -1
package/dist/Client.cjs CHANGED
@@ -14,12 +14,11 @@ function createClient({
14
14
  headers = {},
15
15
  fetch
16
16
  }) {
17
- const http = (0, _index3.createHttpClient)({
18
- fetch
19
- });
20
- const api = (0, _index.createDeferredJobsApiClient)(http, (0, _index.createApiClient)(http, {
17
+ const api = (0, _index.createDeferredJobsApiClient)((0, _index.createApiClient)((0, _index3.createHttpClient)({
18
+ fetch,
19
+ baseUrl
20
+ }), {
21
21
  accessToken,
22
- baseUrl,
23
22
  headers
24
23
  }));
25
24
  return {
package/dist/Client.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { DeferredJobsApiClient } from './api';
2
2
  import { type Fetch } from './api';
3
- import { Accounts, Billing, NewsroomSubscriptions, Campaigns, CampaignRecipients, Contacts, ContactTags, ContactTagGroups, ContactsExports, Coverage, Jobs, Licenses, Newsrooms, NewsroomCategories, NewsroomContacts, NewsroomLanguages, NewsroomThemes, NewsroomWebhooks, NewsroomPrivacyRequests, NewsroomDomains, NewsroomGalleries, NewsroomHub, PricingTables, SenderAddresses, Stories, Snippets, Subscriptions, NotificationSubscriptions, CoverageIntegrations } from './endpoints';
3
+ import { Accounts, Billing, CampaignRecipients, Campaigns, Contacts, ContactsExports, ContactTagGroups, ContactTags, Coverage, CoverageIntegrations, Jobs, Licenses, NewsroomCategories, NewsroomContacts, NewsroomDomains, NewsroomGalleries, NewsroomHub, NewsroomLanguages, NewsroomPrivacyRequests, Newsrooms, NewsroomSubscriptions, NewsroomThemes, NewsroomWebhooks, NotificationSubscriptions, PricingTables, SenderAddresses, Snippets, Stories, Subscriptions } from './endpoints';
4
4
  import type { HeadersMap } from './http';
5
5
  export interface ClientOptions {
6
6
  accessToken: string;
package/dist/Client.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createApiClient, createDeferredJobsApiClient } from "./api/index.js";
2
- import { Accounts, Billing, NewsroomSubscriptions, Campaigns, CampaignRecipients, Contacts, ContactTags, ContactTagGroups, ContactsExports, Coverage, Jobs, Licenses, Newsrooms, NewsroomCategories, NewsroomContacts, NewsroomLanguages, NewsroomThemes, NewsroomWebhooks, NewsroomPrivacyRequests, NewsroomDomains, NewsroomGalleries, NewsroomHub, PricingTables, SenderAddresses, Stories, Snippets, Subscriptions, NotificationSubscriptions, CoverageIntegrations } from "./endpoints/index.js";
2
+ import { Accounts, Billing, CampaignRecipients, Campaigns, Contacts, ContactsExports, ContactTagGroups, ContactTags, Coverage, CoverageIntegrations, Jobs, Licenses, NewsroomCategories, NewsroomContacts, NewsroomDomains, NewsroomGalleries, NewsroomHub, NewsroomLanguages, NewsroomPrivacyRequests, Newsrooms, NewsroomSubscriptions, NewsroomThemes, NewsroomWebhooks, NotificationSubscriptions, PricingTables, SenderAddresses, Snippets, Stories, Subscriptions } from "./endpoints/index.js";
3
3
  import { createHttpClient } from "./http/index.js";
4
4
  const DEFAULT_BASE_URL = 'https://api.prezly.com';
5
5
  export function createClient({
@@ -8,12 +8,11 @@ export function createClient({
8
8
  headers = {},
9
9
  fetch
10
10
  }) {
11
- const http = createHttpClient({
12
- fetch
13
- });
14
- const api = createDeferredJobsApiClient(http, createApiClient(http, {
11
+ const api = createDeferredJobsApiClient(createApiClient(createHttpClient({
12
+ fetch,
13
+ baseUrl
14
+ }), {
15
15
  accessToken,
16
- baseUrl,
17
16
  headers
18
17
  }));
19
18
  return {
@@ -4,11 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createApiClient = createApiClient;
7
- var _utils = require("../utils.cjs");
8
7
  var _constants = require("./constants.cjs");
9
8
  function createApiClient(http, {
10
9
  accessToken,
11
- baseUrl,
12
10
  headers
13
11
  }) {
14
12
  const defaultHeaders = {
@@ -16,14 +14,11 @@ function createApiClient(http, {
16
14
  'User-Agent': _constants.DEFAULT_USER_AGENT,
17
15
  ...headers
18
16
  };
19
- function buildEndpointUrl(endpointUri) {
20
- return `${(0, _utils.stripSlashes)(baseUrl)}/${(0, _utils.stripSlashes)(endpointUri)}`;
21
- }
22
- function get(endpointUri, {
17
+ function get(url, {
23
18
  headers,
24
19
  query
25
20
  } = {}) {
26
- return http.get(buildEndpointUrl(endpointUri), {
21
+ return http.get(url, {
27
22
  headers: {
28
23
  ...defaultHeaders,
29
24
  ...headers
@@ -31,12 +26,12 @@ function createApiClient(http, {
31
26
  query
32
27
  });
33
28
  }
34
- function post(endpointUri, {
29
+ function post(url, {
35
30
  headers,
36
31
  payload,
37
32
  query
38
33
  } = {}) {
39
- return http.post(buildEndpointUrl(endpointUri), {
34
+ return http.post(url, {
40
35
  headers: {
41
36
  ...defaultHeaders,
42
37
  ...headers
@@ -45,12 +40,12 @@ function createApiClient(http, {
45
40
  query
46
41
  });
47
42
  }
48
- function put(endpointUri, {
43
+ function put(url, {
49
44
  headers,
50
45
  payload,
51
46
  query
52
47
  } = {}) {
53
- return http.put(buildEndpointUrl(endpointUri), {
48
+ return http.put(url, {
54
49
  headers: {
55
50
  ...defaultHeaders,
56
51
  ...headers
@@ -59,12 +54,12 @@ function createApiClient(http, {
59
54
  query
60
55
  });
61
56
  }
62
- function patch(endpointUri, {
57
+ function patch(url, {
63
58
  headers,
64
59
  payload,
65
60
  query
66
61
  } = {}) {
67
- return http.patch(buildEndpointUrl(endpointUri), {
62
+ return http.patch(url, {
68
63
  headers: {
69
64
  ...defaultHeaders,
70
65
  ...headers
@@ -73,12 +68,12 @@ function createApiClient(http, {
73
68
  query
74
69
  });
75
70
  }
76
- function doDelete(endpointUri, {
71
+ function doDelete(url, {
77
72
  headers,
78
73
  payload,
79
74
  query
80
75
  } = {}) {
81
- return http.delete(buildEndpointUrl(endpointUri), {
76
+ return http.delete(url, {
82
77
  headers: {
83
78
  ...defaultHeaders,
84
79
  ...headers
@@ -1,14 +1,13 @@
1
1
  import type { ApiResponse, HeadersMap, HttpClient, Params, ParamsWithPayload } from '../http';
2
2
  export interface Options {
3
3
  accessToken: string;
4
- baseUrl: string;
5
4
  headers: HeadersMap;
6
5
  }
7
6
  export type ApiClient = ReturnType<typeof createApiClient>;
8
- export declare function createApiClient(http: HttpClient, { accessToken, baseUrl, headers }: Options): {
9
- get: <V = any>(endpointUri: string, { headers, query }?: Params) => Promise<ApiResponse<V>>;
10
- post: <V = any>(endpointUri: string, { headers, payload, query }?: ParamsWithPayload) => Promise<ApiResponse<V>>;
11
- put: <V = any>(endpointUri: string, { headers, payload, query }?: ParamsWithPayload) => Promise<ApiResponse<V>>;
12
- patch: <V = any>(endpointUri: string, { headers, payload, query }?: ParamsWithPayload) => Promise<ApiResponse<V>>;
13
- delete: <V = any>(endpointUri: string, { headers, payload, query }?: ParamsWithPayload) => Promise<ApiResponse<V>>;
7
+ export declare function createApiClient(http: HttpClient, { accessToken, headers }: Options): {
8
+ get: <V = any>(url: string, { headers, query }?: Params) => Promise<ApiResponse<V>>;
9
+ post: <V_1 = any>(url: string, { headers, payload, query }?: ParamsWithPayload) => Promise<ApiResponse<V_1>>;
10
+ put: <V_2 = any>(url: string, { headers, payload, query }?: ParamsWithPayload) => Promise<ApiResponse<V_2>>;
11
+ patch: <V_3 = any>(url: string, { headers, payload, query }?: ParamsWithPayload) => Promise<ApiResponse<V_3>>;
12
+ delete: <V_4 = any>(url: string, { headers, payload, query }?: ParamsWithPayload) => Promise<ApiResponse<V_4>>;
14
13
  };
@@ -1,8 +1,6 @@
1
- import { stripSlashes } from "../utils.js";
2
1
  import { DEFAULT_USER_AGENT } from "./constants.js";
3
2
  export function createApiClient(http, {
4
3
  accessToken,
5
- baseUrl,
6
4
  headers
7
5
  }) {
8
6
  const defaultHeaders = {
@@ -10,14 +8,11 @@ export function createApiClient(http, {
10
8
  'User-Agent': DEFAULT_USER_AGENT,
11
9
  ...headers
12
10
  };
13
- function buildEndpointUrl(endpointUri) {
14
- return `${stripSlashes(baseUrl)}/${stripSlashes(endpointUri)}`;
15
- }
16
- function get(endpointUri, {
11
+ function get(url, {
17
12
  headers,
18
13
  query
19
14
  } = {}) {
20
- return http.get(buildEndpointUrl(endpointUri), {
15
+ return http.get(url, {
21
16
  headers: {
22
17
  ...defaultHeaders,
23
18
  ...headers
@@ -25,12 +20,12 @@ export function createApiClient(http, {
25
20
  query
26
21
  });
27
22
  }
28
- function post(endpointUri, {
23
+ function post(url, {
29
24
  headers,
30
25
  payload,
31
26
  query
32
27
  } = {}) {
33
- return http.post(buildEndpointUrl(endpointUri), {
28
+ return http.post(url, {
34
29
  headers: {
35
30
  ...defaultHeaders,
36
31
  ...headers
@@ -39,12 +34,12 @@ export function createApiClient(http, {
39
34
  query
40
35
  });
41
36
  }
42
- function put(endpointUri, {
37
+ function put(url, {
43
38
  headers,
44
39
  payload,
45
40
  query
46
41
  } = {}) {
47
- return http.put(buildEndpointUrl(endpointUri), {
42
+ return http.put(url, {
48
43
  headers: {
49
44
  ...defaultHeaders,
50
45
  ...headers
@@ -53,12 +48,12 @@ export function createApiClient(http, {
53
48
  query
54
49
  });
55
50
  }
56
- function patch(endpointUri, {
51
+ function patch(url, {
57
52
  headers,
58
53
  payload,
59
54
  query
60
55
  } = {}) {
61
- return http.patch(buildEndpointUrl(endpointUri), {
56
+ return http.patch(url, {
62
57
  headers: {
63
58
  ...defaultHeaders,
64
59
  ...headers
@@ -67,12 +62,12 @@ export function createApiClient(http, {
67
62
  query
68
63
  });
69
64
  }
70
- function doDelete(endpointUri, {
65
+ function doDelete(url, {
71
66
  headers,
72
67
  payload,
73
68
  query
74
69
  } = {}) {
75
- return http.delete(buildEndpointUrl(endpointUri), {
70
+ return http.delete(url, {
76
71
  headers: {
77
72
  ...defaultHeaders,
78
73
  ...headers
@@ -13,81 +13,84 @@ const JOB_STATUS_POLLING_INTERVAL = 2000; // ms
13
13
  async function sleep(milliseconds) {
14
14
  return new Promise(resolve => setTimeout(resolve, milliseconds));
15
15
  }
16
- async function handleDeferredJob(http, request) {
17
- const response = await request;
18
- if (response.status === _index.HttpCodes.ACCEPTED && (0, _index.isDeferredJobResponse)(response.payload)) {
19
- return new _progressPromise.ProgressPromise(async function (resolve, reject, progress) {
20
- do {
21
- const response = await http.get(_routing.routing.jobsUrl, {
22
- fetch
23
- });
24
- const {
25
- job
26
- } = response.payload;
27
- if (job.status === _index2.JobStatus.RESOLVED) {
28
- resolve(job.value);
29
- return;
30
- }
31
- if (job.status === _index2.JobStatus.REJECTED) {
32
- reject(job.value);
33
- return;
34
- }
35
- progress(job.progress, job.value);
36
- await sleep(JOB_STATUS_POLLING_INTERVAL);
37
- } while (true); // eslint-disable-line no-constant-condition
38
- });
39
- }
40
- return _progressPromise.ProgressPromise.resolve(response.payload);
16
+ function handleDeferredJob(api, request) {
17
+ return new _progressPromise.ProgressPromise(async (resolve, reject, update) => {
18
+ try {
19
+ const response = await request;
20
+ if (response.status === _index.HttpCodes.ACCEPTED && (0, _index.isDeferredJobResponse)(response.payload)) {
21
+ const id = response.payload.progress.id;
22
+ do {
23
+ const response = await api.get(`${_routing.routing.jobsUrl}/${id}`, {
24
+ fetch
25
+ });
26
+ const state = response.payload.job.state;
27
+ if (state.status === _index2.JobStatus.RESOLVED) {
28
+ resolve(state.value);
29
+ return;
30
+ }
31
+ if (state.status === _index2.JobStatus.REJECTED) {
32
+ reject(state.value);
33
+ return;
34
+ }
35
+ update(state.progress, state.value);
36
+ await sleep(JOB_STATUS_POLLING_INTERVAL);
37
+ } while (true); // eslint-disable-line no-constant-condition
38
+ }
39
+ resolve(response.payload);
40
+ } catch (error) {
41
+ reject(error);
42
+ }
43
+ });
41
44
  }
42
- function createDeferredJobsApiClient(http, api) {
43
- function get(endpointUri, {
45
+ function createDeferredJobsApiClient(api) {
46
+ function get(url, {
44
47
  headers,
45
48
  query
46
49
  } = {}) {
47
- return handleDeferredJob(http, api.get(endpointUri, {
50
+ return handleDeferredJob(api, api.get(url, {
48
51
  headers,
49
52
  query
50
53
  }));
51
54
  }
52
- function post(endpointUri, {
55
+ function post(url, {
53
56
  headers,
54
57
  payload,
55
58
  query
56
59
  } = {}) {
57
- return handleDeferredJob(http, api.post(endpointUri, {
60
+ return handleDeferredJob(api, api.post(url, {
58
61
  headers,
59
62
  payload,
60
63
  query
61
64
  }));
62
65
  }
63
- function put(endpointUri, {
66
+ function put(url, {
64
67
  headers,
65
68
  payload,
66
69
  query
67
70
  } = {}) {
68
- return handleDeferredJob(http, api.put(endpointUri, {
71
+ return handleDeferredJob(api, api.put(url, {
69
72
  headers,
70
73
  payload,
71
74
  query
72
75
  }));
73
76
  }
74
- function patch(endpointUri, {
77
+ function patch(url, {
75
78
  headers,
76
79
  payload,
77
80
  query
78
81
  } = {}) {
79
- return handleDeferredJob(http, api.patch(endpointUri, {
82
+ return handleDeferredJob(api, api.patch(url, {
80
83
  headers,
81
84
  payload,
82
85
  query
83
86
  }));
84
87
  }
85
- function doDelete(endpointUri, {
88
+ function doDelete(url, {
86
89
  headers,
87
90
  payload,
88
91
  query
89
92
  } = {}) {
90
- return handleDeferredJob(http, api.delete(endpointUri, {
93
+ return handleDeferredJob(api, api.delete(url, {
91
94
  headers,
92
95
  payload,
93
96
  query
@@ -1,11 +1,11 @@
1
1
  import { ProgressPromise } from '@prezly/progress-promise';
2
- import type { HttpClient, Params, ParamsWithPayload } from '../http';
2
+ import type { Params, ParamsWithPayload } from '../http';
3
3
  import type { ApiClient } from './ApiClient';
4
4
  export type DeferredJobsApiClient = ReturnType<typeof createDeferredJobsApiClient>;
5
- export declare function createDeferredJobsApiClient(http: HttpClient, api: ApiClient): {
6
- get: <V = any, P = any>(endpointUri: string, { headers, query }?: Params) => ProgressPromise<V, P>;
7
- post: <V = any, P = any>(endpointUri: string, { headers, payload, query }?: ParamsWithPayload) => ProgressPromise<V, P>;
8
- put: <V = any, P = any>(endpointUri: string, { headers, payload, query }?: ParamsWithPayload) => ProgressPromise<V, P>;
9
- patch: <V = any, P = any>(endpointUri: string, { headers, payload, query }?: ParamsWithPayload) => ProgressPromise<V, P>;
10
- delete: <V = any, P = any>(endpointUri: string, { headers, payload, query }?: ParamsWithPayload) => ProgressPromise<V, P>;
5
+ export declare function createDeferredJobsApiClient(api: ApiClient): {
6
+ get: <V = any, P = any>(url: string, { headers, query }?: Params) => ProgressPromise<V, P>;
7
+ post: <V_1 = any, P_1 = any>(url: string, { headers, payload, query }?: ParamsWithPayload) => ProgressPromise<V_1, P_1>;
8
+ put: <V_2 = any, P_2 = any>(url: string, { headers, payload, query }?: ParamsWithPayload) => ProgressPromise<V_2, P_2>;
9
+ patch: <V_3 = any, P_3 = any>(url: string, { headers, payload, query }?: ParamsWithPayload) => ProgressPromise<V_3, P_3>;
10
+ delete: <V_4 = any, P_4 = any>(url: string, { headers, payload, query }?: ParamsWithPayload) => ProgressPromise<V_4, P_4>;
11
11
  };
@@ -7,81 +7,84 @@ const JOB_STATUS_POLLING_INTERVAL = 2000; // ms
7
7
  async function sleep(milliseconds) {
8
8
  return new Promise(resolve => setTimeout(resolve, milliseconds));
9
9
  }
10
- async function handleDeferredJob(http, request) {
11
- const response = await request;
12
- if (response.status === HttpCodes.ACCEPTED && isDeferredJobResponse(response.payload)) {
13
- return new ProgressPromise(async function (resolve, reject, progress) {
14
- do {
15
- const response = await http.get(routing.jobsUrl, {
16
- fetch
17
- });
18
- const {
19
- job
20
- } = response.payload;
21
- if (job.status === JobStatus.RESOLVED) {
22
- resolve(job.value);
23
- return;
24
- }
25
- if (job.status === JobStatus.REJECTED) {
26
- reject(job.value);
27
- return;
28
- }
29
- progress(job.progress, job.value);
30
- await sleep(JOB_STATUS_POLLING_INTERVAL);
31
- } while (true); // eslint-disable-line no-constant-condition
32
- });
33
- }
34
- return ProgressPromise.resolve(response.payload);
10
+ function handleDeferredJob(api, request) {
11
+ return new ProgressPromise(async (resolve, reject, update) => {
12
+ try {
13
+ const response = await request;
14
+ if (response.status === HttpCodes.ACCEPTED && isDeferredJobResponse(response.payload)) {
15
+ const id = response.payload.progress.id;
16
+ do {
17
+ const response = await api.get(`${routing.jobsUrl}/${id}`, {
18
+ fetch
19
+ });
20
+ const state = response.payload.job.state;
21
+ if (state.status === JobStatus.RESOLVED) {
22
+ resolve(state.value);
23
+ return;
24
+ }
25
+ if (state.status === JobStatus.REJECTED) {
26
+ reject(state.value);
27
+ return;
28
+ }
29
+ update(state.progress, state.value);
30
+ await sleep(JOB_STATUS_POLLING_INTERVAL);
31
+ } while (true); // eslint-disable-line no-constant-condition
32
+ }
33
+ resolve(response.payload);
34
+ } catch (error) {
35
+ reject(error);
36
+ }
37
+ });
35
38
  }
36
- export function createDeferredJobsApiClient(http, api) {
37
- function get(endpointUri, {
39
+ export function createDeferredJobsApiClient(api) {
40
+ function get(url, {
38
41
  headers,
39
42
  query
40
43
  } = {}) {
41
- return handleDeferredJob(http, api.get(endpointUri, {
44
+ return handleDeferredJob(api, api.get(url, {
42
45
  headers,
43
46
  query
44
47
  }));
45
48
  }
46
- function post(endpointUri, {
49
+ function post(url, {
47
50
  headers,
48
51
  payload,
49
52
  query
50
53
  } = {}) {
51
- return handleDeferredJob(http, api.post(endpointUri, {
54
+ return handleDeferredJob(api, api.post(url, {
52
55
  headers,
53
56
  payload,
54
57
  query
55
58
  }));
56
59
  }
57
- function put(endpointUri, {
60
+ function put(url, {
58
61
  headers,
59
62
  payload,
60
63
  query
61
64
  } = {}) {
62
- return handleDeferredJob(http, api.put(endpointUri, {
65
+ return handleDeferredJob(api, api.put(url, {
63
66
  headers,
64
67
  payload,
65
68
  query
66
69
  }));
67
70
  }
68
- function patch(endpointUri, {
71
+ function patch(url, {
69
72
  headers,
70
73
  payload,
71
74
  query
72
75
  } = {}) {
73
- return handleDeferredJob(http, api.patch(endpointUri, {
76
+ return handleDeferredJob(api, api.patch(url, {
74
77
  headers,
75
78
  payload,
76
79
  query
77
80
  }));
78
81
  }
79
- function doDelete(endpointUri, {
82
+ function doDelete(url, {
80
83
  headers,
81
84
  payload,
82
85
  query
83
86
  } = {}) {
84
- return handleDeferredJob(http, api.delete(endpointUri, {
87
+ return handleDeferredJob(api, api.delete(url, {
85
88
  headers,
86
89
  payload,
87
90
  query
@@ -4,6 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.DEFAULT_USER_AGENT = void 0;
7
- const VERSION = "22.10.0";
7
+ const VERSION = "23.0.0";
8
8
  const URL = 'https://github.com/prezly/javascript-sdk';
9
9
  const DEFAULT_USER_AGENT = exports.DEFAULT_USER_AGENT = `prezly-javascript-sdk/${VERSION} (+${URL})`;
@@ -1,3 +1,3 @@
1
- const VERSION = "22.10.0";
1
+ const VERSION = "23.0.0";
2
2
  const URL = 'https://github.com/prezly/javascript-sdk';
3
3
  export const DEFAULT_USER_AGENT = `prezly-javascript-sdk/${VERSION} (+${URL})`;
@@ -5,5 +5,5 @@ export type Client = ReturnType<typeof createClient>;
5
5
  export declare function createClient(api: DeferredJobsApiClient): {
6
6
  list: () => Promise<ListResponse>;
7
7
  create: (payload: CreateRequest) => Promise<CreateResponse>;
8
- update: (id: UserAccount["id"], payload: UpdateRequest) => Promise<UpdateResponse>;
8
+ update: (id: UserAccount['id'], payload: UpdateRequest) => Promise<UpdateResponse>;
9
9
  };
@@ -4,14 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.SignupPlan = exports.SignupCurrency = void 0;
7
- let SignupPlan = exports.SignupPlan = /*#__PURE__*/function (SignupPlan) {
7
+ let SignupPlan = exports.SignupPlan = void 0;
8
+ (function (SignupPlan) {
8
9
  SignupPlan["STARTER"] = "starter";
9
10
  SignupPlan["CORE"] = "core";
10
11
  SignupPlan["PREMIUM"] = "premium";
11
- return SignupPlan;
12
- }({});
13
- let SignupCurrency = exports.SignupCurrency = /*#__PURE__*/function (SignupCurrency) {
12
+ })(SignupPlan || (exports.SignupPlan = SignupPlan = {}));
13
+ let SignupCurrency = exports.SignupCurrency = void 0;
14
+ (function (SignupCurrency) {
14
15
  SignupCurrency["EUR"] = "eur";
15
16
  SignupCurrency["USD"] = "usd";
16
- return SignupCurrency;
17
- }({});
17
+ })(SignupCurrency || (exports.SignupCurrency = SignupCurrency = {}));
@@ -1,11 +1,11 @@
1
- export let SignupPlan = /*#__PURE__*/function (SignupPlan) {
1
+ export let SignupPlan;
2
+ (function (SignupPlan) {
2
3
  SignupPlan["STARTER"] = "starter";
3
4
  SignupPlan["CORE"] = "core";
4
5
  SignupPlan["PREMIUM"] = "premium";
5
- return SignupPlan;
6
- }({});
7
- export let SignupCurrency = /*#__PURE__*/function (SignupCurrency) {
6
+ })(SignupPlan || (SignupPlan = {}));
7
+ export let SignupCurrency;
8
+ (function (SignupCurrency) {
8
9
  SignupCurrency["EUR"] = "eur";
9
10
  SignupCurrency["USD"] = "usd";
10
- return SignupCurrency;
11
- }({});
11
+ })(SignupCurrency || (SignupCurrency = {}));
@@ -22,6 +22,6 @@ export declare function createClient(api: DeferredJobsApiClient): {
22
22
  removeRecipient: (campaignId: CampaignId, recipientId: EmailRecipientId) => Promise<RecipientsOperationResponse>;
23
23
  removeRecipients: (campaignId: CampaignId, params?: {
24
24
  query: Query;
25
- }) => Promise<RecipientsOperationResponse>;
25
+ } | undefined) => Promise<RecipientsOperationResponse>;
26
26
  };
27
27
  export {};
@@ -75,7 +75,7 @@ function createClient(api) {
75
75
  } = await api.post(`${_routing.routing.campaignsUrl}/${id}/unschedule`);
76
76
  return campaign;
77
77
  }
78
- async function create(payload) {
78
+ function create(payload) {
79
79
  return api.post(_routing.routing.campaignsUrl, {
80
80
  payload
81
81
  });
@@ -6,15 +6,15 @@ export type Client = ReturnType<typeof createClient>;
6
6
  export declare function createClient(api: DeferredJobsApiClient): {
7
7
  list: (options: SearchOptions) => Promise<ListResponse>;
8
8
  search: (options: SearchOptions) => Promise<ListResponse>;
9
- get: (id: Campaign["id"]) => Promise<CampaignResponse>;
10
- duplicate: (id: Campaign["id"]) => Promise<CampaignResponse>;
11
- test: (id: Campaign["id"], emails: string[]) => Promise<void>;
12
- send: (id: Campaign["id"]) => Promise<void>;
13
- schedule: (id: Campaign["id"], sendAt: Date) => Promise<Campaign>;
14
- unschedule: (id: Campaign["id"]) => Promise<Campaign>;
9
+ get: (id: Campaign['id']) => Promise<CampaignResponse>;
10
+ duplicate: (id: Campaign['id']) => Promise<CampaignResponse>;
11
+ test: (id: Campaign['id'], emails: string[]) => Promise<void>;
12
+ send: (id: Campaign['id']) => Promise<void>;
13
+ schedule: (id: Campaign['id'], sendAt: Date) => Promise<Campaign>;
14
+ unschedule: (id: Campaign['id']) => Promise<Campaign>;
15
15
  create: (payload: CreateRequest) => ProgressPromise<RecipientsOperationResponse, {
16
16
  recipients_number: number;
17
17
  }>;
18
- update: (id: Campaign["id"], payload: UpdateRequest) => Promise<CampaignResponse>;
19
- delete: (id: Campaign["id"]) => Promise<void>;
18
+ update: (id: Campaign['id'], payload: UpdateRequest) => Promise<CampaignResponse>;
19
+ delete: (id: Campaign['id']) => Promise<void>;
20
20
  };
@@ -69,7 +69,7 @@ export function createClient(api) {
69
69
  } = await api.post(`${routing.campaignsUrl}/${id}/unschedule`);
70
70
  return campaign;
71
71
  }
72
- async function create(payload) {
72
+ function create(payload) {
73
73
  return api.post(routing.campaignsUrl, {
74
74
  payload
75
75
  });
@@ -4,7 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Color = void 0;
7
- let Color = exports.Color = /*#__PURE__*/function (Color) {
7
+ let Color = exports.Color = void 0;
8
+ (function (Color) {
8
9
  Color["RED"] = "red";
9
10
  Color["PINK"] = "pink";
10
11
  Color["ORANGE"] = "orange";
@@ -15,5 +16,4 @@ let Color = exports.Color = /*#__PURE__*/function (Color) {
15
16
  Color["BLUE"] = "blue";
16
17
  Color["INDIGO"] = "indigo";
17
18
  Color["PURPLE"] = "purple";
18
- return Color;
19
- }({});
19
+ })(Color || (exports.Color = Color = {}));