@glasstrace/sdk 1.15.1 → 1.17.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 (75) hide show
  1. package/README.md +118 -11
  2. package/dist/async-context/index.cjs +21 -2
  3. package/dist/async-context/index.cjs.map +1 -1
  4. package/dist/async-context/index.js +2 -2
  5. package/dist/{capture-error-03qDnC5v.d.cts → capture-error-B0txjNut.d.cts} +2 -2
  6. package/dist/{capture-error-CAfFUyIU.d.ts → capture-error-Dc01rYNR.d.ts} +2 -2
  7. package/dist/{chunk-ZIYT2Y4B.js → chunk-BJOZBAP7.js} +3 -3
  8. package/dist/{chunk-VMK2G6QR.js → chunk-CN5EP25B.js} +2 -2
  9. package/dist/{chunk-HMEHYSTS.js → chunk-EVX6D2TX.js} +2 -2
  10. package/dist/{chunk-T4ETJJSK.js → chunk-F2IPBTDJ.js} +133 -11
  11. package/dist/{chunk-T4ETJJSK.js.map → chunk-F2IPBTDJ.js.map} +1 -1
  12. package/dist/{chunk-XMD5OYD6.js → chunk-M3QGJUEI.js} +2 -2
  13. package/dist/{chunk-7LE2O4ZJ.js → chunk-MKT54VEH.js} +55 -6
  14. package/dist/{chunk-7LE2O4ZJ.js.map → chunk-MKT54VEH.js.map} +1 -1
  15. package/dist/{chunk-MP3QNDXQ.js → chunk-O7IJP2TQ.js} +2 -2
  16. package/dist/{chunk-F7A3QXCT.js → chunk-UOAG72NR.js} +2 -2
  17. package/dist/{chunk-6ST4QV7T.js → chunk-VEQX2YSQ.js} +3 -3
  18. package/dist/{chunk-LQZRGBN5.js → chunk-YKE6HJLW.js} +2 -2
  19. package/dist/cli/init.cjs +18 -5
  20. package/dist/cli/init.cjs.map +1 -1
  21. package/dist/cli/init.js +7 -7
  22. package/dist/cli/mcp-add.cjs +15 -2
  23. package/dist/cli/mcp-add.cjs.map +1 -1
  24. package/dist/cli/mcp-add.js +3 -3
  25. package/dist/cli/uninit.js +3 -3
  26. package/dist/cli/upgrade-instructions.cjs +1 -1
  27. package/dist/cli/upgrade-instructions.js +3 -3
  28. package/dist/cli/validate.cjs +14 -1
  29. package/dist/cli/validate.cjs.map +1 -1
  30. package/dist/cli/validate.js +2 -2
  31. package/dist/{correlation-id-YcfcqOru.d.ts → correlation-id-B9YYmoZw.d.ts} +1 -1
  32. package/dist/{correlation-id-CZ2bstzA.d.cts → correlation-id-CelUvw7j.d.cts} +1 -1
  33. package/dist/edge-entry.cjs +21 -2
  34. package/dist/edge-entry.cjs.map +1 -1
  35. package/dist/edge-entry.d.cts +2 -2
  36. package/dist/edge-entry.d.ts +2 -2
  37. package/dist/edge-entry.js +4 -4
  38. package/dist/import-graph-DBLGNjcI.d.cts +238 -0
  39. package/dist/import-graph-Dka_Fm7j.d.ts +238 -0
  40. package/dist/index.cjs +203 -12
  41. package/dist/index.cjs.map +1 -1
  42. package/dist/{index.d-BQIJ5Dvc.d.cts → index.d-3-cJoY8y.d.cts} +10 -2
  43. package/dist/{index.d-BQIJ5Dvc.d.ts → index.d-3-cJoY8y.d.ts} +10 -2
  44. package/dist/index.d.cts +102 -5
  45. package/dist/index.d.ts +102 -5
  46. package/dist/index.js +30 -5
  47. package/dist/index.js.map +1 -1
  48. package/dist/middleware/index.cjs +21 -2
  49. package/dist/middleware/index.cjs.map +1 -1
  50. package/dist/middleware/index.js +2 -2
  51. package/dist/node-entry.cjs +28 -8
  52. package/dist/node-entry.cjs.map +1 -1
  53. package/dist/node-entry.d.cts +4 -4
  54. package/dist/node-entry.d.ts +4 -4
  55. package/dist/node-entry.js +7 -7
  56. package/dist/node-subpath.cjs +27 -1
  57. package/dist/node-subpath.cjs.map +1 -1
  58. package/dist/node-subpath.d.cts +51 -235
  59. package/dist/node-subpath.d.ts +51 -235
  60. package/dist/node-subpath.js +16 -3
  61. package/dist/node-subpath.js.map +1 -1
  62. package/dist/{source-map-uploader-NUONOEJG.js → source-map-uploader-U7SLSKIZ.js} +3 -3
  63. package/dist/trpc/index.cjs +21 -2
  64. package/dist/trpc/index.cjs.map +1 -1
  65. package/dist/trpc/index.js +1 -1
  66. package/package.json +1 -1
  67. /package/dist/{chunk-ZIYT2Y4B.js.map → chunk-BJOZBAP7.js.map} +0 -0
  68. /package/dist/{chunk-VMK2G6QR.js.map → chunk-CN5EP25B.js.map} +0 -0
  69. /package/dist/{chunk-HMEHYSTS.js.map → chunk-EVX6D2TX.js.map} +0 -0
  70. /package/dist/{chunk-XMD5OYD6.js.map → chunk-M3QGJUEI.js.map} +0 -0
  71. /package/dist/{chunk-MP3QNDXQ.js.map → chunk-O7IJP2TQ.js.map} +0 -0
  72. /package/dist/{chunk-F7A3QXCT.js.map → chunk-UOAG72NR.js.map} +0 -0
  73. /package/dist/{chunk-6ST4QV7T.js.map → chunk-VEQX2YSQ.js.map} +0 -0
  74. /package/dist/{chunk-LQZRGBN5.js.map → chunk-YKE6HJLW.js.map} +0 -0
  75. /package/dist/{source-map-uploader-NUONOEJG.js.map → source-map-uploader-U7SLSKIZ.js.map} +0 -0
