@prezly/sdk 15.21.0 → 16.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.
@@ -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 = "15.20.0";
7
+ const VERSION = "15.21.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 = "15.20.0";
1
+ const VERSION = "15.21.0";
2
2
  const URL = 'https://github.com/prezly/javascript-sdk';
3
3
  export const DEFAULT_USER_AGENT = `prezly-javascript-sdk/${VERSION} (+${URL})`;
@@ -16,9 +16,11 @@ class Client {
16
16
  limit,
17
17
  offset,
18
18
  sortOrder,
19
- include
19
+ include,
20
+ formats
20
21
  } = options ?? {};
21
22
  return this.apiClient.get(_routing.routing.storiesUrl, {
23
+ headers: acceptedFormatsHeader(formats),
22
24
  query: {
23
25
  limit,
24
26
  offset,
@@ -33,9 +35,11 @@ class Client {
33
35
  offset,
34
36
  sortOrder,
35
37
  include,
36
- query
38
+ query,
39
+ formats
37
40
  } = options ?? {};
38
41
  return this.apiClient.post(_routing.routing.storiesSearchUrl, {
42
+ headers: acceptedFormatsHeader(formats),
39
43
  payload: {
40
44
  query,
41
45
  limit,
@@ -54,7 +58,10 @@ class Client {
54
58
  * Implementation
55
59
  */
56
60
  async get(arg, options) {
57
- const include = options?.include;
61
+ const {
62
+ include,
63
+ formats
64
+ } = options ?? {};
58
65
  const isArray = Array.isArray(arg);
59
66
  if (isArray && arg.length === 0) {
60
67
  // No need to call the API.
@@ -70,7 +77,8 @@ class Client {
70
77
  $in: arg
71
78
  }
72
79
  },
73
- include
80
+ include,
81
+ formats
74
82
  });
75
83
  return stories;
76
84
  }
@@ -84,13 +92,15 @@ class Client {
84
92
  $in: arg
85
93
  }
86
94
  },
87
- include
95
+ include,
96
+ formats
88
97
  });
89
98
  return stories;
90
99
  }
91
100
  const {
92
101
  story
93
102
  } = await this.apiClient.get(`${_routing.routing.storiesUrl}/${arg}`, {
103
+ headers: acceptedFormatsHeader(formats),
94
104
  query: {
95
105
  include: include
96
106
  }
@@ -98,10 +108,14 @@ class Client {
98
108
  return story;
99
109
  }
100
110
  async create(payload, options) {
101
- const include = options?.include;
111
+ const {
112
+ include,
113
+ formats
114
+ } = options ?? {};
102
115
  const {
103
116
  story
104
117
  } = await this.apiClient.post(_routing.routing.storiesUrl, {
118
+ headers: acceptedFormatsHeader(formats),
105
119
  payload,
106
120
  query: {
107
121
  include: include
@@ -110,11 +124,15 @@ class Client {
110
124
  return story;
111
125
  }
112
126
  async duplicate(id, options) {
113
- const include = options?.include;
127
+ const {
128
+ include,
129
+ formats
130
+ } = options ?? {};
114
131
  const url = `${_routing.routing.storiesUrl}/${id}/duplicate`;
115
132
  const {
116
133
  story
117
134
  } = await this.apiClient.post(url, {
135
+ headers: acceptedFormatsHeader(formats),
118
136
  query: {
119
137
  include: include
120
138
  }
@@ -125,11 +143,15 @@ class Client {
125
143
  const {
126
144
  culture
127
145
  } = payload ?? {};
128
- const include = options?.include;
146
+ const {
147
+ include,
148
+ formats
149
+ } = options ?? {};
129
150
  const url = `${_routing.routing.storiesUrl}/${id}/translate`;
130
151
  const {
131
152
  story
132
153
  } = await this.apiClient.post(url, {
154
+ headers: acceptedFormatsHeader(formats),
133
155
  query: {
134
156
  include: include
135
157
  },
@@ -140,13 +162,17 @@ class Client {
140
162
  return story;
141
163
  }
142
164
  async move(id, payload, options) {
143
- const include = options?.include;
144
- const force = options?.force;
165
+ const {
166
+ include,
167
+ force,
168
+ formats
169
+ } = options ?? {};
145
170
  const url = `${_routing.routing.storiesUrl}/${id}/move`;
146
171
  try {
147
172
  const {
148
173
  story
149
174
  } = await this.apiClient.post(url, {
175
+ headers: acceptedFormatsHeader(formats),
150
176
  query: {
151
177
  include: include,
152
178
  force
@@ -166,10 +192,14 @@ class Client {
166
192
  }
167
193
  async update(id, payload, options) {
168
194
  const url = `${_routing.routing.storiesUrl}/${id}`;
169
- const include = options?.include;
195
+ const {
196
+ include,
197
+ formats
198
+ } = options ?? {};
170
199
  const {
171
200
  story
172
201
  } = await this.apiClient.patch(url, {
202
+ headers: acceptedFormatsHeader(formats),
173
203
  payload,
174
204
  query: {
175
205
  include: include
@@ -183,10 +213,14 @@ class Client {
183
213
  */
184
214
  async autosave(id, payload, options) {
185
215
  const url = `${_routing.routing.storiesUrl}/${id}/autosave`;
186
- const include = options?.include;
216
+ const {
217
+ include,
218
+ formats
219
+ } = options ?? {};
187
220
  const {
188
221
  story
189
222
  } = await this.apiClient.patch(url, {
223
+ headers: acceptedFormatsHeader(formats),
190
224
  payload,
191
225
  query: {
192
226
  include: include
@@ -200,10 +234,14 @@ class Client {
200
234
  */
201
235
  async revert(id, payload, options) {
202
236
  const url = `${_routing.routing.storiesUrl}/${id}/revert`;
203
- const include = options?.include;
237
+ const {
238
+ include,
239
+ formats
240
+ } = options ?? {};
204
241
  const {
205
242
  story
206
243
  } = await this.apiClient.post(url, {
244
+ headers: acceptedFormatsHeader(formats),
207
245
  payload,
208
246
  query: {
209
247
  include: include
@@ -213,10 +251,14 @@ class Client {
213
251
  }
214
252
  async publish(id, payload, options) {
215
253
  const url = `${_routing.routing.storiesUrl}/${id}/publish`;
216
- const include = options?.include;
254
+ const {
255
+ include,
256
+ formats
257
+ } = options ?? {};
217
258
  const {
218
259
  story
219
260
  } = await this.apiClient.post(url, {
261
+ headers: acceptedFormatsHeader(formats),
220
262
  payload,
221
263
  query: {
222
264
  include: include
@@ -226,10 +268,14 @@ class Client {
226
268
  }
227
269
  async unpublish(id, payload, options) {
228
270
  const url = `${_routing.routing.storiesUrl}/${id}/unpublish`;
229
- const include = options?.include;
271
+ const {
272
+ include,
273
+ formats
274
+ } = options ?? {};
230
275
  const {
231
276
  story
232
277
  } = await this.apiClient.post(url, {
278
+ headers: acceptedFormatsHeader(formats),
233
279
  payload,
234
280
  query: {
235
281
  include: include
@@ -239,10 +285,14 @@ class Client {
239
285
  }
240
286
  async schedule(id, payload, options) {
241
287
  const url = `${_routing.routing.storiesUrl}/${id}/schedule`;
242
- const include = options?.include;
288
+ const {
289
+ include,
290
+ formats
291
+ } = options ?? {};
243
292
  const {
244
293
  story
245
294
  } = await this.apiClient.post(url, {
295
+ headers: acceptedFormatsHeader(formats),
246
296
  payload,
247
297
  query: {
248
298
  include: include
@@ -252,10 +302,14 @@ class Client {
252
302
  }
253
303
  async unschedule(id, payload, options) {
254
304
  const url = `${_routing.routing.storiesUrl}/${id}/unpublish`;
255
- const include = options?.include;
305
+ const {
306
+ include,
307
+ formats
308
+ } = options ?? {};
256
309
  const {
257
310
  story
258
311
  } = await this.apiClient.post(url, {
312
+ headers: acceptedFormatsHeader(formats),
259
313
  payload,
260
314
  query: {
261
315
  include: include
@@ -265,23 +319,32 @@ class Client {
265
319
  }
266
320
  async pin(id, options) {
267
321
  const url = `${_routing.routing.storiesUrl}/${id}/pin`;
268
- const include = options?.include;
322
+ const {
323
+ include,
324
+ force,
325
+ formats
326
+ } = options ?? {};
269
327
  const {
270
328
  story
271
329
  } = await this.apiClient.post(url, {
330
+ headers: acceptedFormatsHeader(formats),
272
331
  query: {
273
332
  include: include,
274
- force: options?.force || undefined
333
+ force: force || undefined
275
334
  }
276
335
  });
277
336
  return story;
278
337
  }
279
338
  async unpin(id, options) {
280
339
  const url = `${_routing.routing.storiesUrl}/${id}/unpin`;
281
- const include = options?.include;
340
+ const {
341
+ include,
342
+ formats
343
+ } = options ?? {};
282
344
  const {
283
345
  story
284
346
  } = await this.apiClient.post(url, {
347
+ headers: acceptedFormatsHeader(formats),
285
348
  query: {
286
349
  include: include
287
350
  }
@@ -305,4 +368,12 @@ class Client {
305
368
  return preview;
306
369
  }
307
370
  }
308
- exports.Client = Client;
371
+ exports.Client = Client;
372
+ function acceptedFormatsHeader(formats = []) {
373
+ if (formats.length === 0) {
374
+ return {};
375
+ }
376
+ return {
377
+ Accept: formats.map(format => `application/json; content-format=v${format}`).join(', ')
378
+ };
379
+ }
@@ -5,6 +5,7 @@ import type { AutosaveRequest, ChangeNewsroomSuccessResponse, ChangeNewsroomUnsa
5
5
  * `uuid` is the preferred way of targeting a Story. Numeric `id` is considered deprecated.
6
6
  */
7
7
  declare type StoryId = Story['uuid'] | Story['id'];
8
+ declare type Formats = Story.FormatVersion[];
8
9
  /**
9
10
  * Utility type to forbid arbitrary ad-hoc extensions of generic parameters.
10
11
  * @see https://stackoverflow.com/a/69666350
@@ -18,44 +19,76 @@ export declare class Client {
18
19
  /**
19
20
  * Get story by UUID.
20
21
  */
21
- get<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: Story['uuid'], options?: Exactly<IncludeOptions<Include>, Options>): Promise<StoryRecord>;
22
+ get<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: Story['uuid'], options?: Exactly<IncludeOptions<Include>, Options> & {
23
+ formats?: Formats;
24
+ }): Promise<StoryRecord>;
22
25
  /**
23
26
  * Get multiple stories by UUIDs.
24
27
  */
25
- get<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(ids: Story['uuid'][], options?: Exactly<IncludeOptions<Include>, Options>): Promise<StoryRecord[]>;
28
+ get<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(ids: Story['uuid'][], options?: Exactly<IncludeOptions<Include>, Options> & {
29
+ formats?: Formats;
30
+ }): Promise<StoryRecord[]>;
26
31
  /**
27
32
  * Get story by deprecated numeric ID, or UUID.
28
33
  * @deprecated Please use UUID instead.
29
34
  */
30
- get<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: Story['id'] | Story['uuid'], options?: Exactly<IncludeOptions<Include>, Options>): Promise<StoryRecord>;
35
+ get<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: Story['id'] | Story['uuid'], options?: Exactly<IncludeOptions<Include>, Options> & {
36
+ formats?: Formats;
37
+ }): Promise<StoryRecord>;
31
38
  /**
32
39
  * Get multiple stories by numeric IDs.
33
40
  * @deprecated Please use UUID instead.
34
41
  */
35
- get<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(ids: Story['id'][], options?: Exactly<IncludeOptions<Include>, Options>): Promise<StoryRecord[]>;
36
- create<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(payload: CreateRequest, options?: Exactly<IncludeOptions<Include>, Options>): Promise<StoryRecord>;
37
- duplicate<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: StoryId, options?: Exactly<IncludeOptions<Include>, Options>): Promise<StoryRecord>;
38
- translate<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: StoryId, payload?: TranslateRequest, options?: Exactly<IncludeOptions<Include>, Options>): Promise<StoryRecord>;
42
+ get<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(ids: Story['id'][], options?: Exactly<IncludeOptions<Include>, Options> & {
43
+ formats?: Formats;
44
+ }): Promise<StoryRecord[]>;
45
+ create<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(payload: CreateRequest, options?: Exactly<IncludeOptions<Include>, Options> & {
46
+ formats?: Formats;
47
+ }): Promise<StoryRecord>;
48
+ duplicate<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: StoryId, options?: Exactly<IncludeOptions<Include>, Options> & {
49
+ formats?: Formats;
50
+ }): Promise<StoryRecord>;
51
+ translate<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: StoryId, payload?: TranslateRequest, options?: Exactly<IncludeOptions<Include>, Options> & {
52
+ formats?: Formats;
53
+ }): Promise<StoryRecord>;
39
54
  move<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: StoryId, payload: MoveRequest, options?: Exactly<IncludeOptions<Include>, Options> & {
40
55
  force?: true;
56
+ formats?: Formats;
41
57
  }): Promise<ChangeNewsroomSuccessResponse<StoryRecord> | ChangeNewsroomUnsafeResponse>;
42
- update<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: StoryId, payload: UpdateRequest, options?: Exactly<IncludeOptions<Include>, Options>): Promise<StoryRecord>;
58
+ update<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: StoryId, payload: UpdateRequest, options?: Exactly<IncludeOptions<Include>, Options> & {
59
+ formats?: Formats;
60
+ }): Promise<StoryRecord>;
43
61
  /**
44
62
  * This operation is only allowed for V3 stories
45
63
  */
46
- autosave<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: StoryId, payload: AutosaveRequest, options?: Exactly<IncludeOptions<Include>, Options>): Promise<StoryRecord>;
64
+ autosave<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: StoryId, payload: AutosaveRequest, options?: Exactly<IncludeOptions<Include>, Options> & {
65
+ formats?: Formats;
66
+ }): Promise<StoryRecord>;
47
67
  /**
48
68
  * This operation is only allowed for V3 stories
49
69
  */
50
- revert<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: StoryId, payload?: RevertRequest, options?: Exactly<IncludeOptions<Include>, Options>): Promise<StoryRecord>;
51
- publish<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: StoryId, payload?: PublishRequest, options?: Exactly<IncludeOptions<Include>, Options>): Promise<StoryRecord>;
52
- unpublish<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: StoryId, payload?: UnpublishRequest, options?: Exactly<IncludeOptions<Include>, Options>): Promise<StoryRecord>;
53
- schedule<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: StoryId, payload?: ScheduleRequest, options?: Exactly<IncludeOptions<Include>, Options>): Promise<StoryRecord>;
54
- unschedule<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: StoryId, payload?: UnscheduleRequest, options?: Exactly<IncludeOptions<Include>, Options>): Promise<StoryRecord>;
70
+ revert<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: StoryId, payload?: RevertRequest, options?: Exactly<IncludeOptions<Include>, Options> & {
71
+ formats?: Formats;
72
+ }): Promise<StoryRecord>;
73
+ publish<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: StoryId, payload?: PublishRequest, options?: Exactly<IncludeOptions<Include>, Options> & {
74
+ formats?: Formats;
75
+ }): Promise<StoryRecord>;
76
+ unpublish<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: StoryId, payload?: UnpublishRequest, options?: Exactly<IncludeOptions<Include>, Options> & {
77
+ formats?: Formats;
78
+ }): Promise<StoryRecord>;
79
+ schedule<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: StoryId, payload?: ScheduleRequest, options?: Exactly<IncludeOptions<Include>, Options> & {
80
+ formats?: Formats;
81
+ }): Promise<StoryRecord>;
82
+ unschedule<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: StoryId, payload?: UnscheduleRequest, options?: Exactly<IncludeOptions<Include>, Options> & {
83
+ formats?: Formats;
84
+ }): Promise<StoryRecord>;
55
85
  pin<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: StoryId, options?: Exactly<IncludeOptions<Include>, Options> & {
56
86
  force?: boolean;
87
+ formats?: Formats;
88
+ }): Promise<StoryRecord>;
89
+ unpin<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: StoryId, options?: Exactly<IncludeOptions<Include>, Options> & {
90
+ formats?: Formats;
57
91
  }): Promise<StoryRecord>;
58
- unpin<Include extends readonly (keyof Story.ExtraFields)[], Options extends IncludeOptions<Include>, StoryRecord extends ExtendedStory = Options['include'] extends Include ? ExtendedStory & Pick<Story.ExtraFields, Options['include'][number]> : ExtendedStory>(id: StoryId, options?: Exactly<IncludeOptions<Include>, Options>): Promise<StoryRecord>;
59
92
  delete(id: StoryId): Promise<void>;
60
93
  preview(id: StoryId, options?: PreviewOptions): Promise<PreviewResponse>;
61
94
  }
@@ -10,9 +10,11 @@ export class Client {
10
10
  limit,
11
11
  offset,
12
12
  sortOrder,
13
- include
13
+ include,
14
+ formats
14
15
  } = options ?? {};
15
16
  return this.apiClient.get(routing.storiesUrl, {
17
+ headers: acceptedFormatsHeader(formats),
16
18
  query: {
17
19
  limit,
18
20
  offset,
@@ -27,9 +29,11 @@ export class Client {
27
29
  offset,
28
30
  sortOrder,
29
31
  include,
30
- query
32
+ query,
33
+ formats
31
34
  } = options ?? {};
32
35
  return this.apiClient.post(routing.storiesSearchUrl, {
36
+ headers: acceptedFormatsHeader(formats),
33
37
  payload: {
34
38
  query,
35
39
  limit,
@@ -48,7 +52,10 @@ export class Client {
48
52
  * Implementation
49
53
  */
50
54
  async get(arg, options) {
51
- const include = options?.include;
55
+ const {
56
+ include,
57
+ formats
58
+ } = options ?? {};
52
59
  const isArray = Array.isArray(arg);
53
60
  if (isArray && arg.length === 0) {
54
61
  // No need to call the API.
@@ -64,7 +71,8 @@ export class Client {
64
71
  $in: arg
65
72
  }
66
73
  },
67
- include
74
+ include,
75
+ formats
68
76
  });
69
77
  return stories;
70
78
  }
@@ -78,13 +86,15 @@ export class Client {
78
86
  $in: arg
79
87
  }
80
88
  },
81
- include
89
+ include,
90
+ formats
82
91
  });
83
92
  return stories;
84
93
  }
85
94
  const {
86
95
  story
87
96
  } = await this.apiClient.get(`${routing.storiesUrl}/${arg}`, {
97
+ headers: acceptedFormatsHeader(formats),
88
98
  query: {
89
99
  include: include
90
100
  }
@@ -92,10 +102,14 @@ export class Client {
92
102
  return story;
93
103
  }
94
104
  async create(payload, options) {
95
- const include = options?.include;
105
+ const {
106
+ include,
107
+ formats
108
+ } = options ?? {};
96
109
  const {
97
110
  story
98
111
  } = await this.apiClient.post(routing.storiesUrl, {
112
+ headers: acceptedFormatsHeader(formats),
99
113
  payload,
100
114
  query: {
101
115
  include: include
@@ -104,11 +118,15 @@ export class Client {
104
118
  return story;
105
119
  }
106
120
  async duplicate(id, options) {
107
- const include = options?.include;
121
+ const {
122
+ include,
123
+ formats
124
+ } = options ?? {};
108
125
  const url = `${routing.storiesUrl}/${id}/duplicate`;
109
126
  const {
110
127
  story
111
128
  } = await this.apiClient.post(url, {
129
+ headers: acceptedFormatsHeader(formats),
112
130
  query: {
113
131
  include: include
114
132
  }
@@ -119,11 +137,15 @@ export class Client {
119
137
  const {
120
138
  culture
121
139
  } = payload ?? {};
122
- const include = options?.include;
140
+ const {
141
+ include,
142
+ formats
143
+ } = options ?? {};
123
144
  const url = `${routing.storiesUrl}/${id}/translate`;
124
145
  const {
125
146
  story
126
147
  } = await this.apiClient.post(url, {
148
+ headers: acceptedFormatsHeader(formats),
127
149
  query: {
128
150
  include: include
129
151
  },
@@ -134,13 +156,17 @@ export class Client {
134
156
  return story;
135
157
  }
136
158
  async move(id, payload, options) {
137
- const include = options?.include;
138
- const force = options?.force;
159
+ const {
160
+ include,
161
+ force,
162
+ formats
163
+ } = options ?? {};
139
164
  const url = `${routing.storiesUrl}/${id}/move`;
140
165
  try {
141
166
  const {
142
167
  story
143
168
  } = await this.apiClient.post(url, {
169
+ headers: acceptedFormatsHeader(formats),
144
170
  query: {
145
171
  include: include,
146
172
  force
@@ -160,10 +186,14 @@ export class Client {
160
186
  }
161
187
  async update(id, payload, options) {
162
188
  const url = `${routing.storiesUrl}/${id}`;
163
- const include = options?.include;
189
+ const {
190
+ include,
191
+ formats
192
+ } = options ?? {};
164
193
  const {
165
194
  story
166
195
  } = await this.apiClient.patch(url, {
196
+ headers: acceptedFormatsHeader(formats),
167
197
  payload,
168
198
  query: {
169
199
  include: include
@@ -177,10 +207,14 @@ export class Client {
177
207
  */
178
208
  async autosave(id, payload, options) {
179
209
  const url = `${routing.storiesUrl}/${id}/autosave`;
180
- const include = options?.include;
210
+ const {
211
+ include,
212
+ formats
213
+ } = options ?? {};
181
214
  const {
182
215
  story
183
216
  } = await this.apiClient.patch(url, {
217
+ headers: acceptedFormatsHeader(formats),
184
218
  payload,
185
219
  query: {
186
220
  include: include
@@ -194,10 +228,14 @@ export class Client {
194
228
  */
195
229
  async revert(id, payload, options) {
196
230
  const url = `${routing.storiesUrl}/${id}/revert`;
197
- const include = options?.include;
231
+ const {
232
+ include,
233
+ formats
234
+ } = options ?? {};
198
235
  const {
199
236
  story
200
237
  } = await this.apiClient.post(url, {
238
+ headers: acceptedFormatsHeader(formats),
201
239
  payload,
202
240
  query: {
203
241
  include: include
@@ -207,10 +245,14 @@ export class Client {
207
245
  }
208
246
  async publish(id, payload, options) {
209
247
  const url = `${routing.storiesUrl}/${id}/publish`;
210
- const include = options?.include;
248
+ const {
249
+ include,
250
+ formats
251
+ } = options ?? {};
211
252
  const {
212
253
  story
213
254
  } = await this.apiClient.post(url, {
255
+ headers: acceptedFormatsHeader(formats),
214
256
  payload,
215
257
  query: {
216
258
  include: include
@@ -220,10 +262,14 @@ export class Client {
220
262
  }
221
263
  async unpublish(id, payload, options) {
222
264
  const url = `${routing.storiesUrl}/${id}/unpublish`;
223
- const include = options?.include;
265
+ const {
266
+ include,
267
+ formats
268
+ } = options ?? {};
224
269
  const {
225
270
  story
226
271
  } = await this.apiClient.post(url, {
272
+ headers: acceptedFormatsHeader(formats),
227
273
  payload,
228
274
  query: {
229
275
  include: include
@@ -233,10 +279,14 @@ export class Client {
233
279
  }
234
280
  async schedule(id, payload, options) {
235
281
  const url = `${routing.storiesUrl}/${id}/schedule`;
236
- const include = options?.include;
282
+ const {
283
+ include,
284
+ formats
285
+ } = options ?? {};
237
286
  const {
238
287
  story
239
288
  } = await this.apiClient.post(url, {
289
+ headers: acceptedFormatsHeader(formats),
240
290
  payload,
241
291
  query: {
242
292
  include: include
@@ -246,10 +296,14 @@ export class Client {
246
296
  }
247
297
  async unschedule(id, payload, options) {
248
298
  const url = `${routing.storiesUrl}/${id}/unpublish`;
249
- const include = options?.include;
299
+ const {
300
+ include,
301
+ formats
302
+ } = options ?? {};
250
303
  const {
251
304
  story
252
305
  } = await this.apiClient.post(url, {
306
+ headers: acceptedFormatsHeader(formats),
253
307
  payload,
254
308
  query: {
255
309
  include: include
@@ -259,23 +313,32 @@ export class Client {
259
313
  }
260
314
  async pin(id, options) {
261
315
  const url = `${routing.storiesUrl}/${id}/pin`;
262
- const include = options?.include;
316
+ const {
317
+ include,
318
+ force,
319
+ formats
320
+ } = options ?? {};
263
321
  const {
264
322
  story
265
323
  } = await this.apiClient.post(url, {
324
+ headers: acceptedFormatsHeader(formats),
266
325
  query: {
267
326
  include: include,
268
- force: options?.force || undefined
327
+ force: force || undefined
269
328
  }
270
329
  });
271
330
  return story;
272
331
  }
273
332
  async unpin(id, options) {
274
333
  const url = `${routing.storiesUrl}/${id}/unpin`;
275
- const include = options?.include;
334
+ const {
335
+ include,
336
+ formats
337
+ } = options ?? {};
276
338
  const {
277
339
  story
278
340
  } = await this.apiClient.post(url, {
341
+ headers: acceptedFormatsHeader(formats),
279
342
  query: {
280
343
  include: include
281
344
  }
@@ -298,4 +361,12 @@ export class Client {
298
361
  });
299
362
  return preview;
300
363
  }
364
+ }
365
+ function acceptedFormatsHeader(formats = []) {
366
+ if (formats.length === 0) {
367
+ return {};
368
+ }
369
+ return {
370
+ Accept: formats.map(format => `application/json; content-format=v${format}`).join(', ')
371
+ };
301
372
  }
@@ -57,6 +57,7 @@ export interface ListOptions<Include extends readonly (keyof Story.ExtraFields)[
57
57
  offset?: number;
58
58
  sortOrder?: SortOrder | string;
59
59
  include?: Include;
60
+ formats?: Story.FormatVersion[];
60
61
  }
61
62
  export interface SearchOptions<Include extends readonly (keyof Story.ExtraFields)[]> extends ListOptions<Include> {
62
63
  query?: Query;
@@ -69,12 +70,9 @@ export interface ListResponse<S extends Story = Story> {
69
70
  }
70
71
  interface GenericCreateRequest {
71
72
  newsroom?: Newsroom['id'] | Newsroom['uuid'];
72
- title?: string;
73
- subtitle?: string;
74
73
  published_at?: Iso8601DateTime;
75
74
  visibility?: Story.Visibility;
76
75
  culture?: CultureRef['code'];
77
- header_image?: UploadedImage | null;
78
76
  preview_image?: UploadedImage | null;
79
77
  social_image?: UploadedImage | null;
80
78
  social_text?: string;
@@ -83,12 +81,9 @@ interface GenericCreateRequest {
83
81
  is_shared_to_prpro?: boolean;
84
82
  }
85
83
  interface GenericUpdateRequest {
86
- title?: string;
87
- subtitle?: string;
88
84
  published_at?: Iso8601DateTime;
89
85
  visibility?: Story.Visibility;
90
86
  culture?: CultureRef['code'];
91
- header_image?: UploadedImage | null;
92
87
  preview_image?: UploadedImage | null;
93
88
  social_image?: UploadedImage | null;
94
89
  social_text?: string;
@@ -106,6 +101,9 @@ export interface HtmlStoryCreateRequest extends GenericCreateRequest {
106
101
  * If format version is omitted, license default editor version will be implied.
107
102
  */
108
103
  format_version?: Story.FormatVersion.HTML;
104
+ header_image?: UploadedImage | null;
105
+ title?: string;
106
+ subtitle?: string;
109
107
  intro?: Html;
110
108
  content?: Html;
111
109
  attached_attachments_content?: Json;
@@ -114,11 +112,28 @@ export interface HtmlStoryCreateRequest extends GenericCreateRequest {
114
112
  attached_gallery_content?: Json;
115
113
  attached_videos_content?: Json;
116
114
  }
117
- export interface SlateStoryCreateRequest extends GenericCreateRequest {
115
+ export interface SlateV3StoryCreateRequest extends GenericCreateRequest {
116
+ /**
117
+ * If format version is omitted, license default editor version will be implied.
118
+ */
119
+ format_version?: Story.FormatVersion.SLATEJS_V3;
120
+ header_image?: UploadedImage | null;
121
+ title?: string;
122
+ subtitle?: string;
123
+ /**
124
+ * Intro field is not supported for Prezly Content Format stories.
125
+ */
126
+ intro?: never;
127
+ content?: PrezlyContentFormat;
128
+ }
129
+ export interface SlateV4StoryCreateRequest extends GenericCreateRequest {
118
130
  /**
119
131
  * If format version is omitted, license default editor version will be implied.
120
132
  */
121
- format_version?: Story.FormatVersion.SLATEJS;
133
+ format_version?: Story.FormatVersion.SLATEJS_V4;
134
+ header_image?: never;
135
+ title?: never;
136
+ subtitle?: never;
122
137
  /**
123
138
  * Intro field is not supported for Prezly Content Format stories.
124
139
  */
@@ -126,6 +141,10 @@ export interface SlateStoryCreateRequest extends GenericCreateRequest {
126
141
  content?: PrezlyContentFormat;
127
142
  }
128
143
  export interface HtmlStoryUpdateRequest extends GenericUpdateRequest {
144
+ format_version?: Story.FormatVersion.HTML;
145
+ header_image?: UploadedImage | null;
146
+ title?: string;
147
+ subtitle?: string;
129
148
  intro?: Html;
130
149
  content?: Html;
131
150
  attached_attachments_content?: Json;
@@ -134,7 +153,24 @@ export interface HtmlStoryUpdateRequest extends GenericUpdateRequest {
134
153
  attached_gallery_content?: Json;
135
154
  attached_videos_content?: Json;
136
155
  }
137
- export interface SlateStoryUpdateRequest extends GenericUpdateRequest {
156
+ export interface SlateV3StoryUpdateRequest extends GenericUpdateRequest {
157
+ format_version?: Story.FormatVersion.SLATEJS_V3;
158
+ header_image?: UploadedImage | null;
159
+ title?: string;
160
+ subtitle?: string;
161
+ /**
162
+ * Intro field is not supported for Prezly Content Format stories.
163
+ */
164
+ intro?: never;
165
+ content?: PrezlyContentFormat;
166
+ autosaved_content?: PrezlyContentFormat;
167
+ content_version?: number;
168
+ }
169
+ export interface SlateV4StoryUpdateRequest extends GenericUpdateRequest {
170
+ format_version?: Story.FormatVersion.SLATEJS_V4;
171
+ header_image?: never;
172
+ title?: never;
173
+ subtitle?: never;
138
174
  /**
139
175
  * Intro field is not supported for Prezly Content Format stories.
140
176
  */
@@ -155,8 +191,8 @@ export interface PreviewOptions {
155
191
  }
156
192
  export import Alignment = Campaign.StoryAlignment;
157
193
  export import Appearance = Campaign.StoryAppearance;
158
- export declare type CreateRequest = HtmlStoryCreateRequest | SlateStoryCreateRequest;
159
- export declare type UpdateRequest = HtmlStoryUpdateRequest | SlateStoryUpdateRequest;
194
+ export declare type CreateRequest = HtmlStoryCreateRequest | SlateV3StoryCreateRequest | SlateV4StoryCreateRequest;
195
+ export declare type UpdateRequest = HtmlStoryUpdateRequest | SlateV3StoryUpdateRequest | SlateV4StoryUpdateRequest;
160
196
  export interface AutosaveRequest {
161
197
  autosaved_content: PrezlyContentFormat;
162
198
  content_version?: number;
@@ -11,7 +11,8 @@ exports.Story = Story;
11
11
  let FormatVersion;
12
12
  (function (FormatVersion) {
13
13
  FormatVersion[FormatVersion["HTML"] = 1] = "HTML";
14
- FormatVersion[FormatVersion["SLATEJS"] = 3] = "SLATEJS";
14
+ FormatVersion[FormatVersion["SLATEJS_V3"] = 3] = "SLATEJS_V3";
15
+ FormatVersion[FormatVersion["SLATEJS_V4"] = 4] = "SLATEJS_V4";
15
16
  })(FormatVersion || (FormatVersion = {}));
16
17
  _Story.FormatVersion = FormatVersion;
17
18
  let Status;
@@ -103,7 +104,21 @@ exports.Story = Story;
103
104
  if (typeof arg === 'object' && arg !== null) {
104
105
  return isSlateFormat(arg.format_version);
105
106
  }
106
- return arg === FormatVersion.SLATEJS;
107
+ return arg === FormatVersion.SLATEJS_V3 || arg === FormatVersion.SLATEJS_V4;
107
108
  }
108
109
  _Story.isSlateFormat = isSlateFormat;
110
+ function isSlateV3Format(arg) {
111
+ if (typeof arg === 'object' && arg !== null) {
112
+ return arg.format_version === FormatVersion.SLATEJS_V3;
113
+ }
114
+ return arg === FormatVersion.SLATEJS_V3;
115
+ }
116
+ _Story.isSlateV3Format = isSlateV3Format;
117
+ function isSlateV4Format(arg) {
118
+ if (typeof arg === 'object' && arg !== null) {
119
+ return arg.format_version === FormatVersion.SLATEJS_V4;
120
+ }
121
+ return arg === FormatVersion.SLATEJS_V4;
122
+ }
123
+ _Story.isSlateV4Format = isSlateV4Format;
109
124
  })(Story || (exports.Story = Story = {}));
@@ -138,7 +138,8 @@ export interface Story {
138
138
  export declare namespace Story {
139
139
  enum FormatVersion {
140
140
  HTML = 1,
141
- SLATEJS = 3
141
+ SLATEJS_V3 = 3,
142
+ SLATEJS_V4 = 4
142
143
  }
143
144
  enum Status {
144
145
  UNINITIALIZED = "uninitialized",
@@ -259,9 +260,17 @@ export declare namespace Story {
259
260
  function isLegacyHtmlFormat<T extends Pick<Story, 'format_version'>>(story: T): story is T & {
260
261
  format_version: FormatVersion.HTML;
261
262
  };
262
- function isSlateFormat(format: FormatVersion): format is FormatVersion.SLATEJS;
263
+ function isSlateFormat(format: FormatVersion): format is FormatVersion.SLATEJS_V3 | FormatVersion.SLATEJS_V4;
263
264
  function isSlateFormat<T extends Pick<Story, 'format_version'>>(story: Pick<Story, 'format_version'>): story is T & {
264
- format_version: FormatVersion.SLATEJS;
265
+ format_version: FormatVersion.SLATEJS_V3 | FormatVersion.SLATEJS_V4;
266
+ };
267
+ function isSlateV3Format(format: FormatVersion): format is FormatVersion.SLATEJS_V3;
268
+ function isSlateV3Format<T extends Pick<Story, 'format_version'>>(story: Pick<Story, 'format_version'>): story is T & {
269
+ format_version: FormatVersion.SLATEJS_V3;
270
+ };
271
+ function isSlateV4Format(format: FormatVersion): format is FormatVersion.SLATEJS_V4;
272
+ function isSlateV4Format<T extends Pick<Story, 'format_version'>>(story: Pick<Story, 'format_version'>): story is T & {
273
+ format_version: FormatVersion.SLATEJS_V4;
265
274
  };
266
275
  }
267
276
  export interface ExtendedStory extends Story, Pick<Story.ExtraFields, 'thumbnail_image' | 'header_image' | 'preview_image' | 'social_image' | 'social_text' | 'tag_names' | 'content' | 'attached_gallery_content' | 'referenced_entities'> {
@@ -4,7 +4,8 @@ export let Story;
4
4
  let FormatVersion;
5
5
  (function (FormatVersion) {
6
6
  FormatVersion[FormatVersion["HTML"] = 1] = "HTML";
7
- FormatVersion[FormatVersion["SLATEJS"] = 3] = "SLATEJS";
7
+ FormatVersion[FormatVersion["SLATEJS_V3"] = 3] = "SLATEJS_V3";
8
+ FormatVersion[FormatVersion["SLATEJS_V4"] = 4] = "SLATEJS_V4";
8
9
  })(FormatVersion || (FormatVersion = {}));
9
10
  _Story.FormatVersion = FormatVersion;
10
11
  let Status;
@@ -96,7 +97,21 @@ export let Story;
96
97
  if (typeof arg === 'object' && arg !== null) {
97
98
  return isSlateFormat(arg.format_version);
98
99
  }
99
- return arg === FormatVersion.SLATEJS;
100
+ return arg === FormatVersion.SLATEJS_V3 || arg === FormatVersion.SLATEJS_V4;
100
101
  }
101
102
  _Story.isSlateFormat = isSlateFormat;
103
+ function isSlateV3Format(arg) {
104
+ if (typeof arg === 'object' && arg !== null) {
105
+ return arg.format_version === FormatVersion.SLATEJS_V3;
106
+ }
107
+ return arg === FormatVersion.SLATEJS_V3;
108
+ }
109
+ _Story.isSlateV3Format = isSlateV3Format;
110
+ function isSlateV4Format(arg) {
111
+ if (typeof arg === 'object' && arg !== null) {
112
+ return arg.format_version === FormatVersion.SLATEJS_V4;
113
+ }
114
+ return arg === FormatVersion.SLATEJS_V4;
115
+ }
116
+ _Story.isSlateV4Format = isSlateV4Format;
102
117
  })(Story || (Story = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prezly/sdk",
3
- "version": "15.21.0",
3
+ "version": "16.0.0",
4
4
  "description": "Prezly API SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",