@djust-b2b/djust-front-sdk 1.22.2 → 1.22.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.
@@ -1,2 +1 @@
1
- export function initSentry(clientConfig: any): void;
2
- export function captureError(error: any, context?: {}): void;
1
+ export {};
package/lib/instrument.js CHANGED
@@ -1,33 +1,15 @@
1
1
  "use strict";
2
2
  const Sentry = require("@sentry/node");
3
3
  const { nodeProfilingIntegration } = require("@sentry/profiling-node");
4
- let isSentryInitialized = false;
5
4
  const SDK_VERSION = require("../package.json").version;
6
- function initSentry(clientConfig) {
7
- const { clientName, env, dsn } = clientConfig;
8
- if (!clientName || !env || !dsn) {
9
- console.warn("[Sentry] Missing clientName, env, or DSN. Sentry is not initialized.");
10
- return;
11
- }
12
- if (!isSentryInitialized) {
13
- Sentry.init({
14
- dsn,
15
- environment: `${clientName}-${env}`,
16
- release: `${clientName}-${env}-${SDK_VERSION}`, // Replace with your SDK version
17
- integrations: [nodeProfilingIntegration(), Sentry.nativeNodeFetchIntegration()],
18
- tracesSampleRate: 1.0, // Adjust for production
19
- profilesSampleRate: 1.0,
20
- });
21
- isSentryInitialized = true;
22
- console.log(`[Sentry] Initialized for ${clientName}-${env}`);
23
- }
24
- }
25
- function captureError(error, context = {}) {
26
- Sentry.withScope((scope) => {
27
- Object.entries(context).forEach(([key, value]) => {
28
- scope.setExtra(key, value);
29
- });
30
- Sentry.captureException(error);
31
- });
32
- }
33
- module.exports = { initSentry, captureError };
5
+ const dsn = "https://39ef5198e24fa0ec7b743c460bd1ca63@o1191347.ingest.us.sentry.io/4508879498575872"; // Replace with your actual DSN
6
+ const clientName = "djust"; // Replace with your actual client name
7
+ const env = "preprod"; // Replace with your actual environment
8
+ Sentry.init({
9
+ dsn,
10
+ environment: `${clientName}-${env}`,
11
+ release: `${clientName}-${env}-${SDK_VERSION}`, // Replace with your SDK version
12
+ integrations: [nodeProfilingIntegration(), Sentry.nativeNodeFetchIntegration()],
13
+ tracesSampleRate: 1.0, // Adjust for production
14
+ profilesSampleRate: 1.0,
15
+ });
@@ -34,7 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.enhancedFetch = exports.updateConfiguration = exports.initialize = void 0;
37
- const instrument_1 = require("../../instrument");
37
+ const Sentry = __importStar(require("@sentry/node"));
38
38
  const qs = __importStar(require("query-string"));
39
39
  require("isomorphic-fetch");
40
40
  let clientConfig = {
@@ -49,7 +49,7 @@ const initialize = (initConfig) => {
49
49
  ...initConfig,
50
50
  };
51
51
  if (!isSDKInitialized) {
52
- (0, instrument_1.initSentry)(clientConfig);
52
+ Sentry.init(clientConfig); // ✅ Pass clientConfig dynamically
53
53
  isSDKInitialized = true;
54
54
  console.log("[Djust SDK] Initialized with client config:", clientConfig);
55
55
  }
@@ -99,7 +99,7 @@ const enhancedFetch = async ({ path, method, params = {}, body, }) => {
99
99
  var _a, _b, _c, _d, _e, _f;
100
100
  if (!isClientInitialized(clientConfig)) {
101
101
  const error = new Error('[Djust SDK] SDK not initialized. Provide both client ID and API key via the "initialize" method.');
102
- (0, instrument_1.captureError)(error);
102
+ Sentry.captureException(error);
103
103
  throw error;
104
104
  }
105
105
  const { clientId, apiKey, accessToken, locale, headers } = clientConfig;
@@ -142,14 +142,16 @@ const enhancedFetch = async ({ path, method, params = {}, body, }) => {
142
142
  if (!response.ok) {
143
143
  const errorMessage = await response.text();
144
144
  const error = new Error(`[Djust SDK] Erreur HTTP ${status}: ${errorMessage}`);
145
- (0, instrument_1.captureError)(error, {
146
- path,
147
- method,
148
- params,
149
- body,
150
- headers,
151
- clientName: clientConfig.clientName,
152
- env: clientConfig.env,
145
+ Sentry.withScope((scope) => {
146
+ scope.setExtra("path", path);
147
+ scope.setExtra("method", method);
148
+ scope.setExtra("status", status);
149
+ scope.setExtra("params", params);
150
+ scope.setExtra("body", body);
151
+ scope.setExtra("headers", headers);
152
+ scope.setExtra("clientName", clientConfig.clientName);
153
+ scope.setExtra("env", clientConfig.env);
154
+ Sentry.captureException(error);
153
155
  });
154
156
  throw error;
155
157
  }
@@ -182,14 +184,15 @@ const enhancedFetch = async ({ path, method, params = {}, body, }) => {
182
184
  return { data, headers, status };
183
185
  }
184
186
  catch (error) {
185
- (0, instrument_1.captureError)(error, {
186
- path,
187
- method,
188
- params: JSON.stringify(params, null, 2),
189
- body: JSON.stringify(body, null, 2),
190
- headers: headers ? headers : undefined,
191
- clientName: clientConfig.clientName,
192
- env: clientConfig.env,
187
+ Sentry.withScope((scope) => {
188
+ scope.setExtra("path", path);
189
+ scope.setExtra("method", method);
190
+ scope.setExtra("params", params);
191
+ scope.setExtra("body", body);
192
+ scope.setExtra("headers", headers);
193
+ scope.setExtra("clientName", clientConfig.clientName);
194
+ scope.setExtra("env", clientConfig.env);
195
+ Sentry.captureException(error);
193
196
  });
194
197
  console.error("[Djust SDK] Erreur Fetch: ", error);
195
198
  throw new Error(`[Djust SDK] ${error.message || "Une erreur inconnue est survenue."}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@djust-b2b/djust-front-sdk",
3
- "version": "1.22.2",
3
+ "version": "1.22.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",