@glasstrace/sdk 0.11.0 → 0.12.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 (48) hide show
  1. package/dist/adapters/drizzle.js +1 -1
  2. package/dist/{chunk-2JUH3VGJ.js → chunk-6GRNJ722.js} +38 -17
  3. package/dist/chunk-6GRNJ722.js.map +1 -0
  4. package/dist/chunk-IPGOKORJ.js +580 -0
  5. package/dist/chunk-IPGOKORJ.js.map +1 -0
  6. package/dist/{chunk-M7RDFOFR.js → chunk-LW7DPKBA.js} +2 -2
  7. package/dist/{chunk-SLSWEQCC.js → chunk-MSMOH6IH.js} +108 -38
  8. package/dist/chunk-MSMOH6IH.js.map +1 -0
  9. package/dist/chunk-NSBPE2FW.js +17 -0
  10. package/dist/{chunk-D3JC3LAK.js → chunk-OKIP4SRG.js} +2 -2
  11. package/dist/cli/init.cjs +454 -329
  12. package/dist/cli/init.cjs.map +1 -1
  13. package/dist/cli/init.d.cts +25 -1
  14. package/dist/cli/init.d.ts +25 -1
  15. package/dist/cli/init.js +114 -4
  16. package/dist/cli/init.js.map +1 -1
  17. package/dist/cli/mcp-add.cjs +60 -46
  18. package/dist/cli/mcp-add.cjs.map +1 -1
  19. package/dist/cli/mcp-add.js +3 -3
  20. package/dist/cli/uninit.js +15 -564
  21. package/dist/cli/uninit.js.map +1 -1
  22. package/dist/{esm-POMEQPKL.js → esm-KBPHCVB4.js} +2 -2
  23. package/dist/{getMachineId-bsd-TC3JSTY5.js → getMachineId-bsd-345PYXFX.js} +2 -2
  24. package/dist/{getMachineId-darwin-2SUKQCE6.js → getMachineId-darwin-5L2D25AD.js} +2 -2
  25. package/dist/{getMachineId-linux-PNAFHLXH.js → getMachineId-linux-KJR4P5HN.js} +2 -2
  26. package/dist/{getMachineId-unsupported-L2MNYW3W.js → getMachineId-unsupported-NDNXDYDY.js} +2 -2
  27. package/dist/{getMachineId-win-D6D42WOQ.js → getMachineId-win-T7PJNJXG.js} +2 -2
  28. package/dist/index.cjs +297 -154
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.d.cts +51 -10
  31. package/dist/index.d.ts +51 -10
  32. package/dist/index.js +133 -78
  33. package/dist/index.js.map +1 -1
  34. package/dist/{source-map-uploader-OFEM54UE.js → source-map-uploader-ZFCYOURS.js} +6 -4
  35. package/package.json +1 -1
  36. package/dist/chunk-2JUH3VGJ.js.map +0 -1
  37. package/dist/chunk-PZ5AY32C.js +0 -10
  38. package/dist/chunk-SLSWEQCC.js.map +0 -1
  39. /package/dist/{chunk-M7RDFOFR.js.map → chunk-LW7DPKBA.js.map} +0 -0
  40. /package/dist/{chunk-PZ5AY32C.js.map → chunk-NSBPE2FW.js.map} +0 -0
  41. /package/dist/{chunk-D3JC3LAK.js.map → chunk-OKIP4SRG.js.map} +0 -0
  42. /package/dist/{esm-POMEQPKL.js.map → esm-KBPHCVB4.js.map} +0 -0
  43. /package/dist/{getMachineId-bsd-TC3JSTY5.js.map → getMachineId-bsd-345PYXFX.js.map} +0 -0
  44. /package/dist/{getMachineId-darwin-2SUKQCE6.js.map → getMachineId-darwin-5L2D25AD.js.map} +0 -0
  45. /package/dist/{getMachineId-linux-PNAFHLXH.js.map → getMachineId-linux-KJR4P5HN.js.map} +0 -0
  46. /package/dist/{getMachineId-unsupported-L2MNYW3W.js.map → getMachineId-unsupported-NDNXDYDY.js.map} +0 -0
  47. /package/dist/{getMachineId-win-D6D42WOQ.js.map → getMachineId-win-T7PJNJXG.js.map} +0 -0
  48. /package/dist/{source-map-uploader-OFEM54UE.js.map → source-map-uploader-ZFCYOURS.js.map} +0 -0
package/dist/index.d.cts CHANGED
@@ -187,8 +187,9 @@ declare function isProductionDisabled(config: ResolvedConfig): boolean;
187
187
  declare function isAnonymousMode(config: ResolvedConfig): boolean;
188
188
 
