@glasstrace/sdk 0.18.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.md +79 -0
  2. package/dist/{chunk-GSGX76Q5.js → chunk-5N2IR4EO.js} +146 -3
  3. package/dist/chunk-5N2IR4EO.js.map +1 -0
  4. package/dist/{chunk-XNDHQN4S.js → chunk-6JRI4OGB.js} +286 -54
  5. package/dist/chunk-6JRI4OGB.js.map +1 -0
  6. package/dist/{chunk-IOPCSX6C.js → chunk-F2TZRBEH.js} +2 -2
  7. package/dist/{chunk-E33Y7BQH.js → chunk-VN3GZDV6.js} +2 -2
  8. package/dist/{chunk-J5BW7V2D.js → chunk-YPXW2TN3.js} +2 -2
  9. package/dist/cli/init.cjs +548 -153
  10. package/dist/cli/init.cjs.map +1 -1
  11. package/dist/cli/init.d.cts +48 -2
  12. package/dist/cli/init.d.ts +48 -2
  13. package/dist/cli/init.js +106 -6
  14. package/dist/cli/init.js.map +1 -1
  15. package/dist/cli/mcp-add.cjs +66 -0
  16. package/dist/cli/mcp-add.cjs.map +1 -1
  17. package/dist/cli/mcp-add.js +2 -2
  18. package/dist/cli/uninit.cjs +172 -54
  19. package/dist/cli/uninit.cjs.map +1 -1
  20. package/dist/cli/uninit.d.cts +2 -0
  21. package/dist/cli/uninit.d.ts +2 -0
  22. package/dist/cli/uninit.js +2 -1
  23. package/dist/index.cjs +157 -34
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +43 -12
  26. package/dist/index.d.ts +43 -12
  27. package/dist/index.js +19 -39
  28. package/dist/index.js.map +1 -1
  29. package/dist/{source-map-uploader-26QPRSCG.js → source-map-uploader-VPDZWWM2.js} +3 -3
  30. package/package.json +1 -1
  31. package/dist/chunk-GSGX76Q5.js.map +0 -1
  32. package/dist/chunk-XNDHQN4S.js.map +0 -1
  33. /package/dist/{chunk-IOPCSX6C.js.map → chunk-F2TZRBEH.js.map} +0 -0
  34. /package/dist/{chunk-E33Y7BQH.js.map → chunk-VN3GZDV6.js.map} +0 -0
  35. /package/dist/{chunk-J5BW7V2D.js.map → chunk-YPXW2TN3.js.map} +0 -0
  36. /package/dist/{source-map-uploader-26QPRSCG.js.map → source-map-uploader-VPDZWWM2.js.map} +0 -0
package/dist/index.d.cts CHANGED
@@ -140,6 +140,49 @@ declare const SourceMapManifestResponseSchema: z.ZodObject<{
140
140
  }, z.core.$strip>;
141
141
  type SourceMapManifestResponse = z.infer<typeof SourceMapManifestResponseSchema>;
142
142
 
143
+ /**
144
+ * Session ID derivation — part of the public Glasstrace wire contract.
145
+ *
146
+ * Deriving the session ID is deterministic: given the same inputs,
147
+ * every runtime that implements this module produces the same
148
+ * 16-character hex identifier. That determinism is the contract — it
149
+ * lets independent clients (SDK, browser extension, server tooling)
150
+ * agree on the same session without coordination.
151
+ *
152
+ * This module is pure: it has no module-level state and no
153
+ * runtime-dependent branches. It is safe to import from Node 20+,
154
+ * modern browsers, Vercel Edge, and Cloudflare Workers. The SHA-256
155
+ * implementation is pure JavaScript; no `node:crypto`, no Web Crypto,
156
+ * no bundler-specific shims.
157
+ */
158
+
159
+ /**
160
+ * Derives a deterministic session ID from the inputs that define a
161
+ * Glasstrace session. The output is a 16-character lowercase hex
162
+ * string validated through {@link SessionIdSchema}.
163
+ *
164
+ * This function is part of the Glasstrace wire contract: any consumer
165
+ * (SDK, browser extension, server tooling) that calls it with the same
166
+ * arguments receives the same `SessionId`. That property is what lets
167
+ * independent clients agree on a session without coordination.
168
+ *
169
+ * Uses a pure-JavaScript SHA-256 so the output is identical across
170
+ * every runtime this package supports (Node 20+, modern browsers,
171
+ * Vercel Edge, Cloudflare Workers).
172
+ *
173
+ * Security note: the session ID is an **identifier**, not a secret or
174
+ * an authentication token. It is never used for authorization.
175
+ *
176
+ * @param apiKey - The project's API key (or anonymous placeholder).
177
+ * @param origin - The origin string identifying the deployment
178
+ * environment (for example `localhost:3000` or `production`).
179
+ * @param date - UTC date as `YYYY-MM-DD`.
180
+ * @param windowIndex - Zero-based index of the 4-hour activity window
181
+ * within the day.
182
+ * @returns A 16-character hex {@link SessionId}.
183
+ */
184
+ declare function deriveSessionId(apiKey: string, origin: string, date: string, windowIndex: number): SessionId;
185
+
143
186
  /**
144
187
  * Internal SDK error class with a typed diagnostic code.
145
188
  * Caught at the boundary and converted to a log message + diagnostic entry.
@@ -188,18 +231,6 @@ declare function isProductionDisabled(config: ResolvedConfig): boolean;
188
231
  */
