@prezly/sdk 16.9.0 → 17.1.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.
Files changed (41) hide show
  1. package/dist/Client.cjs +7 -3
  2. package/dist/Client.d.ts +4 -4
  3. package/dist/Client.js +8 -4
  4. package/dist/api/ApiClient.cjs +7 -7
  5. package/dist/api/ApiClient.d.ts +3 -2
  6. package/dist/api/ApiClient.js +7 -7
  7. package/dist/api/DeferredJobsApiClient.cjs +12 -9
  8. package/dist/api/DeferredJobsApiClient.d.ts +4 -3
  9. package/dist/api/DeferredJobsApiClient.js +13 -10
  10. package/dist/api/constants.cjs +1 -1
  11. package/dist/api/constants.js +1 -1
  12. package/dist/api/index.d.ts +1 -0
  13. package/dist/api/types.cjs +1 -0
  14. package/dist/api/types.d.ts +1 -0
  15. package/dist/api/types.js +1 -0
  16. package/dist/endpoints/index.cjs +1 -3
  17. package/dist/endpoints/index.d.ts +0 -1
  18. package/dist/endpoints/index.js +0 -1
  19. package/dist/http/HttpClient.cjs +71 -0
  20. package/dist/http/HttpClient.d.ts +12 -0
  21. package/dist/http/HttpClient.js +65 -0
  22. package/dist/http/createRequest.cjs +8 -7
  23. package/dist/http/createRequest.d.ts +2 -1
  24. package/dist/http/createRequest.js +8 -7
  25. package/dist/http/index.cjs +3 -3
  26. package/dist/http/index.d.ts +1 -1
  27. package/dist/http/index.js +1 -1
  28. package/dist/http/types.d.ts +2 -0
  29. package/package.json +1 -1
  30. package/dist/endpoints/Signup/Client.cjs +0 -21
  31. package/dist/endpoints/Signup/Client.d.ts +0 -7
  32. package/dist/endpoints/Signup/Client.js +0 -14
  33. package/dist/endpoints/Signup/index.cjs +0 -25
  34. package/dist/endpoints/Signup/index.d.ts +0 -2
  35. package/dist/endpoints/Signup/index.js +0 -2
  36. package/dist/endpoints/Signup/types.cjs +0 -12
  37. package/dist/endpoints/Signup/types.d.ts +0 -9
  38. package/dist/endpoints/Signup/types.js +0 -5
  39. package/dist/http/Http.cjs +0 -69
  40. package/dist/http/Http.d.ts +0 -8
  41. package/dist/http/Http.js +0 -62
package/dist/Client.cjs CHANGED
@@ -6,13 +6,18 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.createClient = createClient;
7
7
  var _index = require("./api/index.cjs");
8
8
  var _index2 = require("./endpoints/index.cjs");
9
+ var _index3 = require("./http/index.cjs");
9
10
  const DEFAULT_BASE_URL = 'https://api.prezly.com';