189
189
  /**
190
- * Derives a deterministic session ID from the given inputs using SHA-256.
191
- * The hash is truncated to 16 hex characters and parsed through SessionIdSchema.
190
+ * Derives a deterministic session ID from the given inputs.
191
+ * Uses SHA-256 (truncated to 16 hex chars) when `node:crypto` is available,
192
+ * or a deterministic FNV-1a hash as a fallback in non-Node environments.
192
193
  *
193
194
  * @param apiKey - The project's API key (or anonymous placeholder).
194
195
  * @param origin - The origin string identifying the deployment environment.
@@ -253,6 +254,7 @@ declare function classifyFetchTarget(url: string): FetchTarget;
253
254
  * - The file does not exist
254
255
  * - The file content is invalid
255
256
  * - An I/O error occurs
257
+ * - `node:fs` is unavailable (non-Node environment)
256
258
  */
257
259
  declare function readAnonKey(projectRoot?: string): Promise<AnonApiKey | null>;
258
260
  /**
@@ -263,17 +265,20 @@ declare function readAnonKey(projectRoot?: string): Promise<AnonApiKey | null>;
263
265
  * - Writes the new key to `.glasstrace/anon_key`, creating the directory if needed
264
266
  * - On file write failure: logs a warning, caches an ephemeral in-memory key so
265
267
  * repeated calls in the same process return the same key
268
+ * - In non-Node environments: returns an ephemeral in-memory key
266
269
  */
267
270
  declare function getOrCreateAnonKey(projectRoot?: string): Promise<AnonApiKey>;
268
271
 
269
272
  /**
270
273
  * Reads and validates a cached config file from `.glasstrace/config`.
271
- * Returns the parsed `SdkInitResponse` or `null` on any failure.
274
+ * Returns the parsed `SdkInitResponse` or `null` on any failure,
275
+ * including when `node:fs` is unavailable (non-Node environments).
272
276
  */
273
277
  declare function loadCachedConfig(projectRoot?: string): SdkInitResponse | null;
274
278
  /**
275
279
  * Persists the init response to `.glasstrace/config`.
276
- * On failure, logs a warning and continues.
280
+ * Silently skipped when `node:fs` is unavailable (non-Node environments).
281
+ * On I/O failure, logs a warning and continues.
277
282
  */
278
283
  declare function saveCachedConfig(response: SdkInitResponse, projectRoot?: string): Promise<void>;
279
284
  /**
@@ -491,9 +496,29 @@ interface SourceMapEntry {
491
496
  filePath: string;
492
497
  content: string;
493
498
  }
499
+ /**
500
+ * Metadata for a discovered source map file, without its content loaded.
501
+ * Used by the streaming upload flow to defer file reads until upload time.
502
+ */
503
+ interface SourceMapFileInfo {
504
+ /** Relative path to the compiled JS file (`.map` extension stripped). */
505
+ filePath: string;
506
+ /** Absolute path on disk for reading the file content on demand. */
507
+ absolutePath: string;
508
+ /** File size in bytes. */
509
+ sizeBytes: number;
510
+ }
511
+ /**
512
+ * Recursively discovers all `.map` files in the given build directory.
513
+ * Returns metadata only — file content is NOT read into memory.
514
+ */
515
+ declare function discoverSourceMapFiles(buildDir: string): Promise<SourceMapFileInfo[]>;
494
516
  /**
495
517
  * Recursively finds all .map files in the given build directory.
496
518
  * Returns relative paths and file contents.
519
+ *
520
+ * @deprecated Prefer {@link discoverSourceMapFiles} to avoid loading all
521
+ * source maps into memory simultaneously.
497
522
  */
498
523
  declare function collectSourceMaps(buildDir: string): Promise<SourceMapEntry[]>;
499
524
  /**
@@ -503,15 +528,24 @@ declare function collectSourceMaps(buildDir: string): Promise<SourceMapEntry[]>;
503
528
  * On failure, falls back to a deterministic content hash:
504
529
  * sort source map file paths alphabetically, concatenate each as
505
530
  * `{relativePath}\n{fileLength}\n{fileContent}`, then SHA-256 the result.
531
+ *
532
+ * Accepts either `SourceMapEntry[]` (legacy, in-memory) or
533
+ * `SourceMapFileInfo[]` (streaming, reads on demand).
506
534
  */
507
- declare function computeBuildHash(maps?: SourceMapEntry[]): Promise<string>;
535
+ declare function computeBuildHash(maps?: SourceMapEntry[] | SourceMapFileInfo[]): Promise<string>;
508
536
  /**
509
537
  * Uploads source maps to the ingestion API.
510
538
  *
511
539
  * POSTs to `{endpoint}/v1/source-maps` with the API key, build hash,
512
540
  * and file entries. Validates the response against SourceMapUploadResponseSchema.
541
+ *
542
+ * Accepts either `SourceMapEntry[]` (legacy, in-memory) or
543
+ * `SourceMapFileInfo[]` (deferred reads). With `SourceMapFileInfo[]`,
544
+ * file content is read at upload time rather than at discovery time.
545
+ * Note: the legacy endpoint sends all files in a single JSON body, so
546
+ * peak memory is similar — the benefit is deferring reads past discovery.
513
547
  */
514
- declare function uploadSourceMaps(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[]): Promise<SourceMapUploadResponse>;
548
+ declare function uploadSourceMaps(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[] | SourceMapFileInfo[]): Promise<SourceMapUploadResponse>;
515
549
  /** Builds at or above this byte size route to the presigned upload flow. */
