@utk09/ui-observability 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -1
- package/README.md +50 -11
- package/dist/{batch-BHXypM1j.cjs → batch-C8OcWR2L.cjs} +2 -2
- package/dist/{batch-BHXypM1j.cjs.map → batch-C8OcWR2L.cjs.map} +1 -1
- package/dist/{batch-BMdT9mKm.js → batch-CL9uWYY3.js} +4 -5
- package/dist/{batch-BMdT9mKm.js.map → batch-CL9uWYY3.js.map} +1 -1
- package/dist/{bus-DKfBaica.js → bus-BZ0GldpT.js} +23 -27
- package/dist/{bus-DKfBaica.js.map → bus-BZ0GldpT.js.map} +1 -1
- package/dist/{bus-Dea9rVhy.cjs → bus-VWlmM5xs.cjs} +2 -2
- package/dist/{bus-Dea9rVhy.cjs.map → bus-VWlmM5xs.cjs.map} +1 -1
- package/dist/console-BPZCuSLc.cjs +2 -0
- package/dist/{console-DZEcs7FL.cjs.map → console-BPZCuSLc.cjs.map} +1 -1
- package/dist/{console-BX_0UCV7.js → console-BeCF7n59.js} +14 -15
- package/dist/{console-BX_0UCV7.js.map → console-BeCF7n59.js.map} +1 -1
- package/dist/{constants-CL0ZdI2f.cjs → constants-DqKJH_MP.cjs} +2 -2
- package/dist/{constants-CL0ZdI2f.cjs.map → constants-DqKJH_MP.cjs.map} +1 -1
- package/dist/{constants-CU60FG4w.js → constants-zyrqveN4.js} +3 -4
- package/dist/{constants-CU60FG4w.js.map → constants-zyrqveN4.js.map} +1 -1
- package/dist/context-storage-BjzeBSxH.cjs.map +1 -1
- package/dist/{context-storage-DxZf4Gfh.js → context-storage-BzkoHzkQ.js} +2 -3
- package/dist/{context-storage-DxZf4Gfh.js.map → context-storage-BzkoHzkQ.js.map} +1 -1
- package/dist/{deadline-5_PecIl5.js → deadline-BOjOxNHj.js} +3 -5
- package/dist/{deadline-5_PecIl5.js.map → deadline-BOjOxNHj.js.map} +1 -1
- package/dist/deadline-XSnm95pg.cjs.map +1 -1
- package/dist/{debug-bundle-yRkrU1ny.cjs → debug-bundle-BzJNpbF0.cjs} +2 -2
- package/dist/{debug-bundle-yRkrU1ny.cjs.map → debug-bundle-BzJNpbF0.cjs.map} +1 -1
- package/dist/{debug-bundle-CZZ6SQQh.js → debug-bundle-C7UkHZ-q.js} +5 -6
- package/dist/{debug-bundle-CZZ6SQQh.js.map → debug-bundle-C7UkHZ-q.js.map} +1 -1
- package/dist/doctor.cjs +1 -1
- package/dist/doctor.cjs.map +1 -1
- package/dist/doctor.js +3 -4
- package/dist/{emergency-queue-CQ-9acZf.cjs → emergency-queue-CNTRui5t.cjs} +2 -2
- package/dist/{emergency-queue-CQ-9acZf.cjs.map → emergency-queue-CNTRui5t.cjs.map} +1 -1
- package/dist/{emergency-queue-Cs8-i2xw.js → emergency-queue-Zy6lNafo.js} +15 -17
- package/dist/{emergency-queue-Cs8-i2xw.js.map → emergency-queue-Zy6lNafo.js.map} +1 -1
- package/dist/{error-like-Ywo5uRHo.js → error-like-B11pB4aL.js} +2 -3
- package/dist/{error-like-Ywo5uRHo.js.map → error-like-B11pB4aL.js.map} +1 -1
- package/dist/error-like-gGRx2s36.cjs.map +1 -1
- package/dist/{errors-oyxrpHjY.js → errors-Dh7kef0i.js} +5 -6
- package/dist/{errors-oyxrpHjY.js.map → errors-Dh7kef0i.js.map} +1 -1
- package/dist/{errors-CigX45pL.cjs → errors-tfEr48bS.cjs} +2 -2
- package/dist/{errors-CigX45pL.cjs.map → errors-tfEr48bS.cjs.map} +1 -1
- package/dist/{factory-Bgsky_e0.js → factory-BonqI3NL.js} +9 -13
- package/dist/{factory-Bgsky_e0.js.map → factory-BonqI3NL.js.map} +1 -1
- package/dist/{factory-BkjNzPYL.cjs → factory-CJXVYp0R.cjs} +2 -2
- package/dist/{factory-BkjNzPYL.cjs.map → factory-CJXVYp0R.cjs.map} +1 -1
- package/dist/fixed-window-CvESpFYV.cjs.map +1 -1
- package/dist/{fixed-window-CtaFHanJ.js → fixed-window-Dq3MLUUv.js} +2 -3
- package/dist/{fixed-window-CtaFHanJ.js.map → fixed-window-Dq3MLUUv.js.map} +1 -1
- package/dist/global-scope-BN-Io_yv.cjs.map +1 -1
- package/dist/{global-scope-dp2jADRl.js → global-scope-D9I8s-oN.js} +2 -3
- package/dist/{global-scope-dp2jADRl.js.map → global-scope-D9I8s-oN.js.map} +1 -1
- package/dist/{guards-CpvOpJL6.js → guards-Cidk71ME.js} +2 -3
- package/dist/{guards-CpvOpJL6.js.map → guards-Cidk71ME.js.map} +1 -1
- package/dist/guards-nJ70syPt.cjs.map +1 -1
- package/dist/{identity-BMlKGHUM.cjs → identity-Cxgj6pZX.cjs} +2 -2
- package/dist/{identity-BMlKGHUM.cjs.map → identity-Cxgj6pZX.cjs.map} +1 -1
- package/dist/{identity-DOaHdfhT.js → identity-DT5VmvXy.js} +3 -4
- package/dist/{identity-DOaHdfhT.js.map → identity-DT5VmvXy.js.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +46 -56
- package/dist/index.js.map +1 -1
- package/dist/{indexeddb-storage-D-lUW_5P.js → indexeddb-storage-BJVtiQKm.js} +5 -6
- package/dist/{indexeddb-storage-D-lUW_5P.js.map → indexeddb-storage-BJVtiQKm.js.map} +1 -1
- package/dist/{indexeddb-storage-CaXGJqDD.cjs → indexeddb-storage-CIoW21Xd.cjs} +2 -2
- package/dist/{indexeddb-storage-CaXGJqDD.cjs.map → indexeddb-storage-CIoW21Xd.cjs.map} +1 -1
- package/dist/{interactions-CqDNrtIR.js → interactions-DTgKy_6K.js} +10 -11
- package/dist/{interactions-CqDNrtIR.js.map → interactions-DTgKy_6K.js.map} +1 -1
- package/dist/{interactions-8DgxtmgO.cjs → interactions-fEN6FbVo.cjs} +2 -2
- package/dist/{interactions-8DgxtmgO.cjs.map → interactions-fEN6FbVo.cjs.map} +1 -1
- package/dist/{journey-DgIjhrIc.js → journey-CuJrHzEg.js} +9 -10
- package/dist/{journey-DgIjhrIc.js.map → journey-CuJrHzEg.js.map} +1 -1
- package/dist/{journey-5tcxEbnG.cjs → journey-pffMVMfa.cjs} +2 -2
- package/dist/{journey-5tcxEbnG.cjs.map → journey-pffMVMfa.cjs.map} +1 -1
- package/dist/keys-BHhw_0Wh.cjs.map +1 -1
- package/dist/{keys-D5r_GH9q.js → keys-BU9j5YqW.js} +2 -3
- package/dist/{keys-D5r_GH9q.js.map → keys-BU9j5YqW.js.map} +1 -1
- package/dist/library-console-C1m6g1BR.js +13 -0
- package/dist/{library-console-CabK2j2-.js.map → library-console-C1m6g1BR.js.map} +1 -1
- package/dist/{library-console-g_VU-wzP.cjs → library-console-D2GY9Or6.cjs} +2 -2
- package/dist/{library-console-g_VU-wzP.cjs.map → library-console-D2GY9Or6.cjs.map} +1 -1
- package/dist/{library-request-FQaiWjCP.cjs → library-request-1BX_UlaX.cjs} +2 -2
- package/dist/{library-request-FQaiWjCP.cjs.map → library-request-1BX_UlaX.cjs.map} +1 -1
- package/dist/{library-request-CyC-9IOk.js → library-request-BQBT9N9Q.js} +4 -5
- package/dist/{library-request-CyC-9IOk.js.map → library-request-BQBT9N9Q.js.map} +1 -1
- package/dist/{lifecycle-C2z_d8OX.cjs → lifecycle-2EtUaRpo.cjs} +2 -2
- package/dist/{lifecycle-C2z_d8OX.cjs.map → lifecycle-2EtUaRpo.cjs.map} +1 -1
- package/dist/{lifecycle-BLC4VU7c.js → lifecycle-BaKx_-32.js} +3 -4
- package/dist/{lifecycle-BLC4VU7c.js.map → lifecycle-BaKx_-32.js.map} +1 -1
- package/dist/{log-record-CndanC-p.js → log-record-CAoGBBf3.js} +3 -4
- package/dist/{log-record-CndanC-p.js.map → log-record-CAoGBBf3.js.map} +1 -1
- package/dist/{log-record-DKvo-B-d.cjs → log-record-i9zOTkpQ.cjs} +2 -2
- package/dist/{log-record-DKvo-B-d.cjs.map → log-record-i9zOTkpQ.cjs.map} +1 -1
- package/dist/{long-frames-CV5ZG2cx.cjs → long-frames-BVg4i5SC.cjs} +2 -2
- package/dist/{long-frames-CV5ZG2cx.cjs.map → long-frames-BVg4i5SC.cjs.map} +1 -1
- package/dist/{long-frames-BQef9rXR.js → long-frames-Czk7IupC.js} +4 -5
- package/dist/{long-frames-BQef9rXR.js.map → long-frames-Czk7IupC.js.map} +1 -1
- package/dist/{network-CvkvYzRU.js → network-DBNwApoF.js} +22 -24
- package/dist/{network-CvkvYzRU.js.map → network-DBNwApoF.js.map} +1 -1
- package/dist/{network-CqnQOqon.cjs → network-xbbuvG_6.cjs} +2 -2
- package/dist/{network-CqnQOqon.cjs.map → network-xbbuvG_6.cjs.map} +1 -1
- package/dist/openfin-Bxelt0yg.js +7 -0
- package/dist/{openfin-BwEN0uj4.js.map → openfin-Bxelt0yg.js.map} +1 -1
- package/dist/openfin-DtH2f7zX.cjs.map +1 -1
- package/dist/{otlp-RVbkNQRh.cjs → otlp-BDvFrLnc.cjs} +2 -2
- package/dist/{otlp-RVbkNQRh.cjs.map → otlp-BDvFrLnc.cjs.map} +1 -1
- package/dist/{otlp-CYIL7MOE.js → otlp-BTJdIa6F.js} +4 -6
- package/dist/{otlp-CYIL7MOE.js.map → otlp-BTJdIa6F.js.map} +1 -1
- package/dist/patch-BX8KrPCT.cjs.map +1 -1
- package/dist/{patch-CCWfuEY7.js → patch-UdPz1ea8.js} +2 -3
- package/dist/{patch-CCWfuEY7.js.map → patch-UdPz1ea8.js.map} +1 -1
- package/dist/{platform-KMWkoI-v.cjs → platform-C2Ez5kDc.cjs} +2 -2
- package/dist/{platform-KMWkoI-v.cjs.map → platform-C2Ez5kDc.cjs.map} +1 -1
- package/dist/{platform-wcAkkv9F.js → platform-DkcuXwe-.js} +4 -5
- package/dist/{platform-wcAkkv9F.js.map → platform-DkcuXwe-.js.map} +1 -1
- package/dist/{remote-rules-CH_7PphT.js → remote-rules-Cfb4K-Nl.js} +5 -6
- package/dist/{remote-rules-CH_7PphT.js.map → remote-rules-Cfb4K-Nl.js.map} +1 -1
- package/dist/{remote-rules-BL8km4xk.cjs → remote-rules-vzvk7aKf.cjs} +2 -2
- package/dist/{remote-rules-BL8km4xk.cjs.map → remote-rules-vzvk7aKf.cjs.map} +1 -1
- package/dist/{reports-Bh_-KpZ2.cjs → reports-Dk2YhKIh.cjs} +2 -2
- package/dist/{reports-Bh_-KpZ2.cjs.map → reports-Dk2YhKIh.cjs.map} +1 -1
- package/dist/{reports-BOKyY3_A.js → reports-TA-zInnq.js} +4 -5
- package/dist/{reports-BOKyY3_A.js.map → reports-TA-zInnq.js.map} +1 -1
- package/dist/{resource-timing-BROnEJ0E.js → resource-timing-BLv3EA2A.js} +6 -7
- package/dist/{resource-timing-BROnEJ0E.js.map → resource-timing-BLv3EA2A.js.map} +1 -1
- package/dist/{resource-timing-CbgwNpog.cjs → resource-timing-Cysw1S1f.cjs} +2 -2
- package/dist/{resource-timing-CbgwNpog.cjs.map → resource-timing-Cysw1S1f.cjs.map} +1 -1
- package/dist/{sampling-BLO_pcV4.js → sampling-C4VV-1MS.js} +4 -5
- package/dist/{sampling-BLO_pcV4.js.map → sampling-C4VV-1MS.js.map} +1 -1
- package/dist/{sampling-ECGVYiDD.cjs → sampling-Ckh2yW9k.cjs} +2 -2
- package/dist/{sampling-ECGVYiDD.cjs.map → sampling-Ckh2yW9k.cjs.map} +1 -1
- package/dist/{sanitize-DS0G4_ea.js → sanitize-6ymPlVvP.js} +4 -5
- package/dist/{sanitize-DS0G4_ea.js.map → sanitize-6ymPlVvP.js.map} +1 -1
- package/dist/{sanitize-Bsn8HQWC.cjs → sanitize-BAWzkZt0.cjs} +2 -2
- package/dist/{sanitize-Bsn8HQWC.cjs.map → sanitize-BAWzkZt0.cjs.map} +1 -1
- package/dist/{select-DWO0-w8_.cjs → select-ZF4by-lF.cjs} +2 -2
- package/dist/{select-DWO0-w8_.cjs.map → select-ZF4by-lF.cjs.map} +1 -1
- package/dist/{select-wqt9Wxio.js → select-xtQaenIi.js} +7 -10
- package/dist/{select-wqt9Wxio.js.map → select-xtQaenIi.js.map} +1 -1
- package/dist/{sender-BkAVt-Rq.js → sender-CiMHC9YG.js} +92 -96
- package/dist/{sender-BkAVt-Rq.js.map → sender-CiMHC9YG.js.map} +1 -1
- package/dist/{sender-D82PxlCY.cjs → sender-D5wBoXA8.cjs} +2 -2
- package/dist/{sender-D82PxlCY.cjs.map → sender-D5wBoXA8.cjs.map} +1 -1
- package/dist/storage-BA9RqRO-.cjs.map +1 -1
- package/dist/{storage-w7Tslvlq.js → storage-DZwed89z.js} +2 -3
- package/dist/{storage-w7Tslvlq.js.map → storage-DZwed89z.js.map} +1 -1
- package/dist/{storm-DCEsqViG.cjs → storm-CYi9Swpx.cjs} +2 -2
- package/dist/{storm-DCEsqViG.cjs.map → storm-CYi9Swpx.cjs.map} +1 -1
- package/dist/{storm-DD4cUkoL.js → storm-VR024_QN.js} +4 -5
- package/dist/{storm-DD4cUkoL.js.map → storm-VR024_QN.js.map} +1 -1
- package/dist/{types-BR9t_w28.js → types-BAerHgCq.js} +2 -3
- package/dist/{types-BR9t_w28.js.map → types-BAerHgCq.js.map} +1 -1
- package/dist/types-C7WNpnG1.cjs.map +1 -1
- package/dist/{unclean-exit-BYZ5yaSI.js → unclean-exit-CwcUhFOn.js} +3 -4
- package/dist/{unclean-exit-BYZ5yaSI.js.map → unclean-exit-CwcUhFOn.js.map} +1 -1
- package/dist/{unclean-exit-CwdpbUDg.cjs → unclean-exit-DFUN57wY.cjs} +2 -2
- package/dist/{unclean-exit-CwdpbUDg.cjs.map → unclean-exit-DFUN57wY.cjs.map} +1 -1
- package/dist/{user-timing-C1kB3JEg.cjs → user-timing-C9kfRq3J.cjs} +2 -2
- package/dist/{user-timing-C1kB3JEg.cjs.map → user-timing-C9kfRq3J.cjs.map} +1 -1
- package/dist/{user-timing-Di2ra5DB.js → user-timing-_jZIhDKI.js} +4 -5
- package/dist/{user-timing-Di2ra5DB.js.map → user-timing-_jZIhDKI.js.map} +1 -1
- package/dist/{web-socket-DwBNhgre.cjs → web-socket-BWUoqBh8.cjs} +2 -2
- package/dist/{web-socket-DwBNhgre.cjs.map → web-socket-BWUoqBh8.cjs.map} +1 -1
- package/dist/{web-socket-B-5qqPy7.js → web-socket-CV7yIMnm.js} +14 -15
- package/dist/{web-socket-B-5qqPy7.js.map → web-socket-CV7yIMnm.js.map} +1 -1
- package/dist/{web-vitals-Bflr5jSA.js → web-vitals-Bq4WFHQo.js} +2 -3
- package/dist/{web-vitals-Bflr5jSA.js.map → web-vitals-Bq4WFHQo.js.map} +1 -1
- package/dist/web-vitals-DFuoTQbZ.cjs.map +1 -1
- package/dist/{worker-protocol-DXekoADQ.cjs → worker-protocol-Bai7GAIA.cjs} +2 -2
- package/dist/{worker-protocol-DXekoADQ.cjs.map → worker-protocol-Bai7GAIA.cjs.map} +1 -1
- package/dist/{worker-protocol-0HMf4-kY.js → worker-protocol-CrsdSDLn.js} +6 -7
- package/dist/{worker-protocol-0HMf4-kY.js.map → worker-protocol-CrsdSDLn.js.map} +1 -1
- package/dist/worker-server-BrIYkfoa.cjs +2 -0
- package/dist/{worker-server-BQK5z2yl.cjs.map → worker-server-BrIYkfoa.cjs.map} +1 -1
- package/dist/{worker-server-CKcmX5m5.js → worker-server-Dp5HYm4b.js} +25 -26
- package/dist/{worker-server-CKcmX5m5.js.map → worker-server-Dp5HYm4b.js.map} +1 -1
- package/dist/{worker-transport-Dj2yCQN5.cjs → worker-transport-Bwej4N2e.cjs} +2 -2
- package/dist/{worker-transport-Dj2yCQN5.cjs.map → worker-transport-Bwej4N2e.cjs.map} +1 -1
- package/dist/{worker-transport-2220ghFZ.js → worker-transport-D6jtgpqN.js} +9 -11
- package/dist/{worker-transport-2220ghFZ.js.map → worker-transport-D6jtgpqN.js.map} +1 -1
- package/package.json +27 -41
- package/dist/console-DZEcs7FL.cjs +0 -2
- package/dist/library-console-CabK2j2-.js +0 -14
- package/dist/openfin-BwEN0uj4.js +0 -8
- package/dist/worker-server-BQK5z2yl.cjs +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network-CqnQOqon.cjs","names":["SERVER_TIMING_MAX_CHARS","isErrorLike","isLibraryRequest","matchesAny","patch","SERVER_TIMING_HEADER","recordedUrl","isTransportPending","require_constants","require_error_like","require_platform","require_library_request","require_patch","require_types","splitHeader","parts","start","quoted","escaped","i","text","char","separator","xhrServerTiming","headers","readServerTiming","result","header","part","rawName","params","name","entry","seen","param","equal","key","value","duration","match","MS_PER_SECOND","HTTP_DURATION","durationAttributes","base","attributes","method","url","status","error","xhrMethods","readUrl","input","readFetchMethod","requested","init","toMethod","isForeignInput","NetworkCapture","ctx","restore","targets","origin","target","active","prepare","record","plan","durationMs","readTiming","call","original","startedAt","response","read","trace","injected","ignored","propagates","meta","proto","restoreOpen","rest","originalOpen","restoreSend","args","addTraceHeaders","originalSend","routingContextId","timing","span","endMs","rounded","xhr"],"sources":["../src/capture/server-timing.ts","../src/capture/network.ts"],"sourcesContent":["import { SERVER_TIMING_MAX_CHARS, SERVER_TIMING_MAX_ENTRIES } from \"../constants\";\n\n/** One duration entry from the Server-Timing response header. */\ninterface ServerTimingEntry {\n name: string;\n duration: number;\n description: string;\n}\n\n/** Server duration entries and the server span that they name. */\nexport interface ServerTiming {\n entries: ServerTimingEntry[];\n link?: { traceId: string; spanId: string };\n}\n\n/** Splits a header outside quoted strings. Escaped quotes do not end a string. */\nfunction splitHeader(text: string, separator: string): string[] {\n const parts: string[] = [];\n let start = 0;\n let quoted = false;\n let escaped = false;\n\n for (let i = 0; i < text.length; i++) {\n const char = text[i];\n if (escaped) {\n escaped = false;\n } else if (quoted && char === \"\\\\\") {\n escaped = true;\n } else if (char === '\"') {\n quoted = !quoted;\n } else if (!quoted && char === separator) {\n parts.push(text.slice(start, i));\n start = i + 1;\n }\n }\n\n parts.push(text.slice(start));\n return parts;\n}\n\n/** Finds the header in an XHR header list. Chrome prints an error for a direct hidden read. */\nexport function xhrServerTiming(headers: string): string | null {\n return /^server-timing:(.*)$/im.exec(headers)?.[1] ?? null;\n}\n\n/** Reads bounded server duration entries. A missing header gives no entries. */\nexport function readServerTiming(header: string | null): ServerTiming {\n const result: ServerTiming = { entries: [] };\n if (!header) {\n return result;\n }\n\n for (const part of splitHeader(header.slice(0, SERVER_TIMING_MAX_CHARS), \",\").slice(\n 0,\n SERVER_TIMING_MAX_ENTRIES,\n )) {\n const [rawName, ...params] = splitHeader(part, \";\");\n const name = rawName.trim();\n if (!/^[!#$%&'*+.^_`|~\\da-z-]+$/i.test(name)) {\n continue;\n }\n\n const entry: ServerTimingEntry = { name, duration: 0, description: \"\" };\n const seen = new Set<string>();\n for (const param of params) {\n const equal = param.indexOf(\"=\");\n if (equal < 0) {\n continue;\n }\n\n const key = param.slice(0, equal).trim().toLowerCase();\n if (seen.has(key)) {\n continue;\n }\n seen.add(key);\n\n let value = param.slice(equal + 1).trim();\n if (value.startsWith('\"') && value.endsWith('\"')) {\n value = value.slice(1, -1).replace(/\\\\(.)/g, \"$1\");\n }\n\n if (key === \"dur\") {\n const duration = Number(value);\n if (Number.isFinite(duration) && duration >= 0) {\n entry.duration = duration;\n }\n } else if (key === \"desc\") {\n entry.description = value;\n }\n }\n\n result.entries.push(entry);\n if (name.toLowerCase() === \"traceparent\") {\n const match = /^00-([\\da-f]{32})-([\\da-f]{16})-[\\da-f]{2}$/.exec(entry.description);\n if (match && /[1-9a-f]/.test(match[1]) && /[1-9a-f]/.test(match[2])) {\n result.link = { traceId: match[1], spanId: match[2] };\n }\n }\n }\n\n return result;\n}\n","// src/capture/network.ts\n//\n// Instruments fetch and XMLHttpRequest to record network request outcomes and timing.\n\nimport { SERVER_TIMING_HEADER } from \"../constants\";\nimport { readServerTiming, xhrServerTiming } from \"./server-timing\";\nimport type { InstrumentDef, MetricAttributes } from \"../models/metric\";\nimport { isErrorLike } from \"../utils/error-like\";\nimport { isLibraryRequest, isTransportPending } from \"../utils/library-request\";\nimport { patch } from \"../utils/patch\";\nimport { recordedUrl } from \"../utils/platform\";\nimport type { ClientSpan } from \"../utils/tracing\";\nimport { type Capture, type CaptureContext, matchesAny } from \"./types\";\n\n/** Signature of the global fetch function. */\ntype FetchFn = typeof fetch;\n\n/** Milliseconds in one second. The histogram is in seconds, as the OpenTelemetry name gives. */\nconst MS_PER_SECOND = 1000;\n\n/**\n * The HTTP client duration histogram of the OpenTelemetry semantic conventions. Its boundaries\n * are the ones that the conventions advise.\n */\nconst HTTP_DURATION: InstrumentDef = {\n name: \"http.client.request.duration\",\n kind: \"histogram\",\n unit: \"s\",\n boundaries: [0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10],\n};\n\n/**\n * Gives the low-cardinality attributes of one request. The path and the query stay out. Each\n * value of an attribute makes a new series in the backend.\n * @param method Uppercase HTTP method.\n * @param url Request URL.\n * @param status HTTP status code, or 0 when no response came.\n * @param error Failure of a request without a response.\n * @returns The attribute set.\n */\nfunction durationAttributes(\n method: string,\n url: string,\n status: number,\n error: unknown,\n): MetricAttributes {\n // A relative URL needs the page URL as its base. A worker has a location too.\n const base = typeof location !== \"undefined\" ? location.href : undefined;\n const attributes: MetricAttributes = {\n \"http.request.method\": method,\n \"server.address\": new URL(url, base).hostname,\n };\n\n if (status === 0) {\n // A request without a response has the type of its error, for example TypeError.\n const name = isErrorLike(error) ? error.name : \"\";\n attributes[\"error.type\"] = name === \"\" ? \"_OTHER\" : name;\n return attributes;\n }\n\n attributes[\"http.response.status_code\"] = status;\n if (status >= 400) {\n attributes[\"error.type\"] = String(status);\n }\n\n return attributes;\n}\n\n/** Request data that the XHR wrapper keeps from open to send. */\ninterface XhrMeta {\n /** Delivery context when the request started. */\n routingContextId?: string;\n /** Uppercase HTTP method. */\n method: string;\n /** Request target URL. */\n url: string;\n /** Performance timestamp at send. */\n startedAt: number;\n /** Client span that the traceparent names. */\n span?: ClientSpan;\n}\n\n/** XMLHttpRequest extended with internal telemetry tracking metadata. */\ntype Tracked = XMLHttpRequest & {\n __uiobs?: XhrMeta;\n};\n\n/** Unbound prototype methods intercepted on XMLHttpRequest. */\ninterface XhrMethods {\n open: (this: XMLHttpRequest, ...args: never[]) => void;\n send: (this: XMLHttpRequest, ...args: never[]) => void;\n}\n\n/** Returns the XMLHttpRequest prototype. */\nfunction xhrMethods(): XhrMethods {\n return XMLHttpRequest.prototype;\n}\n\n/** The fetch call to make, and the method and URL to record. */\ninterface FetchPlan {\n /** Delivery context when the request started. */\n routingContextId?: string;\n /** Uppercase HTTP method. */\n method: string;\n /** Request target URL. */\n url: string;\n /** Input to pass to the original fetch. */\n input: RequestInfo | URL;\n /** Init to pass to the original fetch. */\n init: RequestInit | undefined;\n /** Client span that the traceparent names. */\n span?: ClientSpan;\n}\n\n/**\n * Reads the URL of a fetch input or an XHR URL argument.\n * A Request from another realm fails `instanceof Request`. Its `url` property still works.\n * @param input String, URL, Request, or an object with a text form.\n * @returns The URL.\n * @throws TypeError when the input has no text form. Call it inside a diagnostics guard.\n */\nfunction readUrl(input: unknown): string {\n if (typeof input === \"string\") {\n return input;\n }\n\n if (input instanceof URL) {\n return input.href;\n }\n\n if (typeof input === \"object\" && input !== null) {\n const { url } = input as { url?: unknown };\n if (typeof url === \"string\") {\n return url;\n }\n }\n\n // fetch accepts each value with a text form.\n return String(input);\n}\n\n/**\n * Reads the method of a fetch call. The init method wins over the Request method.\n * @param input Fetch input.\n * @param init Fetch init.\n * @returns Uppercase method. The default is GET.\n */\nfunction readFetchMethod(input: unknown, init: RequestInit | undefined): string {\n let requested: unknown = init?.method;\n\n if (requested === undefined && typeof input === \"object\" && input !== null) {\n requested = (input as { method?: unknown }).method;\n }\n\n return toMethod(requested ?? \"GET\");\n}\n\n/**\n * Tests if a fetch input is an object that is not a Request or a URL of this realm.\n * An example is a Request from an iframe.\n * @param input Fetch input.\n * @returns True for a foreign object.\n */\nfunction isForeignInput(input: unknown): boolean {\n return typeof input === \"object\" && !(input instanceof URL) && !(input instanceof Request);\n}\n\n/**\n * Converts a method argument to text. A method that is not a string does not throw.\n * @param method Method argument of the caller.\n * @returns Uppercase method for a string, or the text form of another value.\n */\nfunction toMethod(method: unknown): string {\n return typeof method === \"string\" ? method.toUpperCase() : String(method);\n}\n\n/** Instruments global fetch and XMLHttpRequest to capture request durations and outcomes. */\nexport class NetworkCapture implements Capture {\n /** Capture module identifier. */\n readonly name = \"network\";\n\n /** Prevents a second wrap on a wrapped function. */\n private installed = false;\n\n /** Restore functions of the installed wrappers. */\n private readonly restores: (() => void)[] = [];\n\n /** True after the report of a request during a custom transport call. It reports one time. */\n private warnedTransport = false;\n\n /**\n * @param ctx Capture context containing configuration, diagnostics, logger, breadcrumbs, and tracing.\n */\n constructor(private readonly ctx: CaptureContext) {}\n\n /** Instruments configured network transport APIs. */\n install(): void {\n if (this.installed) {\n return;\n }\n this.installed = true;\n\n if (this.ctx.config.capture.fetch) {\n this.installFetch();\n }\n if (this.ctx.config.capture.xhr) {\n this.installXhr();\n }\n }\n\n /**\n * Restores each host function that still holds the wrapper of this capture.\n * A wrapper that another script wrapped again stays in place and records nothing.\n */\n uninstall(): void {\n if (!this.installed) {\n return;\n }\n this.installed = false;\n\n for (const restore of this.restores.splice(0)) {\n restore();\n }\n }\n\n /**\n * Tests if a URL matches ignore patterns.\n * @param url Request target URL.\n * @returns True if telemetry must exclude the URL.\n */\n private ignored(url: string): boolean {\n // resolveConfig always adds the endpoint to ignoreUrls. Without it, a failed POST\n // makes a log record. That record causes a new POST, and the loop does not stop.\n // A custom transport has no known URL. Its request starts inside the library scope.\n return isLibraryRequest() || matchesAny(url, this.ctx.config.capture.ignoreUrls);\n }\n\n /**\n * Tests if a request gets the trace headers.\n * @param url Request target URL.\n * @returns True if the URL is in propagateTraceHeaderTo.\n */\n private propagates(url: string): boolean {\n // Add headers only to allowlisted URLs. A traceparent on a third-party request causes\n // a CORS preflight. The third party does not answer it, and its API stops working.\n const targets = this.ctx.config.capture.propagateTraceHeaderTo;\n if (targets.length === 0) {\n return false;\n }\n\n // A string target is an origin. A relative URL resolves against the page.\n const origin = this.ctx.diagnostics.guard(\n \"capture.header_failed\",\n \"The library could not read the origin of a request URL. Only a RegExp target can match it.\",\n () => new URL(url, location.href).origin,\n );\n\n return targets.some((target) =>\n typeof target === \"string\" ? target === origin : target.test(url),\n );\n }\n\n /** Instruments globalThis.fetch with tracing injection and outcome logging. */\n private installFetch(): void {\n if (typeof globalThis.fetch !== \"function\") {\n return;\n }\n\n // Uninstall clears the flag. A wrapper that stays in place then only calls the original.\n let active = true;\n const prepare = (input: RequestInfo | URL, init: RequestInit | undefined) =>\n this.prepareFetch(input, init);\n const record = (\n plan: FetchPlan,\n status: number,\n durationMs: number,\n error: unknown,\n readTiming?: () => string | null,\n ): void => {\n this.record(\n plan.method,\n plan.url,\n status,\n durationMs,\n error,\n plan.span,\n plan.routingContextId,\n readTiming,\n );\n };\n\n const restore = patch(globalThis, \"fetch\", (original: FetchFn) => {\n const call = original.bind(globalThis);\n\n return async function instrumentedFetch(input, init) {\n const plan = active ? prepare(input, init) : undefined;\n if (!plan) {\n return call(input, init);\n }\n\n const startedAt = performance.now();\n try {\n const response = await call(plan.input, plan.init);\n record(plan, response.status, performance.now() - startedAt, undefined, () =>\n response.headers.get(SERVER_TIMING_HEADER),\n );\n return response;\n } catch (error) {\n record(plan, 0, performance.now() - startedAt, error);\n throw error;\n }\n };\n });\n\n this.restores.push(() => {\n active = false;\n restore();\n });\n }\n\n /**\n * Reads a fetch call and adds the trace headers to an allowlisted request.\n * @param input Fetch input of the caller.\n * @param init Fetch init of the caller.\n * @returns The plan, or undefined to send the request unchanged and record nothing.\n */\n private prepareFetch(\n input: RequestInfo | URL,\n init: RequestInit | undefined,\n ): FetchPlan | undefined {\n // A read here runs inside the fetch call of the caller. A throw must not fail the request.\n const read = this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not read a fetch request. It sends the request unchanged.\",\n (): { method: string; url: string; propagate: boolean } | undefined => {\n const url = readUrl(input);\n if (this.ignored(url)) {\n return undefined;\n }\n\n return { method: readFetchMethod(input, init), url, propagate: this.propagates(url) };\n },\n );\n\n if (!read) {\n return undefined;\n }\n\n const { method, url } = read;\n const plan: FetchPlan = {\n method,\n url,\n input,\n init,\n routingContextId: this.ctx.config.securityContext.id,\n };\n // An init with headers replaces all headers of a foreign Request, for example\n // Authorization. Send a foreign input without the trace headers.\n if (!read.propagate || isForeignInput(input)) {\n return plan;\n }\n\n try {\n const trace = this.ctx.tracing.request();\n const injected = Object.entries(trace.headers);\n\n if (input instanceof Request) {\n // Do not spread a non-empty init with a Request input. That runs the Request\n // constructor on `input` again and reads its body. A second read of a body\n // causes a TypeError.\n const headers = new Headers(input.headers);\n for (const [key, value] of injected) {\n headers.set(key, value);\n }\n plan.input = new Request(input, { headers });\n } else {\n const headers = new Headers(init?.headers);\n for (const [key, value] of injected) {\n headers.set(key, value);\n }\n plan.init = { ...init, headers };\n }\n\n // Record the client span only for a request that carries its traceparent.\n plan.span = trace.span;\n } catch (error) {\n // Send the request that the caller gave, without changes. A missing header is\n // better than a failed request.\n plan.input = input;\n plan.init = init;\n this.ctx.diagnostics.report(\n \"capture.header_failed\",\n \"The library could not add the traceparent header. It sends the request unchanged.\",\n { url },\n error,\n );\n }\n\n return plan;\n }\n\n /** Instruments XMLHttpRequest open and send prototype methods. */\n private installXhr(): void {\n if (typeof XMLHttpRequest === \"undefined\") {\n return;\n }\n\n // Uninstall clears the flag. A wrapper that stays in place then only calls the original.\n let active = true;\n const ctx = this.ctx;\n const ignored = (url: string): boolean => this.ignored(url);\n const propagates = (url: string): boolean => this.propagates(url);\n const record = (\n meta: XhrMeta,\n status: number,\n durationMs: number,\n readTiming: () => string | null,\n ): void => {\n this.record(\n meta.method,\n meta.url,\n status,\n durationMs,\n undefined,\n meta.span,\n meta.routingContextId,\n readTiming,\n );\n };\n\n const proto = xhrMethods();\n\n const restoreOpen = patch(\n proto,\n \"open\",\n (originalOpen) =>\n function (this: Tracked, method: unknown, url: unknown, ...rest: never[]) {\n if (active) {\n // A read here runs inside the open call of the caller. A throw must not fail it.\n ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not read an XMLHttpRequest. It does not record the request.\",\n () => {\n this.__uiobs = { method: toMethod(method), url: readUrl(url), startedAt: 0 };\n },\n );\n }\n originalOpen.apply(this, [method, url, ...rest] as never[]);\n },\n );\n\n const restoreSend = patch(\n proto,\n \"send\",\n (originalSend) =>\n function (this: Tracked, ...args: never[]) {\n const meta = active ? this.__uiobs : undefined;\n if (meta) {\n ctx.diagnostics.guard(\n \"capture.record_failed\",\n `The library could not record ${meta.method} ${meta.url}.`,\n () => {\n if (ignored(meta.url)) {\n return;\n }\n\n meta.startedAt = performance.now();\n meta.routingContextId = ctx.config.securityContext.id;\n // A reused XHR gets a new listener at each send. The old one must not fire again.\n this.addEventListener(\n \"loadend\",\n () => {\n record(meta, this.status, performance.now() - meta.startedAt, () =>\n xhrServerTiming(this.getAllResponseHeaders()),\n );\n },\n { once: true },\n );\n\n // setRequestHeader works only between open and send.\n if (propagates(meta.url)) {\n meta.span = addTraceHeaders(this, meta.url, ctx);\n }\n },\n );\n }\n originalSend.apply(this, args);\n },\n );\n\n this.restores.push(() => {\n active = false;\n restoreOpen();\n restoreSend();\n });\n }\n\n /**\n * Records request outcome attributes and breadcrumb entry.\n * @param method Uppercase HTTP method.\n * @param target Request target URL. The method removes the query unless you set fullUrls.\n * @param status HTTP response status code, or 0 on failure.\n * @param durationMs Request duration in milliseconds.\n * @param error Caught error instance on failed requests.\n * @param span Client span that the traceparent of the request names.\n */\n private record(\n method: string,\n target: string,\n status: number,\n durationMs: number,\n error: unknown,\n span?: ClientSpan,\n routingContextId?: string,\n readTiming?: () => string | null,\n ): void {\n if (\n this.ctx.isActive?.() === false ||\n (this.ctx.config.securityContext.isolation &&\n routingContextId !== undefined &&\n routingContextId !== this.ctx.config.securityContext.id)\n ) {\n return;\n }\n\n const timing =\n this.ctx.config.capture.serverTiming && readTiming\n ? this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not read the Server-Timing response header.\",\n () => readServerTiming(readTiming()),\n )\n : undefined;\n\n // Remove the query here, not at the call sites. ignoreUrls and propagateTraceHeaderTo\n // match on the full URL. Only the recorded URL loses the query string.\n const url = recordedUrl(\n target,\n this.ctx.config.capture.fullUrls,\n this.ctx.config.capture.urlTransform,\n this.ctx.diagnostics,\n );\n\n // A request of the transport after an await records a value. That value causes the next send.\n if (!this.warnedTransport && isTransportPending()) {\n this.warnedTransport = true;\n this.ctx.diagnostics.report(\n \"capture.transport_request\",\n `Network capture saw ${method} ${url} during a custom transport call. If the transport sends this request, add its URL to capture.ignoreUrls.`,\n );\n }\n\n // The histogram has its own guard. A URL that does not parse must not stop the record.\n if (this.ctx.config.capture.httpMetrics) {\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n `The library could not record the duration of ${method} ${url}.`,\n () => {\n const attributes = durationAttributes(method, target, status, error);\n this.ctx.recordMetric(HTTP_DURATION, durationMs / MS_PER_SECOND, attributes);\n },\n );\n }\n\n if (span) {\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n `The library could not record the span of ${method} ${url}.`,\n () => {\n const endMs = Date.now();\n this.ctx.recordSpan({\n ...span,\n link: timing?.link,\n name: method,\n kind: \"client\",\n startMs: endMs - durationMs,\n endMs,\n error: status === 0 || status >= 400,\n attributes: { ...durationAttributes(method, target, status, error), \"url.full\": url },\n });\n },\n );\n }\n\n // This code runs inside the fetch call of the caller. An error here must not cause\n // the request of the caller to fail.\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n `The library could not record ${method} ${url}.`,\n () => {\n const rounded = Math.round(durationMs);\n\n this.ctx.breadcrumbs.push({\n t: Date.now(),\n category: \"http\",\n message: `${method} ${url} ${status === 0 ? \"failed\" : String(status)}`,\n data: { durationMs: rounded },\n });\n\n const attributes = {\n \"http.request.method\": method,\n \"url.full\": url,\n \"http.response.status_code\": status,\n \"http.duration_ms\": rounded,\n ...(timing && timing.entries.length > 0 ? { \"server.timing\": timing.entries } : {}),\n };\n\n if (status === 0) {\n this.ctx.logger.error(`${method} ${url} failed`, error, attributes);\n return;\n }\n if (status >= 400) {\n this.ctx.logger.warn(`${method} ${url} returned ${String(status)}`, attributes);\n return;\n }\n\n // Log a success at DEBUG. The default minLevel of INFO drops it.\n // Only failures use bandwidth.\n this.ctx.logger.debug(`${method} ${url}`, attributes);\n },\n );\n }\n}\n\n/**\n * Adds the trace headers to an open XHR. A failure sends the request without them.\n * @param xhr Request between open and send.\n * @param url Request target URL, for the diagnostic.\n * @param ctx Capture context with tracing and diagnostics.\n * @returns The client span that the traceparent names, or undefined.\n */\nfunction addTraceHeaders(\n xhr: XMLHttpRequest,\n url: string,\n ctx: CaptureContext,\n): ClientSpan | undefined {\n try {\n const trace = ctx.tracing.request();\n for (const [key, value] of Object.entries(trace.headers)) {\n xhr.setRequestHeader(key, value);\n }\n return trace.span;\n } catch (error) {\n ctx.diagnostics.report(\n \"capture.header_failed\",\n \"The library could not add the traceparent header. It sends the request unchanged.\",\n { url },\n error,\n );\n return undefined;\n }\n}\n"],"mappings":"wOAgBA,SAASc,EAAY,EAAc,EAA6B,CAC9D,IAAMC,EAAkB,CAAC,EACrBC,EAAQ,EACRC,EAAS,GACTC,EAAU,GAEd,IAAK,IAAIC,EAAI,EAAGA,EAAIC,EAAK,OAAQ,IAAK,CACpC,IAAMC,EAAOD,EAAKD,GACdD,EACF,EAAU,GACDD,GAAUI,IAAS,KAC5B,EAAU,GACDA,IAAS,IAClB,EAAS,CAACJ,EACD,CAACA,GAAUI,IAASC,IAC7BP,EAAM,KAAKK,EAAK,MAAMJ,EAAOG,CAAC,CAAC,EAC/B,EAAQA,EAAI,EAEhB,CAGA,OADAJ,EAAM,KAAKK,EAAK,MAAMJ,CAAK,CAAC,EACrBD,CACT,CAGA,SAAgBQ,EAAgB,EAAgC,CAC9D,MAAO,yBAAyB,KAAKC,CAAO,CAAC,GAAG,IAAM,IACxD,CAGA,SAAgBC,EAAiB,EAAqC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,CACF,EASA,SAASyC,EACP,EACA,EACA,EACwB,CACxB,GAAI,CACF,IAAMX,EAAQhB,EAAI,QAAQ,QAAQ,EAClC,IAAK,GAAM,CAACtB,EAAKC,KAAU,OAAO,QAAQqC,EAAM,OAAO,EACrDkB,EAAI,iBAAiBxD,EAAKC,CAAK,EAEjC,OAAOqC,EAAM,IACf,OAAS1B,EAAO,CACdU,EAAI,YAAY,OACd,wBACA,oFACA,CAAE,KAAI,EACNV,CACF,EACA,MACF,CACF"}
|
|
1
|
+
{"version":3,"file":"network-xbbuvG_6.cjs","names":["SERVER_TIMING_MAX_CHARS","isErrorLike","isLibraryRequest","matchesAny","patch","SERVER_TIMING_HEADER","recordedUrl","isTransportPending","require_constants","require_error_like","require_library_request","require_patch","require_platform","require_types","splitHeader","parts","start","quoted","escaped","i","text","char","separator","xhrServerTiming","headers","readServerTiming","result","header","part","rawName","params","name","entry","seen","param","equal","key","value","duration","match","MS_PER_SECOND","HTTP_DURATION","durationAttributes","base","attributes","method","url","status","error","xhrMethods","readUrl","input","readFetchMethod","requested","init","toMethod","isForeignInput","NetworkCapture","ctx","restore","targets","origin","target","active","prepare","record","plan","durationMs","readTiming","call","original","startedAt","response","read","trace","injected","ignored","propagates","meta","proto","restoreOpen","rest","originalOpen","restoreSend","args","addTraceHeaders","originalSend","routingContextId","timing","span","endMs","rounded","xhr"],"sources":["../src/capture/server-timing.ts","../src/capture/network.ts"],"sourcesContent":["import { SERVER_TIMING_MAX_CHARS, SERVER_TIMING_MAX_ENTRIES } from \"../constants\";\n\n/** One duration entry from the Server-Timing response header. */\ninterface ServerTimingEntry {\n name: string;\n duration: number;\n description: string;\n}\n\n/** Server duration entries and the server span that they name. */\nexport interface ServerTiming {\n entries: ServerTimingEntry[];\n link?: { traceId: string; spanId: string };\n}\n\n/** Splits a header outside quoted strings. Escaped quotes do not end a string. */\nfunction splitHeader(text: string, separator: string): string[] {\n const parts: string[] = [];\n let start = 0;\n let quoted = false;\n let escaped = false;\n\n for (let i = 0; i < text.length; i++) {\n const char = text[i];\n if (escaped) {\n escaped = false;\n } else if (quoted && char === \"\\\\\") {\n escaped = true;\n } else if (char === '\"') {\n quoted = !quoted;\n } else if (!quoted && char === separator) {\n parts.push(text.slice(start, i));\n start = i + 1;\n }\n }\n\n parts.push(text.slice(start));\n return parts;\n}\n\n/** Finds the header in an XHR header list. Chrome prints an error for a direct hidden read. */\nexport function xhrServerTiming(headers: string): string | null {\n return /^server-timing:(.*)$/im.exec(headers)?.[1] ?? null;\n}\n\n/** Reads bounded server duration entries. A missing header gives no entries. */\nexport function readServerTiming(header: string | null): ServerTiming {\n const result: ServerTiming = { entries: [] };\n if (!header) {\n return result;\n }\n\n for (const part of splitHeader(header.slice(0, SERVER_TIMING_MAX_CHARS), \",\").slice(\n 0,\n SERVER_TIMING_MAX_ENTRIES,\n )) {\n const [rawName, ...params] = splitHeader(part, \";\");\n const name = rawName.trim();\n if (!/^[!#$%&'*+.^_`|~\\da-z-]+$/i.test(name)) {\n continue;\n }\n\n const entry: ServerTimingEntry = { name, duration: 0, description: \"\" };\n const seen = new Set<string>();\n for (const param of params) {\n const equal = param.indexOf(\"=\");\n if (equal < 0) {\n continue;\n }\n\n const key = param.slice(0, equal).trim().toLowerCase();\n if (seen.has(key)) {\n continue;\n }\n seen.add(key);\n\n let value = param.slice(equal + 1).trim();\n if (value.startsWith('\"') && value.endsWith('\"')) {\n value = value.slice(1, -1).replace(/\\\\(.)/g, \"$1\");\n }\n\n if (key === \"dur\") {\n const duration = Number(value);\n if (Number.isFinite(duration) && duration >= 0) {\n entry.duration = duration;\n }\n } else if (key === \"desc\") {\n entry.description = value;\n }\n }\n\n result.entries.push(entry);\n if (name.toLowerCase() === \"traceparent\") {\n const match = /^00-([\\da-f]{32})-([\\da-f]{16})-[\\da-f]{2}$/.exec(entry.description);\n if (match && /[1-9a-f]/.test(match[1]) && /[1-9a-f]/.test(match[2])) {\n result.link = { traceId: match[1], spanId: match[2] };\n }\n }\n }\n\n return result;\n}\n","// src/capture/network.ts\n//\n// Instruments fetch and XMLHttpRequest to record network request outcomes and timing.\n\nimport { SERVER_TIMING_HEADER } from \"../constants\";\nimport { readServerTiming, xhrServerTiming } from \"./server-timing\";\nimport type { InstrumentDef, MetricAttributes } from \"../models/metric\";\nimport { isErrorLike } from \"../utils/error-like\";\nimport { isLibraryRequest, isTransportPending } from \"../utils/library-request\";\nimport { patch } from \"../utils/patch\";\nimport { recordedUrl } from \"../utils/platform\";\nimport type { ClientSpan } from \"../utils/tracing\";\nimport { type Capture, type CaptureContext, matchesAny } from \"./types\";\n\n/** Signature of the global fetch function. */\ntype FetchFn = typeof fetch;\n\n/** Milliseconds in one second. The histogram is in seconds, as the OpenTelemetry name gives. */\nconst MS_PER_SECOND = 1000;\n\n/**\n * The HTTP client duration histogram of the OpenTelemetry semantic conventions. Its boundaries\n * are the ones that the conventions advise.\n */\nconst HTTP_DURATION: InstrumentDef = {\n name: \"http.client.request.duration\",\n kind: \"histogram\",\n unit: \"s\",\n boundaries: [0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10],\n};\n\n/**\n * Gives the low-cardinality attributes of one request. The path and the query stay out. Each\n * value of an attribute makes a new series in the backend.\n * @param method Uppercase HTTP method.\n * @param url Request URL.\n * @param status HTTP status code, or 0 when no response came.\n * @param error Failure of a request without a response.\n * @returns The attribute set.\n */\nfunction durationAttributes(\n method: string,\n url: string,\n status: number,\n error: unknown,\n): MetricAttributes {\n // A relative URL needs the page URL as its base. A worker has a location too.\n const base = typeof location !== \"undefined\" ? location.href : undefined;\n const attributes: MetricAttributes = {\n \"http.request.method\": method,\n \"server.address\": new URL(url, base).hostname,\n };\n\n if (status === 0) {\n // A request without a response has the type of its error, for example TypeError.\n const name = isErrorLike(error) ? error.name : \"\";\n attributes[\"error.type\"] = name === \"\" ? \"_OTHER\" : name;\n return attributes;\n }\n\n attributes[\"http.response.status_code\"] = status;\n if (status >= 400) {\n attributes[\"error.type\"] = String(status);\n }\n\n return attributes;\n}\n\n/** Request data that the XHR wrapper keeps from open to send. */\ninterface XhrMeta {\n /** Delivery context when the request started. */\n routingContextId?: string;\n /** Uppercase HTTP method. */\n method: string;\n /** Request target URL. */\n url: string;\n /** Performance timestamp at send. */\n startedAt: number;\n /** Client span that the traceparent names. */\n span?: ClientSpan;\n}\n\n/** XMLHttpRequest extended with internal telemetry tracking metadata. */\ntype Tracked = XMLHttpRequest & {\n __uiobs?: XhrMeta;\n};\n\n/** Unbound prototype methods intercepted on XMLHttpRequest. */\ninterface XhrMethods {\n open: (this: XMLHttpRequest, ...args: never[]) => void;\n send: (this: XMLHttpRequest, ...args: never[]) => void;\n}\n\n/** Returns the XMLHttpRequest prototype. */\nfunction xhrMethods(): XhrMethods {\n return XMLHttpRequest.prototype;\n}\n\n/** The fetch call to make, and the method and URL to record. */\ninterface FetchPlan {\n /** Delivery context when the request started. */\n routingContextId?: string;\n /** Uppercase HTTP method. */\n method: string;\n /** Request target URL. */\n url: string;\n /** Input to pass to the original fetch. */\n input: RequestInfo | URL;\n /** Init to pass to the original fetch. */\n init: RequestInit | undefined;\n /** Client span that the traceparent names. */\n span?: ClientSpan;\n}\n\n/**\n * Reads the URL of a fetch input or an XHR URL argument.\n * A Request from another realm fails `instanceof Request`. Its `url` property still works.\n * @param input String, URL, Request, or an object with a text form.\n * @returns The URL.\n * @throws TypeError when the input has no text form. Call it inside a diagnostics guard.\n */\nfunction readUrl(input: unknown): string {\n if (typeof input === \"string\") {\n return input;\n }\n\n if (input instanceof URL) {\n return input.href;\n }\n\n if (typeof input === \"object\" && input !== null) {\n const { url } = input as { url?: unknown };\n if (typeof url === \"string\") {\n return url;\n }\n }\n\n // fetch accepts each value with a text form.\n return String(input);\n}\n\n/**\n * Reads the method of a fetch call. The init method wins over the Request method.\n * @param input Fetch input.\n * @param init Fetch init.\n * @returns Uppercase method. The default is GET.\n */\nfunction readFetchMethod(input: unknown, init: RequestInit | undefined): string {\n let requested: unknown = init?.method;\n\n if (requested === undefined && typeof input === \"object\" && input !== null) {\n requested = (input as { method?: unknown }).method;\n }\n\n return toMethod(requested ?? \"GET\");\n}\n\n/**\n * Tests if a fetch input is an object that is not a Request or a URL of this realm.\n * An example is a Request from an iframe.\n * @param input Fetch input.\n * @returns True for a foreign object.\n */\nfunction isForeignInput(input: unknown): boolean {\n return typeof input === \"object\" && !(input instanceof URL) && !(input instanceof Request);\n}\n\n/**\n * Converts a method argument to text. A method that is not a string does not throw.\n * @param method Method argument of the caller.\n * @returns Uppercase method for a string, or the text form of another value.\n */\nfunction toMethod(method: unknown): string {\n return typeof method === \"string\" ? method.toUpperCase() : String(method);\n}\n\n/** Instruments global fetch and XMLHttpRequest to capture request durations and outcomes. */\nexport class NetworkCapture implements Capture {\n /** Capture module identifier. */\n readonly name = \"network\";\n\n /** Prevents a second wrap on a wrapped function. */\n private installed = false;\n\n /** Restore functions of the installed wrappers. */\n private readonly restores: (() => void)[] = [];\n\n /** True after the report of a request during a custom transport call. It reports one time. */\n private warnedTransport = false;\n\n /**\n * @param ctx Capture context containing configuration, diagnostics, logger, breadcrumbs, and tracing.\n */\n constructor(private readonly ctx: CaptureContext) {}\n\n /** Instruments configured network transport APIs. */\n install(): void {\n if (this.installed) {\n return;\n }\n this.installed = true;\n\n if (this.ctx.config.capture.fetch) {\n this.installFetch();\n }\n if (this.ctx.config.capture.xhr) {\n this.installXhr();\n }\n }\n\n /**\n * Restores each host function that still holds the wrapper of this capture.\n * A wrapper that another script wrapped again stays in place and records nothing.\n */\n uninstall(): void {\n if (!this.installed) {\n return;\n }\n this.installed = false;\n\n for (const restore of this.restores.splice(0)) {\n restore();\n }\n }\n\n /**\n * Tests if a URL matches ignore patterns.\n * @param url Request target URL.\n * @returns True if telemetry must exclude the URL.\n */\n private ignored(url: string): boolean {\n // resolveConfig always adds the endpoint to ignoreUrls. Without it, a failed POST\n // makes a log record. That record causes a new POST, and the loop does not stop.\n // A custom transport has no known URL. Its request starts inside the library scope.\n return isLibraryRequest() || matchesAny(url, this.ctx.config.capture.ignoreUrls);\n }\n\n /**\n * Tests if a request gets the trace headers.\n * @param url Request target URL.\n * @returns True if the URL is in propagateTraceHeaderTo.\n */\n private propagates(url: string): boolean {\n // Add headers only to allowlisted URLs. A traceparent on a third-party request causes\n // a CORS preflight. The third party does not answer it, and its API stops working.\n const targets = this.ctx.config.capture.propagateTraceHeaderTo;\n if (targets.length === 0) {\n return false;\n }\n\n // A string target is an origin. A relative URL resolves against the page.\n const origin = this.ctx.diagnostics.guard(\n \"capture.header_failed\",\n \"The library could not read the origin of a request URL. Only a RegExp target can match it.\",\n () => new URL(url, location.href).origin,\n );\n\n return targets.some((target) =>\n typeof target === \"string\" ? target === origin : target.test(url),\n );\n }\n\n /** Instruments globalThis.fetch with tracing injection and outcome logging. */\n private installFetch(): void {\n if (typeof globalThis.fetch !== \"function\") {\n return;\n }\n\n // Uninstall clears the flag. A wrapper that stays in place then only calls the original.\n let active = true;\n const prepare = (input: RequestInfo | URL, init: RequestInit | undefined) =>\n this.prepareFetch(input, init);\n const record = (\n plan: FetchPlan,\n status: number,\n durationMs: number,\n error: unknown,\n readTiming?: () => string | null,\n ): void => {\n this.record(\n plan.method,\n plan.url,\n status,\n durationMs,\n error,\n plan.span,\n plan.routingContextId,\n readTiming,\n );\n };\n\n const restore = patch(globalThis, \"fetch\", (original: FetchFn) => {\n const call = original.bind(globalThis);\n\n return async function instrumentedFetch(input, init) {\n const plan = active ? prepare(input, init) : undefined;\n if (!plan) {\n return call(input, init);\n }\n\n const startedAt = performance.now();\n try {\n const response = await call(plan.input, plan.init);\n record(plan, response.status, performance.now() - startedAt, undefined, () =>\n response.headers.get(SERVER_TIMING_HEADER),\n );\n return response;\n } catch (error) {\n record(plan, 0, performance.now() - startedAt, error);\n throw error;\n }\n };\n });\n\n this.restores.push(() => {\n active = false;\n restore();\n });\n }\n\n /**\n * Reads a fetch call and adds the trace headers to an allowlisted request.\n * @param input Fetch input of the caller.\n * @param init Fetch init of the caller.\n * @returns The plan, or undefined to send the request unchanged and record nothing.\n */\n private prepareFetch(\n input: RequestInfo | URL,\n init: RequestInit | undefined,\n ): FetchPlan | undefined {\n // A read here runs inside the fetch call of the caller. A throw must not fail the request.\n const read = this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not read a fetch request. It sends the request unchanged.\",\n (): { method: string; url: string; propagate: boolean } | undefined => {\n const url = readUrl(input);\n if (this.ignored(url)) {\n return undefined;\n }\n\n return { method: readFetchMethod(input, init), url, propagate: this.propagates(url) };\n },\n );\n\n if (!read) {\n return undefined;\n }\n\n const { method, url } = read;\n const plan: FetchPlan = {\n method,\n url,\n input,\n init,\n routingContextId: this.ctx.config.securityContext.id,\n };\n // An init with headers replaces all headers of a foreign Request, for example\n // Authorization. Send a foreign input without the trace headers.\n if (!read.propagate || isForeignInput(input)) {\n return plan;\n }\n\n try {\n const trace = this.ctx.tracing.request();\n const injected = Object.entries(trace.headers);\n\n if (input instanceof Request) {\n // Do not spread a non-empty init with a Request input. That runs the Request\n // constructor on `input` again and reads its body. A second read of a body\n // causes a TypeError.\n const headers = new Headers(input.headers);\n for (const [key, value] of injected) {\n headers.set(key, value);\n }\n plan.input = new Request(input, { headers });\n } else {\n const headers = new Headers(init?.headers);\n for (const [key, value] of injected) {\n headers.set(key, value);\n }\n plan.init = { ...init, headers };\n }\n\n // Record the client span only for a request that carries its traceparent.\n plan.span = trace.span;\n } catch (error) {\n // Send the request that the caller gave, without changes. A missing header is\n // better than a failed request.\n plan.input = input;\n plan.init = init;\n this.ctx.diagnostics.report(\n \"capture.header_failed\",\n \"The library could not add the traceparent header. It sends the request unchanged.\",\n { url },\n error,\n );\n }\n\n return plan;\n }\n\n /** Instruments XMLHttpRequest open and send prototype methods. */\n private installXhr(): void {\n if (typeof XMLHttpRequest === \"undefined\") {\n return;\n }\n\n // Uninstall clears the flag. A wrapper that stays in place then only calls the original.\n let active = true;\n const ctx = this.ctx;\n const ignored = (url: string): boolean => this.ignored(url);\n const propagates = (url: string): boolean => this.propagates(url);\n const record = (\n meta: XhrMeta,\n status: number,\n durationMs: number,\n readTiming: () => string | null,\n ): void => {\n this.record(\n meta.method,\n meta.url,\n status,\n durationMs,\n undefined,\n meta.span,\n meta.routingContextId,\n readTiming,\n );\n };\n\n const proto = xhrMethods();\n\n const restoreOpen = patch(\n proto,\n \"open\",\n (originalOpen) =>\n function (this: Tracked, method: unknown, url: unknown, ...rest: never[]) {\n if (active) {\n // A read here runs inside the open call of the caller. A throw must not fail it.\n ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not read an XMLHttpRequest. It does not record the request.\",\n () => {\n this.__uiobs = { method: toMethod(method), url: readUrl(url), startedAt: 0 };\n },\n );\n }\n originalOpen.apply(this, [method, url, ...rest] as never[]);\n },\n );\n\n const restoreSend = patch(\n proto,\n \"send\",\n (originalSend) =>\n function (this: Tracked, ...args: never[]) {\n const meta = active ? this.__uiobs : undefined;\n if (meta) {\n ctx.diagnostics.guard(\n \"capture.record_failed\",\n `The library could not record ${meta.method} ${meta.url}.`,\n () => {\n if (ignored(meta.url)) {\n return;\n }\n\n meta.startedAt = performance.now();\n meta.routingContextId = ctx.config.securityContext.id;\n // A reused XHR gets a new listener at each send. The old one must not fire again.\n this.addEventListener(\n \"loadend\",\n () => {\n record(meta, this.status, performance.now() - meta.startedAt, () =>\n xhrServerTiming(this.getAllResponseHeaders()),\n );\n },\n { once: true },\n );\n\n // setRequestHeader works only between open and send.\n if (propagates(meta.url)) {\n meta.span = addTraceHeaders(this, meta.url, ctx);\n }\n },\n );\n }\n originalSend.apply(this, args);\n },\n );\n\n this.restores.push(() => {\n active = false;\n restoreOpen();\n restoreSend();\n });\n }\n\n /**\n * Records request outcome attributes and breadcrumb entry.\n * @param method Uppercase HTTP method.\n * @param target Request target URL. The method removes the query unless you set fullUrls.\n * @param status HTTP response status code, or 0 on failure.\n * @param durationMs Request duration in milliseconds.\n * @param error Caught error instance on failed requests.\n * @param span Client span that the traceparent of the request names.\n */\n private record(\n method: string,\n target: string,\n status: number,\n durationMs: number,\n error: unknown,\n span?: ClientSpan,\n routingContextId?: string,\n readTiming?: () => string | null,\n ): void {\n if (\n this.ctx.isActive?.() === false ||\n (this.ctx.config.securityContext.isolation &&\n routingContextId !== undefined &&\n routingContextId !== this.ctx.config.securityContext.id)\n ) {\n return;\n }\n\n const timing =\n this.ctx.config.capture.serverTiming && readTiming\n ? this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not read the Server-Timing response header.\",\n () => readServerTiming(readTiming()),\n )\n : undefined;\n\n // Remove the query here, not at the call sites. ignoreUrls and propagateTraceHeaderTo\n // match on the full URL. Only the recorded URL loses the query string.\n const url = recordedUrl(\n target,\n this.ctx.config.capture.fullUrls,\n this.ctx.config.capture.urlTransform,\n this.ctx.diagnostics,\n );\n\n // A request of the transport after an await records a value. That value causes the next send.\n if (!this.warnedTransport && isTransportPending()) {\n this.warnedTransport = true;\n this.ctx.diagnostics.report(\n \"capture.transport_request\",\n `Network capture saw ${method} ${url} during a custom transport call. If the transport sends this request, add its URL to capture.ignoreUrls.`,\n );\n }\n\n // The histogram has its own guard. A URL that does not parse must not stop the record.\n if (this.ctx.config.capture.httpMetrics) {\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n `The library could not record the duration of ${method} ${url}.`,\n () => {\n const attributes = durationAttributes(method, target, status, error);\n this.ctx.recordMetric(HTTP_DURATION, durationMs / MS_PER_SECOND, attributes);\n },\n );\n }\n\n if (span) {\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n `The library could not record the span of ${method} ${url}.`,\n () => {\n const endMs = Date.now();\n this.ctx.recordSpan({\n ...span,\n link: timing?.link,\n name: method,\n kind: \"client\",\n startMs: endMs - durationMs,\n endMs,\n error: status === 0 || status >= 400,\n attributes: { ...durationAttributes(method, target, status, error), \"url.full\": url },\n });\n },\n );\n }\n\n // This code runs inside the fetch call of the caller. An error here must not cause\n // the request of the caller to fail.\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n `The library could not record ${method} ${url}.`,\n () => {\n const rounded = Math.round(durationMs);\n\n this.ctx.breadcrumbs.push({\n t: Date.now(),\n category: \"http\",\n message: `${method} ${url} ${status === 0 ? \"failed\" : String(status)}`,\n data: { durationMs: rounded },\n });\n\n const attributes = {\n \"http.request.method\": method,\n \"url.full\": url,\n \"http.response.status_code\": status,\n \"http.duration_ms\": rounded,\n ...(timing && timing.entries.length > 0 ? { \"server.timing\": timing.entries } : {}),\n };\n\n if (status === 0) {\n this.ctx.logger.error(`${method} ${url} failed`, error, attributes);\n return;\n }\n if (status >= 400) {\n this.ctx.logger.warn(`${method} ${url} returned ${String(status)}`, attributes);\n return;\n }\n\n // Log a success at DEBUG. The default minLevel of INFO drops it.\n // Only failures use bandwidth.\n this.ctx.logger.debug(`${method} ${url}`, attributes);\n },\n );\n }\n}\n\n/**\n * Adds the trace headers to an open XHR. A failure sends the request without them.\n * @param xhr Request between open and send.\n * @param url Request target URL, for the diagnostic.\n * @param ctx Capture context with tracing and diagnostics.\n * @returns The client span that the traceparent names, or undefined.\n */\nfunction addTraceHeaders(\n xhr: XMLHttpRequest,\n url: string,\n ctx: CaptureContext,\n): ClientSpan | undefined {\n try {\n const trace = ctx.tracing.request();\n for (const [key, value] of Object.entries(trace.headers)) {\n xhr.setRequestHeader(key, value);\n }\n return trace.span;\n } catch (error) {\n ctx.diagnostics.report(\n \"capture.header_failed\",\n \"The library could not add the traceparent header. It sends the request unchanged.\",\n { url },\n error,\n );\n return undefined;\n }\n}\n"],"mappings":"A,wOAgBA,SAASc,EAAY,EAAc,EAA6B,CAC9D,IAAMC,EAAkB,CAAC,EACrBC,EAAQ,EACRC,EAAS,GACTC,EAAU,GAEd,IAAK,IAAIC,EAAI,EAAGA,EAAIC,EAAK,OAAQ,IAAK,CACpC,IAAMC,EAAOD,EAAKD,GACdD,EACF,EAAU,GACDD,GAAUI,IAAS,KAC5B,EAAU,GACDA,IAAS,IAClB,EAAS,CAACJ,EAC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CAAC,CACnF,EAEIzC,IAAW,EACb,KAAK,IAAI,OAAO,MAAM,GAAGF,EAAO,GAAGC,EAAI,SAAUE,EAAOJ,CAAU,EAGhEG,GAAU,IACZ,KAAK,IAAI,OAAO,KAAK,GAAGF,EAAO,GAAGC,EAAI,YAAY,OAAOC,CAAM,IAAKH,CAAU,EAMhF,KAAK,IAAI,OAAO,MAAM,GAAGC,EAAO,GAAGC,IAAOF,CAAU,CACtD,CACF,CACF,CACF,EASA,SAASyC,EACP,EACA,EACA,EACwB,CACxB,GAAI,CACF,IAAMX,EAAQhB,EAAI,QAAQ,QAAQ,EAClC,IAAK,GAAM,CAACtB,EAAKC,KAAU,OAAO,QAAQqC,EAAM,OAAO,EACrDkB,EAAI,iBAAiBxD,EAAKC,CAAK,EAEjC,OAAOqC,EAAM,IACf,OAAS1B,EAAO,CACdU,EAAI,YAAY,OACd,wBACA,oFACA,CAAE,KAAI,EACNV,CACF,EACA,MACF,CACF,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openfin-
|
|
1
|
+
{"version":3,"file":"openfin-Bxelt0yg.js","names":["getFin"],"sources":["../src/utils/openfin.ts"],"sourcesContent":["// src/utils/openfin.ts\n//\n// Reads the optional OpenFin runtime API. The library does not import an OpenFin package. The\n// types list only the members that the library reads. Each member is optional, because a test, an\n// older runtime or OpenFin web can leave it out.\n\n/** The InterApplicationBus operations that the bus link uses. */\nexport interface FinIab {\n /**\n * Publishes a message to all topic subscribers.\n * @param topic Topic name.\n * @param message Message payload.\n */\n publish(topic: string, message: unknown): Promise<void>;\n\n /**\n * Subscribes a listener to a topic for matching application identities.\n * @param identity Target application identity.\n * @param topic Topic name.\n * @param listener Message callback.\n */\n subscribe(\n identity: { uuid: string },\n topic: string,\n listener: (message: unknown, uuid?: string, name?: string) => void,\n ): Promise<void>;\n}\n\n/** The members of fin.me that the library reads. */\nexport interface FinMe {\n /** True in an OpenFin view. */\n isView?: boolean;\n /** Identity of the window or view. */\n identity?: { uuid?: string; name?: string };\n /** Resolves the creation options of the window, with customData. */\n getOptions?: () => Promise<{ customData?: Record<string, unknown> }>;\n /** Adds a window event listener. */\n on?: (event: string, listener: () => void) => void;\n /** Removes a window event listener. */\n removeListener?: (event: string, listener: () => void) => void;\n}\n\n/** The members of the OpenFin global that the library reads. */\nexport interface FinLike {\n /** The window or view of this document. */\n me?: FinMe;\n /** The message bus of the OpenFin runtime. */\n InterApplicationBus?: FinIab;\n}\n\n/**\n * Gives the OpenFin global.\n * @returns The fin global, or undefined outside OpenFin.\n */\nexport function getFin(): FinLike | undefined {\n return (globalThis as { fin?: FinLike }).fin;\n}\n"],"mappings":";AAsDA,SAAgBA,IAA8B;CAC5C,OAAQ,WAAiC;AAC3C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openfin-DtH2f7zX.cjs","names":["getFin"],"sources":["../src/utils/openfin.ts"],"sourcesContent":["// src/utils/openfin.ts\n//\n// Reads the optional OpenFin runtime API. The library does not import an OpenFin package. The\n// types list only the members that the library reads. Each member is optional, because a test, an\n// older runtime or OpenFin web can leave it out.\n\n/** The InterApplicationBus operations that the bus link uses. */\nexport interface FinIab {\n /**\n * Publishes a message to all topic subscribers.\n * @param topic Topic name.\n * @param message Message payload.\n */\n publish(topic: string, message: unknown): Promise<void>;\n\n /**\n * Subscribes a listener to a topic for matching application identities.\n * @param identity Target application identity.\n * @param topic Topic name.\n * @param listener Message callback.\n */\n subscribe(\n identity: { uuid: string },\n topic: string,\n listener: (message: unknown, uuid?: string, name?: string) => void,\n ): Promise<void>;\n}\n\n/** The members of fin.me that the library reads. */\nexport interface FinMe {\n /** True in an OpenFin view. */\n isView?: boolean;\n /** Identity of the window or view. */\n identity?: { uuid?: string; name?: string };\n /** Resolves the creation options of the window, with customData. */\n getOptions?: () => Promise<{ customData?: Record<string, unknown> }>;\n /** Adds a window event listener. */\n on?: (event: string, listener: () => void) => void;\n /** Removes a window event listener. */\n removeListener?: (event: string, listener: () => void) => void;\n}\n\n/** The members of the OpenFin global that the library reads. */\nexport interface FinLike {\n /** The window or view of this document. */\n me?: FinMe;\n /** The message bus of the OpenFin runtime. */\n InterApplicationBus?: FinIab;\n}\n\n/**\n * Gives the OpenFin global.\n * @returns The fin global, or undefined outside OpenFin.\n */\nexport function getFin(): FinLike | undefined {\n return (globalThis as { fin?: FinLike }).fin;\n}\n"],"mappings":"AAsDA,SAAgBA,GAA8B,CAC5C,OAAQ,WAAiC,GAC3C"}
|
|
1
|
+
{"version":3,"file":"openfin-DtH2f7zX.cjs","names":["getFin"],"sources":["../src/utils/openfin.ts"],"sourcesContent":["// src/utils/openfin.ts\n//\n// Reads the optional OpenFin runtime API. The library does not import an OpenFin package. The\n// types list only the members that the library reads. Each member is optional, because a test, an\n// older runtime or OpenFin web can leave it out.\n\n/** The InterApplicationBus operations that the bus link uses. */\nexport interface FinIab {\n /**\n * Publishes a message to all topic subscribers.\n * @param topic Topic name.\n * @param message Message payload.\n */\n publish(topic: string, message: unknown): Promise<void>;\n\n /**\n * Subscribes a listener to a topic for matching application identities.\n * @param identity Target application identity.\n * @param topic Topic name.\n * @param listener Message callback.\n */\n subscribe(\n identity: { uuid: string },\n topic: string,\n listener: (message: unknown, uuid?: string, name?: string) => void,\n ): Promise<void>;\n}\n\n/** The members of fin.me that the library reads. */\nexport interface FinMe {\n /** True in an OpenFin view. */\n isView?: boolean;\n /** Identity of the window or view. */\n identity?: { uuid?: string; name?: string };\n /** Resolves the creation options of the window, with customData. */\n getOptions?: () => Promise<{ customData?: Record<string, unknown> }>;\n /** Adds a window event listener. */\n on?: (event: string, listener: () => void) => void;\n /** Removes a window event listener. */\n removeListener?: (event: string, listener: () => void) => void;\n}\n\n/** The members of the OpenFin global that the library reads. */\nexport interface FinLike {\n /** The window or view of this document. */\n me?: FinMe;\n /** The message bus of the OpenFin runtime. */\n InterApplicationBus?: FinIab;\n}\n\n/**\n * Gives the OpenFin global.\n * @returns The fin global, or undefined outside OpenFin.\n */\nexport function getFin(): FinLike | undefined {\n return (globalThis as { fin?: FinLike }).fin;\n}\n"],"mappings":"AAsDA,SAAgBA,GAA8B,CAC5C,OAAQ,WAAiC,GAC3C,C"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./constants-
|
|
2
|
-
//# sourceMappingURL=otlp-
|
|
1
|
+
const e=require("./constants-DqKJH_MP.cjs");async function t(t){let n=globalThis.CompressionStream;if(n===void 0)return null;let r=new Blob([t]).stream().pipeThrough(new n(e.tt)),i=await new Response(r).arrayBuffer();return new Uint8Array(i)}function n(e){return e==null?null:typeof e==`string`?{stringValue:e}:typeof e==`boolean`?{boolValue:e}:typeof e==`number`?Number.isSafeInteger(e)?{intValue:String(e)}:{doubleValue:e}:typeof e==`bigint`?{intValue:e.toString()}:Array.isArray(e)?{arrayValue:{values:e.map(n).filter(e=>e!==null)}}:typeof e==`object`?{kvlistValue:{values:r(e)}}:null}function r(e){let t=[];for(let[r,i]of Object.entries(e)){let e=n(i);e&&t.push({key:r,value:e})}return t}var i=new WeakMap;function a(e){let t=i.get(e);if(t!==void 0)return t;let n=JSON.stringify(e);return i.set(e,n),n}function o(e){let t=new Map;for(let n of e){let e=a(n.resource),r=t.get(e);r?r.records.push(n):t.set(e,{resource:n.resource,records:[n]})}return[...t.values()]}function s(t){let n=new Map;for(let r of t){let t=r.attributes[e.a],i=typeof t==`string`&&t?t:e.Mn,a=n.get(i);a?a.push(r):n.set(i,[r])}return[...n].map(([e,t])=>({name:e,records:t}))}var c={name:e.mn,serialize(t){let n=o(t).map(e=>({resource:{attributes:r(e.resource)},scopeLogs:s(e.records).map(e=>({scope:{name:e.name},logRecords:e.records.map(e=>({timeUnixNano:e.timeUnixNano,observedTimeUnixNano:e.observedTimeUnixNano??e.timeUnixNano,severityNumber:e.severityNumber,severityText:e.severityText,body:{stringValue:e.body},traceId:e.traceId,spanId:e.spanId,flags:e.traceFlags,attributes:r(e.attributes)}))}))}));return{body:JSON.stringify({resourceLogs:n}),contentType:e.R}}};Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return o}});
|
|
2
|
+
//# sourceMappingURL=otlp-BDvFrLnc.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otlp-RVbkNQRh.cjs","names":["ENCODING_GZIP","items","nested","ATTR_APP_NAMESPACE","TELEMETRY_SDK_NAME","SERIALIZER_NAME_OTLP","CONTENT_TYPE_JSON","require_constants","gzip","CS","stream","text","buffer","toAnyValue","value","item","toKeyValues","out","key","raw","source","resourceKeys","resourceKey","cached","resource","groupByResource","groups","record","records","group","groupByScope","namespace","name","scoped","otlpSerializer","resourceLogs","scope"],"sources":["../src/transport/compression.ts","../src/transport/serializers/otlp.ts"],"sourcesContent":["// src/transport/compression.ts\n//\n// This module compresses payloads with the native CompressionStream API. It returns null\n// when the API is absent. It does not return raw text. The server rejects a non-gzip body\n// that has a \"Content-Encoding: gzip\" header with a 400 status.\n\nimport { ENCODING_GZIP } from \"../constants\";\n\n/**\n * Compresses a string to gzip bytes with CompressionStream. The result is a\n * Uint8Array on a non-shared ArrayBuffer. fetch accepts this result as BodyInit.\n * @param text Raw serialized payload to compress.\n * @returns Promise that resolves to the gzip bytes, or null without CompressionStream.\n */\nexport async function gzip(text: string): Promise<Uint8Array<ArrayBuffer> | null> {\n const CS = (globalThis as { CompressionStream?: typeof CompressionStream }).CompressionStream;\n if (CS === undefined) {\n return null;\n }\n\n const stream = new Blob([text]).stream().pipeThrough(new CS(ENCODING_GZIP));\n const buffer = await new Response(stream).arrayBuffer();\n\n return new Uint8Array(buffer);\n}\n","// src/transport/serializers/otlp.ts\n//\n// This module serializes log batches as OTLP/JSON log records. It groups the records by resource.\n// It gives each logger namespace its own instrumentation scope.\n// The OTLP metrics serializer uses its value encoding and its resource grouping.\n\nimport {\n ATTR_APP_NAMESPACE,\n CONTENT_TYPE_JSON,\n SERIALIZER_NAME_OTLP,\n TELEMETRY_SDK_NAME,\n} from \"../../constants\";\nimport type { LogRecord } from \"../../models/log-record\";\nimport type { LogSerializer, SerializedBatch } from \"../../models/serializer\";\n\n/** This type holds an OTLP AnyValue with typed value wrappers. */\ntype AnyValue = Record<string, unknown>;\n\n/** This interface holds an OTLP KeyValue pair. */\nexport interface KeyValue {\n /** This field holds the attribute key. */\n key: string;\n /** This field holds the typed AnyValue. */\n value: AnyValue;\n}\n\n/** This interface holds the records that share resource attributes. */\nexport interface ResourceGroup {\n /** This field holds the resource attribute map. */\n resource: Record<string, unknown>;\n /** This field holds the log records of the resource. */\n records: LogRecord[];\n}\n\n/**\n * Wraps a JavaScript value in an OTLP AnyValue.\n * @param value Raw attribute or resource value.\n * @returns Typed AnyValue object or null if unsupported.\n */\nfunction toAnyValue(value: unknown): AnyValue | null {\n if (value === null || value === undefined) {\n return null;\n }\n\n if (typeof value === \"string\") {\n return { stringValue: value };\n }\n\n if (typeof value === \"boolean\") {\n return { boolValue: value };\n }\n\n // Encode int64 as a decimal string. The OTLP protobuf JSON mapping requires it. A conforming\n // collector returns a 400 status for a number. The response does not give the cause.\n // An integer above MAX_SAFE_INTEGER goes to doubleValue. Its text can be \"1e+21\" or overflow int64.\n if (typeof value === \"number\") {\n return Number.isSafeInteger(value) ? { intValue: String(value) } : { doubleValue: value };\n }\n\n // Convert a BigInt to a decimal string. JSON.stringify throws on a BigInt and loses the\n // batch.\n if (typeof value === \"bigint\") {\n return { intValue: value.toString() };\n }\n\n if (Array.isArray(value)) {\n const items: readonly unknown[] = value;\n const values = items.map(toAnyValue).filter((item): item is AnyValue => item !== null);\n\n return { arrayValue: { values } };\n }\n\n if (typeof value === \"object\") {\n const nested = value as Record<string, unknown>;\n return { kvlistValue: { values: toKeyValues(nested) } };\n }\n\n return null;\n}\n\n/**\n * Converts a plain object to an array of OTLP KeyValue pairs.\n * @param source Key-value attribute object.\n * @returns Array of valid KeyValue pairs.\n */\nexport function toKeyValues(source: Record<string, unknown>): KeyValue[] {\n const out: KeyValue[] = [];\n\n for (const [key, raw] of Object.entries(source)) {\n const value = toAnyValue(raw);\n if (value) {\n out.push({ key, value });\n }\n }\n\n return out;\n}\n\n/** This map caches the JSON key of each resource object. It prevents a repeated stringify. */\nconst resourceKeys = new WeakMap<object, string>();\n\n/**\n * Returns the stable JSON key of a resource object. It caches the key.\n * @param resource Resource attribute object.\n * @returns JSON key string.\n */\nfunction resourceKey(resource: Record<string, unknown>): string {\n const cached = resourceKeys.get(resource);\n if (cached !== undefined) {\n return cached;\n }\n\n const key = JSON.stringify(resource);\n resourceKeys.set(resource, key);\n\n return key;\n}\n\n/**\n * Groups records by their resource attributes. It keeps the record order in each group.\n * @param records Records to group.\n * @returns One group for each resource.\n */\nexport function groupByResource(records: LogRecord[]): ResourceGroup[] {\n const groups = new Map<string, ResourceGroup>();\n\n for (const record of records) {\n const key = resourceKey(record.resource);\n const group = groups.get(key);\n\n if (group) {\n group.records.push(record);\n continue;\n }\n\n groups.set(key, { resource: record.resource, records: [record] });\n }\n\n return [...groups.values()];\n}\n\n/** This interface holds the records of one instrumentation scope. */\nexport interface ScopeGroup {\n /** This field holds the scope name. It is the logger namespace. */\n name: string;\n /** This field holds the records of the scope. */\n records: LogRecord[];\n}\n\n/**\n * Groups records by their logger namespace. It keeps the record order in each group.\n * A record without a namespace goes to the scope of the library.\n * @param records Records of one resource.\n * @returns One group for each namespace.\n */\nexport function groupByScope(records: LogRecord[]): ScopeGroup[] {\n const groups = new Map<string, LogRecord[]>();\n\n for (const record of records) {\n const namespace: unknown = record.attributes[ATTR_APP_NAMESPACE];\n const name = typeof namespace === \"string\" && namespace ? namespace : TELEMETRY_SDK_NAME;\n const group = groups.get(name);\n\n if (group) {\n group.push(record);\n continue;\n }\n\n groups.set(name, [record]);\n }\n\n return [...groups].map(([name, scoped]) => ({ name, records: scoped }));\n}\n\n/** This serializer writes log records as OTLP/JSON payloads. */\nexport const otlpSerializer: LogSerializer = {\n /** This field holds the format name. */\n name: SERIALIZER_NAME_OTLP,\n\n /**\n * Groups records by resource. It encodes them as an OTLP\n * ExportLogsServiceRequest JSON payload.\n * @param records Array of log records to serialize.\n * @returns Serialized JSON batch payload.\n */\n serialize(records: LogRecord[]): SerializedBatch {\n const resourceLogs = groupByResource(records).map((group) => ({\n resource: { attributes: toKeyValues(group.resource) },\n scopeLogs: groupByScope(group.records).map((scope) => ({\n scope: { name: scope.name },\n logRecords: scope.records.map((record) => ({\n timeUnixNano: record.timeUnixNano,\n // Use timeUnixNano when observedTimeUnixNano is not set.\n observedTimeUnixNano: record.observedTimeUnixNano ?? record.timeUnixNano,\n severityNumber: record.severityNumber,\n severityText: record.severityText,\n body: { stringValue: record.body },\n traceId: record.traceId,\n spanId: record.spanId,\n flags: record.traceFlags,\n attributes: toKeyValues(record.attributes),\n })),\n })),\n }));\n\n return {\n body: JSON.stringify({ resourceLogs }),\n contentType: CONTENT_TYPE_JSON,\n };\n },\n};\n"],"mappings":"4CAcA,eAAsBQ,EAAK,EAAuD,CAChF,IAAMC,EAAM,WAAgE,kBAC5E,GAAIA,IAAO,IAAA,GACT,OAAO,KAGT,IAAMC,EAAS,IAAI,KAAK,CAACC,CAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,YAAY,IAAIF,EAAGT,EAAAA,EAAa,CAAC,EACpEY,EAAS,MAAM,IAAI,SAASF,CAAM,CAAC,CAAC,YAAY,EAEtD,OAAO,IAAI,WAAWE,CAAM,CAC9B,CCeA,SAASC,EAAW,EAAiC,CAsCnD,OArCIC,GAAU,KACL,KAGL,OAAOA,GAAU,SACZ,CAAE,YAAaA,CAAM,EAG1B,OAAOA,GAAU,UACZ,CAAE,UAAWA,CAAM,EAMxB,OAAOA,GAAU,SACZ,OAAO,cAAcA,CAAK,EAAI,CAAE,SAAU,OAAOA,CAAK,CAAE,EAAI,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,EAAO,OAAOD,GAAc,UAAYA,EAAYA,EAAY3B,EAAAA,GAChEyB,EAAQH,EAAO,IAAIM,CAAI,EAEzBH,EACFA,EAAM,KAAKF,CAAM,EAInBD,EAAO,IAAIM,EAAM,CAACL,CAAM,CAAC,CAC3B,CAEA,MAAO,CAAC,GAAGD,CAAM,CAAC,CAAC,KAAK,CAACM,EAAMC,MAAa,CAAE,OAAM,QAASA,CAAO,EAAE,CACxE,CAGA,IAAaC,EAAgC,CAE3C,KAAM7B,EAAAA,GAQN,UAAU,EAAuC,CAC/C,IAAM8B,EAAeV,EAAgBG,CAAO,CAAC,CAAC,IAAK,IAAW,CAC5D,SAAU,CAAE,WAAYZ,EAAYa,EAAM,QAAQ,CAAE,EACpD,UAAWC,EAAaD,EAAM,OAAO,CAAC,CAAC,IAAK,IAAW,CACrD,MAAO,CAAE,KAAMO,EAAM,IAAK,EAC1B,WAAYA,EAAM,QAAQ,IAAK,IAAY,CACzC,aAAcT,EAAO,aAErB,qBAAsBA,EAAO,sBAAwBA,EAAO,aAC5D,eAAgBA,EAAO,eACvB,aAAcA,EAAO,aACrB,KAAM,CAAE,YAAaA,EAAO,IAAK,EACjC,QAASA,EAAO,QAChB,OAAQA,EAAO,OACf,MAAOA,EAAO,WACd,WAAYX,EAAYW,EAAO,UAAU,CAC3C,EAAE,CACJ,EAAE,CACJ,EAAE,EAEF,MAAO,CACL,KAAM,KAAK,UAAU,CAAE,cAAa,CAAC,EACrC,YAAarB,EAAAA,CACf,CACF,CACF"}
|
|
1
|
+
{"version":3,"file":"otlp-BDvFrLnc.cjs","names":["ENCODING_GZIP","items","nested","ATTR_APP_NAMESPACE","TELEMETRY_SDK_NAME","SERIALIZER_NAME_OTLP","CONTENT_TYPE_JSON","require_constants","gzip","CS","stream","text","buffer","toAnyValue","value","item","toKeyValues","out","key","raw","source","resourceKeys","resourceKey","cached","resource","groupByResource","groups","record","records","group","groupByScope","namespace","name","scoped","otlpSerializer","resourceLogs","scope"],"sources":["../src/transport/compression.ts","../src/transport/serializers/otlp.ts"],"sourcesContent":["// src/transport/compression.ts\n//\n// This module compresses payloads with the native CompressionStream API. It returns null\n// when the API is absent. It does not return raw text. The server rejects a non-gzip body\n// that has a \"Content-Encoding: gzip\" header with a 400 status.\n\nimport { ENCODING_GZIP } from \"../constants\";\n\n/**\n * Compresses a string to gzip bytes with CompressionStream. The result is a\n * Uint8Array on a non-shared ArrayBuffer. fetch accepts this result as BodyInit.\n * @param text Raw serialized payload to compress.\n * @returns Promise that resolves to the gzip bytes, or null without CompressionStream.\n */\nexport async function gzip(text: string): Promise<Uint8Array<ArrayBuffer> | null> {\n const CS = (globalThis as { CompressionStream?: typeof CompressionStream }).CompressionStream;\n if (CS === undefined) {\n return null;\n }\n\n const stream = new Blob([text]).stream().pipeThrough(new CS(ENCODING_GZIP));\n const buffer = await new Response(stream).arrayBuffer();\n\n return new Uint8Array(buffer);\n}\n","// src/transport/serializers/otlp.ts\n//\n// This module serializes log batches as OTLP/JSON log records. It groups the records by resource.\n// It gives each logger namespace its own instrumentation scope.\n// The OTLP metrics serializer uses its value encoding and its resource grouping.\n\nimport {\n ATTR_APP_NAMESPACE,\n CONTENT_TYPE_JSON,\n SERIALIZER_NAME_OTLP,\n TELEMETRY_SDK_NAME,\n} from \"../../constants\";\nimport type { LogRecord } from \"../../models/log-record\";\nimport type { LogSerializer, SerializedBatch } from \"../../models/serializer\";\n\n/** This type holds an OTLP AnyValue with typed value wrappers. */\ntype AnyValue = Record<string, unknown>;\n\n/** This interface holds an OTLP KeyValue pair. */\nexport interface KeyValue {\n /** This field holds the attribute key. */\n key: string;\n /** This field holds the typed AnyValue. */\n value: AnyValue;\n}\n\n/** This interface holds the records that share resource attributes. */\nexport interface ResourceGroup {\n /** This field holds the resource attribute map. */\n resource: Record<string, unknown>;\n /** This field holds the log records of the resource. */\n records: LogRecord[];\n}\n\n/**\n * Wraps a JavaScript value in an OTLP AnyValue.\n * @param value Raw attribute or resource value.\n * @returns Typed AnyValue object or null if unsupported.\n */\nfunction toAnyValue(value: unknown): AnyValue | null {\n if (value === null || value === undefined) {\n return null;\n }\n\n if (typeof value === \"string\") {\n return { stringValue: value };\n }\n\n if (typeof value === \"boolean\") {\n return { boolValue: value };\n }\n\n // Encode int64 as a decimal string. The OTLP protobuf JSON mapping requires it. A conforming\n // collector returns a 400 status for a number. The response does not give the cause.\n // An integer above MAX_SAFE_INTEGER goes to doubleValue. Its text can be \"1e+21\" or overflow int64.\n if (typeof value === \"number\") {\n return Number.isSafeInteger(value) ? { intValue: String(value) } : { doubleValue: value };\n }\n\n // Convert a BigInt to a decimal string. JSON.stringify throws on a BigInt and loses the\n // batch.\n if (typeof value === \"bigint\") {\n return { intValue: value.toString() };\n }\n\n if (Array.isArray(value)) {\n const items: readonly unknown[] = value;\n const values = items.map(toAnyValue).filter((item): item is AnyValue => item !== null);\n\n return { arrayValue: { values } };\n }\n\n if (typeof value === \"object\") {\n const nested = value as Record<string, unknown>;\n return { kvlistValue: { values: toKeyValues(nested) } };\n }\n\n return null;\n}\n\n/**\n * Converts a plain object to an array of OTLP KeyValue pairs.\n * @param source Key-value attribute object.\n * @returns Array of valid KeyValue pairs.\n */\nexport function toKeyValues(source: Record<string, unknown>): KeyValue[] {\n const out: KeyValue[] = [];\n\n for (const [key, raw] of Object.entries(source)) {\n const value = toAnyValue(raw);\n if (value) {\n out.push({ key, value });\n }\n }\n\n return out;\n}\n\n/** This map caches the JSON key of each resource object. It prevents a repeated stringify. */\nconst resourceKeys = new WeakMap<object, string>();\n\n/**\n * Returns the stable JSON key of a resource object. It caches the key.\n * @param resource Resource attribute object.\n * @returns JSON key string.\n */\nfunction resourceKey(resource: Record<string, unknown>): string {\n const cached = resourceKeys.get(resource);\n if (cached !== undefined) {\n return cached;\n }\n\n const key = JSON.stringify(resource);\n resourceKeys.set(resource, key);\n\n return key;\n}\n\n/**\n * Groups records by their resource attributes. It keeps the record order in each group.\n * @param records Records to group.\n * @returns One group for each resource.\n */\nexport function groupByResource(records: LogRecord[]): ResourceGroup[] {\n const groups = new Map<string, ResourceGroup>();\n\n for (const record of records) {\n const key = resourceKey(record.resource);\n const group = groups.get(key);\n\n if (group) {\n group.records.push(record);\n continue;\n }\n\n groups.set(key, { resource: record.resource, records: [record] });\n }\n\n return [...groups.values()];\n}\n\n/** This interface holds the records of one instrumentation scope. */\nexport interface ScopeGroup {\n /** This field holds the scope name. It is the logger namespace. */\n name: string;\n /** This field holds the records of the scope. */\n records: LogRecord[];\n}\n\n/**\n * Groups records by their logger namespace. It keeps the record order in each group.\n * A record without a namespace goes to the scope of the library.\n * @param records Records of one resource.\n * @returns One group for each namespace.\n */\nexport function groupByScope(records: LogRecord[]): ScopeGroup[] {\n const groups = new Map<string, LogRecord[]>();\n\n for (const record of records) {\n const namespace: unknown = record.attributes[ATTR_APP_NAMESPACE];\n const name = typeof namespace === \"string\" && namespace ? namespace : TELEMETRY_SDK_NAME;\n const group = groups.get(name);\n\n if (group) {\n group.push(record);\n continue;\n }\n\n groups.set(name, [record]);\n }\n\n return [...groups].map(([name, scoped]) => ({ name, records: scoped }));\n}\n\n/** This serializer writes log records as OTLP/JSON payloads. */\nexport const otlpSerializer: LogSerializer = {\n /** This field holds the format name. */\n name: SERIALIZER_NAME_OTLP,\n\n /**\n * Groups records by resource. It encodes them as an OTLP\n * ExportLogsServiceRequest JSON payload.\n * @param records Array of log records to serialize.\n * @returns Serialized JSON batch payload.\n */\n serialize(records: LogRecord[]): SerializedBatch {\n const resourceLogs = groupByResource(records).map((group) => ({\n resource: { attributes: toKeyValues(group.resource) },\n scopeLogs: groupByScope(group.records).map((scope) => ({\n scope: { name: scope.name },\n logRecords: scope.records.map((record) => ({\n timeUnixNano: record.timeUnixNano,\n // Use timeUnixNano when observedTimeUnixNano is not set.\n observedTimeUnixNano: record.observedTimeUnixNano ?? record.timeUnixNano,\n severityNumber: record.severityNumber,\n severityText: record.severityText,\n body: { stringValue: record.body },\n traceId: record.traceId,\n spanId: record.spanId,\n flags: record.traceFlags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AQ,IAAK,IAAY,CACzC,aAAcT,EAAO,aAErB,qBAAsBA,EAAO,sBAAwBA,EAAO,aAC5D,eAAgBA,EAAO,eACvB,aAAcA,EAAO,aACrB,KAAM,CAAE,YAAaA,EAAO,IAAK,EACjC,QAASA,EAAO,QAChB,OAAQA,EAAO,OACf,MAAOA,EAAO,WACd,WAAYX,EAAYW,EAAO,UAAU,CAC3C,EAAE,CACJ,EAAE,CACJ,EAAE,EAEF,MAAO,CACL,KAAM,KAAK,UAAU,CAAE,cAAa,CAAC,EACrC,YAAarB,EAAAA,CACf,CACF,CACF,E"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { Mn as e, R as t, a as n, mn as r, tt as i } from "./constants-
|
|
2
|
-
|
|
1
|
+
import { Mn as e, R as t, a as n, mn as r, tt as i } from "./constants-zyrqveN4.js";
|
|
2
|
+
// src/transport/compression.ts
|
|
3
3
|
async function a(e) {
|
|
4
4
|
let t = globalThis.CompressionStream;
|
|
5
5
|
if (t === void 0) return null;
|
|
6
6
|
let n = new Blob([e]).stream().pipeThrough(new t(i)), r = await new Response(n).arrayBuffer();
|
|
7
7
|
return new Uint8Array(r);
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
//#region src/transport/serializers/otlp.ts
|
|
9
|
+
// src/transport/serializers/otlp.ts
|
|
11
10
|
function o(e) {
|
|
12
11
|
return e == null ? null : typeof e == "string" ? { stringValue: e } : typeof e == "boolean" ? { boolValue: e } : typeof e == "number" ? Number.isSafeInteger(e) ? { intValue: String(e) } : { doubleValue: e } : typeof e == "bigint" ? { intValue: e.toString() } : Array.isArray(e) ? { arrayValue: { values: e.map(o).filter((e) => e !== null) } } : typeof e == "object" ? { kvlistValue: { values: s(e) } } : null;
|
|
13
12
|
}
|
|
@@ -77,7 +76,6 @@ var f = {
|
|
|
77
76
|
};
|
|
78
77
|
}
|
|
79
78
|
};
|
|
80
|
-
//#endregion
|
|
81
79
|
export { a, s as i, d as n, f as r, u as t };
|
|
82
80
|
|
|
83
|
-
//# sourceMappingURL=otlp-
|
|
81
|
+
//# sourceMappingURL=otlp-BTJdIa6F.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otlp-CYIL7MOE.js","names":["items","nested","TELEMETRY_SDK_NAME","CONTENT_TYPE_JSON","ATTR_APP_NAMESPACE","SERIALIZER_NAME_OTLP","ENCODING_GZIP","gzip","CS","stream","text","buffer","toAnyValue","value","item","toKeyValues","out","key","raw","source","resourceKeys","resourceKey","cached","resource","groupByResource","groups","record","records","group","groupByScope","namespace","name","scoped","otlpSerializer","resourceLogs","scope"],"sources":["../src/transport/compression.ts","../src/transport/serializers/otlp.ts"],"sourcesContent":["// src/transport/compression.ts\n//\n// This module compresses payloads with the native CompressionStream API. It returns null\n// when the API is absent. It does not return raw text. The server rejects a non-gzip body\n// that has a \"Content-Encoding: gzip\" header with a 400 status.\n\nimport { ENCODING_GZIP } from \"../constants\";\n\n/**\n * Compresses a string to gzip bytes with CompressionStream. The result is a\n * Uint8Array on a non-shared ArrayBuffer. fetch accepts this result as BodyInit.\n * @param text Raw serialized payload to compress.\n * @returns Promise that resolves to the gzip bytes, or null without CompressionStream.\n */\nexport async function gzip(text: string): Promise<Uint8Array<ArrayBuffer> | null> {\n const CS = (globalThis as { CompressionStream?: typeof CompressionStream }).CompressionStream;\n if (CS === undefined) {\n return null;\n }\n\n const stream = new Blob([text]).stream().pipeThrough(new CS(ENCODING_GZIP));\n const buffer = await new Response(stream).arrayBuffer();\n\n return new Uint8Array(buffer);\n}\n","// src/transport/serializers/otlp.ts\n//\n// This module serializes log batches as OTLP/JSON log records. It groups the records by resource.\n// It gives each logger namespace its own instrumentation scope.\n// The OTLP metrics serializer uses its value encoding and its resource grouping.\n\nimport {\n ATTR_APP_NAMESPACE,\n CONTENT_TYPE_JSON,\n SERIALIZER_NAME_OTLP,\n TELEMETRY_SDK_NAME,\n} from \"../../constants\";\nimport type { LogRecord } from \"../../models/log-record\";\nimport type { LogSerializer, SerializedBatch } from \"../../models/serializer\";\n\n/** This type holds an OTLP AnyValue with typed value wrappers. */\ntype AnyValue = Record<string, unknown>;\n\n/** This interface holds an OTLP KeyValue pair. */\nexport interface KeyValue {\n /** This field holds the attribute key. */\n key: string;\n /** This field holds the typed AnyValue. */\n value: AnyValue;\n}\n\n/** This interface holds the records that share resource attributes. */\nexport interface ResourceGroup {\n /** This field holds the resource attribute map. */\n resource: Record<string, unknown>;\n /** This field holds the log records of the resource. */\n records: LogRecord[];\n}\n\n/**\n * Wraps a JavaScript value in an OTLP AnyValue.\n * @param value Raw attribute or resource value.\n * @returns Typed AnyValue object or null if unsupported.\n */\nfunction toAnyValue(value: unknown): AnyValue | null {\n if (value === null || value === undefined) {\n return null;\n }\n\n if (typeof value === \"string\") {\n return { stringValue: value };\n }\n\n if (typeof value === \"boolean\") {\n return { boolValue: value };\n }\n\n // Encode int64 as a decimal string. The OTLP protobuf JSON mapping requires it. A conforming\n // collector returns a 400 status for a number. The response does not give the cause.\n // An integer above MAX_SAFE_INTEGER goes to doubleValue. Its text can be \"1e+21\" or overflow int64.\n if (typeof value === \"number\") {\n return Number.isSafeInteger(value) ? { intValue: String(value) } : { doubleValue: value };\n }\n\n // Convert a BigInt to a decimal string. JSON.stringify throws on a BigInt and loses the\n // batch.\n if (typeof value === \"bigint\") {\n return { intValue: value.toString() };\n }\n\n if (Array.isArray(value)) {\n const items: readonly unknown[] = value;\n const values = items.map(toAnyValue).filter((item): item is AnyValue => item !== null);\n\n return { arrayValue: { values } };\n }\n\n if (typeof value === \"object\") {\n const nested = value as Record<string, unknown>;\n return { kvlistValue: { values: toKeyValues(nested) } };\n }\n\n return null;\n}\n\n/**\n * Converts a plain object to an array of OTLP KeyValue pairs.\n * @param source Key-value attribute object.\n * @returns Array of valid KeyValue pairs.\n */\nexport function toKeyValues(source: Record<string, unknown>): KeyValue[] {\n const out: KeyValue[] = [];\n\n for (const [key, raw] of Object.entries(source)) {\n const value = toAnyValue(raw);\n if (value) {\n out.push({ key, value });\n }\n }\n\n return out;\n}\n\n/** This map caches the JSON key of each resource object. It prevents a repeated stringify. */\nconst resourceKeys = new WeakMap<object, string>();\n\n/**\n * Returns the stable JSON key of a resource object. It caches the key.\n * @param resource Resource attribute object.\n * @returns JSON key string.\n */\nfunction resourceKey(resource: Record<string, unknown>): string {\n const cached = resourceKeys.get(resource);\n if (cached !== undefined) {\n return cached;\n }\n\n const key = JSON.stringify(resource);\n resourceKeys.set(resource, key);\n\n return key;\n}\n\n/**\n * Groups records by their resource attributes. It keeps the record order in each group.\n * @param records Records to group.\n * @returns One group for each resource.\n */\nexport function groupByResource(records: LogRecord[]): ResourceGroup[] {\n const groups = new Map<string, ResourceGroup>();\n\n for (const record of records) {\n const key = resourceKey(record.resource);\n const group = groups.get(key);\n\n if (group) {\n group.records.push(record);\n continue;\n }\n\n groups.set(key, { resource: record.resource, records: [record] });\n }\n\n return [...groups.values()];\n}\n\n/** This interface holds the records of one instrumentation scope. */\nexport interface ScopeGroup {\n /** This field holds the scope name. It is the logger namespace. */\n name: string;\n /** This field holds the records of the scope. */\n records: LogRecord[];\n}\n\n/**\n * Groups records by their logger namespace. It keeps the record order in each group.\n * A record without a namespace goes to the scope of the library.\n * @param records Records of one resource.\n * @returns One group for each namespace.\n */\nexport function groupByScope(records: LogRecord[]): ScopeGroup[] {\n const groups = new Map<string, LogRecord[]>();\n\n for (const record of records) {\n const namespace: unknown = record.attributes[ATTR_APP_NAMESPACE];\n const name = typeof namespace === \"string\" && namespace ? namespace : TELEMETRY_SDK_NAME;\n const group = groups.get(name);\n\n if (group) {\n group.push(record);\n continue;\n }\n\n groups.set(name, [record]);\n }\n\n return [...groups].map(([name, scoped]) => ({ name, records: scoped }));\n}\n\n/** This serializer writes log records as OTLP/JSON payloads. */\nexport const otlpSerializer: LogSerializer = {\n /** This field holds the format name. */\n name: SERIALIZER_NAME_OTLP,\n\n /**\n * Groups records by resource. It encodes them as an OTLP\n * ExportLogsServiceRequest JSON payload.\n * @param records Array of log records to serialize.\n * @returns Serialized JSON batch payload.\n */\n serialize(records: LogRecord[]): SerializedBatch {\n const resourceLogs = groupByResource(records).map((group) => ({\n resource: { attributes: toKeyValues(group.resource) },\n scopeLogs: groupByScope(group.records).map((scope) => ({\n scope: { name: scope.name },\n logRecords: scope.records.map((record) => ({\n timeUnixNano: record.timeUnixNano,\n // Use timeUnixNano when observedTimeUnixNano is not set.\n observedTimeUnixNano: record.observedTimeUnixNano ?? record.timeUnixNano,\n severityNumber: record.severityNumber,\n severityText: record.severityText,\n body: { stringValue: record.body },\n traceId: record.traceId,\n spanId: record.spanId,\n flags: record.traceFlags,\n attributes: toKeyValues(record.attributes),\n })),\n })),\n }));\n\n return {\n body: JSON.stringify({ resourceLogs }),\n contentType: CONTENT_TYPE_JSON,\n };\n },\n};\n"],"mappings":";;AAcA,eAAsBO,EAAK,GAAuD;CAChF,IAAMC,IAAM,WAAgE;CAC5E,IAAIA,MAAO,KAAA,GACT,OAAO;CAGT,IAAMC,IAAS,IAAI,KAAK,CAACC,CAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,YAAY,IAAIF,EAAGF,CAAa,CAAC,GACpEK,IAAS,MAAM,IAAI,SAASF,CAAM,CAAC,CAAC,YAAY;CAEtD,OAAO,IAAI,WAAWE,CAAM;AAC9B;;;ACeA,SAASC,EAAW,GAAiC;CAsCnD,OArCIC,KAAU,OACL,OAGL,OAAOA,KAAU,WACZ,EAAE,aAAaA,EAAM,IAG1B,OAAOA,KAAU,YACZ,EAAE,WAAWA,EAAM,IAMxB,OAAOA,KAAU,WACZ,OAAO,cAAcA,CAAK,IAAI,EAAE,UAAU,OAAOA,CAAK,EAAE,IAAI,EAAE,aAAaA,EAAM,IAKtF,OAAOA,KAAU,WACZ,EAAE,UAAUA,EAAM,SAAS,EAAE,IAGlC,MAAM,QAAQA,CAAK,IAId,EAAE,YAAY,EAAE,QAFRb,EAAM,IAAIY,CAAU,CAAC,CAAC,QAAQ,MAA2BE,MAAS,IAE1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AC;CAC3B;CAEA,OAAO,CAAC,GAAGD,CAAM,CAAC,CAAC,KAAK,CAACM,GAAMC,QAAa;EAAE;EAAM,SAASA;CAAO,EAAE;AACxE;AAGA,IAAaC,IAAgC;CAE3C,MAAM5B;CAQN,UAAU,GAAuC;EAC/C,IAAM6B,IAAeV,EAAgBG,CAAO,CAAC,CAAC,KAAK,OAAW;GAC5D,UAAU,EAAE,YAAYZ,EAAYa,EAAM,QAAQ,EAAE;GACpD,WAAWC,EAAaD,EAAM,OAAO,CAAC,CAAC,KAAK,OAAW;IACrD,OAAO,EAAE,MAAMO,EAAM,KAAK;IAC1B,YAAYA,EAAM,QAAQ,KAAK,OAAY;KACzC,cAAcT,EAAO;KAErB,sBAAsBA,EAAO,wBAAwBA,EAAO;KAC5D,gBAAgBA,EAAO;KACvB,cAAcA,EAAO;KACrB,MAAM,EAAE,aAAaA,EAAO,KAAK;KACjC,SAASA,EAAO;KAChB,QAAQA,EAAO;KACf,OAAOA,EAAO;KACd,YAAYX,EAAYW,EAAO,UAAU;IAC3C,EAAE;GACJ,EAAE;EACJ,EAAE;EAEF,OAAO;GACL,MAAM,KAAK,UAAU,EAAE,gBAAa,CAAC;GACrC,aAAavB;EACf;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"otlp-BTJdIa6F.js","names":["items","nested","TELEMETRY_SDK_NAME","CONTENT_TYPE_JSON","ATTR_APP_NAMESPACE","SERIALIZER_NAME_OTLP","ENCODING_GZIP","gzip","CS","stream","text","buffer","toAnyValue","value","item","toKeyValues","out","key","raw","source","resourceKeys","resourceKey","cached","resource","groupByResource","groups","record","records","group","groupByScope","namespace","name","scoped","otlpSerializer","resourceLogs","scope"],"sources":["../src/transport/compression.ts","../src/transport/serializers/otlp.ts"],"sourcesContent":["// src/transport/compression.ts\n//\n// This module compresses payloads with the native CompressionStream API. It returns null\n// when the API is absent. It does not return raw text. The server rejects a non-gzip body\n// that has a \"Content-Encoding: gzip\" header with a 400 status.\n\nimport { ENCODING_GZIP } from \"../constants\";\n\n/**\n * Compresses a string to gzip bytes with CompressionStream. The result is a\n * Uint8Array on a non-shared ArrayBuffer. fetch accepts this result as BodyInit.\n * @param text Raw serialized payload to compress.\n * @returns Promise that resolves to the gzip bytes, or null without CompressionStream.\n */\nexport async function gzip(text: string): Promise<Uint8Array<ArrayBuffer> | null> {\n const CS = (globalThis as { CompressionStream?: typeof CompressionStream }).CompressionStream;\n if (CS === undefined) {\n return null;\n }\n\n const stream = new Blob([text]).stream().pipeThrough(new CS(ENCODING_GZIP));\n const buffer = await new Response(stream).arrayBuffer();\n\n return new Uint8Array(buffer);\n}\n","// src/transport/serializers/otlp.ts\n//\n// This module serializes log batches as OTLP/JSON log records. It groups the records by resource.\n// It gives each logger namespace its own instrumentation scope.\n// The OTLP metrics serializer uses its value encoding and its resource grouping.\n\nimport {\n ATTR_APP_NAMESPACE,\n CONTENT_TYPE_JSON,\n SERIALIZER_NAME_OTLP,\n TELEMETRY_SDK_NAME,\n} from \"../../constants\";\nimport type { LogRecord } from \"../../models/log-record\";\nimport type { LogSerializer, SerializedBatch } from \"../../models/serializer\";\n\n/** This type holds an OTLP AnyValue with typed value wrappers. */\ntype AnyValue = Record<string, unknown>;\n\n/** This interface holds an OTLP KeyValue pair. */\nexport interface KeyValue {\n /** This field holds the attribute key. */\n key: string;\n /** This field holds the typed AnyValue. */\n value: AnyValue;\n}\n\n/** This interface holds the records that share resource attributes. */\nexport interface ResourceGroup {\n /** This field holds the resource attribute map. */\n resource: Record<string, unknown>;\n /** This field holds the log records of the resource. */\n records: LogRecord[];\n}\n\n/**\n * Wraps a JavaScript value in an OTLP AnyValue.\n * @param value Raw attribute or resource value.\n * @returns Typed AnyValue object or null if unsupported.\n */\nfunction toAnyValue(value: unknown): AnyValue | null {\n if (value === null || value === undefined) {\n return null;\n }\n\n if (typeof value === \"string\") {\n return { stringValue: value };\n }\n\n if (typeof value === \"boolean\") {\n return { boolValue: value };\n }\n\n // Encode int64 as a decimal string. The OTLP protobuf JSON mapping requires it. A conforming\n // collector returns a 400 status for a number. The response does not give the cause.\n // An integer above MAX_SAFE_INTEGER goes to doubleValue. Its text can be \"1e+21\" or overflow int64.\n if (typeof value === \"number\") {\n return Number.isSafeInteger(value) ? { intValue: String(value) } : { doubleValue: value };\n }\n\n // Convert a BigInt to a decimal string. JSON.stringify throws on a BigInt and loses the\n // batch.\n if (typeof value === \"bigint\") {\n return { intValue: value.toString() };\n }\n\n if (Array.isArray(value)) {\n const items: readonly unknown[] = value;\n const values = items.map(toAnyValue).filter((item): item is AnyValue => item !== null);\n\n return { arrayValue: { values } };\n }\n\n if (typeof value === \"object\") {\n const nested = value as Record<string, unknown>;\n return { kvlistValue: { values: toKeyValues(nested) } };\n }\n\n return null;\n}\n\n/**\n * Converts a plain object to an array of OTLP KeyValue pairs.\n * @param source Key-value attribute object.\n * @returns Array of valid KeyValue pairs.\n */\nexport function toKeyValues(source: Record<string, unknown>): KeyValue[] {\n const out: KeyValue[] = [];\n\n for (const [key, raw] of Object.entries(source)) {\n const value = toAnyValue(raw);\n if (value) {\n out.push({ key, value });\n }\n }\n\n return out;\n}\n\n/** This map caches the JSON key of each resource object. It prevents a repeated stringify. */\nconst resourceKeys = new WeakMap<object, string>();\n\n/**\n * Returns the stable JSON key of a resource object. It caches the key.\n * @param resource Resource attribute object.\n * @returns JSON key string.\n */\nfunction resourceKey(resource: Record<string, unknown>): string {\n const cached = resourceKeys.get(resource);\n if (cached !== undefined) {\n return cached;\n }\n\n const key = JSON.stringify(resource);\n resourceKeys.set(resource, key);\n\n return key;\n}\n\n/**\n * Groups records by their resource attributes. It keeps the record order in each group.\n * @param records Records to group.\n * @returns One group for each resource.\n */\nexport function groupByResource(records: LogRecord[]): ResourceGroup[] {\n const groups = new Map<string, ResourceGroup>();\n\n for (const record of records) {\n const key = resourceKey(record.resource);\n const group = groups.get(key);\n\n if (group) {\n group.records.push(record);\n continue;\n }\n\n groups.set(key, { resource: record.resource, records: [record] });\n }\n\n return [...groups.values()];\n}\n\n/** This interface holds the records of one instrumentation scope. */\nexport interface ScopeGroup {\n /** This field holds the scope name. It is the logger namespace. */\n name: string;\n /** This field holds the records of the scope. */\n records: LogRecord[];\n}\n\n/**\n * Groups records by their logger namespace. It keeps the record order in each group.\n * A record without a namespace goes to the scope of the library.\n * @param records Records of one resource.\n * @returns One group for each namespace.\n */\nexport function groupByScope(records: LogRecord[]): ScopeGroup[] {\n const groups = new Map<string, LogRecord[]>();\n\n for (const record of records) {\n const namespace: unknown = record.attributes[ATTR_APP_NAMESPACE];\n const name = typeof namespace === \"string\" && namespace ? namespace : TELEMETRY_SDK_NAME;\n const group = groups.get(name);\n\n if (group) {\n group.push(record);\n continue;\n }\n\n groups.set(name, [record]);\n }\n\n return [...groups].map(([name, scoped]) => ({ name, records: scoped }));\n}\n\n/** This serializer writes log records as OTLP/JSON payloads. */\nexport const otlpSerializer: LogSerializer = {\n /** This field holds the format name. */\n name: SERIALIZER_NAME_OTLP,\n\n /**\n * Groups records by resource. It encodes them as an OTLP\n * ExportLogsServiceRequest JSON payload.\n * @param records Array of log records to serialize.\n * @returns Serialized JSON batch payload.\n */\n serialize(records: LogRecord[]): SerializedBatch {\n const resourceLogs = groupByResource(records).map((group) => ({\n resource: { attributes: toKeyValues(group.resource) },\n scopeLogs: groupByScope(group.records).map((scope) => ({\n scope: { name: scope.name },\n logRecords: scope.records.map((record) => ({\n timeUnixNano: record.timeUnixNano,\n // Use timeUnixNano when observedTimeUnixNano is not set.\n observedTimeUnixNano: record.observedTimeUnixNano ?? record.timeUnixNano,\n severityNumber: record.severityNumber,\n severityText: record.severityText,\n body: { stringValue: record.body },\n traceId: record.traceId,\n spanId: record.spanId,\n flags: record.traceFlags,\n attributes: toKeyValues(record.attributes),\n })),\n })),\n }));\n\n return {\n body: JSON.stringify({ resourceLogs }),\n contentType: CONTENT_TYPE_JSON,\n };\n },\n};\n"],"mappings":";;AAcA,eAAsBO,EAAK,GAAuD;CAChF,IAAMC,IAAM,WAAgE;CAC5E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AO;KAChB,QAAQA,EAAO;KACf,OAAOA,EAAO;KACd,YAAYX,EAAYW,EAAO,UAAU;IAC3C,EAAE;GACJ,EAAE;EACJ,EAAE;EAEF,OAAO;GACL,MAAM,KAAK,UAAU,EAAE,gBAAa,CAAC;GACrC,aAAavB;EACf;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch-BX8KrPCT.cjs","names":["patch","original","target","key","wrapper","wrap"],"sources":["../src/utils/patch.ts"],"sourcesContent":["// src/utils/patch.ts\n//\n// Replaces a host function with a wrapper and gives back a safe restore. A router or a\n// second SDK can wrap the same function after the library. A blind restore removes that\n// wrapper and breaks the host page.\n\n/**\n * Replaces `target[key]` with a wrapper of the current value.\n * @param target Object that holds the function, for example `console` or `globalThis`.\n * @param key Property to replace.\n * @param wrap Makes the wrapper from the original value.\n * @returns Restore function. It writes the original back only if the property still holds\n * the wrapper. It then returns true. If not, it changes nothing. It returns false.\n */\nexport function patch<T extends object, K extends keyof T>(\n target: T,\n key: K,\n wrap: (original: T[K]) => T[K],\n): () => boolean {\n const original = target[key];\n const wrapper = wrap(original);\n target[key] = wrapper;\n\n return () => {\n // Another script wrapped the property after the library. Keep its wrapper.\n if (target[key] !== wrapper) {\n return false;\n }\n\n target[key] = original;\n return true;\n };\n}\n"],"mappings":"AAcA,SAAgBA,EACd,EACA,EACA,EACe,CACf,IAAMC,EAAWC,EAAOC,GAClBC,EAAUC,EAAKJ,CAAQ,EAG7B,MAFA,GAAOE,GAAOC,MAIRF,EAAOC,KAASC,IAIpB,EAAOD,GAAOF,EACP,GAEX"}
|
|
1
|
+
{"version":3,"file":"patch-BX8KrPCT.cjs","names":["patch","original","target","key","wrapper","wrap"],"sources":["../src/utils/patch.ts"],"sourcesContent":["// src/utils/patch.ts\n//\n// Replaces a host function with a wrapper and gives back a safe restore. A router or a\n// second SDK can wrap the same function after the library. A blind restore removes that\n// wrapper and breaks the host page.\n\n/**\n * Replaces `target[key]` with a wrapper of the current value.\n * @param target Object that holds the function, for example `console` or `globalThis`.\n * @param key Property to replace.\n * @param wrap Makes the wrapper from the original value.\n * @returns Restore function. It writes the original back only if the property still holds\n * the wrapper. It then returns true. If not, it changes nothing. It returns false.\n */\nexport function patch<T extends object, K extends keyof T>(\n target: T,\n key: K,\n wrap: (original: T[K]) => T[K],\n): () => boolean {\n const original = target[key];\n const wrapper = wrap(original);\n target[key] = wrapper;\n\n return () => {\n // Another script wrapped the property after the library. Keep its wrapper.\n if (target[key] !== wrapper) {\n return false;\n }\n\n target[key] = original;\n return true;\n };\n}\n"],"mappings":"AAcA,SAAgBA,EACd,EACA,EACA,EACe,CACf,IAAMC,EAAWC,EAAOC,GAClBC,EAAUC,EAAKJ,CAAQ,EAG7B,MAFA,GAAOE,GAAOC,MAIRF,EAAOC,KAASC,IAIpB,EAAOD,GAAOF,EACP,GAEX,C"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
// src/utils/patch.ts
|
|
2
2
|
function e(e, t, n) {
|
|
3
3
|
let r = e[t], i = n(r);
|
|
4
4
|
return e[t] = i, () => e[t] === i && (e[t] = r, !0);
|
|
5
5
|
}
|
|
6
|
-
//#endregion
|
|
7
6
|
export { e as t };
|
|
8
7
|
|
|
9
|
-
//# sourceMappingURL=patch-
|
|
8
|
+
//# sourceMappingURL=patch-UdPz1ea8.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch-
|
|
1
|
+
{"version":3,"file":"patch-UdPz1ea8.js","names":["patch","original","target","key","wrapper","wrap"],"sources":["../src/utils/patch.ts"],"sourcesContent":["// src/utils/patch.ts\n//\n// Replaces a host function with a wrapper and gives back a safe restore. A router or a\n// second SDK can wrap the same function after the library. A blind restore removes that\n// wrapper and breaks the host page.\n\n/**\n * Replaces `target[key]` with a wrapper of the current value.\n * @param target Object that holds the function, for example `console` or `globalThis`.\n * @param key Property to replace.\n * @param wrap Makes the wrapper from the original value.\n * @returns Restore function. It writes the original back only if the property still holds\n * the wrapper. It then returns true. If not, it changes nothing. It returns false.\n */\nexport function patch<T extends object, K extends keyof T>(\n target: T,\n key: K,\n wrap: (original: T[K]) => T[K],\n): () => boolean {\n const original = target[key];\n const wrapper = wrap(original);\n target[key] = wrapper;\n\n return () => {\n // Another script wrapped the property after the library. Keep its wrapper.\n if (target[key] !== wrapper) {\n return false;\n }\n\n target[key] = original;\n return true;\n };\n}\n"],"mappings":";AAcA,SAAgBA,EACd,GACA,GACA,GACe;CACf,IAAMC,IAAWC,EAAOC,IAClBC,IAAUC,EAAKJ,CAAQ;CAG7B,OAFA,EAAOE,KAAOC,SAIRF,EAAOC,OAASC,MAIpB,EAAOD,KAAOF,GACP;AAEX"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./constants-
|
|
2
|
-
//# sourceMappingURL=platform-
|
|
1
|
+
const e=require("./constants-DqKJH_MP.cjs"),t=require("./openfin-DtH2f7zX.cjs");var n=null;function r(e,t){let n=e[t];return n!==void 0&&e instanceof n}function i(i){if(n)return n;let s=globalThis,c=s.navigator?.userAgent??``,l=`browser`,u,d,f=!1,p=t.t()?.me;return r(s,`ServiceWorkerGlobalScope`)?(l=`service_worker`,f=!0):r(s,`SharedWorkerGlobalScope`)?(l=`shared_worker`,f=!0):r(s,`WorkerGlobalScope`)?(l=`web_worker`,f=!0):p===void 0?s.Capacitor!==void 0||s.Ionic!==void 0?l=`ionic`:s.cordova!==void 0||a(c)?l=`mobile_webview`:typeof document>`u`&&typeof process<`u`&&(l=`node`):(l=e.Vt.test(c)?`openfin`:`openfin_web`,i.guard(`openfin.unavailable`,`The library could not read fin.me.identity.`,()=>{let e=p.identity;u=e?.uuid,d=e?.name})),n={platform:l,openfinUuid:u,openfinName:d,userAgent:c,isWorker:f,isTopLevelDocument:o(i)},n}function a(t){return e.i.test(t)?!0:(e._t.test(t)||e.jt.test(t)&&e.It.test(t))&&t.includes(`AppleWebKit`)&&!t.includes(`Safari/`)}function o(e){if(typeof window>`u`)return!1;try{return window.self===window.top}catch{return e.count(`platform.api_blocked`),!1}}function s(e){try{return typeof location<`u`?location.href:``}catch{return e.count(`platform.api_blocked`),``}}var c=/^([a-z][a-z\d+.-]*:\/\/)[^/?#]*@/i;function l(e,t,n,r){if(n)try{let t=n(e);return typeof t==`string`?t:``}catch(e){return r?.report(`capture.record_failed`,`capture.urlTransform threw an error. The library records an empty URL.`,void 0,e),``}let i=e.replace(c,`$1`);return t?i:u(i)}function u(e){let t=e.search(/[?#]/);return t===-1?e:e.slice(0,t)}function d(){return globalThis.navigator?.onLine!==!1}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return s}});
|
|
2
|
+
//# sourceMappingURL=platform-C2Ez5kDc.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform-KMWkoI-v.cjs","names":["getFin","OPENFIN_UA_PATTERN","ANDROID_WEBVIEW_UA_PATTERN","IOS_DEVICE_UA_PATTERN","MACINTOSH_UA_PATTERN","MOBILE_UA_PATTERN","require_constants","require_openfin","cached","isGlobalScope","scope","g","name","detectPlatform","ua","platform","openfinUuid","openfinName","isWorker","finMe","isWebView","diagnostics","identity","isTopLevel","currentUrl","USER_INFO_PATTERN","recordedUrl","transform","value","url","error","bare","fullUrls","stripUrlQuery","cut","isOnline"],"sources":["../src/utils/platform.ts"],"sourcesContent":["// src/utils/platform.ts\n//\n// Detects host platform capabilities, OpenFin container metadata, and worker\n// execution realms. The module caches the result. The result does not change during\n// the life of a realm. A webview is also a browser. Test for a webview first.\n\nimport {\n ANDROID_WEBVIEW_UA_PATTERN,\n IOS_DEVICE_UA_PATTERN,\n MACINTOSH_UA_PATTERN,\n MOBILE_UA_PATTERN,\n OPENFIN_UA_PATTERN,\n SAFARI_UA_TOKEN,\n WEBKIT_UA_TOKEN,\n} from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { getFin } from \"./openfin\";\n\n/** Host runtime environment classification attached to resource attributes. */\nexport type PlatformType =\n | \"openfin\"\n | \"openfin_web\"\n | \"browser\"\n | \"mobile_webview\"\n | \"ionic\"\n | \"web_worker\"\n | \"shared_worker\"\n | \"service_worker\"\n | \"node\";\n\n/** Host environment and runtime container metadata resolved at startup. */\nexport interface PlatformMetadata {\n /** Detected platform runtime classification. */\n platform: PlatformType;\n /** OpenFin application UUID if running inside an OpenFin container. */\n openfinUuid?: string;\n /** OpenFin window or view identifier. */\n openfinName?: string;\n /** Raw navigator user agent string or empty string if unavailable. */\n userAgent: string;\n /** True if the code runs in a worker realm. */\n isWorker: boolean;\n /** True if this context is the top-level document rather than an iframe. */\n isTopLevelDocument: boolean;\n}\n\n/** Indexed globalThis type for probing runtime globals. */\ntype Global = typeof globalThis & Record<string, unknown>;\n\n/** Cached platform metadata instance. */\nlet cached: PlatformMetadata | null = null;\n\n/** Abstract constructor type for global scope prototype checks. */\ntype ScopeConstructor = abstract new (...args: never[]) => object;\n\n/**\n * Tests if globalThis is an instance of a specified global scope constructor.\n * @param g Global scope object.\n * @param name Scope constructor name to check.\n * @returns True if globalThis inherits from the named scope constructor.\n */\nfunction isGlobalScope(g: Global, name: string): boolean {\n const scope = g[name];\n if (scope === undefined) {\n return false;\n }\n return g instanceof (scope as ScopeConstructor);\n}\n\n/**\n * Detects and caches host platform metadata for the active realm.\n * @param diagnostics Diagnostics reporter.\n * @returns Detected PlatformMetadata.\n */\nexport function detectPlatform(diagnostics: Diagnostics): PlatformMetadata {\n if (cached) {\n return cached;\n }\n const g = globalThis as Global;\n\n const ua = (g.navigator as Navigator | undefined)?.userAgent ?? \"\";\n let platform: PlatformType = \"browser\";\n let openfinUuid: string | undefined;\n let openfinName: string | undefined;\n let isWorker = false;\n\n const finMe = getFin()?.me;\n\n if (isGlobalScope(g, \"ServiceWorkerGlobalScope\")) {\n platform = \"service_worker\";\n isWorker = true;\n } else if (isGlobalScope(g, \"SharedWorkerGlobalScope\")) {\n platform = \"shared_worker\";\n isWorker = true;\n } else if (isGlobalScope(g, \"WorkerGlobalScope\")) {\n platform = \"web_worker\";\n isWorker = true;\n } else if (finMe !== undefined) {\n platform = OPENFIN_UA_PATTERN.test(ua) ? \"openfin\" : \"openfin_web\";\n diagnostics.guard(\"openfin.unavailable\", \"The library could not read fin.me.identity.\", () => {\n const identity = finMe.identity;\n openfinUuid = identity?.uuid;\n openfinName = identity?.name;\n });\n } else if (g.Capacitor !== undefined || g.Ionic !== undefined) {\n platform = \"ionic\";\n } else if (g.cordova !== undefined || isWebView(ua)) {\n platform = \"mobile_webview\";\n } else if (typeof document === \"undefined\" && typeof process !== \"undefined\") {\n platform = \"node\";\n }\n\n cached = {\n platform,\n openfinUuid,\n openfinName,\n userAgent: ua,\n isWorker,\n isTopLevelDocument: isTopLevel(diagnostics),\n };\n return cached;\n}\n\n/**\n * Tests if a user agent string represents an embedded mobile webview.\n * @param ua User agent string.\n * @returns True if user agent matches Android or iOS webview signatures.\n */\nfunction isWebView(ua: string): boolean {\n if (ANDROID_WEBVIEW_UA_PATTERN.test(ua)) {\n return true;\n }\n const ios =\n IOS_DEVICE_UA_PATTERN.test(ua) || (MACINTOSH_UA_PATTERN.test(ua) && MOBILE_UA_PATTERN.test(ua));\n return ios && ua.includes(WEBKIT_UA_TOKEN) && !ua.includes(SAFARI_UA_TOKEN);\n}\n\n/**\n * Tests if the current window is the top-level browsing context.\n * @param diagnostics Diagnostics reporter. It counts a blocked read of window.top.\n * @returns True if top-level, false if framed or inaccessible due to cross-origin boundaries.\n */\nexport function isTopLevel(diagnostics: Diagnostics): boolean {\n if (typeof window === \"undefined\") {\n return false;\n }\n try {\n return window.self === window.top;\n } catch {\n // A cross-origin parent blocks the read. That proves a frame. Count it. Do not report it.\n diagnostics.count(\"platform.api_blocked\");\n return false;\n }\n}\n\n/**\n * Retrieves the current document URL without caching.\n * @param diagnostics Diagnostics reporter. It counts a blocked read of location.href.\n * @returns Current location.href or empty string.\n */\nexport function currentUrl(diagnostics: Diagnostics): string {\n try {\n return typeof location !== \"undefined\" ? location.href : \"\";\n } catch {\n // A sandbox can block the read. Count the fault. A report on each record is noise.\n diagnostics.count(\"platform.api_blocked\");\n return \"\";\n }\n}\n\n/** Matches the user info of an absolute URL, for example \"user:pass@\". */\nconst USER_INFO_PATTERN = /^([a-z][a-z\\d+.-]*:\\/\\/)[^/?#]*@/i;\n\n/**\n * Gives the form of a URL that the library records. It always removes the user info, which is a\n * credential. Without fullUrls, it also removes the query and the fragment.\n * @param url Absolute or relative URL.\n * @param fullUrls Value of `capture.fullUrls`.\n * @param transform Value of `capture.urlTransform`. It replaces the default rule.\n * @param diagnostics Diagnostics reporter for a transform that throws.\n * @returns The URL to record.\n */\nexport function recordedUrl(\n url: string,\n fullUrls: boolean,\n transform?: (url: string) => string | null,\n diagnostics?: Diagnostics,\n): string {\n if (transform) {\n try {\n const value = transform(url);\n return typeof value === \"string\" ? value : \"\";\n } catch (error) {\n // Report the fault. Without a report, each recorded URL is empty with no visible cause.\n diagnostics?.report(\n \"capture.record_failed\",\n \"capture.urlTransform threw an error. The library records an empty URL.\",\n undefined,\n error,\n );\n return \"\";\n }\n }\n const bare = url.replace(USER_INFO_PATTERN, \"$1\");\n return fullUrls ? bare : stripUrlQuery(bare);\n}\n\n/**\n * Drops the query string and fragment from a URL.\n * It cuts the string and does not parse a URL. A relative request target has no base URL.\n * @param url Absolute or relative URL.\n * @returns The URL up to the first \"?\" or \"#\".\n */\nexport function stripUrlQuery(url: string): string {\n const cut = url.search(/[?#]/);\n\n return cut === -1 ? url : url.slice(0, cut);\n}\n\n/**\n * Tests if the browser can reach the network. A host without navigator.onLine counts as online.\n * @returns False only when navigator.onLine is false.\n */\nexport function isOnline(): boolean {\n return (globalThis as { navigator?: { onLine?: boolean } }).navigator?.onLine !== false;\n}\n\n/** Resets the cached platform metadata for testing. */\nexport function resetPlat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CAC5D,GAAI,OAAO,OAAW,IACpB,MAAO,GAET,GAAI,CACF,OAAO,OAAO,OAAS,OAAO,GAChC,MAAQ,CAGN,OADAF,EAAY,MAAM,sBAAsB,EACjC,EACT,CACF,CAOA,SAAgBG,EAAW,EAAkC,CAC3D,GAAI,CACF,OAAO,OAAO,SAAa,IAAc,SAAS,KAAO,EAC3D,MAAQ,CAGN,OADAH,EAAY,MAAM,sBAAsB,EACjC,EACT,CACF,CAGA,IAAMI,EAAoB,oCAW1B,SAAgBC,EACd,EACA,EACA,EACA,EACQ,CACR,GAAIC,EACF,GAAI,CACF,IAAMC,EAAQD,EAAUE,CAAG,EAC3B,OAAO,OAAOD,GAAU,SAAWA,EAAQ,EAC7C,OAASE,EAAO,CAQd,OANAT,GAAa,OACX,wBACA,yEACA,IAAA,GACAS,CACF,EACO,EACT,CAEF,IAAMC,EAAOF,EAAI,QAAQJ,EAAmB,IAAI,EAChD,OAAOO,EAAWD,EAAOE,EAAcF,CAAI,CAC7C,CAQA,SAAgBE,EAAc,EAAqB,CACjD,IAAMC,EAAML,EAAI,OAAO,MAAM,EAE7B,OAAOK,IAAQ,GAAKL,EAAMA,EAAI,MAAM,EAAGK,CAAG,CAC5C,CAMA,SAAgBC,GAAoB,CAClC,OAAQ,WAAoD,WAAW,SAAW,EACpF"}
|
|
1
|
+
{"version":3,"file":"platform-C2Ez5kDc.cjs","names":["getFin","OPENFIN_UA_PATTERN","ANDROID_WEBVIEW_UA_PATTERN","IOS_DEVICE_UA_PATTERN","MACINTOSH_UA_PATTERN","MOBILE_UA_PATTERN","require_constants","require_openfin","cached","isGlobalScope","scope","g","name","detectPlatform","ua","platform","openfinUuid","openfinName","isWorker","finMe","isWebView","diagnostics","identity","isTopLevel","currentUrl","USER_INFO_PATTERN","recordedUrl","transform","value","url","error","bare","fullUrls","stripUrlQuery","cut","isOnline"],"sources":["../src/utils/platform.ts"],"sourcesContent":["// src/utils/platform.ts\n//\n// Detects host platform capabilities, OpenFin container metadata, and worker\n// execution realms. The module caches the result. The result does not change during\n// the life of a realm. A webview is also a browser. Test for a webview first.\n\nimport {\n ANDROID_WEBVIEW_UA_PATTERN,\n IOS_DEVICE_UA_PATTERN,\n MACINTOSH_UA_PATTERN,\n MOBILE_UA_PATTERN,\n OPENFIN_UA_PATTERN,\n SAFARI_UA_TOKEN,\n WEBKIT_UA_TOKEN,\n} from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { getFin } from \"./openfin\";\n\n/** Host runtime environment classification attached to resource attributes. */\nexport type PlatformType =\n | \"openfin\"\n | \"openfin_web\"\n | \"browser\"\n | \"mobile_webview\"\n | \"ionic\"\n | \"web_worker\"\n | \"shared_worker\"\n | \"service_worker\"\n | \"node\";\n\n/** Host environment and runtime container metadata resolved at startup. */\nexport interface PlatformMetadata {\n /** Detected platform runtime classification. */\n platform: PlatformType;\n /** OpenFin application UUID if running inside an OpenFin container. */\n openfinUuid?: string;\n /** OpenFin window or view identifier. */\n openfinName?: string;\n /** Raw navigator user agent string or empty string if unavailable. */\n userAgent: string;\n /** True if the code runs in a worker realm. */\n isWorker: boolean;\n /** True if this context is the top-level document rather than an iframe. */\n isTopLevelDocument: boolean;\n}\n\n/** Indexed globalThis type for probing runtime globals. */\ntype Global = typeof globalThis & Record<string, unknown>;\n\n/** Cached platform metadata instance. */\nlet cached: PlatformMetadata | null = null;\n\n/** Abstract constructor type for global scope prototype checks. */\ntype ScopeConstructor = abstract new (...args: never[]) => object;\n\n/**\n * Tests if globalThis is an instance of a specified global scope constructor.\n * @param g Global scope object.\n * @param name Scope constructor name to check.\n * @returns True if globalThis inherits from the named scope constructor.\n */\nfunction isGlobalScope(g: Global, name: string): boolean {\n const scope = g[name];\n if (scope === undefined) {\n return false;\n }\n return g instanceof (scope as ScopeConstructor);\n}\n\n/**\n * Detects and caches host platform metadata for the active realm.\n * @param diagnostics Diagnostics reporter.\n * @returns Detected PlatformMetadata.\n */\nexport function detectPlatform(diagnostics: Diagnostics): PlatformMetadata {\n if (cached) {\n return cached;\n }\n const g = globalThis as Global;\n\n const ua = (g.navigator as Navigator | undefined)?.userAgent ?? \"\";\n let platform: PlatformType = \"browser\";\n let openfinUuid: string | undefined;\n let openfinName: string | undefined;\n let isWorker = false;\n\n const finMe = getFin()?.me;\n\n if (isGlobalScope(g, \"ServiceWorkerGlobalScope\")) {\n platform = \"service_worker\";\n isWorker = true;\n } else if (isGlobalScope(g, \"SharedWorkerGlobalScope\")) {\n platform = \"shared_worker\";\n isWorker = true;\n } else if (isGlobalScope(g, \"WorkerGlobalScope\")) {\n platform = \"web_worker\";\n isWorker = true;\n } else if (finMe !== undefined) {\n platform = OPENFIN_UA_PATTERN.test(ua) ? \"openfin\" : \"openfin_web\";\n diagnostics.guard(\"openfin.unavailable\", \"The library could not read fin.me.identity.\", () => {\n const identity = finMe.identity;\n openfinUuid = identity?.uuid;\n openfinName = identity?.name;\n });\n } else if (g.Capacitor !== undefined || g.Ionic !== undefined) {\n platform = \"ionic\";\n } else if (g.cordova !== undefined || isWebView(ua)) {\n platform = \"mobile_webview\";\n } else if (typeof document === \"undefined\" && typeof process !== \"undefined\") {\n platform = \"node\";\n }\n\n cached = {\n platform,\n openfinUuid,\n openfinName,\n userAgent: ua,\n isWorker,\n isTopLevelDocument: isTopLevel(diagnostics),\n };\n return cached;\n}\n\n/**\n * Tests if a user agent string represents an embedded mobile webview.\n * @param ua User agent string.\n * @returns True if user agent matches Android or iOS webview signatures.\n */\nfunction isWebView(ua: string): boolean {\n if (ANDROID_WEBVIEW_UA_PATTERN.test(ua)) {\n return true;\n }\n const ios =\n IOS_DEVICE_UA_PATTERN.test(ua) || (MACINTOSH_UA_PATTERN.test(ua) && MOBILE_UA_PATTERN.test(ua));\n return ios && ua.includes(WEBKIT_UA_TOKEN) && !ua.includes(SAFARI_UA_TOKEN);\n}\n\n/**\n * Tests if the current window is the top-level browsing context.\n * @param diagnostics Diagnostics reporter. It counts a blocked read of window.top.\n * @returns True if top-level, false if framed or inaccessible due to cross-origin boundaries.\n */\nexport function isTopLevel(diagnostics: Diagnostics): boolean {\n if (typeof window === \"undefined\") {\n return false;\n }\n try {\n return window.self === window.top;\n } catch {\n // A cross-origin parent blocks the read. That proves a frame. Count it. Do not report it.\n diagnostics.count(\"platform.api_blocked\");\n return false;\n }\n}\n\n/**\n * Retrieves the current document URL without caching.\n * @param diagnostics Diagnostics reporter. It counts a blocked read of location.href.\n * @returns Current location.href or empty string.\n */\nexport function currentUrl(diagnostics: Diagnostics): string {\n try {\n return typeof location !== \"undefined\" ? location.href : \"\";\n } catch {\n // A sandbox can block the read. Count the fault. A report on each record is noise.\n diagnostics.count(\"platform.api_blocked\");\n return \"\";\n }\n}\n\n/** Matches the user info of an absolute URL, for example \"user:pass@\". */\nconst USER_INFO_PATTERN = /^([a-z][a-z\\d+.-]*:\\/\\/)[^/?#]*@/i;\n\n/**\n * Gives the form of a URL that the library records. It always removes the user info, which is a\n * credential. Without fullUrls, it also removes the query and the fragment.\n * @param url Absolute or relative URL.\n * @param fullUrls Value of `capture.fullUrls`.\n * @param transform Value of `capture.urlTransform`. It replaces the default rule.\n * @param diagnostics Diagnostics reporter for a transform that throws.\n * @returns The URL to record.\n */\nexport function recordedUrl(\n url: string,\n fullUrls: boolean,\n transform?: (url: string) => string | null,\n diagnostics?: Diagnostics,\n): string {\n if (transform) {\n try {\n const value = transform(url);\n return typeof value === \"string\" ? value : \"\";\n } catch (error) {\n // Report the fault. Without a report, each recorded URL is empty with no visible cause.\n diagnostics?.report(\n \"capture.record_failed\",\n \"capture.urlTransform threw an error. The library records an empty URL.\",\n undefined,\n error,\n );\n return \"\";\n }\n }\n const bare = url.replace(USER_INFO_PATTERN, \"$1\");\n return fullUrls ? bare : stripUrlQuery(bare);\n}\n\n/**\n * Drops the query string and fragment from a URL.\n * It cuts the string and does not parse a URL. A relative request target has no base URL.\n * @param url Absolute or relative URL.\n * @returns The URL up to the first \"?\" or \"#\".\n */\nexport function stripUrlQuery(url: string): string {\n const cut = url.search(/[?#]/);\n\n return cut === -1 ? url : url.slice(0, cut);\n}\n\n/**\n * Tests if the browser can reach the network. A host without navigator.onLine counts as online.\n * @returns False only when navigator.onLine is false.\n */\nexport function isOnline(): boolean {\n return (globalThis as { navigator?: { onLine?: boolean } }).navigator?.onLine !== false;\n}\n\n/** Resets the cached platform metadata for testing. */\nexport function resetPlatformCache(): void {\n cached = null;\n}\n"],"mappings":"A,gFAkDA,IAAIQ,EAAkC,KAWtC,SAASC,EAAc,EAAW,EAAuB,CACvD,IAAMC,EAAQC,EAAEC,GAIhB,OAHIF,IAAU,IAAA,IAGPC,aAAcD,CACvB,CAOA,SAAgBG,EAAe,EAA4C,CACzE,GAAIL,EACF,OAAOA,EAET,IAAMG,EAAI,WAEJG,EAAMH,EAAE,WAAqC,WAAa,GAC5DI,EAAyB,UACzBC,EACAC,EACAC,EAAW,GAETC,EAAQnB,EAAAA,EAAO,CAAC,EAAE,GAkCxB,OAhCIS,EAAcE,EAAG,0BAA0B,GAC7C,EAAW,iBACX,EAAW,IACFF,EAAcE,EAAG,yBAAyB,GACnD,EAAW,gBACX,EAAW,IACFF,EAAcE,EAAG,mBAAmB,GAC7C,EAAW,aACX,EAAW,IACFQ,IAAU,IAAA,GAOVR,EAAE,YAAc,IAAA,IAAaA,EAAE,QAAU,IAAA,GAClD,EAAW,QACFA,EAAE,UAAY,IAAA,IAAaS,EAAUN,CAAE,EAChD,EAAW,iBACF,OAAO,SAAa,KAAe,OAAO,QAAY,MAC/D,EAAW,SAXX,EAAWb,EAAAA,GAAmB,KAAKa,CAAE,EAAI,UAAY,cACrDO,EAAY,MAAM,sBAAuB,kDAAqD,CAC5F,IAAMC,EAAWH,EAAM,SACvB,EAAcG,GAAU,KACxB,EAAcA,GAAU,IAC1B,CAAC,GASH,EAAS,CACP,WACA,cACA,cACA,UAAWR,EACX,WACA,mBAAoBS,EAAWF,CAAW,CAC5C,EACOb,CACT,CAOA,SAASY,EAAU,EAAqB,CAMtC,OALIlB,EAAAA,EAA2B,KAAKY,CAAE,EAC7B,IAGPX,EAAAA,GAAsB,KAAKW,CAAE,GAAMV,EAAAA,GAAqB,KAAKU,CAAE,GAAKT,EAAAA,GAAkB,KAAKS,CAAE,IACjFA,EAAG,SAAA,aAAwB,GAAK,CAACA,EAAG,SAAA,SAAwB,CAC5E,CAOA,SAAgBS,EAAW,EAAmC,CAC5D,GAAI,OAAO,OAAW,IACpB,MAAO,GAET,GAAI,CACF,OAAO,OAAO,OAAS,OAAO,GAChC,MAAQ,CAGN,OADAF,EAAY,MAAM,sBAAsB,EACjC,EACT,CACF,CAOA,SAAgBG,EAAW,EAAkC,CAC3D,GAAI,CACF,OAAO,OAAO,SAAa,IAAc,SAAS,KAAO,EAC3D,MAAQ,CAGN,OADAH,EAAY,MAAM,sBAAsB,EACjC,EACT,CACF,CAGA,IAAMI,EAAoB,oCAW1B,SAAgBC,EACd,EACA,EACA,EACA,EACQ,CACR,GAAIC,EACF,GAAI,CACF,IAAMC,EAAQD,EAAUE,CAAG,EAC3B,OAAO,OAAOD,GAAU,SAAWA,EAAQ,EAC7C,OAASE,EAAO,CAQd,OANAT,GAAa,OACX,wBACA,yEACA,IAAA,GACAS,CACF,EACO,EACT,CAEF,IAAMC,EAAOF,EAAI,QAAQJ,EAAmB,IAAI,EAChD,OAAOO,EAAWD,EAAOE,EAAcF,CAAI,CAC7C,CAQA,SAAgBE,EAAc,EAAqB,CACjD,IAAMC,EAAML,EAAI,OAAO,MAAM,EAE7B,OAAOK,IAAQ,GAAKL,EAAMA,EAAI,MAAM,EAAGK,CAAG,CAC5C,CAMA,SAAgBC,GAAoB,CAClC,OAAQ,WAAoD,WAAW,SAAW,EACpF,C"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { It as e, Vt as t, _t as n, i as r, jt as i } from "./constants-
|
|
2
|
-
import { t as a } from "./openfin-
|
|
3
|
-
|
|
1
|
+
import { It as e, Vt as t, _t as n, i as r, jt as i } from "./constants-zyrqveN4.js";
|
|
2
|
+
import { t as a } from "./openfin-Bxelt0yg.js";
|
|
3
|
+
// src/utils/platform.ts
|
|
4
4
|
var o = null;
|
|
5
5
|
function s(e, t) {
|
|
6
6
|
let n = e[t];
|
|
@@ -57,7 +57,6 @@ function m(e) {
|
|
|
57
57
|
function h() {
|
|
58
58
|
return globalThis.navigator?.onLine !== !1;
|
|
59
59
|
}
|
|
60
|
-
//#endregion
|
|
61
60
|
export { p as i, c as n, h as r, d as t };
|
|
62
61
|
|
|
63
|
-
//# sourceMappingURL=platform-
|
|
62
|
+
//# sourceMappingURL=platform-DkcuXwe-.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform-wcAkkv9F.js","names":["MOBILE_UA_PATTERN","OPENFIN_UA_PATTERN","IOS_DEVICE_UA_PATTERN","ANDROID_WEBVIEW_UA_PATTERN","MACINTOSH_UA_PATTERN","getFin","cached","isGlobalScope","scope","g","name","detectPlatform","ua","platform","openfinUuid","openfinName","isWorker","finMe","isWebView","diagnostics","identity","isTopLevel","currentUrl","USER_INFO_PATTERN","recordedUrl","transform","value","url","error","bare","fullUrls","stripUrlQuery","cut","isOnline"],"sources":["../src/utils/platform.ts"],"sourcesContent":["// src/utils/platform.ts\n//\n// Detects host platform capabilities, OpenFin container metadata, and worker\n// execution realms. The module caches the result. The result does not change during\n// the life of a realm. A webview is also a browser. Test for a webview first.\n\nimport {\n ANDROID_WEBVIEW_UA_PATTERN,\n IOS_DEVICE_UA_PATTERN,\n MACINTOSH_UA_PATTERN,\n MOBILE_UA_PATTERN,\n OPENFIN_UA_PATTERN,\n SAFARI_UA_TOKEN,\n WEBKIT_UA_TOKEN,\n} from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { getFin } from \"./openfin\";\n\n/** Host runtime environment classification attached to resource attributes. */\nexport type PlatformType =\n | \"openfin\"\n | \"openfin_web\"\n | \"browser\"\n | \"mobile_webview\"\n | \"ionic\"\n | \"web_worker\"\n | \"shared_worker\"\n | \"service_worker\"\n | \"node\";\n\n/** Host environment and runtime container metadata resolved at startup. */\nexport interface PlatformMetadata {\n /** Detected platform runtime classification. */\n platform: PlatformType;\n /** OpenFin application UUID if running inside an OpenFin container. */\n openfinUuid?: string;\n /** OpenFin window or view identifier. */\n openfinName?: string;\n /** Raw navigator user agent string or empty string if unavailable. */\n userAgent: string;\n /** True if the code runs in a worker realm. */\n isWorker: boolean;\n /** True if this context is the top-level document rather than an iframe. */\n isTopLevelDocument: boolean;\n}\n\n/** Indexed globalThis type for probing runtime globals. */\ntype Global = typeof globalThis & Record<string, unknown>;\n\n/** Cached platform metadata instance. */\nlet cached: PlatformMetadata | null = null;\n\n/** Abstract constructor type for global scope prototype checks. */\ntype ScopeConstructor = abstract new (...args: never[]) => object;\n\n/**\n * Tests if globalThis is an instance of a specified global scope constructor.\n * @param g Global scope object.\n * @param name Scope constructor name to check.\n * @returns True if globalThis inherits from the named scope constructor.\n */\nfunction isGlobalScope(g: Global, name: string): boolean {\n const scope = g[name];\n if (scope === undefined) {\n return false;\n }\n return g instanceof (scope as ScopeConstructor);\n}\n\n/**\n * Detects and caches host platform metadata for the active realm.\n * @param diagnostics Diagnostics reporter.\n * @returns Detected PlatformMetadata.\n */\nexport function detectPlatform(diagnostics: Diagnostics): PlatformMetadata {\n if (cached) {\n return cached;\n }\n const g = globalThis as Global;\n\n const ua = (g.navigator as Navigator | undefined)?.userAgent ?? \"\";\n let platform: PlatformType = \"browser\";\n let openfinUuid: string | undefined;\n let openfinName: string | undefined;\n let isWorker = false;\n\n const finMe = getFin()?.me;\n\n if (isGlobalScope(g, \"ServiceWorkerGlobalScope\")) {\n platform = \"service_worker\";\n isWorker = true;\n } else if (isGlobalScope(g, \"SharedWorkerGlobalScope\")) {\n platform = \"shared_worker\";\n isWorker = true;\n } else if (isGlobalScope(g, \"WorkerGlobalScope\")) {\n platform = \"web_worker\";\n isWorker = true;\n } else if (finMe !== undefined) {\n platform = OPENFIN_UA_PATTERN.test(ua) ? \"openfin\" : \"openfin_web\";\n diagnostics.guard(\"openfin.unavailable\", \"The library could not read fin.me.identity.\", () => {\n const identity = finMe.identity;\n openfinUuid = identity?.uuid;\n openfinName = identity?.name;\n });\n } else if (g.Capacitor !== undefined || g.Ionic !== undefined) {\n platform = \"ionic\";\n } else if (g.cordova !== undefined || isWebView(ua)) {\n platform = \"mobile_webview\";\n } else if (typeof document === \"undefined\" && typeof process !== \"undefined\") {\n platform = \"node\";\n }\n\n cached = {\n platform,\n openfinUuid,\n openfinName,\n userAgent: ua,\n isWorker,\n isTopLevelDocument: isTopLevel(diagnostics),\n };\n return cached;\n}\n\n/**\n * Tests if a user agent string represents an embedded mobile webview.\n * @param ua User agent string.\n * @returns True if user agent matches Android or iOS webview signatures.\n */\nfunction isWebView(ua: string): boolean {\n if (ANDROID_WEBVIEW_UA_PATTERN.test(ua)) {\n return true;\n }\n const ios =\n IOS_DEVICE_UA_PATTERN.test(ua) || (MACINTOSH_UA_PATTERN.test(ua) && MOBILE_UA_PATTERN.test(ua));\n return ios && ua.includes(WEBKIT_UA_TOKEN) && !ua.includes(SAFARI_UA_TOKEN);\n}\n\n/**\n * Tests if the current window is the top-level browsing context.\n * @param diagnostics Diagnostics reporter. It counts a blocked read of window.top.\n * @returns True if top-level, false if framed or inaccessible due to cross-origin boundaries.\n */\nexport function isTopLevel(diagnostics: Diagnostics): boolean {\n if (typeof window === \"undefined\") {\n return false;\n }\n try {\n return window.self === window.top;\n } catch {\n // A cross-origin parent blocks the read. That proves a frame. Count it. Do not report it.\n diagnostics.count(\"platform.api_blocked\");\n return false;\n }\n}\n\n/**\n * Retrieves the current document URL without caching.\n * @param diagnostics Diagnostics reporter. It counts a blocked read of location.href.\n * @returns Current location.href or empty string.\n */\nexport function currentUrl(diagnostics: Diagnostics): string {\n try {\n return typeof location !== \"undefined\" ? location.href : \"\";\n } catch {\n // A sandbox can block the read. Count the fault. A report on each record is noise.\n diagnostics.count(\"platform.api_blocked\");\n return \"\";\n }\n}\n\n/** Matches the user info of an absolute URL, for example \"user:pass@\". */\nconst USER_INFO_PATTERN = /^([a-z][a-z\\d+.-]*:\\/\\/)[^/?#]*@/i;\n\n/**\n * Gives the form of a URL that the library records. It always removes the user info, which is a\n * credential. Without fullUrls, it also removes the query and the fragment.\n * @param url Absolute or relative URL.\n * @param fullUrls Value of `capture.fullUrls`.\n * @param transform Value of `capture.urlTransform`. It replaces the default rule.\n * @param diagnostics Diagnostics reporter for a transform that throws.\n * @returns The URL to record.\n */\nexport function recordedUrl(\n url: string,\n fullUrls: boolean,\n transform?: (url: string) => string | null,\n diagnostics?: Diagnostics,\n): string {\n if (transform) {\n try {\n const value = transform(url);\n return typeof value === \"string\" ? value : \"\";\n } catch (error) {\n // Report the fault. Without a report, each recorded URL is empty with no visible cause.\n diagnostics?.report(\n \"capture.record_failed\",\n \"capture.urlTransform threw an error. The library records an empty URL.\",\n undefined,\n error,\n );\n return \"\";\n }\n }\n const bare = url.replace(USER_INFO_PATTERN, \"$1\");\n return fullUrls ? bare : stripUrlQuery(bare);\n}\n\n/**\n * Drops the query string and fragment from a URL.\n * It cuts the string and does not parse a URL. A relative request target has no base URL.\n * @param url Absolute or relative URL.\n * @returns The URL up to the first \"?\" or \"#\".\n */\nexport function stripUrlQuery(url: string): string {\n const cut = url.search(/[?#]/);\n\n return cut === -1 ? url : url.slice(0, cut);\n}\n\n/**\n * Tests if the browser can reach the network. A host without navigator.onLine counts as online.\n * @returns False only when navigator.onLine is false.\n */\nexport function isOnline(): boolean {\n return (globalThis as { navigator?: { onLine?: boolean } }).navigator?.onLine !== false;\n}\n\n/** Resets the cached platform metadata for testing. */\nexport function resetPlatformCache(): void {\n cached = null;\n}\n"],"mappings":";;;AAkDA,IAAIM,IAAkC;AAWtC,SAASC,EAAc,GAAW,GAAuB;CACvD,IAAMC,IAAQC,EAAEC;CAIhB,OAHIF,MAAU,KAAA,KAGPC,aAAcD;AACvB;AAOA,SAAgBG,EAAe,GAA4C;CACzE,IAAIL,GACF,OAAOA;CAET,I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sBAAsB,GACjC;CACT;AACF;AAGA,IAAMI,IAAoB;AAW1B,SAAgBC,EACd,GACA,GACA,GACA,GACQ;CACR,IAAIC,GACF,IAAI;EACF,IAAMC,IAAQD,EAAUE,CAAG;EAC3B,OAAO,OAAOD,KAAU,WAAWA,IAAQ;CAC7C,SAASE,GAAO;EAQd,OANAT,GAAa,OACX,yBACA,0EACA,KAAA,GACAS,CACF,GACO;CACT;CAEF,IAAMC,IAAOF,EAAI,QAAQJ,GAAmB,IAAI;CAChD,OAAOO,IAAWD,IAAOE,EAAcF,CAAI;AAC7C;AAQA,SAAgBE,EAAc,GAAqB;CACjD,IAAMC,IAAML,EAAI,OAAO,MAAM;CAE7B,OAAOK,MAAQ,KAAKL,IAAMA,EAAI,MAAM,GAAGK,CAAG;AAC5C;AAMA,SAAgBC,IAAoB;CAClC,OAAQ,WAAoD,WAAW,WAAW;AACpF"}
|
|
1
|
+
{"version":3,"file":"platform-DkcuXwe-.js","names":["MOBILE_UA_PATTERN","OPENFIN_UA_PATTERN","IOS_DEVICE_UA_PATTERN","ANDROID_WEBVIEW_UA_PATTERN","MACINTOSH_UA_PATTERN","getFin","cached","isGlobalScope","scope","g","name","detectPlatform","ua","platform","openfinUuid","openfinName","isWorker","finMe","isWebView","diagnostics","identity","isTopLevel","currentUrl","USER_INFO_PATTERN","recordedUrl","transform","value","url","error","bare","fullUrls","stripUrlQuery","cut","isOnline"],"sources":["../src/utils/platform.ts"],"sourcesContent":["// src/utils/platform.ts\n//\n// Detects host platform capabilities, OpenFin container metadata, and worker\n// execution realms. The module caches the result. The result does not change during\n// the life of a realm. A webview is also a browser. Test for a webview first.\n\nimport {\n ANDROID_WEBVIEW_UA_PATTERN,\n IOS_DEVICE_UA_PATTERN,\n MACINTOSH_UA_PATTERN,\n MOBILE_UA_PATTERN,\n OPENFIN_UA_PATTERN,\n SAFARI_UA_TOKEN,\n WEBKIT_UA_TOKEN,\n} from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { getFin } from \"./openfin\";\n\n/** Host runtime environment classification attached to resource attributes. */\nexport type PlatformType =\n | \"openfin\"\n | \"openfin_web\"\n | \"browser\"\n | \"mobile_webview\"\n | \"ionic\"\n | \"web_worker\"\n | \"shared_worker\"\n | \"service_worker\"\n | \"node\";\n\n/** Host environment and runtime container metadata resolved at startup. */\nexport interface PlatformMetadata {\n /** Detected platform runtime classification. */\n platform: PlatformType;\n /** OpenFin application UUID if running inside an OpenFin container. */\n openfinUuid?: string;\n /** OpenFin window or view identifier. */\n openfinName?: string;\n /** Raw navigator user agent string or empty string if unavailable. */\n userAgent: string;\n /** True if the code runs in a worker realm. */\n isWorker: boolean;\n /** True if this context is the top-level document rather than an iframe. */\n isTopLevelDocument: boolean;\n}\n\n/** Indexed globalThis type for probing runtime globals. */\ntype Global = typeof globalThis & Record<string, unknown>;\n\n/** Cached platform metadata instance. */\nlet cached: PlatformMetadata | null = null;\n\n/** Abstract constructor type for global scope prototype checks. */\ntype ScopeConstructor = abstract new (...args: never[]) => object;\n\n/**\n * Tests if globalThis is an instance of a specified global scope constructor.\n * @param g Global scope object.\n * @param name Scope constructor name to check.\n * @returns True if globalThis inherits from the named scope constructor.\n */\nfunction isGlobalScope(g: Global, name: string): boolean {\n const scope = g[name];\n if (scope === undefined) {\n return false;\n }\n return g instanceof (scope as ScopeConstructor);\n}\n\n/**\n * Detects and caches host platform metadata for the active realm.\n * @param diagnostics Diagnostics reporter.\n * @returns Detected PlatformMetadata.\n */\nexport function detectPlatform(diagnostics: Diagnostics): PlatformMetadata {\n if (cached) {\n return cached;\n }\n const g = globalThis as Global;\n\n const ua = (g.navigator as Navigator | undefined)?.userAgent ?? \"\";\n let platform: PlatformType = \"browser\";\n let openfinUuid: string | undefined;\n let openfinName: string | undefined;\n let isWorker = false;\n\n const finMe = getFin()?.me;\n\n if (isGlobalScope(g, \"ServiceWorkerGlobalScope\")) {\n platform = \"service_worker\";\n isWorker = true;\n } else if (isGlobalScope(g, \"SharedWorkerGlobalScope\")) {\n platform = \"shared_worker\";\n isWorker = true;\n } else if (isGlobalScope(g, \"WorkerGlobalScope\")) {\n platform = \"web_worker\";\n isWorker = true;\n } else if (finMe !== undefined) {\n platform = OPENFIN_UA_PATTERN.test(ua) ? \"openfin\" : \"openfin_web\";\n diagnostics.guard(\"openfin.unavailable\", \"The library could not read fin.me.identity.\", () => {\n const identity = finMe.identity;\n openfinUuid = identity?.uuid;\n openfinName = identity?.name;\n });\n } else if (g.Capacitor !== undefined || g.Ionic !== undefined) {\n platform = \"ionic\";\n } else if (g.cordova !== undefined || isWebView(ua)) {\n platform = \"mobile_webview\";\n } else if (typeof document === \"undefined\" && typeof process !== \"undefined\") {\n platform = \"node\";\n }\n\n cached = {\n platform,\n openfinUuid,\n openfinName,\n userAgent: ua,\n isWorker,\n isTopLevelDocument: isTopLevel(diagnostics),\n };\n return cached;\n}\n\n/**\n * Tests if a user agent string represents an embedded mobile webview.\n * @param ua User agent string.\n * @returns True if user agent matches Android or iOS webview signatures.\n */\nfunction isWebView(ua: string): boolean {\n if (ANDROID_WEBVIEW_UA_PATTERN.test(ua)) {\n return true;\n }\n const ios =\n IOS_DEVICE_UA_PATTERN.test(ua) || (MACINTOSH_UA_PATTERN.test(ua) && MOBILE_UA_PATTERN.test(ua));\n return ios && ua.includes(WEBKIT_UA_TOKEN) && !ua.includes(SAFARI_UA_TOKEN);\n}\n\n/**\n * Tests if the current window is the top-level browsing context.\n * @param diagnostics Diagnostics reporter. It counts a blocked read of window.top.\n * @returns True if top-level, false if framed or inaccessible due to cross-origin boundaries.\n */\nexport function isTopLevel(diagnostics: Diagnostics): boolean {\n if (typeof window === \"undefined\") {\n return false;\n }\n try {\n return window.self === window.top;\n } catch {\n // A cross-origin parent blocks the read. That proves a frame. Count it. Do not report it.\n diagnostics.count(\"platform.api_blocked\");\n return false;\n }\n}\n\n/**\n * Retrieves the current document URL without caching.\n * @param diagnostics Diagnostics reporter. It counts a blocked read of location.href.\n * @returns Current location.href or empty string.\n */\nexport function currentUrl(diagnostics: Diagnostics): string {\n try {\n return typeof location !== \"undefined\" ? location.href : \"\";\n } catch {\n // A sandbox can block the read. Count the fault. A report on each record is noise.\n diagnostics.count(\"platform.api_blocked\");\n return \"\";\n }\n}\n\n/** Matches the user info of an absolute URL, for example \"user:pass@\". */\nconst USER_INFO_PATTERN = /^([a-z][a-z\\d+.-]*:\\/\\/)[^/?#]*@/i;\n\n/**\n * Gives the form of a URL that the library records. It always removes the user info, which is a\n * credential. Without fullUrls, it also removes the query and the fragment.\n * @param url Absolute or relative URL.\n * @param fullUrls Value of `capture.fullUrls`.\n * @param transform Value of `capture.urlTransform`. It replaces the default rule.\n * @param diagnostics Diagnostics reporter for a transform that throws.\n * @returns The URL to record.\n */\nexport function recordedUrl(\n url: string,\n fullUrls: boolean,\n transform?: (url: string) => string | null,\n diagnostics?: Diagnostics,\n): string {\n if (transform) {\n try {\n const value = transform(url);\n return typeof value === \"string\" ? value : \"\";\n } catch (error) {\n // Report the fault. Without a report, each recorded URL is empty with no visible cause.\n diagnostics?.report(\n \"capture.record_failed\",\n \"capture.urlTransform threw an error. The library records an empty URL.\",\n undefined,\n error,\n );\n return \"\";\n }\n }\n const bare = url.replace(USER_INFO_PATTERN, \"$1\");\n return fullUrls ? bare : stripUrlQuery(bare);\n}\n\n/**\n * Drops the query string and fragment from a URL.\n * It cuts the string and does not parse a URL. A relative request target has no base URL.\n * @param url Absolute or relative URL.\n * @returns The URL up to the first \"?\" or \"#\".\n */\nexport function stripUrlQuery(url: string): string {\n const cut = url.search(/[?#]/);\n\n return cut === -1 ? url : url.slice(0, cut);\n}\n\n/**\n * Tests if the browser can reach the network. A host without navigator.onLine counts as online.\n * @returns False only when navigator.onLine is false.\n */\nexport function isOnline(): boolean {\n return (globalThis as { navigator?: { onLine?: boolean } }).navigator?.onLine !== false;\n}\n\n/** Resets the cached platform metadata for testing. */\nexport function resetPlatformCache(): void {\n cached = null;\n}\n"],"mappings":";;;AAkDA,IAAIM,IAAkC;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GN,OADAF,EAAY,MAAM,sBAAsB,GACjC;CACT;AACF;AAOA,SAAgBG,EAAW,GAAkC;CAC3D,IAAI;EACF,OAAO,OAAO,WAAa,MAAc,SAAS,OAAO;CAC3D,QAAQ;EAGN,OADAH,EAAY,MAAM,sBAAsB,GACjC;CACT;AACF;AAGA,IAAMI,IAAoB;AAW1B,SAAgBC,EACd,GACA,GACA,GACA,GACQ;CACR,IAAIC,GACF,IAAI;EACF,IAAMC,IAAQD,EAAUE,CAAG;EAC3B,OAAO,OAAOD,KAAU,WAAWA,IAAQ;CAC7C,SAASE,GAAO;EAQd,OANAT,GAAa,OACX,yBACA,0EACA,KAAA,GACAS,CACF,GACO;CACT;CAEF,IAAMC,IAAOF,EAAI,QAAQJ,GAAmB,IAAI;CAChD,OAAOO,IAAWD,IAAOE,EAAcF,CAAI;AAC7C;AAQA,SAAgBE,EAAc,GAAqB;CACjD,IAAMC,IAAML,EAAI,OAAO,MAAM;CAE7B,OAAOK,MAAQ,KAAKL,IAAMA,EAAI,MAAM,GAAGK,CAAG;AAC5C;AAMA,SAAgBC,IAAoB;CAClC,OAAQ,WAAoD,WAAW,WAAW;AACpF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Jt as e, Yt as t, qt as n, wt as r } from "./constants-
|
|
2
|
-
import { t as i } from "./guards-
|
|
3
|
-
import { n as a, r as o } from "./sampling-
|
|
4
|
-
|
|
1
|
+
import { Jt as e, Yt as t, qt as n, wt as r } from "./constants-zyrqveN4.js";
|
|
2
|
+
import { t as i } from "./guards-Cidk71ME.js";
|
|
3
|
+
import { n as a, r as o } from "./sampling-C4VV-1MS.js";
|
|
4
|
+
// src/core/remote-sampling.ts
|
|
5
5
|
var s = class {
|
|
6
6
|
config;
|
|
7
7
|
rules = null;
|
|
@@ -93,7 +93,6 @@ function m(e, t) {
|
|
|
93
93
|
function h(e, t, n) {
|
|
94
94
|
n && (e.sampling ??= new s(t)), e.sampling?.apply(n), e.changed?.();
|
|
95
95
|
}
|
|
96
|
-
//#endregion
|
|
97
96
|
export { m as n, h as t };
|
|
98
97
|
|
|
99
|
-
//# sourceMappingURL=remote-rules-
|
|
98
|
+
//# sourceMappingURL=remote-rules-Cfb4K-Nl.js.map
|