@prezly/sdk 25.7.0 → 26.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/api/DeferredJobsApiClient.cjs +2 -1
- package/dist/api/DeferredJobsApiClient.js +2 -1
- 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/Newsrooms/Client.cjs +97 -32
- package/dist/endpoints/Newsrooms/Client.d.ts +18 -13
- package/dist/endpoints/Newsrooms/Client.js +96 -32
- package/dist/endpoints/Newsrooms/types.d.ts +8 -4
- package/dist/http/createRequest.cjs +1 -1
- package/dist/http/createRequest.js +1 -1
- package/dist/types/Category.cjs +1 -1
- package/dist/types/Category.js +1 -1
- package/dist/types/Newsroom.d.ts +24 -14
- package/package.json +7 -11
|
@@ -34,7 +34,8 @@ function handleDeferredJob(api, request) {
|
|
|
34
34
|
}
|
|
35
35
|
update(state.progress, state.value);
|
|
36
36
|
await sleep(JOB_STATUS_POLLING_INTERVAL);
|
|
37
|
-
|
|
37
|
+
// biome-ignore lint/correctness/noConstantCondition: <This infinite loop is expected and safe. There are two return statements breaking it when needed>
|
|
38
|
+
} while (true);
|
|
38
39
|
}
|
|
39
40
|
resolve(response.payload);
|
|
40
41
|
} catch (error) {
|
|
@@ -28,7 +28,8 @@ function handleDeferredJob(api, request) {
|
|
|
28
28
|
}
|
|
29
29
|
update(state.progress, state.value);
|
|
30
30
|
await sleep(JOB_STATUS_POLLING_INTERVAL);
|
|
31
|
-
|
|
31
|
+
// biome-ignore lint/correctness/noConstantCondition: <This infinite loop is expected and safe. There are two return statements breaking it when needed>
|
|
32
|
+
} while (true);
|
|
32
33
|
}
|
|
33
34
|
resolve(response.payload);
|
|
34
35
|
} catch (error) {
|
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.8.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[];
|
|
@@ -6,30 +6,40 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.createClient = createClient;
|
|
7
7
|
var _routing = require("../../routing.cjs");
|
|
8
8
|
var _index = require("../../types/index.cjs");
|
|
9
|
+
/**
|
|
10
|
+
* Utility type to forbid arbitrary ad-hoc extensions of generic parameters.
|
|
11
|
+
* @see https://stackoverflow.com/a/69666350
|
|
12
|
+
*/
|
|
13
|
+
|
|
9
14
|
function createClient(api) {
|
|
10
|
-
async function list({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
async function list(options) {
|
|
16
|
+
const {
|
|
17
|
+
search,
|
|
18
|
+
limit,
|
|
19
|
+
offset,
|
|
20
|
+
sortOrder,
|
|
21
|
+
include
|
|
22
|
+
} = options ?? {};
|
|
16
23
|
return api.get(_routing.routing.newsroomsUrl, {
|
|
17
24
|
query: {
|
|
18
25
|
limit,
|
|
19
26
|
offset,
|
|
20
27
|
search,
|
|
21
|
-
sort: _index.SortOrder.stringify(sortOrder)
|
|
28
|
+
sort: _index.SortOrder.stringify(sortOrder),
|
|
29
|
+
include: include?.join(',')
|
|
22
30
|
}
|
|
23
31
|
});
|
|
24
32
|
}
|
|
25
|
-
async function search(options
|
|
33
|
+
async function search(options) {
|
|
26
34
|
const {
|
|
27
35
|
query,
|
|
36
|
+
search,
|
|
28
37
|
limit,
|
|
29
38
|
offset,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
} = options;
|
|
39
|
+
sortOrder,
|
|
40
|
+
include
|
|
41
|
+
} = options ?? {};
|
|
42
|
+
|
|
33
43
|
// TODO: Introduce dedicated Search POST API
|
|
34
44
|
return api.get(_routing.routing.newsroomsUrl, {
|
|
35
45
|
query: {
|
|
@@ -37,65 +47,120 @@ function createClient(api) {
|
|
|
37
47
|
limit,
|
|
38
48
|
offset,
|
|
39
49
|
search,
|
|
40
|
-
sort: _index.SortOrder.stringify(sortOrder)
|
|
50
|
+
sort: _index.SortOrder.stringify(sortOrder),
|
|
51
|
+
include: include?.join(',')
|
|
41
52
|
}
|
|
42
53
|
});
|
|
43
54
|
}
|
|
44
|
-
async function get(id) {
|
|
55
|
+
async function get(id, options) {
|
|
56
|
+
const {
|
|
57
|
+
include
|
|
58
|
+
} = options ?? {};
|
|
45
59
|
const {
|
|
46
60
|
newsroom
|
|
47
|
-
} = await api.get(`${_routing.routing.newsroomsUrl}/${id}
|
|
61
|
+
} = await api.get(`${_routing.routing.newsroomsUrl}/${id}`, {
|
|
62
|
+
query: {
|
|
63
|
+
include: include?.join(',')
|
|
64
|
+
}
|
|
65
|
+
});
|
|
48
66
|
return newsroom;
|
|
49
67
|
}
|
|
50
|
-
async function create(payload) {
|
|
68
|
+
async function create(payload, options) {
|
|
69
|
+
const {
|
|
70
|
+
include
|
|
71
|
+
} = options ?? {};
|
|
51
72
|
const {
|
|
52
73
|
newsroom
|
|
53
74
|
} = await api.post(_routing.routing.newsroomsUrl, {
|
|
54
|
-
payload
|
|
75
|
+
payload,
|
|
76
|
+
query: {
|
|
77
|
+
include: include?.join(',')
|
|
78
|
+
}
|
|
55
79
|
});
|
|
56
80
|
return newsroom;
|
|
57
81
|
}
|
|
58
|
-
async function update(id, payload) {
|
|
82
|
+
async function update(id, payload, options) {
|
|
83
|
+
const {
|
|
84
|
+
include
|
|
85
|
+
} = options ?? {};
|
|
59
86
|
const {
|
|
60
87
|
newsroom
|
|
61
88
|
} = await api.patch(`${_routing.routing.newsroomsUrl}/${id}`, {
|
|
62
|
-
payload
|
|
89
|
+
payload,
|
|
90
|
+
query: {
|
|
91
|
+
include: include?.join(',')
|
|
92
|
+
}
|
|
63
93
|
});
|
|
64
94
|
return newsroom;
|
|
65
95
|
}
|
|
66
|
-
async function archive(id) {
|
|
96
|
+
async function archive(id, options) {
|
|
97
|
+
const {
|
|
98
|
+
include
|
|
99
|
+
} = options ?? {};
|
|
67
100
|
const {
|
|
68
101
|
newsroom
|
|
69
|
-
} = await api.post(`${_routing.routing.newsroomsUrl}/${id}/archive
|
|
102
|
+
} = await api.post(`${_routing.routing.newsroomsUrl}/${id}/archive`, {
|
|
103
|
+
query: {
|
|
104
|
+
include: include?.join(',')
|
|
105
|
+
}
|
|
106
|
+
});
|
|
70
107
|
return newsroom;
|
|
71
108
|
}
|
|
72
|
-
async function unarchive(id) {
|
|
109
|
+
async function unarchive(id, options) {
|
|
110
|
+
const {
|
|
111
|
+
include
|
|
112
|
+
} = options ?? {};
|
|
73
113
|
const {
|
|
74
114
|
newsroom
|
|
75
|
-
} = await api.post(`${_routing.routing.newsroomsUrl}/${id}/unarchive
|
|
115
|
+
} = await api.post(`${_routing.routing.newsroomsUrl}/${id}/unarchive`, {
|
|
116
|
+
query: {
|
|
117
|
+
include: include?.join(',')
|
|
118
|
+
}
|
|
119
|
+
});
|
|
76
120
|
return newsroom;
|
|
77
121
|
}
|
|
78
|
-
async function
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
122
|
+
async function takeOffline(id, options) {
|
|
123
|
+
const {
|
|
124
|
+
include
|
|
125
|
+
} = options ?? {};
|
|
82
126
|
const {
|
|
83
127
|
newsroom
|
|
84
|
-
} = await api.post(`${_routing.routing.newsroomsUrl}/${id}/offline
|
|
128
|
+
} = await api.post(`${_routing.routing.newsroomsUrl}/${id}/offline`, {
|
|
129
|
+
query: {
|
|
130
|
+
include: include?.join(',')
|
|
131
|
+
}
|
|
132
|
+
});
|
|
85
133
|
return newsroom;
|
|
86
134
|
}
|
|
87
|
-
async function takeOnline(id) {
|
|
135
|
+
async function takeOnline(id, options) {
|
|
136
|
+
const {
|
|
137
|
+
include
|
|
138
|
+
} = options ?? {};
|
|
88
139
|
const {
|
|
89
140
|
newsroom
|
|
90
|
-
} = await api.post(`${_routing.routing.newsroomsUrl}/${id}/online
|
|
141
|
+
} = await api.post(`${_routing.routing.newsroomsUrl}/${id}/online`, {
|
|
142
|
+
query: {
|
|
143
|
+
include: include?.join(',')
|
|
144
|
+
}
|
|
145
|
+
});
|
|
91
146
|
return newsroom;
|
|
92
147
|
}
|
|
93
|
-
async function convertToHub(id) {
|
|
148
|
+
async function convertToHub(id, options) {
|
|
149
|
+
const {
|
|
150
|
+
include
|
|
151
|
+
} = options ?? {};
|
|
94
152
|
const {
|
|
95
153
|
newsroom
|
|
96
|
-
} = await api.post(`${_routing.routing.newsroomsUrl}/${id}/convert
|
|
154
|
+
} = await api.post(`${_routing.routing.newsroomsUrl}/${id}/convert`, {
|
|
155
|
+
query: {
|
|
156
|
+
include: include?.join(',')
|
|
157
|
+
}
|
|
158
|
+
});
|
|
97
159
|
return newsroom;
|
|
98
160
|
}
|
|
161
|
+
async function deleteNewsroom(id) {
|
|
162
|
+
return api.delete(`${_routing.routing.newsroomsUrl}/${id}`);
|
|
163
|
+
}
|
|
99
164
|
return {
|
|
100
165
|
list,
|
|
101
166
|
search,
|
|
@@ -104,7 +169,7 @@ function createClient(api) {
|
|
|
104
169
|
update,
|
|
105
170
|
archive,
|
|
106
171
|
unarchive,
|
|
107
|
-
delete:
|
|
172
|
+
delete: deleteNewsroom,
|
|
108
173
|
takeOnline,
|
|
109
174
|
takeOffline,
|
|
110
175
|
convertToHub
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import type { DeferredJobsApiClient } from '../../api';
|
|
2
2
|
import type { Newsroom } from '../../types';
|
|
3
|
-
import type { CreateRequest, ListOptions, ListResponse, SearchOptions, UpdateRequest } from './types';
|
|
4
|
-
|
|
3
|
+
import type { CreateRequest, IncludeOptions, ListOptions, ListResponse, SearchOptions, UpdateRequest } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Utility type to forbid arbitrary ad-hoc extensions of generic parameters.
|
|
6
|
+
* @see https://stackoverflow.com/a/69666350
|
|
7
|
+
*/
|
|
8
|
+
type Exactly<Concrete, Abstract> = Concrete & Record<Exclude<keyof Concrete, keyof Abstract>, never>;
|
|
9
|
+
type InferExtraFields<T> = T extends Required<IncludeOptions<infer I>> ? Pick<Newsroom.ExtraFields, I> : unknown;
|
|
5
10
|
export type Client = ReturnType<typeof createClient>;
|
|
6
11
|
export declare function createClient(api: DeferredJobsApiClient): {
|
|
7
|
-
list: (
|
|
8
|
-
search: (options?: SearchOptions) => Promise<ListResponse
|
|
9
|
-
get: (id:
|
|
10
|
-
create: (payload: CreateRequest) => Promise<Newsroom
|
|
11
|
-
update: (id:
|
|
12
|
-
archive: (id:
|
|
13
|
-
unarchive: (id:
|
|
14
|
-
delete: (id:
|
|
15
|
-
takeOnline: (id:
|
|
16
|
-
takeOffline: (id:
|
|
17
|
-
convertToHub: (id:
|
|
12
|
+
list: <Options extends ListOptions<keyof Newsroom.ExtraFields>>(options?: Exactly<Options, ListOptions<keyof Newsroom.ExtraFields>> | undefined) => Promise<ListResponse<Newsroom & InferExtraFields<Options>>>;
|
|
13
|
+
search: <Options_1 extends SearchOptions<keyof Newsroom.ExtraFields>>(options?: Exactly<Options_1, SearchOptions<keyof Newsroom.ExtraFields>> | undefined) => Promise<ListResponse<Newsroom & InferExtraFields<Options_1>>>;
|
|
14
|
+
get: <Options_2 extends IncludeOptions<keyof Newsroom.ExtraFields>>(id: Newsroom['uuid'] | Newsroom['id'], options?: Exactly<Options_2, IncludeOptions<keyof Newsroom.ExtraFields>> | undefined) => Promise<Newsroom & InferExtraFields<Options_2>>;
|
|
15
|
+
create: <Options_3 extends IncludeOptions<keyof Newsroom.ExtraFields>>(payload: CreateRequest, options?: Exactly<Options_3, IncludeOptions<keyof Newsroom.ExtraFields>> | undefined) => Promise<Newsroom & InferExtraFields<Options_3>>;
|
|
16
|
+
update: <Options_4 extends IncludeOptions<keyof Newsroom.ExtraFields>>(id: Newsroom['uuid'] | Newsroom['id'], payload: UpdateRequest, options?: Exactly<Options_4, IncludeOptions<keyof Newsroom.ExtraFields>> | undefined) => Promise<Newsroom & InferExtraFields<Options_4>>;
|
|
17
|
+
archive: <Options_5 extends IncludeOptions<keyof Newsroom.ExtraFields>>(id: Newsroom['uuid'] | Newsroom['id'], options?: Exactly<Options_5, IncludeOptions<keyof Newsroom.ExtraFields>> | undefined) => Promise<Newsroom & InferExtraFields<Options_5>>;
|
|
18
|
+
unarchive: <Options_6 extends IncludeOptions<keyof Newsroom.ExtraFields>>(id: Newsroom['uuid'] | Newsroom['id'], options?: Exactly<Options_6, IncludeOptions<keyof Newsroom.ExtraFields>> | undefined) => Promise<Newsroom & InferExtraFields<Options_6>>;
|
|
19
|
+
delete: (id: Newsroom['uuid'] | Newsroom['id']) => Promise<void>;
|
|
20
|
+
takeOnline: <Options_7 extends IncludeOptions<keyof Newsroom.ExtraFields>>(id: Newsroom['uuid'] | Newsroom['id'], options?: Exactly<Options_7, IncludeOptions<keyof Newsroom.ExtraFields>> | undefined) => Promise<Newsroom & InferExtraFields<Options_7>>;
|
|
21
|
+
takeOffline: <Options_8 extends IncludeOptions<keyof Newsroom.ExtraFields>>(id: Newsroom['uuid'] | Newsroom['id'], options?: Exactly<Options_8, IncludeOptions<keyof Newsroom.ExtraFields>> | undefined) => Promise<Newsroom & InferExtraFields<Options_8>>;
|
|
22
|
+
convertToHub: <Options_9 extends IncludeOptions<keyof Newsroom.ExtraFields>>(id: Newsroom['uuid'] | Newsroom['id'], options?: Exactly<Options_9, IncludeOptions<keyof Newsroom.ExtraFields>> | undefined) => Promise<Newsroom & InferExtraFields<Options_9>>;
|
|
18
23
|
};
|
|
19
24
|
export {};
|
|
@@ -1,29 +1,38 @@
|
|
|
1
1
|
import { routing } from "../../routing.js";
|
|
2
2
|
import { Query, SortOrder } from "../../types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Utility type to forbid arbitrary ad-hoc extensions of generic parameters.
|
|
5
|
+
* @see https://stackoverflow.com/a/69666350
|
|
6
|
+
*/
|
|
3
7
|
export function createClient(api) {
|
|
4
|
-
async function list({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
async function list(options) {
|
|
9
|
+
const {
|
|
10
|
+
search,
|
|
11
|
+
limit,
|
|
12
|
+
offset,
|
|
13
|
+
sortOrder,
|
|
14
|
+
include
|
|
15
|
+
} = options ?? {};
|
|
10
16
|
return api.get(routing.newsroomsUrl, {
|
|
11
17
|
query: {
|
|
12
18
|
limit,
|
|
13
19
|
offset,
|
|
14
20
|
search,
|
|
15
|
-
sort: SortOrder.stringify(sortOrder)
|
|
21
|
+
sort: SortOrder.stringify(sortOrder),
|
|
22
|
+
include: include?.join(',')
|
|
16
23
|
}
|
|
17
24
|
});
|
|
18
25
|
}
|
|
19
|
-
async function search(options
|
|
26
|
+
async function search(options) {
|
|
20
27
|
const {
|
|
21
28
|
query,
|
|
29
|
+
search,
|
|
22
30
|
limit,
|
|
23
31
|
offset,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
} = options;
|
|
32
|
+
sortOrder,
|
|
33
|
+
include
|
|
34
|
+
} = options ?? {};
|
|
35
|
+
|
|
27
36
|
// TODO: Introduce dedicated Search POST API
|
|
28
37
|
return api.get(routing.newsroomsUrl, {
|
|
29
38
|
query: {
|
|
@@ -31,65 +40,120 @@ export function createClient(api) {
|
|
|
31
40
|
limit,
|
|
32
41
|
offset,
|
|
33
42
|
search,
|
|
34
|
-
sort: SortOrder.stringify(sortOrder)
|
|
43
|
+
sort: SortOrder.stringify(sortOrder),
|
|
44
|
+
include: include?.join(',')
|
|
35
45
|
}
|
|
36
46
|
});
|
|
37
47
|
}
|
|
38
|
-
async function get(id) {
|
|
48
|
+
async function get(id, options) {
|
|
49
|
+
const {
|
|
50
|
+
include
|
|
51
|
+
} = options ?? {};
|
|
39
52
|
const {
|
|
40
53
|
newsroom
|
|
41
|
-
} = await api.get(`${routing.newsroomsUrl}/${id}
|
|
54
|
+
} = await api.get(`${routing.newsroomsUrl}/${id}`, {
|
|
55
|
+
query: {
|
|
56
|
+
include: include?.join(',')
|
|
57
|
+
}
|
|
58
|
+
});
|
|
42
59
|
return newsroom;
|
|
43
60
|
}
|
|
44
|
-
async function create(payload) {
|
|
61
|
+
async function create(payload, options) {
|
|
62
|
+
const {
|
|
63
|
+
include
|
|
64
|
+
} = options ?? {};
|
|
45
65
|
const {
|
|
46
66
|
newsroom
|
|
47
67
|
} = await api.post(routing.newsroomsUrl, {
|
|
48
|
-
payload
|
|
68
|
+
payload,
|
|
69
|
+
query: {
|
|
70
|
+
include: include?.join(',')
|
|
71
|
+
}
|
|
49
72
|
});
|
|
50
73
|
return newsroom;
|
|
51
74
|
}
|
|
52
|
-
async function update(id, payload) {
|
|
75
|
+
async function update(id, payload, options) {
|
|
76
|
+
const {
|
|
77
|
+
include
|
|
78
|
+
} = options ?? {};
|
|
53
79
|
const {
|
|
54
80
|
newsroom
|
|
55
81
|
} = await api.patch(`${routing.newsroomsUrl}/${id}`, {
|
|
56
|
-
payload
|
|
82
|
+
payload,
|
|
83
|
+
query: {
|
|
84
|
+
include: include?.join(',')
|
|
85
|
+
}
|
|
57
86
|
});
|
|
58
87
|
return newsroom;
|
|
59
88
|
}
|
|
60
|
-
async function archive(id) {
|
|
89
|
+
async function archive(id, options) {
|
|
90
|
+
const {
|
|
91
|
+
include
|
|
92
|
+
} = options ?? {};
|
|
61
93
|
const {
|
|
62
94
|
newsroom
|
|
63
|
-
} = await api.post(`${routing.newsroomsUrl}/${id}/archive
|
|
95
|
+
} = await api.post(`${routing.newsroomsUrl}/${id}/archive`, {
|
|
96
|
+
query: {
|
|
97
|
+
include: include?.join(',')
|
|
98
|
+
}
|
|
99
|
+
});
|
|
64
100
|
return newsroom;
|
|
65
101
|
}
|
|
66
|
-
async function unarchive(id) {
|
|
102
|
+
async function unarchive(id, options) {
|
|
103
|
+
const {
|
|
104
|
+
include
|
|
105
|
+
} = options ?? {};
|
|
67
106
|
const {
|
|
68
107
|
newsroom
|
|
69
|
-
} = await api.post(`${routing.newsroomsUrl}/${id}/unarchive
|
|
108
|
+
} = await api.post(`${routing.newsroomsUrl}/${id}/unarchive`, {
|
|
109
|
+
query: {
|
|
110
|
+
include: include?.join(',')
|
|
111
|
+
}
|
|
112
|
+
});
|
|
70
113
|
return newsroom;
|
|
71
114
|
}
|
|
72
|
-
async function
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
115
|
+
async function takeOffline(id, options) {
|
|
116
|
+
const {
|
|
117
|
+
include
|
|
118
|
+
} = options ?? {};
|
|
76
119
|
const {
|
|
77
120
|
newsroom
|
|
78
|
-
} = await api.post(`${routing.newsroomsUrl}/${id}/offline
|
|
121
|
+
} = await api.post(`${routing.newsroomsUrl}/${id}/offline`, {
|
|
122
|
+
query: {
|
|
123
|
+
include: include?.join(',')
|
|
124
|
+
}
|
|
125
|
+
});
|
|
79
126
|
return newsroom;
|
|
80
127
|
}
|
|
81
|
-
async function takeOnline(id) {
|
|
128
|
+
async function takeOnline(id, options) {
|
|
129
|
+
const {
|
|
130
|
+
include
|
|
131
|
+
} = options ?? {};
|
|
82
132
|
const {
|
|
83
133
|
newsroom
|
|
84
|
-
} = await api.post(`${routing.newsroomsUrl}/${id}/online
|
|
134
|
+
} = await api.post(`${routing.newsroomsUrl}/${id}/online`, {
|
|
135
|
+
query: {
|
|
136
|
+
include: include?.join(',')
|
|
137
|
+
}
|
|
138
|
+
});
|
|
85
139
|
return newsroom;
|
|
86
140
|
}
|
|
87
|
-
async function convertToHub(id) {
|
|
141
|
+
async function convertToHub(id, options) {
|
|
142
|
+
const {
|
|
143
|
+
include
|
|
144
|
+
} = options ?? {};
|
|
88
145
|
const {
|
|
89
146
|
newsroom
|
|
90
|
-
} = await api.post(`${routing.newsroomsUrl}/${id}/convert
|
|
147
|
+
} = await api.post(`${routing.newsroomsUrl}/${id}/convert`, {
|
|
148
|
+
query: {
|
|
149
|
+
include: include?.join(',')
|
|
150
|
+
}
|
|
151
|
+
});
|
|
91
152
|
return newsroom;
|
|
92
153
|
}
|
|
154
|
+
async function deleteNewsroom(id) {
|
|
155
|
+
return api.delete(`${routing.newsroomsUrl}/${id}`);
|
|
156
|
+
}
|
|
93
157
|
return {
|
|
94
158
|
list,
|
|
95
159
|
search,
|
|
@@ -98,7 +162,7 @@ export function createClient(api) {
|
|
|
98
162
|
update,
|
|
99
163
|
archive,
|
|
100
164
|
unarchive,
|
|
101
|
-
delete:
|
|
165
|
+
delete: deleteNewsroom,
|
|
102
166
|
takeOnline,
|
|
103
167
|
takeOffline,
|
|
104
168
|
convertToHub
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { UploadedImage } from '@prezly/uploads';
|
|
2
2
|
import type { CultureRef, Newsroom, Pagination, Query, SortOrder } from '../../types';
|
|
3
|
-
export interface
|
|
3
|
+
export interface IncludeOptions<Include extends keyof Newsroom.ExtraFields = keyof Newsroom.ExtraFields> {
|
|
4
|
+
include?: Include[];
|
|
5
|
+
}
|
|
6
|
+
export interface ListOptions<Include extends keyof Newsroom.ExtraFields = keyof Newsroom.ExtraFields> {
|
|
7
|
+
include?: Include[];
|
|
4
8
|
limit?: number;
|
|
5
9
|
offset?: number;
|
|
6
10
|
/**
|
|
@@ -9,14 +13,14 @@ export interface ListOptions {
|
|
|
9
13
|
search?: string;
|
|
10
14
|
sortOrder?: SortOrder | string;
|
|
11
15
|
}
|
|
12
|
-
export interface SearchOptions extends ListOptions {
|
|
16
|
+
export interface SearchOptions<Include extends keyof Newsroom.ExtraFields = keyof Newsroom.ExtraFields> extends ListOptions<Include> {
|
|
13
17
|
/**
|
|
14
18
|
* Filter query using Prezly JSON Query Language
|
|
15
19
|
*/
|
|
16
20
|
query?: Query;
|
|
17
21
|
}
|
|
18
|
-
export interface ListResponse {
|
|
19
|
-
newsrooms:
|
|
22
|
+
export interface ListResponse<T extends Newsroom = Newsroom> {
|
|
23
|
+
newsrooms: T[];
|
|
20
24
|
pagination: Pagination;
|
|
21
25
|
sort: string;
|
|
22
26
|
}
|
|
@@ -72,7 +72,7 @@ async function createRequest(fetchImpl, url, options, onError) {
|
|
|
72
72
|
let responsePayload;
|
|
73
73
|
try {
|
|
74
74
|
responsePayload = await response.json();
|
|
75
|
-
} catch
|
|
75
|
+
} catch {
|
|
76
76
|
responsePayload = createFakeErrorPayload(response);
|
|
77
77
|
}
|
|
78
78
|
const error = new _ApiError.ApiError({
|
|
@@ -65,7 +65,7 @@ export async function createRequest(fetchImpl, url, options, onError) {
|
|
|
65
65
|
let responsePayload;
|
|
66
66
|
try {
|
|
67
67
|
responsePayload = await response.json();
|
|
68
|
-
} catch
|
|
68
|
+
} catch {
|
|
69
69
|
responsePayload = createFakeErrorPayload(response);
|
|
70
70
|
}
|
|
71
71
|
const error = new ApiError({
|
package/dist/types/Category.cjs
CHANGED
|
@@ -38,7 +38,7 @@ let Category = exports.Category = void 0;
|
|
|
38
38
|
_Category.translations = translations;
|
|
39
39
|
})(Category || (exports.Category = Category = {}));
|
|
40
40
|
function isNonEmpty(translation) {
|
|
41
|
-
return Boolean(translation
|
|
41
|
+
return Boolean(translation?.name && translation.slug);
|
|
42
42
|
}
|
|
43
43
|
function localeCode(locale) {
|
|
44
44
|
return typeof locale === 'string' ? locale : locale.code;
|
package/dist/types/Category.js
CHANGED
|
@@ -32,7 +32,7 @@ export let Category;
|
|
|
32
32
|
_Category.translations = translations;
|
|
33
33
|
})(Category || (Category = {}));
|
|
34
34
|
function isNonEmpty(translation) {
|
|
35
|
-
return Boolean(translation
|
|
35
|
+
return Boolean(translation?.name && translation.slug);
|
|
36
36
|
}
|
|
37
37
|
function localeCode(locale) {
|
|
38
38
|
return typeof locale === 'string' ? locale : locale.code;
|
package/dist/types/Newsroom.d.ts
CHANGED
|
@@ -94,20 +94,6 @@ export interface Newsroom extends NewsroomRef {
|
|
|
94
94
|
*/
|
|
95
95
|
custom_privacy_policy_link: string | null;
|
|
96
96
|
custom_data_request_link: string | null;
|
|
97
|
-
policies: {
|
|
98
|
-
privacy_policy: {
|
|
99
|
-
link: string;
|
|
100
|
-
} | {
|
|
101
|
-
content: string;
|
|
102
|
-
origin: 'default' | 'custom';
|
|
103
|
-
};
|
|
104
|
-
cookie_policy: {
|
|
105
|
-
link: string;
|
|
106
|
-
} | {
|
|
107
|
-
content: string;
|
|
108
|
-
origin: 'default' | 'custom';
|
|
109
|
-
};
|
|
110
|
-
};
|
|
111
97
|
tracking_policy: Newsroom.TrackingPolicy;
|
|
112
98
|
onetrust_cookie_consent: {
|
|
113
99
|
is_enabled: boolean;
|
|
@@ -183,4 +169,28 @@ export declare namespace Newsroom {
|
|
|
183
169
|
function isInactive(newsroom: Pick<Newsroom, 'status'>): boolean;
|
|
184
170
|
function isArchived(newsroom: Newsroom['status']): boolean;
|
|
185
171
|
function isArchived(newsroom: Pick<Newsroom, 'status'>): boolean;
|
|
172
|
+
interface ExtraFields {
|
|
173
|
+
policies: {
|
|
174
|
+
privacy_policy: {
|
|
175
|
+
link: string;
|
|
176
|
+
} | {
|
|
177
|
+
content: string;
|
|
178
|
+
origin: 'default' | 'custom';
|
|
179
|
+
};
|
|
180
|
+
cookie_policy: {
|
|
181
|
+
link: string;
|
|
182
|
+
} | {
|
|
183
|
+
content: string;
|
|
184
|
+
origin: 'default' | 'custom';
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
draft_stories_number: number;
|
|
188
|
+
published_stories_number: number;
|
|
189
|
+
draft_campaigns_number: number;
|
|
190
|
+
scheduled_campaigns_number: number;
|
|
191
|
+
sent_campaigns_number: number;
|
|
192
|
+
draft_pitches_number: number;
|
|
193
|
+
sent_pitches_number: number;
|
|
194
|
+
online_coverage_number: number;
|
|
195
|
+
}
|
|
186
196
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prezly/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "26.0.0",
|
|
4
4
|
"description": "Prezly API SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -36,17 +36,13 @@
|
|
|
36
36
|
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
|
|
37
37
|
"@babel/preset-env": "^7.7.1",
|
|
38
38
|
"@babel/preset-typescript": "^7.18.6",
|
|
39
|
+
"@biomejs/biome": "^2.2.4",
|
|
40
|
+
"@prezly/biome-config": "^1.0.1",
|
|
39
41
|
"@types/node": "^20.10.4",
|
|
40
|
-
"@typescript-eslint/eslint-plugin": "^6.13.2",
|
|
41
|
-
"@typescript-eslint/parser": "^6.13.2",
|
|
42
42
|
"babel-plugin-add-import-extension": "^1.6.0",
|
|
43
43
|
"babel-plugin-transform-inline-environment-variables": "^0.4.4",
|
|
44
44
|
"cross-env": "^7.0.3",
|
|
45
|
-
"eslint": "^8.56.0",
|
|
46
|
-
"eslint-config-prettier": "^8.10.0",
|
|
47
|
-
"eslint-plugin-import": "^2.29.1",
|
|
48
45
|
"np": "^9.2.0",
|
|
49
|
-
"prettier": "^2.8.8",
|
|
50
46
|
"rimraf": "^3.0.0",
|
|
51
47
|
"typescript": "^5.3.3",
|
|
52
48
|
"vitest": "^1.2.2",
|
|
@@ -61,13 +57,13 @@
|
|
|
61
57
|
"build:cjs": "babel ./src --ignore='**/*.test.ts' --config-file=./babel.config.cjs.json --extensions=.ts,.cts --source-root=./src --out-dir=./dist --out-file-extension .cjs",
|
|
62
58
|
"watch": "tsc --watch --preserveWatchOutput --project .",
|
|
63
59
|
"start": "npm run build --incremental --watch",
|
|
64
|
-
"lint": "
|
|
65
|
-
"lint:fix": "
|
|
60
|
+
"lint": "biome ci",
|
|
61
|
+
"lint:fix": "biome lint --write",
|
|
66
62
|
"test": "npm run test:build && npm run test:unit",
|
|
67
63
|
"test:unit": "vitest run",
|
|
68
64
|
"test:build": "node dist/index.js && tsc --noEmit dist/index.d.ts",
|
|
69
|
-
"
|
|
70
|
-
"
|
|
65
|
+
"format:check": "biome format",
|
|
66
|
+
"format": "biome format --write",
|
|
71
67
|
"prerelease": "npm run build",
|
|
72
68
|
"release": "np"
|
|
73
69
|
},
|