@prezly/sdk 25.6.0 → 25.8.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 +4 -2
- package/dist/Client.d.ts +4 -2
- package/dist/Client.js +4 -2
- package/dist/api/constants.cjs +1 -1
- package/dist/api/constants.js +1 -1
- package/dist/endpoints/Campaigns/Client.cjs +4 -2
- package/dist/endpoints/Campaigns/Client.d.ts +2 -2
- package/dist/endpoints/Campaigns/Client.js +4 -2
- package/dist/endpoints/Campaigns/types.d.ts +3 -0
- package/dist/endpoints/Stories/Client.d.ts +1 -1
- package/dist/http/HttpClient.cjs +6 -5
- package/dist/http/HttpClient.d.ts +6 -2
- package/dist/http/HttpClient.js +6 -5
- package/dist/http/createRequest.cjs +4 -2
- package/dist/http/createRequest.d.ts +3 -2
- package/dist/http/createRequest.js +4 -2
- package/package.json +1 -1
package/dist/Client.cjs
CHANGED
|
@@ -12,11 +12,13 @@ function createClient({
|
|
|
12
12
|
accessToken,
|
|
13
13
|
baseUrl = DEFAULT_BASE_URL,
|
|
14
14
|
headers = {},
|
|
15
|
-
fetch
|
|
15
|
+
fetch,
|
|
16
|
+
onError
|
|
16
17
|
}) {
|
|
17
18
|
const api = (0, _index.createDeferredJobsApiClient)((0, _index.createApiClient)((0, _index3.createHttpClient)({
|
|
18
19
|
fetch,
|
|
19
|
-
baseUrl
|
|
20
|
+
baseUrl,
|
|
21
|
+
onError
|
|
20
22
|
}), {
|
|
21
23
|
accessToken,
|
|
22
24
|
headers
|
package/dist/Client.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { DeferredJobsApiClient } from './api';
|
|
2
2
|
import { type Fetch } from './api';
|
|
3
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, Templates } from './endpoints';
|
|
4
|
-
import type {
|
|
4
|
+
import type { ApiError } from './http';
|
|
5
|
+
import { type HeadersMap } from './http';
|
|
5
6
|
export interface ClientOptions {
|
|
6
7
|
accessToken: string;
|
|
7
8
|
baseUrl?: string;
|
|
8
9
|
headers?: HeadersMap;
|
|
9
10
|
fetch?: Fetch;
|
|
11
|
+
onError?: (error: ApiError) => void;
|
|
10
12
|
}
|
|
11
13
|
export interface Client {
|
|
12
14
|
api: DeferredJobsApiClient;
|
|
@@ -41,4 +43,4 @@ export interface Client {
|
|
|
41
43
|
subscriptions: Subscriptions.Client;
|
|
42
44
|
templates: Templates.Client;
|
|
43
45
|
}
|
|
44
|
-
export declare function createClient({ accessToken, baseUrl, headers, fetch, }: ClientOptions): Client;
|
|
46
|
+
export declare function createClient({ accessToken, baseUrl, headers, fetch, onError, }: ClientOptions): Client;
|
package/dist/Client.js
CHANGED
|
@@ -6,11 +6,13 @@ export function createClient({
|
|
|
6
6
|
accessToken,
|
|
7
7
|
baseUrl = DEFAULT_BASE_URL,
|
|
8
8
|
headers = {},
|
|
9
|
-
fetch
|
|
9
|
+
fetch,
|
|
10
|
+
onError
|
|
10
11
|
}) {
|
|
11
12
|
const api = createDeferredJobsApiClient(createApiClient(createHttpClient({
|
|
12
13
|
fetch,
|
|
13
|
-
baseUrl
|
|
14
|
+
baseUrl,
|
|
15
|
+
onError
|
|
14
16
|
}), {
|
|
15
17
|
accessToken,
|
|
16
18
|
headers
|
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 = "25.
|
|
7
|
+
const VERSION = "25.7.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
|
@@ -47,8 +47,10 @@ function createClient(api) {
|
|
|
47
47
|
async function get(id) {
|
|
48
48
|
return api.get(`${_routing.routing.campaignsUrl}/${id}`);
|
|
49
49
|
}
|
|
50
|
-
async function duplicate(id) {
|
|
51
|
-
return api.post(`${_routing.routing.campaignsUrl}/${id}/duplicate
|
|
50
|
+
async function duplicate(id, options) {
|
|
51
|
+
return api.post(`${_routing.routing.campaignsUrl}/${id}/duplicate`, {
|
|
52
|
+
payload: options
|
|
53
|
+
});
|
|
52
54
|
}
|
|
53
55
|
async function doDelete(id) {
|
|
54
56
|
return api.delete(`${_routing.routing.campaignsUrl}/${id}`);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { ProgressPromise } from '@prezly/progress-promise';
|
|
2
2
|
import type { DeferredJobsApiClient } from '../../api';
|
|
3
3
|
import type { BulkDeletePayload, Campaign } from '../../types';
|
|
4
|
-
import type { CreateRequest, RecipientsOperationResponse, CampaignResponse, UpdateRequest, ListResponse, SearchOptions } from './types';
|
|
4
|
+
import type { CreateRequest, RecipientsOperationResponse, CampaignResponse, UpdateRequest, ListResponse, SearchOptions, DuplicateOptions } from './types';
|
|
5
5
|
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
9
|
get: (id: Campaign['id']) => Promise<CampaignResponse>;
|
|
10
|
-
duplicate: (id: Campaign['id']) => Promise<CampaignResponse>;
|
|
10
|
+
duplicate: (id: Campaign['id'], options?: DuplicateOptions) => Promise<CampaignResponse>;
|
|
11
11
|
test: (id: Campaign['id'], emails: string[]) => Promise<void>;
|
|
12
12
|
send: (id: Campaign['id']) => Promise<void>;
|
|
13
13
|
schedule: (id: Campaign['id'], sendAt: Date) => Promise<Campaign>;
|
|
@@ -41,8 +41,10 @@ export function createClient(api) {
|
|
|
41
41
|
async function get(id) {
|
|
42
42
|
return api.get(`${routing.campaignsUrl}/${id}`);
|
|
43
43
|
}
|
|
44
|
-
async function duplicate(id) {
|
|
45
|
-
return api.post(`${routing.campaignsUrl}/${id}/duplicate
|
|
44
|
+
async function duplicate(id, options) {
|
|
45
|
+
return api.post(`${routing.campaignsUrl}/${id}/duplicate`, {
|
|
46
|
+
payload: options
|
|
47
|
+
});
|
|
46
48
|
}
|
|
47
49
|
async function doDelete(id) {
|
|
48
50
|
return api.delete(`${routing.campaignsUrl}/${id}`);
|
|
@@ -24,6 +24,9 @@ export interface UpdateRequest {
|
|
|
24
24
|
is_open_tracking_enabled?: boolean;
|
|
25
25
|
is_click_tracking_enabled?: boolean;
|
|
26
26
|
}
|
|
27
|
+
export interface DuplicateOptions {
|
|
28
|
+
with_recipients?: boolean;
|
|
29
|
+
}
|
|
27
30
|
export interface RecipientsOperationResponse {
|
|
28
31
|
campaign: Campaign;
|
|
29
32
|
warnings: Warning[];
|
|
@@ -15,7 +15,7 @@ type Exactly<Concrete, Abstract> = Concrete & Record<Exclude<keyof Concrete, key
|
|
|
15
15
|
type InferExtraFields<T> = T extends Required<IncludeOptions<infer I>> ? Pick<Story.ExtraFields, I> : unknown;
|
|
16
16
|
export type Client = ReturnType<typeof createClient>;
|
|
17
17
|
export declare function createClient(api: DeferredJobsApiClient): {
|
|
18
|
-
list: <Options extends ListOptions<keyof Story.ExtraFields>>(options?: Exactly<Options, ListOptions
|
|
18
|
+
list: <Options extends ListOptions<keyof Story.ExtraFields>>(options?: Exactly<Options, ListOptions<keyof Story.ExtraFields>> | undefined) => Promise<ListResponse<Story & InferExtraFields<Options>>>;
|
|
19
19
|
search: <Options_1 extends SearchOptions<keyof Story.ExtraFields>>(options?: Exactly<Options_1, SearchOptions<keyof Story.ExtraFields>> | undefined) => Promise<ListResponse<Story & InferExtraFields<Options_1>>>;
|
|
20
20
|
get: {
|
|
21
21
|
<Options_2 extends IncludeOptions<keyof Story.ExtraFields> & {
|
package/dist/http/HttpClient.cjs
CHANGED
|
@@ -9,6 +9,7 @@ var _types = require("./types.cjs");
|
|
|
9
9
|
function createHttpClient(options = {}) {
|
|
10
10
|
const baseUrl = options.baseUrl ?? null;
|
|
11
11
|
const fetchImpl = options.fetch ?? fetch;
|
|
12
|
+
const onError = options.onError;
|
|
12
13
|
function resolveUrl(url) {
|
|
13
14
|
if (baseUrl) {
|
|
14
15
|
return new URL(url, baseUrl).toString();
|
|
@@ -24,7 +25,7 @@ function createHttpClient(options = {}) {
|
|
|
24
25
|
headers,
|
|
25
26
|
method: _types.Method.GET,
|
|
26
27
|
query
|
|
27
|
-
});
|
|
28
|
+
}, onError);
|
|
28
29
|
},
|
|
29
30
|
post(url, {
|
|
30
31
|
headers,
|
|
@@ -36,7 +37,7 @@ function createHttpClient(options = {}) {
|
|
|
36
37
|
method: _types.Method.POST,
|
|
37
38
|
payload,
|
|
38
39
|
query
|
|
39
|
-
});
|
|
40
|
+
}, onError);
|
|
40
41
|
},
|
|
41
42
|
put(url, {
|
|
42
43
|
headers,
|
|
@@ -48,7 +49,7 @@ function createHttpClient(options = {}) {
|
|
|
48
49
|
method: _types.Method.PUT,
|
|
49
50
|
payload,
|
|
50
51
|
query
|
|
51
|
-
});
|
|
52
|
+
}, onError);
|
|
52
53
|
},
|
|
53
54
|
patch(url, {
|
|
54
55
|
headers,
|
|
@@ -60,7 +61,7 @@ function createHttpClient(options = {}) {
|
|
|
60
61
|
method: _types.Method.PATCH,
|
|
61
62
|
payload,
|
|
62
63
|
query
|
|
63
|
-
});
|
|
64
|
+
}, onError);
|
|
64
65
|
},
|
|
65
66
|
delete(url, {
|
|
66
67
|
headers,
|
|
@@ -72,7 +73,7 @@ function createHttpClient(options = {}) {
|
|
|
72
73
|
method: _types.Method.DELETE,
|
|
73
74
|
payload,
|
|
74
75
|
query
|
|
75
|
-
});
|
|
76
|
+
}, onError);
|
|
76
77
|
}
|
|
77
78
|
};
|
|
78
79
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Fetch } from '../api';
|
|
2
|
+
import type { ApiError } from './ApiError';
|
|
2
3
|
import type { ApiResponse, Params, ParamsWithPayload } from './types';
|
|
3
4
|
export interface HttpClient {
|
|
4
5
|
get<V = any>(url: string, params?: Params): Promise<ApiResponse<V>>;
|
|
@@ -7,7 +8,10 @@ export interface HttpClient {
|
|
|
7
8
|
patch<V = any>(url: string, params?: ParamsWithPayload): Promise<ApiResponse<V>>;
|
|
8
9
|
delete<V = any>(url: string, params?: ParamsWithPayload): Promise<ApiResponse<V>>;
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
+
interface Options {
|
|
11
12
|
baseUrl?: string;
|
|
12
13
|
fetch?: Fetch;
|
|
13
|
-
|
|
14
|
+
onError?: (error: ApiError) => void;
|
|
15
|
+
}
|
|
16
|
+
export declare function createHttpClient(options?: Options): HttpClient;
|
|
17
|
+
export {};
|
package/dist/http/HttpClient.js
CHANGED
|
@@ -3,6 +3,7 @@ import { Method } from "./types.js";
|
|
|
3
3
|
export function createHttpClient(options = {}) {
|
|
4
4
|
const baseUrl = options.baseUrl ?? null;
|
|
5
5
|
const fetchImpl = options.fetch ?? fetch;
|
|
6
|
+
const onError = options.onError;
|
|
6
7
|
function resolveUrl(url) {
|
|
7
8
|
if (baseUrl) {
|
|
8
9
|
return new URL(url, baseUrl).toString();
|
|
@@ -18,7 +19,7 @@ export function createHttpClient(options = {}) {
|
|
|
18
19
|
headers,
|
|
19
20
|
method: Method.GET,
|
|
20
21
|
query
|
|
21
|
-
});
|
|
22
|
+
}, onError);
|
|
22
23
|
},
|
|
23
24
|
post(url, {
|
|
24
25
|
headers,
|
|
@@ -30,7 +31,7 @@ export function createHttpClient(options = {}) {
|
|
|
30
31
|
method: Method.POST,
|
|
31
32
|
payload,
|
|
32
33
|
query
|
|
33
|
-
});
|
|
34
|
+
}, onError);
|
|
34
35
|
},
|
|
35
36
|
put(url, {
|
|
36
37
|
headers,
|
|
@@ -42,7 +43,7 @@ export function createHttpClient(options = {}) {
|
|
|
42
43
|
method: Method.PUT,
|
|
43
44
|
payload,
|
|
44
45
|
query
|
|
45
|
-
});
|
|
46
|
+
}, onError);
|
|
46
47
|
},
|
|
47
48
|
patch(url, {
|
|
48
49
|
headers,
|
|
@@ -54,7 +55,7 @@ export function createHttpClient(options = {}) {
|
|
|
54
55
|
method: Method.PATCH,
|
|
55
56
|
payload,
|
|
56
57
|
query
|
|
57
|
-
});
|
|
58
|
+
}, onError);
|
|
58
59
|
},
|
|
59
60
|
delete(url, {
|
|
60
61
|
headers,
|
|
@@ -66,7 +67,7 @@ export function createHttpClient(options = {}) {
|
|
|
66
67
|
method: Method.DELETE,
|
|
67
68
|
payload,
|
|
68
69
|
query
|
|
69
|
-
});
|
|
70
|
+
}, onError);
|
|
70
71
|
}
|
|
71
72
|
};
|
|
72
73
|
}
|
|
@@ -39,7 +39,7 @@ function createFakeErrorPayload({
|
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
async function createRequest(fetchImpl, url, options) {
|
|
42
|
+
async function createRequest(fetchImpl, url, options, onError) {
|
|
43
43
|
const {
|
|
44
44
|
headers,
|
|
45
45
|
method,
|
|
@@ -75,10 +75,12 @@ async function createRequest(fetchImpl, url, options) {
|
|
|
75
75
|
} catch (error) {
|
|
76
76
|
responsePayload = createFakeErrorPayload(response);
|
|
77
77
|
}
|
|
78
|
-
|
|
78
|
+
const error = new _ApiError.ApiError({
|
|
79
79
|
payload: responsePayload,
|
|
80
80
|
...extractResponse(response)
|
|
81
81
|
});
|
|
82
|
+
onError?.(error);
|
|
83
|
+
throw error;
|
|
82
84
|
}
|
|
83
85
|
const responsePayload = response.status === _types.HttpCodes.NO_CONTENT ? undefined : await response.json();
|
|
84
86
|
return {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Fetch } from '../api';
|
|
2
|
-
import
|
|
2
|
+
import { ApiError } from './ApiError';
|
|
3
|
+
import type { ApiResponse, HeadersMap, Method } from './types';
|
|
3
4
|
export declare function createFakeErrorPayload({ status, statusText, }: {
|
|
4
5
|
status?: number;
|
|
5
6
|
statusText?: string;
|
|
@@ -19,4 +20,4 @@ export declare function createRequest<P = any>(fetchImpl: Fetch, url: string, op
|
|
|
19
20
|
method: Method;
|
|
20
21
|
payload?: object;
|
|
21
22
|
query?: object;
|
|
22
|
-
}): Promise<ApiResponse<P>>;
|
|
23
|
+
}, onError?: (error: ApiError) => void): Promise<ApiResponse<P>>;
|
|
@@ -32,7 +32,7 @@ export function createFakeErrorPayload({
|
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
export async function createRequest(fetchImpl, url, options) {
|
|
35
|
+
export async function createRequest(fetchImpl, url, options, onError) {
|
|
36
36
|
const {
|
|
37
37
|
headers,
|
|
38
38
|
method,
|
|
@@ -68,10 +68,12 @@ export async function createRequest(fetchImpl, url, options) {
|
|
|
68
68
|
} catch (error) {
|
|
69
69
|
responsePayload = createFakeErrorPayload(response);
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
const error = new ApiError({
|
|
72
72
|
payload: responsePayload,
|
|
73
73
|
...extractResponse(response)
|
|
74
74
|
});
|
|
75
|
+
onError?.(error);
|
|
76
|
+
throw error;
|
|
75
77
|
}
|
|
76
78
|
const responsePayload = response.status === HttpCodes.NO_CONTENT ? undefined : await response.json();
|
|
77
79
|
return {
|