@servicetitan/datadog-rum 36.3.1 → 37.0.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 (116) hide show
  1. package/dist/before-send.d.ts +11 -1
  2. package/dist/before-send.d.ts.map +1 -1
  3. package/dist/before-send.js +2 -56
  4. package/dist/before-send.js.map +1 -1
  5. package/dist/build-allowed-tracing-urls.d.ts +9 -0
  6. package/dist/build-allowed-tracing-urls.d.ts.map +1 -0
  7. package/dist/build-allowed-tracing-urls.js +54 -0
  8. package/dist/build-allowed-tracing-urls.js.map +1 -0
  9. package/dist/build-before-send.d.ts +4 -0
  10. package/dist/build-before-send.d.ts.map +1 -0
  11. package/dist/build-before-send.js +64 -0
  12. package/dist/build-before-send.js.map +1 -0
  13. package/dist/bundle-state.d.ts +10 -0
  14. package/dist/bundle-state.d.ts.map +1 -0
  15. package/dist/bundle-state.js +10 -0
  16. package/dist/bundle-state.js.map +1 -0
  17. package/dist/create-impl.d.ts +8 -0
  18. package/dist/create-impl.d.ts.map +1 -0
  19. package/dist/create-impl.js +81 -0
  20. package/dist/create-impl.js.map +1 -0
  21. package/dist/datadog-provider.d.ts +2 -5
  22. package/dist/datadog-provider.d.ts.map +1 -1
  23. package/dist/datadog-provider.js +2 -2
  24. package/dist/datadog-provider.js.map +1 -1
  25. package/dist/enrich-event.d.ts +6 -0
  26. package/dist/enrich-event.d.ts.map +1 -0
  27. package/dist/enrich-event.js +33 -0
  28. package/dist/enrich-event.js.map +1 -0
  29. package/dist/get-shared.d.ts +10 -0
  30. package/dist/get-shared.d.ts.map +1 -0
  31. package/dist/get-shared.js +16 -0
  32. package/dist/get-shared.js.map +1 -0
  33. package/dist/handle-resource.d.ts +3 -0
  34. package/dist/handle-resource.d.ts.map +1 -0
  35. package/dist/handle-resource.js +27 -0
  36. package/dist/handle-resource.js.map +1 -0
  37. package/dist/index.d.ts +3 -0
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +3 -0
  40. package/dist/index.js.map +1 -1
  41. package/dist/init.d.ts +17 -0
  42. package/dist/init.d.ts.map +1 -0
  43. package/dist/init.js +28 -0
  44. package/dist/init.js.map +1 -0
  45. package/dist/runtime-override/constants.d.ts +2 -0
  46. package/dist/runtime-override/constants.d.ts.map +1 -0
  47. package/dist/runtime-override/constants.js +3 -0
  48. package/dist/runtime-override/constants.js.map +1 -0
  49. package/dist/runtime-override/dev-console.d.ts +12 -0
  50. package/dist/runtime-override/dev-console.d.ts.map +1 -0
  51. package/dist/runtime-override/dev-console.js +40 -0
  52. package/dist/runtime-override/dev-console.js.map +1 -0
  53. package/dist/runtime-override/index.d.ts +4 -0
  54. package/dist/runtime-override/index.d.ts.map +1 -0
  55. package/dist/runtime-override/index.js +5 -0
  56. package/dist/runtime-override/index.js.map +1 -0
  57. package/dist/runtime-override/override.d.ts +4 -0
  58. package/dist/runtime-override/override.d.ts.map +1 -0
  59. package/dist/runtime-override/override.js +35 -0
  60. package/dist/runtime-override/override.js.map +1 -0
  61. package/dist/set-user.d.ts +13 -0
  62. package/dist/set-user.d.ts.map +1 -0
  63. package/dist/set-user.js +22 -0
  64. package/dist/set-user.js.map +1 -0
  65. package/dist/shared-impl.d.ts +11 -0
  66. package/dist/shared-impl.d.ts.map +1 -0
  67. package/dist/shared-impl.js +3 -0
  68. package/dist/shared-impl.js.map +1 -0
  69. package/dist/types.d.ts +51 -0
  70. package/dist/types.d.ts.map +1 -0
  71. package/dist/types.js +3 -0
  72. package/dist/types.js.map +1 -0
  73. package/dist/use-rum-service.d.ts +12 -0
  74. package/dist/use-rum-service.d.ts.map +1 -0
  75. package/dist/use-rum-service.js +25 -0
  76. package/dist/use-rum-service.js.map +1 -0
  77. package/package.json +3 -3
  78. package/src/__mocks__/index.ts +6 -0
  79. package/src/__mocks__/init-config.ts +6 -0
  80. package/src/__mocks__/process-event.ts +20 -0
  81. package/src/__mocks__/reset-shared-impl.ts +8 -0
  82. package/src/__mocks__/tracing-urls.ts +30 -0
  83. package/src/__mocks__/types.ts +1 -0
  84. package/src/__tests__/before-send.test.ts +39 -87
  85. package/src/__tests__/build-allowed-tracing-urls.test.ts +120 -0
  86. package/src/__tests__/build-before-send.test.ts +193 -0
  87. package/src/__tests__/create-impl.test.ts +293 -0
  88. package/src/__tests__/datadog-provider.test.tsx +55 -25
  89. package/src/__tests__/enrich-event.test.ts +34 -0
  90. package/src/__tests__/get-shared.test.ts +56 -0
  91. package/src/__tests__/handle-resource.test.ts +76 -0
  92. package/src/__tests__/init.test.ts +69 -0
  93. package/src/__tests__/integration.test.ts +147 -0
  94. package/src/__tests__/set-user.test.ts +61 -0
  95. package/src/__tests__/use-rum-service.test.tsx +82 -0
  96. package/src/before-send.ts +13 -60
  97. package/src/build-allowed-tracing-urls.ts +53 -0
  98. package/src/build-before-send.ts +81 -0
  99. package/src/bundle-state.ts +9 -0
  100. package/src/create-impl.ts +94 -0
  101. package/src/datadog-provider.tsx +4 -6
  102. package/src/enrich-event.ts +38 -0
  103. package/src/get-shared.ts +24 -0
  104. package/src/handle-resource.ts +30 -0
  105. package/src/index.ts +3 -0
  106. package/src/init.ts +39 -0
  107. package/src/runtime-override/__tests__/dev-console.test.ts +158 -0
  108. package/src/runtime-override/__tests__/override.test.ts +109 -0
  109. package/src/runtime-override/constants.ts +1 -0
  110. package/src/runtime-override/dev-console.ts +56 -0
  111. package/src/runtime-override/index.ts +3 -0
  112. package/src/runtime-override/override.ts +41 -0
  113. package/src/set-user.ts +25 -0
  114. package/src/shared-impl.ts +9 -0
  115. package/src/types.ts +62 -0
  116. package/src/use-rum-service.ts +28 -0
@@ -1,3 +1,13 @@
1
- import type { RumInitConfiguration } from '@datadog/browser-rum';
1
+ import type { RumEvent, RumEventDomainContext, RumInitConfiguration } from '@datadog/browser-rum';
2
+ /**
3
+ * Used for `application.beforeSend`. Returning `false` drops the event app-wide;
4
+ * `void` / `true` passes it through.
5
+ */
6
+ export type ApplicationBeforeSendHandler = (event: RumEvent, context: RumEventDomainContext) => boolean | void;
7
+ /**
8
+ * Used for per-service `beforeSend`. Transform-only: the return value is
9
+ * ignored. Only `application.beforeSend` may drop events.
10
+ */
11
+ export type ServiceBeforeSendHandler = (event: RumEvent, context: RumEventDomainContext) => void;
2
12
  export declare function beforeSend(handler?: RumInitConfiguration['beforeSend']): NonNullable<RumInitConfiguration['beforeSend']>;
3
13
  //# sourceMappingURL=before-send.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"before-send.d.ts","sourceRoot":"","sources":["../src/before-send.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGR,oBAAoB,EAGvB,MAAM,sBAAsB,CAAC;AAiE9B,wBAAgB,UAAU,CACtB,OAAO,CAAC,EAAE,oBAAoB,CAAC,YAAY,CAAC,GAC7C,WAAW,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAC,CAcjD"}
