@reopt-ai/data-sdk-client 0.1.6 → 0.3.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/README.md +141 -7
- package/dist/client-B1GlWwVq.d.ts +744 -0
- package/dist/client-B1GlWwVq.d.ts.map +1 -0
- package/dist/client-BCrui21p.d.cts +744 -0
- package/dist/client-BCrui21p.d.cts.map +1 -0
- package/dist/exceptions-C9Fh0BIR.js +285 -0
- package/dist/exceptions-C9Fh0BIR.js.map +1 -0
- package/dist/exceptions-CuhGo9A5.cjs +289 -0
- package/dist/exceptions-CuhGo9A5.cjs.map +1 -0
- package/dist/index.cjs +75 -1874
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +83 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +35 -33
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -70
- package/dist/index.js.map +1 -1
- package/dist/next.cjs +51 -1919
- package/dist/next.cjs.map +1 -1
- package/dist/next.d.cts +31 -0
- package/dist/next.d.cts.map +1 -0
- package/dist/next.d.ts +8 -10
- package/dist/next.d.ts.map +1 -0
- package/dist/next.js +36 -49
- package/dist/next.js.map +1 -1
- package/dist/observe-D-BHMwrO.cjs +54 -0
- package/dist/observe-D-BHMwrO.cjs.map +1 -0
- package/dist/observe-D1pNg1qL.js +54 -0
- package/dist/observe-D1pNg1qL.js.map +1 -0
- package/dist/react.cjs +105 -1863
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +80 -0
- package/dist/react.d.cts.map +1 -0
- package/dist/react.d.ts +52 -46
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +118 -23
- package/dist/react.js.map +1 -1
- package/dist/registry-BPhiH_l9.js +1775 -0
- package/dist/registry-BPhiH_l9.js.map +1 -0
- package/dist/registry-CGqrOtf4.cjs +1810 -0
- package/dist/registry-CGqrOtf4.cjs.map +1 -0
- package/dist/tracing-DAhaKkl0.cjs +93 -0
- package/dist/tracing-DAhaKkl0.cjs.map +1 -0
- package/dist/tracing-Dt1RVuQ9.js +93 -0
- package/dist/tracing-Dt1RVuQ9.js.map +1 -0
- package/package.json +33 -18
- package/dist/chunk-4MTDZBRS.js +0 -57
- package/dist/chunk-4MTDZBRS.js.map +0 -1
- package/dist/chunk-SYCBGBTH.js +0 -1627
- package/dist/chunk-SYCBGBTH.js.map +0 -1
- package/dist/chunk-YRP3I3OD.js +0 -106
- package/dist/chunk-YRP3I3OD.js.map +0 -1
- package/dist/client-BCd2fgmx.d.ts +0 -581
- package/dist/exceptions-NQHZUDYO.js +0 -9
- package/dist/exceptions-NQHZUDYO.js.map +0 -1
- package/dist/tracing-LC3NZND7.js +0 -91
- package/dist/tracing-LC3NZND7.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/identity/tracing.ts"],"sourcesContent":["import { DEVICE_ID_HEADER } from \"@reopt-ai/data-contract/identity\";\n\nexport interface TracingOptions {\n /** Hostnames that receive the header. */\n hosts: string[];\n getDeviceId: () => string;\n}\n\ntype FetchInput = Parameters<typeof fetch>[0];\n\nfunction hostOf(input: FetchInput | string): string | null {\n try {\n const url = typeof input === \"string\" ? input : input instanceof URL ? input.href : input.url;\n return new URL(url, location.href).hostname;\n } catch {\n return null;\n }\n}\n\n/**\n * Adds `reopt-device-id` to outgoing `fetch` and XHR requests bound for the\n * configured hosts, so a route handler that calls the server SDK files its\n * events under the same device the browser is using.\n *\n * Only the device id travels. A session id would let any page inject events\n * into any session it names, and ingest does not trust it — so it is not\n * sent at all until it can be signed.\n *\n * Idempotent: a second install is a no-op. Returns the uninstaller, which\n * restores the original functions only if nobody patched them after us.\n */\nexport function installTracingHeaders(options: TracingOptions): () => void {\n if (typeof window === \"undefined\") return () => {};\n // One patch per page, shared by every client on it; the last one to\n // uninstall restores the originals.\n const holder = window as unknown as { __reoptTracing?: { refs: number; uninstall: () => void } };\n if (holder.__reoptTracing) {\n const shared = holder.__reoptTracing;\n shared.refs += 1;\n return () => {\n shared.refs -= 1;\n if (shared.refs === 0) shared.uninstall();\n };\n }\n\n const hosts = new Set(options.hosts);\n const shouldTag = (input: FetchInput | string) => {\n const host = hostOf(input);\n return host !== null && hosts.has(host);\n };\n\n const originalFetch = window.fetch;\n const patchedFetch: typeof fetch = (input, init) => {\n if (!shouldTag(input)) return originalFetch.call(window, input, init);\n const deviceId = options.getDeviceId();\n if (!deviceId) return originalFetch.call(window, input, init);\n try {\n // A Request instance carries its own headers; a plain init may too.\n if (input instanceof Request && !init) {\n const request = new Request(input);\n request.headers.set(DEVICE_ID_HEADER, deviceId);\n return originalFetch.call(window, request);\n }\n const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : undefined));\n headers.set(DEVICE_ID_HEADER, deviceId);\n return originalFetch.call(window, input, { ...init, headers });\n } catch {\n // Whatever went wrong building headers, the app's request must go out.\n return originalFetch.call(window, input, init);\n }\n };\n window.fetch = patchedFetch;\n\n const XHR = window.XMLHttpRequest;\n const originalOpen = XHR?.prototype.open;\n const originalSend = XHR?.prototype.send;\n const tagged = new WeakSet<XMLHttpRequest>();\n let patchedOpen: typeof XHR.prototype.open | undefined;\n let patchedSend: typeof XHR.prototype.send | undefined;\n if (XHR && originalOpen && originalSend) {\n XHR.prototype.open = function (this: XMLHttpRequest, method: string, url: string | URL, ...rest: unknown[]) {\n if (shouldTag(typeof url === \"string\" ? url : url.href)) tagged.add(this);\n return (originalOpen as (...args: unknown[]) => void).call(this, method, url, ...rest);\n } as typeof XHR.prototype.open;\n XHR.prototype.send = function (this: XMLHttpRequest, body?: Document | XMLHttpRequestBodyInit | null) {\n if (tagged.has(this)) {\n const deviceId = options.getDeviceId();\n if (deviceId) {\n try {\n this.setRequestHeader(DEVICE_ID_HEADER, deviceId);\n } catch {\n // Already sent or header refused — never break the app's request.\n }\n }\n }\n return originalSend.call(this, body);\n };\n patchedOpen = XHR.prototype.open;\n patchedSend = XHR.prototype.send;\n }\n\n const uninstall = () => {\n // Restore only what is still ours; someone may have patched after us.\n if (window.fetch === patchedFetch) window.fetch = originalFetch;\n if (XHR && originalOpen && originalSend) {\n if (XHR.prototype.open === patchedOpen) XHR.prototype.open = originalOpen;\n if (XHR.prototype.send === patchedSend) XHR.prototype.send = originalSend;\n }\n delete holder.__reoptTracing;\n };\n const shared = { refs: 1, uninstall };\n holder.__reoptTracing = shared;\n return () => {\n shared.refs -= 1;\n if (shared.refs === 0) shared.uninstall();\n };\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AAUjC,SAAS,OAAO,OAA2C;AACzD,MAAI;AACF,UAAM,MAAM,OAAO,UAAU,WAAW,QAAQ,iBAAiB,MAAM,MAAM,OAAO,MAAM;AAC1F,WAAO,IAAI,IAAI,KAAK,SAAS,IAAI,EAAE;AAAA,EACrC,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAcO,SAAS,sBAAsB,SAAqC;AACzE,MAAI,OAAO,WAAW,YAAa,QAAO,MAAM;AAAA,EAAC;AAGjD,QAAM,SAAS;AACf,MAAI,OAAO,gBAAgB;AACzB,UAAMA,UAAS,OAAO;AACtB,IAAAA,QAAO,QAAQ;AACf,WAAO,MAAM;AACX,MAAAA,QAAO,QAAQ;AACf,UAAIA,QAAO,SAAS,EAAG,CAAAA,QAAO,UAAU;AAAA,IAC1C;AAAA,EACF;AAEA,QAAM,QAAQ,IAAI,IAAI,QAAQ,KAAK;AACnC,QAAM,YAAY,CAAC,UAA+B;AAChD,UAAM,OAAO,OAAO,KAAK;AACzB,WAAO,SAAS,QAAQ,MAAM,IAAI,IAAI;AAAA,EACxC;AAEA,QAAM,gBAAgB,OAAO;AAC7B,QAAM,eAA6B,CAAC,OAAO,SAAS;AAClD,QAAI,CAAC,UAAU,KAAK,EAAG,QAAO,cAAc,KAAK,QAAQ,OAAO,IAAI;AACpE,UAAM,WAAW,QAAQ,YAAY;AACrC,QAAI,CAAC,SAAU,QAAO,cAAc,KAAK,QAAQ,OAAO,IAAI;AAC5D,QAAI;AAEF,UA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