@servicetitan/datadog-rum 36.0.0 → 36.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.
@@ -43,7 +43,8 @@ function handleResource(event, context) {
43
43
  cfRay = (_context_response = context.response) === null || _context_response === void 0 ? void 0 : _context_response.headers.get('cf-ray');
44
44
  break;
45
45
  case 'xhr':
46
- cfRay = context.xhr.getResponseHeader('cf-ray');
46
+ var _context_xhr;
47
+ cfRay = (_context_xhr = context.xhr) === null || _context_xhr === void 0 ? void 0 : _context_xhr.getResponseHeader('cf-ray');
47
48
  break;
48
49
  }
49
50
  if (cfRay) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/before-send.ts"],"sourcesContent":["import type {\n RumEvent,\n RumEventDomainContext,\n RumFetchResourceEventDomainContext,\n RumInitConfiguration,\n RumResourceEvent,\n RumXhrResourceEventDomainContext,\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: RumEventDomainContext): 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 as RumFetchResourceEventDomainContext).response?.headers.get('cf-ray');\n break;\n\n case 'xhr':\n cfRay = (context as RumXhrResourceEventDomainContext).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);\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":"AASA,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;IAE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AOO;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 RumFetchResourceEventDomainContext,\n RumInitConfiguration,\n RumResourceEvent,\n RumXhrResourceEventDomainContext,\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: RumEventDomainContext): 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 as RumFetchResourceEventDomainContext).response?.headers.get('cf-ray');\n break;\n\n case 'xhr':\n cfRay = (context as RumXhrResourceEventDomainContext).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);\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":"AASA,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,KAA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0",
3
+ "version": "36.1.0",
4
4
  "description": "DataDog RUM JS SDK configuration for standalone applications",
5
5
  "homepage": "https://docs.st.dev/docs/frontend/uikit/datadog-rum",
6
6
  "repository": {
@@ -22,7 +22,7 @@
22
22
  "src"
23
23
  ],
24
24
  "devDependencies": {
25
- "@datadog/browser-rum": "^6.30.1",
25
+ "@datadog/browser-rum": "^6.32.0",
26
26
  "@testing-library/dom": "^10.4.1",
27
27
  "@testing-library/jest-dom": "^6.9.1",
28
28
  "@testing-library/react": "^16.3.2",
@@ -40,5 +40,5 @@
40
40
  "cli": {
41
41
  "webpack": false
42
42
  },
43
- "gitHead": "73584720991027dd55eaeb24fb8e09bad656dbad"
43
+ "gitHead": "b7b5cade33151c4d183faf498ddc1321694b7b2b"
44
44
  }
@@ -93,6 +93,19 @@ describe(`[datadog-rum] ${beforeSend.name}`, () => {
93
93
 
94
94
  itAddsCfRayToEventContext();
95
95
  });
96
+
97
+ describe('with early resource (no request context)', () => {
98
+ beforeEach(() => {
99
+ event.resource = { type: 'xhr', url: window.location.toString() };
100
+ context = {};
101
+ });
102
+
103
+ test('does not add "cfRay" header', () => {
104
+ subject();
105
+
106
+ expect(event.context?.cfRay).toBeUndefined();
107
+ });
108
+ });
96
109
  });
97
110
 
98
111
  describe.each(rumEvents)('when event.type=$event.type and $title', rumEvent => {
@@ -61,7 +61,7 @@ function handleResource(event: RumResourceEvent, context: RumEventDomainContext)
61
61
  break;
62
62
 
63
63
  case 'xhr':
64
- cfRay = (context as RumXhrResourceEventDomainContext).xhr.getResponseHeader('cf-ray');
64
+ cfRay = (context as RumXhrResourceEventDomainContext).xhr?.getResponseHeader('cf-ray');
65
65
  break;
66
66
  }
67
67