@@ -1,239 +1,55 @@
1
- import { m as SourceMapUploadResponse, n as SourceMapManifestResponse, I as ImportGraphPayload } from './index.d-BQIJ5Dvc.cjs';
1
+ export { A as AutoUploadOptions, B as BlobUploader, P as PRESIGNED_THRESHOLD_BYTES, S as SourceMapEntry, a as SourceMapFileInfo, b as buildImportGraph, c as collectSourceMaps, d as computeBuildHash, e as discoverSourceMapFiles, f as discoverTestFiles, g as extractImports, u as uploadSourceMaps, h as uploadSourceMapsAuto, i as uploadSourceMapsPresigned } from './import-graph-DBLGNjcI.cjs';
2
+ import './index.d-3-cJoY8y.cjs';
2
3
  import './v4/classic/external.cjs';
3
4
 
4
5
  /**
5
- * In-memory source map entry: a file path paired with its full text content.
6
- *
7
- * @remarks
8
- * Node-only. Describes the legacy in-memory shape consumed by
9
- * {@link uploadSourceMaps} and {@link uploadSourceMapsAuto}. The type
10
- * itself erases at runtime and is safe to import from edge code, but
11
- * every function that produces or consumes it depends on `node:fs`
12
- * and cannot run at the edge.
13
- */
14
- interface SourceMapEntry {
15
- filePath: string;
16
- content: string;
17
- }
18
- /**
19
- * Metadata for a discovered source map file, without its content loaded.
20
- * Used by the streaming upload flow to defer file reads until upload time.
21
- *
22
- * @remarks
23
- * Node-only. Describes the shape of data produced by the Node-only
24
- * source-map upload flow ({@link discoverSourceMapFiles},
25
- * {@link uploadSourceMapsAuto}). The type itself erases at runtime and
26
- * is safe to import from edge code, but every function that produces
27
- * or consumes it depends on `node:fs`/`node:path` and cannot run at
28
- * the edge.
29
- */
30
- interface SourceMapFileInfo {
31
- /** Relative path to the compiled JS file (`.map` extension stripped). */
32
- filePath: string;
33
- /** Absolute path on disk for reading the file content on demand. */
34
- absolutePath: string;
35
- /** File size in bytes. */
36
- sizeBytes: number;
37
- }
38
- /**
39
- * Recursively discovers all `.map` files in the given build directory.
40
- * Returns metadata only file content is NOT read into memory.
41
- *
42
- * @remarks
43
- * Node-only. Walks the filesystem with `node:fs/promises` (`readdir`,
44
- * `stat`) and resolves paths with `node:path`. No edge-safe
45
- * alternative — call from a Node context (build script, Next.js
46
- * `next.config.ts`, CI job).
47
- */
48
- declare function discoverSourceMapFiles(buildDir: string): Promise<SourceMapFileInfo[]>;
49
- /**
50
- * Recursively finds all .map files in the given build directory.
51
- * Returns relative paths and file contents.
52
- *
53
- * @deprecated Prefer {@link discoverSourceMapFiles} to avoid loading all
54
- * source maps into memory simultaneously.
55
- *
56
- * @remarks
57
- * Node-only. Reads every discovered `.map` file into memory via
58
- * `node:fs/promises` (`readFile`). No edge-safe alternative — call
59
- * from a Node context (build script, Next.js `next.config.ts`, CI job).
60
- */
61
- declare function collectSourceMaps(buildDir: string): Promise<SourceMapEntry[]>;
62
- /**
63
- * Computes a build hash for source map uploads.
64
- *
65
- * First tries `git rev-parse HEAD` to get the git commit SHA.
66
- * On failure, falls back to a deterministic content hash:
67
- * sort source map file paths alphabetically, concatenate each as
68
- * `{relativePath}\n{fileLength}\n{fileContent}`, then SHA-256 the result.
69
- *
70
- * Accepts either `SourceMapEntry[]` (legacy, in-memory) or
71
- * `SourceMapFileInfo[]` (streaming, reads on demand).
72
- *
73
- * @remarks
74
- * Node-only. Spawns `git rev-parse HEAD` via `node:child_process`
75
- * (`execFileSync`), hashes with `node:crypto` (`createHash("sha256")`),
76
- * and reads map contents from disk with `node:fs/promises`. No
77
- * edge-safe alternative — call from a Node context (build script,
78
- * Next.js `next.config.ts`, CI job). If a pre-computed build hash is
79
- * already known (e.g., provided as a CI environment variable), pass
80
- * it directly to {@link uploadSourceMaps} instead of calling this
81
- * helper.
82
- */
83
- declare function computeBuildHash(maps?: SourceMapEntry[] | SourceMapFileInfo[]): Promise<string>;
84
- /**
85
- * Uploads source maps to the ingestion API.
86
- *
87
- * POSTs to `{endpoint}/v1/source-maps` with the API key, build hash,
88
- * and file entries. Validates the response against SourceMapUploadResponseSchema.
89
- *
90
- * Accepts either `SourceMapEntry[]` (legacy, in-memory) or
91
- * `SourceMapFileInfo[]` (deferred reads). With `SourceMapFileInfo[]`,
92
- * file content is read at upload time rather than at discovery time.
93
- * Note: the legacy endpoint sends all files in a single JSON body, so
94
- * peak memory is similar — the benefit is deferring reads past discovery.
95
- *
96
- * @remarks
97
- * Node-only. Reads map contents from disk via `node:fs/promises` when
98
- * invoked with `SourceMapFileInfo[]`. The network call uses the
99
- * platform-standard `fetch` (edge-safe on its own), but the upstream
100
- * discovery and read path is Node-only, so the function is only
101
- * reachable from a Node context (build script, Next.js
102
- * `next.config.ts`, CI job). No edge-safe alternative.
103
- */
104
- declare function uploadSourceMaps(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[] | SourceMapFileInfo[]): Promise<SourceMapUploadResponse>;
105
- /**
106
- * Builds at or above this byte size route to the presigned upload flow.
107
- *
108
- * @remarks
109
- * Node-only. The numeric value itself is pure (a constant is evaluable
110
- * anywhere), but it is meaningful only alongside
111
- * {@link uploadSourceMapsPresigned} and {@link uploadSourceMapsAuto},
112
- * both of which depend on `node:fs` and `@vercel/blob`. No edge-safe
113
- * alternative — consume from a Node context.
114
- */
115
- declare const PRESIGNED_THRESHOLD_BYTES = 4500000;
116
- /**
117
- * Signature for the blob upload function, injectable for testing.
118
- *
119
- * @remarks
120
- * Node-only. Describes the shape of the uploader consumed by
121
- * {@link uploadSourceMapsPresigned} and {@link uploadSourceMapsAuto},
122
- * both of which depend on `@vercel/blob` and `node:fs`. The type itself
123
- * erases at runtime and is safe to import from edge code, but every
124
- * producer and consumer is Node-only.
125
- */
126
- type BlobUploader = (clientToken: string, pathname: string, content: string) => Promise<{
127
- url: string;
128
- size: number;
129
- }>;
130
- /**
131
- * Orchestrates the 3-phase presigned upload flow.
132
- *
133
- * 1. Requests presigned tokens for all source map files
134
- * 2. Uploads each file to blob storage with a concurrency limit of 5,
135
- * reading file content from disk just before each upload
136
- * 3. Submits the manifest to finalize the upload
137
- *
138
- * Accepts either `SourceMapEntry[]` (legacy, in-memory) or
139
- * `SourceMapFileInfo[]` (streaming, reads on demand).
140
- *
141
- * Accepts an optional `blobUploader` for test injection; defaults to
142
- * {@link uploadToBlob}.
143
- *
144
- * @remarks
145
- * Node-only. Streams map contents from disk via `node:fs/promises`
146
- * and uploads through `@vercel/blob/client` (loaded lazily as an
147
- * optional peer dependency). No edge-safe alternative — call from a
148
- * Node context (build script, Next.js `next.config.ts`, CI job).
149
- */
150
- declare function uploadSourceMapsPresigned(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[] | SourceMapFileInfo[], blobUploader?: BlobUploader): Promise<SourceMapManifestResponse>;
151
- /**
152
- * Options for {@link uploadSourceMapsAuto}, primarily used for test injection.
153
- *
154
- * @remarks
155
- * Node-only. Describes the shape of overrides consumed by
156
- * {@link uploadSourceMapsAuto}, which depends on `node:fs` and
157
- * `@vercel/blob`. The type itself erases at runtime and is safe to
158
- * import from edge code, but the surrounding function is Node-only.
159
- */
160
- interface AutoUploadOptions {
161
- /** Override blob availability check (for testing). */
162
- checkBlobAvailable?: () => Promise<boolean>;
163
- /** Override blob uploader (for testing). */
164
- blobUploader?: BlobUploader;
165
- }
166
- /**
167
- * Automatically routes source map uploads based on total build size.
168
- *
169
- * - Below {@link PRESIGNED_THRESHOLD_BYTES}: uses the legacy single-request
170
- * {@link uploadSourceMaps} endpoint.
171
- * - At or above the threshold: checks if `@vercel/blob` is available and
172
- * uses the presigned 3-phase flow. Falls back to legacy with a warning
173
- * if the package is not installed.
174
- *
175
- * Accepts either `SourceMapEntry[]` (legacy, in-memory) or
176
- * `SourceMapFileInfo[]` (streaming, reads on demand).
177
- *
178
- * @remarks
179
- * Node-only. Reads source map sizes/contents via `node:fs/promises`
180
- * and, above the threshold, dynamically loads `@vercel/blob/client`
181
- * (optional peer dependency) for direct blob storage uploads. No
182
- * edge-safe alternative — call from a Node context (build script,
183
- * Next.js `next.config.ts`, CI job). This is the recommended entry
184
- * point for source-map upload in most projects.
185
- */
186
- declare function uploadSourceMapsAuto(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[] | SourceMapFileInfo[], options?: AutoUploadOptions): Promise<SourceMapUploadResponse | SourceMapManifestResponse>;
187
-
188
- /**
189
- * Discovers test files by scanning the project directory for conventional
190
- * test file patterns. Also reads vitest/jest config files for custom include
191
- * patterns and merges them with the defaults. Excludes node_modules/ and .next/.
192
- *
193
- * @param projectRoot - Absolute path to the project root directory.
194
- * @returns Relative POSIX paths from projectRoot, capped at {@link MAX_TEST_FILES}.
195
- *
196
- * @remarks
197
- * Node-only. Walks the filesystem with `node:fs/promises`
198
- * (`readdir`), reads vitest/jest config files with `node:fs`
199
- * (`readFileSync`), and resolves paths with `node:path`. No edge-safe
200
- * alternative — call from a Node context (build script, CI job,
201
- * Next.js `next.config.ts`).
202
- */
203
- declare function discoverTestFiles(projectRoot: string): Promise<string[]>;
204
- /**
205
- * Extracts import paths from file content using regex.
206
- * Handles ES module imports, CommonJS requires, and dynamic imports.
207
- *
208
- * @param fileContent - The full text content of a TypeScript/JavaScript file.
209
- * @returns An array of import path strings as written in the source (e.g. "./foo", "react").
210
- *
211
- * @remarks
212
- * Node-only. The function body itself is pure string processing and
213
- * would run anywhere, but it is exported through `@glasstrace/sdk/node`
214
- * alongside {@link discoverTestFiles} and {@link buildImportGraph} —
215
- * the practical consumers all pair it with those Node-only helpers.
216
- * Kept under the `/node` subpath for API cohesion; call from a Node
217
- * context (build script, CI job, Next.js `next.config.ts`).
218
- */
219
- declare function extractImports(fileContent: string): string[];
220
- /**
221
- * Builds an import graph mapping test file paths to their imported module paths.
222
- *
223
- * Discovers test files, reads each, extracts imports, and builds a graph.
224
- * Computes a deterministic buildHash from the serialized graph content.
225
- * Individual file read failures are silently skipped.
226
- *
227
- * @param projectRoot - Absolute path to the project root directory.
228
- * @returns An {@link ImportGraphPayload} containing the graph and a deterministic buildHash.
229
- *
230
- * @remarks
231
- * Node-only. Walks the project with `node:fs/promises`, reads each
232
- * test file from disk, resolves paths with `node:path`, and hashes
233
- * the serialized graph with `node:crypto` (`createHash("sha256")`).
234
- * No edge-safe alternative — call from a Node context (build script,
235
- * CI job, Next.js `next.config.ts`).
236
- */
237
- declare function buildImportGraph(projectRoot: string): Promise<ImportGraphPayload>;
6
+ * Producer-side identifier pseudonymization for the value-fidelity
7
+ * scalar channel.
8
+ *
9
+ * `hashId` turns a raw identifier into a stable, opaque `gthid_<hex>`
10
+ * token that a producer can emit on an `*Id` scalar without leaking the
11
+ * raw value. The SDK's `checkScalarField` rejects unhashed `*Id` values
12
+ * under `strict`, so a producer that wants id correlation pre-hashes the
13
+ * id with this helper.
14
+ *
15
+ * NODE-ONLY. This module imports `node:crypto` and is therefore exported
16
+ * exclusively from the `@glasstrace/sdk/node` subpath, never the root
17
+ * barrel — the root must stay edge-bundle-safe (no node builtins in the
18
+ * edge closure). `*Id` capture is a server-side concern, so the
19
+ * node-only placement does not reduce real coverage.
20
+ */
21
+ /**
22
+ * Pseudonymize a raw identifier into a stable `gthid_<hex>` token using
23
+ * HMAC-SHA256 keyed by `key`.
24
+ *
25
+ * Node-only. Uses `node:crypto`, so it ships exclusively on the
26
+ * `@glasstrace/sdk/node` subpath.
27
+ *
28
+ * Fail-closed: returns `null` when `raw` or `key` is missing or empty,
29
+ * so a misconfigured caller emits no id rather than a raw or weakly
30
+ * keyed one. A `null` return routes the `*Id` scalar to the
31
+ * `unhashed_id` omission counter at emit time.
32
+ *
33
+ * The same `(raw, key)` always produces the same token, enabling
34
+ * cross-trace correlation of the same entity. This is also the privacy
35
+ * boundary's weak point:
36
+ *
37
+ * - **Key rotation breaks correlation by design.** Tokens hashed under
38
+ * a new key do not match tokens hashed under the old one. If
39
+ * cross-rotation correlation is required, embed a key-id segment in
40
+ * the key-management layer and rotate deliberately.
41
+ * - **A leaked key de-pseudonymizes every id hashed under it** (an
42
+ * attacker can hash a candidate id space and match tokens). Treat the
43
+ * key as a secret; scope it per tenant.
44
+ * - **Stable tokens plus quasi-identifier scalars enable corpus-level
45
+ * re-identification / linkage**, bounded by per-tenant scope. Do not
46
+ * treat a `gthid_` token as anonymization.
47
+ *
48
+ * @param raw - The raw identifier to pseudonymize.
49
+ * @param key - The per-tenant HMAC secret (e.g. from
50
+ * `GLASSTRACE_ATTR_HMAC_KEY`). Never logged or emitted.
51
+ * @returns A `gthid_<32hex>` token, or `null` if `raw`/`key` is empty.
52
+ */
53
+ declare function hashId(raw: string, key: string): string | null;
238
54
 
