strapi-sdk-js 2.3.4 → 2.4.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 +18 -12
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +18 -12
- package/package.json +11 -5
package/dist/index.cjs
CHANGED
|
@@ -40,6 +40,7 @@ class Strapi {
|
|
|
40
40
|
__publicField(this, "axios");
|
|
41
41
|
__publicField(this, "options");
|
|
42
42
|
__publicField(this, "user", null);
|
|
43
|
+
__publicField(this, "_token", null);
|
|
43
44
|
const _options = defu(options || {}, defaults);
|
|
44
45
|
this.options = {
|
|
45
46
|
..._options,
|
|
@@ -48,7 +49,9 @@ class Strapi {
|
|
|
48
49
|
};
|
|
49
50
|
this.axios = axios.create({
|
|
50
51
|
baseURL: ufo.joinURL(this.options.url, this.options.prefix),
|
|
51
|
-
paramsSerializer:
|
|
52
|
+
paramsSerializer: {
|
|
53
|
+
serialize: (params) => qs.stringify(params)
|
|
54
|
+
},
|
|
52
55
|
...this.options.axiosOptions
|
|
53
56
|
});
|
|
54
57
|
this.axios.interceptors.request.use((config) => {
|
|
@@ -336,13 +339,12 @@ class Strapi {
|
|
|
336
339
|
*/
|
|
337
340
|
getToken() {
|
|
338
341
|
const { useLocalStorage, key } = this.options.store;
|
|
339
|
-
if (isBrowser())
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
return
|
|
344
|
-
|
|
345
|
-
return null;
|
|
342
|
+
if (!isBrowser())
|
|
343
|
+
return this._token;
|
|
344
|
+
const token = useLocalStorage ? window.localStorage.getItem(key) : Cookies.get(key);
|
|
345
|
+
if (typeof token === "undefined")
|
|
346
|
+
return null;
|
|
347
|
+
return token;
|
|
346
348
|
}
|
|
347
349
|
/**
|
|
348
350
|
* Set token in chosen storage
|
|
@@ -352,9 +354,11 @@ class Strapi {
|
|
|
352
354
|
*/
|
|
353
355
|
setToken(token) {
|
|
354
356
|
const { useLocalStorage, key, cookieOptions } = this.options.store;
|
|
355
|
-
if (isBrowser()) {
|
|
356
|
-
|
|
357
|
+
if (!isBrowser()) {
|
|
358
|
+
this._token = token;
|
|
359
|
+
return;
|
|
357
360
|
}
|
|
361
|
+
useLocalStorage ? window.localStorage.setItem(key, token) : Cookies.set(key, token, cookieOptions);
|
|
358
362
|
}
|
|
359
363
|
/**
|
|
360
364
|
* Remove token from chosen storage (Cookies or Local)
|
|
@@ -363,9 +367,11 @@ class Strapi {
|
|
|
363
367
|
*/
|
|
364
368
|
removeToken() {
|
|
365
369
|
const { useLocalStorage, key } = this.options.store;
|
|
366
|
-
if (isBrowser()) {
|
|
367
|
-
|
|
370
|
+
if (!isBrowser()) {
|
|
371
|
+
this._token = null;
|
|
372
|
+
return;
|
|
368
373
|
}
|
|
374
|
+
useLocalStorage ? window.localStorage.removeItem(key) : Cookies.remove(key);
|
|
369
375
|
}
|
|
370
376
|
}
|
|
371
377
|
|
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -38,6 +38,7 @@ class Strapi {
|
|
|
38
38
|
__publicField(this, "axios");
|
|
39
39
|
__publicField(this, "options");
|
|
40
40
|
__publicField(this, "user", null);
|
|
41
|
+
__publicField(this, "_token", null);
|
|
41
42
|
const _options = defu(options || {}, defaults);
|
|
42
43
|
this.options = {
|
|
43
44
|
..._options,
|
|
@@ -46,7 +47,9 @@ class Strapi {
|
|
|
46
47
|
};
|
|
47
48
|
this.axios = axios.create({
|
|
48
49
|
baseURL: joinURL(this.options.url, this.options.prefix),
|
|
49
|
-
paramsSerializer:
|
|
50
|
+
paramsSerializer: {
|
|
51
|
+
serialize: (params) => qs.stringify(params)
|
|
52
|
+
},
|
|
50
53
|
...this.options.axiosOptions
|
|
51
54
|
});
|
|
52
55
|
this.axios.interceptors.request.use((config) => {
|
|
@@ -334,13 +337,12 @@ class Strapi {
|
|
|
334
337
|
*/
|
|
335
338
|
getToken() {
|
|
336
339
|
const { useLocalStorage, key } = this.options.store;
|
|
337
|
-
if (isBrowser())
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
return
|
|
342
|
-
|
|
343
|
-
return null;
|
|
340
|
+
if (!isBrowser())
|
|
341
|
+
return this._token;
|
|
342
|
+
const token = useLocalStorage ? window.localStorage.getItem(key) : Cookies.get(key);
|
|
343
|
+
if (typeof token === "undefined")
|
|
344
|
+
return null;
|
|
345
|
+
return token;
|
|
344
346
|
}
|
|
345
347
|
/**
|
|
346
348
|
* Set token in chosen storage
|
|
@@ -350,9 +352,11 @@ class Strapi {
|
|
|
350
352
|
*/
|
|
351
353
|
setToken(token) {
|
|
352
354
|
const { useLocalStorage, key, cookieOptions } = this.options.store;
|
|
353
|
-
if (isBrowser()) {
|
|
354
|
-
|
|
355
|
+
if (!isBrowser()) {
|
|
356
|
+
this._token = token;
|
|
357
|
+
return;
|
|
355
358
|
}
|
|
359
|
+
useLocalStorage ? window.localStorage.setItem(key, token) : Cookies.set(key, token, cookieOptions);
|
|
356
360
|
}
|
|
357
361
|
/**
|
|
358
362
|
* Remove token from chosen storage (Cookies or Local)
|
|
@@ -361,9 +365,11 @@ class Strapi {
|
|
|
361
365
|
*/
|
|
362
366
|
removeToken() {
|
|
363
367
|
const { useLocalStorage, key } = this.options.store;
|
|
364
|
-
if (isBrowser()) {
|
|
365
|
-
|
|
368
|
+
if (!isBrowser()) {
|
|
369
|
+
this._token = null;
|
|
370
|
+
return;
|
|
366
371
|
}
|
|
372
|
+
useLocalStorage ? window.localStorage.removeItem(key) : Cookies.remove(key);
|
|
367
373
|
}
|
|
368
374
|
}
|
|
369
375
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "strapi-sdk-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "📦 Javascript SDK for your Strapi API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -49,6 +49,9 @@
|
|
|
49
49
|
"files": [
|
|
50
50
|
"dist/"
|
|
51
51
|
],
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=16"
|
|
54
|
+
},
|
|
52
55
|
"scripts": {
|
|
53
56
|
"start": "rollup -c --watch",
|
|
54
57
|
"build": "rm -rf dist && rollup -c",
|
|
@@ -70,13 +73,16 @@
|
|
|
70
73
|
"path": "./node_modules/cz-conventional-changelog"
|
|
71
74
|
}
|
|
72
75
|
},
|
|
76
|
+
"publishConfig": {
|
|
77
|
+
"registry": "https://registry.npmjs.org"
|
|
78
|
+
},
|
|
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": {
|