@djust-b2b/djust-front-sdk 1.7.1 → 1.7.3

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.
@@ -0,0 +1,4 @@
1
+ export declare function isBrowser(): boolean;
2
+ export declare function getCookie(name: string): string | null;
3
+ export declare function setCookie(name: string, value: string, expirationDays: number): void;
4
+ export declare function deleteCookie(name: string): void;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isBrowser = isBrowser;
4
+ exports.getCookie = getCookie;
5
+ exports.setCookie = setCookie;
6
+ exports.deleteCookie = deleteCookie;
7
+ function isBrowser() {
8
+ return typeof window !== "undefined";
9
+ }
10
+ function getCookie(name) {
11
+ if (!isBrowser())
12
+ return null;
13
+ const cookies = document.cookie.split(";").map((cookie) => cookie.trim());
14
+ const cookie = cookies.find((cookie) => cookie.startsWith(`${name}=`));
15
+ return cookie ? cookie.split("=")[1] : null;
16
+ }
17
+ function setCookie(name, value, expirationDays) {
18
+ if (!isBrowser())
19
+ return;
20
+ const date = new Date();
21
+ date.setTime(date.getTime() + expirationDays * 24 * 60 * 60 * 1000);
22
+ const expires = `expires=${date.toUTCString()}`;
23
+ document.cookie = `${name}=${value};${expires};path=/`;
24
+ }
25
+ function deleteCookie(name) {
26
+ if (!isBrowser())
27
+ return;
28
+ document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 UTC;path=/;`;
29
+ }
@@ -25,6 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.enhancedFetch = exports.updateConfiguration = exports.initialize = void 0;
27
27
  const qs = __importStar(require("query-string"));
28
+ const utils_1 = require("../helpers/utils");
28
29
  require("isomorphic-fetch");
29
30
  let clientConfig = { baseUrl: "", clientId: "", apiKey: "" };
30
31
  const initialize = (initConfig) => {
@@ -61,6 +62,12 @@ const enhancedFetch = async ({ path, method, params, body, }) => {
61
62
  "dj-api-key": apiKey,
62
63
  "Content-Type": "application/json",
63
64
  });
65
+ if ((0, utils_1.isBrowser)()) {
66
+ const token = (0, utils_1.getCookie)("token");
67
+ if (token) {
68
+ requestHeaders.append("Authorization", `Bearer ${token}`);
69
+ }
70
+ }
64
71
  if (accessToken)
65
72
  requestHeaders.append("Authorization", `Bearer ${accessToken}`);
66
73
  if (locale)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@djust-b2b/djust-front-sdk",
3
- "version": "1.7.1",
3
+ "version": "1.7.3",
4
4
  "description": "DJUST Front SDK is a versatile JavaScript Software Development Kit (SDK) ",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",