189
232
  declare function isAnonymousMode(config: ResolvedConfig): boolean;
190
233
 
191
- /**
192
- * Derives a deterministic session ID from the given inputs.
193
- * Uses SHA-256 (truncated to 16 hex chars) when `node:crypto` is available,
194
- * or a deterministic FNV-1a hash as a fallback in non-Node environments.
195
- *
196
- * @param apiKey - The project's API key (or anonymous placeholder).
197
- * @param origin - The origin string identifying the deployment environment.
198
- * @param date - UTC date as YYYY-MM-DD.
199
- * @param windowIndex - Zero-based index of the 4-hour activity window within the day.
200
- * @returns A 16-character hex SessionId.
201
- */
202
- declare function deriveSessionId(apiKey: string, origin: string, date: string, windowIndex: number): SessionId;
203
234
  /**
204
235
  * Returns the origin string for the current process.
205
236
  * If GLASSTRACE_ENV is set, returns that value.
package/dist/index.d.ts CHANGED
@@ -140,6 +140,49 @@ declare const SourceMapManifestResponseSchema: z.ZodObject<{
140
140
  }, z.core.$strip>;
141
141
  type SourceMapManifestResponse = z.infer<typeof SourceMapManifestResponseSchema>;
142
142
 
143
+ /**
144
+ * Session ID derivation — part of the public Glasstrace wire contract.
145
+ *
146
+ * Deriving the session ID is deterministic: given the same inputs,
147
+ * every runtime that implements this module produces the same
148
+ * 16-character hex identifier. That determinism is the contract — it
149
+ * lets independent clients (SDK, browser extension, server tooling)
150
+ * agree on the same session without coordination.
151
+ *
152
+ * This module is pure: it has no module-level state and no
153
+ * runtime-dependent branches. It is safe to import from Node 20+,
154
+ * modern browsers, Vercel Edge, and Cloudflare Workers. The SHA-256
155
+ * implementation is pure JavaScript; no `node:crypto`, no Web Crypto,
156
+ * no bundler-specific shims.
157
+ */
158
+
159
+ /**
160
+ * Derives a deterministic session ID from the inputs that define a
161
+ * Glasstrace session. The output is a 16-character lowercase hex
162
+ * string validated through {@link SessionIdSchema}.
163
+ *
164
+ * This function is part of the Glasstrace wire contract: any consumer
165
+ * (SDK, browser extension, server tooling) that calls it with the same
166
+ * arguments receives the same `SessionId`. That property is what lets
167
+ * independent clients agree on a session without coordination.
168
+ *
169
+ * Uses a pure-JavaScript SHA-256 so the output is identical across
170
+ * every runtime this package supports (Node 20+, modern browsers,
171
+ * Vercel Edge, Cloudflare Workers).
172
+ *
173
+ * Security note: the session ID is an **identifier**, not a secret or
174
+ * an authentication token. It is never used for authorization.
175
+ *
176
+ * @param apiKey - The project's API key (or anonymous placeholder).
177
+ * @param origin - The origin string identifying the deployment
178
+ * environment (for example `localhost:3000` or `production`).
179
+ * @param date - UTC date as `YYYY-MM-DD`.
180
+ * @param windowIndex - Zero-based index of the 4-hour activity window
181
+ * within the day.
182
+ * @returns A 16-character hex {@link SessionId}.
183
+ */
184
+ declare function deriveSessionId(apiKey: string, origin: string, date: string, windowIndex: number): SessionId;
185
+
143
186
  /**
144
187
  * Internal SDK error class with a typed diagnostic code.
145
188
  * Caught at the boundary and converted to a log message + diagnostic entry.
@@ -188,18 +231,6 @@ declare function isProductionDisabled(config: ResolvedConfig): boolean;
188
231
  */