239
- export { type AutoUploadOptions, type BlobUploader, PRESIGNED_THRESHOLD_BYTES, type SourceMapEntry, type SourceMapFileInfo, buildImportGraph, collectSourceMaps, computeBuildHash, discoverSourceMapFiles, discoverTestFiles, extractImports, uploadSourceMaps, uploadSourceMapsAuto, uploadSourceMapsPresigned };
55
+ export { hashId };
@@ -1,239 +1,55 @@
1
- import { m as SourceMapUploadResponse, n as SourceMapManifestResponse, I as ImportGraphPayload } from './index.d-BQIJ5Dvc.js';
1
+ export { A as AutoUploadOptions, B as BlobUploader, P as PRESIGNED_THRESHOLD_BYTES, S as SourceMapEntry, a as SourceMapFileInfo, b as buildImportGraph, c as collectSourceMaps, d as computeBuildHash, e as discoverSourceMapFiles, f as discoverTestFiles, g as extractImports, u as uploadSourceMaps, h as uploadSourceMapsAuto, i as uploadSourceMapsPresigned } from './import-graph-Dka_Fm7j.js';
2
+ import './index.d-3-cJoY8y.js';
2
3
  import './v4/classic/external.cjs';
3
4
 
4
5
  /**
5
- * In-memory source map entry: a file path paired with its full text content.
6
- *
7
- * @remarks
8
- * Node-only. Describes the legacy in-memory shape consumed by
9
- * {@link uploadSourceMaps} and {@link uploadSourceMapsAuto}. The type
10
- * itself erases at runtime and is safe to import from edge code, but
11
- * every function that produces or consumes it depends on `node:fs`
12
- * and cannot run at the edge.
13
- */
14
- interface SourceMapEntry {
15
- filePath: string;
16
- content: string;
17
- }
18
- /**
19
- * Metadata for a discovered source map file, without its content loaded.
20
- * Used by the streaming upload flow to defer file reads until upload time.
21
- *
22
- * @remarks
23
- * Node-only. Describes the shape of data produced by the Node-only
24
- * source-map upload flow ({@link discoverSourceMapFiles},
25
- * {@link uploadSourceMapsAuto}). The type itself erases at runtime and
26
- * is safe to import from edge code, but every function that produces
27
- * or consumes it depends on `node:fs`/`node:path` and cannot run at
28
- * the edge.
29
- */
30
- interface SourceMapFileInfo {
31
- /** Relative path to the compiled JS file (`.map` extension stripped). */
32
- filePath: string;
33
- /** Absolute path on disk for reading the file content on demand. */
34
- absolutePath: string;
35
- /** File size in bytes. */
36
- sizeBytes: number;
37
- }
38
- /**
39
- * Recursively discovers all `.map` files in the given build directory.
40
- * Returns metadata only file content is NOT read into memory.
41
- *
42
- * @remarks
43
- * Node-only. Walks the filesystem with `node:fs/promises` (`readdir`,
44
- * `stat`) and resolves paths with `node:path`. No edge-safe
45
- * alternative — call from a Node context (build script, Next.js
46
- * `next.config.ts`, CI job).
47
- */
48
- declare function discoverSourceMapFiles(buildDir: string): Promise<SourceMapFileInfo[]>;
49
- /**
50
- * Recursively finds all .map files in the given build directory.
51
- * Returns relative paths and file contents.
52
- *
53
- * @deprecated Prefer {@link discoverSourceMapFiles} to avoid loading all
54
- * source maps into memory simultaneously.
55
- *
56
- * @remarks
57
- * Node-only. Reads every discovered `.map` file into memory via
58
- * `node:fs/promises` (`readFile`). No edge-safe alternative — call
59
- * from a Node context (build script, Next.js `next.config.ts`, CI job).
60
- */
61
- declare function collectSourceMaps(buildDir: string): Promise<SourceMapEntry[]>;
62
- /**
63
- * Computes a build hash for source map uploads.
64
- *
65
- * First tries `git rev-parse HEAD` to get the git commit SHA.
66
- * On failure, falls back to a deterministic content hash:
67
- * sort source map file paths alphabetically, concatenate each as
68
- * `{relativePath}\n{fileLength}\n{fileContent}`, then SHA-256 the result.
69
- *
70
- * Accepts either `SourceMapEntry[]` (legacy, in-memory) or
71
- * `SourceMapFileInfo[]` (streaming, reads on demand).
72
- *
73
- * @remarks
74
- * Node-only. Spawns `git rev-parse HEAD` via `node:child_process`
75
- * (`execFileSync`), hashes with `node:crypto` (`createHash("sha256")`),
76
- * and reads map contents from disk with `node:fs/promises`. No
77
- * edge-safe alternative — call from a Node context (build script,
78
- * Next.js `next.config.ts`, CI job). If a pre-computed build hash is
79
- * already known (e.g., provided as a CI environment variable), pass
80
- * it directly to {@link uploadSourceMaps} instead of calling this
81
- * helper.
82
- */
83
- declare function computeBuildHash(maps?: SourceMapEntry[] | SourceMapFileInfo[]): Promise<string>;
84
- /**
85
- * Uploads source maps to the ingestion API.
86
- *
87
- * POSTs to `{endpoint}/v1/source-maps` with the API key, build hash,
88
- * and file entries. Validates the response against SourceMapUploadResponseSchema.
89
- *
90
- * Accepts either `SourceMapEntry[]` (legacy, in-memory) or
91
- * `SourceMapFileInfo[]` (deferred reads). With `SourceMapFileInfo[]`,
92
- * file content is read at upload time rather than at discovery time.
93
- * Note: the legacy endpoint sends all files in a single JSON body, so
94
- * peak memory is similar — the benefit is deferring reads past discovery.
95
- *
96
- * @remarks
97
- * Node-only. Reads map contents from disk via `node:fs/promises` when
98
- * invoked with `SourceMapFileInfo[]`. The network call uses the
99
- * platform-standard `fetch` (edge-safe on its own), but the upstream
100
- * discovery and read path is Node-only, so the function is only
101
- * reachable from a Node context (build script, Next.js
102
- * `next.config.ts`, CI job). No edge-safe alternative.
103
- */
104
- declare function uploadSourceMaps(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[] | SourceMapFileInfo[]): Promise<SourceMapUploadResponse>;
105
- /**
106
- * Builds at or above this byte size route to the presigned upload flow.
107
- *
108
- * @remarks
109
- * Node-only. The numeric value itself is pure (a constant is evaluable
110
- * anywhere), but it is meaningful only alongside
111
- * {@link uploadSourceMapsPresigned} and {@link uploadSourceMapsAuto},
112
- * both of which depend on `node:fs` and `@vercel/blob`. No edge-safe
113
- * alternative — consume from a Node context.
114
- */
115
- declare const PRESIGNED_THRESHOLD_BYTES = 4500000;
116
- /**
117
- * Signature for the blob upload function, injectable for testing.
118
- *
119
- * @remarks
120
- * Node-only. Describes the shape of the uploader consumed by
121
- * {@link uploadSourceMapsPresigned} and {@link uploadSourceMapsAuto},
122
- * both of which depend on `@vercel/blob` and `node:fs`. The type itself
123
- * erases at runtime and is safe to import from edge code, but every
124
- * producer and consumer is Node-only.
125
- */
126
- type BlobUploader = (clientToken: string, pathname: string, content: string) => Promise<{
127
- url: string;
128
- size: number;
129
- }>;
130
- /**
131
- * Orchestrates the 3-phase presigned upload flow.
132
- *
133
- * 1. Requests presigned tokens for all source map files
134
- * 2. Uploads each file to blob storage with a concurrency limit of 5,
135
- * reading file content from disk just before each upload
136
- * 3. Submits the manifest to finalize the upload
137
- *
138
- * Accepts either `SourceMapEntry[]` (legacy, in-memory) or
139
- * `SourceMapFileInfo[]` (streaming, reads on demand).
140
- *
141
- * Accepts an optional `blobUploader` for test injection; defaults to
142
- * {@link uploadToBlob}.
143
- *
144
- * @remarks
145
- * Node-only. Streams map contents from disk via `node:fs/promises`
146
- * and uploads through `@vercel/blob/client` (loaded lazily as an
147
- * optional peer dependency). No edge-safe alternative — call from a
148
- * Node context (build script, Next.js `next.config.ts`, CI job).
149
- */
150
- declare function uploadSourceMapsPresigned(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[] | SourceMapFileInfo[], blobUploader?: BlobUploader): Promise<SourceMapManifestResponse>;
151
- /**
152
- * Options for {@link uploadSourceMapsAuto}, primarily used for test injection.
153
- *
154
- * @remarks
155
- * Node-only. Describes the shape of overrides consumed by
156
- * {@link uploadSourceMapsAuto}, which depends on `node:fs` and
157
- * `@vercel/blob`. The type itself erases at runtime and is safe to
158
- * import from edge code, but the surrounding function is Node-only.
159
- */
160
- interface AutoUploadOptions {
161
- /** Override blob availability check (for testing). */
162
- checkBlobAvailable?: () => Promise<boolean>;
163
- /** Override blob uploader (for testing). */
164
- blobUploader?: BlobUploader;
165
- }
166
- /**
167
- * Automatically routes source map uploads based on total build size.
168
- *
169
- * - Below {@link PRESIGNED_THRESHOLD_BYTES}: uses the legacy single-request
170
- * {@link uploadSourceMaps} endpoint.
171
- * - At or above the threshold: checks if `@vercel/blob` is available and
172
- * uses the presigned 3-phase flow. Falls back to legacy with a warning
173
- * if the package is not installed.
174
- *
175
- * Accepts either `SourceMapEntry[]` (legacy, in-memory) or
176
- * `SourceMapFileInfo[]` (streaming, reads on demand).
177
- *
178
- * @remarks
179
- * Node-only. Reads source map sizes/contents via `node:fs/promises`
180
- * and, above the threshold, dynamically loads `@vercel/blob/client`
181
- * (optional peer dependency) for direct blob storage uploads. No
182
- * edge-safe alternative — call from a Node context (build script,
183
- * Next.js `next.config.ts`, CI job). This is the recommended entry
184
- * point for source-map upload in most projects.
185
- */
186
- declare function uploadSourceMapsAuto(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[] | SourceMapFileInfo[], options?: AutoUploadOptions): Promise<SourceMapUploadResponse | SourceMapManifestResponse>;
187
-
188
- /**
189
- * Discovers test files by scanning the project directory for conventional
190
- * test file patterns. Also reads vitest/jest config files for custom include
191
- * patterns and merges them with the defaults. Excludes node_modules/ and .next/.
192
- *
193
- * @param projectRoot - Absolute path to the project root directory.
194
- * @returns Relative POSIX paths from projectRoot, capped at {@link MAX_TEST_FILES}.
195
- *
196
- * @remarks
197
- * Node-only. Walks the filesystem with `node:fs/promises`
198
- * (`readdir`), reads vitest/jest config files with `node:fs`
199
- * (`readFileSync`), and resolves paths with `node:path`. No edge-safe
200
- * alternative — call from a Node context (build script, CI job,
201
- * Next.js `next.config.ts`).
202
- */
203
- declare function discoverTestFiles(projectRoot: string): Promise<string[]>;
204
- /**
205
- * Extracts import paths from file content using regex.
206
- * Handles ES module imports, CommonJS requires, and dynamic imports.
207
- *
208
- * @param fileContent - The full text content of a TypeScript/JavaScript file.
209
- * @returns An array of import path strings as written in the source (e.g. "./foo", "react").
210
- *
211
- * @remarks
212
- * Node-only. The function body itself is pure string processing and
213
- * would run anywhere, but it is exported through `@glasstrace/sdk/node`
214
- * alongside {@link discoverTestFiles} and {@link buildImportGraph} —
215
- * the practical consumers all pair it with those Node-only helpers.
216
- * Kept under the `/node` subpath for API cohesion; call from a Node
217
- * context (build script, CI job, Next.js `next.config.ts`).
218
- */
219
- declare function extractImports(fileContent: string): string[];
220
- /**
221
- * Builds an import graph mapping test file paths to their imported module paths.
222
- *
223
- * Discovers test files, reads each, extracts imports, and builds a graph.
224
- * Computes a deterministic buildHash from the serialized graph content.
225
- * Individual file read failures are silently skipped.
226
- *
227
- * @param projectRoot - Absolute path to the project root directory.
228
- * @returns An {@link ImportGraphPayload} containing the graph and a deterministic buildHash.
229
- *
230
- * @remarks
231
- * Node-only. Walks the project with `node:fs/promises`, reads each
232
- * test file from disk, resolves paths with `node:path`, and hashes
233
- * the serialized graph with `node:crypto` (`createHash("sha256")`).
234
- * No edge-safe alternative — call from a Node context (build script,
235
- * CI job, Next.js `next.config.ts`).
236
- */
237
- declare function buildImportGraph(projectRoot: string): Promise<ImportGraphPayload>;
6
+ * Producer-side identifier pseudonymization for the value-fidelity
7
+ * scalar channel.
8
+ *
9
+ * `hashId` turns a raw identifier into a stable, opaque `gthid_<hex>`
10
+ * token that a producer can emit on an `*Id` scalar without leaking the
11
+ * raw value. The SDK's `checkScalarField` rejects unhashed `*Id` values
12
+ * under `strict`, so a producer that wants id correlation pre-hashes the
13
+ * id with this helper.
14
+ *
15
+ * NODE-ONLY. This module imports `node:crypto` and is therefore exported
16
+ * exclusively from the `@glasstrace/sdk/node` subpath, never the root
17
+ * barrel — the root must stay edge-bundle-safe (no node builtins in the
18
+ * edge closure). `*Id` capture is a server-side concern, so the
19
+ * node-only placement does not reduce real coverage.
20
+ */
21
+ /**
22
+ * Pseudonymize a raw identifier into a stable `gthid_<hex>` token using
23
+ * HMAC-SHA256 keyed by `key`.
24
+ *
25
+ * Node-only. Uses `node:crypto`, so it ships exclusively on the
26
+ * `@glasstrace/sdk/node` subpath.
27
+ *
28
+ * Fail-closed: returns `null` when `raw` or `key` is missing or empty,
29
+ * so a misconfigured caller emits no id rather than a raw or weakly
30
+ * keyed one. A `null` return routes the `*Id` scalar to the
31
+ * `unhashed_id` omission counter at emit time.
32
+ *
33
+ * The same `(raw, key)` always produces the same token, enabling
34
+ * cross-trace correlation of the same entity. This is also the privacy
35
+ * boundary's weak point:
36
+ *
37
+ * - **Key rotation breaks correlation by design.** Tokens hashed under
38
+ * a new key do not match tokens hashed under the old one. If
39
+ * cross-rotation correlation is required, embed a key-id segment in
40
+ * the key-management layer and rotate deliberately.
41
+ * - **A leaked key de-pseudonymizes every id hashed under it** (an
42
+ * attacker can hash a candidate id space and match tokens). Treat the
43
+ * key as a secret; scope it per tenant.
44
+ * - **Stable tokens plus quasi-identifier scalars enable corpus-level
45
+ * re-identification / linkage**, bounded by per-tenant scope. Do not
46
+ * treat a `gthid_` token as anonymization.
47
+ *
48
+ * @param raw - The raw identifier to pseudonymize.
49
+ * @param key - The per-tenant HMAC secret (e.g. from
50
+ * `GLASSTRACE_ATTR_HMAC_KEY`). Never logged or emitted.
51
+ * @returns A `gthid_<32hex>` token, or `null` if `raw`/`key` is empty.
52
+ */
53
+ declare function hashId(raw: string, key: string): string | null;
238
54
 
