@glasstrace/sdk 0.20.1 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +76 -5
  2. package/dist/chunk-3TU62WD6.js +142 -0
  3. package/dist/chunk-3TU62WD6.js.map +1 -0
  4. package/dist/chunk-67RIOAXV.js +105 -0
  5. package/dist/chunk-67RIOAXV.js.map +1 -0
  6. package/dist/{chunk-IQN6TRMQ.js → chunk-KE7MCPO5.js} +3 -140
  7. package/dist/chunk-KE7MCPO5.js.map +1 -0
  8. package/dist/{chunk-R4DAIPXD.js → chunk-MV3F7HVX.js} +96 -10
  9. package/dist/chunk-MV3F7HVX.js.map +1 -0
  10. package/dist/{chunk-BT2OCXCG.js → chunk-UGJ3X4CT.js} +1 -1
  11. package/dist/chunk-UGJ3X4CT.js.map +1 -0
  12. package/dist/cli/init.cjs +1 -1
  13. package/dist/cli/init.cjs.map +1 -1
  14. package/dist/cli/init.js +2 -2
  15. package/dist/cli/init.js.map +1 -1
  16. package/dist/{edge-entry-Ds2fNOeh.d.ts → edge-entry-CFq085RZ.d.ts} +2 -29
  17. package/dist/{edge-entry-FJFKkeFF.d.cts → edge-entry-DYl05SJ-.d.cts} +2 -29
  18. package/dist/edge-entry.cjs +2 -102
  19. package/dist/edge-entry.cjs.map +1 -1
  20. package/dist/edge-entry.d.cts +2 -2
  21. package/dist/edge-entry.d.ts +2 -2
  22. package/dist/edge-entry.js +3 -5
  23. package/dist/index.cjs +38 -244
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/{index.d-DgeH-pNJ.d.cts → index.d-CYYe3PxB.d.cts} +1 -1
  26. package/dist/{index.d-DgeH-pNJ.d.ts → index.d-CYYe3PxB.d.ts} +1 -1
  27. package/dist/index.d.cts +4 -5
  28. package/dist/index.d.ts +4 -5
  29. package/dist/index.js +4 -29
  30. package/dist/node-entry.cjs +93 -104
  31. package/dist/node-entry.cjs.map +1 -1
  32. package/dist/node-entry.d.cts +2 -2
  33. package/dist/node-entry.d.ts +2 -2
  34. package/dist/node-entry.js +6 -7
  35. package/dist/node-subpath.cjs.map +1 -1
  36. package/dist/node-subpath.d.cts +110 -3
  37. package/dist/node-subpath.d.ts +110 -3
  38. package/dist/node-subpath.js +3 -2
  39. package/dist/{source-map-uploader-YXWO6JLN.js → source-map-uploader-BJIXRLJ6.js} +3 -2
  40. package/package.json +11 -2
  41. package/dist/chunk-BT2OCXCG.js.map +0 -1
  42. package/dist/chunk-IQN6TRMQ.js.map +0 -1
  43. package/dist/chunk-R4DAIPXD.js.map +0 -1
  44. package/dist/chunk-Z2EGETTT.js +0 -204
  45. package/dist/chunk-Z2EGETTT.js.map +0 -1
  46. /package/dist/{source-map-uploader-YXWO6JLN.js.map → source-map-uploader-BJIXRLJ6.js.map} +0 -0
