@djust-b2b/djust-front-sdk 1.21.2 → 1.22.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/lib/index.d.ts CHANGED
@@ -10,6 +10,9 @@ export declare const DjustSDK: {
10
10
  storeId?: string;
11
11
  storeViewId?: string;
12
12
  customerAccountId?: string;
13
+ clientName?: string;
14
+ dsn?: string;
15
+ env?: string;
13
16
  }) => void;
14
17
  updateConfiguration: (newConfig: Partial<{
15
18
  baseUrl: string;
@@ -22,6 +25,9 @@ export declare const DjustSDK: {
22
25
  storeId?: string;
23
26
  storeViewId?: string;
24
27
  customerAccountId?: string;
28
+ clientName?: string;
29
+ dsn?: string;
30
+ env?: string;
25
31
  }>) => void;
26
32
  getIncidents({ customerAccountIds, linkedType, ids, status, idType, page, size, sort, }: import("./services/incident/definitions").getIncidentsParameters): Promise<import("./services/incident/definitions").getIncidentsResponse>;
27
33
  getIncident({ incidentId, idType, }: import("./services/incident/definitions").getIncidentParameters): Promise<import("./services/incident/definitions").getIncidentResponse>;
@@ -6,13 +6,13 @@ import { CreateObjectCustomerAccountRequest, CustomerAccountDto, LegalUserDto }
6
6
  import { CustomerOrganisationDto, CustomerOrganisationStatus } from "../../interfaces/models/customer-organisation";
7
7
  import { CivilityType, CreateCustomerUserRequest, PageCustomerUser, PageCustomerUserDto } from "../../interfaces/models/customer-user";
8
8
  export interface CreateCustomerAccountParameters {
9
- createAddressRequests: CreateAddressRequest[];
10
- createCustomerUserRequest: CreateCustomerUserRequest;
11
- createObjectCustomerAccountRequest: CreateObjectCustomerAccountRequest;
12
- customFieldValues: CustomFieldValueRequest[];
13
- customerTagList: string[];
14
- fromFO: boolean;
15
- legalUser: LegalUserDto;
9
+ createAddressRequests?: CreateAddressRequest[];
10
+ createCustomerUserRequest?: CreateCustomerUserRequest;
11
+ createObjectCustomerAccountRequest?: CreateObjectCustomerAccountRequest;
12
+ customFieldValues?: CustomFieldValueRequest[];
13
+ customerTagList?: string[];
14
+ fromFO?: boolean;
15
+ legalUser?: LegalUserDto;
16
16
  }
17
17
  export interface UpdateCustomerAccountParameters {
18
18
  organisationId: string;
@@ -411,10 +411,16 @@ async function updateCustomerAccountAddress({ addressId, additionalAddress, addr
411
411
  * @returns {Promise<GetCustomerAccountOrdersResponse>} - The response containing the customer account orders.
412
412
  */
413
413
  async function getCustomerAccountOrders(params) {
414
+ var _a, _b, _c;
414
415
  const { data } = await (0, fetch_instance_1.enhancedFetch)({
415
416
  method: "GET",
416
417
  path: `/v1/shop/customer-accounts/orders`,
417
- params,
418
+ params: {
419
+ page: (_a = params.pageable) === null || _a === void 0 ? void 0 : _a.page,
420
+ size: (_b = params.pageable) === null || _b === void 0 ? void 0 : _b.size,
421
+ sort: (_c = params.pageable) === null || _c === void 0 ? void 0 : _c.sort,
422
+ locale: params.locale,
423
+ },
418
424
  });
419
425
  return data;
420
426
  }
@@ -444,11 +450,16 @@ async function getCustomerAccountOrders(params) {
444
450
  * ```
445
451
  */
446
452
  async function getCustomerAccountUsers(params) {
453
+ var _a, _b, _c;
447
454
  (0, parameters_validation_1.required)({ pageable: params.pageable });
448
455
  const { data } = await (0, fetch_instance_1.enhancedFetch)({
449
456
  method: "GET",
450
457
  path: `/v1/shop/customer-accounts/users`,
451
- params,
458
+ params: {
459
+ page: (_a = params.pageable) === null || _a === void 0 ? void 0 : _a.page,
460
+ size: (_b = params.pageable) === null || _b === void 0 ? void 0 : _b.size,
461
+ sort: (_c = params.pageable) === null || _c === void 0 ? void 0 : _c.sort,
462
+ },
452
463
  });
453
464
  return data;
454
465
  }
@@ -719,6 +730,7 @@ async function updateCustomerAccountOrganisationAddress(params) {
719
730
  * ```
720
731
  */
721
732
  async function getCustomerAccountOrganisationOrders(params) {
733
+ var _a, _b, _c;
722
734
  (0, parameters_validation_1.required)({
723
735
  organisationId: params.organisationId,
724
736
  pageable: params.pageable,
@@ -727,7 +739,12 @@ async function getCustomerAccountOrganisationOrders(params) {
727
739
  const { data } = await (0, fetch_instance_1.enhancedFetch)({
728
740
  method: "GET",
729
741
  path: `/v1/shop/customer-accounts/organisations/${params.organisationId}/orders`,
730
- params,
742
+ params: {
743
+ page: (_a = params.pageable) === null || _a === void 0 ? void 0 : _a.page,
744
+ size: (_b = params.pageable) === null || _b === void 0 ? void 0 : _b.size,
745
+ sort: (_c = params.pageable) === null || _c === void 0 ? void 0 : _c.sort,
746
+ locale: params.locale,
747
+ },
731
748
  });
732
749
  return data;
733
750
  }
@@ -759,6 +776,7 @@ async function getCustomerAccountOrganisationOrders(params) {
759
776
  * ```
760
777
  */
761
778
  async function getCustomerAccountOrganisationUsers(params) {
779
+ var _a, _b, _c;
762
780
  (0, parameters_validation_1.required)({
763
781
  organisationId: params.organisationId,
764
782
  pageable: params.pageable,
@@ -766,7 +784,11 @@ async function getCustomerAccountOrganisationUsers(params) {
766
784
  const { data } = await (0, fetch_instance_1.enhancedFetch)({
767
785
  method: "GET",
768
786
  path: `/v1/shop/customer-accounts/organisations/${params.organisationId}/users`,
769
- params,
787
+ params: {
788
+ page: (_a = params.pageable) === null || _a === void 0 ? void 0 : _a.page,
789
+ size: (_b = params.pageable) === null || _b === void 0 ? void 0 : _b.size,
790
+ sort: (_c = params.pageable) === null || _c === void 0 ? void 0 : _c.sort,
791
+ },
770
792
  });
771
793
  return data;
772
794
  }
@@ -10,6 +10,9 @@ type ClientConfig = {
10
10
  storeId?: string;
11
11
  storeViewId?: string;
12
12
  customerAccountId?: string;
13
+ clientName?: string;
14
+ dsn?: string;
15
+ env?: string;
13
16
  };
14
17
  export declare const initialize: (initConfig: ClientConfig) => void;
15
18
  export declare const updateConfiguration: (newConfig: Partial<ClientConfig>) => void;
@@ -35,12 +35,34 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.enhancedFetch = exports.updateConfiguration = exports.initialize = void 0;
37
37
  const qs = __importStar(require("query-string"));
38
+ const Sentry = __importStar(require("@sentry/node"));
39
+ const profiling_node_1 = require("@sentry/profiling-node");
38
40
  require("isomorphic-fetch");
39
- let clientConfig = { baseUrl: "", clientId: "", apiKey: "" };
41
+ const SDK_VERSION = require("../package.json").version;
42
+ let clientConfig = {
43
+ baseUrl: "",
44
+ clientId: "",
45
+ apiKey: "",
46
+ dsn: "https://39ef5198e24fa0ec7b743c460bd1ca63@o1191347.ingest.us.sentry.io/4508879498575872",
47
+ };
48
+ let isSentryInitialized = false;
40
49
  const initialize = (initConfig) => {
41
50
  clientConfig = {
42
51
  ...initConfig,
43
52
  };
53
+ // ✅ Auto-initialisation de Sentry si `clientName` et `env` sont définis
54
+ if (!isSentryInitialized && clientConfig.clientName && clientConfig.env) {
55
+ Sentry.init({
56
+ dsn: clientConfig.dsn,
57
+ environment: `${clientConfig.clientName}-${clientConfig.env}`,
58
+ release: `${clientConfig.clientName}-${clientConfig.env}-${SDK_VERSION}`,
59
+ tracesSampleRate: 1.0,
60
+ profilesSampleRate: 1.0,
61
+ integrations: [(0, profiling_node_1.nodeProfilingIntegration)()],
62
+ });
63
+ isSentryInitialized = true;
64
+ console.log(`[Djust SDK] Sentry activé pour ${clientConfig.clientName}-${clientConfig.env}-${SDK_VERSION}`);
65
+ }
44
66
  };
45
67
  exports.initialize = initialize;
46
68
  const updateConfiguration = (newConfig) => {
@@ -86,7 +108,9 @@ const isPublicRoute = (path, method) => {
86
108
  const enhancedFetch = async ({ path, method, params = {}, body, }) => {
87
109
  var _a, _b, _c, _d, _e, _f;
88
110
  if (!isClientInitialized(clientConfig)) {
89
- throw new Error('[Djust SDK] SDK not initialized. Provide both client ID and API key via the "initialize" method.');
111
+ const error = new Error('[Djust SDK] SDK not initialized. Provide both client ID and API key via the "initialize" method.');
112
+ Sentry.captureException(error);
113
+ throw error;
90
114
  }
91
115
  const { clientId, apiKey, accessToken, locale, headers } = clientConfig;
92
116
  const requestHeaders = new Headers({
@@ -94,12 +118,6 @@ const enhancedFetch = async ({ path, method, params = {}, body, }) => {
94
118
  "dj-api-key": apiKey,
95
119
  "Content-Type": "application/json",
96
120
  });
97
- // if (isBrowser()) {
98
- // const token = getCookie("token");
99
- // if (token) {
100
- // requestHeaders.append("Authorization", `Bearer ${token}`);
101
- // }
102
- // }
103
121
  if (!isPublicRoute(path, method) && accessToken)
104
122
  requestHeaders.append("Authorization", `Bearer ${accessToken}`);
105
123
  if (locale)
@@ -133,11 +151,22 @@ const enhancedFetch = async ({ path, method, params = {}, body, }) => {
133
151
  const { status, headers } = response;
134
152
  if (!response.ok) {
135
153
  const errorMessage = await response.text();
136
- throw new Error(`[Djust SDK] HTTP error ${status}: ${errorMessage}`);
154
+ const error = new Error(`[Djust SDK] Erreur HTTP ${status}: ${errorMessage}`);
155
+ Sentry.withScope((scope) => {
156
+ scope.setExtra("path", path);
157
+ scope.setExtra("method", method);
158
+ scope.setExtra("status", status);
159
+ scope.setExtra("params", params);
160
+ scope.setExtra("body", body);
161
+ scope.setExtra("headers", headers);
162
+ scope.setExtra("clientName", clientConfig.clientName);
163
+ scope.setExtra("env", clientConfig.env);
164
+ Sentry.captureException(error);
165
+ });
166
+ throw error;
137
167
  }
138
168
  const isJsonResponse = (_d = headers
139
169
  .get("content-type")) === null || _d === void 0 ? void 0 : _d.includes("application/json");
140
- // Additional check: ensure the response has content before attempting to parse JSON
141
170
  let responseText = await response.text();
142
171
  function isJsonString(str) {
143
172
  if (typeof str !== "string")
@@ -165,8 +194,18 @@ const enhancedFetch = async ({ path, method, params = {}, body, }) => {
165
194
  return { data, headers, status };
166
195
  }
167
196
  catch (error) {
168
- console.error("[Djust SDK] Fetch error: ", error);
169
- throw new Error(`[Djust SDK] ${error.message || "Unknown error occurred"}`);
197
+ Sentry.withScope((scope) => {
198
+ scope.setExtra("path", path);
199
+ scope.setExtra("method", method);
200
+ scope.setExtra("params", params);
201
+ scope.setExtra("body", body);
202
+ scope.setExtra("headers", headers);
203
+ scope.setExtra("clientName", clientConfig.clientName);
204
+ scope.setExtra("env", clientConfig.env);
205
+ Sentry.captureException(error);
206
+ });
207
+ console.error("[Djust SDK] Erreur Fetch: ", error);
208
+ throw new Error(`[Djust SDK] ${error.message || "Une erreur inconnue est survenue."}`);
170
209
  }
171
210
  };
172
211
  exports.enhancedFetch = enhancedFetch;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@djust-b2b/djust-front-sdk",
3
- "version": "1.21.2",
3
+ "version": "1.22.0",
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",
@@ -50,6 +50,8 @@
50
50
  "lib/**/**.d.ts"
51
51
  ],
52
52
  "dependencies": {
53
+ "@sentry/node": "^9.2.0",
54
+ "@sentry/profiling-node": "^9.2.0",
53
55
  "isomorphic-fetch": "^3.0.0",
54
56
  "query-string": "^7.1.1"
55
57
  },