@djust-b2b/djust-front-sdk 3.0.0 → 3.1.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.
Files changed (45) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/.tsbuildinfo-esm +1 -1
  3. package/dist/index.cjs +12 -1
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.mjs +248 -1
  7. package/dist/monitoring/index.d.ts +7 -0
  8. package/dist/monitoring/index.d.ts.map +1 -0
  9. package/dist/monitoring/observability.d.ts +60 -0
  10. package/dist/monitoring/observability.d.ts.map +1 -0
  11. package/dist/monitoring/sentry.d.ts +72 -0
  12. package/dist/monitoring/sentry.d.ts.map +1 -0
  13. package/dist/monitoring/utils.d.ts +3 -0
  14. package/dist/monitoring/utils.d.ts.map +1 -0
  15. package/dist/monitoring/w3c-trace.d.ts +13 -0
  16. package/dist/monitoring/w3c-trace.d.ts.map +1 -0
  17. package/dist/settings/sdk-version.d.ts +1 -1
  18. package/lib/.tsbuildinfo +1 -1
  19. package/lib/index.d.ts +2 -0
  20. package/lib/index.d.ts.map +1 -1
  21. package/lib/index.js +12 -1
  22. package/lib/index.js.map +1 -1
  23. package/lib/monitoring/index.d.ts +7 -0
  24. package/lib/monitoring/index.d.ts.map +1 -0
  25. package/lib/monitoring/index.js +14 -0
  26. package/lib/monitoring/index.js.map +1 -0
  27. package/lib/monitoring/observability.d.ts +60 -0
  28. package/lib/monitoring/observability.d.ts.map +1 -0
  29. package/lib/monitoring/observability.js +115 -0
  30. package/lib/monitoring/observability.js.map +1 -0
  31. package/lib/monitoring/sentry.d.ts +72 -0
  32. package/lib/monitoring/sentry.d.ts.map +1 -0
  33. package/lib/monitoring/sentry.js +142 -0
  34. package/lib/monitoring/sentry.js.map +1 -0
  35. package/lib/monitoring/utils.d.ts +3 -0
  36. package/lib/monitoring/utils.d.ts.map +1 -0
  37. package/lib/monitoring/utils.js +13 -0
  38. package/lib/monitoring/utils.js.map +1 -0
  39. package/lib/monitoring/w3c-trace.d.ts +13 -0
  40. package/lib/monitoring/w3c-trace.d.ts.map +1 -0
  41. package/lib/monitoring/w3c-trace.js +23 -0
  42. package/lib/monitoring/w3c-trace.js.map +1 -0
  43. package/lib/settings/sdk-version.d.ts +1 -1
  44. package/lib/settings/sdk-version.js +1 -1
  45. package/package.json +6 -1
package/dist/index.cjs CHANGED
@@ -24,7 +24,7 @@
24
24
  * @packageDocumentation
