strapi-sdk-js 2.3.3 → 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,38 +293,41 @@ 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
318
323
  *
319
324
  * @returns Promise<StrapiUser>
320
325
  */
321
- async fetchUser() {
326
+ async fetchUser(params) {
322
327
  try {
323
- const user = await this.request("get", "/users/me");
328
+ const user = await this.request("get", "/users/me", {
329
+ params
330
+ });
324
331
  this.user = user;
325
332
  } catch (e) {
326
333
  this.logout();
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>;
@@ -67,6 +83,7 @@ interface StrapiRegistrationData {
67
83
  username: string;
68
84
  email: string;
69
85
  password: string;
86
+ [k: string]: unknown;
70
87
  }
71
88
  interface StrapiForgotPasswordData {
72
89
  email: string;
@@ -192,16 +209,16 @@ declare class Strapi {
192
209
  * @param {StrapiRequestParams} params? - Query parameters
193
210
  * @returns Promise<StrapiResponse<T>>
194
211
  */
195
- find<T>(contentType: string, params?: StrapiRequestParams): Promise<StrapiResponse<T>>;
212
+ find<T>(contentType: string, params?: StrapiRequestParams): Promise<StrapiResponse<T[]>>;
196
213
  /**
197
214
  * Get a specific {content-type} entry
198
215
  *
199
216
  * @param {string} contentType - Content type's name pluralized
200
- * @param {string|number} id - ID of entry
217
+ * @param {string} documentId - documentId of the entry
201
218
  * @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
202
219
  * @returns Promise<StrapiResponse<T>>
203
220
  */
204
- findOne<T>(contentType: string, id: string | number, params?: StrapiBaseRequestParams): Promise<StrapiResponse<T>>;
221
+ findOne<T>(contentType: string, documentId: string, params?: StrapiBaseRequestParams): Promise<StrapiResponse<T>>;
205
222
  /**
206
223
  * Create a {content-type} entry
207
224
  *
@@ -215,27 +232,26 @@ declare class Strapi {
215
232
  * Update a specific entry
216
233
  *
217
234
  * @param {string} contentType - Content type's name pluralized
218
- * @param {string|number} id - ID of entry to be updated
235
+ * @param {string} documentId - documentId of entry to be updated
219
236
  * @param {AxiosRequestConfig["data"]} data - New entry data
220
237
  * @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
221
238
  * @returns Promise<StrapiResponse<T>>
222
239
  */
223
- 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>>;
224
241
  /**
225
242
  * Delete en entry
226
243
  *
227
244
  * @param {string} contentType - Content type's name pluralized
228
- * @param {string|number} id - ID of entry to be deleted
229
- * @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
230
- * @returns Promise<StrapiResponse<T>>
245
+ * @param {string} documentId - documentId of entry to be deleted
246
+ * @returns Promise<void>
231
247
  */
232
- delete<T>(contentType: string, id: string | number, params?: StrapiBaseRequestParams): Promise<StrapiResponse<T>>;
248
+ delete(contentType: string, documentId: string): Promise<void>;
233
249
  /**
234
250
  * Refresh local data of the logged-in user
235
251
  *
236
252
  * @returns Promise<StrapiUser>
237
253
  */
238
- fetchUser(): Promise<StrapiUser>;
254
+ fetchUser(params?: StrapiBaseRequestParams): Promise<StrapiUser>;
239
255
  /**
240
256
  * Retrieve token from chosen storage
241
257
  *
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,38 +291,41 @@ 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
316
321
  *
317
322
  * @returns Promise<StrapiUser>
318
323
  */
319
- async fetchUser() {
324
+ async fetchUser(params) {
320
325
  try {
321
- const user = await this.request("get", "/users/me");
326
+ const user = await this.request("get", "/users/me", {
327
+ params
328
+ });
322
329
  this.user = user;
323
330
  } catch (e) {
324
331
  this.logout();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strapi-sdk-js",
3
- "version": "2.3.3",
3
+ "version": "3.0.0",
4
4
  "description": "📦 Javascript SDK for your Strapi API",
5
5
  "keywords": [
6
6
  "strapi",
@@ -58,7 +58,7 @@
58
58
  "test": "run-s build lint test:unit",
59
59
  "test:unit": "jest",
60
60
  "commit": "git-cz",
61
- "docs:release": "dotenv node ./scripts/beforeRelease.js",
61
+ "docs:release": "node ./scripts/beforeRelease.js",
62
62
  "release": "dotenv release-it --",
63
63
  "prepare": "rollup -c"
64
64
  },