strapi-sdk-js 3.0.0 → 3.1.0-rc.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 +28 -26
- package/dist/index.d.ts +16 -5
- package/dist/index.mjs +28 -26
- package/package.json +28 -21
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,
|
|
@@ -48,7 +41,9 @@ class Strapi {
|
|
|
48
41
|
};
|
|
49
42
|
this.axios = axios.create({
|
|
50
43
|
baseURL: ufo.joinURL(this.options.url, this.options.prefix),
|
|
51
|
-
paramsSerializer:
|
|
44
|
+
paramsSerializer: {
|
|
45
|
+
serialize: (params) => qs.stringify(params)
|
|
46
|
+
},
|
|
52
47
|
...this.options.axiosOptions
|
|
53
48
|
});
|
|
54
49
|
this.axios.interceptors.request.use((config) => {
|
|
@@ -223,8 +218,7 @@ class Strapi {
|
|
|
223
218
|
const params = qs.parse(window.location.search, {
|
|
224
219
|
ignoreQueryPrefix: true
|
|
225
220
|
});
|
|
226
|
-
if (params.access_token)
|
|
227
|
-
access_token = params.access_token;
|
|
221
|
+
if (params.access_token) access_token = params.access_token;
|
|
228
222
|
}
|
|
229
223
|
const { user, jwt } = await this.request(
|
|
230
224
|
"get",
|
|
@@ -309,14 +303,21 @@ class Strapi {
|
|
|
309
303
|
);
|
|
310
304
|
}
|
|
311
305
|
/**
|
|
312
|
-
* Delete
|
|
306
|
+
* Delete an entry
|
|
313
307
|
*
|
|
314
308
|
* @param {string} contentType - Content type's name pluralized
|
|
315
309
|
* @param {string} documentId - documentId of entry to be deleted
|
|
310
|
+
* @param {StrapiDeleteRequestParams} params? - Delete-specific query parameters
|
|
316
311
|
* @returns Promise<void>
|
|
317
312
|
*/
|
|
318
|
-
delete(contentType, documentId) {
|
|
319
|
-
return this.request(
|
|
313
|
+
delete(contentType, documentId, params) {
|
|
314
|
+
return this.request(
|
|
315
|
+
"delete",
|
|
316
|
+
`/${contentType}/${documentId}`,
|
|
317
|
+
{
|
|
318
|
+
params
|
|
319
|
+
}
|
|
320
|
+
);
|
|
320
321
|
}
|
|
321
322
|
/**
|
|
322
323
|
* Refresh local data of the logged-in user
|
|
@@ -341,13 +342,10 @@ class Strapi {
|
|
|
341
342
|
*/
|
|
342
343
|
getToken() {
|
|
343
344
|
const { useLocalStorage, key } = this.options.store;
|
|
344
|
-
if (isBrowser())
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
return token;
|
|
349
|
-
}
|
|
350
|
-
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;
|
|
351
349
|
}
|
|
352
350
|
/**
|
|
353
351
|
* Set token in chosen storage
|
|
@@ -357,9 +355,11 @@ class Strapi {
|
|
|
357
355
|
*/
|
|
358
356
|
setToken(token) {
|
|
359
357
|
const { useLocalStorage, key, cookieOptions } = this.options.store;
|
|
360
|
-
if (isBrowser()) {
|
|
361
|
-
|
|
358
|
+
if (!isBrowser()) {
|
|
359
|
+
this._token = token;
|
|
360
|
+
return;
|
|
362
361
|
}
|
|
362
|
+
useLocalStorage ? window.localStorage.setItem(key, token) : Cookies.set(key, token, cookieOptions);
|
|
363
363
|
}
|
|
364
364
|
/**
|
|
365
365
|
* Remove token from chosen storage (Cookies or Local)
|
|
@@ -368,9 +368,11 @@ class Strapi {
|
|
|
368
368
|
*/
|
|
369
369
|
removeToken() {
|
|
370
370
|
const { useLocalStorage, key } = this.options.store;
|
|
371
|
-
if (isBrowser()) {
|
|
372
|
-
|
|
371
|
+
if (!isBrowser()) {
|
|
372
|
+
this._token = null;
|
|
373
|
+
return;
|
|
373
374
|
}
|
|
375
|
+
useLocalStorage ? window.localStorage.removeItem(key) : Cookies.remove(key);
|
|
374
376
|
}
|
|
375
377
|
}
|
|
376
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,
|
|
@@ -46,7 +39,9 @@ class Strapi {
|
|
|
46
39
|
};
|
|
47
40
|
this.axios = axios.create({
|
|
48
41
|
baseURL: joinURL(this.options.url, this.options.prefix),
|
|
49
|
-
paramsSerializer:
|
|
42
|
+
paramsSerializer: {
|
|
43
|
+
serialize: (params) => qs.stringify(params)
|
|
44
|
+
},
|
|
50
45
|
...this.options.axiosOptions
|
|
51
46
|
});
|
|
52
47
|
this.axios.interceptors.request.use((config) => {
|
|
@@ -221,8 +216,7 @@ class Strapi {
|
|
|
221
216
|
const params = qs.parse(window.location.search, {
|
|
222
217
|
ignoreQueryPrefix: true
|
|
223
218
|
});
|
|
224
|
-
if (params.access_token)
|
|
225
|
-
access_token = params.access_token;
|
|
219
|
+
if (params.access_token) access_token = params.access_token;
|
|
226
220
|
}
|
|
227
221
|
const { user, jwt } = await this.request(
|
|
228
222
|
"get",
|
|
@@ -307,14 +301,21 @@ class Strapi {
|
|
|
307
301
|
);
|
|
308
302
|
}
|
|
309
303
|
/**
|
|
310
|
-
* Delete
|
|
304
|
+
* Delete an entry
|
|
311
305
|
*
|
|
312
306
|
* @param {string} contentType - Content type's name pluralized
|
|
313
307
|
* @param {string} documentId - documentId of entry to be deleted
|
|
308
|
+
* @param {StrapiDeleteRequestParams} params? - Delete-specific query parameters
|
|
314
309
|
* @returns Promise<void>
|
|
315
310
|
*/
|
|
316
|
-
delete(contentType, documentId) {
|
|
317
|
-
return this.request(
|
|
311
|
+
delete(contentType, documentId, params) {
|
|
312
|
+
return this.request(
|
|
313
|
+
"delete",
|
|
314
|
+
`/${contentType}/${documentId}`,
|
|
315
|
+
{
|
|
316
|
+
params
|
|
317
|
+
}
|
|
318
|
+
);
|
|
318
319
|
}
|
|
319
320
|
/**
|
|
320
321
|
* Refresh local data of the logged-in user
|
|
@@ -339,13 +340,10 @@ class Strapi {
|
|
|
339
340
|
*/
|
|
340
341
|
getToken() {
|
|
341
342
|
const { useLocalStorage, key } = this.options.store;
|
|
342
|
-
if (isBrowser())
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
return token;
|
|
347
|
-
}
|
|
348
|
-
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;
|
|
349
347
|
}
|
|
350
348
|
/**
|
|
351
349
|
* Set token in chosen storage
|
|
@@ -355,9 +353,11 @@ class Strapi {
|
|
|
355
353
|
*/
|
|
356
354
|
setToken(token) {
|
|
357
355
|
const { useLocalStorage, key, cookieOptions } = this.options.store;
|
|
358
|
-
if (isBrowser()) {
|
|
359
|
-
|
|
356
|
+
if (!isBrowser()) {
|
|
357
|
+
this._token = token;
|
|
358
|
+
return;
|
|
360
359
|
}
|
|
360
|
+
useLocalStorage ? window.localStorage.setItem(key, token) : Cookies.set(key, token, cookieOptions);
|
|
361
361
|
}
|
|
362
362
|
/**
|
|
363
363
|
* Remove token from chosen storage (Cookies or Local)
|
|
@@ -366,9 +366,11 @@ class Strapi {
|
|
|
366
366
|
*/
|
|
367
367
|
removeToken() {
|
|
368
368
|
const { useLocalStorage, key } = this.options.store;
|
|
369
|
-
if (isBrowser()) {
|
|
370
|
-
|
|
369
|
+
if (!isBrowser()) {
|
|
370
|
+
this._token = null;
|
|
371
|
+
return;
|
|
371
372
|
}
|
|
373
|
+
useLocalStorage ? window.localStorage.removeItem(key) : Cookies.remove(key);
|
|
372
374
|
}
|
|
373
375
|
}
|
|
374
376
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "strapi-sdk-js",
|
|
3
|
-
"version": "3.0.0",
|
|
3
|
+
"version": "3.1.0-rc.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",
|
|
@@ -49,6 +52,9 @@
|
|
|
49
52
|
"files": [
|
|
50
53
|
"dist/"
|
|
51
54
|
],
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=20"
|
|
57
|
+
},
|
|
52
58
|
"scripts": {
|
|
53
59
|
"start": "rollup -c --watch",
|
|
54
60
|
"build": "rm -rf dist && rollup -c",
|
|
@@ -73,36 +79,37 @@
|
|
|
73
79
|
"dependencies": {
|
|
74
80
|
"@types/js-cookie": "^3.0.0",
|
|
75
81
|
"@types/qs": "^6.9.6",
|
|
76
|
-
"axios": "^0.
|
|
77
|
-
"defu": "^
|
|
78
|
-
"js-cookie": "^3.0.
|
|
79
|
-
"qs": "^6.
|
|
82
|
+
"axios": "^0.32.0",
|
|
83
|
+
"defu": "^6.1.5",
|
|
84
|
+
"js-cookie": "^3.0.7",
|
|
85
|
+
"qs": "^6.15.2",
|
|
80
86
|
"ufo": "^1.2.0"
|
|
81
87
|
},
|
|
82
88
|
"devDependencies": {
|
|
83
|
-
"@commitlint/cli": "
|
|
84
|
-
"@commitlint/config-conventional": "
|
|
85
|
-
"@release-it/conventional-changelog": "
|
|
86
|
-
"@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",
|
|
87
93
|
"@rollup/plugin-json": "^6.0.0",
|
|
88
|
-
"@rollup/plugin-node-resolve": "^
|
|
94
|
+
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
89
95
|
"@types/jest": "27.5.2",
|
|
90
|
-
"@types/
|
|
96
|
+
"@types/node": "^25.9.1",
|
|
97
|
+
"@types/sinon": "21.0.1",
|
|
91
98
|
"@typescript-eslint/eslint-plugin": "5.62.0",
|
|
92
99
|
"@typescript-eslint/parser": "5.62.0",
|
|
93
|
-
"commitizen": "4.3.
|
|
100
|
+
"commitizen": "4.3.1",
|
|
94
101
|
"cz-conventional-changelog": "3.3.0",
|
|
95
|
-
"dotenv-cli": "
|
|
96
|
-
"esbuild": "^0.
|
|
97
|
-
"eslint": "8.
|
|
98
|
-
"husky": "
|
|
102
|
+
"dotenv-cli": "11.0.0",
|
|
103
|
+
"esbuild": "^0.28.0",
|
|
104
|
+
"eslint": "8.57.1",
|
|
105
|
+
"husky": "9.1.7",
|
|
99
106
|
"jest": "27.5.1",
|
|
100
|
-
"lint-staged": "
|
|
107
|
+
"lint-staged": "17.0.7",
|
|
101
108
|
"npm-run-all": "4.1.5",
|
|
102
|
-
"release-it": "
|
|
103
|
-
"rollup": "^
|
|
104
|
-
"rollup-plugin-dts": "^
|
|
105
|
-
"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",
|
|
106
113
|
"sinon": "15.2.0",
|
|
107
114
|
"ts-jest": "27.1.5",
|
|
108
115
|
"typescript": "5.1.6"
|