@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.
- package/lib/instrument.d.ts +1 -2
- package/lib/instrument.js +11 -29
- package/lib/src/settings/fetch-instance.js +22 -19
- package/package.json +1 -1
package/lib/instrument.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
(
|
|
146
|
-
path,
|
|
147
|
-
method,
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
-
(
|
|
186
|
-
path,
|
|
187
|
-
method,
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
headers
|
|
191
|
-
clientName
|
|
192
|
-
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."}`);
|