239
- export { type AutoUploadOptions, type BlobUploader, PRESIGNED_THRESHOLD_BYTES, type SourceMapEntry, type SourceMapFileInfo, buildImportGraph, collectSourceMaps, computeBuildHash, discoverSourceMapFiles, discoverTestFiles, extractImports, uploadSourceMaps, uploadSourceMapsAuto, uploadSourceMapsPresigned };
55
+ export { hashId };
@@ -6,16 +6,28 @@ import {
6
6
  uploadSourceMaps,
7
7
  uploadSourceMapsAuto,
8
8
  uploadSourceMapsPresigned
9
- } from "./chunk-MP3QNDXQ.js";
9
+ } from "./chunk-O7IJP2TQ.js";
10
10
  import "./chunk-YG3X7TUI.js";
11
11
  import {
12
12
  buildImportGraph,
13
13
  discoverTestFiles,
14
14
  extractImports
15
- } from "./chunk-XMD5OYD6.js";
15
+ } from "./chunk-M3QGJUEI.js";
16
16
  import "./chunk-VUZCLMIX.js";
17
- import "./chunk-7LE2O4ZJ.js";
17
+ import {
18
+ SIDE_EFFECT_HASHED_ID_HEX_LENGTH,
19
+ SIDE_EFFECT_HASHED_ID_PREFIX
20
+ } from "./chunk-MKT54VEH.js";
18
21
  import "./chunk-NSBPE2FW.js";
