strapi-sdk-js 2.3.4 → 3.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/README.md CHANGED
@@ -15,7 +15,7 @@
15
15
 
16
16
  ## 🚀 Features
17
17
 
18
- - Strapi v4 supports
18
+ - Strapi v5 supports
19
19
  - RESTful methods
20
20
  - Simplified request responses
21
21
  - Formatted error handling
package/dist/index.cjs CHANGED
@@ -262,14 +262,18 @@ class Strapi {
262
262
  * Get a specific {content-type} entry
263
263
  *
264
264
  * @param {string} contentType - Content type's name pluralized
265
- * @param {string|number} id - ID of entry
265
+ * @param {string} documentId - documentId of the entry
266
266
  * @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
267
267
  * @returns Promise<StrapiResponse<T>>
268
268
  */
269
- findOne(contentType, id, params) {
270
- return this.request("get", `/${contentType}/${id}`, {
271
- params
272
- });
269
+ findOne(contentType, documentId, params) {
270
+ return this.request(
271
+ "get",
272
+ `/${contentType}/${documentId}`,
273
+ {
274
+ params
275
+ }
276
+ );
273
277
  }
274
278
  /**
275
279
  * Create a {content-type} entry
@@ -289,29 +293,30 @@ class Strapi {
289
293
  * Update a specific entry
290
294
  *
291
295
  * @param {string} contentType - Content type's name pluralized
292
- * @param {string|number} id - ID of entry to be updated
296
+ * @param {string} documentId - documentId of entry to be updated
293
297
  * @param {AxiosRequestConfig["data"]} data - New entry data
294
298
  * @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
295
299
  * @returns Promise<StrapiResponse<T>>
296
300
  */
297
- update(contentType, id, data, params) {
298
- return this.request("put", `/${contentType}/${id}`, {
299
- data: { data },
300
- params
301
- });
301
+ update(contentType, documentId, data, params) {
302
+ return this.request(
303
+ "put",
304
+ `/${contentType}/${documentId}`,
305
+ {
306
+ data: { data },
307
+ params
308
+ }
309
+ );
302
310
  }
303
311
  /**
304
312
  * Delete en entry
305
313
  *
306
314
  * @param {string} contentType - Content type's name pluralized
307
- * @param {string|number} id - ID of entry to be deleted
308
- * @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
309
- * @returns Promise<StrapiResponse<T>>
315
+ * @param {string} documentId - documentId of entry to be deleted
316
+ * @returns Promise<void>
310
317
  */
311
- delete(contentType, id, params) {
312
- return this.request("delete", `/${contentType}/${id}`, {
313
- params
314
- });
318
+ delete(contentType, documentId) {
319
+ return this.request("delete", `/${contentType}/${documentId}`);
315
320
  }
316
321
  /**
317
322
  * Refresh local data of the logged-in user
package/dist/index.d.ts CHANGED
@@ -39,7 +39,7 @@ interface StrapiRequestParams extends StrapiBaseRequestParams {
39
39
  sort?: string | Array<string>;
40
40
  pagination?: PaginationByOffset | PaginationByPage;
41
41
  filters?: Record<string, unknown>;
42
- publicationState?: "live" | "preview";
42
+ state?: "draft" | "published";
43
43
  locale?: StrapiLocale;
44
44
  }
45
45
  interface StrapiError {
@@ -51,9 +51,25 @@ interface StrapiError {
51
51
  details: Record<string, unknown>;
52
52
  };
53
53
  }
54
+ interface StrapiSystemFields {
55
+ /** @deprecated use documentId instead */
56
+ id: number | string;
57
+ documentId: string;
58
+ locale?: string;
59
+ }
60
+ type StrapiResponseData<T> = T extends undefined | null ? StrapiSystemFields : T extends object ? T extends Array<infer U> ? Array<StrapiResponseData<U>> : T extends Record<string, unknown> ? {
61
+ [K in keyof T]: StrapiResponseData<T[K]>;
62
+ } & StrapiSystemFields : T : T;
54
63
  interface StrapiResponse<T> {
55
- data: T;
56
- meta: Record<string, unknown>;
64
+ data: StrapiResponseData<T> & StrapiSystemFields;
65
+ meta: StrapiResponseMeta;
66
+ }
67
+ interface StrapiResponseMetaPagination {
68
+ page: number;
69
+ pageSize: number;
70
+ }
71
+ interface StrapiResponseMeta extends Record<string, unknown> {
72
+ pagination?: StrapiResponseMetaPagination;
57
73
  }
58
74
  interface StrapiAuthenticationResponse {
59
75
  user: Record<string, unknown>;
@@ -193,16 +209,16 @@ declare class Strapi {
193
209
  * @param {StrapiRequestParams} params? - Query parameters
194
210
  * @returns Promise<StrapiResponse<T>>
195
211
  */
196
- find<T>(contentType: string, params?: StrapiRequestParams): Promise<StrapiResponse<T>>;
212
+ find<T>(contentType: string, params?: StrapiRequestParams): Promise<StrapiResponse<T[]>>;
197
213
  /**
198
214
  * Get a specific {content-type} entry
199
215
  *
200
216
  * @param {string} contentType - Content type's name pluralized
201
- * @param {string|number} id - ID of entry
217
+ * @param {string} documentId - documentId of the entry
202
218
  * @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
203
219
  * @returns Promise<StrapiResponse<T>>
204
220
  */
205
- findOne<T>(contentType: string, id: string | number, params?: StrapiBaseRequestParams): Promise<StrapiResponse<T>>;
221
+ findOne<T>(contentType: string, documentId: string, params?: StrapiBaseRequestParams): Promise<StrapiResponse<T>>;
206
222
  /**
207
223
  * Create a {content-type} entry
208
224
  *
@@ -216,21 +232,20 @@ declare class Strapi {
216
232
  * Update a specific entry
217
233
  *
218
234
  * @param {string} contentType - Content type's name pluralized
219
- * @param {string|number} id - ID of entry to be updated
235
+ * @param {string} documentId - documentId of entry to be updated
220
236
  * @param {AxiosRequestConfig["data"]} data - New entry data
221
237
  * @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
222
238
  * @returns Promise<StrapiResponse<T>>
223
239
  */
224
- update<T>(contentType: string, id: string | number, data: AxiosRequestConfig["data"], params?: StrapiBaseRequestParams): Promise<StrapiResponse<T>>;
240
+ update<T>(contentType: string, documentId: string, data: AxiosRequestConfig["data"], params?: StrapiBaseRequestParams): Promise<StrapiResponse<T>>;
225
241
  /**
226
242
  * Delete en entry
227
243
  *
228
244
  * @param {string} contentType - Content type's name pluralized
229
- * @param {string|number} id - ID of entry to be deleted
230
- * @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
231
- * @returns Promise<StrapiResponse<T>>
245
+ * @param {string} documentId - documentId of entry to be deleted
246
+ * @returns Promise<void>
232
247
  */
233
- delete<T>(contentType: string, id: string | number, params?: StrapiBaseRequestParams): Promise<StrapiResponse<T>>;
248
+ delete(contentType: string, documentId: string): Promise<void>;
234
249
  /**
235
250
  * Refresh local data of the logged-in user
236
251
  *
package/dist/index.mjs CHANGED
@@ -260,14 +260,18 @@ class Strapi {
260
260
  * Get a specific {content-type} entry
261
261
  *
262
262
  * @param {string} contentType - Content type's name pluralized
263
- * @param {string|number} id - ID of entry
263
+ * @param {string} documentId - documentId of the entry
264
264
  * @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
265
265
  * @returns Promise<StrapiResponse<T>>
266
266
  */
267
- findOne(contentType, id, params) {
268
- return this.request("get", `/${contentType}/${id}`, {
269
- params
270
- });
267
+ findOne(contentType, documentId, params) {
268
+ return this.request(
269
+ "get",
270
+ `/${contentType}/${documentId}`,
271
+ {
272
+ params
273
+ }
274
+ );
271
275
  }
272
276
  /**
273
277
  * Create a {content-type} entry
@@ -287,29 +291,30 @@ class Strapi {
287
291
  * Update a specific entry
288
292
  *
289
293
  * @param {string} contentType - Content type's name pluralized
290
- * @param {string|number} id - ID of entry to be updated
294
+ * @param {string} documentId - documentId of entry to be updated
291
295
  * @param {AxiosRequestConfig["data"]} data - New entry data
292
296
  * @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
293
297
  * @returns Promise<StrapiResponse<T>>
294
298
  */
295
- update(contentType, id, data, params) {
296
- return this.request("put", `/${contentType}/${id}`, {
297
- data: { data },
298
- params
299
- });
299
+ update(contentType, documentId, data, params) {
300
+ return this.request(
301
+ "put",
302
+ `/${contentType}/${documentId}`,
303
+ {
304
+ data: { data },
305
+ params
306
+ }
307
+ );
300
308
  }
301
309
  /**
302
310
  * Delete en entry
303
311
  *
304
312
  * @param {string} contentType - Content type's name pluralized
305
- * @param {string|number} id - ID of entry to be deleted
306
- * @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
307
- * @returns Promise<StrapiResponse<T>>
313
+ * @param {string} documentId - documentId of entry to be deleted
314
+ * @returns Promise<void>
308
315
  */
309
- delete(contentType, id, params) {
310
- return this.request("delete", `/${contentType}/${id}`, {
311
- params
312
- });
316
+ delete(contentType, documentId) {
317
+ return this.request("delete", `/${contentType}/${documentId}`);
313
318
  }
314
319
  /**
315
320
  * Refresh local data of the logged-in user
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strapi-sdk-js",
3
- "version": "2.3.4",
3
+ "version": "3.0.0",
4
4
  "description": "📦 Javascript SDK for your Strapi API",
5
5
  "keywords": [
6
6
  "strapi",