@prezly/sdk 18.2.2 → 18.3.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 = "18.2.1";
7
+ const VERSION = "18.2.2";
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 = "18.2.1";
1
+ const VERSION = "18.2.2";
2
2
  const URL = 'https://github.com/prezly/javascript-sdk';
3
3
  export const DEFAULT_USER_AGENT = `prezly-javascript-sdk/${VERSION} (+${URL})`;
@@ -112,22 +112,47 @@ class Client {
112
112
  });
113
113
  return story;
114
114
  }
115
- async create(payload, options) {
115
+ async getBySlug(slug, options) {
116
+ if (slug.includes('/') || slug.includes('\\')) {
117
+ throw new Error('Story slugs cannot contain slashes.');
118
+ }
116
119
  const {
117
120
  include,
121
+ query,
118
122
  formats
119
123
  } = options ?? {};
120
124
  const {
121
125
  story
122
- } = await this.apiClient.post(_routing.routing.storiesUrl, {
126
+ } = await this.apiClient.post(`${_routing.routing.storiesUrl}/by-slug/${slug}`, {
123
127
  headers: acceptedFormatsHeader(formats),
124
- payload,
125
128
  query: {
126
129
  include
130
+ },
131
+ payload: {
132
+ query
127
133
  }
128
134
  });
129
135
  return story;
130
136
  }
137
+ async create(payload, options) {
138
+ const {
139
+ include,
140
+ formats,
141
+ force = false
142
+ } = options ?? {};
143
+ const {
144
+ story
145
+ } = await this.apiClient.post(_routing.routing.storiesUrl, {
146
+ headers: acceptedFormatsHeader(formats),
147
+ query: {
148
+ include,
149
+ force: force || undefined // only pass it if it's true
150
+ },
151
+
152
+ payload
153
+ });
154
+ return story;
155
+ }
131
156
  async duplicate(id, options) {
132
157
  const {
133
158
  include,
@@ -169,8 +194,8 @@ class Client {
169
194
  async move(id, payload, options) {
170
195
  const {
171
196
  include,
172
- force,
173
- formats
197
+ formats,
198
+ force = false
174
199
  } = options ?? {};
175
200
  const url = `${_routing.routing.storiesUrl}/${id}/move`;
176
201
  try {
@@ -179,9 +204,10 @@ class Client {
179
204
  } = await this.apiClient.post(url, {
180
205
  headers: acceptedFormatsHeader(formats),
181
206
  query: {
182
- include: include,
183
- force
207
+ include,
208
+ force: force || undefined // only pass it if it's true
184
209
  },
210
+
185
211
  payload
186
212
  });
187
213
  return {
@@ -199,16 +225,19 @@ class Client {
199
225
  const url = `${_routing.routing.storiesUrl}/${id}`;
200
226
  const {
201
227
  include,
202
- formats
228
+ formats,
229
+ force = false
203
230
  } = options ?? {};
204
231
  const {
205
232
  story
206
233
  } = await this.apiClient.patch(url, {
207
234
  headers: acceptedFormatsHeader(formats),
208
- payload,
209
235
  query: {
210
- include: include
211
- }
236
+ include,
237
+ force: force || undefined // only pass it if it's true
238
+ },
239
+
240
+ payload
212
241
  });
213
242
  return story;
214
243
  }
@@ -228,7 +257,7 @@ class Client {
228
257
  headers: acceptedFormatsHeader(formats),
229
258
  payload,
230
259
  query: {
231
- include: include
260
+ include
232
261
  }
233
262
  });
234
263
  return story;
@@ -249,7 +278,7 @@ class Client {
249
278
  headers: acceptedFormatsHeader(formats),
250
279
  payload,
251
280
  query: {
252
- include: include
281
+ include
253
282
  }
254
283
  });
255
284
  return story;
@@ -266,7 +295,7 @@ class Client {
266
295
  headers: acceptedFormatsHeader(formats),
267
296
  payload,
268
297
  query: {
269
- include: include
298
+ include
270
299
  }
271
300
  });
272
301
  return story;
@@ -283,7 +312,7 @@ class Client {
283
312
  headers: acceptedFormatsHeader(formats),
284
313
  payload,
285
314
  query: {
286
- include: include
315
+ include
287
316
  }
288
317
  });
289
318
  return story;
@@ -300,7 +329,7 @@ class Client {
300
329
  headers: acceptedFormatsHeader(formats),
301
330
  payload,
302
331
  query: {
303
- include: include
332
+ include
304
333
  }
305
334
  });
306
335
  return story;
@@ -317,7 +346,7 @@ class Client {
317
346
  headers: acceptedFormatsHeader(formats),
318
347
  payload,
319
348
  query: {
320
- include: include
349
+ include
321
350
  }
322
351
  });
323
352
  return story;
@@ -326,8 +355,8 @@ class Client {
326
355
  const url = `${_routing.routing.storiesUrl}/${id}/pin`;
327
356
  const {
328
357
  include,
329
- force,
330
- formats
358
+ formats,
359
+ force = false
331
360
  } = options ?? {};
332
361
  const {
333
362
  story
@@ -335,9 +364,10 @@ class Client {
335
364
  headers: acceptedFormatsHeader(formats),
336
365
  query: {
337
366
  include: include,
338
- force: force || undefined
367
+ force: force || undefined // only pass it if it's true
339
368
  }
340
369
  });
370
+
341
371
  return story;
342
372
  }
343
373
  async unpin(id, options) {
@@ -1,5 +1,5 @@
1
1
  import type { DeferredJobsApiClient } from '../../api';
2
- import type { ExtendedStory, Story } from '../../types';
2
+ import type { ExtendedStory, Query, Story } from '../../types';
3
3
  import type { AutosaveRequest, ChangeNewsroomSuccessResponse, ChangeNewsroomUnsafeResponse, CreateRequest, IncludeOptions, ListOptions, ListResponse, MoveRequest, PreviewResponse, PreviewOptions, PublishRequest, RevertRequest, ScheduleRequest, SearchOptions, TranslateRequest, UnpublishRequest, UnscheduleRequest, UpdateRequest } from './types';
4
4
  /**
5
5
  * `uuid` is the preferred way of targeting a Story. Numeric `id` is considered deprecated.
@@ -51,10 +51,19 @@ export declare class Client {
51
51
  }>(ids: Story['id'][], options?: Exactly<Options, IncludeOptions & {
52
52
  formats?: Formats;
53
53
  }>): Promise<(ExtendedStory & InferExtraFields<Options>)[]>;
54
+ getBySlug<Options extends IncludeOptions & {
55
+ formats?: Formats;
56
+ query?: Query;
57
+ }>(slug: Story['slug'], options?: Exactly<Options, IncludeOptions & {
58
+ formats?: Formats;
59
+ query?: Query;
60
+ }>): Promise<ExtendedStory & InferExtraFields<Options>>;
54
61
  create<Options extends IncludeOptions & {
55
62
  formats?: Formats;
63
+ force?: boolean;
56
64
  }>(payload: CreateRequest, options?: Exactly<Options, IncludeOptions & {
57
65
  formats?: Formats;
66
+ force?: boolean;
58
67
  }>): Promise<ExtendedStory & InferExtraFields<Options>>;
59
68
  duplicate<Options extends IncludeOptions & {
60
69
  formats?: Formats;
@@ -67,16 +76,18 @@ export declare class Client {
67
76
  formats?: Formats;
68
77
  }>): Promise<ExtendedStory & InferExtraFields<Options>>;
69
78
  move<Options extends IncludeOptions & {
70
- force?: true;
71
79
  formats?: Formats;
80
+ force?: boolean;
72
81
  }>(id: StoryId, payload: MoveRequest, options?: Exactly<Options, IncludeOptions & {
73
- force?: true;
74
82
  formats?: Formats;
83
+ force?: boolean;
75
84
  }>): Promise<ChangeNewsroomSuccessResponse<ExtendedStory & InferExtraFields<Options>> | ChangeNewsroomUnsafeResponse>;
76
85
  update<Options extends IncludeOptions & {
77
86
  formats?: Formats;
87
+ force?: boolean;
78
88
  }>(id: StoryId, payload: UpdateRequest, options?: Exactly<Options, IncludeOptions & {
79
89
  formats?: Formats;
90
+ force?: boolean;
80
91
  }>): Promise<ExtendedStory & InferExtraFields<Options>>;
81
92
  /**
82
93
  * This operation is only allowed for V3 stories
@@ -115,11 +126,11 @@ export declare class Client {
115
126
  formats?: Formats;
116
127
  }>): Promise<ExtendedStory & InferExtraFields<Options>>;
117
128
  pin<Options extends IncludeOptions & {
118
- force?: boolean;
119
129
  formats?: Formats;
120
- }>(id: StoryId, options?: Exactly<Options, IncludeOptions & {
121
130
  force?: boolean;
131
+ }>(id: StoryId, options?: Exactly<Options, IncludeOptions & {
122
132
  formats?: Formats;
133
+ force?: boolean;
123
134
  }>): Promise<ExtendedStory & InferExtraFields<Options>>;
124
135
  unpin<Options extends IncludeOptions & {
125
136
  formats?: Formats;
@@ -108,22 +108,47 @@ export class Client {
108
108
  });
109
109
  return story;
110
110
  }
111
- async create(payload, options) {
111
+ async getBySlug(slug, options) {
112
+ if (slug.includes('/') || slug.includes('\\')) {
113
+ throw new Error('Story slugs cannot contain slashes.');
114
+ }
112
115
  const {
113
116
  include,
117
+ query,
114
118
  formats
115
119
  } = options ?? {};
116
120
  const {
117
121
  story
118
- } = await this.apiClient.post(routing.storiesUrl, {
122
+ } = await this.apiClient.post(`${routing.storiesUrl}/by-slug/${slug}`, {
119
123
  headers: acceptedFormatsHeader(formats),
120
- payload,
121
124
  query: {
122
125
  include
126
+ },
127
+ payload: {
128
+ query
123
129
  }
124
130
  });
125
131
  return story;
126
132
  }
133
+ async create(payload, options) {
134
+ const {
135
+ include,
136
+ formats,
137
+ force = false
138
+ } = options ?? {};
139
+ const {
140
+ story
141
+ } = await this.apiClient.post(routing.storiesUrl, {
142
+ headers: acceptedFormatsHeader(formats),
143
+ query: {
144
+ include,
145
+ force: force || undefined // only pass it if it's true
146
+ },
147
+
148
+ payload
149
+ });
150
+ return story;
151
+ }
127
152
  async duplicate(id, options) {
128
153
  const {
129
154
  include,
@@ -165,8 +190,8 @@ export class Client {
165
190
  async move(id, payload, options) {
166
191
  const {
167
192
  include,
168
- force,
169
- formats
193
+ formats,
194
+ force = false
170
195
  } = options ?? {};
171
196
  const url = `${routing.storiesUrl}/${id}/move`;
172
197
  try {
@@ -175,9 +200,10 @@ export class Client {
175
200
  } = await this.apiClient.post(url, {
176
201
  headers: acceptedFormatsHeader(formats),
177
202
  query: {
178
- include: include,
179
- force
203
+ include,
204
+ force: force || undefined // only pass it if it's true
180
205
  },
206
+
181
207
  payload
182
208
  });
183
209
  return {
@@ -195,16 +221,19 @@ export class Client {
195
221
  const url = `${routing.storiesUrl}/${id}`;
196
222
  const {
197
223
  include,
198
- formats
224
+ formats,
225
+ force = false
199
226
  } = options ?? {};
200
227
  const {
201
228
  story
202
229
  } = await this.apiClient.patch(url, {
203
230
  headers: acceptedFormatsHeader(formats),
204
- payload,
205
231
  query: {
206
- include: include
207
- }
232
+ include,
233
+ force: force || undefined // only pass it if it's true
234
+ },
235
+
236
+ payload
208
237
  });
209
238
  return story;
210
239
  }
@@ -224,7 +253,7 @@ export class Client {
224
253
  headers: acceptedFormatsHeader(formats),
225
254
  payload,
226
255
  query: {
227
- include: include
256
+ include
228
257
  }
229
258
  });
230
259
  return story;
@@ -245,7 +274,7 @@ export class Client {
245
274
  headers: acceptedFormatsHeader(formats),
246
275
  payload,
247
276
  query: {
248
- include: include
277
+ include
249
278
  }
250
279
  });
251
280
  return story;
@@ -262,7 +291,7 @@ export class Client {
262
291
  headers: acceptedFormatsHeader(formats),
263
292
  payload,
264
293
  query: {
265
- include: include
294
+ include
266
295
  }
267
296
  });
268
297
  return story;
@@ -279,7 +308,7 @@ export class Client {
279
308
  headers: acceptedFormatsHeader(formats),
280
309
  payload,
281
310
  query: {
282
- include: include
311
+ include
283
312
  }
284
313
  });
285
314
  return story;
@@ -296,7 +325,7 @@ export class Client {
296
325
  headers: acceptedFormatsHeader(formats),
297
326
  payload,
298
327
  query: {
299
- include: include
328
+ include
300
329
  }
301
330
  });
302
331
  return story;
@@ -313,7 +342,7 @@ export class Client {
313
342
  headers: acceptedFormatsHeader(formats),
314
343
  payload,
315
344
  query: {
316
- include: include
345
+ include
317
346
  }
318
347
  });
319
348
  return story;
@@ -322,8 +351,8 @@ export class Client {
322
351
  const url = `${routing.storiesUrl}/${id}/pin`;
323
352
  const {
324
353
  include,
325
- force,
326
- formats
354
+ formats,
355
+ force = false
327
356
  } = options ?? {};
328
357
  const {
329
358
  story
@@ -331,9 +360,10 @@ export class Client {
331
360
  headers: acceptedFormatsHeader(formats),
332
361
  query: {
333
362
  include: include,
334
- force: force || undefined
363
+ force: force || undefined // only pass it if it's true
335
364
  }
336
365
  });
366
+
337
367
  return story;
338
368
  }
339
369
  async unpin(id, options) {
@@ -70,6 +70,15 @@ export interface ListResponse<S extends Story = Story> {
70
70
  sort: string;
71
71
  }
72
72
  interface GenericCreateRequest {
73
+ /**
74
+ * Set a custom slug for a Story.
75
+ *
76
+ * - If there is another story with exactly the same slug value, the Create request will throw [HTTP 409 Conflict].
77
+ *
78
+ * - Conflicts can be force-resolved by passing `?force` GET parameter.
79
+ * This will update other conflicting stories slugs to something else (i.e. adding random suffix).
80
+ */
81
+ slug?: Story['slug'];
73
82
  newsroom?: Newsroom['id'] | Newsroom['uuid'];
74
83
  published_at?: Iso8601DateTime;
75
84
  visibility?: Story.Visibility;
@@ -82,6 +91,16 @@ interface GenericCreateRequest {
82
91
  is_shared_to_prpro?: boolean;
83
92
  }
84
93
  interface GenericUpdateRequest {
94
+ /**
95
+ * Set a custom slug for a Story.
96
+ * Updating it to `null` will revert back to automatically generated slugs.
97
+ *
98
+ * - If there is another story with exactly the same slug value, the Update request will throw [HTTP 409 Conflict].
99
+ *
100
+ * - Conflicts can be force-resolved by passing `?force` GET parameter.
101
+ * This will update other conflicting stories slugs to something else (i.e. adding random suffix).
102
+ */
103
+ slug?: Story['slug'] | null;
85
104
  published_at?: Iso8601DateTime;
86
105
  visibility?: Story.Visibility;
87
106
  culture?: CultureRef['code'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prezly/sdk",
3
- "version": "18.2.2",
3
+ "version": "18.3.0",
4
4
  "description": "Prezly API SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",