@djust-b2b/djust-front-sdk 1.21.3 → 1.22.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/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>;
@@ -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,31 @@ 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"));
38
39
  require("isomorphic-fetch");
39
- let clientConfig = { baseUrl: "", clientId: "", apiKey: "" };
40
+ const SDK_VERSION = require("../package.json").version;
41
+ let clientConfig = {
42
+ baseUrl: "",
43
+ clientId: "",
44
+ apiKey: "",
45
+ dsn: "https://39ef5198e24fa0ec7b743c460bd1ca63@o1191347.ingest.us.sentry.io/4508879498575872",
46
+ };
47
+ let isSentryInitialized = false;
40
48
  const initialize = (initConfig) => {
41
49
  clientConfig = {
42
50
  ...initConfig,
43
51
  };
52
+ // ✅ Auto-initialisation de Sentry si `clientName` et `env` sont définis
53
+ if (!isSentryInitialized && clientConfig.clientName && clientConfig.env) {
54
+ Sentry.init({
55
+ dsn: clientConfig.dsn,
56
+ environment: `${clientConfig.clientName}-${clientConfig.env}`,
57
+ release: `${clientConfig.clientName}-${clientConfig.env}-${SDK_VERSION}`,
58
+ tracesSampleRate: 1.0,
59
+ });
60
+ isSentryInitialized = true;
61
+ console.log(`[Djust SDK] Sentry activé pour ${clientConfig.clientName}-${clientConfig.env}-${SDK_VERSION}`);
62
+ }
44
63
  };
45
64
  exports.initialize = initialize;
46
65
  const updateConfiguration = (newConfig) => {
@@ -86,7 +105,9 @@ const isPublicRoute = (path, method) => {
86
105
  const enhancedFetch = async ({ path, method, params = {}, body, }) => {
87
106
  var _a, _b, _c, _d, _e, _f;
88
107
  if (!isClientInitialized(clientConfig)) {
89
- throw new Error('[Djust SDK] SDK not initialized. Provide both client ID and API key via the "initialize" method.');
108
+ const error = new Error('[Djust SDK] SDK not initialized. Provide both client ID and API key via the "initialize" method.');
109
+ Sentry.captureException(error);
110
+ throw error;
90
111
  }
91
112
  const { clientId, apiKey, accessToken, locale, headers } = clientConfig;
92
113
  const requestHeaders = new Headers({
@@ -94,12 +115,6 @@ const enhancedFetch = async ({ path, method, params = {}, body, }) => {
94
115
  "dj-api-key": apiKey,
95
116
  "Content-Type": "application/json",
96
117
  });
97
- // if (isBrowser()) {
98
- // const token = getCookie("token");
99
- // if (token) {
100
- // requestHeaders.append("Authorization", `Bearer ${token}`);
101
- // }
102
- // }
103
118
  if (!isPublicRoute(path, method) && accessToken)
104
119
  requestHeaders.append("Authorization", `Bearer ${accessToken}`);
105
120
  if (locale)
@@ -133,11 +148,22 @@ const enhancedFetch = async ({ path, method, params = {}, body, }) => {
133
148
  const { status, headers } = response;
134
149
  if (!response.ok) {
135
150
  const errorMessage = await response.text();
136
- throw new Error(`[Djust SDK] HTTP error ${status}: ${errorMessage}`);
151
+ const error = new Error(`[Djust SDK] Erreur HTTP ${status}: ${errorMessage}`);
152
+ Sentry.withScope((scope) => {
153
+ scope.setExtra("path", path);
154
+ scope.setExtra("method", method);
155
+ scope.setExtra("status", status);
156
+ scope.setExtra("params", params);
157
+ scope.setExtra("body", body);
158
+ scope.setExtra("headers", headers);
159
+ scope.setExtra("clientName", clientConfig.clientName);
160
+ scope.setExtra("env", clientConfig.env);
161
+ Sentry.captureException(error);
162
+ });
163
+ throw error;
137
164
  }
138
165
  const isJsonResponse = (_d = headers
139
166
  .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
167
  let responseText = await response.text();
142
168
  function isJsonString(str) {
143
169
  if (typeof str !== "string")
@@ -165,8 +191,18 @@ const enhancedFetch = async ({ path, method, params = {}, body, }) => {
165
191
  return { data, headers, status };
166
192
  }
167
193
  catch (error) {
168
- console.error("[Djust SDK] Fetch error: ", error);
169
- throw new Error(`[Djust SDK] ${error.message || "Unknown error occurred"}`);
194
+ Sentry.withScope((scope) => {
195
+ scope.setExtra("path", path);
196
+ scope.setExtra("method", method);
197
+ scope.setExtra("params", params);
198
+ scope.setExtra("body", body);
199
+ scope.setExtra("headers", headers);
200
+ scope.setExtra("clientName", clientConfig.clientName);
201
+ scope.setExtra("env", clientConfig.env);
202
+ Sentry.captureException(error);
203
+ });
204
+ console.error("[Djust SDK] Erreur Fetch: ", error);
205
+ throw new Error(`[Djust SDK] ${error.message || "Une erreur inconnue est survenue."}`);
170
206
  }
171
207
  };
172
208
  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.3",
3
+ "version": "1.22.1",
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
  },