strapi-sdk-js 2.3.5 → 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 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,
@@ -338,13 +339,12 @@ class Strapi {
338
339
  */
339
340
  getToken() {
340
341
  const { useLocalStorage, key } = this.options.store;
341
- if (isBrowser()) {
342
- const token = useLocalStorage ? window.localStorage.getItem(key) : Cookies.get(key);
343
- if (typeof token === "undefined")
344
- return null;
345
- return token;
346
- }
347
- 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;
348
348
  }
349
349
  /**
350
350
  * Set token in chosen storage
@@ -354,9 +354,11 @@ class Strapi {
354
354
  */
355
355
  setToken(token) {
356
356
  const { useLocalStorage, key, cookieOptions } = this.options.store;
357
- if (isBrowser()) {
358
- useLocalStorage ? window.localStorage.setItem(key, token) : Cookies.set(key, token, cookieOptions);
357
+ if (!isBrowser()) {
358
+ this._token = token;
359
+ return;
359
360
  }
361
+ useLocalStorage ? window.localStorage.setItem(key, token) : Cookies.set(key, token, cookieOptions);
360
362
  }
361
363
  /**
362
364
  * Remove token from chosen storage (Cookies or Local)
@@ -365,9 +367,11 @@ class Strapi {
365
367
  */
366
368
  removeToken() {
367
369
  const { useLocalStorage, key } = this.options.store;
368
- if (isBrowser()) {
369
- useLocalStorage ? window.localStorage.removeItem(key) : Cookies.remove(key);
370
+ if (!isBrowser()) {
371
+ this._token = null;
372
+ return;
370
373
  }
374
+ useLocalStorage ? window.localStorage.removeItem(key) : Cookies.remove(key);
371
375
  }
372
376
  }
373
377
 
package/dist/index.d.ts CHANGED
@@ -90,6 +90,7 @@ declare class Strapi {
90
90
  axios: AxiosInstance;
91
91
  options: StrapiDefaultOptions;
92
92
  user: StrapiUser;
93
+ private _token;
93
94
  /**
94
95
  * Strapi SDK Constructor
95
96
  *
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,
@@ -336,13 +337,12 @@ class Strapi {
336
337
  */
337
338
  getToken() {
338
339
  const { useLocalStorage, key } = this.options.store;
339
- if (isBrowser()) {
340
- const token = useLocalStorage ? window.localStorage.getItem(key) : Cookies.get(key);
341
- if (typeof token === "undefined")
342
- return null;
343
- return token;
344
- }
345
- 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;
346
346
  }
347
347
  /**
348
348
  * Set token in chosen storage
@@ -352,9 +352,11 @@ class Strapi {
352
352
  */
353
353
  setToken(token) {
354
354
  const { useLocalStorage, key, cookieOptions } = this.options.store;
355
- if (isBrowser()) {
356
- useLocalStorage ? window.localStorage.setItem(key, token) : Cookies.set(key, token, cookieOptions);
355
+ if (!isBrowser()) {
356
+ this._token = token;
357
+ return;
357
358
  }
359
+ useLocalStorage ? window.localStorage.setItem(key, token) : Cookies.set(key, token, cookieOptions);
358
360
  }
359
361
  /**
360
362
  * Remove token from chosen storage (Cookies or Local)
@@ -363,9 +365,11 @@ class Strapi {
363
365
  */
364
366
  removeToken() {
365
367
  const { useLocalStorage, key } = this.options.store;
366
- if (isBrowser()) {
367
- useLocalStorage ? window.localStorage.removeItem(key) : Cookies.remove(key);
368
+ if (!isBrowser()) {
369
+ this._token = null;
370
+ return;
368
371
  }
372
+ useLocalStorage ? window.localStorage.removeItem(key) : Cookies.remove(key);
369
373
  }
370
374
  }
371
375
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strapi-sdk-js",
3
- "version": "2.3.5",
3
+ "version": "2.4.0",
4
4
  "description": "📦 Javascript SDK for your Strapi API",
5
5
  "keywords": [
6
6
  "strapi",