@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.
- package/dist/Client.cjs +4 -5
- package/dist/Client.d.ts +1 -1
- package/dist/Client.js +5 -6
- package/dist/api/ApiClient.cjs +10 -15
- package/dist/api/ApiClient.d.ts +6 -7
- package/dist/api/ApiClient.js +10 -15
- package/dist/api/DeferredJobsApiClient.cjs +39 -36
- package/dist/api/DeferredJobsApiClient.d.ts +7 -7
- package/dist/api/DeferredJobsApiClient.js +39 -36
- package/dist/api/constants.cjs +1 -1
- package/dist/api/constants.js +1 -1
- package/dist/endpoints/Accounts/Client.d.ts +1 -1
- package/dist/endpoints/Billing/types.cjs +6 -6
- package/dist/endpoints/Billing/types.js +6 -6
- package/dist/endpoints/CampaignRecipients/Client.d.ts +1 -1
- package/dist/endpoints/Campaigns/Client.cjs +1 -1
- package/dist/endpoints/Campaigns/Client.d.ts +8 -8
- package/dist/endpoints/Campaigns/Client.js +1 -1
- package/dist/endpoints/ContactTagGroups/types.cjs +3 -3
- package/dist/endpoints/ContactTagGroups/types.js +3 -3
- package/dist/endpoints/ContactTags/Client.d.ts +4 -4
- package/dist/endpoints/Contacts/Client.cjs +2 -2
- package/dist/endpoints/Contacts/Client.d.ts +6 -6
- package/dist/endpoints/Contacts/Client.js +2 -2
- package/dist/endpoints/ContactsExports/Client.d.ts +2 -2
- package/dist/endpoints/Coverage/Client.cjs +1 -1
- package/dist/endpoints/Coverage/Client.js +1 -1
- package/dist/endpoints/NewsroomCategories/Client.d.ts +3 -3
- package/dist/endpoints/NewsroomGalleries/Client.d.ts +1 -1
- package/dist/endpoints/NewsroomLanguages/Client.d.ts +10 -10
- package/dist/endpoints/NewsroomPrivacyRequests/Client.d.ts +2 -2
- package/dist/endpoints/NewsroomThemes/Client.d.ts +1 -1
- package/dist/endpoints/NewsroomWebhooks/Client.d.ts +3 -3
- package/dist/endpoints/PricingTables/types.cjs +12 -12
- package/dist/endpoints/PricingTables/types.js +12 -12
- package/dist/endpoints/SenderAddresses/Client.d.ts +3 -3
- package/dist/endpoints/Stories/Client.d.ts +102 -102
- package/dist/endpoints/Stories/types.d.ts +2 -4
- package/dist/endpoints/Subscriptions/Client.d.ts +2 -2
- package/dist/endpoints/Subscriptions/types.cjs +3 -3
- package/dist/endpoints/Subscriptions/types.js +3 -3
- package/dist/endpoints/index.cjs +1 -1
- package/dist/http/HttpClient.cjs +12 -5
- package/dist/http/HttpClient.d.ts +1 -0
- package/dist/http/HttpClient.js +12 -5
- package/dist/http/lib.cjs +1 -1
- package/dist/http/types.cjs +6 -6
- package/dist/http/types.js +6 -6
- package/dist/types/BillingCycle.cjs +3 -3
- package/dist/types/BillingCycle.js +3 -3
- package/dist/types/Campaign.cjs +18 -18
- package/dist/types/Campaign.js +18 -18
- package/dist/types/Category.cjs +1 -0
- package/dist/types/Category.js +1 -0
- package/dist/types/Contact.cjs +18 -18
- package/dist/types/Contact.js +18 -18
- package/dist/types/ContactDuplicateSuggestion.cjs +3 -3
- package/dist/types/ContactDuplicateSuggestion.js +4 -3
- package/dist/types/ContactTag.cjs +2 -1
- package/dist/types/ContactTag.js +2 -1
- package/dist/types/ContactsExport.cjs +3 -3
- package/dist/types/ContactsExport.js +3 -3
- package/dist/types/ContactsScope.cjs +3 -3
- package/dist/types/ContactsScope.js +3 -3
- package/dist/types/CoverageEntry.cjs +9 -9
- package/dist/types/CoverageEntry.js +9 -9
- package/dist/types/CoverageIntegration.cjs +3 -3
- package/dist/types/CoverageIntegration.js +3 -3
- package/dist/types/CoverageIntegrationRun.cjs +3 -3
- package/dist/types/CoverageIntegrationRun.js +3 -3
- package/dist/types/Culture.cjs +3 -3
- package/dist/types/Culture.js +3 -3
- package/dist/types/Currency.cjs +3 -3
- package/dist/types/Currency.js +3 -3
- package/dist/types/EmailRecipient.cjs +3 -3
- package/dist/types/EmailRecipient.js +3 -3
- package/dist/types/JobState.cjs +3 -3
- package/dist/types/JobState.js +3 -3
- package/dist/types/License.cjs +9 -9
- package/dist/types/License.js +9 -9
- package/dist/types/Newsroom.cjs +12 -12
- package/dist/types/Newsroom.js +12 -12
- package/dist/types/NewsroomDomain.cjs +6 -6
- package/dist/types/NewsroomDomain.js +6 -6
- package/dist/types/NewsroomGallery.cjs +6 -6
- package/dist/types/NewsroomGallery.js +6 -6
- package/dist/types/NewsroomTheme.cjs +8 -7
- package/dist/types/NewsroomTheme.js +8 -7
- package/dist/types/NewsroomWebhook.cjs +3 -3
- package/dist/types/NewsroomWebhook.js +3 -3
- package/dist/types/NotificationSubscription.cjs +3 -3
- package/dist/types/NotificationSubscription.js +3 -3
- package/dist/types/Permissions.cjs +3 -3
- package/dist/types/Permissions.js +3 -3
- package/dist/types/Plan.cjs +10 -10
- package/dist/types/Plan.js +11 -11
- package/dist/types/Price.cjs +6 -6
- package/dist/types/Price.js +6 -6
- package/dist/types/PrivacyRequest.cjs +6 -6
- package/dist/types/PrivacyRequest.js +6 -6
- package/dist/types/SenderAddress.cjs +3 -3
- package/dist/types/SenderAddress.js +3 -3
- package/dist/types/SenderDomain.cjs +3 -3
- package/dist/types/SenderDomain.js +3 -3
- package/dist/types/SortOrder.cjs +3 -3
- package/dist/types/SortOrder.js +3 -3
- package/dist/types/Story.cjs +12 -12
- package/dist/types/Story.js +12 -12
- package/dist/types/User.cjs +6 -6
- package/dist/types/User.js +6 -6
- package/dist/types/common/Notification.cjs +3 -3
- package/dist/types/common/Notification.js +3 -3
- package/dist/types/common/OEmbedInfo.cjs +3 -3
- package/dist/types/common/OEmbedInfo.js +3 -3
- package/dist/types/common/Pagination.cjs +3 -3
- package/dist/types/common/Pagination.js +3 -3
- package/dist/types/common/Query.js +1 -0
- 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
|
|
18
|
-
fetch
|
|
19
|
-
|
|
20
|
-
|
|
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,
|
|
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,
|
|
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
|
|
12
|
-
fetch
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
const api = createDeferredJobsApiClient(createApiClient(createHttpClient({
|
|
12
|
+
fetch,
|
|
13
|
+
baseUrl
|
|
14
|
+
}), {
|
|
15
15
|
accessToken,
|
|
16
|
-
baseUrl,
|
|
17
16
|
headers
|
|
18
17
|
}));
|
|
19
18
|
return {
|
package/dist/api/ApiClient.cjs
CHANGED
|
@@ -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
|
|
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(
|
|
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(
|
|
29
|
+
function post(url, {
|
|
35
30
|
headers,
|
|
36
31
|
payload,
|
|
37
32
|
query
|
|
38
33
|
} = {}) {
|
|
39
|
-
return http.post(
|
|
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(
|
|
43
|
+
function put(url, {
|
|
49
44
|
headers,
|
|
50
45
|
payload,
|
|
51
46
|
query
|
|
52
47
|
} = {}) {
|
|
53
|
-
return http.put(
|
|
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(
|
|
57
|
+
function patch(url, {
|
|
63
58
|
headers,
|
|
64
59
|
payload,
|
|
65
60
|
query
|
|
66
61
|
} = {}) {
|
|
67
|
-
return http.patch(
|
|
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(
|
|
71
|
+
function doDelete(url, {
|
|
77
72
|
headers,
|
|
78
73
|
payload,
|
|
79
74
|
query
|
|
80
75
|
} = {}) {
|
|
81
|
-
return http.delete(
|
|
76
|
+
return http.delete(url, {
|
|
82
77
|
headers: {
|
|
83
78
|
...defaultHeaders,
|
|
84
79
|
...headers
|
package/dist/api/ApiClient.d.ts
CHANGED
|
@@ -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,
|
|
9
|
-
get: <V = any>(
|
|
10
|
-
post: <
|
|
11
|
-
put: <
|
|
12
|
-
patch: <
|
|
13
|
-
delete: <
|
|
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
|
};
|
package/dist/api/ApiClient.js
CHANGED
|
@@ -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
|
|
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(
|
|
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(
|
|
23
|
+
function post(url, {
|
|
29
24
|
headers,
|
|
30
25
|
payload,
|
|
31
26
|
query
|
|
32
27
|
} = {}) {
|
|
33
|
-
return http.post(
|
|
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(
|
|
37
|
+
function put(url, {
|
|
43
38
|
headers,
|
|
44
39
|
payload,
|
|
45
40
|
query
|
|
46
41
|
} = {}) {
|
|
47
|
-
return http.put(
|
|
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(
|
|
51
|
+
function patch(url, {
|
|
57
52
|
headers,
|
|
58
53
|
payload,
|
|
59
54
|
query
|
|
60
55
|
} = {}) {
|
|
61
|
-
return http.patch(
|
|
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(
|
|
65
|
+
function doDelete(url, {
|
|
71
66
|
headers,
|
|
72
67
|
payload,
|
|
73
68
|
query
|
|
74
69
|
} = {}) {
|
|
75
|
-
return http.delete(
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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(
|
|
43
|
-
function get(
|
|
45
|
+
function createDeferredJobsApiClient(api) {
|
|
46
|
+
function get(url, {
|
|
44
47
|
headers,
|
|
45
48
|
query
|
|
46
49
|
} = {}) {
|
|
47
|
-
return handleDeferredJob(
|
|
50
|
+
return handleDeferredJob(api, api.get(url, {
|
|
48
51
|
headers,
|
|
49
52
|
query
|
|
50
53
|
}));
|
|
51
54
|
}
|
|
52
|
-
function post(
|
|
55
|
+
function post(url, {
|
|
53
56
|
headers,
|
|
54
57
|
payload,
|
|
55
58
|
query
|
|
56
59
|
} = {}) {
|
|
57
|
-
return handleDeferredJob(
|
|
60
|
+
return handleDeferredJob(api, api.post(url, {
|
|
58
61
|
headers,
|
|
59
62
|
payload,
|
|
60
63
|
query
|
|
61
64
|
}));
|
|
62
65
|
}
|
|
63
|
-
function put(
|
|
66
|
+
function put(url, {
|
|
64
67
|
headers,
|
|
65
68
|
payload,
|
|
66
69
|
query
|
|
67
70
|
} = {}) {
|
|
68
|
-
return handleDeferredJob(
|
|
71
|
+
return handleDeferredJob(api, api.put(url, {
|
|
69
72
|
headers,
|
|
70
73
|
payload,
|
|
71
74
|
query
|
|
72
75
|
}));
|
|
73
76
|
}
|
|
74
|
-
function patch(
|
|
77
|
+
function patch(url, {
|
|
75
78
|
headers,
|
|
76
79
|
payload,
|
|
77
80
|
query
|
|
78
81
|
} = {}) {
|
|
79
|
-
return handleDeferredJob(
|
|
82
|
+
return handleDeferredJob(api, api.patch(url, {
|
|
80
83
|
headers,
|
|
81
84
|
payload,
|
|
82
85
|
query
|
|
83
86
|
}));
|
|
84
87
|
}
|
|
85
|
-
function doDelete(
|
|
88
|
+
function doDelete(url, {
|
|
86
89
|
headers,
|
|
87
90
|
payload,
|
|
88
91
|
query
|
|
89
92
|
} = {}) {
|
|
90
|
-
return handleDeferredJob(
|
|
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 {
|
|
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(
|
|
6
|
-
get: <V = any, P = any>(
|
|
7
|
-
post: <
|
|
8
|
-
put: <
|
|
9
|
-
patch: <
|
|
10
|
-
delete: <
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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(
|
|
37
|
-
function get(
|
|
39
|
+
export function createDeferredJobsApiClient(api) {
|
|
40
|
+
function get(url, {
|
|
38
41
|
headers,
|
|
39
42
|
query
|
|
40
43
|
} = {}) {
|
|
41
|
-
return handleDeferredJob(
|
|
44
|
+
return handleDeferredJob(api, api.get(url, {
|
|
42
45
|
headers,
|
|
43
46
|
query
|
|
44
47
|
}));
|
|
45
48
|
}
|
|
46
|
-
function post(
|
|
49
|
+
function post(url, {
|
|
47
50
|
headers,
|
|
48
51
|
payload,
|
|
49
52
|
query
|
|
50
53
|
} = {}) {
|
|
51
|
-
return handleDeferredJob(
|
|
54
|
+
return handleDeferredJob(api, api.post(url, {
|
|
52
55
|
headers,
|
|
53
56
|
payload,
|
|
54
57
|
query
|
|
55
58
|
}));
|
|
56
59
|
}
|
|
57
|
-
function put(
|
|
60
|
+
function put(url, {
|
|
58
61
|
headers,
|
|
59
62
|
payload,
|
|
60
63
|
query
|
|
61
64
|
} = {}) {
|
|
62
|
-
return handleDeferredJob(
|
|
65
|
+
return handleDeferredJob(api, api.put(url, {
|
|
63
66
|
headers,
|
|
64
67
|
payload,
|
|
65
68
|
query
|
|
66
69
|
}));
|
|
67
70
|
}
|
|
68
|
-
function patch(
|
|
71
|
+
function patch(url, {
|
|
69
72
|
headers,
|
|
70
73
|
payload,
|
|
71
74
|
query
|
|
72
75
|
} = {}) {
|
|
73
|
-
return handleDeferredJob(
|
|
76
|
+
return handleDeferredJob(api, api.patch(url, {
|
|
74
77
|
headers,
|
|
75
78
|
payload,
|
|
76
79
|
query
|
|
77
80
|
}));
|
|
78
81
|
}
|
|
79
|
-
function doDelete(
|
|
82
|
+
function doDelete(url, {
|
|
80
83
|
headers,
|
|
81
84
|
payload,
|
|
82
85
|
query
|
|
83
86
|
} = {}) {
|
|
84
|
-
return handleDeferredJob(
|
|
87
|
+
return handleDeferredJob(api, api.delete(url, {
|
|
85
88
|
headers,
|
|
86
89
|
payload,
|
|
87
90
|
query
|
package/dist/api/constants.cjs
CHANGED
|
@@ -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 = "
|
|
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})`;
|
package/dist/api/constants.js
CHANGED
|
@@ -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[
|
|
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 =
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
17
|
-
}({});
|
|
17
|
+
})(SignupCurrency || (exports.SignupCurrency = SignupCurrency = {}));
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export let SignupPlan
|
|
1
|
+
export let SignupPlan;
|
|
2
|
+
(function (SignupPlan) {
|
|
2
3
|
SignupPlan["STARTER"] = "starter";
|
|
3
4
|
SignupPlan["CORE"] = "core";
|
|
4
5
|
SignupPlan["PREMIUM"] = "premium";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
})(SignupPlan || (SignupPlan = {}));
|
|
7
|
+
export let SignupCurrency;
|
|
8
|
+
(function (SignupCurrency) {
|
|
8
9
|
SignupCurrency["EUR"] = "eur";
|
|
9
10
|
SignupCurrency["USD"] = "usd";
|
|
10
|
-
|
|
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
|
-
|
|
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[
|
|
10
|
-
duplicate: (id: Campaign[
|
|
11
|
-
test: (id: Campaign[
|
|
12
|
-
send: (id: Campaign[
|
|
13
|
-
schedule: (id: Campaign[
|
|
14
|
-
unschedule: (id: 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[
|
|
19
|
-
delete: (id: Campaign[
|
|
18
|
+
update: (id: Campaign['id'], payload: UpdateRequest) => Promise<CampaignResponse>;
|
|
19
|
+
delete: (id: Campaign['id']) => Promise<void>;
|
|
20
20
|
};
|
|
@@ -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 =
|
|
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
|
-
|
|
19
|
-
}({});
|
|
19
|
+
})(Color || (exports.Color = Color = {}));
|