@interfere/next 3.0.0 → 4.0.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/dist/_virtual/_rolldown/runtime.mjs +13 -0
- package/dist/config.d.mts +21 -0
- package/dist/config.d.mts.map +1 -0
- package/dist/config.mjs +103 -0
- package/dist/config.mjs.map +1 -0
- package/dist/instrument-client.d.mts +3 -0
- package/dist/instrument-client.mjs +2 -0
- package/dist/internal/build/configure-build.d.mts +25 -0
- package/dist/internal/build/configure-build.d.mts.map +1 -0
- package/dist/internal/build/configure-build.mjs +87 -0
- package/dist/internal/build/configure-build.mjs.map +1 -0
- package/dist/internal/build/pipeline.d.mts +49 -0
- package/dist/internal/build/pipeline.d.mts.map +1 -0
- package/dist/internal/build/pipeline.mjs +67 -0
- package/dist/internal/build/pipeline.mjs.map +1 -0
- package/dist/internal/build/release/destinations/vercel.d.mts +6 -0
- package/dist/internal/build/release/destinations/vercel.d.mts.map +1 -0
- package/dist/internal/build/release/destinations/vercel.mjs +25 -0
- package/dist/internal/build/release/destinations/vercel.mjs.map +1 -0
- package/dist/internal/build/release/git.d.mts +4 -0
- package/dist/internal/build/release/git.d.mts.map +1 -0
- package/dist/internal/build/release/git.mjs +21 -0
- package/dist/internal/build/release/git.mjs.map +1 -0
- package/dist/internal/build/release/index.d.mts +8 -0
- package/dist/internal/build/release/index.d.mts.map +1 -0
- package/dist/internal/build/release/index.mjs +18 -0
- package/dist/internal/build/release/index.mjs.map +1 -0
- package/dist/internal/build/release/sources/github.d.mts +6 -0
- package/dist/internal/build/release/sources/github.d.mts.map +1 -0
- package/dist/internal/build/release/sources/github.mjs +15 -0
- package/dist/internal/build/release/sources/github.mjs.map +1 -0
- package/dist/internal/build/source-maps/discover.d.mts +15 -0
- package/dist/internal/build/source-maps/discover.d.mts.map +1 -0
- package/dist/internal/build/source-maps/discover.mjs +62 -0
- package/dist/internal/build/source-maps/discover.mjs.map +1 -0
- package/dist/internal/build/source-maps/index.d.mts +26 -0
- package/dist/internal/build/source-maps/index.d.mts.map +1 -0
- package/dist/internal/build/source-maps/index.mjs +28 -0
- package/dist/internal/build/source-maps/index.mjs.map +1 -0
- package/dist/internal/build/value-injection-loader.d.mts +13 -0
- package/dist/internal/build/value-injection-loader.d.mts.map +1 -0
- package/dist/internal/build/value-injection-loader.mjs +24 -0
- package/dist/internal/build/value-injection-loader.mjs.map +1 -0
- package/dist/internal/env.d.mts +16 -0
- package/dist/internal/env.d.mts.map +1 -0
- package/dist/internal/env.mjs +19 -0
- package/dist/internal/env.mjs.map +1 -0
- package/dist/internal/logger.d.mts +9 -0
- package/dist/internal/logger.d.mts.map +1 -0
- package/dist/internal/logger.mjs +60 -0
- package/dist/internal/logger.mjs.map +1 -0
- package/dist/internal/route/handle-get.d.mts +4 -0
- package/dist/internal/route/handle-get.d.mts.map +1 -0
- package/dist/internal/route/handle-get.mjs +15 -0
- package/dist/internal/route/handle-get.mjs.map +1 -0
- package/dist/internal/route/handle-post.d.mts +4 -0
- package/dist/internal/route/handle-post.d.mts.map +1 -0
- package/dist/internal/route/handle-post.mjs +123 -0
- package/dist/internal/route/handle-post.mjs.map +1 -0
- package/dist/internal/route/sw-script.d.mts +4 -0
- package/dist/internal/route/sw-script.d.mts.map +1 -0
- package/dist/internal/route/sw-script.mjs +38 -0
- package/dist/internal/route/sw-script.mjs.map +1 -0
- package/dist/internal/server/capture.d.mts +9 -0
- package/dist/internal/server/capture.d.mts.map +1 -0
- package/dist/internal/server/capture.mjs +50 -0
- package/dist/internal/server/capture.mjs.map +1 -0
- package/dist/internal/server/dedupe.d.mts +5 -0
- package/dist/internal/server/dedupe.d.mts.map +1 -0
- package/dist/internal/server/dedupe.mjs +11 -0
- package/dist/internal/server/dedupe.mjs.map +1 -0
- package/dist/internal/server/envelope.d.mts +14 -0
- package/dist/internal/server/envelope.d.mts.map +1 -0
- package/dist/internal/server/envelope.mjs +55 -0
- package/dist/internal/server/envelope.mjs.map +1 -0
- package/dist/internal/server/normalize-request.d.mts +7 -0
- package/dist/internal/server/normalize-request.d.mts.map +1 -0
- package/dist/internal/server/normalize-request.mjs +50 -0
- package/dist/internal/server/normalize-request.mjs.map +1 -0
- package/dist/internal/server/runtime.d.mts +14 -0
- package/dist/internal/server/runtime.d.mts.map +1 -0
- package/dist/internal/server/runtime.mjs +18 -0
- package/dist/internal/server/runtime.mjs.map +1 -0
- package/dist/internal/server/transport.d.mts +12 -0
- package/dist/internal/server/transport.d.mts.map +1 -0
- package/dist/internal/server/transport.mjs +17 -0
- package/dist/internal/server/transport.mjs.map +1 -0
- package/dist/internal/server/types.d.mts +17 -0
- package/dist/internal/server/types.d.mts.map +1 -0
- package/dist/internal/server/types.mjs +1 -0
- package/dist/provider.d.mts +3 -0
- package/dist/provider.mjs +3 -0
- package/dist/route-handler.d.mts +7 -0
- package/dist/route-handler.d.mts.map +1 -0
- package/dist/route-handler.mjs +26 -0
- package/dist/route-handler.mjs.map +1 -0
- package/dist/server.d.mts +3 -0
- package/dist/server.mjs +2 -0
- package/package.json +26 -26
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { isAbsolute, join, relative, resolve } from "node:path";
|
|
2
|
+
import { readFile, readdir } from "node:fs/promises";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
//#region src/internal/build/source-maps/discover.ts
|
|
5
|
+
const SOURCEMAPPING_RE = /\/\/[#@]\s*sourceMappingURL=(\S+)\s*$/;
|
|
6
|
+
function resolveDistDir(projectDir, distDir) {
|
|
7
|
+
return isAbsolute(distDir) ? distDir : resolve(projectDir, distDir);
|
|
8
|
+
}
|
|
9
|
+
async function findJsFiles(dir) {
|
|
10
|
+
return (await readdir(dir, { recursive: true }).catch(() => [])).filter((entry) => entry.endsWith(".js")).map((entry) => join(dir, entry));
|
|
11
|
+
}
|
|
12
|
+
async function discover(projectDir, distDir) {
|
|
13
|
+
const absDistDir = resolveDistDir(projectDir, distDir);
|
|
14
|
+
const relDistDir = relative(projectDir, absDistDir);
|
|
15
|
+
const [staticFiles, serverFiles] = await Promise.all([findJsFiles(join(absDistDir, "static")), findJsFiles(join(absDistDir, "server"))]);
|
|
16
|
+
const jsPaths = [...staticFiles, ...serverFiles];
|
|
17
|
+
const mapping = {};
|
|
18
|
+
const mapAbsolutes = /* @__PURE__ */ new Map();
|
|
19
|
+
for (const jsAbs of jsPaths) {
|
|
20
|
+
const content = await readFile(jsAbs, "utf8");
|
|
21
|
+
const match = SOURCEMAPPING_RE.exec(content);
|
|
22
|
+
if (!match?.[1]) continue;
|
|
23
|
+
const mapAbs = `${jsAbs.slice(0, jsAbs.lastIndexOf("/") + 1)}${decodeURIComponent(match[1])}`;
|
|
24
|
+
const jsPublic = toPublicPath(relative(projectDir, jsAbs), relDistDir);
|
|
25
|
+
const mapPublic = toPublicPath(relative(projectDir, mapAbs), relDistDir);
|
|
26
|
+
mapping[mapPublic] = jsPublic;
|
|
27
|
+
mapAbsolutes.set(mapPublic, mapAbs);
|
|
28
|
+
}
|
|
29
|
+
const loaded = (await Promise.all([...mapAbsolutes.entries()].map(async ([mapPublic, mapAbs]) => {
|
|
30
|
+
const content = await readFile(mapAbs, "utf8").catch(() => null);
|
|
31
|
+
if (content === null) return null;
|
|
32
|
+
return {
|
|
33
|
+
absolute: mapAbs,
|
|
34
|
+
path: mapPublic,
|
|
35
|
+
content,
|
|
36
|
+
hash: createHash("sha256").update(content).digest("hex")
|
|
37
|
+
};
|
|
38
|
+
}))).filter((f) => f !== null);
|
|
39
|
+
const validMapping = {};
|
|
40
|
+
for (const file of loaded) {
|
|
41
|
+
const js = mapping[file.path];
|
|
42
|
+
if (js) validMapping[file.path] = js;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
files: loaded,
|
|
46
|
+
mapping: validMapping,
|
|
47
|
+
sourceFileCount: mapAbsolutes.size
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function normalizeDistDir(distDir = ".next") {
|
|
51
|
+
let d = distDir.split("\\").join("/");
|
|
52
|
+
while (d.startsWith("./")) d = d.slice(2);
|
|
53
|
+
return d;
|
|
54
|
+
}
|
|
55
|
+
function toPublicPath(rel, distDir) {
|
|
56
|
+
const p = rel.split("\\").join("/");
|
|
57
|
+
if (p.startsWith(`${distDir}/`)) return `_next/${p.slice(distDir.length + 1)}`;
|
|
58
|
+
if (p.startsWith(".next/")) return `_next/${p.slice(6)}`;
|
|
59
|
+
return p;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
export { discover, normalizeDistDir };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discover.mjs","names":[],"sources":["../../../../src/internal/build/source-maps/discover.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { readFile, readdir } from \"node:fs/promises\";\nimport { isAbsolute, join, relative, resolve } from \"node:path\";\n\nconst SOURCEMAPPING_RE = /\\/\\/[#@]\\s*sourceMappingURL=(\\S+)\\s*$/;\n\nexport type SourceMapFile = {\n readonly absolute: string;\n readonly path: string;\n readonly content: string;\n readonly hash: string;\n};\n\nfunction resolveDistDir(projectDir: string, distDir: string) {\n return isAbsolute(distDir) ? distDir : resolve(projectDir, distDir);\n}\n\nasync function findJsFiles(dir: string) {\n const entries = await readdir(dir, { recursive: true }).catch(\n () => [] as string[]\n );\n return entries\n .filter((entry) => entry.endsWith(\".js\"))\n .map((entry) => join(dir, entry));\n}\n\nexport async function discover(projectDir: string, distDir: string) {\n const absDistDir = resolveDistDir(projectDir, distDir);\n const relDistDir = relative(projectDir, absDistDir);\n\n const [staticFiles, serverFiles] = await Promise.all([\n findJsFiles(join(absDistDir, \"static\")),\n findJsFiles(join(absDistDir, \"server\")),\n ]);\n\n const jsPaths = [...staticFiles, ...serverFiles];\n\n const mapping: Record<string, string> = {};\n const mapAbsolutes = new Map<string, string>();\n\n for (const jsAbs of jsPaths) {\n const content = await readFile(jsAbs, \"utf8\");\n const match = SOURCEMAPPING_RE.exec(content);\n if (!match?.[1]) continue;\n\n const jsDir = jsAbs.slice(0, jsAbs.lastIndexOf(\"/\") + 1);\n const mapRef = decodeURIComponent(match[1]);\n const mapAbs = `${jsDir}${mapRef}`;\n const jsPublic = toPublicPath(relative(projectDir, jsAbs), relDistDir);\n const mapPublic = toPublicPath(relative(projectDir, mapAbs), relDistDir);\n\n mapping[mapPublic] = jsPublic;\n mapAbsolutes.set(mapPublic, mapAbs);\n }\n\n const files = await Promise.all(\n [...mapAbsolutes.entries()].map(async ([mapPublic, mapAbs]) => {\n const content = await readFile(mapAbs, \"utf8\").catch(() => null);\n if (content === null) return null;\n\n return {\n absolute: mapAbs,\n path: mapPublic,\n content,\n hash: createHash(\"sha256\").update(content).digest(\"hex\"),\n };\n }),\n );\n\n const loaded = files.filter((f): f is SourceMapFile => f !== null);\n\n const validMapping: Record<string, string> = {};\n for (const file of loaded) {\n const js = mapping[file.path];\n if (js) validMapping[file.path] = js;\n }\n\n return { files: loaded, mapping: validMapping, sourceFileCount: mapAbsolutes.size };\n}\n\nexport function normalizeDistDir(distDir = \".next\") {\n let d = distDir.split(\"\\\\\").join(\"/\");\n while (d.startsWith(\"./\")) d = d.slice(2);\n return d;\n}\n\nfunction toPublicPath(rel: string, distDir: string) {\n const p = rel.split(\"\\\\\").join(\"/\");\n if (p.startsWith(`${distDir}/`)) return `_next/${p.slice(distDir.length + 1)}`;\n if (p.startsWith(\".next/\")) return `_next/${p.slice(6)}`;\n return p;\n}\n"],"mappings":";;;;AAIA,MAAM,mBAAmB;AASzB,SAAS,eAAe,YAAoB,SAAiB;AAC3D,QAAO,WAAW,QAAQ,GAAG,UAAU,QAAQ,YAAY,QAAQ;;AAGrE,eAAe,YAAY,KAAa;AAItC,SAHgB,MAAM,QAAQ,KAAK,EAAE,WAAW,MAAM,CAAC,CAAC,YAChD,EAAE,CACT,EAEE,QAAQ,UAAU,MAAM,SAAS,MAAM,CAAC,CACxC,KAAK,UAAU,KAAK,KAAK,MAAM,CAAC;;AAGrC,eAAsB,SAAS,YAAoB,SAAiB;CAClE,MAAM,aAAa,eAAe,YAAY,QAAQ;CACtD,MAAM,aAAa,SAAS,YAAY,WAAW;CAEnD,MAAM,CAAC,aAAa,eAAe,MAAM,QAAQ,IAAI,CACnD,YAAY,KAAK,YAAY,SAAS,CAAC,EACvC,YAAY,KAAK,YAAY,SAAS,CAAC,CACxC,CAAC;CAEF,MAAM,UAAU,CAAC,GAAG,aAAa,GAAG,YAAY;CAEhD,MAAM,UAAkC,EAAE;CAC1C,MAAM,+BAAe,IAAI,KAAqB;AAE9C,MAAK,MAAM,SAAS,SAAS;EAC3B,MAAM,UAAU,MAAM,SAAS,OAAO,OAAO;EAC7C,MAAM,QAAQ,iBAAiB,KAAK,QAAQ;AAC5C,MAAI,CAAC,QAAQ,GAAI;EAIjB,MAAM,SAAS,GAFD,MAAM,MAAM,GAAG,MAAM,YAAY,IAAI,GAAG,EAAE,GACzC,mBAAmB,MAAM,GAAG;EAE3C,MAAM,WAAW,aAAa,SAAS,YAAY,MAAM,EAAE,WAAW;EACtE,MAAM,YAAY,aAAa,SAAS,YAAY,OAAO,EAAE,WAAW;AAExE,UAAQ,aAAa;AACrB,eAAa,IAAI,WAAW,OAAO;;CAiBrC,MAAM,UAdQ,MAAM,QAAQ,IAC1B,CAAC,GAAG,aAAa,SAAS,CAAC,CAAC,IAAI,OAAO,CAAC,WAAW,YAAY;EAC7D,MAAM,UAAU,MAAM,SAAS,QAAQ,OAAO,CAAC,YAAY,KAAK;AAChE,MAAI,YAAY,KAAM,QAAO;AAE7B,SAAO;GACL,UAAU;GACV,MAAM;GACN;GACA,MAAM,WAAW,SAAS,CAAC,OAAO,QAAQ,CAAC,OAAO,MAAM;GACzD;GACD,CACH,EAEoB,QAAQ,MAA0B,MAAM,KAAK;CAElE,MAAM,eAAuC,EAAE;AAC/C,MAAK,MAAM,QAAQ,QAAQ;EACzB,MAAM,KAAK,QAAQ,KAAK;AACxB,MAAI,GAAI,cAAa,KAAK,QAAQ;;AAGpC,QAAO;EAAE,OAAO;EAAQ,SAAS;EAAc,iBAAiB,aAAa;EAAM;;AAGrF,SAAgB,iBAAiB,UAAU,SAAS;CAClD,IAAI,IAAI,QAAQ,MAAM,KAAK,CAAC,KAAK,IAAI;AACrC,QAAO,EAAE,WAAW,KAAK,CAAE,KAAI,EAAE,MAAM,EAAE;AACzC,QAAO;;AAGT,SAAS,aAAa,KAAa,SAAiB;CAClD,MAAM,IAAI,IAAI,MAAM,KAAK,CAAC,KAAK,IAAI;AACnC,KAAI,EAAE,WAAW,GAAG,QAAQ,GAAG,CAAE,QAAO,SAAS,EAAE,MAAM,QAAQ,SAAS,EAAE;AAC5E,KAAI,EAAE,WAAW,SAAS,CAAE,QAAO,SAAS,EAAE,MAAM,EAAE;AACtD,QAAO"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SourceMapFile, discover, normalizeDistDir } from "./discover.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/internal/build/source-maps/index.d.ts
|
|
4
|
+
declare function buildUploadBody(discovered: {
|
|
5
|
+
files: SourceMapFile[];
|
|
6
|
+
mapping: Record<string, string>;
|
|
7
|
+
sourceFileCount: number;
|
|
8
|
+
}): {
|
|
9
|
+
body: {
|
|
10
|
+
files: {
|
|
11
|
+
fileName: string;
|
|
12
|
+
content: Blob;
|
|
13
|
+
}[];
|
|
14
|
+
metadata: {
|
|
15
|
+
sourceMapToGenerated: Record<string, string>;
|
|
16
|
+
hashes: {
|
|
17
|
+
[k: string]: string;
|
|
18
|
+
};
|
|
19
|
+
sourceFileCount: number;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
totalBytes: number;
|
|
23
|
+
};
|
|
24
|
+
declare function cleanupSourceMaps(files: SourceMapFile[]): Promise<void>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { type SourceMapFile, buildUploadBody, cleanupSourceMaps, discover, normalizeDistDir };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../../src/internal/build/source-maps/index.ts"],"mappings":";;;iBAMgB,eAAA,CAAgB,UAAA;EAC9B,KAAA,EAAO,aAAA;EACP,OAAA,EAAS,MAAA;EACT,eAAA;AAAA;;;;;;;;;;;;;;;;iBAqBoB,iBAAA,CAAkB,KAAA,EAAO,aAAA,KAAe,OAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { discover, normalizeDistDir } from "./discover.mjs";
|
|
2
|
+
import { unlink } from "node:fs/promises";
|
|
3
|
+
//#region src/internal/build/source-maps/index.ts
|
|
4
|
+
function buildUploadBody(discovered) {
|
|
5
|
+
let totalBytes = 0;
|
|
6
|
+
return {
|
|
7
|
+
body: {
|
|
8
|
+
files: discovered.files.map((file) => {
|
|
9
|
+
totalBytes += file.content.length;
|
|
10
|
+
return {
|
|
11
|
+
fileName: file.path,
|
|
12
|
+
content: new Blob([file.content], { type: "application/json" })
|
|
13
|
+
};
|
|
14
|
+
}),
|
|
15
|
+
metadata: {
|
|
16
|
+
sourceMapToGenerated: discovered.mapping,
|
|
17
|
+
hashes: Object.fromEntries(discovered.files.map((f) => [f.path, f.hash])),
|
|
18
|
+
sourceFileCount: discovered.sourceFileCount
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
totalBytes
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
async function cleanupSourceMaps(files) {
|
|
25
|
+
await Promise.all(files.map((f) => unlink(f.absolute).catch(() => void 0)));
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { buildUploadBody, cleanupSourceMaps, discover, normalizeDistDir };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/internal/build/source-maps/index.ts"],"sourcesContent":["import { unlink } from \"node:fs/promises\";\n\nimport type { SourceMapFile } from \"./discover.js\";\n\nexport { discover, normalizeDistDir, type SourceMapFile } from \"./discover.js\";\n\nexport function buildUploadBody(discovered: {\n files: SourceMapFile[];\n mapping: Record<string, string>;\n sourceFileCount: number;\n}) {\n let totalBytes = 0;\n\n const files = discovered.files.map((file) => {\n totalBytes += file.content.length;\n return {\n fileName: file.path,\n content: new Blob([file.content], { type: \"application/json\" }),\n };\n });\n\n const metadata = {\n sourceMapToGenerated: discovered.mapping,\n hashes: Object.fromEntries(discovered.files.map((f) => [f.path, f.hash])),\n sourceFileCount: discovered.sourceFileCount,\n };\n\n return { body: { files, metadata }, totalBytes };\n}\n\nexport async function cleanupSourceMaps(files: SourceMapFile[]) {\n await Promise.all(files.map((f) => unlink(f.absolute).catch(() => undefined)));\n}\n"],"mappings":";;;AAMA,SAAgB,gBAAgB,YAI7B;CACD,IAAI,aAAa;AAgBjB,QAAO;EAAE,MAAM;GAAE,OAdH,WAAW,MAAM,KAAK,SAAS;AAC3C,kBAAc,KAAK,QAAQ;AAC3B,WAAO;KACL,UAAU,KAAK;KACf,SAAS,IAAI,KAAK,CAAC,KAAK,QAAQ,EAAE,EAAE,MAAM,oBAAoB,CAAC;KAChE;KACD;GAQsB,UANP;IACf,sBAAsB,WAAW;IACjC,QAAQ,OAAO,YAAY,WAAW,MAAM,KAAK,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACzE,iBAAiB,WAAW;IAC7B;GAEiC;EAAE;EAAY;;AAGlD,eAAsB,kBAAkB,OAAwB;AAC9D,OAAM,QAAQ,IAAI,MAAM,KAAK,MAAM,OAAO,EAAE,SAAS,CAAC,YAAY,KAAA,EAAU,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { InterfereInjectedValues } from "./configure-build.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/internal/build/value-injection-loader.d.ts
|
|
4
|
+
interface ValueInjectionLoaderOptions {
|
|
5
|
+
readonly values?: Partial<InterfereInjectedValues>;
|
|
6
|
+
readonly serializedValues?: string;
|
|
7
|
+
}
|
|
8
|
+
interface LoaderThis<T> {
|
|
9
|
+
getOptions(): T;
|
|
10
|
+
}
|
|
11
|
+
declare function valueInjectionLoader(this: LoaderThis<ValueInjectionLoaderOptions>, userCode: string): string;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { ValueInjectionLoaderOptions, valueInjectionLoader as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value-injection-loader.d.mts","names":[],"sources":["../../../src/internal/build/value-injection-loader.ts"],"mappings":";;;UAEiB,2BAAA;EAAA,SACN,MAAA,GAAS,OAAA,CAAQ,uBAAA;EAAA,SACjB,gBAAA;AAAA;AAAA,UAGD,UAAA;EACR,UAAA,IAAc,CAAA;AAAA;AAAA,iBAGQ,oBAAA,CACtB,IAAA,EAAM,UAAA,CAAW,2BAAA,GACjB,QAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/internal/build/value-injection-loader.ts
|
|
2
|
+
function valueInjectionLoader(userCode) {
|
|
3
|
+
const values = resolveValues(this.getOptions());
|
|
4
|
+
const lines = Object.entries(values).filter(([, value]) => value !== void 0).map(([key, value]) => {
|
|
5
|
+
return `globalThis["${key.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"] = ${JSON.stringify(value)};`;
|
|
6
|
+
});
|
|
7
|
+
if (lines.length === 0) return userCode;
|
|
8
|
+
return `${lines.join("\n")}\n${userCode}`;
|
|
9
|
+
}
|
|
10
|
+
function resolveValues(options) {
|
|
11
|
+
if (typeof options.serializedValues === "string") try {
|
|
12
|
+
const parsed = JSON.parse(options.serializedValues);
|
|
13
|
+
if (isRecord(parsed)) return parsed;
|
|
14
|
+
return {};
|
|
15
|
+
} catch {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
return options.values ?? {};
|
|
19
|
+
}
|
|
20
|
+
function isRecord(value) {
|
|
21
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { valueInjectionLoader as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value-injection-loader.mjs","names":[],"sources":["../../../src/internal/build/value-injection-loader.ts"],"sourcesContent":["import type { InterfereInjectedValues } from \"./configure-build.js\";\n\nexport interface ValueInjectionLoaderOptions {\n readonly values?: Partial<InterfereInjectedValues>;\n readonly serializedValues?: string;\n}\n\ninterface LoaderThis<T> {\n getOptions(): T;\n}\n\nexport default function valueInjectionLoader(\n this: LoaderThis<ValueInjectionLoaderOptions>,\n userCode: string\n): string {\n const values = resolveValues(this.getOptions());\n const lines = Object.entries(values)\n .filter(([, value]) => value !== undefined)\n .map(([key, value]) => {\n const escapedKey = key.replace(/\\\\/g, \"\\\\\\\\\").replace(/\"/g, '\\\\\"');\n return `globalThis[\"${escapedKey}\"] = ${JSON.stringify(value)};`;\n });\n\n if (lines.length === 0) {\n return userCode;\n }\n\n return `${lines.join(\"\\n\")}\\n${userCode}`;\n}\n\nfunction resolveValues(options: ValueInjectionLoaderOptions): Record<string, unknown> {\n if (typeof options.serializedValues === \"string\") {\n try {\n const parsed = JSON.parse(options.serializedValues);\n if (isRecord(parsed)) {\n return parsed;\n }\n return {};\n } catch {\n return {};\n }\n }\n\n return options.values ?? {};\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n"],"mappings":";AAWA,SAAwB,qBAEtB,UACQ;CACR,MAAM,SAAS,cAAc,KAAK,YAAY,CAAC;CAC/C,MAAM,QAAQ,OAAO,QAAQ,OAAO,CACjC,QAAQ,GAAG,WAAW,UAAU,KAAA,EAAU,CAC1C,KAAK,CAAC,KAAK,WAAW;AAErB,SAAO,eADY,IAAI,QAAQ,OAAO,OAAO,CAAC,QAAQ,MAAM,OAAM,CACjC,OAAO,KAAK,UAAU,MAAM,CAAC;GAC9D;AAEJ,KAAI,MAAM,WAAW,EACnB,QAAO;AAGT,QAAO,GAAG,MAAM,KAAK,KAAK,CAAC,IAAI;;AAGjC,SAAS,cAAc,SAA+D;AACpF,KAAI,OAAO,QAAQ,qBAAqB,SACtC,KAAI;EACF,MAAM,SAAS,KAAK,MAAM,QAAQ,iBAAiB;AACnD,MAAI,SAAS,OAAO,CAClB,QAAO;AAET,SAAO,EAAE;SACH;AACN,SAAO,EAAE;;AAIb,QAAO,QAAQ,UAAU,EAAE;;AAG7B,SAAS,SAAS,OAAkD;AAClE,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Env } from "@interfere/types/sdk/runtime";
|
|
2
|
+
|
|
3
|
+
//#region src/internal/env.d.ts
|
|
4
|
+
interface InterfereEnv {
|
|
5
|
+
readonly apiKey: string | null;
|
|
6
|
+
readonly apiUrl: string;
|
|
7
|
+
readonly nextRuntime: string | null;
|
|
8
|
+
readonly nodeEnvironment: Exclude<Env, null>;
|
|
9
|
+
readonly release: {
|
|
10
|
+
readonly sourceId: string | null;
|
|
11
|
+
readonly destinationId: string | null;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
declare function readInterfereEnv(): InterfereEnv;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { InterfereEnv, readInterfereEnv };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.mts","names":[],"sources":["../../src/internal/env.ts"],"mappings":";;;UAKiB,YAAA;EAAA,SACN,MAAA;EAAA,SACA,MAAA;EAAA,SACA,WAAA;EAAA,SACA,eAAA,EAAiB,OAAA,CAAQ,GAAA;EAAA,SACzB,OAAA;IAAA,SACE,QAAA;IAAA,SACA,aAAA;EAAA;AAAA;AAAA,iBAIG,gBAAA,CAAA,GAAoB,YAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { API_URL } from "@interfere/constants/api";
|
|
2
|
+
import { parseEnvValue } from "@interfere/types/sdk/env";
|
|
3
|
+
import { normalizeEnv } from "@interfere/types/sdk/runtime";
|
|
4
|
+
//#region src/internal/env.ts
|
|
5
|
+
function readInterfereEnv() {
|
|
6
|
+
const nodeEnvironment = normalizeEnv(process.env.NODE_ENV) ?? "production";
|
|
7
|
+
return {
|
|
8
|
+
apiKey: parseEnvValue(process.env.INTERFERE_API_KEY),
|
|
9
|
+
apiUrl: parseEnvValue(process.env.INTERFERE_API_URL) ?? API_URL,
|
|
10
|
+
nextRuntime: parseEnvValue(process.env.NEXT_RUNTIME),
|
|
11
|
+
nodeEnvironment,
|
|
12
|
+
release: {
|
|
13
|
+
sourceId: parseEnvValue(process.env.NEXT_PUBLIC_INTERFERE_BUILD_ID),
|
|
14
|
+
destinationId: parseEnvValue(process.env.NEXT_PUBLIC_INTERFERE_RELEASE_ID)
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { readInterfereEnv };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.mjs","names":[],"sources":["../../src/internal/env.ts"],"sourcesContent":["import { API_URL } from \"@interfere/constants/api\";\nimport { parseEnvValue } from \"@interfere/types/sdk/env\";\nimport type { Env } from \"@interfere/types/sdk/runtime\";\nimport { normalizeEnv } from \"@interfere/types/sdk/runtime\";\n\nexport interface InterfereEnv {\n readonly apiKey: string | null;\n readonly apiUrl: string;\n readonly nextRuntime: string | null;\n readonly nodeEnvironment: Exclude<Env, null>;\n readonly release: {\n readonly sourceId: string | null;\n readonly destinationId: string | null;\n };\n}\n\nexport function readInterfereEnv(): InterfereEnv {\n const nodeEnvironment = normalizeEnv(process.env.NODE_ENV) ?? \"production\";\n\n return {\n apiKey: parseEnvValue(process.env.INTERFERE_API_KEY),\n apiUrl: parseEnvValue(process.env.INTERFERE_API_URL) ?? API_URL,\n nextRuntime: parseEnvValue(process.env.NEXT_RUNTIME),\n nodeEnvironment,\n release: {\n sourceId: parseEnvValue(process.env.NEXT_PUBLIC_INTERFERE_BUILD_ID),\n destinationId: parseEnvValue(\n process.env.NEXT_PUBLIC_INTERFERE_RELEASE_ID\n ),\n },\n };\n}\n"],"mappings":";;;;AAgBA,SAAgB,mBAAiC;CAC/C,MAAM,kBAAkB,aAAa,QAAQ,IAAI,SAAS,IAAI;AAE9D,QAAO;EACL,QAAQ,cAAc,QAAQ,IAAI,kBAAkB;EACpD,QAAQ,cAAc,QAAQ,IAAI,kBAAkB,IAAI;EACxD,aAAa,cAAc,QAAQ,IAAI,aAAa;EACpD;EACA,SAAS;GACP,UAAU,cAAc,QAAQ,IAAI,+BAA+B;GACnE,eAAe,cACb,QAAQ,IAAI,iCACb;GACF;EACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/internal/logger.d.ts
|
|
2
|
+
declare const log: {
|
|
3
|
+
info: (title: string, lines: string[]) => void;
|
|
4
|
+
warn: (title: string, lines: string[]) => void;
|
|
5
|
+
error: (title: string, lines: string[]) => void;
|
|
6
|
+
fatal(title: string, lines: string[]): never;
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { log };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.mts","names":[],"sources":["../../src/internal/logger.ts"],"mappings":";cA6Ea,GAAA;wBACS,KAAA;wBACA,KAAA;yBACC,KAAA;uBACF,KAAA;AAAA"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
//#region src/internal/logger.ts
|
|
3
|
+
const styles = {
|
|
4
|
+
info: {
|
|
5
|
+
prefix: `${chalk.whiteBright.bold("❖")}`,
|
|
6
|
+
text: chalk.cyan.bold,
|
|
7
|
+
content: chalk.white,
|
|
8
|
+
prependLevel: false
|
|
9
|
+
},
|
|
10
|
+
warn: {
|
|
11
|
+
prefix: `${chalk.yellow.bold("⚠")} `,
|
|
12
|
+
text: chalk.yellow.bold,
|
|
13
|
+
content: chalk.yellowBright,
|
|
14
|
+
prependLevel: false
|
|
15
|
+
},
|
|
16
|
+
error: {
|
|
17
|
+
prefix: `${chalk.red.bold("⨯")} `,
|
|
18
|
+
text: chalk.red.bold,
|
|
19
|
+
content: chalk.redBright,
|
|
20
|
+
prependLevel: true
|
|
21
|
+
},
|
|
22
|
+
fatal: {
|
|
23
|
+
prefix: `${chalk.red.bold("⨯")} `,
|
|
24
|
+
text: chalk.red.bold,
|
|
25
|
+
content: chalk.redBright,
|
|
26
|
+
prependLevel: true
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const consoleMethods = {
|
|
30
|
+
info: "log",
|
|
31
|
+
warn: "warn",
|
|
32
|
+
error: "error",
|
|
33
|
+
fatal: "error"
|
|
34
|
+
};
|
|
35
|
+
function isTestEnv() {
|
|
36
|
+
return Boolean(process.env.VITEST || process.env.VITEST_WORKER_ID);
|
|
37
|
+
}
|
|
38
|
+
function emit(level, title, lines) {
|
|
39
|
+
if (isTestEnv()) return;
|
|
40
|
+
const style = styles[level];
|
|
41
|
+
const method = consoleMethods[level];
|
|
42
|
+
const fn = globalThis.console[method];
|
|
43
|
+
if (typeof fn !== "function") return;
|
|
44
|
+
const invoke = (...args) => Reflect.apply(fn, globalThis.console, args);
|
|
45
|
+
const prependLevel = style.prependLevel ? `[${style.text(level.toUpperCase())}] ` : "";
|
|
46
|
+
invoke(`${prependLevel} ${chalk.white("Interfere →")} ${style.text(title)}`);
|
|
47
|
+
for (const [i, line] of lines.entries()) invoke(`${prependLevel} ${i === lines.length - 1 ? "└" : "├"} ${style.content(line)}`);
|
|
48
|
+
}
|
|
49
|
+
const log = {
|
|
50
|
+
info: (title, lines) => emit("info", title, lines),
|
|
51
|
+
warn: (title, lines) => emit("warn", title, lines),
|
|
52
|
+
error: (title, lines) => emit("error", title, lines),
|
|
53
|
+
fatal(title, lines) {
|
|
54
|
+
emit("fatal", title, lines);
|
|
55
|
+
if (isTestEnv()) throw new Error(title);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
//#endregion
|
|
60
|
+
export { log };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.mjs","names":[],"sources":["../../src/internal/logger.ts"],"sourcesContent":["import chalk from \"chalk\";\n\ntype LogLevel = \"info\" | \"warn\" | \"error\" | \"fatal\";\n\nconst styles = {\n info: {\n prefix: `${chalk.whiteBright.bold(\"❖\")}`,\n text: chalk.cyan.bold,\n content: chalk.white,\n prependLevel: false,\n },\n warn: {\n prefix: `${chalk.yellow.bold(\"⚠\")} `,\n text: chalk.yellow.bold,\n content: chalk.yellowBright,\n prependLevel: false,\n },\n error: {\n prefix: `${chalk.red.bold(\"⨯\")} `,\n text: chalk.red.bold,\n content: chalk.redBright,\n prependLevel: true,\n },\n fatal: {\n prefix: `${chalk.red.bold(\"⨯\")} `,\n text: chalk.red.bold,\n content: chalk.redBright,\n prependLevel: true,\n },\n} satisfies Record<\n LogLevel,\n {\n prefix: string;\n text: typeof chalk.bold;\n content: typeof chalk;\n prependLevel: boolean;\n }\n>;\n\nconst consoleMethods = {\n info: \"log\",\n warn: \"warn\",\n error: \"error\",\n fatal: \"error\",\n} satisfies Record<LogLevel, string>;\n\nfunction isTestEnv() {\n return Boolean(process.env.VITEST || process.env.VITEST_WORKER_ID);\n}\n\nfunction emit(level: LogLevel, title: string, lines: string[]) {\n if (isTestEnv()) {\n return;\n }\n\n const style = styles[level];\n const method = consoleMethods[level] as keyof Console;\n const fn = globalThis.console[method];\n if (typeof fn !== \"function\") {\n return;\n }\n\n const invoke = (...args: unknown[]) =>\n Reflect.apply(fn, globalThis.console, args);\n\n const prependLevel = style.prependLevel\n ? `[${style.text(level.toUpperCase())}] `\n : \"\";\n\n invoke(`${prependLevel} ${chalk.white(\"Interfere →\")} ${style.text(title)}`);\n\n for (const [i, line] of lines.entries()) {\n const connector = i === lines.length - 1 ? \"└\" : \"├\";\n invoke(`${prependLevel} ${connector} ${style.content(line)}`);\n }\n}\n\nexport const log = {\n info: (title: string, lines: string[]) => emit(\"info\", title, lines),\n warn: (title: string, lines: string[]) => emit(\"warn\", title, lines),\n error: (title: string, lines: string[]) => emit(\"error\", title, lines),\n fatal(title: string, lines: string[]): never {\n emit(\"fatal\", title, lines);\n\n if (isTestEnv()) {\n throw new Error(title);\n }\n\n process.exit(1);\n },\n};\n"],"mappings":";;AAIA,MAAM,SAAS;CACb,MAAM;EACJ,QAAQ,GAAG,MAAM,YAAY,KAAK,IAAI;EACtC,MAAM,MAAM,KAAK;EACjB,SAAS,MAAM;EACf,cAAc;EACf;CACD,MAAM;EACJ,QAAQ,GAAG,MAAM,OAAO,KAAK,IAAI,CAAC;EAClC,MAAM,MAAM,OAAO;EACnB,SAAS,MAAM;EACf,cAAc;EACf;CACD,OAAO;EACL,QAAQ,GAAG,MAAM,IAAI,KAAK,IAAI,CAAC;EAC/B,MAAM,MAAM,IAAI;EAChB,SAAS,MAAM;EACf,cAAc;EACf;CACD,OAAO;EACL,QAAQ,GAAG,MAAM,IAAI,KAAK,IAAI,CAAC;EAC/B,MAAM,MAAM,IAAI;EAChB,SAAS,MAAM;EACf,cAAc;EACf;CACF;AAUD,MAAM,iBAAiB;CACrB,MAAM;CACN,MAAM;CACN,OAAO;CACP,OAAO;CACR;AAED,SAAS,YAAY;AACnB,QAAO,QAAQ,QAAQ,IAAI,UAAU,QAAQ,IAAI,iBAAiB;;AAGpE,SAAS,KAAK,OAAiB,OAAe,OAAiB;AAC7D,KAAI,WAAW,CACb;CAGF,MAAM,QAAQ,OAAO;CACrB,MAAM,SAAS,eAAe;CAC9B,MAAM,KAAK,WAAW,QAAQ;AAC9B,KAAI,OAAO,OAAO,WAChB;CAGF,MAAM,UAAU,GAAG,SACjB,QAAQ,MAAM,IAAI,WAAW,SAAS,KAAK;CAE7C,MAAM,eAAe,MAAM,eACvB,IAAI,MAAM,KAAK,MAAM,aAAa,CAAC,CAAC,MACpC;AAEJ,QAAO,GAAG,aAAa,GAAG,MAAM,MAAM,cAAc,CAAC,GAAG,MAAM,KAAK,MAAM,GAAG;AAE5E,MAAK,MAAM,CAAC,GAAG,SAAS,MAAM,SAAS,CAErC,QAAO,GAAG,aAAa,GADL,MAAM,MAAM,SAAS,IAAI,MAAM,IACb,GAAG,MAAM,QAAQ,KAAK,GAAG;;AAIjE,MAAa,MAAM;CACjB,OAAO,OAAe,UAAoB,KAAK,QAAQ,OAAO,MAAM;CACpE,OAAO,OAAe,UAAoB,KAAK,QAAQ,OAAO,MAAM;CACpE,QAAQ,OAAe,UAAoB,KAAK,SAAS,OAAO,MAAM;CACtE,MAAM,OAAe,OAAwB;AAC3C,OAAK,SAAS,OAAO,MAAM;AAE3B,MAAI,WAAW,CACb,OAAM,IAAI,MAAM,MAAM;AAGxB,UAAQ,KAAK,EAAE;;CAElB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-get.d.mts","names":[],"sources":["../../../src/internal/route/handle-get.ts"],"mappings":";iBAEgB,SAAA,CAAU,OAAA,EAAS,OAAA,GAAU,QAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SW_SCRIPT } from "./sw-script.mjs";
|
|
2
|
+
//#region src/internal/route/handle-get.ts
|
|
3
|
+
function handleGet(request) {
|
|
4
|
+
if (!new URL(request.url).pathname.endsWith("/sw")) return new Response("Not Found", { status: 404 });
|
|
5
|
+
return new Response(SW_SCRIPT, {
|
|
6
|
+
status: 200,
|
|
7
|
+
headers: {
|
|
8
|
+
"content-type": "application/javascript",
|
|
9
|
+
"service-worker-allowed": "/",
|
|
10
|
+
"cache-control": "public, max-age=3600"
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { handleGet };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-get.mjs","names":[],"sources":["../../../src/internal/route/handle-get.ts"],"sourcesContent":["import { SW_SCRIPT } from \"./sw-script.js\";\n\nexport function handleGet(request: Request): Response {\n const pathname = new URL(request.url).pathname;\n if (!pathname.endsWith(\"/sw\")) {\n return new Response(\"Not Found\", { status: 404 });\n }\n\n return new Response(SW_SCRIPT, {\n status: 200,\n headers: {\n \"content-type\": \"application/javascript\",\n \"service-worker-allowed\": \"/\",\n \"cache-control\": \"public, max-age=3600\",\n },\n });\n}\n"],"mappings":";;AAEA,SAAgB,UAAU,SAA4B;AAEpD,KAAI,CADa,IAAI,IAAI,QAAQ,IAAI,CAAC,SACxB,SAAS,MAAM,CAC3B,QAAO,IAAI,SAAS,aAAa,EAAE,QAAQ,KAAK,CAAC;AAGnD,QAAO,IAAI,SAAS,WAAW;EAC7B,QAAQ;EACR,SAAS;GACP,gBAAgB;GAChB,0BAA0B;GAC1B,iBAAiB;GAClB;EACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-post.d.mts","names":[],"sources":["../../../src/internal/route/handle-post.ts"],"mappings":";iBA2EsB,UAAA,CAAW,OAAA,EAAS,OAAA,GAAU,OAAA,CAAQ,QAAA"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { log } from "../logger.mjs";
|
|
2
|
+
import { readInterfereEnv } from "../env.mjs";
|
|
3
|
+
import { API_PATHS } from "@interfere/constants/api";
|
|
4
|
+
//#region src/internal/route/handle-post.ts
|
|
5
|
+
function parseEnvelopes(value) {
|
|
6
|
+
if (!Array.isArray(value)) return null;
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
function injectReleaseMetadata(envelopes, metadata) {
|
|
10
|
+
if (metadata.sourceId === null && metadata.destinationId === null) return envelopes;
|
|
11
|
+
return envelopes.map((envelope) => ({
|
|
12
|
+
...envelope,
|
|
13
|
+
buildId: metadata.sourceId ?? envelope.buildId,
|
|
14
|
+
releaseId: metadata.destinationId ?? envelope.releaseId
|
|
15
|
+
}));
|
|
16
|
+
}
|
|
17
|
+
function formatProxyError(error) {
|
|
18
|
+
if (!(error instanceof Error)) return {
|
|
19
|
+
message: String(error),
|
|
20
|
+
lines: [String(error)]
|
|
21
|
+
};
|
|
22
|
+
const lines = [`${error.name}: ${error.message}`];
|
|
23
|
+
if ("cause" in error && error.cause) {
|
|
24
|
+
const cause = error.cause instanceof Error ? error.cause.message : String(error.cause);
|
|
25
|
+
lines.push(`cause: ${cause}`);
|
|
26
|
+
}
|
|
27
|
+
if ("code" in error && typeof error.code === "string") lines.push(`code: ${error.code}`);
|
|
28
|
+
return {
|
|
29
|
+
message: `${error.name}: ${error.message}`,
|
|
30
|
+
lines
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const PROXY_PATH_PATTERN = /\/api\/interfere(\/.*)/;
|
|
34
|
+
function extractSubPath(request) {
|
|
35
|
+
return new URL(request.url).pathname.match(PROXY_PATH_PATTERN)?.[1] ?? "/";
|
|
36
|
+
}
|
|
37
|
+
async function handlePost(request) {
|
|
38
|
+
const env = readInterfereEnv();
|
|
39
|
+
if (env.apiKey === null) {
|
|
40
|
+
log.warn("Not configured", ["INTERFERE_API_KEY is not set. The proxy route will return 503."]);
|
|
41
|
+
return Response.json({
|
|
42
|
+
code: "INTERFERE_NOT_CONFIGURED",
|
|
43
|
+
message: "INTERFERE_API_KEY is required."
|
|
44
|
+
}, { status: 503 });
|
|
45
|
+
}
|
|
46
|
+
const authed = {
|
|
47
|
+
apiKey: env.apiKey,
|
|
48
|
+
apiUrl: env.apiUrl,
|
|
49
|
+
release: env.release
|
|
50
|
+
};
|
|
51
|
+
const subPath = extractSubPath(request);
|
|
52
|
+
try {
|
|
53
|
+
if (subPath === API_PATHS.INGEST) return await handleIngest(request, authed);
|
|
54
|
+
return await forwardToCollector(request, authed, subPath);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
const detail = formatProxyError(error);
|
|
57
|
+
log.error(`Proxy ${request.method} ${subPath} failed`, detail.lines);
|
|
58
|
+
return Response.json({
|
|
59
|
+
code: "INTERFERE_PROXY_ERROR",
|
|
60
|
+
message: detail.message
|
|
61
|
+
}, { status: 502 });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async function handleIngest(request, env) {
|
|
65
|
+
let payload;
|
|
66
|
+
try {
|
|
67
|
+
payload = await request.json();
|
|
68
|
+
} catch {
|
|
69
|
+
return Response.json({
|
|
70
|
+
code: "INTERFERE_INVALID_JSON",
|
|
71
|
+
message: "Request body must be valid JSON."
|
|
72
|
+
}, { status: 400 });
|
|
73
|
+
}
|
|
74
|
+
const envelopes = parseEnvelopes(payload);
|
|
75
|
+
if (envelopes === null) return Response.json({
|
|
76
|
+
code: "INTERFERE_INVALID_ENVELOPES",
|
|
77
|
+
message: "Request body must be an array of envelopes."
|
|
78
|
+
}, { status: 400 });
|
|
79
|
+
const traceparent = request.headers.get("traceparent");
|
|
80
|
+
const upstream = await fetch(`${env.apiUrl}${API_PATHS.INGEST}`, {
|
|
81
|
+
method: "POST",
|
|
82
|
+
headers: {
|
|
83
|
+
"content-type": "application/json",
|
|
84
|
+
"x-api-key": env.apiKey,
|
|
85
|
+
...traceparent ? { traceparent } : {}
|
|
86
|
+
},
|
|
87
|
+
body: JSON.stringify(injectReleaseMetadata(envelopes, env.release)),
|
|
88
|
+
signal: AbortSignal.timeout(1e4)
|
|
89
|
+
});
|
|
90
|
+
return new Response(upstream.body, {
|
|
91
|
+
status: upstream.status,
|
|
92
|
+
headers: { "content-type": upstream.headers.get("content-type") ?? "application/json" }
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
async function forwardToCollector(request, env, subPath) {
|
|
96
|
+
const url = `${env.apiUrl}${subPath}`;
|
|
97
|
+
const traceparent = request.headers.get("traceparent");
|
|
98
|
+
const body = await request.text();
|
|
99
|
+
const upstream = await fetch(url, {
|
|
100
|
+
method: request.method,
|
|
101
|
+
headers: {
|
|
102
|
+
"content-type": request.headers.get("content-type") ?? "application/json",
|
|
103
|
+
"x-api-key": env.apiKey,
|
|
104
|
+
...traceparent ? { traceparent } : {}
|
|
105
|
+
},
|
|
106
|
+
body,
|
|
107
|
+
signal: AbortSignal.timeout(1e4)
|
|
108
|
+
});
|
|
109
|
+
if (!upstream.ok) {
|
|
110
|
+
const body = await upstream.text().catch(() => "");
|
|
111
|
+
log.error(`Upstream ${upstream.status} for ${request.method} ${subPath}`, [body]);
|
|
112
|
+
return Response.json({
|
|
113
|
+
code: "INTERFERE_UPSTREAM_ERROR",
|
|
114
|
+
message: body
|
|
115
|
+
}, { status: upstream.status });
|
|
116
|
+
}
|
|
117
|
+
return new Response(upstream.body, {
|
|
118
|
+
status: upstream.status,
|
|
119
|
+
headers: { "content-type": upstream.headers.get("content-type") ?? "application/json" }
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
export { handlePost };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-post.mjs","names":[],"sources":["../../../src/internal/route/handle-post.ts"],"sourcesContent":["import { API_PATHS } from \"@interfere/constants/api\";\nimport type { Envelope } from \"@interfere/types/sdk/envelope\";\n\nimport { type InterfereEnv, readInterfereEnv } from \"../env.js\";\nimport { log } from \"../logger.js\";\n\nfunction parseEnvelopes(value: unknown): Envelope[] | null {\n if (!Array.isArray(value)) {\n return null;\n }\n\n return value as Envelope[];\n}\n\nfunction injectReleaseMetadata(\n envelopes: Envelope[],\n metadata: { sourceId: string | null; destinationId: string | null }\n): Envelope[] {\n if (metadata.sourceId === null && metadata.destinationId === null) {\n return envelopes;\n }\n\n return envelopes.map((envelope) => ({\n ...envelope,\n buildId: metadata.sourceId ?? envelope.buildId,\n releaseId: metadata.destinationId ?? envelope.releaseId,\n }));\n}\n\nfunction formatProxyError(error: unknown): {\n message: string;\n lines: string[];\n} {\n if (!(error instanceof Error)) {\n return {\n message: String(error),\n lines: [String(error)],\n };\n }\n\n const lines = [`${error.name}: ${error.message}`];\n\n if (\"cause\" in error && error.cause) {\n const cause =\n error.cause instanceof Error ? error.cause.message : String(error.cause);\n lines.push(`cause: ${cause}`);\n }\n\n if (\n \"code\" in error &&\n typeof (error as NodeJS.ErrnoException).code === \"string\"\n ) {\n lines.push(`code: ${(error as NodeJS.ErrnoException).code}`);\n }\n\n return {\n message: `${error.name}: ${error.message}`,\n lines,\n };\n}\n\nconst PROXY_PATH_PATTERN = /\\/api\\/interfere(\\/.*)/;\n\nfunction extractSubPath(request: Request): string {\n const url = new URL(request.url);\n const match = url.pathname.match(PROXY_PATH_PATTERN);\n return match?.[1] ?? \"/\";\n}\n\ninterface AuthenticatedEnv {\n apiKey: string;\n apiUrl: string;\n release: InterfereEnv[\"release\"];\n}\n\nexport async function handlePost(request: Request): Promise<Response> {\n const env = readInterfereEnv();\n\n if (env.apiKey === null) {\n log.warn(\"Not configured\", [\n \"INTERFERE_API_KEY is not set. The proxy route will return 503.\",\n ]);\n\n return Response.json(\n {\n code: \"INTERFERE_NOT_CONFIGURED\",\n message: \"INTERFERE_API_KEY is required.\",\n },\n { status: 503 }\n );\n }\n\n const authed: AuthenticatedEnv = {\n apiKey: env.apiKey,\n apiUrl: env.apiUrl,\n release: env.release,\n };\n\n const subPath = extractSubPath(request);\n\n try {\n if (subPath === API_PATHS.INGEST) {\n return await handleIngest(request, authed);\n }\n\n return await forwardToCollector(request, authed, subPath);\n } catch (error) {\n const detail = formatProxyError(error);\n log.error(`Proxy ${request.method} ${subPath} failed`, detail.lines);\n return Response.json(\n {\n code: \"INTERFERE_PROXY_ERROR\",\n message: detail.message,\n },\n { status: 502 }\n );\n }\n}\n\nasync function handleIngest(\n request: Request,\n env: AuthenticatedEnv\n): Promise<Response> {\n let payload: unknown;\n try {\n payload = await request.json();\n } catch {\n return Response.json(\n {\n code: \"INTERFERE_INVALID_JSON\",\n message: \"Request body must be valid JSON.\",\n },\n { status: 400 }\n );\n }\n\n const envelopes = parseEnvelopes(payload);\n if (envelopes === null) {\n return Response.json(\n {\n code: \"INTERFERE_INVALID_ENVELOPES\",\n message: \"Request body must be an array of envelopes.\",\n },\n { status: 400 }\n );\n }\n\n const traceparent = request.headers.get(\"traceparent\");\n const upstream = await fetch(`${env.apiUrl}${API_PATHS.INGEST}`, {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n \"x-api-key\": env.apiKey,\n ...(traceparent ? { traceparent } : {}),\n },\n body: JSON.stringify(injectReleaseMetadata(envelopes, env.release)),\n signal: AbortSignal.timeout(10_000),\n });\n\n return new Response(upstream.body, {\n status: upstream.status,\n headers: {\n \"content-type\":\n upstream.headers.get(\"content-type\") ?? \"application/json\",\n },\n });\n}\n\nasync function forwardToCollector(\n request: Request,\n env: AuthenticatedEnv,\n subPath: string\n): Promise<Response> {\n const url = `${env.apiUrl}${subPath}`;\n const traceparent = request.headers.get(\"traceparent\");\n const body = await request.text();\n\n const upstream = await fetch(url, {\n method: request.method,\n headers: {\n \"content-type\": request.headers.get(\"content-type\") ?? \"application/json\",\n \"x-api-key\": env.apiKey,\n ...(traceparent ? { traceparent } : {}),\n },\n body,\n signal: AbortSignal.timeout(10_000),\n });\n\n if (!upstream.ok) {\n const body = await upstream.text().catch(() => \"\");\n log.error(`Upstream ${upstream.status} for ${request.method} ${subPath}`, [\n body,\n ]);\n return Response.json(\n { code: \"INTERFERE_UPSTREAM_ERROR\", message: body },\n { status: upstream.status }\n );\n }\n\n return new Response(upstream.body, {\n status: upstream.status,\n headers: {\n \"content-type\":\n upstream.headers.get(\"content-type\") ?? \"application/json\",\n },\n });\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
//#region src/internal/route/sw-script.d.ts
|
|
2
|
+
declare const SW_SCRIPT = "importScripts('https://storage.googleapis.com/workbox-cdn/releases/7.3.0/workbox-sw.js');\n\nself.addEventListener('install', function() { self.skipWaiting(); });\nself.addEventListener('activate', function(e) { e.waitUntil(self.clients.claim()); });\n\nself.addEventListener('unhandledrejection', function(event) {\n if (event.reason && event.reason.name === 'no-response') {\n event.preventDefault();\n }\n});\n\nworkbox.setConfig({ debug: false });\n\nworkbox.routing.registerRoute(\n function(ctx) {\n return ctx.request.method === 'POST' && ctx.url.pathname.startsWith('/api/interfere/');\n },\n new workbox.strategies.NetworkOnly({\n plugins: [\n new workbox.backgroundSync.BackgroundSyncPlugin('interfere-queue', {\n maxRetentionTime: 1440,\n }),\n {\n fetchDidSucceed: function(ctx) {\n if (ctx.response.status === 429 || ctx.response.status >= 500) {\n throw new Error(ctx.request.url + ' returned ' + ctx.response.status);\n }\n return ctx.response;\n },\n },\n ],\n }),\n 'POST'\n);";
|
|
3
|
+
//#endregion
|
|
4
|
+
export { SW_SCRIPT };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sw-script.d.mts","names":[],"sources":["../../../src/internal/route/sw-script.ts"],"mappings":";cAAa,SAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region src/internal/route/sw-script.ts
|
|
2
|
+
const SW_SCRIPT = `\
|
|
3
|
+
importScripts('https://storage.googleapis.com/workbox-cdn/releases/7.3.0/workbox-sw.js');
|
|
4
|
+
|
|
5
|
+
self.addEventListener('install', function() { self.skipWaiting(); });
|
|
6
|
+
self.addEventListener('activate', function(e) { e.waitUntil(self.clients.claim()); });
|
|
7
|
+
|
|
8
|
+
self.addEventListener('unhandledrejection', function(event) {
|
|
9
|
+
if (event.reason && event.reason.name === 'no-response') {
|
|
10
|
+
event.preventDefault();
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
workbox.setConfig({ debug: false });
|
|
15
|
+
|
|
16
|
+
workbox.routing.registerRoute(
|
|
17
|
+
function(ctx) {
|
|
18
|
+
return ctx.request.method === 'POST' && ctx.url.pathname.startsWith('/api/interfere/');
|
|
19
|
+
},
|
|
20
|
+
new workbox.strategies.NetworkOnly({
|
|
21
|
+
plugins: [
|
|
22
|
+
new workbox.backgroundSync.BackgroundSyncPlugin('interfere-queue', {
|
|
23
|
+
maxRetentionTime: 1440,
|
|
24
|
+
}),
|
|
25
|
+
{
|
|
26
|
+
fetchDidSucceed: function(ctx) {
|
|
27
|
+
if (ctx.response.status === 429 || ctx.response.status >= 500) {
|
|
28
|
+
throw new Error(ctx.request.url + ' returned ' + ctx.response.status);
|
|
29
|
+
}
|
|
30
|
+
return ctx.response;
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
}),
|
|
35
|
+
'POST'
|
|
36
|
+
);`;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { SW_SCRIPT };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sw-script.mjs","names":[],"sources":["../../../src/internal/route/sw-script.ts"],"sourcesContent":["export const SW_SCRIPT = `\\\nimportScripts('https://storage.googleapis.com/workbox-cdn/releases/7.3.0/workbox-sw.js');\n\nself.addEventListener('install', function() { self.skipWaiting(); });\nself.addEventListener('activate', function(e) { e.waitUntil(self.clients.claim()); });\n\nself.addEventListener('unhandledrejection', function(event) {\n if (event.reason && event.reason.name === 'no-response') {\n event.preventDefault();\n }\n});\n\nworkbox.setConfig({ debug: false });\n\nworkbox.routing.registerRoute(\n function(ctx) {\n return ctx.request.method === 'POST' && ctx.url.pathname.startsWith('/api/interfere/');\n },\n new workbox.strategies.NetworkOnly({\n plugins: [\n new workbox.backgroundSync.BackgroundSyncPlugin('interfere-queue', {\n maxRetentionTime: 1440,\n }),\n {\n fetchDidSucceed: function(ctx) {\n if (ctx.response.status === 429 || ctx.response.status >= 500) {\n throw new Error(ctx.request.url + ' returned ' + ctx.response.status);\n }\n return ctx.response;\n },\n },\n ],\n }),\n 'POST'\n);`;\n"],"mappings":";AAAA,MAAa,YAAY"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CaptureErrorContext, OnRequestErrorContext } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/internal/server/capture.d.ts
|
|
4
|
+
declare function captureError(error: unknown, request?: unknown, context?: CaptureErrorContext): Promise<void>;
|
|
5
|
+
declare function onRequestError(error: Error & {
|
|
6
|
+
digest?: string;
|
|
7
|
+
}, request: unknown, context: OnRequestErrorContext): Promise<void>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { captureError, onRequestError };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capture.d.mts","names":[],"sources":["../../../src/internal/server/capture.ts"],"mappings":";;;iBAqBsB,YAAA,CACpB,KAAA,WACA,OAAA,YACA,OAAA,GAAU,mBAAA,GACT,OAAA;AAAA,iBA4BmB,cAAA,CACpB,KAAA,EAAO,KAAA;EAAU,MAAA;AAAA,GACjB,OAAA,WACA,OAAA,EAAS,qBAAA,GACR,OAAA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { isErrorCaptured, markErrorCaptured } from "./dedupe.mjs";
|
|
2
|
+
import { buildErrorEnvelope } from "./envelope.mjs";
|
|
3
|
+
import { normalizeRequest } from "./normalize-request.mjs";
|
|
4
|
+
import { resolveServerCaptureRuntime } from "./runtime.mjs";
|
|
5
|
+
import { sendEnvelope } from "./transport.mjs";
|
|
6
|
+
//#region src/internal/server/capture.ts
|
|
7
|
+
const ON_REQUEST_ERROR_MECHANISM = {
|
|
8
|
+
type: "onRequestError",
|
|
9
|
+
handled: false,
|
|
10
|
+
synthetic: false
|
|
11
|
+
};
|
|
12
|
+
const DEFAULT_REQUEST = {
|
|
13
|
+
method: "GET",
|
|
14
|
+
path: "/",
|
|
15
|
+
headers: new Headers()
|
|
16
|
+
};
|
|
17
|
+
async function captureError(error, request, context) {
|
|
18
|
+
const runtime = resolveServerCaptureRuntime();
|
|
19
|
+
if (runtime.apiKey === null) return;
|
|
20
|
+
const normalizedRequest = normalizeRequest(request);
|
|
21
|
+
const envelope = buildErrorEnvelope({
|
|
22
|
+
error,
|
|
23
|
+
request: normalizedRequest,
|
|
24
|
+
context,
|
|
25
|
+
runtime
|
|
26
|
+
});
|
|
27
|
+
try {
|
|
28
|
+
await sendEnvelope({
|
|
29
|
+
envelope,
|
|
30
|
+
runtime,
|
|
31
|
+
traceparent: context?.traceparent ?? normalizedRequest?.headers.get("traceparent") ?? void 0
|
|
32
|
+
});
|
|
33
|
+
} catch {}
|
|
34
|
+
}
|
|
35
|
+
async function onRequestError(error, request, context) {
|
|
36
|
+
if (isErrorCaptured(error)) return;
|
|
37
|
+
markErrorCaptured(error);
|
|
38
|
+
const normalizedRequest = normalizeRequest(request) ?? DEFAULT_REQUEST;
|
|
39
|
+
await captureError(error, normalizedRequest, {
|
|
40
|
+
mechanism: ON_REQUEST_ERROR_MECHANISM,
|
|
41
|
+
nextjs: {
|
|
42
|
+
...context,
|
|
43
|
+
requestMethod: normalizedRequest.method,
|
|
44
|
+
requestPath: normalizedRequest.path,
|
|
45
|
+
...error.digest ? { errorDigest: error.digest } : {}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { captureError, onRequestError };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capture.mjs","names":[],"sources":["../../../src/internal/server/capture.ts"],"sourcesContent":["import type { ErrorMechanism } from \"@interfere/types/sdk/plugins/payload/errors\";\n\nimport { isErrorCaptured, markErrorCaptured } from \"./dedupe.js\";\nimport { buildErrorEnvelope } from \"./envelope.js\";\nimport { normalizeRequest, TRACEPARENT_HEADER } from \"./normalize-request.js\";\nimport { resolveServerCaptureRuntime } from \"./runtime.js\";\nimport { sendEnvelope } from \"./transport.js\";\nimport type { CaptureErrorContext, OnRequestErrorContext } from \"./types.js\";\n\nconst ON_REQUEST_ERROR_MECHANISM: ErrorMechanism = {\n type: \"onRequestError\",\n handled: false,\n synthetic: false,\n};\n\nconst DEFAULT_REQUEST = {\n method: \"GET\",\n path: \"/\",\n headers: new Headers(),\n};\n\nexport async function captureError(\n error: unknown,\n request?: unknown,\n context?: CaptureErrorContext\n): Promise<void> {\n const runtime = resolveServerCaptureRuntime();\n if (runtime.apiKey === null) {\n return;\n }\n\n const normalizedRequest = normalizeRequest(request);\n const envelope = buildErrorEnvelope({\n error,\n request: normalizedRequest,\n context,\n runtime,\n });\n\n try {\n await sendEnvelope({\n envelope,\n runtime,\n traceparent:\n context?.traceparent ??\n normalizedRequest?.headers.get(TRACEPARENT_HEADER) ??\n undefined,\n });\n } catch {\n /* best-effort */\n }\n}\n\nexport async function onRequestError(\n error: Error & { digest?: string },\n request: unknown,\n context: OnRequestErrorContext\n): Promise<void> {\n if (isErrorCaptured(error)) {\n return;\n }\n markErrorCaptured(error);\n\n const normalizedRequest = normalizeRequest(request) ?? DEFAULT_REQUEST;\n\n await captureError(error, normalizedRequest, {\n mechanism: ON_REQUEST_ERROR_MECHANISM,\n nextjs: {\n ...context,\n requestMethod: normalizedRequest.method,\n requestPath: normalizedRequest.path,\n ...(error.digest ? { errorDigest: error.digest } : {}),\n },\n });\n}\n"],"mappings":";;;;;;AASA,MAAM,6BAA6C;CACjD,MAAM;CACN,SAAS;CACT,WAAW;CACZ;AAED,MAAM,kBAAkB;CACtB,QAAQ;CACR,MAAM;CACN,SAAS,IAAI,SAAS;CACvB;AAED,eAAsB,aACpB,OACA,SACA,SACe;CACf,MAAM,UAAU,6BAA6B;AAC7C,KAAI,QAAQ,WAAW,KACrB;CAGF,MAAM,oBAAoB,iBAAiB,QAAQ;CACnD,MAAM,WAAW,mBAAmB;EAClC;EACA,SAAS;EACT;EACA;EACD,CAAC;AAEF,KAAI;AACF,QAAM,aAAa;GACjB;GACA;GACA,aACE,SAAS,eACT,mBAAmB,QAAQ,IAAA,cAAuB,IAClD,KAAA;GACH,CAAC;SACI;;AAKV,eAAsB,eACpB,OACA,SACA,SACe;AACf,KAAI,gBAAgB,MAAM,CACxB;AAEF,mBAAkB,MAAM;CAExB,MAAM,oBAAoB,iBAAiB,QAAQ,IAAI;AAEvD,OAAM,aAAa,OAAO,mBAAmB;EAC3C,WAAW;EACX,QAAQ;GACN,GAAG;GACH,eAAe,kBAAkB;GACjC,aAAa,kBAAkB;GAC/B,GAAI,MAAM,SAAS,EAAE,aAAa,MAAM,QAAQ,GAAG,EAAE;GACtD;EACF,CAAC"}
|