@prezly/sdk 22.10.0 → 23.0.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
@@ -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_1 = any>(endpointUri: string, { headers, payload, query }?: ParamsWithPayload) => Promise<ApiResponse<V_1>>;
11
- put: <V_2 = any>(endpointUri: string, { headers, payload, query }?: ParamsWithPayload) => Promise<ApiResponse<V_2>>;
12
- patch: <V_3 = any>(endpointUri: string, { headers, payload, query }?: ParamsWithPayload) => Promise<ApiResponse<V_3>>;
13
- delete: <V_4 = any>(endpointUri: string, { headers, payload, query }?: ParamsWithPayload) => Promise<ApiResponse<V_4>>;
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,80 @@ 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) {
16
+ function handleDeferredJob(api, request) {
17
+ return new _progressPromise.ProgressPromise(async (resolve, reject, update) => {
18
+ const response = await request;
19
+ if (response.status === _index.HttpCodes.ACCEPTED && (0, _index.isDeferredJobResponse)(response.payload)) {
20
+ const id = response.payload.progress.id;
20
21
  do {
21
- const response = await http.get(_routing.routing.jobsUrl, {
22
+ const response = await api.get(`${_routing.routing.jobsUrl}/${id}`, {
22
23
  fetch
23
24
  });
24
- const {
25
- job
26
- } = response.payload;
27
- if (job.status === _index2.JobStatus.RESOLVED) {
28
- resolve(job.value);
25
+ const state = response.payload.job.state;
26
+ if (state.status === _index2.JobStatus.RESOLVED) {
27
+ resolve(state.value);
29
28
  return;
30
29
  }
31
- if (job.status === _index2.JobStatus.REJECTED) {
32
- reject(job.value);
30
+ if (state.status === _index2.JobStatus.REJECTED) {
31
+ reject(state.value);
33
32
  return;
34
33
  }
35
- progress(job.progress, job.value);
34
+ update(state.progress, state.value);
36
35
  await sleep(JOB_STATUS_POLLING_INTERVAL);
37
36
  } while (true); // eslint-disable-line no-constant-condition
38
- });
39
- }
40
- return _progressPromise.ProgressPromise.resolve(response.payload);
37
+ }
38
+ resolve(response.payload);
39
+ });
41
40
  }
42
- function createDeferredJobsApiClient(http, api) {
43
- function get(endpointUri, {
41
+ function createDeferredJobsApiClient(api) {
42
+ function get(url, {
44
43
  headers,
45
44
  query
46
45
  } = {}) {
47
- return handleDeferredJob(http, api.get(endpointUri, {
46
+ return handleDeferredJob(api, api.get(url, {
48
47
  headers,
49
48
  query
50
49
  }));
51
50
  }
52
- function post(endpointUri, {
51
+ function post(url, {
53
52
  headers,
54
53
  payload,
55
54
  query
56
55
  } = {}) {
57
- return handleDeferredJob(http, api.post(endpointUri, {
56
+ return handleDeferredJob(api, api.post(url, {
58
57
  headers,
59
58
  payload,
60
59
  query
61
60
  }));
62
61
  }
63
- function put(endpointUri, {
62
+ function put(url, {
64
63
  headers,
65
64
  payload,
66
65
  query
67
66
  } = {}) {
68
- return handleDeferredJob(http, api.put(endpointUri, {
67
+ return handleDeferredJob(api, api.put(url, {
69
68
  headers,
70
69
  payload,
71
70
  query
72
71
  }));
73
72
  }
74
- function patch(endpointUri, {
73
+ function patch(url, {
75
74
  headers,
76
75
  payload,
77
76
  query
78
77
  } = {}) {
79
- return handleDeferredJob(http, api.patch(endpointUri, {
78
+ return handleDeferredJob(api, api.patch(url, {
80
79
  headers,
81
80
  payload,
82
81
  query
83
82
  }));
84
83
  }
85
- function doDelete(endpointUri, {
84
+ function doDelete(url, {
86
85
  headers,
87
86
  payload,
88
87
  query
89
88
  } = {}) {
90
- return handleDeferredJob(http, api.delete(endpointUri, {
89
+ return handleDeferredJob(api, api.delete(url, {
91
90
  headers,
92
91
  payload,
93
92
  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_1 = any, P_1 = any>(endpointUri: string, { headers, payload, query }?: ParamsWithPayload) => ProgressPromise<V_1, P_1>;
8
- put: <V_2 = any, P_2 = any>(endpointUri: string, { headers, payload, query }?: ParamsWithPayload) => ProgressPromise<V_2, P_2>;
9
- patch: <V_3 = any, P_3 = any>(endpointUri: string, { headers, payload, query }?: ParamsWithPayload) => ProgressPromise<V_3, P_3>;
10
- delete: <V_4 = any, P_4 = any>(endpointUri: string, { headers, payload, query }?: ParamsWithPayload) => ProgressPromise<V_4, P_4>;
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,80 @@ 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) {
10
+ function handleDeferredJob(api, request) {
11
+ return new ProgressPromise(async (resolve, reject, update) => {
12
+ const response = await request;
13
+ if (response.status === HttpCodes.ACCEPTED && isDeferredJobResponse(response.payload)) {
14
+ const id = response.payload.progress.id;
14
15
  do {
15
- const response = await http.get(routing.jobsUrl, {
16
+ const response = await api.get(`${routing.jobsUrl}/${id}`, {
16
17
  fetch
17
18
  });
18
- const {
19
- job
20
- } = response.payload;
21
- if (job.status === JobStatus.RESOLVED) {
22
- resolve(job.value);
19
+ const state = response.payload.job.state;
20
+ if (state.status === JobStatus.RESOLVED) {
21
+ resolve(state.value);
23
22
  return;
24
23
  }
25
- if (job.status === JobStatus.REJECTED) {
26
- reject(job.value);
24
+ if (state.status === JobStatus.REJECTED) {
25
+ reject(state.value);
27
26
  return;
28
27
  }
29
- progress(job.progress, job.value);
28
+ update(state.progress, state.value);
30
29
  await sleep(JOB_STATUS_POLLING_INTERVAL);
31
30
  } while (true); // eslint-disable-line no-constant-condition
32
- });
33
- }
34
- return ProgressPromise.resolve(response.payload);
31
+ }
32
+ resolve(response.payload);
33
+ });
35
34
  }
36
- export function createDeferredJobsApiClient(http, api) {
37
- function get(endpointUri, {
35
+ export function createDeferredJobsApiClient(api) {
36
+ function get(url, {
38
37
  headers,
39
38
  query
40
39
  } = {}) {
41
- return handleDeferredJob(http, api.get(endpointUri, {
40
+ return handleDeferredJob(api, api.get(url, {
42
41
  headers,
43
42
  query
44
43
  }));
45
44
  }
46
- function post(endpointUri, {
45
+ function post(url, {
47
46
  headers,
48
47
  payload,
49
48
  query
50
49
  } = {}) {
51
- return handleDeferredJob(http, api.post(endpointUri, {
50
+ return handleDeferredJob(api, api.post(url, {
52
51
  headers,
53
52
  payload,
54
53
  query
55
54
  }));
56
55
  }
57
- function put(endpointUri, {
56
+ function put(url, {
58
57
  headers,
59
58
  payload,
60
59
  query
61
60
  } = {}) {
62
- return handleDeferredJob(http, api.put(endpointUri, {
61
+ return handleDeferredJob(api, api.put(url, {
63
62
  headers,
64
63
  payload,
65
64
  query
66
65
  }));
67
66
  }
68
- function patch(endpointUri, {
67
+ function patch(url, {
69
68
  headers,
70
69
  payload,
71
70
  query
72
71
  } = {}) {
73
- return handleDeferredJob(http, api.patch(endpointUri, {
72
+ return handleDeferredJob(api, api.patch(url, {
74
73
  headers,
75
74
  payload,
76
75
  query
77
76
  }));
78
77
  }
79
- function doDelete(endpointUri, {
78
+ function doDelete(url, {
80
79
  headers,
81
80
  payload,
82
81
  query
83
82
  } = {}) {
84
- return handleDeferredJob(http, api.delete(endpointUri, {
83
+ return handleDeferredJob(api, api.delete(url, {
85
84
  headers,
86
85
  payload,
87
86
  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.9.0";
7
+ const VERSION = "22.10.1";
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.9.0";
1
+ const VERSION = "22.10.1";
2
2
  const URL = 'https://github.com/prezly/javascript-sdk';
3
3
  export const DEFAULT_USER_AGENT = `prezly-javascript-sdk/${VERSION} (+${URL})`;
@@ -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
  });
@@ -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
  });
@@ -123,7 +123,7 @@ function createClient(api) {
123
123
  });
124
124
  return contact;
125
125
  }
126
- async function bulkTag(selector, tags) {
126
+ function bulkTag(selector, tags) {
127
127
  const {
128
128
  scope,
129
129
  query
@@ -136,7 +136,7 @@ function createClient(api) {
136
136
  }
137
137
  });
138
138
  }
139
- async function bulkUntag(selector, tags) {
139
+ function bulkUntag(selector, tags) {
140
140
  const {
141
141
  query,
142
142
  scope
@@ -117,7 +117,7 @@ export function createClient(api) {
117
117
  });
118
118
  return contact;
119
119
  }
120
- async function bulkTag(selector, tags) {
120
+ function bulkTag(selector, tags) {
121
121
  const {
122
122
  scope,
123
123
  query
@@ -130,7 +130,7 @@ export function createClient(api) {
130
130
  }
131
131
  });
132
132
  }
133
- async function bulkUntag(selector, tags) {
133
+ function bulkUntag(selector, tags) {
134
134
  const {
135
135
  query,
136
136
  scope
@@ -95,7 +95,7 @@ function createClient(api) {
95
95
  async function doDelete(id) {
96
96
  return api.delete(`${_routing.routing.coverageUrl}/${id}`);
97
97
  }
98
- async function bulkDelete(options) {
98
+ function bulkDelete(options) {
99
99
  const {
100
100
  selection,
101
101
  query
@@ -89,7 +89,7 @@ export function createClient(api) {
89
89
  async function doDelete(id) {
90
90
  return api.delete(`${routing.coverageUrl}/${id}`);
91
91
  }
92
- async function bulkDelete(options) {
92
+ function bulkDelete(options) {
93
93
  const {
94
94
  selection,
95
95
  query
@@ -190,7 +190,8 @@ function createClient(api) {
190
190
  }
191
191
  async function translate(id, payload = {}, options) {
192
192
  const {
193
- culture
193
+ culture,
194
+ auto = false
194
195
  } = payload ?? {};
195
196
  const {
196
197
  include,
@@ -205,7 +206,8 @@ function createClient(api) {
205
206
  include
206
207
  },
207
208
  payload: {
208
- culture
209
+ culture,
210
+ auto
209
211
  }
210
212
  });
211
213
  return story;
@@ -182,7 +182,8 @@ export function createClient(api) {
182
182
  }
183
183
  async function translate(id, payload = {}, options) {
184
184
  const {
185
- culture
185
+ culture,
186
+ auto = false
186
187
  } = payload ?? {};
187
188
  const {
188
189
  include,
@@ -197,7 +198,8 @@ export function createClient(api) {
197
198
  include
198
199
  },
199
200
  payload: {
200
- culture
201
+ culture,
202
+ auto
201
203
  }
202
204
  });
203
205
  return story;
@@ -7,13 +7,20 @@ exports.createHttpClient = createHttpClient;
7
7
  var _createRequest = require("./createRequest.cjs");
8
8
  var _types = require("./types.cjs");
9
9
  function createHttpClient(options = {}) {
10
+ const baseUrl = options.baseUrl ?? null;
10
11
  const fetchImpl = options.fetch ?? fetch;
12
+ function resolveUrl(url) {
13
+ if (baseUrl) {
14
+ return new URL(url, baseUrl).toString();
15
+ }
16
+ return url;
17
+ }
11
18
  return {
12
19
  get(url, {
13
20
  headers,
14
21
  query
15
22
  } = {}) {
16
- return (0, _createRequest.createRequest)(fetchImpl, url, {
23
+ return (0, _createRequest.createRequest)(fetchImpl, resolveUrl(url), {
17
24
  headers,
18
25
  method: _types.Method.GET,
19
26
  query
@@ -24,7 +31,7 @@ function createHttpClient(options = {}) {
24
31
  payload,
25
32
  query
26
33
  } = {}) {
27
- return (0, _createRequest.createRequest)(fetchImpl, url, {
34
+ return (0, _createRequest.createRequest)(fetchImpl, resolveUrl(url), {
28
35
  headers,
29
36
  method: _types.Method.POST,
30
37
  payload,
@@ -36,7 +43,7 @@ function createHttpClient(options = {}) {
36
43
  payload,
37
44
  query
38
45
  } = {}) {
39
- return (0, _createRequest.createRequest)(fetchImpl, url, {
46
+ return (0, _createRequest.createRequest)(fetchImpl, resolveUrl(url), {
40
47
  headers,
41
48
  method: _types.Method.PUT,
42
49
  payload,
@@ -48,7 +55,7 @@ function createHttpClient(options = {}) {
48
55
  payload,
49
56
  query
50
57
  } = {}) {
51
- return (0, _createRequest.createRequest)(fetchImpl, url, {
58
+ return (0, _createRequest.createRequest)(fetchImpl, resolveUrl(url), {
52
59
  headers,
53
60
  method: _types.Method.PATCH,
54
61
  payload,
@@ -60,7 +67,7 @@ function createHttpClient(options = {}) {
60
67
  payload,
61
68
  query
62
69
  } = {}) {
63
- return (0, _createRequest.createRequest)(fetchImpl, url, {
70
+ return (0, _createRequest.createRequest)(fetchImpl, resolveUrl(url), {
64
71
  headers,
65
72
  method: _types.Method.DELETE,
66
73
  payload,
@@ -8,5 +8,6 @@ export interface HttpClient {
8
8
  delete<V = any>(url: string, params?: ParamsWithPayload): Promise<ApiResponse<V>>;
9
9
  }
10
10
  export declare function createHttpClient(options?: {
11
+ baseUrl?: string;
11
12
  fetch?: Fetch;
12
13
  }): HttpClient;
@@ -1,13 +1,20 @@
1
1
  import { createRequest } from "./createRequest.js";
2
2
  import { Method } from "./types.js";
3
3
  export function createHttpClient(options = {}) {
4
+ const baseUrl = options.baseUrl ?? null;
4
5
  const fetchImpl = options.fetch ?? fetch;
6
+ function resolveUrl(url) {
7
+ if (baseUrl) {
8
+ return new URL(url, baseUrl).toString();
9
+ }
10
+ return url;
11
+ }
5
12
  return {
6
13
  get(url, {
7
14
  headers,
8
15
  query
9
16
  } = {}) {
10
- return createRequest(fetchImpl, url, {
17
+ return createRequest(fetchImpl, resolveUrl(url), {
11
18
  headers,
12
19
  method: Method.GET,
13
20
  query
@@ -18,7 +25,7 @@ export function createHttpClient(options = {}) {
18
25
  payload,
19
26
  query
20
27
  } = {}) {
21
- return createRequest(fetchImpl, url, {
28
+ return createRequest(fetchImpl, resolveUrl(url), {
22
29
  headers,
23
30
  method: Method.POST,
24
31
  payload,
@@ -30,7 +37,7 @@ export function createHttpClient(options = {}) {
30
37
  payload,
31
38
  query
32
39
  } = {}) {
33
- return createRequest(fetchImpl, url, {
40
+ return createRequest(fetchImpl, resolveUrl(url), {
34
41
  headers,
35
42
  method: Method.PUT,
36
43
  payload,
@@ -42,7 +49,7 @@ export function createHttpClient(options = {}) {
42
49
  payload,
43
50
  query
44
51
  } = {}) {
45
- return createRequest(fetchImpl, url, {
52
+ return createRequest(fetchImpl, resolveUrl(url), {
46
53
  headers,
47
54
  method: Method.PATCH,
48
55
  payload,
@@ -54,7 +61,7 @@ export function createHttpClient(options = {}) {
54
61
  payload,
55
62
  query
56
63
  } = {}) {
57
- return createRequest(fetchImpl, url, {
64
+ return createRequest(fetchImpl, resolveUrl(url), {
58
65
  headers,
59
66
  method: Method.DELETE,
60
67
  payload,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prezly/sdk",
3
- "version": "22.10.0",
3
+ "version": "23.0.0",
4
4
  "description": "Prezly API SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",