@deploze/next 0.0.0-stage → 0.1.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.
@@ -0,0 +1,347 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/core/index.ts
31
+ var core_exports = {};
32
+ __export(core_exports, {
33
+ SCHEMA_VERSION: () => SCHEMA_VERSION,
34
+ createCollector: () => createCollector,
35
+ getBuildId: () => getBuildId,
36
+ normalizeErrorSignature: () => normalizeErrorSignature,
37
+ normalizePathPattern: () => normalizePathPattern,
38
+ send: () => send
39
+ });
40
+ module.exports = __toCommonJS(core_exports);
41
+
42
+ // src/core/normalize.ts
43
+ function normalizePathPattern(path) {
44
+ if (!path) return "/unknown";
45
+ return path.split("?")[0].split("#")[0].replace(
46
+ /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi,
47
+ ":id"
48
+ ).replace(/\/[0-9a-f]{16,}\b/gi, "/:id").replace(/\/\d{2,}\b/g, "/:id").replace(/\/$/, "") || "/";
49
+ }
50
+ function normalizeErrorSignature(message) {
51
+ return message.replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi, "{UUID}").replace(/\b[0-9a-f]{16,}\b/gi, "{ID}").replace(/\b\d{6,}\b/g, "{ID}").replace(/:\d+:\d+/g, ":{LINE}").replace(/\s+/g, " ").trim().slice(0, 200);
52
+ }
53
+
54
+ // src/core/protocol.ts
55
+ var SCHEMA_VERSION = 1;
56
+
57
+ // src/core/build-id.ts
58
+ var import_meta = {};
59
+ function getEnv(name) {
60
+ try {
61
+ return globalThis.process?.env?.[name];
62
+ } catch {
63
+ return void 0;
64
+ }
65
+ }
66
+ async function readGeneratedBuildId() {
67
+ if (process.env.NEXT_RUNTIME !== "edge") {
68
+ try {
69
+ const fs = await import("fs");
70
+ const path = await import("path");
71
+ const { fileURLToPath } = await import("url");
72
+ const dir = getModuleDir(path, fileURLToPath);
73
+ const candidates = [
74
+ path.join(dir, ".build-id.json"),
75
+ path.join(dir, "..", ".build-id.json"),
76
+ path.join(dir, "..", "..", ".build-id.json")
77
+ ];
78
+ for (const candidate of candidates) {
79
+ try {
80
+ if (!fs.existsSync(candidate)) continue;
81
+ const raw = JSON.parse(fs.readFileSync(candidate, "utf8"));
82
+ return typeof raw?.sha === "string" && raw.sha ? raw.sha : null;
83
+ } catch {
84
+ return null;
85
+ }
86
+ }
87
+ } catch {
88
+ }
89
+ }
90
+ return null;
91
+ }
92
+ function getModuleDir(path, fileURLToPath) {
93
+ try {
94
+ return path.dirname(fileURLToPath(import_meta.url));
95
+ } catch {
96
+ const dir = globalThis.__dirname;
97
+ return typeof dir !== "undefined" ? dir : process.cwd();
98
+ }
99
+ }
100
+ async function getBuildId() {
101
+ return getEnv("DEPLOZE_GIT_SHA") || getEnv("VERCEL_GIT_COMMIT_SHA") || await readGeneratedBuildId() || null;
102
+ }
103
+
104
+ // src/core/transport.ts
105
+ var SDK_VERSION = "0.1.0";
106
+ function parseRemoteConfig(body) {
107
+ if (!body || typeof body !== "object") return void 0;
108
+ const raw = body.config;
109
+ if (!raw || typeof raw !== "object") return void 0;
110
+ const cfg = raw;
111
+ const config = {};
112
+ const flush = Number(cfg.flush_interval_ms);
113
+ if (Number.isFinite(flush) && flush >= 1e3 && flush <= 6e5) {
114
+ config.flush_interval_ms = Math.floor(flush);
115
+ }
116
+ const buckets = Number(cfg.max_buckets);
117
+ if (Number.isFinite(buckets) && buckets >= 1 && buckets <= 1e4) {
118
+ config.max_buckets = Math.floor(buckets);
119
+ }
120
+ const samples = Number(cfg.max_error_samples);
121
+ if (Number.isFinite(samples) && samples >= 1 && samples <= 1e3) {
122
+ config.max_error_samples = Math.floor(samples);
123
+ }
124
+ return Object.keys(config).length > 0 ? config : void 0;
125
+ }
126
+ async function send(payload, options) {
127
+ const { endpoint, apiKey, timeoutMs = 3e3 } = options;
128
+ const fetchImpl = options.fetchImpl ?? globalThis.fetch;
129
+ if (typeof fetchImpl !== "function") return { ok: false };
130
+ try {
131
+ const controller = new AbortController();
132
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
133
+ const body = {
134
+ schema_version: payload.schema_version ?? SCHEMA_VERSION,
135
+ stats: payload.stats,
136
+ errors: payload.errors
137
+ };
138
+ const buildId = await getBuildId();
139
+ const headers = {
140
+ "Content-Type": "application/json",
141
+ Authorization: `Bearer ${apiKey}`,
142
+ "User-Agent": `@deploze/next/${SDK_VERSION}`
143
+ };
144
+ if (buildId) headers["X-Deploze-Git-Sha"] = buildId;
145
+ const res = await fetchImpl(endpoint, {
146
+ method: "POST",
147
+ headers,
148
+ body: JSON.stringify(body),
149
+ keepalive: true,
150
+ signal: controller.signal
151
+ });
152
+ clearTimeout(timer);
153
+ if (!res.ok) return { ok: false };
154
+ let config;
155
+ try {
156
+ const parsed = typeof res.json === "function" ? await res.json() : typeof res.text === "function" ? JSON.parse(await res.text()) : void 0;
157
+ config = parseRemoteConfig(parsed);
158
+ } catch {
159
+ }
160
+ return { ok: true, config };
161
+ } catch {
162
+ return { ok: false };
163
+ }
164
+ }
165
+
166
+ // src/core/collector.ts
167
+ var DEFAULT_MAX_BUCKETS = 200;
168
+ var DEFAULT_MAX_ERROR_SAMPLES = 10;
169
+ var RESERVOIR_SIZE = 200;
170
+ var DEFAULT_FLUSH_INTERVAL_MS = 3e4;
171
+ var DEFAULT_ENDPOINT = "https://app.deploze.com/api/ingest";
172
+ function p95(values) {
173
+ if (values.length === 0) return void 0;
174
+ const sorted = [...values].sort((a, b) => a - b);
175
+ const idx = Math.min(sorted.length - 1, Math.ceil(sorted.length * 0.95) - 1);
176
+ return sorted[Math.max(0, idx)];
177
+ }
178
+ function createCollector(options = {}) {
179
+ const apiKey = options.apiKey ?? getEnv2("DEPLOZE_INGEST_KEY");
180
+ const endpoint = options.endpoint ?? getEnv2("DEPLOZE_INGEST_URL") ?? DEFAULT_ENDPOINT;
181
+ let flushIntervalMs = options.flushIntervalMs ?? DEFAULT_FLUSH_INTERVAL_MS;
182
+ let maxBuckets = DEFAULT_MAX_BUCKETS;
183
+ let maxErrorSamples = DEFAULT_MAX_ERROR_SAMPLES;
184
+ const now = options.now ?? Date.now;
185
+ const autoFlush = options.autoFlush !== false;
186
+ const buckets = /* @__PURE__ */ new Map();
187
+ const errorSamples = /* @__PURE__ */ new Map();
188
+ let timer = null;
189
+ let flushing = false;
190
+ const isLocalDev = getEnv2("NODE_ENV") === "development" && getEnv2("DEPLOZE_ENABLE_DEV") !== "1";
191
+ const enabled = Boolean(apiKey) && !isLocalDev;
192
+ if (!enabled) {
193
+ return {
194
+ record() {
195
+ },
196
+ async flush() {
197
+ },
198
+ stop() {
199
+ },
200
+ pendingBucketCount: () => 0
201
+ };
202
+ }
203
+ const transport = {
204
+ endpoint,
205
+ apiKey,
206
+ fetchImpl: options.fetchImpl
207
+ };
208
+ function startTimer(intervalMs) {
209
+ if (!autoFlush) return;
210
+ if (timer) {
211
+ clearInterval(timer);
212
+ timer = null;
213
+ }
214
+ timer = setInterval(() => {
215
+ void flush();
216
+ }, intervalMs);
217
+ if (typeof timer === "object" && "unref" in timer) {
218
+ timer.unref();
219
+ }
220
+ }
221
+ function applyConfig(config) {
222
+ if (!config) return;
223
+ if (typeof config.max_buckets === "number") {
224
+ maxBuckets = config.max_buckets;
225
+ }
226
+ if (typeof config.max_error_samples === "number") {
227
+ maxErrorSamples = config.max_error_samples;
228
+ }
229
+ if (typeof config.flush_interval_ms === "number" && config.flush_interval_ms !== flushIntervalMs) {
230
+ flushIntervalMs = config.flush_interval_ms;
231
+ startTimer(flushIntervalMs);
232
+ }
233
+ }
234
+ function record(input) {
235
+ try {
236
+ const status = Number(input.status);
237
+ if (!Number.isFinite(status)) return;
238
+ const path = normalizePathPattern(input.path ?? null);
239
+ const minute = new Date(Math.floor(now() / 6e4) * 6e4).toISOString();
240
+ const key = `${minute}|${path}`;
241
+ let bucket = buckets.get(key);
242
+ if (!bucket) {
243
+ if (buckets.size >= maxBuckets) return;
244
+ bucket = {
245
+ path,
246
+ minute,
247
+ count: 0,
248
+ e5xx: 0,
249
+ e4xx: 0,
250
+ latencySum: 0,
251
+ latencyCount: 0,
252
+ reservoir: [],
253
+ seen: 0
254
+ };
255
+ buckets.set(key, bucket);
256
+ }
257
+ bucket.count += 1;
258
+ if (status >= 500) bucket.e5xx += 1;
259
+ else if (status >= 400) bucket.e4xx += 1;
260
+ const duration = Number(input.durationMs);
261
+ if (Number.isFinite(duration) && duration >= 0) {
262
+ bucket.latencySum += duration;
263
+ bucket.latencyCount += 1;
264
+ bucket.seen += 1;
265
+ if (bucket.reservoir.length < RESERVOIR_SIZE) {
266
+ bucket.reservoir.push(duration);
267
+ } else {
268
+ const j = Math.floor(Math.random() * bucket.seen);
269
+ if (j < RESERVOIR_SIZE) bucket.reservoir[j] = duration;
270
+ }
271
+ }
272
+ if (status >= 500 && input.errorMessage) {
273
+ const pattern = normalizeErrorSignature(input.errorMessage);
274
+ const existing = errorSamples.get(`${path}|${pattern}`);
275
+ if (existing) {
276
+ existing.count += 1;
277
+ } else if (errorSamples.size < maxErrorSamples) {
278
+ errorSamples.set(`${path}|${pattern}`, {
279
+ path,
280
+ pattern,
281
+ sample: input.errorMessage.slice(0, 1e3),
282
+ count: 1
283
+ });
284
+ }
285
+ }
286
+ } catch {
287
+ }
288
+ }
289
+ async function flush() {
290
+ if (flushing || buckets.size === 0 && errorSamples.size === 0) return;
291
+ flushing = true;
292
+ try {
293
+ const statRows = [...buckets.values()];
294
+ const errorRows = [...errorSamples.values()];
295
+ buckets.clear();
296
+ errorSamples.clear();
297
+ const payload = {
298
+ schema_version: SCHEMA_VERSION,
299
+ stats: statRows.map((b) => ({
300
+ path: b.path,
301
+ minute: b.minute,
302
+ total_requests: b.count,
303
+ error_count: b.e5xx,
304
+ client_error_count: b.e4xx,
305
+ avg_latency_ms: b.latencyCount > 0 ? Math.round(b.latencySum / b.latencyCount) : void 0,
306
+ p95_latency_ms: p95(b.reservoir)
307
+ })),
308
+ errors: errorRows.map((e) => ({
309
+ path: e.path,
310
+ error_pattern: e.pattern,
311
+ sample_message: e.sample,
312
+ count: e.count
313
+ }))
314
+ };
315
+ const result = await send(payload, transport);
316
+ if (result.ok) {
317
+ applyConfig(result.config);
318
+ }
319
+ } finally {
320
+ flushing = false;
321
+ }
322
+ }
323
+ function stop() {
324
+ if (timer) {
325
+ clearInterval(timer);
326
+ timer = null;
327
+ }
328
+ }
329
+ startTimer(flushIntervalMs);
330
+ return { record, flush, stop, pendingBucketCount: () => buckets.size };
331
+ }
332
+ function getEnv2(name) {
333
+ try {
334
+ return globalThis.process?.env?.[name];
335
+ } catch {
336
+ return void 0;
337
+ }
338
+ }
339
+ // Annotate the CommonJS export names for ESM import in node:
340
+ 0 && (module.exports = {
341
+ SCHEMA_VERSION,
342
+ createCollector,
343
+ getBuildId,
344
+ normalizeErrorSignature,
345
+ normalizePathPattern,
346
+ send
347
+ });
@@ -0,0 +1,127 @@
1
+ export { C as Collector, a as CollectorOptions, R as RecordInput, c as createCollector } from '../collector-BHP98_1d.cjs';
2
+
3
+ /**
4
+ * Path and error normalization.
5
+ *
6
+ * normalizePathPattern is a port of the server's canonical implementation
7
+ * (deploy/src/lib/monitoring/endpoint-monitoring.ts). The server re-runs
8
+ * normalization on ingest, so this is a bandwidth/cardinality optimization,
9
+ * not a trust boundary — but the outputs must match for buckets to merge.
10
+ */
11
+ declare function normalizePathPattern(path: string | null): string;
12
+ /**
13
+ * Collapse an error message into a stable signature for deduplication.
14
+ * Mirrors the server's normalizeErrorType (deploy/src/lib/deploy/baselines.ts).
15
+ */
16
+ declare function normalizeErrorSignature(message: string): string;
17
+
18
+ /**
19
+ * Wire-protocol types for POST /api/ingest.
20
+ *
21
+ * These are the shared contract between every Deploze SDK and the
22
+ * ingest server. Keep this module dependency-free so future SDKs
23
+ * (or non-JS ports following PROTOCOL.md) can mirror it exactly.
24
+ */
25
+ /** Current payload schema version. Bump when the wire shape changes incompatibly. */
26
+ declare const SCHEMA_VERSION: 1;
27
+ interface IngestStatRow {
28
+ path: string;
29
+ minute: string;
30
+ total_requests: number;
31
+ error_count: number;
32
+ client_error_count: number;
33
+ avg_latency_ms?: number;
34
+ p95_latency_ms?: number;
35
+ }
36
+ interface IngestErrorRow {
37
+ path: string;
38
+ error_pattern: string;
39
+ sample_message?: string;
40
+ count?: number;
41
+ }
42
+ interface IngestPayload {
43
+ /** Absent or 1 today; older SDKs omit it and the server defaults to 1. */
44
+ schema_version?: number;
45
+ stats: IngestStatRow[];
46
+ errors: IngestErrorRow[];
47
+ }
48
+ /**
49
+ * Server-pushed knobs. Every field is optional — SDKs MUST tolerate
50
+ * a partial or fully absent config and keep their current defaults.
51
+ */
52
+ interface RemoteConfig {
53
+ /** Flush interval in milliseconds (e.g. 30000). */
54
+ flush_interval_ms?: number;
55
+ /** Max distinct (minute, path) buckets kept in memory per flush. */
56
+ max_buckets?: number;
57
+ /** Max deduplicated error samples kept per flush. */
58
+ max_error_samples?: number;
59
+ }
60
+ interface IngestResponse {
61
+ received: number;
62
+ errors_received: number;
63
+ deploy_id: string | null;
64
+ upserted: number;
65
+ config?: RemoteConfig;
66
+ }
67
+ interface SendResult {
68
+ ok: boolean;
69
+ config?: RemoteConfig;
70
+ }
71
+
72
+ /**
73
+ * Fire-and-forget transport.
74
+ *
75
+ * Invariants:
76
+ * - NEVER throws — a monitoring SDK must not be able to crash the host app.
77
+ * - Bounded time: 3s timeout per flush attempt.
78
+ * - No retry queue: on failure the payload is dropped (the next flush
79
+ * carries fresh data; losing one 30s bucket is acceptable by design).
80
+ * - On success, parses the JSON body for an optional remote-config object
81
+ * the collector can apply without an SDK version bump.
82
+ */
83
+
84
+ interface TransportOptions {
85
+ endpoint: string;
86
+ apiKey: string;
87
+ timeoutMs?: number;
88
+ /** Injectable for tests */
89
+ fetchImpl?: typeof fetch;
90
+ }
91
+ declare function send(payload: IngestPayload, options: TransportOptions): Promise<SendResult>;
92
+
93
+ /**
94
+ * Best-effort build identity (git commit SHA) for deploy attribution.
95
+ *
96
+ * Resolution order (first match wins):
97
+ * 1. `DEPLOZE_GIT_SHA` — explicit, user-set (e.g. `$GITHUB_SHA` / `$CI_COMMIT_SHA`
98
+ * wired into the deploy env). Always trusted over auto-detection.
99
+ * 2. `VERCEL_GIT_COMMIT_SHA` — free on Vercel, no setup required.
100
+ * 3. `.build-id.json` written by this package's postinstall script at
101
+ * `npm install` time (best effort — see postinstall.cjs for caveats
102
+ * around dependency caching and missing `.git`).
103
+ *
104
+ * Never throws — a missing/unreadable value just means no identity is sent.
105
+ *
106
+ * IMPORTANT — Edge safety: Next.js bundles this module for the Edge runtime
107
+ * too (any app with edge middleware compiles `instrumentation.ts` for both
108
+ * runtimes), and Edge has no Node builtins. It's not enough to dodge the
109
+ * *build* error (e.g. via `webpackIgnore`) — Vercel's Edge Function
110
+ * packager separately scans the compiled bundle *text* for `fs`/`path`/`url`
111
+ * specifiers and refuses to deploy if it finds them, even if the code
112
+ * calling them is unreachable at runtime.
113
+ *
114
+ * The fix is to gate the dynamic imports behind
115
+ * `process.env.NEXT_RUNTIME !== 'edge'`. Next.js's webpack config replaces
116
+ * `process.env.NEXT_RUNTIME` with a literal string per compile target via
117
+ * `DefinePlugin`, and webpack's `ConstPlugin` then eliminates the resulting
118
+ * dead `if` branch — including the dynamic imports inside it — during the
119
+ * dependency-collection ("make") phase, *before* module resolution runs.
120
+ * So for the Edge compile pass the import specifiers never make it into the
121
+ * output at all. (Do NOT add `webpackIgnore` here — that suppresses the
122
+ * resolution error but leaves the specifier text in the bundle, which is
123
+ * exactly what trips Vercel's Edge Function scanner.)
124
+ */
125
+ declare function getBuildId(): Promise<string | null>;
126
+
127
+ export { type IngestErrorRow, type IngestPayload, type IngestResponse, type IngestStatRow, type RemoteConfig, SCHEMA_VERSION, type SendResult, type TransportOptions, getBuildId, normalizeErrorSignature, normalizePathPattern, send };
@@ -0,0 +1,127 @@
1
+ export { C as Collector, a as CollectorOptions, R as RecordInput, c as createCollector } from '../collector-BHP98_1d.js';
2
+
3
+ /**
4
+ * Path and error normalization.
5
+ *
6
+ * normalizePathPattern is a port of the server's canonical implementation
7
+ * (deploy/src/lib/monitoring/endpoint-monitoring.ts). The server re-runs
8
+ * normalization on ingest, so this is a bandwidth/cardinality optimization,
9
+ * not a trust boundary — but the outputs must match for buckets to merge.
10
+ */
11
+ declare function normalizePathPattern(path: string | null): string;
12
+ /**
13
+ * Collapse an error message into a stable signature for deduplication.
14
+ * Mirrors the server's normalizeErrorType (deploy/src/lib/deploy/baselines.ts).
15
+ */
16
+ declare function normalizeErrorSignature(message: string): string;
17
+
18
+ /**
19
+ * Wire-protocol types for POST /api/ingest.
20
+ *
21
+ * These are the shared contract between every Deploze SDK and the
22
+ * ingest server. Keep this module dependency-free so future SDKs
23
+ * (or non-JS ports following PROTOCOL.md) can mirror it exactly.
24
+ */
25
+ /** Current payload schema version. Bump when the wire shape changes incompatibly. */
26
+ declare const SCHEMA_VERSION: 1;
27
+ interface IngestStatRow {
28
+ path: string;
29
+ minute: string;
30
+ total_requests: number;
31
+ error_count: number;
32
+ client_error_count: number;
33
+ avg_latency_ms?: number;
34
+ p95_latency_ms?: number;
35
+ }
36
+ interface IngestErrorRow {
37
+ path: string;
38
+ error_pattern: string;
39
+ sample_message?: string;
40
+ count?: number;
41
+ }
42
+ interface IngestPayload {
43
+ /** Absent or 1 today; older SDKs omit it and the server defaults to 1. */
44
+ schema_version?: number;
45
+ stats: IngestStatRow[];
46
+ errors: IngestErrorRow[];
47
+ }
48
+ /**
49
+ * Server-pushed knobs. Every field is optional — SDKs MUST tolerate
50
+ * a partial or fully absent config and keep their current defaults.
51
+ */
52
+ interface RemoteConfig {
53
+ /** Flush interval in milliseconds (e.g. 30000). */
54
+ flush_interval_ms?: number;
55
+ /** Max distinct (minute, path) buckets kept in memory per flush. */
56
+ max_buckets?: number;
57
+ /** Max deduplicated error samples kept per flush. */
58
+ max_error_samples?: number;
59
+ }
60
+ interface IngestResponse {
61
+ received: number;
62
+ errors_received: number;
63
+ deploy_id: string | null;
64
+ upserted: number;
65
+ config?: RemoteConfig;
66
+ }
67
+ interface SendResult {
68
+ ok: boolean;
69
+ config?: RemoteConfig;
70
+ }
71
+
72
+ /**
73
+ * Fire-and-forget transport.
74
+ *
75
+ * Invariants:
76
+ * - NEVER throws — a monitoring SDK must not be able to crash the host app.
77
+ * - Bounded time: 3s timeout per flush attempt.
78
+ * - No retry queue: on failure the payload is dropped (the next flush
79
+ * carries fresh data; losing one 30s bucket is acceptable by design).
80
+ * - On success, parses the JSON body for an optional remote-config object
81
+ * the collector can apply without an SDK version bump.
82
+ */
83
+
84
+ interface TransportOptions {
85
+ endpoint: string;
86
+ apiKey: string;
87
+ timeoutMs?: number;
88
+ /** Injectable for tests */
89
+ fetchImpl?: typeof fetch;
90
+ }
91
+ declare function send(payload: IngestPayload, options: TransportOptions): Promise<SendResult>;
92
+
93
+ /**
94
+ * Best-effort build identity (git commit SHA) for deploy attribution.
95
+ *
96
+ * Resolution order (first match wins):
97
+ * 1. `DEPLOZE_GIT_SHA` — explicit, user-set (e.g. `$GITHUB_SHA` / `$CI_COMMIT_SHA`
98
+ * wired into the deploy env). Always trusted over auto-detection.
99
+ * 2. `VERCEL_GIT_COMMIT_SHA` — free on Vercel, no setup required.
100
+ * 3. `.build-id.json` written by this package's postinstall script at
101
+ * `npm install` time (best effort — see postinstall.cjs for caveats
102
+ * around dependency caching and missing `.git`).
103
+ *
104
+ * Never throws — a missing/unreadable value just means no identity is sent.
105
+ *
106
+ * IMPORTANT — Edge safety: Next.js bundles this module for the Edge runtime
107
+ * too (any app with edge middleware compiles `instrumentation.ts` for both
108
+ * runtimes), and Edge has no Node builtins. It's not enough to dodge the
109
+ * *build* error (e.g. via `webpackIgnore`) — Vercel's Edge Function
110
+ * packager separately scans the compiled bundle *text* for `fs`/`path`/`url`
111
+ * specifiers and refuses to deploy if it finds them, even if the code
112
+ * calling them is unreachable at runtime.
113
+ *
114
+ * The fix is to gate the dynamic imports behind
115
+ * `process.env.NEXT_RUNTIME !== 'edge'`. Next.js's webpack config replaces
116
+ * `process.env.NEXT_RUNTIME` with a literal string per compile target via
117
+ * `DefinePlugin`, and webpack's `ConstPlugin` then eliminates the resulting
118
+ * dead `if` branch — including the dynamic imports inside it — during the
119
+ * dependency-collection ("make") phase, *before* module resolution runs.
120
+ * So for the Edge compile pass the import specifiers never make it into the
121
+ * output at all. (Do NOT add `webpackIgnore` here — that suppresses the
122
+ * resolution error but leaves the specifier text in the bundle, which is
123
+ * exactly what trips Vercel's Edge Function scanner.)
124
+ */
125
+ declare function getBuildId(): Promise<string | null>;
126
+
127
+ export { type IngestErrorRow, type IngestPayload, type IngestResponse, type IngestStatRow, type RemoteConfig, SCHEMA_VERSION, type SendResult, type TransportOptions, getBuildId, normalizeErrorSignature, normalizePathPattern, send };
@@ -0,0 +1,16 @@
1
+ import {
2
+ SCHEMA_VERSION,
3
+ createCollector,
4
+ getBuildId,
5
+ normalizeErrorSignature,
6
+ normalizePathPattern,
7
+ send
8
+ } from "../chunk-2ZXSSRDV.js";
9
+ export {
10
+ SCHEMA_VERSION,
11
+ createCollector,
12
+ getBuildId,
13
+ normalizeErrorSignature,
14
+ normalizePathPattern,
15
+ send
16
+ };