@@ -1,6 +1,3 @@
1
- import {
2
- createDiscoveryHandler
3
- } from "./chunk-Z2EGETTT.js";
4
1
  import {
5
2
  DiagLogLevel,
6
3
  INVALID_SPAN_CONTEXT,
@@ -23,7 +20,7 @@ import {
23
20
  maybeShowMcpNudge,
24
21
  maybeShowServerActionNudge,
25
22
  sdkLog
26
- } from "./chunk-IQN6TRMQ.js";
23
+ } from "./chunk-3TU62WD6.js";
27
24
  import {
28
25
  _setCurrentConfig,
29
26
  collectHealthReport,
@@ -3668,6 +3665,95 @@ async function runRegistrationPath(config, sessionManager) {
3668
3665
  emitLifecycleEvent("otel:configured", { state: OtelState.OWNS_PROVIDER, scenario: "A" });
3669
3666
  }
3670
3667
 
3668
+ // src/discovery-endpoint.ts
3669
+ function isAllowedOrigin(origin) {
3670
+ if (origin === null) return true;
3671
+ if (origin.startsWith("chrome-extension://")) return true;
3672
+ if (origin.startsWith("moz-extension://")) return true;
3673
+ if (origin.startsWith("safari-web-extension://")) return true;
3674
+ return false;
3675
+ }
3676
+ function buildCorsHeaders(origin) {
3677
+ const headers = {
3678
+ "Content-Type": "application/json",
3679
+ Vary: "Origin"
3680
+ };
3681
+ if (origin && isAllowedOrigin(origin)) {
3682
+ headers["Access-Control-Allow-Origin"] = origin;
3683
+ }
3684
+ return headers;
3685
+ }
3686
+ function createDiscoveryHandler(getAnonKey, getSessionId, getClaimState) {
3687
+ return async (request) => {
3688
+ let url;
3689
+ try {
3690
+ url = new URL(request.url);
3691
+ } catch {
3692
+ return null;
3693
+ }
3694
+ if (url.pathname !== "/__glasstrace/config") {
3695
+ return null;
3696
+ }
3697
+ const origin = request.headers.get("Origin");
3698
+ const corsHeaders = buildCorsHeaders(origin);
3699
+ if (request.method === "OPTIONS") {
3700
+ return new Response(null, {
3701
+ status: 204,
3702
+ headers: {
3703
+ ...corsHeaders,
3704
+ "Access-Control-Allow-Methods": "GET, OPTIONS",
3705
+ "Access-Control-Allow-Headers": "Content-Type"
3706
+ }
3707
+ });
3708
+ }
3709
+ if (request.method !== "GET") {
3710
+ return new Response(
3711
+ JSON.stringify({ error: "method_not_allowed" }),
3712
+ {
3713
+ status: 405,
3714
+ headers: corsHeaders
3715
+ }
3716
+ );
3717
+ }
3718
+ try {
3719
+ const anonKey = await getAnonKey();
3720
+ if (anonKey === null) {
3721
+ return new Response(
3722
+ JSON.stringify({ error: "not_ready" }),
3723
+ {
3724
+ status: 503,
3725
+ headers: corsHeaders
3726
+ }
3727
+ );
3728
+ }
3729
+ const sessionId = getSessionId();
3730
+ const responseBody = { key: anonKey, sessionId };
3731
+ const claimState = getClaimState?.();
3732
+ if (claimState?.claimed) {
3733
+ responseBody.claimed = true;
3734
+ if (claimState.accountHint) {
3735
+ responseBody.accountHint = claimState.accountHint;
3736
+ }
3737
+ }
3738
+ return new Response(
3739
+ JSON.stringify(responseBody),
3740
+ {
3741
+ status: 200,
3742
+ headers: corsHeaders
3743
+ }
3744
+ );
3745
+ } catch {
3746
+ return new Response(
3747
+ JSON.stringify({ error: "internal_error" }),
3748
+ {
3749
+ status: 500,
3750
+ headers: corsHeaders
3751
+ }
3752
+ );
3753
+ }
3754
+ };
3755
+ }
3756
+
3671
3757
  // src/context-manager.ts
3672
3758
  import { AsyncLocalStorage } from "node:async_hooks";
3673
3759
  function installContextManager() {
@@ -3919,7 +4005,7 @@ function registerGlasstrace(options) {
3919
4005
  setCoreState(CoreState.REGISTERING);
3920
4006
  startRuntimeStateWriter({
3921
4007
  projectRoot: process.cwd(),
3922
- sdkVersion: "0.20.1"
4008
+ sdkVersion: "1.0.1"
3923
4009
  });
3924
4010
  const config = resolveConfig(options);
3925
4011
  if (config.verbose) {
@@ -4085,8 +4171,8 @@ async function backgroundInit(config, anonKeyForInit, generation) {
4085
4171
  if (config.verbose) {
4086
4172
  console.info("[glasstrace] Background init firing.");
4087
4173
  }
4088
- const healthReport = collectHealthReport("0.20.1");
4089
- const initResult = await performInit(config, anonKeyForInit, "0.20.1", healthReport);
4174
+ const healthReport = collectHealthReport("1.0.1");
4175
+ const initResult = await performInit(config, anonKeyForInit, "1.0.1", healthReport);
4090
4176
  if (generation !== registrationGeneration) return;
4091
4177
  const currentState = getCoreState();
4092
4178
  if (currentState === CoreState.SHUTTING_DOWN || currentState === CoreState.SHUTDOWN) {
@@ -4109,7 +4195,7 @@ async function backgroundInit(config, anonKeyForInit, generation) {
4109
4195
  }
4110
4196
  maybeInstallConsoleCapture();
4111
4197
  if (didLastInitSucceed()) {
4112
- startHeartbeat(config, anonKeyForInit, "0.20.1", generation, (newApiKey, accountId) => {
4198
+ startHeartbeat(config, anonKeyForInit, "1.0.1", generation, (newApiKey, accountId) => {
4113
4199
  setAuthState(AuthState.CLAIMING);
4114
4200
  emitLifecycleEvent("auth:claim_started", { accountId });
4115
4201
  setResolvedApiKey(newApiKey);
@@ -4404,7 +4490,7 @@ async function handleSourceMapUpload(distDir) {
4404
4490
  );
4405
4491
  return;
4406
4492
  }
4407
- const { discoverSourceMapFiles, computeBuildHash, uploadSourceMaps } = await import("./source-map-uploader-YXWO6JLN.js");
4493
+ const { discoverSourceMapFiles, computeBuildHash, uploadSourceMaps } = await import("./source-map-uploader-BJIXRLJ6.js");
4408
4494
  const files = await discoverSourceMapFiles(distDir);
4409
4495
  if (files.length === 0) {
4410
4496
  console.info("[glasstrace] No source map files found. Skipping upload.");
@@ -4458,4 +4544,4 @@ export {
4458
4544
  withGlasstraceConfig,
4459
4545
  captureError
4460
4546
  };
4461
- //# sourceMappingURL=chunk-R4DAIPXD.js.map
4547
+ //# sourceMappingURL=chunk-MV3F7HVX.js.map