10
11
  function createClient({
11
12
  accessToken,
12
13
  baseUrl = DEFAULT_BASE_URL,
13
- headers = {}
14
+ headers = {},
15
+ fetch
14
16
  }) {
15
- const apiClient = new _index.DeferredJobsApiClient(new _index.ApiClient({
17
+ const http = (0, _index3.createHttpClient)({
18
+ fetch
19
+ });
20
+ const apiClient = new _index.DeferredJobsApiClient(http, new _index.ApiClient(http, {
16
21
  accessToken,
17
22
  baseUrl,
18
23
  headers
@@ -40,7 +45,6 @@ function createClient({
40
45
  newsroomHub: new _index2.NewsroomHub.Client(apiClient),
41
46
  pricingTables: new _index2.PricingTables.Client(apiClient),
42
47
  senderAddresses: new _index2.SenderAddresses.Client(apiClient),
43
- signup: new _index2.Signup.Client(apiClient),
44
48
  stories: new _index2.Stories.Client(apiClient),
45
49
  snippets: new _index2.Snippets.Client(apiClient),
46
50
  subscriptions: new _index2.Subscriptions.Client(apiClient),
package/dist/Client.d.ts CHANGED
@@ -1,11 +1,12 @@
1
- import { DeferredJobsApiClient } from './api';
1
+ import { DeferredJobsApiClient, type Fetch } from './api';
2
2
  import { Contacts } from './endpoints';
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
+ import { Accounts, Billing, Campaigns, CampaignRecipients, ContactsExports, Coverage, Jobs, Licenses, Newsrooms, NewsroomCategories, NewsroomContacts, NewsroomLanguages, NewsroomThemes, NewsroomWebhooks, NewsroomPrivacyRequests, NewsroomDomains, NewsroomGalleries, NewsroomHub, PricingTables, SenderAddresses, Stories, Snippets, Subscriptions, NotificationSubscriptions } from './endpoints';
4
4
  import type { HeadersMap } from './http';
5
5
  export interface ClientOptions {
6
6
  accessToken: string;
7
7
  baseUrl?: string;
8
8
  headers?: HeadersMap;
9
+ fetch?: Fetch;
9
10
  }
10
11
  export interface Client {
11
12
  api: DeferredJobsApiClient;
@@ -30,10 +31,9 @@ export interface Client {
30
31
  newsroomHub: NewsroomHub.Client;
31
32
  pricingTables: PricingTables.Client;
32
33
  senderAddresses: SenderAddresses.Client;
33
- signup: Signup.Client;
34
34
  stories: Stories.Client;
35
35
  snippets: Snippets.Client;
36
36
  subscriptions: Subscriptions.Client;
37
37
  notificationSubscriptions: NotificationSubscriptions.Client;
38
38
  }
39
- export declare function createClient({ accessToken, baseUrl, headers, }: ClientOptions): Client;
39
+ export declare function createClient({ accessToken, baseUrl, headers, fetch, }: ClientOptions): Client;
package/dist/Client.js CHANGED
@@ -1,13 +1,18 @@
1
1
  import { ApiClient, DeferredJobsApiClient } from "./api/index.js";
2
2
  import { Contacts } from "./endpoints/index.js";
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
+ import { Accounts, Billing, Campaigns, CampaignRecipients, ContactsExports, Coverage, Jobs, Licenses, Newsrooms, NewsroomCategories, NewsroomContacts, NewsroomLanguages, NewsroomThemes, NewsroomWebhooks, NewsroomPrivacyRequests, NewsroomDomains, NewsroomGalleries, NewsroomHub, PricingTables, SenderAddresses, Stories, Snippets, Subscriptions, NotificationSubscriptions } from "./endpoints/index.js";
4
+ import { createHttpClient } from "./http/index.js";
4
5
  const DEFAULT_BASE_URL = 'https://api.prezly.com';
5
6
  export function createClient({
6
7
  accessToken,
7
8
  baseUrl = DEFAULT_BASE_URL,
8
- headers = {}
9
+ headers = {},
10
+ fetch
9
11
  }) {
10
- const apiClient = new DeferredJobsApiClient(new ApiClient({
12
+ const http = createHttpClient({
13
+ fetch
14
+ });
15
+ const apiClient = new DeferredJobsApiClient(http, new ApiClient(http, {
11
16
  accessToken,
12
17
  baseUrl,
13
18
  headers
@@ -35,7 +40,6 @@ export function createClient({
35
40
  newsroomHub: new NewsroomHub.Client(apiClient),
36
41
  pricingTables: new PricingTables.Client(apiClient),
37
42
  senderAddresses: new SenderAddresses.Client(apiClient),
38
- signup: new Signup.Client(apiClient),
39
43
  stories: new Stories.Client(apiClient),
40
44
  snippets: new Snippets.Client(apiClient),
41
45
  subscriptions: new Subscriptions.Client(apiClient),
@@ -4,15 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.ApiClient = void 0;
7
- var _index = require("../http/index.cjs");
8
7
  var _utils = require("../utils.cjs");
9
8
  var _constants = require("./constants.cjs");
10
9
  class ApiClient {
11
- constructor({
10
+ constructor(http, {
12
11
  accessToken,
13
12
  baseUrl,
14
13
  headers
15
14
  }) {
15
+ this.http = http;
16
16
  this.baseUrl = baseUrl;
17
17
  this.headers = {
18
18
  authorization: `Bearer ${accessToken}`,
@@ -24,7 +24,7 @@ class ApiClient {
24
24
  headers,
25
25
  query
26
26
  } = {}) {
27
- return _index.Http.get(this.buildEndpointUrl(endpointUri), {
27
+ return this.http.get(this.buildEndpointUrl(endpointUri), {
28
28
  headers: {
29
29
  ...this.headers,
30
30
  ...headers
@@ -37,7 +37,7 @@ class ApiClient {
37
37
  payload,
38
38
  query
39
39
  } = {}) {
40
- return _index.Http.post(this.buildEndpointUrl(endpointUri), {
40
+ return this.http.post(this.buildEndpointUrl(endpointUri), {
41
41
  headers: {
42
42
  ...this.headers,
43
43
  ...headers
@@ -51,7 +51,7 @@ class ApiClient {
51
51
  payload,
52
52
  query
53
53
  } = {}) {
54
- return _index.Http.put(this.buildEndpointUrl(endpointUri), {
54
+ return this.http.put(this.buildEndpointUrl(endpointUri), {
55
55
  headers: {
56
56
  ...this.headers,
57
57
  ...headers
@@ -65,7 +65,7 @@ class ApiClient {
65
65
  payload,
66
66
  query
67
67
  } = {}) {
68
- return _index.Http.patch(this.buildEndpointUrl(endpointUri), {
68
+ return this.http.patch(this.buildEndpointUrl(endpointUri), {
69
69
  headers: {
70
70
  ...this.headers,
71
71
  ...headers
@@ -79,7 +79,7 @@ class ApiClient {
79
79
  payload,
80
80
  query
81
81
  } = {}) {
82
- return _index.Http.delete(this.buildEndpointUrl(endpointUri), {
82
+ return this.http.delete(this.buildEndpointUrl(endpointUri), {
83
83
  headers: {
84
84
  ...this.headers,
85
85
  ...headers
@@ -1,13 +1,14 @@
1
- import type { ApiResponse, HeadersMap, Params, ParamsWithPayload } from '../http';
1
+ import type { ApiResponse, HeadersMap, HttpClient, Params, ParamsWithPayload } from '../http';
2
2
  export interface Options {
3
3
  accessToken: string;
4
4
  baseUrl: string;
5
5
  headers: HeadersMap;
6
6
  }
7
7
  export declare class ApiClient {
8
+ private readonly http;
8
9
  private readonly baseUrl;
9
10
  private readonly headers;
10
- constructor({ accessToken, baseUrl, headers }: Options);
11
+ constructor(http: HttpClient, { accessToken, baseUrl, headers }: Options);
11
12
  get<V = any>(endpointUri: string, { headers, query }?: Params): Promise<ApiResponse<V>>;
12
13
  post<V = any>(endpointUri: string, { headers, payload, query }?: ParamsWithPayload): Promise<ApiResponse<V>>;
13
14
  put<V = any>(endpointUri: string, { headers, payload, query }?: ParamsWithPayload): Promise<ApiResponse<V>>;
@@ -1,12 +1,12 @@
1
- import { Http } from "../http/index.js";
2
1
  import { stripSlashes } from "../utils.js";
3
2
  import { DEFAULT_USER_AGENT } from "./constants.js";
4
3
  export class ApiClient {
5
- constructor({
4
+ constructor(http, {
6
5
  accessToken,
7
6
  baseUrl,
8
7
  headers
9
8
  }) {
9
+ this.http = http;
10
10
  this.baseUrl = baseUrl;
11
11
  this.headers = {
12
12
  authorization: `Bearer ${accessToken}`,
@@ -18,7 +18,7 @@ export class ApiClient {
18
18
  headers,
19
19
  query
20
20
  } = {}) {
21
- return Http.get(this.buildEndpointUrl(endpointUri), {
21
+ return this.http.get(this.buildEndpointUrl(endpointUri), {
22
22
  headers: {
23
23
  ...this.headers,
24
24
  ...headers
@@ -31,7 +31,7 @@ export class ApiClient {
31
31
  payload,
32
32
  query
33
33
  } = {}) {
34
- return Http.post(this.buildEndpointUrl(endpointUri), {
34
+ return this.http.post(this.buildEndpointUrl(endpointUri), {
35
35
  headers: {
36
36
  ...this.headers,
37
37
  ...headers
@@ -45,7 +45,7 @@ export class ApiClient {
45
45
  payload,
46
46
  query
47
47
  } = {}) {
48
- return Http.put(this.buildEndpointUrl(endpointUri), {
48
+ return this.http.put(this.buildEndpointUrl(endpointUri), {
49
49
  headers: {
50
50
  ...this.headers,
51
51
  ...headers
@@ -59,7 +59,7 @@ export class ApiClient {
59
59
  payload,
60
60
  query
61
61
  } = {}) {
62
- return Http.patch(this.buildEndpointUrl(endpointUri), {
62
+ return this.http.patch(this.buildEndpointUrl(endpointUri), {
63
63
  headers: {
64
64
  ...this.headers,
65
65
  ...headers
@@ -73,7 +73,7 @@ export class ApiClient {
73
73
  payload,
74
74
  query
75
75
  } = {}) {
76
- return Http.delete(this.buildEndpointUrl(endpointUri), {
76
+ return this.http.delete(this.buildEndpointUrl(endpointUri), {
77
77
  headers: {
78
78
  ...this.headers,
79
79
  ...headers
@@ -13,12 +13,14 @@ 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(request) {
16
+ async function handleDeferredJob(http, request) {
17
17
  const response = await request;
18
18
  if (response.status === _index.HttpCodes.ACCEPTED && (0, _index.isDeferredJobResponse)(response.payload)) {
19
19
  return new _progressPromise.ProgressPromise(async function (resolve, reject, progress) {
20
20
  do {
21
- const response = await _index.Http.get(_routing.routing.jobsUrl);
21
+ const response = await http.get(_routing.routing.jobsUrl, {
22
+ fetch
23
+ });
22
24
  const {
23
25
  job
24
26
  } = response.payload;
@@ -39,14 +41,15 @@ async function handleDeferredJob(request) {
39
41
  return _progressPromise.ProgressPromise.resolve(response.payload);
40
42
  }
41
43
  class DeferredJobsApiClient {
42
- constructor(apiClient) {
43
- this.apiClient = apiClient;
44
+ constructor(httpClient, apiClient) {
45
+ this.http = httpClient;
46
+ this.api = apiClient;
44
47
  }
45
48
  get(endpointUri, {
46
49
  headers,
47
50
  query
48
51
  } = {}) {
49
- return handleDeferredJob(this.apiClient.get(endpointUri, {
52
+ return handleDeferredJob(this.http, this.api.get(endpointUri, {
50
53
  headers,
51
54
  query
52
55
  }));
@@ -56,7 +59,7 @@ class DeferredJobsApiClient {
56
59
  payload,
57
60
  query
58
61
  } = {}) {
59
- return handleDeferredJob(this.apiClient.post(endpointUri, {
62
+ return handleDeferredJob(this.http, this.api.post(endpointUri, {
60
63
  headers,
61
64
  payload,
62
65
  query
@@ -67,7 +70,7 @@ class DeferredJobsApiClient {
67
70
  payload,
68
71
  query
69
72
  } = {}) {
70
- return handleDeferredJob(this.apiClient.put(endpointUri, {
73
+ return handleDeferredJob(this.http, this.api.put(endpointUri, {
71
74
  headers,
72
75
  payload,
73
76
  query
@@ -78,7 +81,7 @@ class DeferredJobsApiClient {
78
81
  payload,
79
82
  query
80
83
  } = {}) {
81
- return handleDeferredJob(this.apiClient.patch(endpointUri, {
84
+ return handleDeferredJob(this.http, this.api.patch(endpointUri, {
82
85
  headers,
83
86
  payload,
84
87
  query
@@ -89,7 +92,7 @@ class DeferredJobsApiClient {
89
92
  payload,
90
93
  query
91
94
  } = {}) {
92
- return handleDeferredJob(this.apiClient.delete(endpointUri, {
95
+ return handleDeferredJob(this.http, this.api.delete(endpointUri, {
93
96
  headers,
94
97
  payload,
95
98
  query
@@ -1,9 +1,10 @@
1
1
  import { ProgressPromise } from '@prezly/progress-promise';
2
- import type { Params, ParamsWithPayload } from '../http';
2
+ import type { HttpClient, Params, ParamsWithPayload } from '../http';
3
3
  import type { ApiClient } from './ApiClient';
4
4
  export declare class DeferredJobsApiClient {
5
- private readonly apiClient;
6
- constructor(apiClient: ApiClient);
5
+ private readonly http;
6
+ private readonly api;
7
+ constructor(httpClient: HttpClient, apiClient: ApiClient);
7
8
  get<V = any, P = any>(endpointUri: string, { headers, query }?: Params): ProgressPromise<V, P>;
8
9
  post<V = any, P = any>(endpointUri: string, { headers, payload, query }?: ParamsWithPayload): ProgressPromise<V, P>;
9
10
  put<V = any, P = any>(endpointUri: string, { headers, payload, query }?: ParamsWithPayload): ProgressPromise<V, P>;
@@ -1,5 +1,5 @@
1
1
  import { ProgressPromise } from '@prezly/progress-promise';
2
- import { Http, HttpCodes, isDeferredJobResponse } from "../http/index.js";
2
+ import { HttpCodes, isDeferredJobResponse } from "../http/index.js";
3
3
  import { routing } from "../routing.js";
4
4
  import { JobStatus } from "../types/index.js";
5
5
  const JOB_STATUS_POLLING_INTERVAL = 2000; // ms
@@ -7,12 +7,14 @@ 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(request) {
10
+ async function handleDeferredJob(http, request) {
11
11
  const response = await request;
12
12
  if (response.status === HttpCodes.ACCEPTED && isDeferredJobResponse(response.payload)) {
13
13
  return new ProgressPromise(async function (resolve, reject, progress) {
14
14
  do {
15
- const response = await Http.get(routing.jobsUrl);
15
+ const response = await http.get(routing.jobsUrl, {
16
+ fetch
17
+ });
16
18
  const {
17
19
  job
18
20
  } = response.payload;
@@ -33,14 +35,15 @@ async function handleDeferredJob(request) {
33
35
  return ProgressPromise.resolve(response.payload);
34
36
  }
35
37
  export class DeferredJobsApiClient {
36
- constructor(apiClient) {
37
- this.apiClient = apiClient;
38
+ constructor(httpClient, apiClient) {
39
+ this.http = httpClient;
40
+ this.api = apiClient;
38
41
  }
39
42
  get(endpointUri, {
40
43
  headers,
41
44
  query
42
45
  } = {}) {
43
- return handleDeferredJob(this.apiClient.get(endpointUri, {
46
+ return handleDeferredJob(this.http, this.api.get(endpointUri, {
44
47
  headers,
45
48
  query
46
49
  }));
@@ -50,7 +53,7 @@ export class DeferredJobsApiClient {
50
53
  payload,
51
54
  query
52
55
  } = {}) {
53
- return handleDeferredJob(this.apiClient.post(endpointUri, {
56
+ return handleDeferredJob(this.http, this.api.post(endpointUri, {
54
57
  headers,
55
58
  payload,
56
59
  query
@@ -61,7 +64,7 @@ export class DeferredJobsApiClient {
61
64
  payload,
62
65
  query
63
66
  } = {}) {
64
- return handleDeferredJob(this.apiClient.put(endpointUri, {
67
+ return handleDeferredJob(this.http, this.api.put(endpointUri, {
65
68
  headers,
66
69
  payload,
67
70
  query
@@ -72,7 +75,7 @@ export class DeferredJobsApiClient {
72
75
  payload,
73
76
  query
74
77
  } = {}) {
75
- return handleDeferredJob(this.apiClient.patch(endpointUri, {
78
+ return handleDeferredJob(this.http, this.api.patch(endpointUri, {
76
79
  headers,
77
80
  payload,
78
81
  query
@@ -83,7 +86,7 @@ export class DeferredJobsApiClient {
83
86
  payload,
84
87
  query
85
88
  } = {}) {
86
- return handleDeferredJob(this.apiClient.delete(endpointUri, {
89
+ return handleDeferredJob(this.http, this.api.delete(endpointUri, {
87
90
  headers,
88
91
  payload,
89
92
  query
@@ -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 = "16.8.0";
7
+ const VERSION = "17.0.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 = "16.8.0";
1
+ const VERSION = "17.0.0";
2
2
  const URL = 'https://github.com/prezly/javascript-sdk';
3
3
  export const DEFAULT_USER_AGENT = `prezly-javascript-sdk/${VERSION} (+${URL})`;
@@ -1,2 +1,3 @@
1
1
  export { ApiClient } from './ApiClient';
2
2
  export { DeferredJobsApiClient } from './DeferredJobsApiClient';
3
+ export type { Fetch } from './types';
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ export declare type Fetch = typeof fetch;
@@ -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.Contacts = exports.Campaigns = exports.CampaignRecipients = exports.Billing = exports.Accounts = void 0;
6
+ exports.NotificationSubscriptions = exports.Subscriptions = exports.Stories = exports.Snippets = 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"));
@@ -48,8 +48,6 @@ var _PricingTables = _interopRequireWildcard(require("./PricingTables/index.cjs"
48
48
  exports.PricingTables = _PricingTables;
49
49
  var _SenderAddresses = _interopRequireWildcard(require("./SenderAddresses/index.cjs"));
50
50
  exports.SenderAddresses = _SenderAddresses;
51
- var _Signup = _interopRequireWildcard(require("./Signup/index.cjs"));
52
- exports.Signup = _Signup;
53
51
  var _Snippets = _interopRequireWildcard(require("./Snippets/index.cjs"));
54
52
  exports.Snippets = _Snippets;
55
53
  var _Stories = _interopRequireWildcard(require("./Stories/index.cjs"));
@@ -20,7 +20,6 @@ export * as NewsroomThemes from './NewsroomThemes';
20
20
  export * as NewsroomWebhooks from './NewsroomWebhooks';
21
21
  export * as PricingTables from './PricingTables';
22
22
  export * as SenderAddresses from './SenderAddresses';
23
- export * as Signup from './Signup';
24
23
  export * as Snippets from './Snippets';
25
24
  export * as Stories from './Stories';
26
25
  export * as Subscriptions from './Subscriptions';
@@ -20,7 +20,6 @@ export * as NewsroomThemes from "./NewsroomThemes/index.js";
20
20
  export * as NewsroomWebhooks from "./NewsroomWebhooks/index.js";
21
21
  export * as PricingTables from "./PricingTables/index.js";
22
22
  export * as SenderAddresses from "./SenderAddresses/index.js";
23
- export * as Signup from "./Signup/index.js";
24
23
  export * as Snippets from "./Snippets/index.js";
25
24
  export * as Stories from "./Stories/index.js";
26
25
  export * as Subscriptions from "./Subscriptions/index.js";
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createHttpClient = createHttpClient;
7
+ var _createRequest = require("./createRequest.cjs");
8
+ var _types = require("./types.cjs");
9
+ function createHttpClient(options = {}) {
10
+ const fetchImpl = options.fetch ?? fetch;
11
+ return {
12
+ get(url, {
13
+ headers,
14
+ query
15
+ } = {}) {
16
+ return (0, _createRequest.createRequest)(fetchImpl, url, {
17
+ headers,
18
+ method: _types.Method.GET,
19
+ query
20
+ });
21
+ },
22
+ post(url, {
23
+ headers,
24
+ payload,
25
+ query
26
+ } = {}) {
27
+ return (0, _createRequest.createRequest)(fetchImpl, url, {
28
+ headers,
29
+ method: _types.Method.POST,
30
+ payload,
31
+ query
32
+ });
33
+ },
34
+ put(url, {
35
+ headers,
36
+ payload,
37
+ query
38
+ } = {}) {
39
+ return (0, _createRequest.createRequest)(fetchImpl, url, {
40
+ headers,
41
+ method: _types.Method.PUT,
42
+ payload,
43
+ query
44
+ });
45
+ },
46
+ patch(url, {
47
+ headers,
48
+ payload,
49
+ query
50
+ } = {}) {
51
+ return (0, _createRequest.createRequest)(fetchImpl, url, {
52
+ headers,
53
+ method: _types.Method.PATCH,
54
+ payload,
55
+ query
56
+ });
57
+ },
58
+ delete(url, {
59
+ headers,
60
+ payload,
61
+ query
62
+ } = {}) {
63
+ return (0, _createRequest.createRequest)(fetchImpl, url, {
64
+ headers,
65
+ method: _types.Method.DELETE,
66
+ payload,
67
+ query
68
+ });
69
+ }
70
+ };
71
+ }
@@ -0,0 +1,12 @@
1
+ import type { Fetch } from '../api';
2
+ import type { ApiResponse, Params, ParamsWithPayload } from './types';
3
+ export interface HttpClient {
4
+ get<V = any>(url: string, params?: Params): Promise<ApiResponse<V>>;
5
+ post<V = any>(url: string, params?: ParamsWithPayload): Promise<ApiResponse<V>>;
6
+ put<V = any>(url: string, params?: ParamsWithPayload): Promise<ApiResponse<V>>;
7
+ patch<V = any>(url: string, params?: ParamsWithPayload): Promise<ApiResponse<V>>;
8
+ delete<V = any>(url: string, params?: ParamsWithPayload): Promise<ApiResponse<V>>;
9
+ }
10
+ export declare function createHttpClient(options?: {
11
+ fetch?: Fetch;
12
+ }): HttpClient;
@@ -0,0 +1,65 @@
1
+ import { createRequest } from "./createRequest.js";
2
+ import { Method } from "./types.js";
3
+ export function createHttpClient(options = {}) {
4
+ const fetchImpl = options.fetch ?? fetch;
5
+ return {
6
+ get(url, {
7
+ headers,
8
+ query
9
+ } = {}) {
10
+ return createRequest(fetchImpl, url, {
11
+ headers,
12
+ method: Method.GET,
13
+ query
14
+ });
15
+ },
16
+ post(url, {
17
+ headers,
18
+ payload,
19
+ query
20
+ } = {}) {
21
+ return createRequest(fetchImpl, url, {
22
+ headers,
23
+ method: Method.POST,
24
+ payload,
25
+ query
26
+ });
27
+ },
28
+ put(url, {
29
+ headers,
30
+ payload,
31
+ query
32
+ } = {}) {
33
+ return createRequest(fetchImpl, url, {
34
+ headers,
35
+ method: Method.PUT,
36
+ payload,
37
+ query
38
+ });
39
+ },
40
+ patch(url, {
41
+ headers,
42
+ payload,
43
+ query
44
+ } = {}) {
45
+ return createRequest(fetchImpl, url, {
46
+ headers,
47
+ method: Method.PATCH,
48
+ payload,
49
+ query
50
+ });
51
+ },
52
+ delete(url, {
53
+ headers,
54
+ payload,
55
+ query
56
+ } = {}) {
57
+ return createRequest(fetchImpl, url, {
58
+ headers,
59
+ method: Method.DELETE,
60
+ payload,
61
+ query
62
+ });
63
+ }
64
+ };
65
+ }
@@ -39,15 +39,16 @@ function createFakeErrorPayload({
39
39
  }
40
40
  };
41
41
  }
42
- async function createRequest(url, {
43
- headers,
44
- method,
45
- payload,
46
- query
47
- }) {
42
+ async function createRequest(fetchImpl, url, options) {
43
+ const {
44
+ headers,
45
+ method,
46
+ payload,
47
+ query
48
+ } = options;
48
49
  try {
49
50
  const urlWithQuery = (0, _lib.createUrlWithQuery)(url, query);
50
- const response = await fetch(urlWithQuery.href, {
51
+ const response = await fetchImpl(urlWithQuery.href, {
51
52
  method,
52
53
  headers: {
53
54
  Accept: 'application/json',
@@ -1,3 +1,4 @@
1
+ import type { Fetch } from '../api';
1
2
  import type { Method, HeadersMap, ApiResponse } from './types';
2
3
  export declare function createFakeErrorPayload({ status, statusText, }: {
3
4
  status?: number;
@@ -13,7 +14,7 @@ export declare function createFakeErrorPayload({ status, statusText, }: {
13
14
  }[];
14
15
  };
15
16
  };
16
- export declare function createRequest<P = any>(url: string, { headers, method, payload, query, }: {
17
+ export declare function createRequest<P = any>(fetchImpl: Fetch, url: string, options: {
17
18
  headers?: HeadersMap;
18
19
  method: Method;
19
20
  payload?: object;
@@ -32,15 +32,16 @@ export function createFakeErrorPayload({
32
32
  }
33
33
  };
34
34
  }
35
- export async function createRequest(url, {
36
- headers,
37
- method,
38
- payload,
39
- query
40
- }) {
35
+ export async function createRequest(fetchImpl, url, options) {
36
+ const {
37
+ headers,
38
+ method,
39
+ payload,
40
+ query
41
+ } = options;
41
42
  try {
42
43
  const urlWithQuery = createUrlWithQuery(url, query);
43
- const response = await fetch(urlWithQuery.href, {
44
+ const response = await fetchImpl(urlWithQuery.href, {
44
45
  method,
45
46
  headers: {
46
47
  Accept: 'application/json',
@@ -9,10 +9,10 @@ Object.defineProperty(exports, "ApiError", {
9
9
  return _ApiError.ApiError;
10
10
  }
11
11
  });
12
- Object.defineProperty(exports, "Http", {
12
+ Object.defineProperty(exports, "createHttpClient", {
13
13
  enumerable: true,
14
14
  get: function () {
15
- return _Http.Http;
15
+ return _HttpClient.createHttpClient;
16
16
  }
17
17
  });
18
18
  Object.defineProperty(exports, "isDeferredJobResponse", {
@@ -34,6 +34,6 @@ Object.defineProperty(exports, "Method", {
34
34
  }
35
35
  });
36
36
  var _ApiError = require("./ApiError.cjs");
37
- var _Http = require("./Http.cjs");
37
+ var _HttpClient = require("./HttpClient.cjs");
38
38
  var _lib = require("./lib.cjs");
39
39
  var _types = require("./types.cjs");
@@ -1,4 +1,4 @@
1
1
  export { ApiError } from './ApiError';
2
- export { Http } from './Http';
2
+ export { type HttpClient, createHttpClient } from './HttpClient';
3
3
  export { isDeferredJobResponse } from './lib';
4
4
  export { type ApiResponse, type HeadersMap, type Params, type ParamsWithPayload, HttpCodes, Method, } from './types';
@@ -1,4 +1,4 @@
1
1
  export { ApiError } from "./ApiError.js";
2
- export { Http } from "./Http.js";
2
+ export { createHttpClient } from "./HttpClient.js";
3
3
  export { isDeferredJobResponse } from "./lib.js";
4
4
  export { HttpCodes, Method } from "./types.js";
@@ -1,3 +1,4 @@
1
+ import type { Fetch } from '../api';
1
2
  export declare enum HttpCodes {
2
3
  ACCEPTED = 202,
3
4
  NO_CONTENT = 204,
@@ -17,6 +18,7 @@ export interface HeadersMap {
17
18
  [name: string]: string;
18
19
  }
19
20
  export interface Params {
21
+ fetch?: Fetch;
20
22
  headers?: HeadersMap;
21
23
  query?: Record<string, undefined | boolean | number | string | number[] | string[]>;
22
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prezly/sdk",
3
- "version": "16.9.0",
3
+ "version": "17.1.0",
4
4
  "description": "Prezly API SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -1,21 +0,0 @@
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
- class Client {
9
- constructor(apiClient) {
10
- this.apiClient = apiClient;
11
- }
12
- async checkEmailAvailability(email) {
13
- const url = `${_routing.routing.signup}/check-availability`;
14
- return this.apiClient.post(url, {
15
- payload: {
16
- email
17
- }
18
- });
19
- }
20
- }
21
- exports.Client = Client;
@@ -1,7 +0,0 @@
1
- import type { DeferredJobsApiClient } from '../../api';
2
- import type { CheckEmailAvailabilityResponse } from './types';
3
- export declare class Client {
4
- private readonly apiClient;
5
- constructor(apiClient: DeferredJobsApiClient);
6
- checkEmailAvailability(email: string): Promise<CheckEmailAvailabilityResponse>;
7
- }
@@ -1,14 +0,0 @@
1
- import { routing } from "../../routing.js";
2
- export class Client {
3
- constructor(apiClient) {
4
- this.apiClient = apiClient;
5
- }
6
- async checkEmailAvailability(email) {
7
- const url = `${routing.signup}/check-availability`;
8
- return this.apiClient.post(url, {
9
- payload: {
10
- email
11
- }
12
- });
13
- }
14
- }
@@ -1,25 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _Client = require("./Client.cjs");
7
- Object.keys(_Client).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- Object.defineProperty(exports, key, {
10
- enumerable: true,
11
- get: function () {
12
- return _Client[key];
13
- }
14
- });
15
- });
16
- var _types = require("./types.cjs");
17
- Object.keys(_types).forEach(function (key) {
18
- if (key === "default" || key === "__esModule") return;
19
- Object.defineProperty(exports, key, {
20
- enumerable: true,
21
- get: function () {
22
- return _types[key];
23
- }
24
- });
25
- });
@@ -1,2 +0,0 @@
1
- export * from './Client';
2
- export * from './types';
@@ -1,2 +0,0 @@
1
- export * from "./Client.js";
2
- export * from "./types.js";
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.EmailAvailability = void 0;
7
- let EmailAvailability;
8
- exports.EmailAvailability = EmailAvailability;
9
- (function (EmailAvailability) {
10
- EmailAvailability["AVAILABLE"] = "available";
11
- EmailAvailability["TAKEN"] = "taken";
12
- })(EmailAvailability || (exports.EmailAvailability = EmailAvailability = {}));
@@ -1,9 +0,0 @@
1
- export declare enum EmailAvailability {
2
- AVAILABLE = "available",
3
- TAKEN = "taken"
4
- }
5
- export interface CheckEmailAvailabilityResponse {
6
- result: {
7
- email: EmailAvailability;
8
- };
9
- }
@@ -1,5 +0,0 @@
1
- export let EmailAvailability;
2
- (function (EmailAvailability) {
3
- EmailAvailability["AVAILABLE"] = "available";
4
- EmailAvailability["TAKEN"] = "taken";
5
- })(EmailAvailability || (EmailAvailability = {}));
@@ -1,69 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Http = void 0;
7
- var _createRequest = require("./createRequest.cjs");
8
- var _types = require("./types.cjs");
9
- const Http = {
10
- get(url, {
11
- headers,
12
- query
13
- } = {}) {
14
- return (0, _createRequest.createRequest)(url, {
15
- headers,
16
- method: _types.Method.GET,
17
- query
18
- });
19
- },
20
- post(url, {
21
- headers,
22
- payload,
23
- query
24
- } = {}) {
25
- return (0, _createRequest.createRequest)(url, {
26
- headers,
27
- method: _types.Method.POST,
28
- payload,
29
- query
30
- });
31
- },
32
- put(url, {
33
- headers,
34
- payload,
35
- query
36
- } = {}) {
37
- return (0, _createRequest.createRequest)(url, {
38
- headers,
39
- method: _types.Method.PUT,
40
- payload,
41
- query
42
- });
43
- },
44
- patch(url, {
45
- headers,
46
- payload,
47
- query
48
- } = {}) {
49
- return (0, _createRequest.createRequest)(url, {
50
- headers,
51
- method: _types.Method.PATCH,
52
- payload,
53
- query
54
- });
55
- },
56
- delete(url, {
57
- headers,
58
- payload,
59
- query
60
- } = {}) {
61
- return (0, _createRequest.createRequest)(url, {
62
- headers,
63
- method: _types.Method.DELETE,
64
- payload,
65
- query
66
- });
67
- }
68
- };
69
- exports.Http = Http;
@@ -1,8 +0,0 @@
1
- import type { ApiResponse, Params, ParamsWithPayload } from './types';
2
- export declare const Http: {
3
- get<V = any>(url: string, { headers, query }?: Params): Promise<ApiResponse<V>>;
4
- post<V_1 = any>(url: string, { headers, payload, query }?: ParamsWithPayload): Promise<ApiResponse<V_1>>;
5
- put<V_2 = any>(url: string, { headers, payload, query }?: ParamsWithPayload): Promise<ApiResponse<V_2>>;
6
- patch<V_3 = any>(url: string, { headers, payload, query }?: ParamsWithPayload): Promise<ApiResponse<V_3>>;
7
- delete<V_4 = any>(url: string, { headers, payload, query }?: ParamsWithPayload): Promise<ApiResponse<V_4>>;
8
- };
package/dist/http/Http.js DELETED
@@ -1,62 +0,0 @@
1
- import { createRequest } from "./createRequest.js";
2
- import { Method } from "./types.js";
3
- export const Http = {
4
- get(url, {
5
- headers,
6
- query
7
- } = {}) {
8
- return createRequest(url, {
9
- headers,
10
- method: Method.GET,
11
- query
12
- });
13
- },
14
- post(url, {
15
- headers,
16
- payload,
17
- query
18
- } = {}) {
19
- return createRequest(url, {
20
- headers,
21
- method: Method.POST,
22
- payload,
23
- query
24
- });
25
- },
26
- put(url, {
27
- headers,
28
- payload,
29
- query
30
- } = {}) {
31
- return createRequest(url, {
32
- headers,
33
- method: Method.PUT,
34
- payload,
35
- query
36
- });
37
- },
38
- patch(url, {
39
- headers,
40
- payload,
41
- query
42
- } = {}) {
43
- return createRequest(url, {
44
- headers,
45
- method: Method.PATCH,
46
- payload,
47
- query
48
- });
49
- },
50
- delete(url, {
51
- headers,
52
- payload,
53
- query
54
- } = {}) {
55
- return createRequest(url, {
56
- headers,
57
- method: Method.DELETE,
58
- payload,
59
- query
60
- });
61
- }
62
- };