strapi-sdk-js 3.0.1 → 3.1.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/index.cjs +25 -25
- package/dist/index.d.ts +16 -5
- package/dist/index.mjs +25 -25
- package/package.json +19 -15
package/dist/index.cjs
CHANGED
|
@@ -10,12 +10,6 @@ function isBrowser() {
|
|
|
10
10
|
return typeof window !== "undefined";
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
var __defProp = Object.defineProperty;
|
|
14
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
15
|
-
var __publicField = (obj, key, value) => {
|
|
16
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
17
|
-
return value;
|
|
18
|
-
};
|
|
19
13
|
const defaults = {
|
|
20
14
|
url: "http://localhost:1337",
|
|
21
15
|
prefix: "/api",
|
|
@@ -37,9 +31,8 @@ class Strapi {
|
|
|
37
31
|
* @param {AxiosRequestConfig} options.axiosOptions? - The list of your Content type on your Strapi API
|
|
38
32
|
*/
|
|
39
33
|
constructor(options) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
__publicField(this, "user", null);
|
|
34
|
+
this.user = null;
|
|
35
|
+
this._token = null;
|
|
43
36
|
const _options = defu(options || {}, defaults);
|
|
44
37
|
this.options = {
|
|
45
38
|
..._options,
|
|
@@ -225,8 +218,7 @@ class Strapi {
|
|
|
225
218
|
const params = qs.parse(window.location.search, {
|
|
226
219
|
ignoreQueryPrefix: true
|
|
227
220
|
});
|
|
228
|
-
if (params.access_token)
|
|
229
|
-
access_token = params.access_token;
|
|
221
|
+
if (params.access_token) access_token = params.access_token;
|
|
230
222
|
}
|
|
231
223
|
const { user, jwt } = await this.request(
|
|
232
224
|
"get",
|
|
@@ -311,14 +303,21 @@ class Strapi {
|
|
|
311
303
|
);
|
|
312
304
|
}
|
|
313
305
|
/**
|
|
314
|
-
* Delete
|
|
306
|
+
* Delete an entry
|
|
315
307
|
*
|
|
316
308
|
* @param {string} contentType - Content type's name pluralized
|
|
317
309
|
* @param {string} documentId - documentId of entry to be deleted
|
|
310
|
+
* @param {StrapiDeleteRequestParams} params? - Delete-specific query parameters
|
|
318
311
|
* @returns Promise<void>
|
|
319
312
|
*/
|
|
320
|
-
delete(contentType, documentId) {
|
|
321
|
-
return this.request(
|
|
313
|
+
delete(contentType, documentId, params) {
|
|
314
|
+
return this.request(
|
|
315
|
+
"delete",
|
|
316
|
+
`/${contentType}/${documentId}`,
|
|
317
|
+
{
|
|
318
|
+
params
|
|
319
|
+
}
|
|
320
|
+
);
|
|
322
321
|
}
|
|
323
322
|
/**
|
|
324
323
|
* Refresh local data of the logged-in user
|
|
@@ -343,13 +342,10 @@ class Strapi {
|
|
|
343
342
|
*/
|
|
344
343
|
getToken() {
|
|
345
344
|
const { useLocalStorage, key } = this.options.store;
|
|
346
|
-
if (isBrowser())
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
return token;
|
|
351
|
-
}
|
|
352
|
-
return null;
|
|
345
|
+
if (!isBrowser()) return this._token;
|
|
346
|
+
const token = useLocalStorage ? window.localStorage.getItem(key) : Cookies.get(key);
|
|
347
|
+
if (typeof token === "undefined") return null;
|
|
348
|
+
return token;
|
|
353
349
|
}
|
|
354
350
|
/**
|
|
355
351
|
* Set token in chosen storage
|
|
@@ -359,9 +355,11 @@ class Strapi {
|
|
|
359
355
|
*/
|
|
360
356
|
setToken(token) {
|
|
361
357
|
const { useLocalStorage, key, cookieOptions } = this.options.store;
|
|
362
|
-
if (isBrowser()) {
|
|
363
|
-
|
|
358
|
+
if (!isBrowser()) {
|
|
359
|
+
this._token = token;
|
|
360
|
+
return;
|
|
364
361
|
}
|
|
362
|
+
useLocalStorage ? window.localStorage.setItem(key, token) : Cookies.set(key, token, cookieOptions);
|
|
365
363
|
}
|
|
366
364
|
/**
|
|
367
365
|
* Remove token from chosen storage (Cookies or Local)
|
|
@@ -370,9 +368,11 @@ class Strapi {
|
|
|
370
368
|
*/
|
|
371
369
|
removeToken() {
|
|
372
370
|
const { useLocalStorage, key } = this.options.store;
|
|
373
|
-
if (isBrowser()) {
|
|
374
|
-
|
|
371
|
+
if (!isBrowser()) {
|
|
372
|
+
this._token = null;
|
|
373
|
+
return;
|
|
375
374
|
}
|
|
375
|
+
useLocalStorage ? window.localStorage.removeItem(key) : Cookies.remove(key);
|
|
376
376
|
}
|
|
377
377
|
}
|
|
378
378
|
|
package/dist/index.d.ts
CHANGED
|
@@ -35,11 +35,15 @@ interface StrapiBaseRequestParams {
|
|
|
35
35
|
fields?: Array<string>;
|
|
36
36
|
populate?: string | Array<string> | Record<string, unknown>;
|
|
37
37
|
}
|
|
38
|
+
interface StrapiDeleteRequestParams {
|
|
39
|
+
locale?: StrapiLocale;
|
|
40
|
+
}
|
|
41
|
+
type StrapiPublicationStatus = "draft" | "published";
|
|
38
42
|
interface StrapiRequestParams extends StrapiBaseRequestParams {
|
|
39
43
|
sort?: string | Array<string>;
|
|
40
44
|
pagination?: PaginationByOffset | PaginationByPage;
|
|
41
45
|
filters?: Record<string, unknown>;
|
|
42
|
-
|
|
46
|
+
status?: StrapiPublicationStatus;
|
|
43
47
|
locale?: StrapiLocale;
|
|
44
48
|
}
|
|
45
49
|
interface StrapiError {
|
|
@@ -61,12 +65,16 @@ type StrapiResponseData<T> = T extends undefined | null ? StrapiSystemFields : T
|
|
|
61
65
|
[K in keyof T]: StrapiResponseData<T[K]>;
|
|
62
66
|
} & StrapiSystemFields : T : T;
|
|
63
67
|
interface StrapiResponse<T> {
|
|
64
|
-
data: StrapiResponseData<T
|
|
68
|
+
data: StrapiResponseData<T>;
|
|
65
69
|
meta: StrapiResponseMeta;
|
|
66
70
|
}
|
|
67
71
|
interface StrapiResponseMetaPagination {
|
|
68
72
|
page: number;
|
|
69
73
|
pageSize: number;
|
|
74
|
+
start: number;
|
|
75
|
+
limit: number;
|
|
76
|
+
pageCount?: number;
|
|
77
|
+
total?: number;
|
|
70
78
|
}
|
|
71
79
|
interface StrapiResponseMeta extends Record<string, unknown> {
|
|
72
80
|
pagination?: StrapiResponseMetaPagination;
|
|
@@ -106,6 +114,7 @@ declare class Strapi {
|
|
|
106
114
|
axios: AxiosInstance;
|
|
107
115
|
options: StrapiDefaultOptions;
|
|
108
116
|
user: StrapiUser;
|
|
117
|
+
private _token;
|
|
109
118
|
/**
|
|
110
119
|
* Strapi SDK Constructor
|
|
111
120
|
*
|
|
@@ -239,13 +248,14 @@ declare class Strapi {
|
|
|
239
248
|
*/
|
|
240
249
|
update<T>(contentType: string, documentId: string, data: AxiosRequestConfig["data"], params?: StrapiBaseRequestParams): Promise<StrapiResponse<T>>;
|
|
241
250
|
/**
|
|
242
|
-
* Delete
|
|
251
|
+
* Delete an entry
|
|
243
252
|
*
|
|
244
253
|
* @param {string} contentType - Content type's name pluralized
|
|
245
254
|
* @param {string} documentId - documentId of entry to be deleted
|
|
255
|
+
* @param {StrapiDeleteRequestParams} params? - Delete-specific query parameters
|
|
246
256
|
* @returns Promise<void>
|
|
247
257
|
*/
|
|
248
|
-
delete(contentType: string, documentId: string): Promise<void>;
|
|
258
|
+
delete(contentType: string, documentId: string, params?: StrapiDeleteRequestParams): Promise<void>;
|
|
249
259
|
/**
|
|
250
260
|
* Refresh local data of the logged-in user
|
|
251
261
|
*
|
|
@@ -273,4 +283,5 @@ declare class Strapi {
|
|
|
273
283
|
removeToken(): void;
|
|
274
284
|
}
|
|
275
285
|
|
|
276
|
-
export {
|
|
286
|
+
export { Strapi as default };
|
|
287
|
+
export type { PaginationByOffset, PaginationByPage, StoreConfig, StrapiAuthProvider, StrapiAuthenticationData, StrapiAuthenticationResponse, StrapiBaseRequestParams, StrapiChangePasswordData, StrapiDefaultOptions, StrapiDeleteRequestParams, StrapiEmailConfirmationData, StrapiError, StrapiForgotPasswordData, StrapiLocale, StrapiOptions, StrapiPublicationStatus, StrapiRegistrationData, StrapiRequestParams, StrapiResetPasswordData, StrapiResponse, StrapiResponseMeta, StrapiResponseMetaPagination, StrapiUser };
|
package/dist/index.mjs
CHANGED
|
@@ -8,12 +8,6 @@ function isBrowser() {
|
|
|
8
8
|
return typeof window !== "undefined";
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
var __defProp = Object.defineProperty;
|
|
12
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
-
var __publicField = (obj, key, value) => {
|
|
14
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
15
|
-
return value;
|
|
16
|
-
};
|
|
17
11
|
const defaults = {
|
|
18
12
|
url: "http://localhost:1337",
|
|
19
13
|
prefix: "/api",
|
|
@@ -35,9 +29,8 @@ class Strapi {
|
|
|
35
29
|
* @param {AxiosRequestConfig} options.axiosOptions? - The list of your Content type on your Strapi API
|
|
36
30
|
*/
|
|
37
31
|
constructor(options) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
__publicField(this, "user", null);
|
|
32
|
+
this.user = null;
|
|
33
|
+
this._token = null;
|
|
41
34
|
const _options = defu(options || {}, defaults);
|
|
42
35
|
this.options = {
|
|
43
36
|
..._options,
|
|
@@ -223,8 +216,7 @@ class Strapi {
|
|
|
223
216
|
const params = qs.parse(window.location.search, {
|
|
224
217
|
ignoreQueryPrefix: true
|
|
225
218
|
});
|
|
226
|
-
if (params.access_token)
|
|
227
|
-
access_token = params.access_token;
|
|
219
|
+
if (params.access_token) access_token = params.access_token;
|
|
228
220
|
}
|
|
229
221
|
const { user, jwt } = await this.request(
|
|
230
222
|
"get",
|
|
@@ -309,14 +301,21 @@ class Strapi {
|
|
|
309
301
|
);
|
|
310
302
|
}
|
|
311
303
|
/**
|
|
312
|
-
* Delete
|
|
304
|
+
* Delete an entry
|
|
313
305
|
*
|
|
314
306
|
* @param {string} contentType - Content type's name pluralized
|
|
315
307
|
* @param {string} documentId - documentId of entry to be deleted
|
|
308
|
+
* @param {StrapiDeleteRequestParams} params? - Delete-specific query parameters
|
|
316
309
|
* @returns Promise<void>
|
|
317
310
|
*/
|
|
318
|
-
delete(contentType, documentId) {
|
|
319
|
-
return this.request(
|
|
311
|
+
delete(contentType, documentId, params) {
|
|
312
|
+
return this.request(
|
|
313
|
+
"delete",
|
|
314
|
+
`/${contentType}/${documentId}`,
|
|
315
|
+
{
|
|
316
|
+
params
|
|
317
|
+
}
|
|
318
|
+
);
|
|
320
319
|
}
|
|
321
320
|
/**
|
|
322
321
|
* Refresh local data of the logged-in user
|
|
@@ -341,13 +340,10 @@ class Strapi {
|
|
|
341
340
|
*/
|
|
342
341
|
getToken() {
|
|
343
342
|
const { useLocalStorage, key } = this.options.store;
|
|
344
|
-
if (isBrowser())
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
return token;
|
|
349
|
-
}
|
|
350
|
-
return null;
|
|
343
|
+
if (!isBrowser()) return this._token;
|
|
344
|
+
const token = useLocalStorage ? window.localStorage.getItem(key) : Cookies.get(key);
|
|
345
|
+
if (typeof token === "undefined") return null;
|
|
346
|
+
return token;
|
|
351
347
|
}
|
|
352
348
|
/**
|
|
353
349
|
* Set token in chosen storage
|
|
@@ -357,9 +353,11 @@ class Strapi {
|
|
|
357
353
|
*/
|
|
358
354
|
setToken(token) {
|
|
359
355
|
const { useLocalStorage, key, cookieOptions } = this.options.store;
|
|
360
|
-
if (isBrowser()) {
|
|
361
|
-
|
|
356
|
+
if (!isBrowser()) {
|
|
357
|
+
this._token = token;
|
|
358
|
+
return;
|
|
362
359
|
}
|
|
360
|
+
useLocalStorage ? window.localStorage.setItem(key, token) : Cookies.set(key, token, cookieOptions);
|
|
363
361
|
}
|
|
364
362
|
/**
|
|
365
363
|
* Remove token from chosen storage (Cookies or Local)
|
|
@@ -368,9 +366,11 @@ class Strapi {
|
|
|
368
366
|
*/
|
|
369
367
|
removeToken() {
|
|
370
368
|
const { useLocalStorage, key } = this.options.store;
|
|
371
|
-
if (isBrowser()) {
|
|
372
|
-
|
|
369
|
+
if (!isBrowser()) {
|
|
370
|
+
this._token = null;
|
|
371
|
+
return;
|
|
373
372
|
}
|
|
373
|
+
useLocalStorage ? window.localStorage.removeItem(key) : Cookies.remove(key);
|
|
374
374
|
}
|
|
375
375
|
}
|
|
376
376
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "strapi-sdk-js",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "📦 Javascript SDK for your Strapi API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -28,6 +28,9 @@
|
|
|
28
28
|
"email": "thibautdavid@icloud.com",
|
|
29
29
|
"url": "https://thibautdavid.com"
|
|
30
30
|
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"registry": "https://registry.npmjs.org"
|
|
33
|
+
},
|
|
31
34
|
"maintainers": [
|
|
32
35
|
{
|
|
33
36
|
"name": "Thibaut DAVID",
|
|
@@ -83,29 +86,30 @@
|
|
|
83
86
|
"ufo": "^1.2.0"
|
|
84
87
|
},
|
|
85
88
|
"devDependencies": {
|
|
86
|
-
"@commitlint/cli": "
|
|
87
|
-
"@commitlint/config-conventional": "
|
|
88
|
-
"@release-it/conventional-changelog": "
|
|
89
|
-
"@rollup/plugin-commonjs": "^
|
|
89
|
+
"@commitlint/cli": "21.0.2",
|
|
90
|
+
"@commitlint/config-conventional": "21.0.2",
|
|
91
|
+
"@release-it/conventional-changelog": "11.0.1",
|
|
92
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
90
93
|
"@rollup/plugin-json": "^6.0.0",
|
|
91
|
-
"@rollup/plugin-node-resolve": "^
|
|
94
|
+
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
92
95
|
"@types/jest": "27.5.2",
|
|
93
|
-
"@types/
|
|
96
|
+
"@types/node": "^25.9.1",
|
|
97
|
+
"@types/sinon": "21.0.1",
|
|
94
98
|
"@typescript-eslint/eslint-plugin": "5.62.0",
|
|
95
99
|
"@typescript-eslint/parser": "5.62.0",
|
|
96
100
|
"commitizen": "4.3.1",
|
|
97
101
|
"cz-conventional-changelog": "3.3.0",
|
|
98
|
-
"dotenv-cli": "
|
|
99
|
-
"esbuild": "^0.
|
|
102
|
+
"dotenv-cli": "11.0.0",
|
|
103
|
+
"esbuild": "^0.28.0",
|
|
100
104
|
"eslint": "8.57.1",
|
|
101
|
-
"husky": "
|
|
105
|
+
"husky": "9.1.7",
|
|
102
106
|
"jest": "27.5.1",
|
|
103
|
-
"lint-staged": "
|
|
107
|
+
"lint-staged": "17.0.7",
|
|
104
108
|
"npm-run-all": "4.1.5",
|
|
105
|
-
"release-it": "
|
|
106
|
-
"rollup": "^
|
|
107
|
-
"rollup-plugin-dts": "^
|
|
108
|
-
"rollup-plugin-esbuild": "^
|
|
109
|
+
"release-it": "20.2.0",
|
|
110
|
+
"rollup": "^4.0.0",
|
|
111
|
+
"rollup-plugin-dts": "^6.0.0",
|
|
112
|
+
"rollup-plugin-esbuild": "^6.0.0",
|
|
109
113
|
"sinon": "15.2.0",
|
|
110
114
|
"ts-jest": "27.1.5",
|
|
111
115
|
"typescript": "5.1.6"
|