22
+
23
+ // src/side-effect/hash-id.ts
24
+ import { createHmac } from "node:crypto";
25
+ function hashId(raw, key) {
26
+ if (typeof raw !== "string" || raw.length === 0) return null;
27
+ if (typeof key !== "string" || key.length === 0) return null;
28
+ const digest = createHmac("sha256", key).update(raw).digest("hex").slice(0, SIDE_EFFECT_HASHED_ID_HEX_LENGTH);
29
+ return `${SIDE_EFFECT_HASHED_ID_PREFIX}${digest}`;
30
+ }
19
31
  export {
20
32
  PRESIGNED_THRESHOLD_BYTES,
21
33
  buildImportGraph,
@@ -24,6 +36,7 @@ export {
24
36
  discoverSourceMapFiles,
25
37
  discoverTestFiles,
26
38
  extractImports,
39
+ hashId,
27
40
  uploadSourceMaps,
28
41
  uploadSourceMapsAuto,
29
42
  uploadSourceMapsPresigned
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"sources":["../src/side-effect/hash-id.ts"],"sourcesContent":["/**\n * Producer-side identifier pseudonymization for the value-fidelity\n * scalar channel.\n *\n * `hashId` turns a raw identifier into a stable, opaque `gthid_<hex>`\n * token that a producer can emit on an `*Id` scalar without leaking the\n * raw value. The SDK's `checkScalarField` rejects unhashed `*Id` values\n * under `strict`, so a producer that wants id correlation pre-hashes the\n * id with this helper.\n *\n * NODE-ONLY. This module imports `node:crypto` and is therefore exported\n * exclusively from the `@glasstrace/sdk/node` subpath, never the root\n * barrel — the root must stay edge-bundle-safe (no node builtins in the\n * edge closure). `*Id` capture is a server-side concern, so the\n * node-only placement does not reduce real coverage.\n */\n\nimport { createHmac } from \"node:crypto\";\nimport {\n SIDE_EFFECT_HASHED_ID_HEX_LENGTH,\n SIDE_EFFECT_HASHED_ID_PREFIX,\n} from \"@glasstrace/protocol\";\n\n// 32 hex = 128 bits of the HMAC-SHA256 output — not brute-forceable\n// without the key, and compact. The length is shared with the SDK's\n// strict `*Id` scalar validator (via the protocol constant) so the\n// emitter and the admission check cannot drift.\n\n/**\n * Pseudonymize a raw identifier into a stable `gthid_<hex>` token using\n * HMAC-SHA256 keyed by `key`.\n *\n * Node-only. Uses `node:crypto`, so it ships exclusively on the\n * `@glasstrace/sdk/node` subpath.\n *\n * Fail-closed: returns `null` when `raw` or `key` is missing or empty,\n * so a misconfigured caller emits no id rather than a raw or weakly\n * keyed one. A `null` return routes the `*Id` scalar to the\n * `unhashed_id` omission counter at emit time.\n *\n * The same `(raw, key)` always produces the same token, enabling\n * cross-trace correlation of the same entity. This is also the privacy\n * boundary's weak point:\n *\n * - **Key rotation breaks correlation by design.** Tokens hashed under\n * a new key do not match tokens hashed under the old one. If\n * cross-rotation correlation is required, embed a key-id segment in\n * the key-management layer and rotate deliberately.\n * - **A leaked key de-pseudonymizes every id hashed under it** (an\n * attacker can hash a candidate id space and match tokens). Treat the\n * key as a secret; scope it per tenant.\n * - **Stable tokens plus quasi-identifier scalars enable corpus-level\n * re-identification / linkage**, bounded by per-tenant scope. Do not\n * treat a `gthid_` token as anonymization.\n *\n * @param raw - The raw identifier to pseudonymize.\n * @param key - The per-tenant HMAC secret (e.g. from\n * `GLASSTRACE_ATTR_HMAC_KEY`). Never logged or emitted.\n * @returns A `gthid_<32hex>` token, or `null` if `raw`/`key` is empty.\n */\nexport function hashId(raw: string, key: string): string | null {\n if (typeof raw !== \"string\" || raw.length === 0) return null;\n if (typeof key !== \"string\" || key.length === 0) return null;\n const digest = createHmac(\"sha256\", key)\n .update(raw)\n .digest(\"hex\")\n .slice(0, SIDE_EFFECT_HASHED_ID_HEX_LENGTH);\n return `${SIDE_EFFECT_HASHED_ID_PREFIX}${digest}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAiBA,SAAS,kBAAkB;AA2CpB,SAAS,OAAO,KAAa,KAA4B;AAC9D,MAAI,OAAO,QAAQ,YAAY,IAAI,WAAW,EAAG,QAAO;AACxD,MAAI,OAAO,QAAQ,YAAY,IAAI,WAAW,EAAG,QAAO;AACxD,QAAM,SAAS,WAAW,UAAU,GAAG,EACpC,OAAO,GAAG,EACV,OAAO,KAAK,EACZ,MAAM,GAAG,gCAAgC;AAC5C,SAAO,GAAG,4BAA4B,GAAG,MAAM;AACjD;","names":[]}
@@ -11,10 +11,10 @@ import {
11
11
  uploadSourceMapsAuto,
12
12
  uploadSourceMapsPresigned,
13
13
  uploadToBlob
14
- } from "./chunk-MP3QNDXQ.js";
14
+ } from "./chunk-O7IJP2TQ.js";
15
15
  import "./chunk-YG3X7TUI.js";
16
16
  import "./chunk-VUZCLMIX.js";
17
- import "./chunk-7LE2O4ZJ.js";
17
+ import "./chunk-MKT54VEH.js";
18
18
  import "./chunk-NSBPE2FW.js";
19
19
  export {
20
20
  PRESIGNED_THRESHOLD_BYTES,
@@ -30,4 +30,4 @@ export {
30
30
  uploadSourceMapsPresigned,
31
31
  uploadToBlob
32
32
  };
33
- //# sourceMappingURL=source-map-uploader-NUONOEJG.js.map
33
+ //# sourceMappingURL=source-map-uploader-U7SLSKIZ.js.map