516
550
  declare const PRESIGNED_THRESHOLD_BYTES = 4500000;
517
551
  /** Signature for the blob upload function, injectable for testing. */
@@ -523,13 +557,17 @@ type BlobUploader = (clientToken: string, pathname: string, content: string) =>
523
557
  * Orchestrates the 3-phase presigned upload flow.
524
558
  *
525
559
  * 1. Requests presigned tokens for all source map files
526
- * 2. Uploads each file to blob storage with a concurrency limit of 5
560
+ * 2. Uploads each file to blob storage with a concurrency limit of 5,
561
+ * reading file content from disk just before each upload
527
562
  * 3. Submits the manifest to finalize the upload
528
563
  *
564
+ * Accepts either `SourceMapEntry[]` (legacy, in-memory) or
565
+ * `SourceMapFileInfo[]` (streaming, reads on demand).
566
+ *
529
567
  * Accepts an optional `blobUploader` for test injection; defaults to
530
568
  * {@link uploadToBlob}.
531
569
  */
532
- declare function uploadSourceMapsPresigned(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[], blobUploader?: BlobUploader): Promise<SourceMapManifestResponse>;
570
+ declare function uploadSourceMapsPresigned(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[] | SourceMapFileInfo[], blobUploader?: BlobUploader): Promise<SourceMapManifestResponse>;
533
571
  /**
534
572
  * Options for {@link uploadSourceMapsAuto}, primarily used for test injection.
535
573
  */
