strapi-sdk-js 2.3.5 → 2.4.1
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 -15
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +18 -15
- package/package.json +3 -3
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,
|
|
@@ -54,12 +55,11 @@ class Strapi {
|
|
|
54
55
|
...this.options.axiosOptions
|
|
55
56
|
});
|
|
56
57
|
this.axios.interceptors.request.use((config) => {
|
|
58
|
+
var _a;
|
|
57
59
|
const token = this.getToken();
|
|
58
60
|
if (token) {
|
|
59
|
-
config.headers = {
|
|
60
|
-
|
|
61
|
-
Authorization: `Bearer ${token}`
|
|
62
|
-
};
|
|
61
|
+
(_a = config.headers) != null ? _a : config.headers = {};
|
|
62
|
+
config.headers.Authorization = `Bearer ${token}`;
|
|
63
63
|
}
|
|
64
64
|
return config;
|
|
65
65
|
});
|
|
@@ -338,13 +338,12 @@ class Strapi {
|
|
|
338
338
|
*/
|
|
339
339
|
getToken() {
|
|
340
340
|
const { useLocalStorage, key } = this.options.store;
|
|
341
|
-
if (isBrowser())
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
return
|
|
346
|
-
|
|
347
|
-
return null;
|
|
341
|
+
if (!isBrowser())
|
|
342
|
+
return this._token;
|
|
343
|
+
const token = useLocalStorage ? window.localStorage.getItem(key) : Cookies.get(key);
|
|
344
|
+
if (typeof token === "undefined")
|
|
345
|
+
return null;
|
|
346
|
+
return token;
|
|
348
347
|
}
|
|
349
348
|
/**
|
|
350
349
|
* Set token in chosen storage
|
|
@@ -354,9 +353,11 @@ class Strapi {
|
|
|
354
353
|
*/
|
|
355
354
|
setToken(token) {
|
|
356
355
|
const { useLocalStorage, key, cookieOptions } = this.options.store;
|
|
357
|
-
if (isBrowser()) {
|
|
358
|
-
|
|
356
|
+
if (!isBrowser()) {
|
|
357
|
+
this._token = token;
|
|
358
|
+
return;
|
|
359
359
|
}
|
|
360
|
+
useLocalStorage ? window.localStorage.setItem(key, token) : Cookies.set(key, token, cookieOptions);
|
|
360
361
|
}
|
|
361
362
|
/**
|
|
362
363
|
* Remove token from chosen storage (Cookies or Local)
|
|
@@ -365,9 +366,11 @@ class Strapi {
|
|
|
365
366
|
*/
|
|
366
367
|
removeToken() {
|
|
367
368
|
const { useLocalStorage, key } = this.options.store;
|
|
368
|
-
if (isBrowser()) {
|
|
369
|
-
|
|
369
|
+
if (!isBrowser()) {
|
|
370
|
+
this._token = null;
|
|
371
|
+
return;
|
|
370
372
|
}
|
|
373
|
+
useLocalStorage ? window.localStorage.removeItem(key) : Cookies.remove(key);
|
|
371
374
|
}
|
|
372
375
|
}
|
|
373
376
|
|
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,
|
|
@@ -52,12 +53,11 @@ class Strapi {
|
|
|
52
53
|
...this.options.axiosOptions
|
|
53
54
|
});
|
|
54
55
|
this.axios.interceptors.request.use((config) => {
|
|
56
|
+
var _a;
|
|
55
57
|
const token = this.getToken();
|
|
56
58
|
if (token) {
|
|
57
|
-
config.headers = {
|
|
58
|
-
|
|
59
|
-
Authorization: `Bearer ${token}`
|
|
60
|
-
};
|
|
59
|
+
(_a = config.headers) != null ? _a : config.headers = {};
|
|
60
|
+
config.headers.Authorization = `Bearer ${token}`;
|
|
61
61
|
}
|
|
62
62
|
return config;
|
|
63
63
|
});
|
|
@@ -336,13 +336,12 @@ class Strapi {
|
|
|
336
336
|
*/
|
|
337
337
|
getToken() {
|
|
338
338
|
const { useLocalStorage, key } = this.options.store;
|
|
339
|
-
if (isBrowser())
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
return
|
|
344
|
-
|
|
345
|
-
return null;
|
|
339
|
+
if (!isBrowser())
|
|
340
|
+
return this._token;
|
|
341
|
+
const token = useLocalStorage ? window.localStorage.getItem(key) : Cookies.get(key);
|
|
342
|
+
if (typeof token === "undefined")
|
|
343
|
+
return null;
|
|
344
|
+
return token;
|
|
346
345
|
}
|
|
347
346
|
/**
|
|
348
347
|
* Set token in chosen storage
|
|
@@ -352,9 +351,11 @@ class Strapi {
|
|
|
352
351
|
*/
|
|
353
352
|
setToken(token) {
|
|
354
353
|
const { useLocalStorage, key, cookieOptions } = this.options.store;
|
|
355
|
-
if (isBrowser()) {
|
|
356
|
-
|
|
354
|
+
if (!isBrowser()) {
|
|
355
|
+
this._token = token;
|
|
356
|
+
return;
|
|
357
357
|
}
|
|
358
|
+
useLocalStorage ? window.localStorage.setItem(key, token) : Cookies.set(key, token, cookieOptions);
|
|
358
359
|
}
|
|
359
360
|
/**
|
|
360
361
|
* Remove token from chosen storage (Cookies or Local)
|
|
@@ -363,9 +364,11 @@ class Strapi {
|
|
|
363
364
|
*/
|
|
364
365
|
removeToken() {
|
|
365
366
|
const { useLocalStorage, key } = this.options.store;
|
|
366
|
-
if (isBrowser()) {
|
|
367
|
-
|
|
367
|
+
if (!isBrowser()) {
|
|
368
|
+
this._token = null;
|
|
369
|
+
return;
|
|
368
370
|
}
|
|
371
|
+
useLocalStorage ? window.localStorage.removeItem(key) : Cookies.remove(key);
|
|
369
372
|
}
|
|
370
373
|
}
|
|
371
374
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "strapi-sdk-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "📦 Javascript SDK for your Strapi API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -79,10 +79,10 @@
|
|
|
79
79
|
"dependencies": {
|
|
80
80
|
"@types/js-cookie": "^3.0.0",
|
|
81
81
|
"@types/qs": "^6.9.6",
|
|
82
|
-
"axios": "^0.
|
|
82
|
+
"axios": "^0.36.0",
|
|
83
83
|
"defu": "^6.1.5",
|
|
84
84
|
"js-cookie": "^3.0.7",
|
|
85
|
-
"qs": "^6.
|
|
85
|
+
"qs": "^6.17.1",
|
|
86
86
|
"ufo": "^1.2.0"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|