189
232
  declare function isAnonymousMode(config: ResolvedConfig): boolean;
190
233
 
191
- /**
192
- * Derives a deterministic session ID from the given inputs.
193
- * Uses SHA-256 (truncated to 16 hex chars) when `node:crypto` is available,
194
- * or a deterministic FNV-1a hash as a fallback in non-Node environments.
195
- *
196
- * @param apiKey - The project's API key (or anonymous placeholder).
197
- * @param origin - The origin string identifying the deployment environment.
198
- * @param date - UTC date as YYYY-MM-DD.
199
- * @param windowIndex - Zero-based index of the 4-hour activity window within the day.
200
- * @returns A 16-character hex SessionId.
201
- */
202
- declare function deriveSessionId(apiKey: string, origin: string, date: string, windowIndex: number): SessionId;
203
234
  /**
204
235
  * Returns the origin string for the current process.
205
236
  * If GLASSTRACE_ENV is set, returns that value.
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  uploadSourceMaps,
11
11
  uploadSourceMapsAuto,
12
12
  uploadSourceMapsPresigned
13
- } from "./chunk-E33Y7BQH.js";
13
+ } from "./chunk-VN3GZDV6.js";
14
14
  import {
15
15
  _setCurrentConfig,
16
16
  buildImportGraph,
@@ -28,7 +28,7 @@ import {
28
28
  recordSpansExported,
29
29
  saveCachedConfig,
30
30
  sendInitRequest
31
- } from "./chunk-IOPCSX6C.js";
31
+ } from "./chunk-F2TZRBEH.js";
32
32
  import {
33
33
  isAnonymousMode,
34
34
  isProductionDisabled,
@@ -38,11 +38,11 @@ import {
38
38
  import {
39
39
  getOrCreateAnonKey,
40
40
  readAnonKey
41
- } from "./chunk-J5BW7V2D.js";
41
+ } from "./chunk-YPXW2TN3.js";
42
42
  import {
43
43
  GLASSTRACE_ATTRIBUTE_NAMES,
44
- SessionIdSchema
45
- } from "./chunk-GSGX76Q5.js";
44
+ deriveSessionId
45
+ } from "./chunk-5N2IR4EO.js";
46
46
  import {
47
47
  DiagLogLevel,
48
48
  INVALID_SPAN_CONTEXT,
@@ -76,37 +76,8 @@ var SdkError = class extends Error {
76
76
 
77
77
  // src/session.ts
78
78
  var FOUR_HOURS_MS = 4 * 60 * 60 * 1e3;
79
- var hashFn = null;
80
- function fnv1aHash(input) {
81
- let hash = 2166136261;
82
- for (let i = 0; i < input.length; i++) {
83
- hash ^= input.charCodeAt(i);
84
- hash = Math.imul(hash, 16777619);
85
- hash >>>= 0;
86
- }
87
- return hash.toString(16).padStart(8, "0");
88
- }
89
- function getHashFn() {
90
- if (hashFn) return hashFn;
91
- try {
92
- const { createHash } = __require("node:crypto");
93
- hashFn = (input) => createHash("sha256").update(input).digest("hex").slice(0, 16);
94
- } catch {
95
- hashFn = (input) => {
96
- const h1 = fnv1aHash(input);
97
- const h2 = fnv1aHash(input + "\0");
98
- return (h1 + h2).slice(0, 16);
99
- };
100
- }
101
- return hashFn;
102
- }
103
79
  var cachedGlasstraceEnv = process.env.GLASSTRACE_ENV;
104
80
  var cachedPort = process.env.PORT ?? "3000";
105
- function deriveSessionId(apiKey, origin, date, windowIndex) {
106
- const input = JSON.stringify([apiKey, origin, date, windowIndex]);
107
- const hash = getHashFn()(input);
108
- return SessionIdSchema.parse(hash);
109
- }
110
81
  function getOrigin() {
111
82
  if (cachedGlasstraceEnv) {
112
83
  return cachedGlasstraceEnv;
@@ -616,6 +587,14 @@ function deriveErrorCategory(errorType) {
616
587
  }
617
588
 
618
589
  // src/discovery-endpoint.ts
590
+ var runtimeHandlerDeprecationWarned = false;
591
+ function warnRuntimeHandlerDeprecatedOnce() {
592
+ if (runtimeHandlerDeprecationWarned) return;
593
+ runtimeHandlerDeprecationWarned = true;
594
+ console.warn(
595
+ "[glasstrace] createDiscoveryHandler is deprecated. Run `npx glasstrace init` to generate a static file at public/.well-known/glasstrace.json (or static/.well-known/glasstrace.json on SvelteKit). The runtime handler will be removed in v1.0.0."
596
+ );
597
+ }
619
598
  function isAllowedOrigin(origin) {
620
599
  if (origin === null) return true;
621
600
  if (origin.startsWith("chrome-extension://")) return true;
@@ -644,6 +623,7 @@ function createDiscoveryHandler(getAnonKey, getSessionId, getClaimState) {
644
623
  if (url.pathname !== "/__glasstrace/config") {
645
624
  return null;
646
625
  }
626
+ warnRuntimeHandlerDeprecatedOnce();
647
627
  const origin = request.headers.get("Origin");
648
628
  const corsHeaders = buildCorsHeaders(origin);
649
629
  if (request.method === "OPTIONS") {
@@ -4236,7 +4216,7 @@ function registerGlasstrace(options) {
4236
4216
  setCoreState(CoreState.REGISTERING);
4237
4217
  startRuntimeStateWriter({
4238
4218
  projectRoot: process.cwd(),
4239
- sdkVersion: "0.18.0"
4219
+ sdkVersion: "0.20.0"
4240
4220
  });
4241
4221
  const config = resolveConfig(options);
4242
4222
  if (config.verbose) {
@@ -4402,8 +4382,8 @@ async function backgroundInit(config, anonKeyForInit, generation) {
4402
4382
  if (config.verbose) {
4403
4383
  console.info("[glasstrace] Background init firing.");
4404
4384
  }
4405
- const healthReport = collectHealthReport("0.18.0");
4406
- const initResult = await performInit(config, anonKeyForInit, "0.18.0", healthReport);
4385
+ const healthReport = collectHealthReport("0.20.0");
4386
+ const initResult = await performInit(config, anonKeyForInit, "0.20.0", healthReport);
4407
4387
  if (generation !== registrationGeneration) return;
4408
4388
  const currentState = getCoreState();
4409
4389
  if (currentState === CoreState.SHUTTING_DOWN || currentState === CoreState.SHUTDOWN) {
@@ -4426,7 +4406,7 @@ async function backgroundInit(config, anonKeyForInit, generation) {
4426
4406
  }
4427
4407
  maybeInstallConsoleCapture();
4428
4408
  if (didLastInitSucceed()) {
4429
- startHeartbeat(config, anonKeyForInit, "0.18.0", generation, (newApiKey, accountId) => {
4409
+ startHeartbeat(config, anonKeyForInit, "0.20.0", generation, (newApiKey, accountId) => {
4430
4410
  setAuthState(AuthState.CLAIMING);
4431
4411
  emitLifecycleEvent("auth:claim_started", { accountId });
4432
4412
  setResolvedApiKey(newApiKey);
@@ -4563,7 +4543,7 @@ async function handleSourceMapUpload(distDir) {
4563
4543
  );
4564
4544
  return;
4565
4545
  }
4566
- const { discoverSourceMapFiles: discoverSourceMapFiles2, computeBuildHash: computeBuildHash2, uploadSourceMaps: uploadSourceMaps2 } = await import("./source-map-uploader-26QPRSCG.js");
4546
+ const { discoverSourceMapFiles: discoverSourceMapFiles2, computeBuildHash: computeBuildHash2, uploadSourceMaps: uploadSourceMaps2 } = await import("./source-map-uploader-VPDZWWM2.js");
4567
4547
  const files = await discoverSourceMapFiles2(distDir);
4568
4548
  if (files.length === 0) {
4569
4549
  console.info("[glasstrace] No source map files found. Skipping upload.");