@djust-b2b/djust-front-sdk 1.21.5 → 1.21.7

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
+ env?: string;
15
+ dsn?: 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
+ env?: string;
30
+ dsn?: 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>;
package/lib/index.js CHANGED
@@ -46,8 +46,8 @@ const NavigationCategoryServices = __importStar(require("./services/navigation-c
46
46
  const ProductServices = __importStar(require("./services/product"));
47
47
  const QuoteServices = __importStar(require("./services/quote"));
48
48
  const SupplierServices = __importStar(require("./services/supplier"));
49
- const LogisticOrderServices = __importStar(require("./services/logistic-order"));
50
49
  const CommercialOrderServices = __importStar(require("./services/commercial-order"));
50
+ const LogisticOrderServices = __importStar(require("./services/logistic-order"));
51
51
  const IncidentServices = __importStar(require("./services/incident"));
52
52
  const fetch_instance_1 = require("./settings/fetch-instance");
53
53
  exports.DjustSDK = {
@@ -10,6 +10,9 @@ type ClientConfig = {
10
10
  storeId?: string;
11
11
  storeViewId?: string;
12
12
  customerAccountId?: string;
13
+ clientName?: string;
14
+ env?: string;
15
+ dsn?: 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,38 @@ 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/browser"));
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
+ env: "development",
47
+ clientName: "Djust",
48
+ };
40
49
  const initialize = (initConfig) => {
41
50
  clientConfig = {
42
51
  ...initConfig,
43
52
  };
53
+ if (clientConfig.dsn) {
54
+ Sentry.init({
55
+ dsn: clientConfig.dsn ||
56
+ "https://39ef5198e24fa0ec7b743c460bd1ca63@o1191347.ingest.us.sentry.io/4508879498575872",
57
+ environment: `${clientConfig.clientName}-${clientConfig.env}`,
58
+ release: `${SDK_VERSION || "unknown"}`,
59
+ integrations: [
60
+ Sentry.browserTracingIntegration(),
61
+ Sentry.replayIntegration(),
62
+ ],
63
+ tracesSampleRate: 1.0,
64
+ replaysSessionSampleRate: 0.1,
65
+ replaysOnErrorSampleRate: 1.0,
66
+ profilesSampleRate: 1.0,
67
+ });
68
+ console.log(`[Djust SDK] Sentry initialized in ${clientConfig.clientName || "unknown"} environment: ${clientConfig.env || "unknown"}.`);
69
+ }
44
70
  };
45
71
  exports.initialize = initialize;
46
72
  const updateConfiguration = (newConfig) => {
@@ -86,7 +112,11 @@ const isPublicRoute = (path, method) => {
86
112
  const enhancedFetch = async ({ path, method, params = {}, body, }) => {
87
113
  var _a, _b, _c, _d, _e, _f;
88
114
  if (!isClientInitialized(clientConfig)) {
89
- throw new Error('[Djust SDK] SDK not initialized. Provide both client ID and API key via the "initialize" method.');
115
+ const error = new Error("[Djust SDK] SDK not initialized.");
116
+ Sentry.captureException(error, {
117
+ tags: { env: clientConfig.env },
118
+ });
119
+ throw error;
90
120
  }
91
121
  const { clientId, apiKey, accessToken, locale, headers } = clientConfig;
92
122
  const requestHeaders = new Headers({
@@ -127,7 +157,26 @@ const enhancedFetch = async ({ path, method, params = {}, body, }) => {
127
157
  const { status, headers } = response;
128
158
  if (!response.ok) {
129
159
  const errorMessage = await response.text();
130
- throw new Error(`[Djust SDK] HTTP error ${status}: ${errorMessage}`);
160
+ const error = new Error(`[Djust SDK] HTTP error ${response.status}: ${errorMessage}`);
161
+ Sentry.captureException(error, {
162
+ extra: {
163
+ url: fullPath,
164
+ method,
165
+ response: errorMessage,
166
+ status: response.status,
167
+ env: clientConfig.env,
168
+ headers: (() => {
169
+ const headersObj = {};
170
+ requestHeaders.forEach((value, key) => {
171
+ headersObj[key] = value;
172
+ });
173
+ return headersObj;
174
+ })(),
175
+ body: body ? body : null,
176
+ params,
177
+ },
178
+ });
179
+ throw error;
131
180
  }
132
181
  const isJsonResponse = (_d = headers
133
182
  .get("content-type")) === null || _d === void 0 ? void 0 : _d.includes("application/json");
@@ -159,8 +208,8 @@ const enhancedFetch = async ({ path, method, params = {}, body, }) => {
159
208
  return { data, headers, status };
160
209
  }
161
210
  catch (error) {
162
- console.error("[Djust SDK] Fetch error: ", error);
163
- throw new Error(`[Djust SDK] ${error.message || "Unknown error occurred"}`);
211
+ Sentry.captureException(error, { tags: { env: clientConfig.env } });
212
+ throw new Error(`[Djust SDK] ${error || "Unknown error occurred"}`);
164
213
  }
165
214
  };
166
215
  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.5",
3
+ "version": "1.21.7",
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,7 @@
50
50
  "lib/**/**.d.ts"
51
51
  ],
52
52
  "dependencies": {
53
+ "@sentry/browser": "^9.2.0",
53
54
  "isomorphic-fetch": "^3.0.0",
54
55
  "query-string": "^7.1.1"
55
56
  },