@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.
- package/README.md +118 -11
- package/dist/async-context/index.cjs +21 -2
- package/dist/async-context/index.cjs.map +1 -1
- package/dist/async-context/index.js +2 -2
- package/dist/{capture-error-03qDnC5v.d.cts → capture-error-B0txjNut.d.cts} +2 -2
- package/dist/{capture-error-CAfFUyIU.d.ts → capture-error-Dc01rYNR.d.ts} +2 -2
- package/dist/{chunk-ZIYT2Y4B.js → chunk-BJOZBAP7.js} +3 -3
- package/dist/{chunk-VMK2G6QR.js → chunk-CN5EP25B.js} +2 -2
- package/dist/{chunk-HMEHYSTS.js → chunk-EVX6D2TX.js} +2 -2
- package/dist/{chunk-T4ETJJSK.js → chunk-F2IPBTDJ.js} +133 -11
- package/dist/{chunk-T4ETJJSK.js.map → chunk-F2IPBTDJ.js.map} +1 -1
- package/dist/{chunk-XMD5OYD6.js → chunk-M3QGJUEI.js} +2 -2
- package/dist/{chunk-7LE2O4ZJ.js → chunk-MKT54VEH.js} +55 -6
- package/dist/{chunk-7LE2O4ZJ.js.map → chunk-MKT54VEH.js.map} +1 -1
- package/dist/{chunk-MP3QNDXQ.js → chunk-O7IJP2TQ.js} +2 -2
- package/dist/{chunk-F7A3QXCT.js → chunk-UOAG72NR.js} +2 -2
- package/dist/{chunk-6ST4QV7T.js → chunk-VEQX2YSQ.js} +3 -3
- package/dist/{chunk-LQZRGBN5.js → chunk-YKE6HJLW.js} +2 -2
- package/dist/cli/init.cjs +18 -5
- package/dist/cli/init.cjs.map +1 -1
- package/dist/cli/init.js +7 -7
- package/dist/cli/mcp-add.cjs +15 -2
- package/dist/cli/mcp-add.cjs.map +1 -1
- package/dist/cli/mcp-add.js +3 -3
- package/dist/cli/uninit.js +3 -3
- package/dist/cli/upgrade-instructions.cjs +1 -1
- package/dist/cli/upgrade-instructions.js +3 -3
- package/dist/cli/validate.cjs +14 -1
- package/dist/cli/validate.cjs.map +1 -1
- package/dist/cli/validate.js +2 -2
- package/dist/{correlation-id-YcfcqOru.d.ts → correlation-id-B9YYmoZw.d.ts} +1 -1
- package/dist/{correlation-id-CZ2bstzA.d.cts → correlation-id-CelUvw7j.d.cts} +1 -1
- package/dist/edge-entry.cjs +21 -2
- package/dist/edge-entry.cjs.map +1 -1
- package/dist/edge-entry.d.cts +2 -2
- package/dist/edge-entry.d.ts +2 -2
- package/dist/edge-entry.js +4 -4
- package/dist/import-graph-DBLGNjcI.d.cts +238 -0
- package/dist/import-graph-Dka_Fm7j.d.ts +238 -0
- package/dist/index.cjs +203 -12
- package/dist/index.cjs.map +1 -1
- package/dist/{index.d-BQIJ5Dvc.d.cts → index.d-3-cJoY8y.d.cts} +10 -2
- package/dist/{index.d-BQIJ5Dvc.d.ts → index.d-3-cJoY8y.d.ts} +10 -2
- package/dist/index.d.cts +102 -5
- package/dist/index.d.ts +102 -5
- package/dist/index.js +30 -5
- package/dist/index.js.map +1 -1
- package/dist/middleware/index.cjs +21 -2
- package/dist/middleware/index.cjs.map +1 -1
- package/dist/middleware/index.js +2 -2
- package/dist/node-entry.cjs +28 -8
- package/dist/node-entry.cjs.map +1 -1
- package/dist/node-entry.d.cts +4 -4
- package/dist/node-entry.d.ts +4 -4
- package/dist/node-entry.js +7 -7
- package/dist/node-subpath.cjs +27 -1
- package/dist/node-subpath.cjs.map +1 -1
- package/dist/node-subpath.d.cts +51 -235
- package/dist/node-subpath.d.ts +51 -235
- package/dist/node-subpath.js +16 -3
- package/dist/node-subpath.js.map +1 -1
- package/dist/{source-map-uploader-NUONOEJG.js → source-map-uploader-U7SLSKIZ.js} +3 -3
- package/dist/trpc/index.cjs +21 -2
- package/dist/trpc/index.cjs.map +1 -1
- package/dist/trpc/index.js +1 -1
- package/package.json +1 -1
- /package/dist/{chunk-ZIYT2Y4B.js.map → chunk-BJOZBAP7.js.map} +0 -0
- /package/dist/{chunk-VMK2G6QR.js.map → chunk-CN5EP25B.js.map} +0 -0
- /package/dist/{chunk-HMEHYSTS.js.map → chunk-EVX6D2TX.js.map} +0 -0
- /package/dist/{chunk-XMD5OYD6.js.map → chunk-M3QGJUEI.js.map} +0 -0
- /package/dist/{chunk-MP3QNDXQ.js.map → chunk-O7IJP2TQ.js.map} +0 -0
- /package/dist/{chunk-F7A3QXCT.js.map → chunk-UOAG72NR.js.map} +0 -0
- /package/dist/{chunk-6ST4QV7T.js.map → chunk-VEQX2YSQ.js.map} +0 -0
- /package/dist/{chunk-LQZRGBN5.js.map → chunk-YKE6HJLW.js.map} +0 -0
- /package/dist/{source-map-uploader-NUONOEJG.js.map → source-map-uploader-U7SLSKIZ.js.map} +0 -0
package/dist/edge-entry.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { C as CorrelationIdRequest, G as GlasstraceSpanProcessor, S as SdkError, c as captureCorrelationId } from './correlation-id-
|
|
1
|
+
export { C as CorrelationIdRequest, G as GlasstraceSpanProcessor, S as SdkError, c as captureCorrelationId } from './correlation-id-CelUvw7j.cjs';
|
|
2
2
|
export { RequestMiddlewareFunction, TracedRequestMiddlewareOptions, tracedRequestMiddleware } from './middleware/index.cjs';
|
|
3
3
|
export { WithAsyncCausalityOptions, withAsyncCausality } from './async-context/index.cjs';
|
|
4
|
-
import './index.d-
|
|
4
|
+
import './index.d-3-cJoY8y.cjs';
|
|
5
5
|
import './v4/classic/external.cjs';
|
|
6
6
|
import './export/ReadableSpan';
|
|
7
7
|
import './Span';
|
package/dist/edge-entry.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { C as CorrelationIdRequest, G as GlasstraceSpanProcessor, S as SdkError, c as captureCorrelationId } from './correlation-id-
|
|
1
|
+
export { C as CorrelationIdRequest, G as GlasstraceSpanProcessor, S as SdkError, c as captureCorrelationId } from './correlation-id-B9YYmoZw.js';
|
|
2
2
|
export { RequestMiddlewareFunction, TracedRequestMiddlewareOptions, tracedRequestMiddleware } from './middleware/index.js';
|
|
3
3
|
export { WithAsyncCausalityOptions, withAsyncCausality } from './async-context/index.js';
|
|
4
|
-
import './index.d-
|
|
4
|
+
import './index.d-3-cJoY8y.js';
|
|
5
5
|
import './v4/classic/external.cjs';
|
|
6
6
|
import './export/ReadableSpan';
|
|
7
7
|
import './Span';
|
package/dist/edge-entry.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
tracedRequestMiddleware
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-CN5EP25B.js";
|
|
4
4
|
import {
|
|
5
5
|
withAsyncCausality
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-YKE6HJLW.js";
|
|
7
7
|
import {
|
|
8
8
|
GlasstraceSpanProcessor,
|
|
9
9
|
SdkError,
|
|
10
10
|
captureCorrelationId
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-EVX6D2TX.js";
|
|
12
12
|
import "./chunk-CL3OVHPO.js";
|
|
13
13
|
import "./chunk-DQ25VOKK.js";
|
|
14
|
-
import "./chunk-
|
|
14
|
+
import "./chunk-MKT54VEH.js";
|
|
15
15
|
import "./chunk-NSBPE2FW.js";
|
|
16
16
|
export {
|
|
17
17
|
GlasstraceSpanProcessor,
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { g as SourceMapUploadResponse, h as SourceMapManifestResponse, I as ImportGraphPayload } from './index.d-3-cJoY8y.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* In-memory source map entry: a file path paired with its full text content.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Node-only. Describes the legacy in-memory shape consumed by
|
|
8
|
+
* {@link uploadSourceMaps} and {@link uploadSourceMapsAuto}. The type
|
|
9
|
+
* itself erases at runtime and is safe to import from edge code, but
|
|
10
|
+
* every function that produces or consumes it depends on `node:fs`
|
|
11
|
+
* and cannot run at the edge.
|
|
12
|
+
*/
|
|
13
|
+
interface SourceMapEntry {
|
|
14
|
+
filePath: string;
|
|
15
|
+
content: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Metadata for a discovered source map file, without its content loaded.
|
|
19
|
+
* Used by the streaming upload flow to defer file reads until upload time.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* Node-only. Describes the shape of data produced by the Node-only
|
|
23
|
+
* source-map upload flow ({@link discoverSourceMapFiles},
|
|
24
|
+
* {@link uploadSourceMapsAuto}). The type itself erases at runtime and
|
|
25
|
+
* is safe to import from edge code, but every function that produces
|
|
26
|
+
* or consumes it depends on `node:fs`/`node:path` and cannot run at
|
|
27
|
+
* the edge.
|
|
28
|
+
*/
|
|
29
|
+
interface SourceMapFileInfo {
|
|
30
|
+
/** Relative path to the compiled JS file (`.map` extension stripped). */
|
|
31
|
+
filePath: string;
|
|
32
|
+
/** Absolute path on disk for reading the file content on demand. */
|
|
33
|
+
absolutePath: string;
|
|
34
|
+
/** File size in bytes. */
|
|
35
|
+
sizeBytes: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Recursively discovers all `.map` files in the given build directory.
|
|
39
|
+
* Returns metadata only — file content is NOT read into memory.
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* Node-only. Walks the filesystem with `node:fs/promises` (`readdir`,
|
|
43
|
+
* `stat`) and resolves paths with `node:path`. No edge-safe
|
|
44
|
+
* alternative — call from a Node context (build script, Next.js
|
|
45
|
+
* `next.config.ts`, CI job).
|
|
46
|
+
*/
|
|
47
|
+
declare function discoverSourceMapFiles(buildDir: string): Promise<SourceMapFileInfo[]>;
|
|
48
|
+
/**
|
|
49
|
+
* Recursively finds all .map files in the given build directory.
|
|
50
|
+
* Returns relative paths and file contents.
|
|
51
|
+
*
|
|
52
|
+
* @deprecated Prefer {@link discoverSourceMapFiles} to avoid loading all
|
|
53
|
+
* source maps into memory simultaneously.
|
|
54
|
+
*
|
|
55
|
+
* @remarks
|
|
56
|
+
* Node-only. Reads every discovered `.map` file into memory via
|
|
57
|
+
* `node:fs/promises` (`readFile`). No edge-safe alternative — call
|
|
58
|
+
* from a Node context (build script, Next.js `next.config.ts`, CI job).
|
|
59
|
+
*/
|
|
60
|
+
declare function collectSourceMaps(buildDir: string): Promise<SourceMapEntry[]>;
|
|
61
|
+
/**
|
|
62
|
+
* Computes a build hash for source map uploads.
|
|
63
|
+
*
|
|
64
|
+
* First tries `git rev-parse HEAD` to get the git commit SHA.
|
|
65
|
+
* On failure, falls back to a deterministic content hash:
|
|
66
|
+
* sort source map file paths alphabetically, concatenate each as
|
|
67
|
+
* `{relativePath}\n{fileLength}\n{fileContent}`, then SHA-256 the result.
|
|
68
|
+
*
|
|
69
|
+
* Accepts either `SourceMapEntry[]` (legacy, in-memory) or
|
|
70
|
+
* `SourceMapFileInfo[]` (streaming, reads on demand).
|
|
71
|
+
*
|
|
72
|
+
* @remarks
|
|
73
|
+
* Node-only. Spawns `git rev-parse HEAD` via `node:child_process`
|
|
74
|
+
* (`execFileSync`), hashes with `node:crypto` (`createHash("sha256")`),
|
|
75
|
+
* and reads map contents from disk with `node:fs/promises`. No
|
|
76
|
+
* edge-safe alternative — call from a Node context (build script,
|
|
77
|
+
* Next.js `next.config.ts`, CI job). If a pre-computed build hash is
|
|
78
|
+
* already known (e.g., provided as a CI environment variable), pass
|
|
79
|
+
* it directly to {@link uploadSourceMaps} instead of calling this
|
|
80
|
+
* helper.
|
|
81
|
+
*/
|
|
82
|
+
declare function computeBuildHash(maps?: SourceMapEntry[] | SourceMapFileInfo[]): Promise<string>;
|
|
83
|
+
/**
|
|
84
|
+
* Uploads source maps to the ingestion API.
|
|
85
|
+
*
|
|
86
|
+
* POSTs to `{endpoint}/v1/source-maps` with the API key, build hash,
|
|
87
|
+
* and file entries. Validates the response against SourceMapUploadResponseSchema.
|
|
88
|
+
*
|
|
89
|
+
* Accepts either `SourceMapEntry[]` (legacy, in-memory) or
|
|
90
|
+
* `SourceMapFileInfo[]` (deferred reads). With `SourceMapFileInfo[]`,
|
|
91
|
+
* file content is read at upload time rather than at discovery time.
|
|
92
|
+
* Note: the legacy endpoint sends all files in a single JSON body, so
|
|
93
|
+
* peak memory is similar — the benefit is deferring reads past discovery.
|
|
94
|
+
*
|
|
95
|
+
* @remarks
|
|
96
|
+
* Node-only. Reads map contents from disk via `node:fs/promises` when
|
|
97
|
+
* invoked with `SourceMapFileInfo[]`. The network call uses the
|
|
98
|
+
* platform-standard `fetch` (edge-safe on its own), but the upstream
|
|
99
|
+
* discovery and read path is Node-only, so the function is only
|
|
100
|
+
* reachable from a Node context (build script, Next.js
|
|
101
|
+
* `next.config.ts`, CI job). No edge-safe alternative.
|
|
102
|
+
*/
|
|
103
|
+
declare function uploadSourceMaps(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[] | SourceMapFileInfo[]): Promise<SourceMapUploadResponse>;
|
|
104
|
+
/**
|
|
105
|
+
* Builds at or above this byte size route to the presigned upload flow.
|
|
106
|
+
*
|
|
107
|
+
* @remarks
|
|
108
|
+
* Node-only. The numeric value itself is pure (a constant is evaluable
|
|
109
|
+
* anywhere), but it is meaningful only alongside
|
|
110
|
+
* {@link uploadSourceMapsPresigned} and {@link uploadSourceMapsAuto},
|
|
111
|
+
* both of which depend on `node:fs` and `@vercel/blob`. No edge-safe
|
|
112
|
+
* alternative — consume from a Node context.
|
|
113
|
+
*/
|
|
114
|
+
declare const PRESIGNED_THRESHOLD_BYTES = 4500000;
|
|
115
|
+
/**
|
|
116
|
+
* Signature for the blob upload function, injectable for testing.
|
|
117
|
+
*
|
|
118
|
+
* @remarks
|
|
119
|
+
* Node-only. Describes the shape of the uploader consumed by
|
|
120
|
+
* {@link uploadSourceMapsPresigned} and {@link uploadSourceMapsAuto},
|
|
121
|
+
* both of which depend on `@vercel/blob` and `node:fs`. The type itself
|
|
122
|
+
* erases at runtime and is safe to import from edge code, but every
|
|
123
|
+
* producer and consumer is Node-only.
|
|
124
|
+
*/
|
|
125
|
+
type BlobUploader = (clientToken: string, pathname: string, content: string) => Promise<{
|
|
126
|
+
url: string;
|
|
127
|
+
size: number;
|
|
128
|
+
}>;
|
|
129
|
+
/**
|
|
130
|
+
* Orchestrates the 3-phase presigned upload flow.
|
|
131
|
+
*
|
|
132
|
+
* 1. Requests presigned tokens for all source map files
|
|
133
|
+
* 2. Uploads each file to blob storage with a concurrency limit of 5,
|
|
134
|
+
* reading file content from disk just before each upload
|
|
135
|
+
* 3. Submits the manifest to finalize the upload
|
|
136
|
+
*
|
|
137
|
+
* Accepts either `SourceMapEntry[]` (legacy, in-memory) or
|
|
138
|
+
* `SourceMapFileInfo[]` (streaming, reads on demand).
|
|
139
|
+
*
|
|
140
|
+
* Accepts an optional `blobUploader` for test injection; defaults to
|
|
141
|
+
* {@link uploadToBlob}.
|
|
142
|
+
*
|
|
143
|
+
* @remarks
|
|
144
|
+
* Node-only. Streams map contents from disk via `node:fs/promises`
|
|
145
|
+
* and uploads through `@vercel/blob/client` (loaded lazily as an
|
|
146
|
+
* optional peer dependency). No edge-safe alternative — call from a
|
|
147
|
+
* Node context (build script, Next.js `next.config.ts`, CI job).
|
|
148
|
+
*/
|
|
149
|
+
declare function uploadSourceMapsPresigned(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[] | SourceMapFileInfo[], blobUploader?: BlobUploader): Promise<SourceMapManifestResponse>;
|
|
150
|
+
/**
|
|
151
|
+
* Options for {@link uploadSourceMapsAuto}, primarily used for test injection.
|
|
152
|
+
*
|
|
153
|
+
* @remarks
|
|
154
|
+
* Node-only. Describes the shape of overrides consumed by
|
|
155
|
+
* {@link uploadSourceMapsAuto}, which depends on `node:fs` and
|
|
156
|
+
* `@vercel/blob`. The type itself erases at runtime and is safe to
|
|
157
|
+
* import from edge code, but the surrounding function is Node-only.
|
|
158
|
+
*/
|
|
159
|
+
interface AutoUploadOptions {
|
|
160
|
+
/** Override blob availability check (for testing). */
|
|
161
|
+
checkBlobAvailable?: () => Promise<boolean>;
|
|
162
|
+
/** Override blob uploader (for testing). */
|
|
163
|
+
blobUploader?: BlobUploader;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Automatically routes source map uploads based on total build size.
|
|
167
|
+
*
|
|
168
|
+
* - Below {@link PRESIGNED_THRESHOLD_BYTES}: uses the legacy single-request
|
|
169
|
+
* {@link uploadSourceMaps} endpoint.
|
|
170
|
+
* - At or above the threshold: checks if `@vercel/blob` is available and
|
|
171
|
+
* uses the presigned 3-phase flow. Falls back to legacy with a warning
|
|
172
|
+
* if the package is not installed.
|
|
173
|
+
*
|
|
174
|
+
* Accepts either `SourceMapEntry[]` (legacy, in-memory) or
|
|
175
|
+
* `SourceMapFileInfo[]` (streaming, reads on demand).
|
|
176
|
+
*
|
|
177
|
+
* @remarks
|
|
178
|
+
* Node-only. Reads source map sizes/contents via `node:fs/promises`
|
|
179
|
+
* and, above the threshold, dynamically loads `@vercel/blob/client`
|
|
180
|
+
* (optional peer dependency) for direct blob storage uploads. No
|
|
181
|
+
* edge-safe alternative — call from a Node context (build script,
|
|
182
|
+
* Next.js `next.config.ts`, CI job). This is the recommended entry
|
|
183
|
+
* point for source-map upload in most projects.
|
|
184
|
+
*/
|
|
185
|
+
declare function uploadSourceMapsAuto(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[] | SourceMapFileInfo[], options?: AutoUploadOptions): Promise<SourceMapUploadResponse | SourceMapManifestResponse>;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Discovers test files by scanning the project directory for conventional
|
|
189
|
+
* test file patterns. Also reads vitest/jest config files for custom include
|
|
190
|
+
* patterns and merges them with the defaults. Excludes node_modules/ and .next/.
|
|
191
|
+
*
|
|
192
|
+
* @param projectRoot - Absolute path to the project root directory.
|
|
193
|
+
* @returns Relative POSIX paths from projectRoot, capped at {@link MAX_TEST_FILES}.
|
|
194
|
+
*
|
|
195
|
+
* @remarks
|
|
196
|
+
* Node-only. Walks the filesystem with `node:fs/promises`
|
|
197
|
+
* (`readdir`), reads vitest/jest config files with `node:fs`
|
|
198
|
+
* (`readFileSync`), and resolves paths with `node:path`. No edge-safe
|
|
199
|
+
* alternative — call from a Node context (build script, CI job,
|
|
200
|
+
* Next.js `next.config.ts`).
|
|
201
|
+
*/
|
|
202
|
+
declare function discoverTestFiles(projectRoot: string): Promise<string[]>;
|
|
203
|
+
/**
|
|
204
|
+
* Extracts import paths from file content using regex.
|
|
205
|
+
* Handles ES module imports, CommonJS requires, and dynamic imports.
|
|
206
|
+
*
|
|
207
|
+
* @param fileContent - The full text content of a TypeScript/JavaScript file.
|
|
208
|
+
* @returns An array of import path strings as written in the source (e.g. "./foo", "react").
|
|
209
|
+
*
|
|
210
|
+
* @remarks
|
|
211
|
+
* Node-only. The function body itself is pure string processing and
|
|
212
|
+
* would run anywhere, but it is exported through `@glasstrace/sdk/node`
|
|
213
|
+
* alongside {@link discoverTestFiles} and {@link buildImportGraph} —
|
|
214
|
+
* the practical consumers all pair it with those Node-only helpers.
|
|
215
|
+
* Kept under the `/node` subpath for API cohesion; call from a Node
|
|
216
|
+
* context (build script, CI job, Next.js `next.config.ts`).
|
|
217
|
+
*/
|
|
218
|
+
declare function extractImports(fileContent: string): string[];
|
|
219
|
+
/**
|
|
220
|
+
* Builds an import graph mapping test file paths to their imported module paths.
|
|
221
|
+
*
|
|
222
|
+
* Discovers test files, reads each, extracts imports, and builds a graph.
|
|
223
|
+
* Computes a deterministic buildHash from the serialized graph content.
|
|
224
|
+
* Individual file read failures are silently skipped.
|
|
225
|
+
*
|
|
226
|
+
* @param projectRoot - Absolute path to the project root directory.
|
|
227
|
+
* @returns An {@link ImportGraphPayload} containing the graph and a deterministic buildHash.
|
|
228
|
+
*
|
|
229
|
+
* @remarks
|
|
230
|
+
* Node-only. Walks the project with `node:fs/promises`, reads each
|
|
231
|
+
* test file from disk, resolves paths with `node:path`, and hashes
|
|
232
|
+
* the serialized graph with `node:crypto` (`createHash("sha256")`).
|
|
233
|
+
* No edge-safe alternative — call from a Node context (build script,
|
|
234
|
+
* CI job, Next.js `next.config.ts`).
|
|
235
|
+
*/
|
|
236
|
+
declare function buildImportGraph(projectRoot: string): Promise<ImportGraphPayload>;
|
|
237
|
+
|
|
238
|
+
export { type AutoUploadOptions as A, type BlobUploader as B, PRESIGNED_THRESHOLD_BYTES as P, type SourceMapEntry as S, type SourceMapFileInfo as a, buildImportGraph as b, collectSourceMaps as c, computeBuildHash as d, discoverSourceMapFiles as e, discoverTestFiles as f, extractImports as g, uploadSourceMapsAuto as h, uploadSourceMapsPresigned as i, uploadSourceMaps as u };
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { g as SourceMapUploadResponse, h as SourceMapManifestResponse, I as ImportGraphPayload } from './index.d-3-cJoY8y.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* In-memory source map entry: a file path paired with its full text content.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Node-only. Describes the legacy in-memory shape consumed by
|
|
8
|
+
* {@link uploadSourceMaps} and {@link uploadSourceMapsAuto}. The type
|
|
9
|
+
* itself erases at runtime and is safe to import from edge code, but
|
|
10
|
+
* every function that produces or consumes it depends on `node:fs`
|
|
11
|
+
* and cannot run at the edge.
|
|
12
|
+
*/
|
|
13
|
+
interface SourceMapEntry {
|
|
14
|
+
filePath: string;
|
|
15
|
+
content: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Metadata for a discovered source map file, without its content loaded.
|
|
19
|
+
* Used by the streaming upload flow to defer file reads until upload time.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* Node-only. Describes the shape of data produced by the Node-only
|
|
23
|
+
* source-map upload flow ({@link discoverSourceMapFiles},
|
|
24
|
+
* {@link uploadSourceMapsAuto}). The type itself erases at runtime and
|
|
25
|
+
* is safe to import from edge code, but every function that produces
|
|
26
|
+
* or consumes it depends on `node:fs`/`node:path` and cannot run at
|
|
27
|
+
* the edge.
|
|
28
|
+
*/
|
|
29
|
+
interface SourceMapFileInfo {
|
|
30
|
+
/** Relative path to the compiled JS file (`.map` extension stripped). */
|
|
31
|
+
filePath: string;
|
|
32
|
+
/** Absolute path on disk for reading the file content on demand. */
|
|
33
|
+
absolutePath: string;
|
|
34
|
+
/** File size in bytes. */
|
|
35
|
+
sizeBytes: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Recursively discovers all `.map` files in the given build directory.
|
|
39
|
+
* Returns metadata only — file content is NOT read into memory.
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* Node-only. Walks the filesystem with `node:fs/promises` (`readdir`,
|
|
43
|
+
* `stat`) and resolves paths with `node:path`. No edge-safe
|
|
44
|
+
* alternative — call from a Node context (build script, Next.js
|
|
45
|
+
* `next.config.ts`, CI job).
|
|
46
|
+
*/
|
|
47
|
+
declare function discoverSourceMapFiles(buildDir: string): Promise<SourceMapFileInfo[]>;
|
|
48
|
+
/**
|
|
49
|
+
* Recursively finds all .map files in the given build directory.
|
|
50
|
+
* Returns relative paths and file contents.
|
|
51
|
+
*
|
|
52
|
+
* @deprecated Prefer {@link discoverSourceMapFiles} to avoid loading all
|
|
53
|
+
* source maps into memory simultaneously.
|
|
54
|
+
*
|
|
55
|
+
* @remarks
|
|
56
|
+
* Node-only. Reads every discovered `.map` file into memory via
|
|
57
|
+
* `node:fs/promises` (`readFile`). No edge-safe alternative — call
|
|
58
|
+
* from a Node context (build script, Next.js `next.config.ts`, CI job).
|
|
59
|
+
*/
|
|
60
|
+
declare function collectSourceMaps(buildDir: string): Promise<SourceMapEntry[]>;
|
|
61
|
+
/**
|
|
62
|
+
* Computes a build hash for source map uploads.
|
|
63
|
+
*
|
|
64
|
+
* First tries `git rev-parse HEAD` to get the git commit SHA.
|
|
65
|
+
* On failure, falls back to a deterministic content hash:
|
|
66
|
+
* sort source map file paths alphabetically, concatenate each as
|
|
67
|
+
* `{relativePath}\n{fileLength}\n{fileContent}`, then SHA-256 the result.
|
|
68
|
+
*
|
|
69
|
+
* Accepts either `SourceMapEntry[]` (legacy, in-memory) or
|
|
70
|
+
* `SourceMapFileInfo[]` (streaming, reads on demand).
|
|
71
|
+
*
|
|
72
|
+
* @remarks
|
|
73
|
+
* Node-only. Spawns `git rev-parse HEAD` via `node:child_process`
|
|
74
|
+
* (`execFileSync`), hashes with `node:crypto` (`createHash("sha256")`),
|
|
75
|
+
* and reads map contents from disk with `node:fs/promises`. No
|
|
76
|
+
* edge-safe alternative — call from a Node context (build script,
|
|
77
|
+
* Next.js `next.config.ts`, CI job). If a pre-computed build hash is
|
|
78
|
+
* already known (e.g., provided as a CI environment variable), pass
|
|
79
|
+
* it directly to {@link uploadSourceMaps} instead of calling this
|
|
80
|
+
* helper.
|
|
81
|
+
*/
|
|
82
|
+
declare function computeBuildHash(maps?: SourceMapEntry[] | SourceMapFileInfo[]): Promise<string>;
|
|
83
|
+
/**
|
|
84
|
+
* Uploads source maps to the ingestion API.
|
|
85
|
+
*
|
|
86
|
+
* POSTs to `{endpoint}/v1/source-maps` with the API key, build hash,
|
|
87
|
+
* and file entries. Validates the response against SourceMapUploadResponseSchema.
|
|
88
|
+
*
|
|
89
|
+
* Accepts either `SourceMapEntry[]` (legacy, in-memory) or
|
|
90
|
+
* `SourceMapFileInfo[]` (deferred reads). With `SourceMapFileInfo[]`,
|
|
91
|
+
* file content is read at upload time rather than at discovery time.
|
|
92
|
+
* Note: the legacy endpoint sends all files in a single JSON body, so
|
|
93
|
+
* peak memory is similar — the benefit is deferring reads past discovery.
|
|
94
|
+
*
|
|
95
|
+
* @remarks
|
|
96
|
+
* Node-only. Reads map contents from disk via `node:fs/promises` when
|
|
97
|
+
* invoked with `SourceMapFileInfo[]`. The network call uses the
|
|
98
|
+
* platform-standard `fetch` (edge-safe on its own), but the upstream
|
|
99
|
+
* discovery and read path is Node-only, so the function is only
|
|
100
|
+
* reachable from a Node context (build script, Next.js
|
|
101
|
+
* `next.config.ts`, CI job). No edge-safe alternative.
|
|
102
|
+
*/
|
|
103
|
+
declare function uploadSourceMaps(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[] | SourceMapFileInfo[]): Promise<SourceMapUploadResponse>;
|
|
104
|
+
/**
|
|
105
|
+
* Builds at or above this byte size route to the presigned upload flow.
|
|
106
|
+
*
|
|
107
|
+
* @remarks
|
|
108
|
+
* Node-only. The numeric value itself is pure (a constant is evaluable
|
|
109
|
+
* anywhere), but it is meaningful only alongside
|
|
110
|
+
* {@link uploadSourceMapsPresigned} and {@link uploadSourceMapsAuto},
|
|
111
|
+
* both of which depend on `node:fs` and `@vercel/blob`. No edge-safe
|
|
112
|
+
* alternative — consume from a Node context.
|
|
113
|
+
*/
|
|
114
|
+
declare const PRESIGNED_THRESHOLD_BYTES = 4500000;
|
|
115
|
+
/**
|
|
116
|
+
* Signature for the blob upload function, injectable for testing.
|
|
117
|
+
*
|
|
118
|
+
* @remarks
|
|
119
|
+
* Node-only. Describes the shape of the uploader consumed by
|
|
120
|
+
* {@link uploadSourceMapsPresigned} and {@link uploadSourceMapsAuto},
|
|
121
|
+
* both of which depend on `@vercel/blob` and `node:fs`. The type itself
|
|
122
|
+
* erases at runtime and is safe to import from edge code, but every
|
|
123
|
+
* producer and consumer is Node-only.
|
|
124
|
+
*/
|
|
125
|
+
type BlobUploader = (clientToken: string, pathname: string, content: string) => Promise<{
|
|
126
|
+
url: string;
|
|
127
|
+
size: number;
|
|
128
|
+
}>;
|
|
129
|
+
/**
|
|
130
|
+
* Orchestrates the 3-phase presigned upload flow.
|
|
131
|
+
*
|
|
132
|
+
* 1. Requests presigned tokens for all source map files
|
|
133
|
+
* 2. Uploads each file to blob storage with a concurrency limit of 5,
|
|
134
|
+
* reading file content from disk just before each upload
|
|
135
|
+
* 3. Submits the manifest to finalize the upload
|
|
136
|
+
*
|
|
137
|
+
* Accepts either `SourceMapEntry[]` (legacy, in-memory) or
|
|
138
|
+
* `SourceMapFileInfo[]` (streaming, reads on demand).
|
|
139
|
+
*
|
|
140
|
+
* Accepts an optional `blobUploader` for test injection; defaults to
|
|
141
|
+
* {@link uploadToBlob}.
|
|
142
|
+
*
|
|
143
|
+
* @remarks
|
|
144
|
+
* Node-only. Streams map contents from disk via `node:fs/promises`
|
|
145
|
+
* and uploads through `@vercel/blob/client` (loaded lazily as an
|
|
146
|
+
* optional peer dependency). No edge-safe alternative — call from a
|
|
147
|
+
* Node context (build script, Next.js `next.config.ts`, CI job).
|
|
148
|
+
*/
|
|
149
|
+
declare function uploadSourceMapsPresigned(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[] | SourceMapFileInfo[], blobUploader?: BlobUploader): Promise<SourceMapManifestResponse>;
|
|
150
|
+
/**
|
|
151
|
+
* Options for {@link uploadSourceMapsAuto}, primarily used for test injection.
|
|
152
|
+
*
|
|
153
|
+
* @remarks
|
|
154
|
+
* Node-only. Describes the shape of overrides consumed by
|
|
155
|
+
* {@link uploadSourceMapsAuto}, which depends on `node:fs` and
|
|
156
|
+
* `@vercel/blob`. The type itself erases at runtime and is safe to
|
|
157
|
+
* import from edge code, but the surrounding function is Node-only.
|
|
158
|
+
*/
|
|
159
|
+
interface AutoUploadOptions {
|
|
160
|
+
/** Override blob availability check (for testing). */
|
|
161
|
+
checkBlobAvailable?: () => Promise<boolean>;
|
|
162
|
+
/** Override blob uploader (for testing). */
|
|
163
|
+
blobUploader?: BlobUploader;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Automatically routes source map uploads based on total build size.
|
|
167
|
+
*
|
|
168
|
+
* - Below {@link PRESIGNED_THRESHOLD_BYTES}: uses the legacy single-request
|
|
169
|
+
* {@link uploadSourceMaps} endpoint.
|
|
170
|
+
* - At or above the threshold: checks if `@vercel/blob` is available and
|
|
171
|
+
* uses the presigned 3-phase flow. Falls back to legacy with a warning
|
|
172
|
+
* if the package is not installed.
|
|
173
|
+
*
|
|
174
|
+
* Accepts either `SourceMapEntry[]` (legacy, in-memory) or
|
|
175
|
+
* `SourceMapFileInfo[]` (streaming, reads on demand).
|
|
176
|
+
*
|
|
177
|
+
* @remarks
|
|
178
|
+
* Node-only. Reads source map sizes/contents via `node:fs/promises`
|
|
179
|
+
* and, above the threshold, dynamically loads `@vercel/blob/client`
|
|
180
|
+
* (optional peer dependency) for direct blob storage uploads. No
|
|
181
|
+
* edge-safe alternative — call from a Node context (build script,
|
|
182
|
+
* Next.js `next.config.ts`, CI job). This is the recommended entry
|
|
183
|
+
* point for source-map upload in most projects.
|
|
184
|
+
*/
|
|
185
|
+
declare function uploadSourceMapsAuto(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[] | SourceMapFileInfo[], options?: AutoUploadOptions): Promise<SourceMapUploadResponse | SourceMapManifestResponse>;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Discovers test files by scanning the project directory for conventional
|
|
189
|
+
* test file patterns. Also reads vitest/jest config files for custom include
|
|
190
|
+
* patterns and merges them with the defaults. Excludes node_modules/ and .next/.
|
|
191
|
+
*
|
|
192
|
+
* @param projectRoot - Absolute path to the project root directory.
|
|
193
|
+
* @returns Relative POSIX paths from projectRoot, capped at {@link MAX_TEST_FILES}.
|
|
194
|
+
*
|
|
195
|
+
* @remarks
|
|
196
|
+
* Node-only. Walks the filesystem with `node:fs/promises`
|
|
197
|
+
* (`readdir`), reads vitest/jest config files with `node:fs`
|
|
198
|
+
* (`readFileSync`), and resolves paths with `node:path`. No edge-safe
|
|
199
|
+
* alternative — call from a Node context (build script, CI job,
|
|
200
|
+
* Next.js `next.config.ts`).
|
|
201
|
+
*/
|
|
202
|
+
declare function discoverTestFiles(projectRoot: string): Promise<string[]>;
|
|
203
|
+
/**
|
|
204
|
+
* Extracts import paths from file content using regex.
|
|
205
|
+
* Handles ES module imports, CommonJS requires, and dynamic imports.
|
|
206
|
+
*
|
|
207
|
+
* @param fileContent - The full text content of a TypeScript/JavaScript file.
|
|
208
|
+
* @returns An array of import path strings as written in the source (e.g. "./foo", "react").
|
|
209
|
+
*
|
|
210
|
+
* @remarks
|
|
211
|
+
* Node-only. The function body itself is pure string processing and
|
|
212
|
+
* would run anywhere, but it is exported through `@glasstrace/sdk/node`
|
|
213
|
+
* alongside {@link discoverTestFiles} and {@link buildImportGraph} —
|
|
214
|
+
* the practical consumers all pair it with those Node-only helpers.
|
|
215
|
+
* Kept under the `/node` subpath for API cohesion; call from a Node
|
|
216
|
+
* context (build script, CI job, Next.js `next.config.ts`).
|
|
217
|
+
*/
|
|
218
|
+
declare function extractImports(fileContent: string): string[];
|
|
219
|
+
/**
|
|
220
|
+
* Builds an import graph mapping test file paths to their imported module paths.
|
|
221
|
+
*
|
|
222
|
+
* Discovers test files, reads each, extracts imports, and builds a graph.
|
|
223
|
+
* Computes a deterministic buildHash from the serialized graph content.
|
|
224
|
+
* Individual file read failures are silently skipped.
|
|
225
|
+
*
|
|
226
|
+
* @param projectRoot - Absolute path to the project root directory.
|
|
227
|
+
* @returns An {@link ImportGraphPayload} containing the graph and a deterministic buildHash.
|
|
228
|
+
*
|
|
229
|
+
* @remarks
|
|
230
|
+
* Node-only. Walks the project with `node:fs/promises`, reads each
|
|
231
|
+
* test file from disk, resolves paths with `node:path`, and hashes
|
|
232
|
+
* the serialized graph with `node:crypto` (`createHash("sha256")`).
|
|
233
|
+
* No edge-safe alternative — call from a Node context (build script,
|
|
234
|
+
* CI job, Next.js `next.config.ts`).
|
|
235
|
+
*/
|
|
236
|
+
declare function buildImportGraph(projectRoot: string): Promise<ImportGraphPayload>;
|
|
237
|
+
|
|
238
|
+
export { type AutoUploadOptions as A, type BlobUploader as B, PRESIGNED_THRESHOLD_BYTES as P, type SourceMapEntry as S, type SourceMapFileInfo as a, buildImportGraph as b, collectSourceMaps as c, computeBuildHash as d, discoverSourceMapFiles as e, discoverTestFiles as f, extractImports as g, uploadSourceMapsAuto as h, uploadSourceMapsPresigned as i, uploadSourceMaps as u };
|