1
+ {"version":3,"file":"before-send.d.ts","sourceRoot":"","sources":["../src/before-send.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,QAAQ,EACR,qBAAqB,EACrB,oBAAoB,EAEvB,MAAM,sBAAsB,CAAC;AAI9B;;;GAGG;AACH,MAAM,MAAM,4BAA4B,GAAG,CACvC,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,qBAAqB,KAC7B,OAAO,GAAG,IAAI,CAAC;AAEpB;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,qBAAqB,KAAK,IAAI,CAAC;AAEjG,wBAAgB,UAAU,CACtB,OAAO,CAAC,EAAE,oBAAoB,CAAC,YAAY,CAAC,GAC7C,WAAW,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAC,CAcjD"}
@@ -1,59 +1,5 @@
1
- const SERVICE_REGEX = /unpkg\.servicetitan\.com\/@servicetitan\/(?<service>[\w-]+)(?:@(?<version>\d+\.\d+\.\d+(?:-[\w.]+)?))?/;
2
- function isSameDomainRequest(url) {
3
- return new URL(url).hostname === window.location.hostname;
4
- }
5
- function parseService(event, input) {
6
- var _match_groups, _match_groups1;
7
- const match = input === null || input === void 0 ? void 0 : input.match(SERVICE_REGEX);
8
- const service = match === null || match === void 0 ? void 0 : (_match_groups = match.groups) === null || _match_groups === void 0 ? void 0 : _match_groups.service;
9
- const version = match === null || match === void 0 ? void 0 : (_match_groups1 = match.groups) === null || _match_groups1 === void 0 ? void 0 : _match_groups1.version;
10
- if (service) {
11
- event.service = service;
12
- event.version = version !== null && version !== void 0 ? version : 'unknown';
13
- return true;
14
- }
15
- return false;
16
- }
17
- /**
18
- * See https://docs.datadoghq.com/real_user_monitoring/browser/advanced_configuration/?tab=npm#micro-frontend
19
- */ function enrichEvent(event, context) {
20
- var _ref;
21
- var _event_error, _event_error1, _event_resource;
22
- const stack = (_ref = context && 'handlingStack' in context ? context.handlingStack : undefined) !== null && _ref !== void 0 ? _ref : event.type === 'error' ? (_event_error = event.error) === null || _event_error === void 0 ? void 0 : _event_error.stack : undefined;
23
- const message = event.type === 'error' ? (_event_error1 = event.error) === null || _event_error1 === void 0 ? void 0 : _event_error1.message : undefined;
24
- const url = event.type === 'resource' ? (_event_resource = event.resource) === null || _event_resource === void 0 ? void 0 : _event_resource.url : undefined;
25
- for (const source of [
26
- stack,
27
- message,
28
- url
29
- ]){
30
- if (parseService(event, source)) {
31
- break;
32
- }
33
- }
34
- }
35
- function handleResource(event, context) {
36
- if (!isSameDomainRequest(event.resource.url)) {
37
- return;
38
- }
39
- let cfRay = undefined;
40
- switch(event.resource.type){
41
- case 'fetch':
42
- var _context_response;
43
- cfRay = (_context_response = context.response) === null || _context_response === void 0 ? void 0 : _context_response.headers.get('cf-ray');
44
- break;
45
- case 'xhr':
46
- var _context_xhr;
47
- cfRay = (_context_xhr = context.xhr) === null || _context_xhr === void 0 ? void 0 : _context_xhr.getResponseHeader('cf-ray');
48
- break;
49
- }
50
- if (cfRay) {
51
- event.context = {
52
- ...event.context,
53
- cfRay
54
- };
55
- }
56
- }
1
+ import { enrichEvent } from './enrich-event';
2
+ import { handleResource } from './handle-resource';
57
3
  export function beforeSend(handler) {
58
4
  return function(event, context) {
59
5
  try {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/before-send.ts"],"sourcesContent":["import type {\n RumEvent,\n RumEventDomainContext,\n RumInitConfiguration,\n RumResourceEvent,\n RumResourceEventDomainContext,\n} from '@datadog/browser-rum';\n\nconst SERVICE_REGEX =\n /unpkg\\.servicetitan\\.com\\/@servicetitan\\/(?<service>[\\w-]+)(?:@(?<version>\\d+\\.\\d+\\.\\d+(?:-[\\w.]+)?))?/;\n\nfunction isSameDomainRequest(url: string) {\n return new URL(url).hostname === window.location.hostname;\n}\n\nfunction parseService(event: RumEvent, input: string | undefined) {\n const match = input?.match(SERVICE_REGEX);\n\n const service = match?.groups?.service;\n const version = match?.groups?.version;\n\n if (service) {\n event.service = service;\n event.version = version ?? 'unknown';\n return true;\n }\n\n return false;\n}\n\n/**\n * See https://docs.datadoghq.com/real_user_monitoring/browser/advanced_configuration/?tab=npm#micro-frontend\n */\nfunction enrichEvent(event: RumEvent, context: RumEventDomainContext): void {\n const stack =\n (context && 'handlingStack' in context ? context.handlingStack : undefined) ??\n (event.type === 'error' ? event.error?.stack : undefined);\n\n const message = event.type === 'error' ? event.error?.message : undefined;\n\n const url = event.type === 'resource' ? event.resource?.url : undefined;\n\n for (const source of [stack, message, url]) {\n if (parseService(event, source)) {\n break;\n }\n }\n}\n\nfunction handleResource(event: RumResourceEvent, context: RumResourceEventDomainContext): void {\n if (!isSameDomainRequest(event.resource.url)) {\n return;\n }\n\n let cfRay: string | undefined | null = undefined;\n\n switch (event.resource.type) {\n case 'fetch':\n cfRay = context.response?.headers.get('cf-ray');\n break;\n\n case 'xhr':\n cfRay = context.xhr?.getResponseHeader('cf-ray');\n break;\n }\n\n if (cfRay) {\n event.context = { ...event.context, cfRay };\n }\n}\n\nexport function beforeSend(\n handler?: RumInitConfiguration['beforeSend']\n): NonNullable<RumInitConfiguration['beforeSend']> {\n return function (event: RumEvent, context: RumEventDomainContext) {\n try {\n if (event.type === 'resource') {\n handleResource(event, context as RumResourceEventDomainContext);\n }\n\n enrichEvent(event, context);\n\n return handler?.(event, context) ?? true;\n } catch {} // eslint-disable-line no-empty\n\n return true;\n };\n}\n"],"names":["SERVICE_REGEX","isSameDomainRequest","url","URL","hostname","window","location","parseService","event","input","match","service","groups","version","enrichEvent","context","stack","handlingStack","undefined","type","error","message","resource","source","handleResource","cfRay","response","headers","get","xhr","getResponseHeader","beforeSend","handler"],"mappings":"AAQA,MAAMA,gBACF;AAEJ,SAASC,oBAAoBC,GAAW;IACpC,OAAO,IAAIC,IAAID,KAAKE,QAAQ,KAAKC,OAAOC,QAAQ,CAACF,QAAQ;AAC7D;AAEA,SAASG,aAAaC,KAAe,EAAEC,KAAyB;QAG5CC,eACAA;IAHhB,MAAMA,QAAQD,kBAAAA,4BAAAA,MAAOC,KAAK,CAACV;IAE3B,MAAMW,UAAUD,kBAAAA,6BAAAA,gBAAAA,MAAOE,MAAM,cAAbF,oCAAAA,cAAeC,OAAO;IACtC,MAAME,UAAUH,kBAAAA,6BAAAA,iBAAAA,MAAOE,MAAM,cAAbF,qCAAAA,eAAeG,OAAO;IAEtC,IAAIF,SAAS;QACTH,MAAMG,OAAO,GAAGA;QAChBH,MAAMK,OAAO,GAAGA,oBAAAA,qBAAAA,UAAW;QAC3B,OAAO;IACX;IAEA,OAAO;AACX;AAEA;;CAEC,GACD,SAASC,YAAYN,KAAe,EAAEO,OAA8B;QAE3DA;QACyBP,cAEWA,eAEDA;IANxC,MAAMQ,SACDD,OAAAA,WAAW,mBAAmBA,UAAUA,QAAQE,aAAa,GAAGC,uBAAhEH,kBAAAA,OACAP,MAAMW,IAAI,KAAK,WAAUX,eAAAA,MAAMY,KAAK,cAAXZ,mCAAAA,aAAaQ,KAAK,GAAGE;IAEnD,MAAMG,UAAUb,MAAMW,IAAI,KAAK,WAAUX,gBAAAA,MAAMY,KAAK,cAAXZ,oCAAAA,cAAaa,OAAO,GAAGH;IAEhE,MAAMhB,MAAMM,MAAMW,IAAI,KAAK,cAAaX,kBAAAA,MAAMc,QAAQ,cAAdd,sCAAAA,gBAAgBN,GAAG,GAAGgB;IAE9D,KAAK,MAAMK,UAAU;QAACP;QAAOK;QAASnB;KAAI,CAAE;QACxC,IAAIK,aAAaC,OAAOe,SAAS;YAC7B;QACJ;IACJ;AACJ;AAEA,SAASC,eAAehB,KAAuB,EAAEO,OAAsC;IACnF,IAAI,CAACd,oBAAoBO,MAAMc,QAAQ,CAACpB,GAAG,GAAG;QAC1C;IACJ;IAEA,IAAIuB,QAAmCP;IAEvC,OAAQV,MAAMc,QAAQ,CAACH,IAAI;QACvB,KAAK;gBACOJ;YAARU,SAAQV,oBAAAA,QAAQW,QAAQ,cAAhBX,wCAAAA,kBAAkBY,OAAO,CAACC,GAAG,CAAC;YACtC;QAEJ,KAAK;gBACOb;YAARU,SAAQV,eAAAA,QAAQc,GAAG,cAAXd,mCAAAA,aAAae,iBAAiB,CAAC;YACvC;IACR;IAEA,IAAIL,OAAO;QACPjB,MAAMO,OAAO,GAAG;YAAE,GAAGP,MAAMO,OAAO;YAAEU;QAAM;IAC9C;AACJ;AAEA,OAAO,SAASM,WACZC,OAA4C;IAE5C,OAAO,SAAUxB,KAAe,EAAEO,OAA8B;QAC5D,IAAI;;YACA,IAAIP,MAAMW,IAAI,KAAK,YAAY;gBAC3BK,eAAehB,OAAOO;YAC1B;YAEAD,YAAYN,OAAOO;YAEnB,eAAOiB,oBAAAA,8BAAAA,QAAUxB,OAAOO,+CAAY;QACxC,EAAE,eAAM,CAAC,EAAE,+BAA+B;QAE1C,OAAO;IACX;AACJ"}
1
+ {"version":3,"sources":["../src/before-send.ts"],"sourcesContent":["import type {\n RumEvent,\n RumEventDomainContext,\n RumInitConfiguration,\n RumResourceEventDomainContext,\n} from '@datadog/browser-rum';\nimport { enrichEvent } from './enrich-event';\nimport { handleResource } from './handle-resource';\n\n/**\n * Used for `application.beforeSend`. Returning `false` drops the event app-wide;\n * `void` / `true` passes it through.\n */\nexport type ApplicationBeforeSendHandler = (\n event: RumEvent,\n context: RumEventDomainContext\n) => boolean | void;\n\n/**\n * Used for per-service `beforeSend`. Transform-only: the return value is\n * ignored. Only `application.beforeSend` may drop events.\n */\nexport type ServiceBeforeSendHandler = (event: RumEvent, context: RumEventDomainContext) => void;\n\nexport function beforeSend(\n handler?: RumInitConfiguration['beforeSend']\n): NonNullable<RumInitConfiguration['beforeSend']> {\n return function (event: RumEvent, context: RumEventDomainContext) {\n try {\n if (event.type === 'resource') {\n handleResource(event, context as RumResourceEventDomainContext);\n }\n\n enrichEvent(event, context);\n\n return handler?.(event, context) ?? true;\n } catch {} // eslint-disable-line no-empty\n\n return true;\n };\n}\n"],"names":["enrichEvent","handleResource","beforeSend","handler","event","context","type"],"mappings":"AAMA,SAASA,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,cAAc,QAAQ,oBAAoB;AAiBnD,OAAO,SAASC,WACZC,OAA4C;IAE5C,OAAO,SAAUC,KAAe,EAAEC,OAA8B;QAC5D,IAAI;;YACA,IAAID,MAAME,IAAI,KAAK,YAAY;gBAC3BL,eAAeG,OAAOC;YAC1B;YAEAL,YAAYI,OAAOC;YAEnB,eAAOF,oBAAAA,8BAAAA,QAAUC,OAAOC,+CAAY;QACxC,EAAE,eAAM,CAAC,EAAE,+BAA+B;QAE1C,OAAO;IACX;AACJ"}
@@ -0,0 +1,9 @@
1
+ import type { RumInitConfiguration } from '@datadog/browser-rum';
2
+ import type { State } from './types';
3
+ /**
4
+ * Emits one dynamic wrapper per `PropagatorType`. Each wrapper's `match` walks
5
+ * registered services and returns true if any matcher registered under that
6
+ * propagator matches. Late-loading MFEs work fully dynamically.
7
+ */
8
+ export declare function buildAllowedTracingUrls(state: State): NonNullable<RumInitConfiguration['allowedTracingUrls']>;
9
+ //# sourceMappingURL=build-allowed-tracing-urls.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-allowed-tracing-urls.d.ts","sourceRoot":"","sources":["../src/build-allowed-tracing-urls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA+B,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC9F,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AA0BrC;;;;GAIG;AACH,wBAAgB,uBAAuB,CACnC,KAAK,EAAE,KAAK,GACb,WAAW,CAAC,oBAAoB,CAAC,oBAAoB,CAAC,CAAC,CAkBzD"}
@@ -0,0 +1,54 @@
1
+ const PROPAGATOR_TYPES = [
2
+ 'datadog',
3
+ 'tracecontext',
4
+ 'b3',
5
+ 'b3multi'
6
+ ];
7
+ /**
8
+ * Mirrors `@datadog/browser-rum-core`'s tracing URL match semantics:
9
+ * - strings are prefix-matched (SDK passes `useStartsWith=true` for tracing URLs)
10
+ *
11
+ * Per-call try/catch mirrors the SDK's `matchList`: a throwing user function or
12
+ * malformed RegExp only loses its own match decision rather than breaking the
13
+ * wrapper for every other matcher.
14
+ */ function matchOption(opt, url) {
15
+ try {
16
+ if (typeof opt === 'function') {
17
+ return opt(url);
18
+ }
19
+ if (typeof opt === 'string') {
20
+ return url.startsWith(opt);
21
+ }
22
+ return opt.test(url);
23
+ } catch (unused) {
24
+ return false;
25
+ }
26
+ }
27
+ /**
28
+ * Emits one dynamic wrapper per `PropagatorType`. Each wrapper's `match` walks
29
+ * registered services and returns true if any matcher registered under that
30
+ * propagator matches. Late-loading MFEs work fully dynamically.
31
+ */ export function buildAllowedTracingUrls(state) {
32
+ return PROPAGATOR_TYPES.map((pt)=>({
33
+ match: (url)=>{
34
+ for (const entry of state.services.values()){
35
+ var _entry_allowedTracingUrls;
36
+ const matchers = (_entry_allowedTracingUrls = entry.allowedTracingUrls) === null || _entry_allowedTracingUrls === void 0 ? void 0 : _entry_allowedTracingUrls[pt];
37
+ if (!matchers) {
38
+ continue;
39
+ }
40
+ for (const m of matchers){
41
+ if (matchOption(m, url)) {
42
+ return true;
43
+ }
44
+ }
45
+ }
46
+ return false;
47
+ },
48
+ propagatorTypes: [
49
+ pt
50
+ ]
51
+ }));
52
+ }
53
+
54
+ //# sourceMappingURL=build-allowed-tracing-urls.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/build-allowed-tracing-urls.ts"],"sourcesContent":["import type { MatchOption, PropagatorType, RumInitConfiguration } from '@datadog/browser-rum';\nimport type { State } from './types';\n\nconst PROPAGATOR_TYPES: readonly PropagatorType[] = ['datadog', 'tracecontext', 'b3', 'b3multi'];\n\n/**\n * Mirrors `@datadog/browser-rum-core`'s tracing URL match semantics:\n * - strings are prefix-matched (SDK passes `useStartsWith=true` for tracing URLs)\n *\n * Per-call try/catch mirrors the SDK's `matchList`: a throwing user function or\n * malformed RegExp only loses its own match decision rather than breaking the\n * wrapper for every other matcher.\n */\nfunction matchOption(opt: MatchOption, url: string): boolean {\n try {\n if (typeof opt === 'function') {\n return opt(url);\n }\n if (typeof opt === 'string') {\n return url.startsWith(opt);\n }\n return opt.test(url);\n } catch {\n return false;\n }\n}\n\n/**\n * Emits one dynamic wrapper per `PropagatorType`. Each wrapper's `match` walks\n * registered services and returns true if any matcher registered under that\n * propagator matches. Late-loading MFEs work fully dynamically.\n */\nexport function buildAllowedTracingUrls(\n state: State\n): NonNullable<RumInitConfiguration['allowedTracingUrls']> {\n return PROPAGATOR_TYPES.map(pt => ({\n match: (url: string) => {\n for (const entry of state.services.values()) {\n const matchers = entry.allowedTracingUrls?.[pt];\n if (!matchers) {\n continue;\n }\n for (const m of matchers) {\n if (matchOption(m, url)) {\n return true;\n }\n }\n }\n return false;\n },\n propagatorTypes: [pt],\n }));\n}\n"],"names":["PROPAGATOR_TYPES","matchOption","opt","url","startsWith","test","buildAllowedTracingUrls","state","map","pt","match","entry","services","values","matchers","allowedTracingUrls","m","propagatorTypes"],"mappings":"AAGA,MAAMA,mBAA8C;IAAC;IAAW;IAAgB;IAAM;CAAU;AAEhG;;;;;;;CAOC,GACD,SAASC,YAAYC,GAAgB,EAAEC,GAAW;IAC9C,IAAI;QACA,IAAI,OAAOD,QAAQ,YAAY;YAC3B,OAAOA,IAAIC;QACf;QACA,IAAI,OAAOD,QAAQ,UAAU;YACzB,OAAOC,IAAIC,UAAU,CAACF;QAC1B;QACA,OAAOA,IAAIG,IAAI,CAACF;IACpB,EAAE,eAAM;QACJ,OAAO;IACX;AACJ;AAEA;;;;CAIC,GACD,OAAO,SAASG,wBACZC,KAAY;IAEZ,OAAOP,iBAAiBQ,GAAG,CAACC,CAAAA,KAAO,CAAA;YAC/BC,OAAO,CAACP;gBACJ,KAAK,MAAMQ,SAASJ,MAAMK,QAAQ,CAACC,MAAM,GAAI;wBACxBF;oBAAjB,MAAMG,YAAWH,4BAAAA,MAAMI,kBAAkB,cAAxBJ,gDAAAA,yBAA0B,CAACF,GAAG;oBAC/C,IAAI,CAACK,UAAU;wBACX;oBACJ;oBACA,KAAK,MAAME,KAAKF,SAAU;wBACtB,IAAIb,YAAYe,GAAGb,MAAM;4BACrB,OAAO;wBACX;oBACJ;gBACJ;gBACA,OAAO;YACX;YACAc,iBAAiB;gBAACR;aAAG;QACzB,CAAA;AACJ"}
@@ -0,0 +1,4 @@
1
+ import type { RumInitConfiguration } from '@datadog/browser-rum';
2
+ import type { State } from './types';
3
+ export declare function buildBeforeSend(state: State): NonNullable<RumInitConfiguration['beforeSend']>;
4
+ //# sourceMappingURL=build-before-send.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-before-send.d.ts","sourceRoot":"","sources":["../src/build-before-send.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGR,oBAAoB,EAEvB,MAAM,sBAAsB,CAAC;AAI9B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAyDrC,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,WAAW,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAC,CAc7F"}
@@ -0,0 +1,64 @@
1
+ import { enrichEvent } from './enrich-event';
2
+ import { handleResource } from './handle-resource';
3
+ function applyBuiltIn(event, context) {
4
+ if (event.type === 'resource') {
5
+ handleResource(event, context);
6
+ }
7
+ enrichEvent(event, context);
8
+ }
9
+ function callApplicationHandler(handler, event, context) {
10
+ try {
11
+ return handler(event, context) !== false;
12
+ } catch (unused) {
13
+ return true;
14
+ }
15
+ }
16
+ function callServiceHandler(handler, event, context) {
17
+ try {
18
+ handler(event, context);
19
+ } catch (unused) {
20
+ // Fail-open: a service handler may not drop or block events.
21
+ }
22
+ }
23
+ function applyApplication(state, event, context) {
24
+ if (state.applicationBeforeSend) {
25
+ return callApplicationHandler(state.applicationBeforeSend, event, context);
26
+ }
27
+ return true;
28
+ }
29
+ function applyServiceSpecific(state, event, context) {
30
+ const serviceKey = event.service;
31
+ if (!serviceKey) {
32
+ return;
33
+ }
34
+ const entry = state.services.get(serviceKey);
35
+ if (!entry) {
36
+ return;
37
+ }
38
+ if (entry.beforeSend) {
39
+ callServiceHandler(entry.beforeSend, event, context);
40
+ }
41
+ if (entry.context) {
42
+ event.context = {
43
+ ...event.context,
44
+ ...entry.context
45
+ };
46
+ }
47
+ }
48
+ export function buildBeforeSend(state) {
49
+ return function(event, context) {
50
+ try {
51
+ applyBuiltIn(event, context);
52
+ if (!applyApplication(state, event, context)) {
53
+ return false;
54
+ }
55
+ applyServiceSpecific(state, event, context);
56
+ return true;
57
+ } catch (unused) {
58
+ // Fail-open: prefer noisy data over no data.
59
+ return true;
60
+ }
61
+ };
62
+ }
63
+
64
+ //# sourceMappingURL=build-before-send.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/build-before-send.ts"],"sourcesContent":["import type {\n RumEvent,\n RumEventDomainContext,\n RumInitConfiguration,\n RumResourceEventDomainContext,\n} from '@datadog/browser-rum';\nimport type { ApplicationBeforeSendHandler, ServiceBeforeSendHandler } from './before-send';\nimport { enrichEvent } from './enrich-event';\nimport { handleResource } from './handle-resource';\nimport type { State } from './types';\n\nfunction applyBuiltIn(event: RumEvent, context: RumEventDomainContext): void {\n if (event.type === 'resource') {\n handleResource(event, context as RumResourceEventDomainContext);\n }\n enrichEvent(event, context);\n}\n\nfunction callApplicationHandler(\n handler: ApplicationBeforeSendHandler,\n event: RumEvent,\n context: RumEventDomainContext\n): boolean {\n try {\n return handler(event, context) !== false;\n } catch {\n return true;\n }\n}\n\nfunction callServiceHandler(\n handler: ServiceBeforeSendHandler,\n event: RumEvent,\n context: RumEventDomainContext\n): void {\n try {\n handler(event, context);\n } catch {\n // Fail-open: a service handler may not drop or block events.\n }\n}\n\nfunction applyApplication(state: State, event: RumEvent, context: RumEventDomainContext): boolean {\n if (state.applicationBeforeSend) {\n return callApplicationHandler(state.applicationBeforeSend, event, context);\n }\n return true;\n}\n\nfunction applyServiceSpecific(state: State, event: RumEvent, context: RumEventDomainContext): void {\n const serviceKey = event.service;\n if (!serviceKey) {\n return;\n }\n const entry = state.services.get(serviceKey);\n if (!entry) {\n return;\n }\n if (entry.beforeSend) {\n callServiceHandler(entry.beforeSend, event, context);\n }\n if (entry.context) {\n event.context = { ...event.context, ...entry.context };\n }\n}\n\nexport function buildBeforeSend(state: State): NonNullable<RumInitConfiguration['beforeSend']> {\n return function (event: RumEvent, context: RumEventDomainContext) {\n try {\n applyBuiltIn(event, context);\n if (!applyApplication(state, event, context)) {\n return false;\n }\n applyServiceSpecific(state, event, context);\n return true;\n } catch {\n // Fail-open: prefer noisy data over no data.\n return true;\n }\n };\n}\n"],"names":["enrichEvent","handleResource","applyBuiltIn","event","context","type","callApplicationHandler","handler","callServiceHandler","applyApplication","state","applicationBeforeSend","applyServiceSpecific","serviceKey","service","entry","services","get","beforeSend","buildBeforeSend"],"mappings":"AAOA,SAASA,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,cAAc,QAAQ,oBAAoB;AAGnD,SAASC,aAAaC,KAAe,EAAEC,OAA8B;IACjE,IAAID,MAAME,IAAI,KAAK,YAAY;QAC3BJ,eAAeE,OAAOC;IAC1B;IACAJ,YAAYG,OAAOC;AACvB;AAEA,SAASE,uBACLC,OAAqC,EACrCJ,KAAe,EACfC,OAA8B;IAE9B,IAAI;QACA,OAAOG,QAAQJ,OAAOC,aAAa;IACvC,EAAE,eAAM;QACJ,OAAO;IACX;AACJ;AAEA,SAASI,mBACLD,OAAiC,EACjCJ,KAAe,EACfC,OAA8B;IAE9B,IAAI;QACAG,QAAQJ,OAAOC;IACnB,EAAE,eAAM;IACJ,6DAA6D;IACjE;AACJ;AAEA,SAASK,iBAAiBC,KAAY,EAAEP,KAAe,EAAEC,OAA8B;IACnF,IAAIM,MAAMC,qBAAqB,EAAE;QAC7B,OAAOL,uBAAuBI,MAAMC,qBAAqB,EAAER,OAAOC;IACtE;IACA,OAAO;AACX;AAEA,SAASQ,qBAAqBF,KAAY,EAAEP,KAAe,EAAEC,OAA8B;IACvF,MAAMS,aAAaV,MAAMW,OAAO;IAChC,IAAI,CAACD,YAAY;QACb;IACJ;IACA,MAAME,QAAQL,MAAMM,QAAQ,CAACC,GAAG,CAACJ;IACjC,IAAI,CAACE,OAAO;QACR;IACJ;IACA,IAAIA,MAAMG,UAAU,EAAE;QAClBV,mBAAmBO,MAAMG,UAAU,EAAEf,OAAOC;IAChD;IACA,IAAIW,MAAMX,OAAO,EAAE;QACfD,MAAMC,OAAO,GAAG;YAAE,GAAGD,MAAMC,OAAO;YAAE,GAAGW,MAAMX,OAAO;QAAC;IACzD;AACJ;AAEA,OAAO,SAASe,gBAAgBT,KAAY;IACxC,OAAO,SAAUP,KAAe,EAAEC,OAA8B;QAC5D,IAAI;YACAF,aAAaC,OAAOC;YACpB,IAAI,CAACK,iBAAiBC,OAAOP,OAAOC,UAAU;gBAC1C,OAAO;YACX;YACAQ,qBAAqBF,OAAOP,OAAOC;YACnC,OAAO;QACX,EAAE,eAAM;YACJ,6CAA6C;YAC7C,OAAO;QACX;IACJ;AACJ"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Bundle-local state. Each bundle that loads `@servicetitan/datadog-rum` gets
3
+ * its own copy of this module; nothing here lives on `globalThis`. The bundle
4
+ * whose `init` call wins the SDK init race sets `isSdkInitializer` here, and
5
+ * only its own bundle's `setUser` reads `true` from it.
6
+ */
7
+ export declare const bundleState: {
8
+ isSdkInitializer: boolean;
9
+ };
10
+ //# sourceMappingURL=bundle-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle-state.d.ts","sourceRoot":"","sources":["../src/bundle-state.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,WAAW;;CAEvB,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Bundle-local state. Each bundle that loads `@servicetitan/datadog-rum` gets
3
+ * its own copy of this module; nothing here lives on `globalThis`. The bundle
4
+ * whose `init` call wins the SDK init race sets `isSdkInitializer` here, and
5
+ * only its own bundle's `setUser` reads `true` from it.
6
+ */ export const bundleState = {
7
+ isSdkInitializer: false
8
+ };
9
+
10
+ //# sourceMappingURL=bundle-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/bundle-state.ts"],"sourcesContent":["/**\n * Bundle-local state. Each bundle that loads `@servicetitan/datadog-rum` gets\n * its own copy of this module; nothing here lives on `globalThis`. The bundle\n * whose `init` call wins the SDK init race sets `isSdkInitializer` here, and\n * only its own bundle's `setUser` reads `true` from it.\n */\nexport const bundleState = {\n isSdkInitializer: false,\n};\n"],"names":["bundleState","isSdkInitializer"],"mappings":"AAAA;;;;;CAKC,GACD,OAAO,MAAMA,cAAc;IACvBC,kBAAkB;AACtB,EAAE"}
@@ -0,0 +1,8 @@
1
+ import type { SharedImpl } from './shared-impl';
2
+ /**
3
+ * Interop surface: stored on globalThis, shared across independently
4
+ * deployed bundles. First bundle to load wins. Append-only — never
5
+ * remove or change method signatures.
6
+ */
7
+ export declare function createImpl(): SharedImpl;
8
+ //# sourceMappingURL=create-impl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-impl.d.ts","sourceRoot":"","sources":["../src/create-impl.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAShD;;;;GAIG;AACH,wBAAgB,UAAU,IAAI,UAAU,CA2EvC"}
@@ -0,0 +1,81 @@
1
+ import { datadogRum } from '@datadog/browser-rum';
2
+ import { buildAllowedTracingUrls } from './build-allowed-tracing-urls';
3
+ import { buildBeforeSend } from './build-before-send';
4
+ import { DATADOG_RUM_FOR_DEV, installDevConsole, isForceEnabled } from './runtime-override';
5
+ const DEFAULTS = {
6
+ sessionSampleRate: 100,
7
+ sessionReplaySampleRate: 0,
8
+ defaultPrivacyLevel: 'mask-user-input'
9
+ };
10
+ /**
11
+ * Interop surface: stored on globalThis, shared across independently
12
+ * deployed bundles. First bundle to load wins. Append-only — never
13
+ * remove or change method signatures.
14
+ */ export function createImpl() {
15
+ let initialized = false;
16
+ const state = {
17
+ services: new Map()
18
+ };
19
+ function initializeSdk(service, application, enabled) {
20
+ if (initialized) {
21
+ // eslint-disable-next-line no-console
22
+ console.info('[datadog-rum] init: application config ignored; SDK already initialized.');
23
+ return false;
24
+ }
25
+ if (datadogRum.getInitConfiguration()) {
26
+ // eslint-disable-next-line no-console
27
+ console.warn('[datadog-rum] init: SDK was initialized outside the facade; service handlers will not fire.');
28
+ return false;
29
+ }
30
+ const { beforeSend: appBeforeSend, ...sdkConfigPart } = application;
31
+ if (appBeforeSend) {
32
+ state.applicationBeforeSend = appBeforeSend;
33
+ }
34
+ datadogRum.init({
35
+ ...DEFAULTS,
36
+ ...sdkConfigPart,
37
+ service: service.name,
38
+ beforeSend: buildBeforeSend(state),
39
+ allowedTracingUrls: buildAllowedTracingUrls(state)
40
+ });
41
+ if (!enabled) {
42
+ datadogRum.setGlobalContextProperty(DATADOG_RUM_FOR_DEV, true);
43
+ }
44
+ initialized = true;
45
+ return true;
46
+ }
47
+ function registerService({ name, ...reg }) {
48
+ const existing = state.services.get(name);
49
+ state.services.set(name, {
50
+ ...reg,
51
+ context: existing === null || existing === void 0 ? void 0 : existing.context
52
+ });
53
+ }
54
+ return {
55
+ init ({ service, application, enabled = true }) {
56
+ let initializedSdk = false;
57
+ if (application) {
58
+ if (!enabled) {
59
+ installDevConsole();
60
+ }
61
+ if (enabled || isForceEnabled()) {
62
+ initializedSdk = initializeSdk(service, application, enabled);
63
+ }
64
+ }
65
+ registerService(service);
66
+ return {
67
+ cleanup: ()=>state.services.delete(service.name),
68
+ initializedSdk
69
+ };
70
+ },
71
+ setServiceContext (key, context) {
72
+ const existing = state.services.get(key);
73
+ state.services.set(key, {
74
+ ...existing,
75
+ context
76
+ });
77
+ }
78
+ };
79
+ }
80
+
81
+ //# sourceMappingURL=create-impl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/create-impl.ts"],"sourcesContent":["import { datadogRum } from '@datadog/browser-rum';\nimport { buildAllowedTracingUrls } from './build-allowed-tracing-urls';\nimport { buildBeforeSend } from './build-before-send';\nimport { DATADOG_RUM_FOR_DEV, installDevConsole, isForceEnabled } from './runtime-override';\nimport type { SharedImpl } from './shared-impl';\nimport type { ApplicationConfig, ServiceConfig, State } from './types';\n\nconst DEFAULTS = {\n sessionSampleRate: 100,\n sessionReplaySampleRate: 0,\n defaultPrivacyLevel: 'mask-user-input',\n} as const;\n\n/**\n * Interop surface: stored on globalThis, shared across independently\n * deployed bundles. First bundle to load wins. Append-only — never\n * remove or change method signatures.\n */\nexport function createImpl(): SharedImpl {\n let initialized = false;\n const state: State = {\n services: new Map(),\n };\n\n function initializeSdk(\n service: ServiceConfig,\n application: ApplicationConfig,\n enabled: boolean\n ): boolean {\n if (initialized) {\n // eslint-disable-next-line no-console\n console.info(\n '[datadog-rum] init: application config ignored; SDK already initialized.'\n );\n return false;\n }\n if (datadogRum.getInitConfiguration()) {\n // eslint-disable-next-line no-console\n console.warn(\n '[datadog-rum] init: SDK was initialized outside the facade; service handlers will not fire.'\n );\n return false;\n }\n\n const { beforeSend: appBeforeSend, ...sdkConfigPart } = application;\n if (appBeforeSend) {\n state.applicationBeforeSend = appBeforeSend;\n }\n datadogRum.init({\n ...DEFAULTS,\n ...sdkConfigPart,\n service: service.name,\n beforeSend: buildBeforeSend(state),\n allowedTracingUrls: buildAllowedTracingUrls(state),\n });\n if (!enabled) {\n datadogRum.setGlobalContextProperty(DATADOG_RUM_FOR_DEV, true);\n }\n initialized = true;\n return true;\n }\n\n function registerService({ name, ...reg }: ServiceConfig): void {\n const existing = state.services.get(name);\n state.services.set(name, { ...reg, context: existing?.context });\n }\n\n return {\n init({ service, application, enabled = true }) {\n let initializedSdk = false;\n\n if (application) {\n if (!enabled) {\n installDevConsole();\n }\n if (enabled || isForceEnabled()) {\n initializedSdk = initializeSdk(service, application, enabled);\n }\n }\n\n registerService(service);\n\n return {\n cleanup: () => state.services.delete(service.name),\n initializedSdk,\n };\n },\n\n setServiceContext(key, context) {\n const existing = state.services.get(key);\n state.services.set(key, { ...existing, context });\n },\n };\n}\n"],"names":["datadogRum","buildAllowedTracingUrls","buildBeforeSend","DATADOG_RUM_FOR_DEV","installDevConsole","isForceEnabled","DEFAULTS","sessionSampleRate","sessionReplaySampleRate","defaultPrivacyLevel","createImpl","initialized","state","services","Map","initializeSdk","service","application","enabled","console","info","getInitConfiguration","warn","beforeSend","appBeforeSend","sdkConfigPart","applicationBeforeSend","init","name","allowedTracingUrls","setGlobalContextProperty","registerService","reg","existing","get","set","context","initializedSdk","cleanup","delete","setServiceContext","key"],"mappings":"AAAA,SAASA,UAAU,QAAQ,uBAAuB;AAClD,SAASC,uBAAuB,QAAQ,+BAA+B;AACvE,SAASC,eAAe,QAAQ,sBAAsB;AACtD,SAASC,mBAAmB,EAAEC,iBAAiB,EAAEC,cAAc,QAAQ,qBAAqB;AAI5F,MAAMC,WAAW;IACbC,mBAAmB;IACnBC,yBAAyB;IACzBC,qBAAqB;AACzB;AAEA;;;;CAIC,GACD,OAAO,SAASC;IACZ,IAAIC,cAAc;IAClB,MAAMC,QAAe;QACjBC,UAAU,IAAIC;IAClB;IAEA,SAASC,cACLC,OAAsB,EACtBC,WAA8B,EAC9BC,OAAgB;QAEhB,IAAIP,aAAa;YACb,sCAAsC;YACtCQ,QAAQC,IAAI,CACR;YAEJ,OAAO;QACX;QACA,IAAIpB,WAAWqB,oBAAoB,IAAI;YACnC,sCAAsC;YACtCF,QAAQG,IAAI,CACR;YAEJ,OAAO;QACX;QAEA,MAAM,EAAEC,YAAYC,aAAa,EAAE,GAAGC,eAAe,GAAGR;QACxD,IAAIO,eAAe;YACfZ,MAAMc,qBAAqB,GAAGF;QAClC;QACAxB,WAAW2B,IAAI,CAAC;YACZ,GAAGrB,QAAQ;YACX,GAAGmB,aAAa;YAChBT,SAASA,QAAQY,IAAI;YACrBL,YAAYrB,gBAAgBU;YAC5BiB,oBAAoB5B,wBAAwBW;QAChD;QACA,IAAI,CAACM,SAAS;YACVlB,WAAW8B,wBAAwB,CAAC3B,qBAAqB;QAC7D;QACAQ,cAAc;QACd,OAAO;IACX;IAEA,SAASoB,gBAAgB,EAAEH,IAAI,EAAE,GAAGI,KAAoB;QACpD,MAAMC,WAAWrB,MAAMC,QAAQ,CAACqB,GAAG,CAACN;QACpChB,MAAMC,QAAQ,CAACsB,GAAG,CAACP,MAAM;YAAE,GAAGI,GAAG;YAAEI,OAAO,EAAEH,qBAAAA,+BAAAA,SAAUG,OAAO;QAAC;IAClE;IAEA,OAAO;QACHT,MAAK,EAAEX,OAAO,EAAEC,WAAW,EAAEC,UAAU,IAAI,EAAE;YACzC,IAAImB,iBAAiB;YAErB,IAAIpB,aAAa;gBACb,IAAI,CAACC,SAAS;oBACVd;gBACJ;gBACA,IAAIc,WAAWb,kBAAkB;oBAC7BgC,iBAAiBtB,cAAcC,SAASC,aAAaC;gBACzD;YACJ;YAEAa,gBAAgBf;YAEhB,OAAO;gBACHsB,SAAS,IAAM1B,MAAMC,QAAQ,CAAC0B,MAAM,CAACvB,QAAQY,IAAI;gBACjDS;YACJ;QACJ;QAEAG,mBAAkBC,GAAG,EAAEL,OAAO;YAC1B,MAAMH,WAAWrB,MAAMC,QAAQ,CAACqB,GAAG,CAACO;YACpC7B,MAAMC,QAAQ,CAACsB,GAAG,CAACM,KAAK;gBAAE,GAAGR,QAAQ;gBAAEG;YAAQ;QACnD;IACJ;AACJ"}
@@ -1,14 +1,11 @@
1
1
  import { FC, PropsWithChildren } from 'react';
2
- type User = Omit<import('@datadog/browser-core').User, 'id'> & {
3
- id: string;
4
- };
2
+ import { type RumUser } from './set-user';
5
3
  export interface Options {
6
4
  hashRouting?: boolean;
7
5
  }
8
6
  export declare const DatadogProvider: FC<PropsWithChildren & {
9
7
  isEnabled: boolean;
10
- user?: User;
8
+ user?: RumUser;
11
9
  options?: Options;
12
10
  }>;
13
- export {};
14
11
  //# sourceMappingURL=datadog-provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"datadog-provider.d.ts","sourceRoot":"","sources":["../src/datadog-provider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAY,iBAAiB,EAAa,MAAM,OAAO,CAAC;AAGnE,KAAK,IAAI,GAAG,IAAI,CAAC,OAAO,uBAAuB,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9E,MAAM,WAAW,OAAO;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;CACzB;AAYD,eAAO,MAAM,eAAe,EAAE,EAAE,CAC5B,iBAAiB,GAAG;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB,CAYJ,CAAC"}
1
+ {"version":3,"file":"datadog-provider.d.ts","sourceRoot":"","sources":["../src/datadog-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAY,iBAAiB,EAAa,MAAM,OAAO,CAAC;AAEnE,OAAO,EAAW,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAEnD,MAAM,WAAW,OAAO;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;CACzB;AAYD,eAAO,MAAM,eAAe,EAAE,EAAE,CAC5B,iBAAiB,GAAG;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB,CAYJ,CAAC"}
@@ -1,11 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { datadogRum } from '@datadog/browser-rum';
3
2
  import { Fragment, useEffect } from 'react';
4
3
  import { HashRouting } from './hash-routing';
4
+ import { setUser } from './set-user';
5
5
  const SetUser = ({ user })=>{
6
6
  useEffect(()=>{
7
7
  if (user) {
8
- datadogRum.setUser(user);
8
+ setUser(user);
9
9
  }
10
10
  }, [
11
11
  user
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/datadog-provider.tsx"],"sourcesContent":["import { datadogRum } from '@datadog/browser-rum';\nimport { FC, Fragment, PropsWithChildren, useEffect } from 'react';\nimport { HashRouting } from './hash-routing';\n\ntype User = Omit<import('@datadog/browser-core').User, 'id'> & { id: string };\n\nexport interface Options {\n hashRouting?: boolean;\n}\n\nconst SetUser: FC<{ user?: User }> = ({ user }) => {\n useEffect(() => {\n if (user) {\n datadogRum.setUser(user);\n }\n }, [user]);\n\n return null;\n};\n\nexport const DatadogProvider: FC<\n PropsWithChildren & {\n isEnabled: boolean;\n user?: User;\n options?: Options;\n }\n> = ({ children, isEnabled, user, options }) => {\n if (isEnabled) {\n return (\n <Fragment>\n <SetUser user={user} />\n {options?.hashRouting && <HashRouting />}\n {children}\n </Fragment>\n );\n }\n return children;\n};\n"],"names":["datadogRum","Fragment","useEffect","HashRouting","SetUser","user","setUser","DatadogProvider","children","isEnabled","options","hashRouting"],"mappings":";AAAA,SAASA,UAAU,QAAQ,uBAAuB;AAClD,SAAaC,QAAQ,EAAqBC,SAAS,QAAQ,QAAQ;AACnE,SAASC,WAAW,QAAQ,iBAAiB;AAQ7C,MAAMC,UAA+B,CAAC,EAAEC,IAAI,EAAE;IAC1CH,UAAU;QACN,IAAIG,MAAM;YACNL,WAAWM,OAAO,CAACD;QACvB;IACJ,GAAG;QAACA;KAAK;IAET,OAAO;AACX;AAEA,OAAO,MAAME,kBAMT,CAAC,EAAEC,QAAQ,EAAEC,SAAS,EAAEJ,IAAI,EAAEK,OAAO,EAAE;IACvC,IAAID,WAAW;QACX,qBACI,MAACR;;8BACG,KAACG;oBAAQC,MAAMA;;gBACdK,CAAAA,oBAAAA,8BAAAA,QAASC,WAAW,mBAAI,KAACR;gBACzBK;;;IAGb;IACA,OAAOA;AACX,EAAE"}
1
+ {"version":3,"sources":["../src/datadog-provider.tsx"],"sourcesContent":["import { FC, Fragment, PropsWithChildren, useEffect } from 'react';\nimport { HashRouting } from './hash-routing';\nimport { setUser, type RumUser } from './set-user';\n\nexport interface Options {\n hashRouting?: boolean;\n}\n\nconst SetUser: FC<{ user?: RumUser }> = ({ user }) => {\n useEffect(() => {\n if (user) {\n setUser(user);\n }\n }, [user]);\n\n return null;\n};\n\nexport const DatadogProvider: FC<\n PropsWithChildren & {\n isEnabled: boolean;\n user?: RumUser;\n options?: Options;\n }\n> = ({ children, isEnabled, user, options }) => {\n if (isEnabled) {\n return (\n <Fragment>\n <SetUser user={user} />\n {options?.hashRouting && <HashRouting />}\n {children}\n </Fragment>\n );\n }\n return children;\n};\n"],"names":["Fragment","useEffect","HashRouting","setUser","SetUser","user","DatadogProvider","children","isEnabled","options","hashRouting"],"mappings":";AAAA,SAAaA,QAAQ,EAAqBC,SAAS,QAAQ,QAAQ;AACnE,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,OAAO,QAAsB,aAAa;AAMnD,MAAMC,UAAkC,CAAC,EAAEC,IAAI,EAAE;IAC7CJ,UAAU;QACN,IAAII,MAAM;YACNF,QAAQE;QACZ;IACJ,GAAG;QAACA;KAAK;IAET,OAAO;AACX;AAEA,OAAO,MAAMC,kBAMT,CAAC,EAAEC,QAAQ,EAAEC,SAAS,EAAEH,IAAI,EAAEI,OAAO,EAAE;IACvC,IAAID,WAAW;QACX,qBACI,MAACR;;8BACG,KAACI;oBAAQC,MAAMA;;gBACdI,CAAAA,oBAAAA,8BAAAA,QAASC,WAAW,mBAAI,KAACR;gBACzBK;;;IAGb;IACA,OAAOA;AACX,EAAE"}
@@ -0,0 +1,6 @@
1
+ import type { RumEvent, RumEventDomainContext } from '@datadog/browser-rum';
2
+ /**
3
+ * See https://docs.datadoghq.com/real_user_monitoring/browser/advanced_configuration/?tab=npm#micro-frontend
4
+ */
5
+ export declare function enrichEvent(event: RumEvent, context: RumEventDomainContext): void;
6
+ //# sourceMappingURL=enrich-event.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enrich-event.d.ts","sourceRoot":"","sources":["../src/enrich-event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAoB5E;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,qBAAqB,GAAG,IAAI,CAcjF"}
@@ -0,0 +1,33 @@
1
+ const SERVICE_REGEX = /unpkg\.servicetitan\.com\/@servicetitan\/(?<service>[\w-]+)(?:@(?<version>\d+\.\d+\.\d+(?:-[\w.]+)?))?/;
2
+ function parseService(event, input) {
3
+ var _match_groups, _match_groups1;
4
+ const match = input === null || input === void 0 ? void 0 : input.match(SERVICE_REGEX);
5
+ const service = match === null || match === void 0 ? void 0 : (_match_groups = match.groups) === null || _match_groups === void 0 ? void 0 : _match_groups.service;
6
+ const version = match === null || match === void 0 ? void 0 : (_match_groups1 = match.groups) === null || _match_groups1 === void 0 ? void 0 : _match_groups1.version;
7
+ if (service) {
8
+ event.service = service;
9
+ event.version = version !== null && version !== void 0 ? version : 'unknown';
10
+ return true;
11
+ }
12
+ return false;
13
+ }
14
+ /**
15
+ * See https://docs.datadoghq.com/real_user_monitoring/browser/advanced_configuration/?tab=npm#micro-frontend
16
+ */ export function enrichEvent(event, context) {
17
+ var _ref;
18
+ var _event_error, _event_error1, _event_resource;
19
+ const stack = (_ref = context && 'handlingStack' in context ? context.handlingStack : undefined) !== null && _ref !== void 0 ? _ref : event.type === 'error' ? (_event_error = event.error) === null || _event_error === void 0 ? void 0 : _event_error.stack : undefined;
20
+ const message = event.type === 'error' ? (_event_error1 = event.error) === null || _event_error1 === void 0 ? void 0 : _event_error1.message : undefined;
21
+ const url = event.type === 'resource' ? (_event_resource = event.resource) === null || _event_resource === void 0 ? void 0 : _event_resource.url : undefined;
22
+ for (const source of [
23
+ stack,
24
+ message,
25
+ url
26
+ ]){
27
+ if (parseService(event, source)) {
28
+ break;
29
+ }
30
+ }
31
+ }
32
+
33
+ //# sourceMappingURL=enrich-event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/enrich-event.ts"],"sourcesContent":["import type { RumEvent, RumEventDomainContext } from '@datadog/browser-rum';\n\nconst SERVICE_REGEX =\n /unpkg\\.servicetitan\\.com\\/@servicetitan\\/(?<service>[\\w-]+)(?:@(?<version>\\d+\\.\\d+\\.\\d+(?:-[\\w.]+)?))?/;\n\nfunction parseService(event: RumEvent, input: string | undefined) {\n const match = input?.match(SERVICE_REGEX);\n\n const service = match?.groups?.service;\n const version = match?.groups?.version;\n\n if (service) {\n event.service = service;\n event.version = version ?? 'unknown';\n return true;\n }\n\n return false;\n}\n\n/**\n * See https://docs.datadoghq.com/real_user_monitoring/browser/advanced_configuration/?tab=npm#micro-frontend\n */\nexport function enrichEvent(event: RumEvent, context: RumEventDomainContext): void {\n const stack =\n (context && 'handlingStack' in context ? context.handlingStack : undefined) ??\n (event.type === 'error' ? event.error?.stack : undefined);\n\n const message = event.type === 'error' ? event.error?.message : undefined;\n\n const url = event.type === 'resource' ? event.resource?.url : undefined;\n\n for (const source of [stack, message, url]) {\n if (parseService(event, source)) {\n break;\n }\n }\n}\n"],"names":["SERVICE_REGEX","parseService","event","input","match","service","groups","version","enrichEvent","context","stack","handlingStack","undefined","type","error","message","url","resource","source"],"mappings":"AAEA,MAAMA,gBACF;AAEJ,SAASC,aAAaC,KAAe,EAAEC,KAAyB;QAG5CC,eACAA;IAHhB,MAAMA,QAAQD,kBAAAA,4BAAAA,MAAOC,KAAK,CAACJ;IAE3B,MAAMK,UAAUD,kBAAAA,6BAAAA,gBAAAA,MAAOE,MAAM,cAAbF,oCAAAA,cAAeC,OAAO;IACtC,MAAME,UAAUH,kBAAAA,6BAAAA,iBAAAA,MAAOE,MAAM,cAAbF,qCAAAA,eAAeG,OAAO;IAEtC,IAAIF,SAAS;QACTH,MAAMG,OAAO,GAAGA;QAChBH,MAAMK,OAAO,GAAGA,oBAAAA,qBAAAA,UAAW;QAC3B,OAAO;IACX;IAEA,OAAO;AACX;AAEA;;CAEC,GACD,OAAO,SAASC,YAAYN,KAAe,EAAEO,OAA8B;QAElEA;QACyBP,cAEWA,eAEDA;IANxC,MAAMQ,SACDD,OAAAA,WAAW,mBAAmBA,UAAUA,QAAQE,aAAa,GAAGC,uBAAhEH,kBAAAA,OACAP,MAAMW,IAAI,KAAK,WAAUX,eAAAA,MAAMY,KAAK,cAAXZ,mCAAAA,aAAaQ,KAAK,GAAGE;IAEnD,MAAMG,UAAUb,MAAMW,IAAI,KAAK,WAAUX,gBAAAA,MAAMY,KAAK,cAAXZ,oCAAAA,cAAaa,OAAO,GAAGH;IAEhE,MAAMI,MAAMd,MAAMW,IAAI,KAAK,cAAaX,kBAAAA,MAAMe,QAAQ,cAAdf,sCAAAA,gBAAgBc,GAAG,GAAGJ;IAE9D,KAAK,MAAMM,UAAU;QAACR;QAAOK;QAASC;KAAI,CAAE;QACxC,IAAIf,aAAaC,OAAOgB,SAAS;YAC7B;QACJ;IACJ;AACJ"}
@@ -0,0 +1,10 @@
1
+ import type { SharedImpl } from './shared-impl';
2
+ export declare const STATE_KEY: unique symbol;
3
+ export interface GlobalSlot {
4
+ [STATE_KEY]?: SharedImpl;
5
+ }
6
+ /** Returns the shared impl, creating it if it doesn't exist yet. Only called by `init`. */
7
+ export declare function getOrCreateSharedImpl(): SharedImpl;
8
+ /** Returns the shared impl if it already exists, or `undefined`. */
9
+ export declare function getSharedImpl(): SharedImpl | undefined;
10
+ //# sourceMappingURL=get-shared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-shared.d.ts","sourceRoot":"","sources":["../src/get-shared.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,eAAO,MAAM,SAAS,eAA0C,CAAC;AAEjE,MAAM,WAAW,UAAU;IACvB,CAAC,SAAS,CAAC,CAAC,EAAE,UAAU,CAAC;CAC5B;AAMD,2FAA2F;AAC3F,wBAAgB,qBAAqB,IAAI,UAAU,CAIlD;AAED,oEAAoE;AACpE,wBAAgB,aAAa,IAAI,UAAU,GAAG,SAAS,CAEtD"}
@@ -0,0 +1,16 @@
1
+ import { createImpl } from './create-impl';
2
+ export const STATE_KEY = Symbol.for('@servicetitan/datadog-rum');
3
+ function slot() {
4
+ return globalThis;
5
+ }
6
+ /** Returns the shared impl, creating it if it doesn't exist yet. Only called by `init`. */ export function getOrCreateSharedImpl() {
7
+ var _s, _STATE_KEY, _;
8
+ const s = slot();
9
+ (_ = (_s = s)[_STATE_KEY = STATE_KEY]) !== null && _ !== void 0 ? _ : _s[_STATE_KEY] = createImpl();
10
+ return s[STATE_KEY];
11
+ }
12
+ /** Returns the shared impl if it already exists, or `undefined`. */ export function getSharedImpl() {
13
+ return slot()[STATE_KEY];
14
+ }
15
+
16
+ //# sourceMappingURL=get-shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/get-shared.ts"],"sourcesContent":["import { createImpl } from './create-impl';\nimport type { SharedImpl } from './shared-impl';\n\nexport const STATE_KEY = Symbol.for('@servicetitan/datadog-rum');\n\nexport interface GlobalSlot {\n [STATE_KEY]?: SharedImpl;\n}\n\nfunction slot(): GlobalSlot {\n return globalThis as unknown as GlobalSlot;\n}\n\n/** Returns the shared impl, creating it if it doesn't exist yet. Only called by `init`. */\nexport function getOrCreateSharedImpl(): SharedImpl {\n const s = slot();\n s[STATE_KEY] ??= createImpl();\n return s[STATE_KEY];\n}\n\n/** Returns the shared impl if it already exists, or `undefined`. */\nexport function getSharedImpl(): SharedImpl | undefined {\n return slot()[STATE_KEY];\n}\n"],"names":["createImpl","STATE_KEY","Symbol","for","slot","globalThis","getOrCreateSharedImpl","s","getSharedImpl"],"mappings":"AAAA,SAASA,UAAU,QAAQ,gBAAgB;AAG3C,OAAO,MAAMC,YAAYC,OAAOC,GAAG,CAAC,6BAA6B;AAMjE,SAASC;IACL,OAAOC;AACX;AAEA,yFAAyF,GACzF,OAAO,SAASC;QAEZC,IAAEN,YAAFM;IADA,MAAMA,IAAIH;KACVG,IAAAA,CAAAA,KAAAA,EAAC,CAACN,aAAAA,UAAU,cAAZM,eAAAA,IAAAA,EAAC,CAACN,WAAU,GAAKD;IACjB,OAAOO,CAAC,CAACN,UAAU;AACvB;AAEA,kEAAkE,GAClE,OAAO,SAASO;IACZ,OAAOJ,MAAM,CAACH,UAAU;AAC5B"}
@@ -0,0 +1,3 @@
1
+ import type { RumResourceEvent, RumResourceEventDomainContext } from '@datadog/browser-rum';
2
+ export declare function handleResource(event: RumResourceEvent, context: RumResourceEventDomainContext): void;
3
+ //# sourceMappingURL=handle-resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle-resource.d.ts","sourceRoot":"","sources":["../src/handle-resource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AAM5F,wBAAgB,cAAc,CAC1B,KAAK,EAAE,gBAAgB,EACvB,OAAO,EAAE,6BAA6B,GACvC,IAAI,CAoBN"}
@@ -0,0 +1,27 @@
1
+ function isSameDomainRequest(url) {
2
+ return new URL(url).hostname === window.location.hostname;
3
+ }
4
+ export function handleResource(event, context) {
5
+ if (!isSameDomainRequest(event.resource.url)) {
6
+ return;
7
+ }
8
+ let cfRay = undefined;
9
+ switch(event.resource.type){
10
+ case 'fetch':
11
+ var _context_response;
12
+ cfRay = (_context_response = context.response) === null || _context_response === void 0 ? void 0 : _context_response.headers.get('cf-ray');
13
+ break;
14
+ case 'xhr':
15
+ var _context_xhr;
16
+ cfRay = (_context_xhr = context.xhr) === null || _context_xhr === void 0 ? void 0 : _context_xhr.getResponseHeader('cf-ray');
17
+ break;
18
+ }
19
+ if (cfRay) {
20
+ event.context = {
21
+ ...event.context,
22
+ cfRay
23
+ };
24
+ }
25
+ }
26
+
27
+ //# sourceMappingURL=handle-resource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/handle-resource.ts"],"sourcesContent":["import type { RumResourceEvent, RumResourceEventDomainContext } from '@datadog/browser-rum';\n\nfunction isSameDomainRequest(url: string) {\n return new URL(url).hostname === window.location.hostname;\n}\n\nexport function handleResource(\n event: RumResourceEvent,\n context: RumResourceEventDomainContext\n): void {\n if (!isSameDomainRequest(event.resource.url)) {\n return;\n }\n\n let cfRay: string | undefined | null = undefined;\n\n switch (event.resource.type) {\n case 'fetch':\n cfRay = context.response?.headers.get('cf-ray');\n break;\n\n case 'xhr':\n cfRay = context.xhr?.getResponseHeader('cf-ray');\n break;\n }\n\n if (cfRay) {\n event.context = { ...event.context, cfRay };\n }\n}\n"],"names":["isSameDomainRequest","url","URL","hostname","window","location","handleResource","event","context","resource","cfRay","undefined","type","response","headers","get","xhr","getResponseHeader"],"mappings":"AAEA,SAASA,oBAAoBC,GAAW;IACpC,OAAO,IAAIC,IAAID,KAAKE,QAAQ,KAAKC,OAAOC,QAAQ,CAACF,QAAQ;AAC7D;AAEA,OAAO,SAASG,eACZC,KAAuB,EACvBC,OAAsC;IAEtC,IAAI,CAACR,oBAAoBO,MAAME,QAAQ,CAACR,GAAG,GAAG;QAC1C;IACJ;IAEA,IAAIS,QAAmCC;IAEvC,OAAQJ,MAAME,QAAQ,CAACG,IAAI;QACvB,KAAK;gBACOJ;YAARE,SAAQF,oBAAAA,QAAQK,QAAQ,cAAhBL,wCAAAA,kBAAkBM,OAAO,CAACC,GAAG,CAAC;YACtC;QAEJ,KAAK;gBACOP;YAARE,SAAQF,eAAAA,QAAQQ,GAAG,cAAXR,mCAAAA,aAAaS,iBAAiB,CAAC;YACvC;IACR;IAEA,IAAIP,OAAO;QACPH,MAAMC,OAAO,GAAG;YAAE,GAAGD,MAAMC,OAAO;YAAEE;QAAM;IAC9C;AACJ"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
1
  export * from './before-send';
2
2
  export * from './datadog-provider';
3
+ export * from './init';
4
+ export * from './set-user';
5
+ export * from './use-rum-service';
3
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,7 @@
1
1
  export * from './before-send';
2
2
  export * from './datadog-provider';
3
+ export * from './init';
4
+ export * from './set-user';
5
+ export * from './use-rum-service';
3
6
 
4
7
  //# sourceMappingURL=index.js.map