@@ -547,8 +585,11 @@ interface AutoUploadOptions {
547
585
  * - At or above the threshold: checks if `@vercel/blob` is available and
548
586
  * uses the presigned 3-phase flow. Falls back to legacy with a warning
549
587
  * if the package is not installed.
588
+ *
589
+ * Accepts either `SourceMapEntry[]` (legacy, in-memory) or
590
+ * `SourceMapFileInfo[]` (streaming, reads on demand).
550
591
  */
551
- declare function uploadSourceMapsAuto(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[], options?: AutoUploadOptions): Promise<SourceMapUploadResponse | SourceMapManifestResponse>;
592
+ declare function uploadSourceMapsAuto(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[] | SourceMapFileInfo[], options?: AutoUploadOptions): Promise<SourceMapUploadResponse | SourceMapManifestResponse>;
552
593
 
553
594
  /**
554
595
  * Manual error capture API.
@@ -611,4 +652,4 @@ declare function extractImports(fileContent: string): string[];
611
652
  */
612
653
  declare function buildImportGraph(projectRoot: string): Promise<ImportGraphPayload>;
613
654
 
614
- export { type AutoUploadOptions, type BlobUploader, type ClaimState, type FetchTarget, GlasstraceExporter, type GlasstraceExporterOptions, GlasstraceSpanProcessor, type InitClaimResult, PRESIGNED_THRESHOLD_BYTES, type ResolvedConfig, SdkError, SessionManager, type SourceMapEntry, buildImportGraph, captureError, classifyFetchTarget, collectSourceMaps, computeBuildHash, createDiscoveryHandler, deriveSessionId, discoverTestFiles, extractImports, getActiveConfig, getDateString, getDiscoveryHandler, getLinkedAccountId, getOrCreateAnonKey, getOrigin, isAnonymousMode, isProductionDisabled, loadCachedConfig, performInit, readAnonKey, readEnvVars, registerGlasstrace, resolveConfig, saveCachedConfig, sendInitRequest, uploadSourceMaps, uploadSourceMapsAuto, uploadSourceMapsPresigned, withGlasstraceConfig };
655
+ export { type AutoUploadOptions, type BlobUploader, type ClaimState, type FetchTarget, GlasstraceExporter, type GlasstraceExporterOptions, GlasstraceSpanProcessor, type InitClaimResult, PRESIGNED_THRESHOLD_BYTES, type ResolvedConfig, SdkError, SessionManager, type SourceMapEntry, type SourceMapFileInfo, buildImportGraph, captureError, classifyFetchTarget, collectSourceMaps, computeBuildHash, createDiscoveryHandler, deriveSessionId, discoverSourceMapFiles, discoverTestFiles, extractImports, getActiveConfig, getDateString, getDiscoveryHandler, getLinkedAccountId, getOrCreateAnonKey, getOrigin, isAnonymousMode, isProductionDisabled, loadCachedConfig, performInit, readAnonKey, readEnvVars, registerGlasstrace, resolveConfig, saveCachedConfig, sendInitRequest, uploadSourceMaps, uploadSourceMapsAuto, uploadSourceMapsPresigned, withGlasstraceConfig };
package/dist/index.d.ts CHANGED
@@ -187,8 +187,9 @@ declare function isProductionDisabled(config: ResolvedConfig): boolean;
187
187
  declare function isAnonymousMode(config: ResolvedConfig): boolean;
188
188
 
189
189
  /**
190
- * Derives a deterministic session ID from the given inputs using SHA-256.
191
- * The hash is truncated to 16 hex characters and parsed through SessionIdSchema.
190
+ * Derives a deterministic session ID from the given inputs.
191
+ * Uses SHA-256 (truncated to 16 hex chars) when `node:crypto` is available,
192
+ * or a deterministic FNV-1a hash as a fallback in non-Node environments.
192
193
  *
193
194
  * @param apiKey - The project's API key (or anonymous placeholder).
194
195
  * @param origin - The origin string identifying the deployment environment.
@@ -253,6 +254,7 @@ declare function classifyFetchTarget(url: string): FetchTarget;
253
254
  * - The file does not exist
254
255
  * - The file content is invalid
255
256
  * - An I/O error occurs
257
+ * - `node:fs` is unavailable (non-Node environment)
256
258
  */
257
259
  declare function readAnonKey(projectRoot?: string): Promise<AnonApiKey | null>;
258
260
  /**
@@ -263,17 +265,20 @@ declare function readAnonKey(projectRoot?: string): Promise<AnonApiKey | null>;
263
265
  * - Writes the new key to `.glasstrace/anon_key`, creating the directory if needed
264
266
  * - On file write failure: logs a warning, caches an ephemeral in-memory key so
265
267
  * repeated calls in the same process return the same key
268
+ * - In non-Node environments: returns an ephemeral in-memory key
266
269
  */
267
270
  declare function getOrCreateAnonKey(projectRoot?: string): Promise<AnonApiKey>;
268
271
 
269
272
  /**
270
273
  * Reads and validates a cached config file from `.glasstrace/config`.
271
- * Returns the parsed `SdkInitResponse` or `null` on any failure.
274
+ * Returns the parsed `SdkInitResponse` or `null` on any failure,
275
+ * including when `node:fs` is unavailable (non-Node environments).
272
276
  */
273
277
  declare function loadCachedConfig(projectRoot?: string): SdkInitResponse | null;
274
278
  /**
275
279
  * Persists the init response to `.glasstrace/config`.
276
- * On failure, logs a warning and continues.
280
+ * Silently skipped when `node:fs` is unavailable (non-Node environments).
281
+ * On I/O failure, logs a warning and continues.
277
282
  */
278
283
  declare function saveCachedConfig(response: SdkInitResponse, projectRoot?: string): Promise<void>;
279
284
  /**
@@ -491,9 +496,29 @@ interface SourceMapEntry {
491
496
  filePath: string;
492
497
  content: string;
493
498
  }
499
+ /**
500
+ * Metadata for a discovered source map file, without its content loaded.
501
+ * Used by the streaming upload flow to defer file reads until upload time.
502
+ */
503
+ interface SourceMapFileInfo {
504
+ /** Relative path to the compiled JS file (`.map` extension stripped). */
505
+ filePath: string;
506
+ /** Absolute path on disk for reading the file content on demand. */
507
+ absolutePath: string;
508
+ /** File size in bytes. */
509
+ sizeBytes: number;
510
+ }
511
+ /**
512
+ * Recursively discovers all `.map` files in the given build directory.
513
+ * Returns metadata only — file content is NOT read into memory.
514
+ */
515
+ declare function discoverSourceMapFiles(buildDir: string): Promise<SourceMapFileInfo[]>;
494
516
  /**
495
517
  * Recursively finds all .map files in the given build directory.
496
518
  * Returns relative paths and file contents.
519
+ *
520
+ * @deprecated Prefer {@link discoverSourceMapFiles} to avoid loading all
521
+ * source maps into memory simultaneously.
497
522
  */
498
523
  declare function collectSourceMaps(buildDir: string): Promise<SourceMapEntry[]>;
499
524
  /**
@@ -503,15 +528,24 @@ declare function collectSourceMaps(buildDir: string): Promise<SourceMapEntry[]>;
503
528
  * On failure, falls back to a deterministic content hash:
504
529
  * sort source map file paths alphabetically, concatenate each as
505
530
  * `{relativePath}\n{fileLength}\n{fileContent}`, then SHA-256 the result.
531
+ *
532
+ * Accepts either `SourceMapEntry[]` (legacy, in-memory) or
533
+ * `SourceMapFileInfo[]` (streaming, reads on demand).
506
534
  */
507
- declare function computeBuildHash(maps?: SourceMapEntry[]): Promise<string>;
535
+ declare function computeBuildHash(maps?: SourceMapEntry[] | SourceMapFileInfo[]): Promise<string>;
508
536
  /**
509
537
  * Uploads source maps to the ingestion API.
510
538
  *
511
539
  * POSTs to `{endpoint}/v1/source-maps` with the API key, build hash,
512
540
  * and file entries. Validates the response against SourceMapUploadResponseSchema.
541
+ *
542
+ * Accepts either `SourceMapEntry[]` (legacy, in-memory) or
543
+ * `SourceMapFileInfo[]` (deferred reads). With `SourceMapFileInfo[]`,
544
+ * file content is read at upload time rather than at discovery time.
545
+ * Note: the legacy endpoint sends all files in a single JSON body, so
546
+ * peak memory is similar — the benefit is deferring reads past discovery.
513
547
  */
514
- declare function uploadSourceMaps(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[]): Promise<SourceMapUploadResponse>;
548
+ declare function uploadSourceMaps(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[] | SourceMapFileInfo[]): Promise<SourceMapUploadResponse>;
515
549
  /** Builds at or above this byte size route to the presigned upload flow. */
516
550
  declare const PRESIGNED_THRESHOLD_BYTES = 4500000;
517
551
  /** Signature for the blob upload function, injectable for testing. */
@@ -523,13 +557,17 @@ type BlobUploader = (clientToken: string, pathname: string, content: string) =>
523
557
  * Orchestrates the 3-phase presigned upload flow.
524
558
  *
525
559
  * 1. Requests presigned tokens for all source map files
526
- * 2. Uploads each file to blob storage with a concurrency limit of 5
560
+ * 2. Uploads each file to blob storage with a concurrency limit of 5,
561
+ * reading file content from disk just before each upload
527
562
  * 3. Submits the manifest to finalize the upload
528
563
  *
564
+ * Accepts either `SourceMapEntry[]` (legacy, in-memory) or
565
+ * `SourceMapFileInfo[]` (streaming, reads on demand).
566
+ *
529
567
  * Accepts an optional `blobUploader` for test injection; defaults to
530
568
  * {@link uploadToBlob}.
531
569
  */
532
- declare function uploadSourceMapsPresigned(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[], blobUploader?: BlobUploader): Promise<SourceMapManifestResponse>;
570
+ declare function uploadSourceMapsPresigned(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[] | SourceMapFileInfo[], blobUploader?: BlobUploader): Promise<SourceMapManifestResponse>;
533
571
  /**
534
572
  * Options for {@link uploadSourceMapsAuto}, primarily used for test injection.
535
573
  */
@@ -547,8 +585,11 @@ interface AutoUploadOptions {
547
585
  * - At or above the threshold: checks if `@vercel/blob` is available and
548
586
  * uses the presigned 3-phase flow. Falls back to legacy with a warning
549
587
  * if the package is not installed.
588
+ *
589
+ * Accepts either `SourceMapEntry[]` (legacy, in-memory) or
590
+ * `SourceMapFileInfo[]` (streaming, reads on demand).
550
591
  */
551
- declare function uploadSourceMapsAuto(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[], options?: AutoUploadOptions): Promise<SourceMapUploadResponse | SourceMapManifestResponse>;
592
+ declare function uploadSourceMapsAuto(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[] | SourceMapFileInfo[], options?: AutoUploadOptions): Promise<SourceMapUploadResponse | SourceMapManifestResponse>;
552
593
 
553
594
  /**
554
595
  * Manual error capture API.
@@ -611,4 +652,4 @@ declare function extractImports(fileContent: string): string[];
611
652
  */
612
653
  declare function buildImportGraph(projectRoot: string): Promise<ImportGraphPayload>;
613
654
 
614
- export { type AutoUploadOptions, type BlobUploader, type ClaimState, type FetchTarget, GlasstraceExporter, type GlasstraceExporterOptions, GlasstraceSpanProcessor, type InitClaimResult, PRESIGNED_THRESHOLD_BYTES, type ResolvedConfig, SdkError, SessionManager, type SourceMapEntry, buildImportGraph, captureError, classifyFetchTarget, collectSourceMaps, computeBuildHash, createDiscoveryHandler, deriveSessionId, discoverTestFiles, extractImports, getActiveConfig, getDateString, getDiscoveryHandler, getLinkedAccountId, getOrCreateAnonKey, getOrigin, isAnonymousMode, isProductionDisabled, loadCachedConfig, performInit, readAnonKey, readEnvVars, registerGlasstrace, resolveConfig, saveCachedConfig, sendInitRequest, uploadSourceMaps, uploadSourceMapsAuto, uploadSourceMapsPresigned, withGlasstraceConfig };
655
+ export { type AutoUploadOptions, type BlobUploader, type ClaimState, type FetchTarget, GlasstraceExporter, type GlasstraceExporterOptions, GlasstraceSpanProcessor, type InitClaimResult, PRESIGNED_THRESHOLD_BYTES, type ResolvedConfig, SdkError, SessionManager, type SourceMapEntry, type SourceMapFileInfo, buildImportGraph, captureError, classifyFetchTarget, collectSourceMaps, computeBuildHash, createDiscoveryHandler, deriveSessionId, discoverSourceMapFiles, discoverTestFiles, extractImports, getActiveConfig, getDateString, getDiscoveryHandler, getLinkedAccountId, getOrCreateAnonKey, getOrigin, isAnonymousMode, isProductionDisabled, loadCachedConfig, performInit, readAnonKey, readEnvVars, registerGlasstrace, resolveConfig, saveCachedConfig, sendInitRequest, uploadSourceMaps, uploadSourceMapsAuto, uploadSourceMapsPresigned, withGlasstraceConfig };
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ import {
2
2
  PRESIGNED_THRESHOLD_BYTES,
3
3
  collectSourceMaps,
4
4
  computeBuildHash,
5
+ discoverSourceMapFiles,
5
6
  installConsoleCapture,
6
7
  isAnonymousMode,
7
8
  isProductionDisabled,
@@ -11,23 +12,23 @@ import {
11
12
  uploadSourceMaps,
12
13
  uploadSourceMapsAuto,
13
14
  uploadSourceMapsPresigned
14
- } from "./chunk-SLSWEQCC.js";
15
+ } from "./chunk-MSMOH6IH.js";
15
16
  import {
16
17
  buildImportGraph,
17
18
  discoverTestFiles,
18
19
  extractImports
19
- } from "./chunk-M7RDFOFR.js";
20
+ } from "./chunk-LW7DPKBA.js";
20
21
  import {
21
22
  getOrCreateAnonKey,
22
23
  readAnonKey
23
- } from "./chunk-2JUH3VGJ.js";
24
+ } from "./chunk-6GRNJ722.js";
24
25
  import {
25
26
  DEFAULT_CAPTURE_CONFIG,
26
27
  GLASSTRACE_ATTRIBUTE_NAMES,
27
28
  SdkCachedConfigSchema,
28
29
  SdkInitResponseSchema,
29
30
  SessionIdSchema
30
- } from "./chunk-D3JC3LAK.js";
31
+ } from "./chunk-OKIP4SRG.js";
31
32
  import {
32
33
  INVALID_SPAN_CONTEXT,
33
34
  SamplingDecision,
@@ -43,7 +44,9 @@ import {
43
44
  isValidTraceId,
44
45
  trace
45
46
  } from "./chunk-DQ25VOKK.js";
46
- import "./chunk-PZ5AY32C.js";
47
+ import {
48
+ __require
49
+ } from "./chunk-NSBPE2FW.js";
47
50
 
48
51
  // src/errors.ts
49
52
  var SdkError = class extends Error {
@@ -56,13 +59,36 @@ var SdkError = class extends Error {
56
59
  };
57
60
 
58
61
  // src/session.ts
59
- import { createHash } from "crypto";
60
62
  var FOUR_HOURS_MS = 4 * 60 * 60 * 1e3;
63
+ var hashFn = null;
64
+ function fnv1aHash(input) {
65
+ let hash = 2166136261;
66
+ for (let i = 0; i < input.length; i++) {
67
+ hash ^= input.charCodeAt(i);
68
+ hash = Math.imul(hash, 16777619);
69
+ hash >>>= 0;
70
+ }
71
+ return hash.toString(16).padStart(8, "0");
72
+ }
73
+ function getHashFn() {
74
+ if (hashFn) return hashFn;
75
+ try {
76
+ const { createHash } = __require("crypto");
77
+ hashFn = (input) => createHash("sha256").update(input).digest("hex").slice(0, 16);
78
+ } catch {
79
+ hashFn = (input) => {
80
+ const h1 = fnv1aHash(input);
81
+ const h2 = fnv1aHash(input + "\0");
82
+ return (h1 + h2).slice(0, 16);
83
+ };
84
+ }
85
+ return hashFn;
86
+ }
61
87
  var cachedGlasstraceEnv = process.env.GLASSTRACE_ENV;
62
88
  var cachedPort = process.env.PORT ?? "3000";
63
89
  function deriveSessionId(apiKey, origin, date, windowIndex) {
64
90
  const input = JSON.stringify([apiKey, origin, date, windowIndex]);
65
- const hash = createHash("sha256").update(input).digest("hex").slice(0, 16);
91
+ const hash = getHashFn()(input);
66
92
  return SessionIdSchema.parse(hash);
67
93
  }
68
94
  function getOrigin() {
@@ -148,21 +174,44 @@ function classifyFetchTarget(url) {
148
174
  }
149
175
 
150
176
  // src/init-client.ts
151
- import { readFileSync } from "fs";
152
- import { readFile, writeFile, mkdir, chmod } from "fs/promises";
153
- import { join } from "path";
154
177
  var GLASSTRACE_DIR = ".glasstrace";
155
178
  var CONFIG_FILE = "config";
156
179
  var TWENTY_FOUR_HOURS_MS = 24 * 60 * 60 * 1e3;
157
180
  var INIT_TIMEOUT_MS = 1e4;
181
+ var fsPathAsyncCache;
182
+ async function loadFsPathAsync() {
183
+ if (fsPathAsyncCache !== void 0) return fsPathAsyncCache;
184
+ try {
185
+ const [fs2, path2] = await Promise.all([
186
+ import("fs/promises"),
187
+ import("path")
188
+ ]);
189
+ fsPathAsyncCache = { fs: fs2, path: path2 };
190
+ return fsPathAsyncCache;
191
+ } catch {
192
+ fsPathAsyncCache = null;
193
+ return null;
194
+ }
195
+ }
196
+ function loadFsSyncOrNull() {
197
+ try {
198
+ const fs2 = __require("fs");
199
+ const path2 = __require("path");
200
+ return { readFileSync: fs2.readFileSync, join: path2.join };
201
+ } catch {
202
+ return null;
203
+ }
204
+ }
158
205
  var currentConfig = null;
159
206
  var configCacheChecked = false;
160
207
  var rateLimitBackoff = false;
161
208
  function loadCachedConfig(projectRoot) {
209
+ const modules = loadFsSyncOrNull();
210
+ if (!modules) return null;
162
211
  const root = projectRoot ?? process.cwd();
163
- const configPath = join(root, GLASSTRACE_DIR, CONFIG_FILE);
212
+ const configPath = modules.join(root, GLASSTRACE_DIR, CONFIG_FILE);
164
213
  try {
165
- const content = readFileSync(configPath, "utf-8");
214
+ const content = modules.readFileSync(configPath, "utf-8");
166
215
  const parsed = JSON.parse(content);
167
216
  const cached = SdkCachedConfigSchema.parse(parsed);
168
217
  const age = Date.now() - cached.cachedAt;
@@ -182,18 +231,20 @@ function loadCachedConfig(projectRoot) {
182
231
  }
183
232
  }
184
233
  async function saveCachedConfig(response, projectRoot) {
234
+ const modules = await loadFsPathAsync();
235
+ if (!modules) return;
185
236
  const root = projectRoot ?? process.cwd();
186
- const dirPath = join(root, GLASSTRACE_DIR);
187
- const configPath = join(dirPath, CONFIG_FILE);
237
+ const dirPath = modules.path.join(root, GLASSTRACE_DIR);
238
+ const configPath = modules.path.join(dirPath, CONFIG_FILE);
188
239
  try {
189
- await mkdir(dirPath, { recursive: true, mode: 448 });
190
- await chmod(dirPath, 448);
240
+ await modules.fs.mkdir(dirPath, { recursive: true, mode: 448 });
241
+ await modules.fs.chmod(dirPath, 448);
191
242
  const cached = {
192
243
  response,
193
244
  cachedAt: Date.now()
194
245
  };
195
- await writeFile(configPath, JSON.stringify(cached), { encoding: "utf-8", mode: 384 });
196
- await chmod(configPath, 384);
246
+ await modules.fs.writeFile(configPath, JSON.stringify(cached), { encoding: "utf-8", mode: 384 });
247
+ await modules.fs.chmod(configPath, 384);
197
248
  } catch (err) {
198
249
  console.warn(
199
250
  `[glasstrace] Failed to cache config to ${configPath}: ${err instanceof Error ? err.message : String(err)}`
@@ -247,69 +298,72 @@ async function sendInitRequest(config, anonKey, sdkVersion, importGraph, healthR
247
298
  return SdkInitResponseSchema.parse(body);
248
299
  }
249
300
  async function writeClaimedKey(newApiKey, projectRoot) {
250
- const root = projectRoot ?? process.cwd();
251
- const envLocalPath = join(root, ".env.local");
252
- let envLocalWritten = false;
253
- try {
254
- let content;
301
+ const modules = await loadFsPathAsync();
302
+ if (modules) {
303
+ const root = projectRoot ?? process.cwd();
304
+ const envLocalPath = modules.path.join(root, ".env.local");
305
+ let envLocalWritten = false;
255
306
  try {
256
- content = await readFile(envLocalPath, "utf-8");
257
- if (/^GLASSTRACE_API_KEY=.*/m.test(content)) {
258
- content = content.replace(
259
- /^GLASSTRACE_API_KEY=.*$/gm,
260
- `GLASSTRACE_API_KEY=${newApiKey}`
261
- );
262
- } else {
263
- if (content.length > 0 && !content.endsWith("\n")) {
264
- content += "\n";
307
+ let content;
308
+ try {
309
+ content = await modules.fs.readFile(envLocalPath, "utf-8");
310
+ if (/^GLASSTRACE_API_KEY=.*/m.test(content)) {
311
+ content = content.replace(
312
+ /^GLASSTRACE_API_KEY=.*$/gm,
313
+ `GLASSTRACE_API_KEY=${newApiKey}`
314
+ );
315
+ } else {
316
+ if (content.length > 0 && !content.endsWith("\n")) {
317
+ content += "\n";
318
+ }
319
+ content += `GLASSTRACE_API_KEY=${newApiKey}
320
+ `;
321
+ }
322
+ } catch (readErr) {
323
+ const code = readErr instanceof Error ? readErr.code : void 0;
324
+ if (code !== "ENOENT") {
325
+ throw readErr;
265
326
  }
266
- content += `GLASSTRACE_API_KEY=${newApiKey}
327
+ content = `GLASSTRACE_API_KEY=${newApiKey}
267
328
  `;
268
329
  }
269
- } catch (readErr) {
270
- const code = readErr instanceof Error ? readErr.code : void 0;
271
- if (code !== "ENOENT") {
272
- throw readErr;
330
+ await modules.fs.writeFile(envLocalPath, content, { encoding: "utf-8", mode: 384 });
331
+ await modules.fs.chmod(envLocalPath, 384);
332
+ envLocalWritten = true;
333
+ } catch {
334
+ }
335
+ if (envLocalWritten) {
336
+ try {
337
+ process.stderr.write(
338
+ "[glasstrace] Account claimed! API key written to .env.local. Restart your dev server to use it.\n"
339
+ );
340
+ } catch {
273
341
  }
274
- content = `GLASSTRACE_API_KEY=${newApiKey}
275
- `;
342
+ return;
276
343
  }
277
- await writeFile(envLocalPath, content, { encoding: "utf-8", mode: 384 });
278
- await chmod(envLocalPath, 384);
279
- envLocalWritten = true;
280
- } catch {
281
- }
282
- if (envLocalWritten) {
344
+ let claimedKeyWritten = false;
283
345
  try {
284
- process.stderr.write(
285
- "[glasstrace] Account claimed! API key written to .env.local. Restart your dev server to use it.\n"
286
- );
346
+ const dirPath = modules.path.join(root, GLASSTRACE_DIR);
347
+ await modules.fs.mkdir(dirPath, { recursive: true, mode: 448 });
348
+ await modules.fs.chmod(dirPath, 448);
349
+ const claimedKeyPath = modules.path.join(dirPath, "claimed-key");
350
+ await modules.fs.writeFile(claimedKeyPath, newApiKey, {
351
+ encoding: "utf-8",
352
+ mode: 384
353
+ });
354
+ await modules.fs.chmod(claimedKeyPath, 384);
355
+ claimedKeyWritten = true;
287
356
  } catch {
288
357
  }
289
- return;
290
- }
291
- let claimedKeyWritten = false;
292
- try {
293
- const dirPath = join(root, GLASSTRACE_DIR);
294
- await mkdir(dirPath, { recursive: true, mode: 448 });
295
- await chmod(dirPath, 448);
296
- const claimedKeyPath = join(dirPath, "claimed-key");
297
- await writeFile(claimedKeyPath, newApiKey, {
298
- encoding: "utf-8",
299
- mode: 384
300
- });
301
- await chmod(claimedKeyPath, 384);
302
- claimedKeyWritten = true;
303
- } catch {
304
- }
305
- if (claimedKeyWritten) {
306
- try {
307
- process.stderr.write(
308
- "[glasstrace] Account claimed! API key written to .glasstrace/claimed-key. Copy it to your .env.local file.\n"
309
- );
310
- } catch {
358
+ if (claimedKeyWritten) {
359
+ try {
360
+ process.stderr.write(
361
+ "[glasstrace] Account claimed! API key written to .glasstrace/claimed-key. Copy it to your .env.local file.\n"
362
+ );
363
+ } catch {
364
+ }
365
+ return;
311
366
  }
312
- return;
313
367
  }
314
368
  try {
315
369
  process.stderr.write(
@@ -3618,7 +3672,7 @@ async function backgroundInit(config, anonKeyForInit, generation) {
3618
3672
  if (config.verbose) {
3619
3673
  console.info("[glasstrace] Background init firing.");
3620
3674
  }
3621
- const initResult = await performInit(config, anonKeyForInit, "0.11.0");
3675
+ const initResult = await performInit(config, anonKeyForInit, "0.12.1");
3622
3676
  if (generation !== registrationGeneration) return;
3623
3677
  if (initResult?.claimResult) {
3624
3678
  setResolvedApiKey(initResult.claimResult.newApiKey);
@@ -3692,16 +3746,16 @@ async function handleSourceMapUpload(distDir) {
3692
3746
  );
3693
3747
  return;
3694
3748
  }
3695
- const { collectSourceMaps: collectSourceMaps2, computeBuildHash: computeBuildHash2, uploadSourceMaps: uploadSourceMaps2 } = await import("./source-map-uploader-OFEM54UE.js");
3696
- const maps = await collectSourceMaps2(distDir);
3697
- if (maps.length === 0) {
3749
+ const { discoverSourceMapFiles: discoverSourceMapFiles2, computeBuildHash: computeBuildHash2, uploadSourceMaps: uploadSourceMaps2 } = await import("./source-map-uploader-ZFCYOURS.js");
3750
+ const files = await discoverSourceMapFiles2(distDir);
3751
+ if (files.length === 0) {
3698
3752
  console.info("[glasstrace] No source map files found. Skipping upload.");
3699
3753
  return;
3700
3754
  }
3701
- const buildHash = await computeBuildHash2(maps);
3702
- await uploadSourceMaps2(apiKey, endpoint, buildHash, maps);
3755
+ const buildHash = await computeBuildHash2(files);
3756
+ await uploadSourceMaps2(apiKey, endpoint, buildHash, files);
3703
3757
  console.info(
3704
- `[glasstrace] Uploaded ${String(maps.length)} source map(s) for build ${buildHash}.`
3758
+ `[glasstrace] Uploaded ${String(files.length)} source map(s) for build ${buildHash}.`
3705
3759
  );
3706
3760
  } catch (error) {
3707
3761
  const message = error instanceof Error ? error.message : "Unknown error";
@@ -3743,6 +3797,7 @@ export {
3743
3797
  computeBuildHash,
3744
3798
  createDiscoveryHandler,
3745
3799
  deriveSessionId,
3800
+ discoverSourceMapFiles,
3746
3801
  discoverTestFiles,
3747
3802
  extractImports,
3748
3803
  getActiveConfig,