@djust-b2b/djust-front-sdk 1.7.0 → 1.7.2

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
+ }
package/lib/index.d.ts CHANGED
@@ -86,6 +86,7 @@ export declare const DjustSDK: {
86
86
  getNavigationCategories({ locale, }: import("./interfaces").GetNavigationCategoriesParameters): Promise<import("./interfaces").GetNavigationCategoriesResponse>;
87
87
  getNavigationCategory({ locale, idType, navigationCategoryId, }: import("./interfaces").GetNavigationCategoryParameters): Promise<import("./interfaces").GetNavigationCategoryResponse>;
88
88
  getNavigationCategoryBreadcrumbs({ locale, idType, navigationCategoryId, }: import("./interfaces").GetNavigationCategoryBreadcrumbsParameters): Promise<import("./interfaces").GetNavigationCategoryBreadcrumbsResponse>;
89
+ getAuthenticatedUser(): Promise<any>;
89
90
  createCustomerUser({ activationUrl, civility, customFieldValues, email, externalId, firstName, lastName, password, groups, status, mainOrganisationId, organisations, phone, }: import("./interfaces").CreateCustomerUserParameters): Promise<import("./interfaces").CreateCustomerUserResponse>;
90
91
  updateCustomerUser({ civility, firstName, lastName, phone, customFieldValues, }: import("./interfaces").UpdateCustomerUserParameters): Promise<import("./interfaces").UpdateCustomerUserResponse>;
91
92
  activateCustomerUser({ token, }: import("./interfaces").ActivateCustomerUserParameters): Promise<void>;
@@ -1,4 +1,8 @@
1
1
  import { ActivateCustomerUserParameters, CreateCustomerUserParameters, CreateCustomerUserResponse, GetCustomerUserAddressesParameters, GetCustomerUserOrganisationsResponse, SendCustomerUserActivationRequestParameters, UpdateCustomerUserParameters, UpdateCustomerUserResponse } from "./definitions";
2
+ /**
3
+ * Get authenticated user
4
+ */
5
+ export declare function getAuthenticatedUser(): Promise<any>;
2
6
  /**
3
7
  * Create a customer user
4
8
  */
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAuthenticatedUser = getAuthenticatedUser;
3
4
  exports.createCustomerUser = createCustomerUser;
4
5
  exports.updateCustomerUser = updateCustomerUser;
5
6
  exports.activateCustomerUser = activateCustomerUser;
@@ -8,6 +9,16 @@ exports.getCustomerUserOrganisations = getCustomerUserOrganisations;
8
9
  exports.sendCustomerUserActivationRequest = sendCustomerUserActivationRequest;
9
10
  const parameters_validation_1 = require("../../helpers/parameters-validation");
10
11
  const fetch_instance_1 = require("../../settings/fetch-instance");
12
+ /**
13
+ * Get authenticated user
14
+ */
15
+ async function getAuthenticatedUser() {
16
+ const { data } = await (0, fetch_instance_1.enhancedFetch)({
17
+ method: "GET",
18
+ path: `/v1/authenticated-user`,
19
+ });
20
+ return data;
21
+ }
11
22
  /**
12
23
  * Create a customer user
13
24
  */
@@ -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) => {
@@ -89,6 +90,12 @@ const enhancedFetch = async ({ path, method, params, body, }) => {
89
90
  const errorMessage = await response.text();
90
91
  throw new Error(`[Djust SDK] HTTP error ${status}: ${errorMessage}`);
91
92
  }
93
+ if ((0, utils_1.isBrowser)()) {
94
+ const token = (0, utils_1.getCookie)("token");
95
+ if (token) {
96
+ requestHeaders.append("Authorization", `Bearer ${token}`);
97
+ }
98
+ }
92
99
  const isJsonResponse = (_a = headers
93
100
  .get("content-type")) === null || _a === void 0 ? void 0 : _a.includes("application/json");
94
101
  // Additional check: ensure the response has content before attempting to parse JSON
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@djust-b2b/djust-front-sdk",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
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",