25
25
  */
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.getHttpStatus = exports.isApiError = exports.withStructuredErrors = exports.withLegacyErrors = exports.parseLegacyError = exports.isLegacyError = exports.fromLegacyError = exports.toLegacyError = exports.getUserFriendlyMessage = exports.extractErrorCode = exports.extractStatusCode = exports.isTransientError = exports.isClientError = exports.shouldReauthenticate = exports.getRetryDelay = exports.isRetryable = exports.isUnexpectedError = exports.isRateLimitError = exports.isNotFoundError = exports.isValidationError = exports.isServerError = exports.isTimeoutError = exports.isNetworkError = exports.isForbiddenError = exports.isAuthError = exports.isSDKError = exports.createErrorFromException = exports.createErrorFromResponse = exports.UnexpectedError = exports.ServerError = exports.TimeoutError = exports.NetworkError = exports.RateLimitError = exports.NotFoundError = exports.ForbiddenError = exports.AuthError = exports.ValidationError = exports.RETRIABLE_HTTP_STATUS_CODES = exports.RETRIABLE_ERROR_CODES = exports.SDKErrorCode = exports.SDKError = exports.createDjustClient = exports.DjustSDK = void 0;
27
+ exports.getW3CTraceFromHeaders = exports.mergeTransportHooks = exports.createDjustErrorHooks = exports.buildDjustErrorEvent = exports.createDjustSentryHooks = exports.captureDjustError = exports.buildDjustSentryTags = exports.getHttpStatus = exports.isApiError = exports.withStructuredErrors = exports.withLegacyErrors = exports.parseLegacyError = exports.isLegacyError = exports.fromLegacyError = exports.toLegacyError = exports.getUserFriendlyMessage = exports.extractErrorCode = exports.extractStatusCode = exports.isTransientError = exports.isClientError = exports.shouldReauthenticate = exports.getRetryDelay = exports.isRetryable = exports.isUnexpectedError = exports.isRateLimitError = exports.isNotFoundError = exports.isValidationError = exports.isServerError = exports.isTimeoutError = exports.isNetworkError = exports.isForbiddenError = exports.isAuthError = exports.isSDKError = exports.createErrorFromException = exports.createErrorFromResponse = exports.UnexpectedError = exports.ServerError = exports.TimeoutError = exports.NetworkError = exports.RateLimitError = exports.NotFoundError = exports.ForbiddenError = exports.AuthError = exports.ValidationError = exports.RETRIABLE_HTTP_STATUS_CODES = exports.RETRIABLE_ERROR_CODES = exports.SDKErrorCode = exports.SDKError = exports.createDjustClient = exports.DjustSDK = void 0;
28
28
  const tslib_1 = require("tslib");
29
29
  const AuthServices = tslib_1.__importStar(require("./services/auth"));
30
30
  const CartServices = tslib_1.__importStar(require("./services/cart"));
