@djust-b2b/djust-front-sdk 1.21.3 → 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>;
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
169
|
-
|
|
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.
|
|
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
|
},
|