@@ -176,6 +176,17 @@ Object.defineProperty(exports, "withStructuredErrors", { enumerable: true, get:
176
176
  Object.defineProperty(exports, "isApiError", { enumerable: true, get: function () { return errors_1.isApiError; } });
177
177
  Object.defineProperty(exports, "getHttpStatus", { enumerable: true, get: function () { return errors_1.getHttpStatus; } });
178
178
  // ============================================================================
179
+ // MONITORING (Sentry helpers — @sentry/node is a host-app peer)
180
+ // ============================================================================
181
+ var monitoring_1 = require("./monitoring");
182
+ Object.defineProperty(exports, "buildDjustSentryTags", { enumerable: true, get: function () { return monitoring_1.buildDjustSentryTags; } });
183
+ Object.defineProperty(exports, "captureDjustError", { enumerable: true, get: function () { return monitoring_1.captureDjustError; } });
184
+ Object.defineProperty(exports, "createDjustSentryHooks", { enumerable: true, get: function () { return monitoring_1.createDjustSentryHooks; } });
185
+ Object.defineProperty(exports, "buildDjustErrorEvent", { enumerable: true, get: function () { return monitoring_1.buildDjustErrorEvent; } });
186
+ Object.defineProperty(exports, "createDjustErrorHooks", { enumerable: true, get: function () { return monitoring_1.createDjustErrorHooks; } });
187
+ Object.defineProperty(exports, "mergeTransportHooks", { enumerable: true, get: function () { return monitoring_1.mergeTransportHooks; } });
188
+ Object.defineProperty(exports, "getW3CTraceFromHeaders", { enumerable: true, get: function () { return monitoring_1.getW3CTraceFromHeaders; } });
189
+ // ============================================================================
179
190
  // INTERFACES (unchanged)
180
191
  // ============================================================================
181
192
  tslib_1.__exportStar(require("./interfaces"), exports);
package/dist/index.d.ts CHANGED
@@ -263,5 +263,7 @@ export { createDjustClient } from "./client";
263
263
  export type { DjustClientConfig, DjustClient, DjustScopedClient, RequestContext, RetryConfig, TransportHooks, } from "./client";
264
264
  export { SDKError, SDKErrorCode, RETRIABLE_ERROR_CODES, RETRIABLE_HTTP_STATUS_CODES, ValidationError, AuthError, ForbiddenError, NotFoundError, RateLimitError, NetworkError, TimeoutError, ServerError, UnexpectedError, createErrorFromResponse, createErrorFromException, isSDKError, isAuthError, isForbiddenError, isNetworkError, isTimeoutError, isServerError, isValidationError, isNotFoundError, isRateLimitError, isUnexpectedError, isRetryable, getRetryDelay, shouldReauthenticate, isClientError, isTransientError, extractStatusCode, extractErrorCode, getUserFriendlyMessage, toLegacyError, fromLegacyError, isLegacyError, parseLegacyError, withLegacyErrors, withStructuredErrors, isApiError, getHttpStatus, } from "./errors";
265
265
  export type { SDKErrorCodeType, SDKErrorOptions, RequestMetadata, ErrorFactoryOptions, SerializedError, ClientSafeError, } from "./errors";
266
+ export { buildDjustSentryTags, captureDjustError, createDjustSentryHooks, buildDjustErrorEvent, createDjustErrorHooks, mergeTransportHooks, getW3CTraceFromHeaders, } from "./monitoring";
267
+ export type { DjustErrorCaptureContext, DjustSentryMonitoringOptions, SentryLike, SentryScope, DjustErrorEvent, DjustErrorHooksOptions, DjustErrorListener, DjustMonitoringTier, W3CTraceFields, } from "./monitoring";
266
268
  export * from "./interfaces";
267
269
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAwBH;;;;;;;;;;;;;;GAcG;AACH,eAAO,M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e,GAChB,MAAM,UAAU,CAAC;AAMlB,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV,wBAAwB,EACxB,4BAA4B,EAC5B,UAAU,EACV,WAAW,EACX,eAAe,EACf,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,GACf,MAAM,cAAc,CAAC;AAMtB,cAAc,cAAc,CAAC"}
package/dist/index.mjs CHANGED
@@ -1326,7 +1326,7 @@ import * as Sentry from "@sentry/browser";
1326
1326
  import "isomorphic-fetch";
1327
1327
 
1328
1328
  // src/settings/sdk-version.ts
1329
- var SDK_VERSION = "3.0.0";
1329
+ var SDK_VERSION = "3.1.0";
1330
1330
 
1331
1331
  // src/settings/fetch-instance.ts
1332
1332
  var clientConfig = {
@@ -11628,6 +11628,246 @@ init_unexpected_error();
11628
11628
  // src/errors/index.ts
11629
11629
  init_factory();
11630
11630
 
11631
+ // src/monitoring/w3c-trace.ts
11632
+ function getW3CTraceFromHeaders(headers) {
11633
+ const traceparent = headers.traceparent ?? headers.Traceparent;
11634
+ if (!traceparent) {
11635
+ return {};
11636
+ }
11637
+ const parts = traceparent.trim().split("-");
11638
+ if (parts.length !== 4 || parts[0] !== "00") {
11639
+ return { traceparent };
11640
+ }
11641
+ const [, traceId, spanId] = parts;
11642
+ const isHex = (value, length) => value.length === length && /^[0-9a-f]+$/i.test(value);
11643
+ if (!isHex(traceId, 32) || !isHex(spanId, 16)) {
11644
+ return { traceparent };
11645
+ }
11646
+ return { traceparent, traceId, spanId };
11647
+ }
11648
+
11649
+ // src/monitoring/utils.ts
11650
+ function getEndpoint(url) {
11651
+ try {
11652
+ return new URL(url).pathname;
11653
+ } catch {
11654
+ return url;
11655
+ }
11656
+ }
11657
+
11658
+ // src/monitoring/sentry.ts
11659
+ function resolveErrorCode(error) {
11660
+ if (isSDKError(error)) {
11661
+ return String(error.code);
11662
+ }
11663
+ const legacy = fromLegacyError(error);
11664
+ return legacy ? String(legacy.code) : SDKErrorCode.UNEXPECTED_ERROR;
11665
+ }
11666
+ function resolveHttpStatus(error) {
11667
+ if (isSDKError(error)) {
11668
+ return error.httpStatus;
11669
+ }
11670
+ const legacy = fromLegacyError(error);
11671
+ return legacy?.httpStatus ?? 500;
11672
+ }
11673
+ function buildDjustSentryTags(error, context) {
11674
+ const tags = {
11675
+ "djust.source": context.source,
11676
+ "djust.error_code": resolveErrorCode(error),
11677
+ "djust.http_status": String(resolveHttpStatus(error)),
11678
+ "djust.retriable": String(isSDKError(error) ? error.retriable : false)
11679
+ };
11680
+ if (context.clientId)
11681
+ tags["djust.client_id"] = context.clientId;
11682
+ if (context.clientName)
11683
+ tags["djust.client_name"] = context.clientName;
11684
+ if (context.environment)
11685
+ tags["djust.env"] = context.environment;
11686
+ if (context.requestId)
11687
+ tags["djust.request_id"] = context.requestId;
11688
+ if (context.traceId)
11689
+ tags["djust.trace_id"] = context.traceId;
11690
+ if (context.traceparent)
11691
+ tags["djust.traceparent"] = context.traceparent;
11692
+ if (context.spanId)
11693
+ tags["djust.span_id"] = context.spanId;
11694
+ if (context.method)
11695
+ tags["djust.method"] = context.method;
11696
+ if (context.endpoint)
11697
+ tags["djust.endpoint"] = context.endpoint;
11698
+ if (context.bffRoute)
11699
+ tags["djust.bff_route"] = context.bffRoute;
11700
+ if (context.monitoringTier) {
11701
+ tags["djust.monitoring_tier"] = context.monitoringTier;
11702
+ }
11703
+ if (context.willRetry !== void 0) {
11704
+ tags["djust.will_retry"] = String(context.willRetry);
11705
+ }
11706
+ return tags;
11707
+ }
11708
+ function captureDjustError(sentry, error, context, options) {
11709
+ if (options?.skipIfRetrying && context.willRetry) {
11710
+ return;
11711
+ }
11712
+ const httpStatus = resolveHttpStatus(error);
11713
+ const ignored = options?.ignoredHttpStatuses ?? [];
11714
+ if (ignored.includes(httpStatus)) {
11715
+ return;
11716
+ }
11717
+ const endpoint = context.endpoint ?? (isSDKError(error) ? error.metadata.endpoint : void 0);
11718
+ const tags = buildDjustSentryTags(error, { ...context, endpoint });
11719
+ sentry.withScope((scope) => {
11720
+ for (const [key, value] of Object.entries(tags)) {
11721
+ scope.setTag(key, value);
11722
+ }
11723
+ if (isSDKError(error)) {
11724
+ scope.setContext(
11725
+ "djust_error",
11726
+ error.toJSON()
11727
+ );
11728
+ }
11729
+ if (context.traceparent || context.traceId || context.spanId) {
11730
+ scope.setContext("w3c_trace", {
11731
+ traceId: context.traceId ?? context.requestId,
11732
+ spanId: context.spanId,
11733
+ traceparent: context.traceparent
11734
+ });
11735
+ }
11736
+ scope.captureException(error);
11737
+ });
11738
+ }
11739
+ function createDjustSentryHooks(sentry, options = {}) {
11740
+ const skipRetrying = options.skipRetryingErrors ?? true;
11741
+ const ignoredHttpStatuses = options.ignoredHttpStatuses ?? [];
11742
+ return {
11743
+ onError(ctx) {
11744
+ const w3c = getW3CTraceFromHeaders(ctx.headers);
11745
+ captureDjustError(
11746
+ sentry,
11747
+ ctx.error,
11748
+ {
11749
+ source: "sdk",
11750
+ monitoringTier: options.monitoringTier ?? "djust",
11751
+ clientId: options.clientId,
11752
+ clientName: options.clientName,
11753
+ environment: options.environment,
11754
+ requestId: ctx.requestId,
11755
+ traceId: w3c.traceId ?? ctx.requestId,
11756
+ traceparent: w3c.traceparent,
11757
+ spanId: w3c.spanId,
11758
+ method: ctx.method,
11759
+ endpoint: getEndpoint(ctx.url),
11760
+ willRetry: ctx.willRetry
11761
+ },
11762
+ { skipIfRetrying: skipRetrying, ignoredHttpStatuses }
11763
+ );
11764
+ },
11765
+ onRetry(ctx) {
11766
+ sentry.addBreadcrumb({
11767
+ category: "djust.retry",
11768
+ message: `Retry ${ctx.attempt}/${ctx.maxAttempts} for ${ctx.requestId}`,
11769
+ level: "warning",
11770
+ data: {
11771
+ requestId: ctx.requestId,
11772
+ attempt: ctx.attempt,
11773
+ delayMs: ctx.delayMs,
11774
+ reason: ctx.reason,
11775
+ errorCode: resolveErrorCode(ctx.error)
11776
+ }
11777
+ });
11778
+ }
11779
+ };
11780
+ }
11781
+
11782
+ // src/monitoring/observability.ts
11783
+ function resolveMessage(error) {
11784
+ if (error instanceof Error) {
11785
+ return error.message;
11786
+ }
11787
+ return String(error);
11788
+ }
11789
+ function buildDjustErrorEvent(error, context) {
11790
+ const sdkError = isSDKError(error) ? error : fromLegacyError(error);
11791
+ const endpoint = context.endpoint ?? (isSDKError(error) ? error.metadata.endpoint : void 0);
11792
+ return {
11793
+ code: sdkError ? String(sdkError.code) : SDKErrorCode.UNEXPECTED_ERROR,
11794
+ httpStatus: sdkError?.httpStatus ?? 500,
11795
+ retriable: sdkError?.retriable ?? false,
11796
+ message: resolveMessage(error),
11797
+ source: context.source,
11798
+ monitoringTier: context.monitoringTier,
11799
+ clientId: context.clientId,
11800
+ clientName: context.clientName,
11801
+ environment: context.environment,
11802
+ traceId: context.traceId ?? context.requestId,
11803
+ traceparent: context.traceparent,
11804
+ spanId: context.spanId,
11805
+ requestId: context.requestId,
11806
+ method: context.method,
11807
+ endpoint,
11808
+ bffRoute: context.bffRoute,
11809
+ willRetry: context.willRetry,
11810
+ serialized: isSDKError(error) ? error.toJSON() : void 0,
11811
+ error
11812
+ };
11813
+ }
11814
+ function createDjustErrorHooks(onError, options = {}) {
11815
+ const skipRetrying = options.skipRetryingErrors ?? true;
11816
+ const ignoredHttpStatuses = options.ignoredHttpStatuses ?? [];
11817
+ return {
11818
+ onError(ctx) {
11819
+ if (skipRetrying && ctx.willRetry) {
11820
+ return;
11821
+ }
11822
+ const httpStatus = isSDKError(ctx.error) ? ctx.error.httpStatus : fromLegacyError(ctx.error)?.httpStatus ?? 500;
11823
+ if (ignoredHttpStatuses.includes(httpStatus)) {
11824
+ return;
11825
+ }
11826
+ const w3c = getW3CTraceFromHeaders(ctx.headers);
11827
+ const event = buildDjustErrorEvent(ctx.error, {
11828
+ source: "sdk",
11829
+ monitoringTier: options.monitoringTier,
11830
+ clientId: options.clientId,
11831
+ clientName: options.clientName,
11832
+ environment: options.environment,
11833
+ requestId: ctx.requestId,
11834
+ traceId: w3c.traceId ?? ctx.requestId,
11835
+ traceparent: w3c.traceparent,
11836
+ spanId: w3c.spanId,
11837
+ method: ctx.method,
11838
+ endpoint: getEndpoint(ctx.url),
11839
+ willRetry: ctx.willRetry
11840
+ });
11841
+ return onError(event);
11842
+ }
11843
+ };
11844
+ }
11845
+ var TRANSPORT_HOOK_NAMES = [
11846
+ "onRequestStart",
11847
+ "onRequestEnd",
11848
+ "onError",
11849
+ "onRetry",
11850
+ "onCacheHit"
11851
+ ];
11852
+ function mergeTransportHooks(...hookSets) {
11853
+ const merged = {};
11854
+ for (const hookName of TRANSPORT_HOOK_NAMES) {
11855
+ const handlers = hookSets.map((set) => set[hookName]).filter(
11856
+ (handler) => Boolean(handler)
11857
+ );
11858
+ if (handlers.length === 0) {
11859
+ continue;
11860
+ }
11861
+ const runHandlers = async (ctx) => {
11862
+ await Promise.allSettled(
11863
+ handlers.map(async (handler) => handler(ctx))
11864
+ );
11865
+ };
11866
+ Object.assign(merged, { [hookName]: runHandlers });
11867
+ }
11868
+ return merged;
11869
+ }
11870
+
11631
11871
  // src/services/operation/definitions.ts
11632
11872
  var OperationType = /* @__PURE__ */ ((OperationType2) => {
11633
11873
  OperationType2["PUBLIC"] = "PUBLIC";
@@ -11693,7 +11933,12 @@ export {
11693
11933
  TimeoutError,
11694
11934
  UnexpectedError,
11695
11935
  ValidationError,
11936
+ buildDjustErrorEvent,
11937
+ buildDjustSentryTags,
11938
+ captureDjustError,
11696
11939
  createDjustClient,
11940
+ createDjustErrorHooks,
11941
+ createDjustSentryHooks,
11697
11942
  createErrorFromException,
11698
11943
  createErrorFromResponse,
11699
11944
  extractErrorCode,
@@ -11702,6 +11947,7 @@ export {
11702
11947
  getHttpStatus,
11703
11948
  getRetryDelay,
11704
11949
  getUserFriendlyMessage,
11950
+ getW3CTraceFromHeaders,
11705
11951
  isApiError,
11706
11952
  isAuthError,
11707
11953
  isClientError,
@@ -11717,6 +11963,7 @@ export {
11717
11963
  isTransientError,
11718
11964
  isUnexpectedError,
11719
11965
  isValidationError,
11966
+ mergeTransportHooks,
11720
11967
  parseLegacyError,
11721
11968
  shouldReauthenticate,
11722
11969
  toLegacyError,
@@ -0,0 +1,7 @@
1
+ export { buildDjustSentryTags, captureDjustError, createDjustSentryHooks, } from "./sentry";
2
+ export { buildDjustErrorEvent, createDjustErrorHooks, mergeTransportHooks, } from "./observability";
3
+ export { getW3CTraceFromHeaders } from "./w3c-trace";
4
+ export type { W3CTraceFields } from "./w3c-trace";
5
+ export type { DjustErrorCaptureContext, DjustSentryMonitoringOptions, SentryLike, SentryScope, } from "./sentry";
6
+ export type { DjustErrorEvent, DjustErrorHooksOptions, DjustErrorListener, DjustMonitoringTier, } from "./observability";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/monitoring/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAErD,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,YAAY,EACV,wBAAwB,EACxB,4BAA4B,EAC5B,UAAU,EACV,WAAW,GACZ,MAAM,UAAU,CAAC;AAElB,YAAY,EACV,eAAe,EACf,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Vendor-neutral observability primitives.
3
+ * DJUST Sentry and client monitoring (Sentry, DataDog, …) run in parallel.
4
+ *
5
+ * @module monitoring/observability
6
+ * @since 3.0.1
7
+ */
8
+ import type { TransportHooks } from "../client/transport";
9
+ import type { SerializedError } from "../errors/types";
10
+ import type { DjustErrorCaptureContext } from "./sentry";
11
+ export type DjustMonitoringTier = "djust" | "client";
12
+ export interface DjustErrorEvent {
13
+ /** Normalized error payload — safe for logs and third-party tools */
14
+ code: string;
15
+ httpStatus: number;
16
+ retriable: boolean;
17
+ message: string;
18
+ source: DjustErrorCaptureContext["source"];
19
+ monitoringTier?: DjustMonitoringTier;
20
+ clientId?: string;
21
+ clientName?: string;
22
+ environment?: string;
23
+ /** W3C trace id — aligns with `getSDKTraceFields(event).requestId` */
24
+ traceId?: string;
25
+ traceparent?: string;
26
+ spanId?: string;
27
+ requestId?: string;
28
+ method?: string;
29
+ endpoint?: string;
30
+ bffRoute?: string;
31
+ willRetry?: boolean;
32
+ /** Present when the original error is an SDKError */
33
+ serialized?: SerializedError;
34
+ /** Original error reference (do not send to external tools verbatim) */
35
+ error: unknown;
36
+ }
37
+ export type DjustErrorListener = (event: DjustErrorEvent) => void | Promise<void>;
38
+ export interface DjustErrorHooksOptions {
39
+ clientId?: string;
40
+ clientName?: string;
41
+ environment?: string;
42
+ monitoringTier?: DjustMonitoringTier;
43
+ skipRetryingErrors?: boolean;
44
+ ignoredHttpStatuses?: number[];
45
+ }
46
+ /**
47
+ * Builds a vendor-neutral error event from an SDKError (or legacy error).
48
+ * Use for DataDog, custom loggers, or a client-owned Sentry project.
49
+ */
50
+ export declare function buildDjustErrorEvent(error: unknown, context: DjustErrorCaptureContext): DjustErrorEvent;
51
+ /**
52
+ * Generic transport hooks for any monitoring backend.
53
+ * Compose in parallel with `createDjustSentryHooks` via `mergeTransportHooks`.
54
+ */
55
+ export declare function createDjustErrorHooks(onError: DjustErrorListener, options?: DjustErrorHooksOptions): Pick<TransportHooks, "onError">;
56
+ /**
57
+ * Runs multiple hook sets in parallel — DJUST Sentry + client Sentry + DataDog, etc.
58
+ */
59
+ export declare function mergeTransportHooks(...hookSets: TransportHooks[]): TransportHooks;
60
+ //# sourceMappingURL=observability.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observability.d.ts","sourceRoot":"","sources":["../../src/monitoring/observability.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAGV,cAAc,EACf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAIzD,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,QAAQ,CAAC;AAErD,MAAM,WAAW,eAAe;IAC9B,qEAAqE;IACrE,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,wBAAwB,CAAC,QAAQ,CAAC,CAAC;IAC3C,cAAc,CAAC,EAAE,mBAAmB,CAAC;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sEAAsE;IACtE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,qDAAqD;IACrD,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B,wEAAwE;IACxE,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,MAAM,kBAAkB,GAAG,CAC/B,KAAK,EAAE,eAAe,KACnB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,mBAAmB,CAAC;IACrC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;CAChC;AAUD;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,wBAAwB,GAChC,eAAe,CA4BjB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,kBAAkB,EAC3B,OAAO,GAAE,sBAA2B,GACnC,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,CAsCjC;AAYD;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,QAAQ,EAAE,cAAc,EAAE,GAC5B,cAAc,CAuBhB"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Sentry helpers for DJUST SDK and Auth BFF monitoring.
3
+ * Uses a minimal interface so @sentry/node stays a host-app peer dependency.
4
+ *
5
+ * @module monitoring/sentry
6
+ * @since 3.0.1
7
+ */
8
+ import type { TransportHooks } from "../client/transport";
9
+ export interface SentryScope {
10
+ setTag(key: string, value: string): void;
11
+ setContext(name: string, context: Record<string, unknown> | null): void;
12
+ captureException(exception: unknown): string;
13
+ }
14
+ export interface SentryLike {
15
+ withScope(callback: (scope: SentryScope) => void): void;
16
+ addBreadcrumb(breadcrumb: {
17
+ category?: string;
18
+ message?: string;
19
+ level?: "debug" | "info" | "warning" | "error" | "fatal";
20
+ data?: Record<string, unknown>;
21
+ }): void;
22
+ }
23
+ export interface DjustErrorCaptureContext {
24
+ /** `sdk` for commerce API calls, `auth` for Auth BFF routes */
25
+ source: "sdk" | "auth";
26
+ /** `djust` = DJUST org Sentry; `client` = portal-owned monitoring */
27
+ monitoringTier?: "djust" | "client";
28
+ clientId?: string;
29
+ clientName?: string;
30
+ environment?: string;
31
+ /** W3C trace id (same as `requestId` when `getSDKTraceFields` is wired) */
32
+ traceId?: string;
33
+ /** W3C `traceparent` header propagated to the Ecom API */
34
+ traceparent?: string;
35
+ /** W3C parent span id for the current SSR request */
36
+ spanId?: string;
37
+ requestId?: string;
38
+ method?: string;
39
+ /** Backend API path (from SDKError.metadata.endpoint) */
40
+ endpoint?: string;
41
+ /** BFF route, e.g. `POST /api/auth/login` */
42
+ bffRoute?: string;
43
+ willRetry?: boolean;
44
+ }
45
+ export interface DjustSentryMonitoringOptions {
46
+ clientId?: string;
47
+ clientName?: string;
48
+ environment?: string;
49
+ /** Defaults to `djust` — set `client` for a portal-owned Sentry project */
50
+ monitoringTier?: "djust" | "client";
51
+ /** Skip capture while the transport will retry (default: true) */
52
+ skipRetryingErrors?: boolean;
53
+ /** HTTP statuses excluded from capture (e.g. 404, 422) */
54
+ ignoredHttpStatuses?: number[];
55
+ }
56
+ /**
57
+ * Builds stable Sentry tags from an SDKError (or legacy error) and request context.
58
+ * Use the same tags across SDK commerce calls and Auth BFF routes for cross-client dashboards.
59
+ */
60
+ export declare function buildDjustSentryTags(error: unknown, context: DjustErrorCaptureContext): Record<string, string>;
61
+ /**
62
+ * Captures a DJUST error in Sentry with SDKError-aligned tags and context.
63
+ */
64
+ export declare function captureDjustError(sentry: SentryLike, error: unknown, context: DjustErrorCaptureContext, options?: Pick<DjustSentryMonitoringOptions, "ignoredHttpStatuses"> & {
65
+ skipIfRetrying?: boolean;
66
+ }): void;
67
+ /**
68
+ * Creates Transport hooks that report SDK commerce errors to Sentry.
69
+ * Wire in the host `createDjustClient({ hooks: createDjustSentryHooks(Sentry, opts) })`.
70
+ */
71
+ export declare function createDjustSentryHooks(sentry: SentryLike, options?: DjustSentryMonitoringOptions): TransportHooks;
72
+ //# sourceMappingURL=sentry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sentry.d.ts","sourceRo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AAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yDAAyD;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2EAA2E;IAC3E,cAAc,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IACpC,kEAAkE;IAClE,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,0DAA0D;IAC1D,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;CAChC;AAoBD;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,wBAAwB,GAChC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA0BxB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,wBAAwB,EACjC,OAAO,CAAC,EAAE,IAAI,CAAC,4BAA4B,EAAE,qBAAqB,CAAC,GAAG;IACpE,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,GACA,IAAI,CAuCN;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,UAAU,EAClB,OAAO,GAAE,4BAAiC,GACzC,cAAc,CA4ChB"}
@@ -0,0 +1,3 @@
1
+ /** Extracts the pathname from a request URL for monitoring tags. */
2
+ export declare function getEndpoint(url: string): string;
3
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/monitoring/utils.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAM/C"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * W3C Trace Context fields ([trace-context](https://www.w3.org/TR/trace-context/)).
3
+ */
4
+ export interface W3CTraceFields {
5
+ traceparent?: string;
6
+ traceId?: string;
7
+ spanId?: string;
8
+ }
9
+ /**
10
+ * Parses W3C `traceparent` from outbound SDK request headers.
11
+ */
12
+ export declare function getW3CTraceFromHeaders(headers: Record<string, string>): W3CTraceFields;
13
+ //# sourceMappingURL=w3c-trace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"w3c-trace.d.ts","sourceRoot":"","sources":["../../src/monitoring/w3c-trace.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,cAAc,CAoBhB"}
@@ -1,3 +1,3 @@
1
1
  /** Auto-generated by scripts/sync-sdk-version.js — do not edit */
2
- export declare const SDK_VERSION = "3.0.0";
2
+ export declare const SDK_VERSION = "3.1.0";
3
3
  //# sourceMappingURL=sdk-version.d.ts.map