@interfere/next 7.0.0 → 8.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/config.d.mts.map +1 -1
- package/dist/config.mjs +10 -6
- package/dist/config.mjs.map +1 -1
- package/dist/internal/build/pipeline.d.mts +5 -5
- package/dist/internal/build/release/destinations/vercel.mjs +3 -3
- package/dist/internal/build/release/destinations/vercel.mjs.map +1 -1
- package/dist/internal/build/release/sources/github.mjs +3 -3
- package/dist/internal/build/release/sources/github.mjs.map +1 -1
- package/dist/internal/env.mjs +8 -8
- package/dist/internal/env.mjs.map +1 -1
- package/dist/internal/logger.mjs +1 -1
- package/dist/internal/logger.mjs.map +1 -1
- package/dist/internal/route/proxy.d.mts.map +1 -1
- package/dist/internal/route/proxy.mjs +2 -1
- package/dist/internal/route/proxy.mjs.map +1 -1
- package/dist/internal/server/envelope.d.mts +1 -1
- package/dist/internal/server/envelope.mjs.map +1 -1
- package/dist/internal/server/transport.d.mts +1 -1
- package/dist/internal/server/transport.mjs.map +1 -1
- package/dist/package.mjs +1 -1
- package/package.json +9 -9
package/dist/config.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.mts","names":[],"sources":["../src/config.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"config.d.mts","names":[],"sources":["../src/config.ts"],"mappings":";;;;UAgBiB,eAAA,SACP,OAAA,CAAQ,IAAA,CAAK,QAAA;AAAA,UAEN,uBAAA,SAAgC,UAAA;EAC/C,SAAA,GAAY,eAAA;AAAA;AAAA,UAGG,mBAAA;EAAA,SACN,MAAA;EAAA,SACA,MAAA;EAAA,SACA,OAAA;EAAA,SACA,SAAA;AAAA;AAAA,iBAGK,aAAA,CACd,UAAA,GAAY,uBAAA,GACX,UAAA;AAAA,UA2Fc,wBAAA;EAAA,SACN,OAAA;EAAA,SACA,UAAA;AAAA"}
|
package/dist/config.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { readInterfereEnv } from "./internal/env.mjs";
|
|
|
5
5
|
import { API_URL } from "@interfere/constants/api";
|
|
6
6
|
import { releaseDestinationIdEnvKeys, releaseSourceIdEnvKeys } from "@interfere/types/integrations";
|
|
7
7
|
import { parseEnvValue, readFirstEnvValue } from "@interfere/types/sdk/env";
|
|
8
|
+
import { omitUndefined } from "@interfere/types/util/omit-undefined";
|
|
8
9
|
//#region src/config.ts
|
|
9
10
|
function withInterfere(nextConfig = {}) {
|
|
10
11
|
const { interfere, env: userEnv, webpack, turbopack, compiler, productionBrowserSourceMaps, ...rest } = nextConfig;
|
|
@@ -20,19 +21,22 @@ function withInterfere(nextConfig = {}) {
|
|
|
20
21
|
});
|
|
21
22
|
if (config.apiKey !== null && !build.webpack && !build.turbopack) return log.fatal("Missing instrumentation client", ["INTERFERE_API_KEY is set but no instrumentation-client file was found.", "Create an instrumentation-client.ts file in your project root or src/ directory."]);
|
|
22
23
|
const existingHook = compiler?.runAfterProductionCompile;
|
|
24
|
+
const browserSourceMaps = config.apiKey === null ? productionBrowserSourceMaps : true;
|
|
23
25
|
return {
|
|
24
26
|
...rest,
|
|
25
27
|
env: mergeEnvConfig(userEnv, config),
|
|
26
28
|
compiler: {
|
|
27
|
-
...compiler ?? {},
|
|
29
|
+
...omitUndefined(compiler ?? {}),
|
|
28
30
|
async runAfterProductionCompile(context) {
|
|
29
31
|
if (existingHook) await existingHook(context);
|
|
30
32
|
await runBuildReleasePipeline(context, config);
|
|
31
33
|
}
|
|
32
34
|
},
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
...omitUndefined({
|
|
36
|
+
productionBrowserSourceMaps: browserSourceMaps,
|
|
37
|
+
turbopack: build.turbopack,
|
|
38
|
+
webpack: build.webpack
|
|
39
|
+
})
|
|
36
40
|
};
|
|
37
41
|
}
|
|
38
42
|
function resolveBuildConfig(interfere) {
|
|
@@ -48,8 +52,8 @@ function resolveBuildConfig(interfere) {
|
|
|
48
52
|
}
|
|
49
53
|
function mergeEnvConfig(userEnv, config) {
|
|
50
54
|
const merged = {};
|
|
51
|
-
if (config.buildId !== null) merged
|
|
52
|
-
if (config.releaseId !== null) merged
|
|
55
|
+
if (config.buildId !== null) merged["NEXT_PUBLIC_INTERFERE_BUILD_ID"] = config.buildId;
|
|
56
|
+
if (config.releaseId !== null) merged["NEXT_PUBLIC_INTERFERE_RELEASE_ID"] = config.releaseId;
|
|
53
57
|
return {
|
|
54
58
|
...merged,
|
|
55
59
|
...userEnv
|
package/dist/config.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.mjs","names":[],"sources":["../src/config.ts"],"sourcesContent":["import { API_URL } from \"@interfere/constants/api\";\nimport {\n releaseDestinationIdEnvKeys,\n releaseSourceIdEnvKeys,\n} from \"@interfere/types/integrations\";\nimport { parseEnvValue, readFirstEnvValue } from \"@interfere/types/sdk/env\";\nimport type { Envelope } from \"@interfere/types/sdk/envelope\";\n\nimport type { NextConfig } from \"next\";\n\nimport { configureBuild } from \"./internal/build/configure-build.js\";\nimport { runGitCommand } from \"./internal/build/release/git.js\";\nimport { readInterfereEnv } from \"./internal/env.js\";\nimport { log } from \"./internal/logger.js\";\n\nexport interface InterfereConfig\n extends Partial<Pick<Envelope, \"buildId\" | \"releaseId\">> {}\n\nexport interface NextConfigWithInterfere extends NextConfig {\n interfere?: InterfereConfig;\n}\n\nexport interface ResolvedBuildConfig {\n readonly apiKey: string | null;\n readonly apiUrl: string;\n readonly buildId: string | null;\n readonly releaseId: string | null;\n}\n\nexport function withInterfere(\n nextConfig: NextConfigWithInterfere = {}\n): NextConfig {\n const {\n interfere,\n env: userEnv,\n webpack,\n turbopack,\n compiler,\n productionBrowserSourceMaps,\n ...rest\n } = nextConfig;\n\n const config = resolveBuildConfig(interfere);\n const build = configureBuild({\n existingWebpack: webpack,\n existingTurbopack: turbopack,\n projectDir: process.cwd(),\n values: {\n __INTERFERE_BUILD_ID__: config.buildId,\n __INTERFERE_RELEASE_ID__: config.releaseId,\n },\n });\n\n if (config.apiKey !== null && !build.webpack && !build.turbopack) {\n return log.fatal(\"Missing instrumentation client\", [\n \"INTERFERE_API_KEY is set but no instrumentation-client file was found.\",\n \"Create an instrumentation-client.ts file in your project root or src/ directory.\",\n ]);\n }\n\n const existingHook = (compiler as NextCompilerWithProductionHook | undefined)\n ?.runAfterProductionCompile;\n\n return {\n ...rest,\n env: mergeEnvConfig(userEnv, config),\n compiler: {\n ...(compiler ?? {}),\n async runAfterProductionCompile(context: ProductionCompileContext) {\n if (existingHook) {\n await existingHook(context);\n }\n\n await runBuildReleasePipeline(context, config);\n },\n }
|
|
1
|
+
{"version":3,"file":"config.mjs","names":[],"sources":["../src/config.ts"],"sourcesContent":["import { API_URL } from \"@interfere/constants/api\";\nimport {\n releaseDestinationIdEnvKeys,\n releaseSourceIdEnvKeys,\n} from \"@interfere/types/integrations\";\nimport { parseEnvValue, readFirstEnvValue } from \"@interfere/types/sdk/env\";\nimport type { Envelope } from \"@interfere/types/sdk/envelope\";\nimport { omitUndefined } from \"@interfere/types/util/omit-undefined\";\n\nimport type { NextConfig } from \"next\";\n\nimport { configureBuild } from \"./internal/build/configure-build.js\";\nimport { runGitCommand } from \"./internal/build/release/git.js\";\nimport { readInterfereEnv } from \"./internal/env.js\";\nimport { log } from \"./internal/logger.js\";\n\nexport interface InterfereConfig\n extends Partial<Pick<Envelope, \"buildId\" | \"releaseId\">> {}\n\nexport interface NextConfigWithInterfere extends NextConfig {\n interfere?: InterfereConfig;\n}\n\nexport interface ResolvedBuildConfig {\n readonly apiKey: string | null;\n readonly apiUrl: string;\n readonly buildId: string | null;\n readonly releaseId: string | null;\n}\n\nexport function withInterfere(\n nextConfig: NextConfigWithInterfere = {}\n): NextConfig {\n const {\n interfere,\n env: userEnv,\n webpack,\n turbopack,\n compiler,\n productionBrowserSourceMaps,\n ...rest\n } = nextConfig;\n\n const config = resolveBuildConfig(interfere);\n const build = configureBuild({\n existingWebpack: webpack,\n existingTurbopack: turbopack,\n projectDir: process.cwd(),\n values: {\n __INTERFERE_BUILD_ID__: config.buildId,\n __INTERFERE_RELEASE_ID__: config.releaseId,\n },\n });\n\n if (config.apiKey !== null && !build.webpack && !build.turbopack) {\n return log.fatal(\"Missing instrumentation client\", [\n \"INTERFERE_API_KEY is set but no instrumentation-client file was found.\",\n \"Create an instrumentation-client.ts file in your project root or src/ directory.\",\n ]);\n }\n\n const existingHook = (compiler as NextCompilerWithProductionHook | undefined)\n ?.runAfterProductionCompile;\n\n const browserSourceMaps =\n config.apiKey === null ? productionBrowserSourceMaps : true;\n\n return {\n ...rest,\n env: mergeEnvConfig(userEnv, config),\n\n compiler: {\n ...omitUndefined(compiler ?? {}),\n async runAfterProductionCompile(context: ProductionCompileContext) {\n if (existingHook) {\n await existingHook(context);\n }\n\n await runBuildReleasePipeline(context, config);\n },\n },\n\n ...omitUndefined({\n productionBrowserSourceMaps: browserSourceMaps,\n turbopack: build.turbopack,\n webpack: build.webpack,\n }),\n };\n}\n\nfunction resolveBuildConfig(interfere?: InterfereConfig): ResolvedBuildConfig {\n const { apiKey, apiUrl } = readInterfereEnv();\n\n const buildId =\n parseEnvValue(interfere?.buildId) ??\n readFirstEnvValue(process.env, releaseSourceIdEnvKeys) ??\n runGitCommand(\"git rev-parse HEAD\");\n\n const releaseId =\n parseEnvValue(interfere?.releaseId) ??\n readFirstEnvValue(process.env, releaseDestinationIdEnvKeys) ??\n buildId;\n\n return { apiKey: apiKey ?? null, apiUrl, buildId, releaseId };\n}\n\nfunction mergeEnvConfig(\n userEnv: NextConfig[\"env\"] | undefined,\n config: ResolvedBuildConfig\n): Record<string, string | undefined> {\n const merged: Record<string, string> = {};\n\n if (config.buildId !== null) {\n merged[\"NEXT_PUBLIC_INTERFERE_BUILD_ID\"] = config.buildId;\n }\n\n if (config.releaseId !== null) {\n merged[\"NEXT_PUBLIC_INTERFERE_RELEASE_ID\"] = config.releaseId;\n }\n\n return { ...merged, ...userEnv };\n}\n\nexport interface ProductionCompileContext {\n readonly distDir: string;\n readonly projectDir: string;\n}\n\ntype NextCompilerWithProductionHook = NonNullable<NextConfig[\"compiler\"]> & {\n runAfterProductionCompile?: (\n context: ProductionCompileContext\n ) => void | Promise<void>;\n};\n\nfunction isNetworkError(error: unknown): boolean {\n if (error instanceof TypeError) {\n return true;\n }\n if (error instanceof Error) {\n const msg = error.message.toLowerCase();\n return (\n msg.includes(\"econnrefused\") ||\n msg.includes(\"enotfound\") ||\n msg.includes(\"fetch failed\") ||\n msg.includes(\"network\")\n );\n }\n return false;\n}\n\nasync function runBuildReleasePipeline(\n context: ProductionCompileContext,\n config: ResolvedBuildConfig\n): Promise<void> {\n const { apiKey, apiUrl, buildId } = config;\n\n if (!apiKey) {\n return log.fatal(\"API key not set\", [\n \"withInterfere() requires an API key to upload source maps during production builds.\",\n \"Set the INTERFERE_API_KEY environment variable, or remove withInterfere() from your Next.js config.\",\n \"See: https://interfere.com/docs/nextjs/setup\",\n ]);\n }\n\n if (!buildId) {\n return log.fatal(\"Build ID missing\", [\n \"Could not resolve a build ID from config, environment variables, or git.\",\n \"Set INTERFERE_BUILD_ID, or ensure git is available in your build environment.\",\n ]);\n }\n\n const { runBuildPipeline } = await import(\"./internal/build/pipeline.js\");\n\n try {\n const result = await runBuildPipeline(context, {\n ...config,\n apiKey,\n buildId,\n });\n\n if (!result.ready) {\n log.warn(\"Skipping\", [\"No source maps found\"]);\n return;\n }\n\n log.info(\"Completed\", [\n `https://interfere.com/~/${result.config?.org.slug}/surfaces/${result.config?.surface.slug}`,\n `Release: ${result.release?.destination.slug ?? \"Unknown\"}`,\n `Build: ${result.buildId}`,\n `Artifacts: ${result.fileCount} source maps`,\n ]);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n\n if (apiUrl !== API_URL) {\n const isNetwork = isNetworkError(error);\n\n log.warn(\"Skipping release pipeline\", [\n message,\n isNetwork\n ? `${apiUrl} is unreachable — this is expected during local development.`\n : `${apiUrl} returned an error. Ensure the collector is running and configured correctly.`,\n ]);\n\n return;\n }\n\n log.error(\"Error\", [message]);\n throw error;\n }\n}\n"],"mappings":";;;;;;;;;AA8BA,SAAgB,cACd,aAAsC,EAAE,EAC5B;CACZ,MAAM,EACJ,WACA,KAAK,SACL,SACA,WACA,UACA,6BACA,GAAG,SACD;CAEJ,MAAM,SAAS,mBAAmB,UAAU;CAC5C,MAAM,QAAQ,eAAe;EAC3B,iBAAiB;EACjB,mBAAmB;EACnB,YAAY,QAAQ,KAAK;EACzB,QAAQ;GACN,wBAAwB,OAAO;GAC/B,0BAA0B,OAAO;GAClC;EACF,CAAC;AAEF,KAAI,OAAO,WAAW,QAAQ,CAAC,MAAM,WAAW,CAAC,MAAM,UACrD,QAAO,IAAI,MAAM,kCAAkC,CACjD,0EACA,mFACD,CAAC;CAGJ,MAAM,eAAgB,UAClB;CAEJ,MAAM,oBACJ,OAAO,WAAW,OAAO,8BAA8B;AAEzD,QAAO;EACL,GAAG;EACH,KAAK,eAAe,SAAS,OAAO;EAEpC,UAAU;GACR,GAAG,cAAc,YAAY,EAAE,CAAC;GAChC,MAAM,0BAA0B,SAAmC;AACjE,QAAI,aACF,OAAM,aAAa,QAAQ;AAG7B,UAAM,wBAAwB,SAAS,OAAO;;GAEjD;EAED,GAAG,cAAc;GACf,6BAA6B;GAC7B,WAAW,MAAM;GACjB,SAAS,MAAM;GAChB,CAAC;EACH;;AAGH,SAAS,mBAAmB,WAAkD;CAC5E,MAAM,EAAE,QAAQ,WAAW,kBAAkB;CAE7C,MAAM,UACJ,cAAc,WAAW,QAAQ,IACjC,kBAAkB,QAAQ,KAAK,uBAAuB,IACtD,cAAc,qBAAqB;CAErC,MAAM,YACJ,cAAc,WAAW,UAAU,IACnC,kBAAkB,QAAQ,KAAK,4BAA4B,IAC3D;AAEF,QAAO;EAAE,QAAQ,UAAU;EAAM;EAAQ;EAAS;EAAW;;AAG/D,SAAS,eACP,SACA,QACoC;CACpC,MAAM,SAAiC,EAAE;AAEzC,KA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QAAQ,CAAC;AAC7B,QAAM"}
|
|
@@ -32,10 +32,10 @@ declare function runBuildPipeline(context: ProductionCompileContext, metadata: R
|
|
|
32
32
|
ready: boolean;
|
|
33
33
|
reason: string;
|
|
34
34
|
fileCount: number;
|
|
35
|
-
release?:
|
|
36
|
-
config?:
|
|
37
|
-
buildId?:
|
|
38
|
-
timing?:
|
|
35
|
+
release?: never;
|
|
36
|
+
config?: never;
|
|
37
|
+
buildId?: never;
|
|
38
|
+
timing?: never;
|
|
39
39
|
} | {
|
|
40
40
|
ready: true;
|
|
41
41
|
fileCount: number;
|
|
@@ -43,7 +43,7 @@ declare function runBuildPipeline(context: ProductionCompileContext, metadata: R
|
|
|
43
43
|
config: ReleasesConfigResponse;
|
|
44
44
|
buildId: string;
|
|
45
45
|
timing: BuildTiming;
|
|
46
|
-
reason?:
|
|
46
|
+
reason?: never;
|
|
47
47
|
}>;
|
|
48
48
|
//#endregion
|
|
49
49
|
export { BuildTiming, PipelineResult, runBuildPipeline };
|
|
@@ -3,8 +3,8 @@ import { parseEnvValue } from "@interfere/types/sdk/env";
|
|
|
3
3
|
//#region src/internal/build/release/destinations/vercel.ts
|
|
4
4
|
var vercel_exports = /* @__PURE__ */ __exportAll({ resolve: () => resolve });
|
|
5
5
|
function resolve() {
|
|
6
|
-
const environment = parseEnvValue(process.env
|
|
7
|
-
const deploymentId = parseEnvValue(process.env
|
|
6
|
+
const environment = parseEnvValue(process.env["VERCEL_ENV"] ?? process.env["VERCEL_TARGET_ENV"]);
|
|
7
|
+
const deploymentId = parseEnvValue(process.env["VERCEL_DEPLOYMENT_ID"]);
|
|
8
8
|
return {
|
|
9
9
|
provider: "vercel",
|
|
10
10
|
destinationReleaseId: deploymentId,
|
|
@@ -16,7 +16,7 @@ function resolve() {
|
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
function resolveDeploymentUrl() {
|
|
19
|
-
const deploymentUrl = parseEnvValue(process.env
|
|
19
|
+
const deploymentUrl = parseEnvValue(process.env["VERCEL_URL"]);
|
|
20
20
|
if (deploymentUrl === null) return null;
|
|
21
21
|
if (deploymentUrl.startsWith("https://") || deploymentUrl.startsWith("http://")) return deploymentUrl;
|
|
22
22
|
return `https://${deploymentUrl}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vercel.mjs","names":[],"sources":["../../../../../src/internal/build/release/destinations/vercel.ts"],"sourcesContent":["import type { ReleaseDestinationMetadata } from \"@interfere/types/integrations\";\nimport { parseEnvValue } from \"@interfere/types/sdk/env\";\n\nexport function resolve(): ReleaseDestinationMetadata {\n const environment = parseEnvValue(\n process.env
|
|
1
|
+
{"version":3,"file":"vercel.mjs","names":[],"sources":["../../../../../src/internal/build/release/destinations/vercel.ts"],"sourcesContent":["import type { ReleaseDestinationMetadata } from \"@interfere/types/integrations\";\nimport { parseEnvValue } from \"@interfere/types/sdk/env\";\n\nexport function resolve(): ReleaseDestinationMetadata {\n const environment = parseEnvValue(\n process.env[\"VERCEL_ENV\"] ?? process.env[\"VERCEL_TARGET_ENV\"],\n );\n\n const deploymentId = parseEnvValue(process.env[\"VERCEL_DEPLOYMENT_ID\"]);\n\n return {\n provider: \"vercel\",\n destinationReleaseId: deploymentId,\n environment,\n deploymentId,\n deploymentUrl: resolveDeploymentUrl(),\n environmentName: environment,\n environmentTarget: environment,\n };\n}\n\nfunction resolveDeploymentUrl(): string | null {\n const deploymentUrl = parseEnvValue(process.env[\"VERCEL_URL\"]);\n\n if (deploymentUrl === null) {\n return null;\n }\n\n if (\n deploymentUrl.startsWith(\"https://\") ||\n deploymentUrl.startsWith(\"http://\")\n ) {\n return deploymentUrl;\n }\n\n return `https://${deploymentUrl}`;\n}\n"],"mappings":";;;;AAGA,SAAgB,UAAsC;CACpD,MAAM,cAAc,cAClB,QAAQ,IAAI,iBAAiB,QAAQ,IAAI,qBAC1C;CAED,MAAM,eAAe,cAAc,QAAQ,IAAI,wBAAwB;AAEvE,QAAO;EACL,UAAU;EACV,sBAAsB;EACtB;EACA;EACA,eAAe,sBAAsB;EACrC,iBAAiB;EACjB,mBAAmB;EACpB;;AAGH,SAAS,uBAAsC;CAC7C,MAAM,gBAAgB,cAAc,QAAQ,IAAI,cAAc;AAE9D,KAAI,kBAAkB,KACpB,QAAO;AAGT,KACE,cAAc,WAAW,WAAW,IACpC,cAAc,WAAW,UAAU,CAEnC,QAAO;AAGT,QAAO,WAAW"}
|
|
@@ -6,9 +6,9 @@ var github_exports = /* @__PURE__ */ __exportAll({ resolve: () => resolve });
|
|
|
6
6
|
function resolve() {
|
|
7
7
|
return {
|
|
8
8
|
provider: "github",
|
|
9
|
-
branch: parseEnvValue(process.env
|
|
10
|
-
commitMessage: parseEnvValue(process.env
|
|
11
|
-
commitSha: parseEnvValue(process.env
|
|
9
|
+
branch: parseEnvValue(process.env["VERCEL_GIT_COMMIT_REF"]) ?? parseEnvValue(process.env["GITHUB_REF_NAME"]) ?? parseEnvValue(process.env["GITHUB_HEAD_REF"]) ?? runGitCommand("git rev-parse --abbrev-ref HEAD") ?? "unknown",
|
|
10
|
+
commitMessage: parseEnvValue(process.env["VERCEL_GIT_COMMIT_MESSAGE"]) ?? runGitCommand("git log -1 --pretty=%B") ?? "",
|
|
11
|
+
commitSha: parseEnvValue(process.env["VERCEL_GIT_COMMIT_SHA"]) ?? parseEnvValue(process.env["GITHUB_SHA"]) ?? runGitCommand("git rev-parse HEAD")
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"github.mjs","names":[],"sources":["../../../../../src/internal/build/release/sources/github.ts"],"sourcesContent":["import type { ReleaseSourceMetadata } from \"@interfere/types/integrations\";\nimport { parseEnvValue } from \"@interfere/types/sdk/env\";\n\nimport { runGitCommand } from \"../git.js\";\n\nexport function resolve(): ReleaseSourceMetadata {\n return {\n provider: \"github\",\n branch:\n parseEnvValue(process.env
|
|
1
|
+
{"version":3,"file":"github.mjs","names":[],"sources":["../../../../../src/internal/build/release/sources/github.ts"],"sourcesContent":["import type { ReleaseSourceMetadata } from \"@interfere/types/integrations\";\nimport { parseEnvValue } from \"@interfere/types/sdk/env\";\n\nimport { runGitCommand } from \"../git.js\";\n\nexport function resolve(): ReleaseSourceMetadata {\n return {\n provider: \"github\",\n branch:\n parseEnvValue(process.env[\"VERCEL_GIT_COMMIT_REF\"]) ??\n parseEnvValue(process.env[\"GITHUB_REF_NAME\"]) ??\n parseEnvValue(process.env[\"GITHUB_HEAD_REF\"]) ??\n runGitCommand(\"git rev-parse --abbrev-ref HEAD\") ??\n \"unknown\",\n commitMessage:\n parseEnvValue(process.env[\"VERCEL_GIT_COMMIT_MESSAGE\"]) ??\n runGitCommand(\"git log -1 --pretty=%B\") ??\n \"\",\n commitSha:\n parseEnvValue(process.env[\"VERCEL_GIT_COMMIT_SHA\"]) ??\n parseEnvValue(process.env[\"GITHUB_SHA\"]) ??\n runGitCommand(\"git rev-parse HEAD\"),\n };\n}\n"],"mappings":";;;;;AAKA,SAAgB,UAAiC;AAC/C,QAAO;EACL,UAAU;EACV,QACE,cAAc,QAAQ,IAAI,yBAAyB,IACnD,cAAc,QAAQ,IAAI,mBAAmB,IAC7C,cAAc,QAAQ,IAAI,mBAAmB,IAC7C,cAAc,kCAAkC,IAChD;EACF,eACE,cAAc,QAAQ,IAAI,6BAA6B,IACvD,cAAc,yBAAyB,IACvC;EACF,WACE,cAAc,QAAQ,IAAI,yBAAyB,IACnD,cAAc,QAAQ,IAAI,cAAc,IACxC,cAAc,qBAAqB;EACtC"}
|
package/dist/internal/env.mjs
CHANGED
|
@@ -3,19 +3,19 @@ import { parseEnvValue } from "@interfere/types/sdk/env";
|
|
|
3
3
|
import { normalizeEnv } from "@interfere/types/sdk/runtime";
|
|
4
4
|
//#region src/internal/env.ts
|
|
5
5
|
function isEnabledInEnvironment() {
|
|
6
|
-
if (process.env
|
|
7
|
-
return !!process.env
|
|
6
|
+
if (process.env["NODE_ENV"] === "production") return true;
|
|
7
|
+
return !!process.env["NEXT_PUBLIC_INTERFERE_FORCE_ENABLE"];
|
|
8
8
|
}
|
|
9
9
|
function readInterfereEnv() {
|
|
10
|
-
const nodeEnvironment = normalizeEnv(process.env
|
|
10
|
+
const nodeEnvironment = normalizeEnv(process.env["NODE_ENV"]) ?? "production";
|
|
11
11
|
return {
|
|
12
|
-
apiKey: parseEnvValue(process.env
|
|
13
|
-
apiUrl: parseEnvValue(process.env
|
|
14
|
-
nextRuntime: parseEnvValue(process.env
|
|
12
|
+
apiKey: parseEnvValue(process.env["INTERFERE_API_KEY"]),
|
|
13
|
+
apiUrl: parseEnvValue(process.env["INTERFERE_API_URL"]) ?? API_URL,
|
|
14
|
+
nextRuntime: parseEnvValue(process.env["NEXT_RUNTIME"]),
|
|
15
15
|
nodeEnvironment,
|
|
16
16
|
release: {
|
|
17
|
-
sourceId: parseEnvValue(process.env
|
|
18
|
-
destinationId: parseEnvValue(process.env
|
|
17
|
+
sourceId: parseEnvValue(process.env["NEXT_PUBLIC_INTERFERE_BUILD_ID"]),
|
|
18
|
+
destinationId: parseEnvValue(process.env["NEXT_PUBLIC_INTERFERE_RELEASE_ID"])
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
21
|
}
|
|
@@ -1 +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 isEnabledInEnvironment(): boolean {\n if (process.env
|
|
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 isEnabledInEnvironment(): boolean {\n if (process.env[\"NODE_ENV\"] === \"production\") {\n return true;\n }\n return !!process.env[\"NEXT_PUBLIC_INTERFERE_FORCE_ENABLE\"];\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,yBAAkC;AAChD,KAAI,QAAQ,IAAI,gBAAgB,aAC9B,QAAO;AAET,QAAO,CAAC,CAAC,QAAQ,IAAI;;AAGvB,SAAgB,mBAAiC;CAC/C,MAAM,kBAAkB,aAAa,QAAQ,IAAI,YAAY,IAAI;AAEjE,QAAO;EACL,QAAQ,cAAc,QAAQ,IAAI,qBAAqB;EACvD,QAAQ,cAAc,QAAQ,IAAI,qBAAqB,IAAI;EAC3D,aAAa,cAAc,QAAQ,IAAI,gBAAgB;EACvD;EACA,SAAS;GACP,UAAU,cAAc,QAAQ,IAAI,kCAAkC;GACtE,eAAe,cACb,QAAQ,IAAI,oCACb;GACF;EACF"}
|
package/dist/internal/logger.mjs
CHANGED
|
@@ -33,7 +33,7 @@ const consoleMethods = {
|
|
|
33
33
|
fatal: "error"
|
|
34
34
|
};
|
|
35
35
|
function isTestEnv() {
|
|
36
|
-
return Boolean(process.env
|
|
36
|
+
return Boolean(process.env["VITEST"] || process.env["VITEST_WORKER_ID"]);
|
|
37
37
|
}
|
|
38
38
|
function emit(level, title, lines) {
|
|
39
39
|
if (isTestEnv()) return;
|
|
@@ -1 +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
|
|
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,M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AoB,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.d.mts","names":[],"sources":["../../../src/internal/route/proxy.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"proxy.d.mts","names":[],"sources":["../../../src/internal/route/proxy.ts"],"mappings":";;;UAOiB,gBAAA;EACf,MAAA;EACA,MAAA;EACA,OAAA,EAAS,YAAA;AAAA;AAAA,iBAGK,uBAAA,CAAA,GAA2B,gBAAA;AAAA,iBAQ3B,cAAA,CAAe,OAAA,EAAS,OAAA;AAAA,iBAMxB,qBAAA,CAAA,GAAyB,QAAA;AAAA,iBAazB,gBAAA,CAAiB,KAAA;EAC/B,OAAA;EACA,KAAA;AAAA;AAAA,iBAwBoB,kBAAA,CACpB,OAAA,EAAS,OAAA,EACT,GAAA,EAAK,gBAAA,EACL,OAAA,WACC,OAAA,CAAQ,QAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { log } from "../logger.mjs";
|
|
2
2
|
import { readInterfereEnv } from "../env.mjs";
|
|
3
|
+
import { omitUndefined } from "@interfere/types/util/omit-undefined";
|
|
3
4
|
//#region src/internal/route/proxy.ts
|
|
4
5
|
const PROXY_PATH_PATTERN = /\/api\/interfere(\/.*)/;
|
|
5
6
|
function resolveAuthenticatedEnv() {
|
|
@@ -42,13 +43,13 @@ async function forwardToCollector(request, env, subPath) {
|
|
|
42
43
|
const traceparent = request.headers.get("traceparent");
|
|
43
44
|
const body = request.method !== "GET" && request.method !== "HEAD" ? await request.text() : void 0;
|
|
44
45
|
const upstream = await fetch(url, {
|
|
46
|
+
...omitUndefined({ body }),
|
|
45
47
|
method: request.method,
|
|
46
48
|
headers: {
|
|
47
49
|
"content-type": request.headers.get("content-type") ?? "application/json",
|
|
48
50
|
"x-api-key": env.apiKey,
|
|
49
51
|
...traceparent ? { traceparent } : {}
|
|
50
52
|
},
|
|
51
|
-
...body === void 0 ? {} : { body },
|
|
52
53
|
signal: AbortSignal.timeout(1e4)
|
|
53
54
|
});
|
|
54
55
|
if (!upstream.ok) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.mjs","names":[],"sources":["../../../src/internal/route/proxy.ts"],"sourcesContent":["import { type InterfereEnv, readInterfereEnv } from \"../env.js\";\nimport { log } from \"../logger.js\";\n\nconst PROXY_PATH_PATTERN = /\\/api\\/interfere(\\/.*)/;\n\nexport interface AuthenticatedEnv {\n apiKey: string;\n apiUrl: string;\n release: InterfereEnv[\"release\"];\n}\n\nexport function resolveAuthenticatedEnv(): AuthenticatedEnv | null {\n const env = readInterfereEnv();\n if (env.apiKey === null) {\n return null;\n }\n return { apiKey: env.apiKey, apiUrl: env.apiUrl, release: env.release };\n}\n\nexport function 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\nexport function notConfiguredResponse(): Response {\n log.warn(\"Not configured\", [\n \"INTERFERE_API_KEY is not set. The proxy route will return 503.\",\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\nexport function formatProxyError(error: unknown): {\n message: string;\n lines: string[];\n} {\n if (!(error instanceof Error)) {\n return { message: String(error), lines: [String(error)] };\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 { message: `${error.name}: ${error.message}`, lines };\n}\n\nexport async 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 hasBody = request.method !== \"GET\" && request.method !== \"HEAD\";\n const body = hasBody ? await request.text() : undefined;\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
|
|
1
|
+
{"version":3,"file":"proxy.mjs","names":[],"sources":["../../../src/internal/route/proxy.ts"],"sourcesContent":["import { omitUndefined } from \"@interfere/types/util/omit-undefined\";\n\nimport { type InterfereEnv, readInterfereEnv } from \"../env.js\";\nimport { log } from \"../logger.js\";\n\nconst PROXY_PATH_PATTERN = /\\/api\\/interfere(\\/.*)/;\n\nexport interface AuthenticatedEnv {\n apiKey: string;\n apiUrl: string;\n release: InterfereEnv[\"release\"];\n}\n\nexport function resolveAuthenticatedEnv(): AuthenticatedEnv | null {\n const env = readInterfereEnv();\n if (env.apiKey === null) {\n return null;\n }\n return { apiKey: env.apiKey, apiUrl: env.apiUrl, release: env.release };\n}\n\nexport function 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\nexport function notConfiguredResponse(): Response {\n log.warn(\"Not configured\", [\n \"INTERFERE_API_KEY is not set. The proxy route will return 503.\",\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\nexport function formatProxyError(error: unknown): {\n message: string;\n lines: string[];\n} {\n if (!(error instanceof Error)) {\n return { message: String(error), lines: [String(error)] };\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 { message: `${error.name}: ${error.message}`, lines };\n}\n\nexport async 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 hasBody = request.method !== \"GET\" && request.method !== \"HEAD\";\n const body = hasBody ? await request.text() : undefined;\n\n const upstream = await fetch(url, {\n ...omitUndefined({ body }),\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 signal: AbortSignal.timeout(10_000),\n });\n\n if (!upstream.ok) {\n const text = await upstream.text().catch(() => \"\");\n\n if (upstream.status >= 500) {\n log.error(\n `Upstream ${upstream.status} for ${request.method} ${subPath}`,\n [text]\n );\n return Response.json(\n { code: \"INTERFERE_UPSTREAM_ERROR\", message: text },\n { status: upstream.status }\n );\n }\n if (upstream.status >= 400) {\n log.warn(`Upstream ${upstream.status} for ${request.method} ${subPath}`, [\n text,\n ]);\n return Response.json(\n { code: \"INTERFERE_UPSTREAM_WARNING\", message: text },\n { status: upstream.status }\n );\n }\n\n log.error(`Upstream ${upstream.status} for ${request.method} ${subPath}`, [\n text,\n ]);\n return Response.json(\n { code: \"INTERFERE_UPSTREAM_ERROR\", message: text },\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":";;;;AAKA,MAAM,qBAAqB;AAQ3B,SAAgB,0BAAmD;CACjE,MAAM,MAAM,kBAAkB;AAC9B,KAAI,IAAI,WAAW,KACjB,QAAO;A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,EAAE;GACvC;EACD,QAAQ,YAAY,QAAQ,IAAO;EACpC,CAAC;AAEF,KAAI,CAAC,SAAS,IAAI;EAChB,MAAM,OAAO,MAAM,SAAS,MAAM,CAAC,YAAY,GAAG;AAElD,MAAI,SAAS,UAAU,KAAK;AAC1B,OAAI,MACF,YAAY,SAAS,OAAO,OAAO,QAAQ,OAAO,GAAG,WACrD,CAAC,KAAK,CACP;AACD,UAAO,SAAS,KACd;IAAE,MAAM;IAA4B,SAAS;IAAM,EACnD,EAAE,QAAQ,SAAS,QAAQ,CAC5B;;AAEH,MAAI,SAAS,UAAU,KAAK;AAC1B,OAAI,KAAK,YAAY,SAAS,OAAO,OAAO,QAAQ,OAAO,GAAG,WAAW,CACvE,KACD,CAAC;AACF,UAAO,SAAS,KACd;IAAE,MAAM;IAA8B,SAAS;IAAM,EACrD,EAAE,QAAQ,SAAS,QAAQ,CAC5B;;AAGH,MAAI,MAAM,YAAY,SAAS,OAAO,OAAO,QAAQ,OAAO,GAAG,WAAW,CACxE,KACD,CAAC;AACF,SAAO,SAAS,KACd;GAAE,MAAM;GAA4B,SAAS;GAAM,EACnD,EAAE,QAAQ,SAAS,QAAQ,CAC5B;;AAGH,QAAO,IAAI,SAAS,SAAS,MAAM;EACjC,QAAQ,SAAS;EACjB,SAAS,EACP,gBACE,SAAS,QAAQ,IAAI,eAAe,IAAI,oBAC3C;EACF,CAAC"}
|
|
@@ -4,7 +4,7 @@ import { Envelope } from "@interfere/types/sdk/envelope";
|
|
|
4
4
|
|
|
5
5
|
//#region src/internal/server/envelope.d.ts
|
|
6
6
|
interface BuildErrorEnvelopeParams {
|
|
7
|
-
readonly context?: CaptureErrorContext;
|
|
7
|
+
readonly context?: CaptureErrorContext | undefined;
|
|
8
8
|
readonly error: unknown;
|
|
9
9
|
readonly request: NormalizedRequest | null;
|
|
10
10
|
readonly runtime: ServerCaptureRuntime;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envelope.mjs","names":["uuidv7"],"sources":["../../../src/internal/server/envelope.ts"],"sourcesContent":["import type { SessionId } from \"@interfere/types/data/session\";\nimport { sessionIdSchema } from \"@interfere/types/data/session\";\nimport type { Envelope, SessionSource } from \"@interfere/types/sdk/envelope\";\nimport { toError, toExceptions } from \"@interfere/types/sdk/errors\";\nimport type { NextjsContext } from \"@interfere/types/sdk/plugins/context/next\";\nimport type { ErrorMechanism } from \"@interfere/types/sdk/plugins/payload/errors\";\n\nimport { v7 as uuidv7 } from \"uuid\";\n\nimport { PRODUCER_VERSION } from \"../version.js\";\nimport type { ServerCaptureRuntime } from \"./runtime.js\";\nimport type { CaptureErrorContext, NormalizedRequest } from \"./types.js\";\n\nconst SESSION_HEADER = \"x-interfere-session\";\n\nconst DEFAULT_ERROR_MECHANISM: ErrorMechanism = {\n type: \"captureError\",\n handled: true,\n};\n\ninterface BuildErrorEnvelopeParams {\n readonly context?: CaptureErrorContext;\n readonly error: unknown;\n readonly request: NormalizedRequest | null;\n readonly runtime: ServerCaptureRuntime;\n}\n\nexport function buildErrorEnvelope(\n params: BuildErrorEnvelopeParams\n): Envelope<\"error\"> {\n const { error, request, context, runtime } = params;\n const session = resolveSession(request?.headers ?? new Headers());\n\n let nextjsContext: NextjsContext | undefined;\n if (context?.nextjs) {\n nextjsContext = toNextjsContext(context.nextjs);\n } else if (request) {\n nextjsContext = toNextjsRequestContext(request);\n }\n\n return {\n uuid: uuidv7(),\n v: 0,\n type: \"error\",\n payload: {\n exceptions: toExceptions(\n toError(error),\n context?.mechanism ?? DEFAULT_ERROR_MECHANISM\n ),\n },\n clientTs: Date.now(),\n runtime: runtime.runtime,\n environment: runtime.environment,\n buildId: runtime.buildId,\n releaseId: runtime.releaseId,\n producerVersion: PRODUCER_VERSION,\n sessionId: session.id,\n ...(session.source ? { sessionSource: session.source } : {}),\n ...(nextjsContext ? { context: nextjsContext } : {}),\n };\n}\n\nfunction toNextjsRequestContext(request: NormalizedRequest): NextjsContext {\n return {\n runtime: \"nextjs\",\n requestMethod: request.method,\n requestPath: request.path,\n };\n}\n\nfunction toNextjsContext(\n context: Omit<NextjsContext, \"runtime\">\n): NextjsContext {\n return {\n runtime: \"nextjs\",\n ...context,\n };\n}\n\nfunction resolveSession(headers: Headers): {\n readonly id: SessionId | null;\n readonly source?: SessionSource;\n} {\n const sessionId = headers.get(SESSION_HEADER);\n if (sessionId === null) {\n return { id: null };\n }\n\n const parsed = sessionIdSchema.safeParse(sessionId);\n if (!parsed.success) {\n return { id: null };\n }\n\n return {\n id: parsed.data,\n source: \"header\",\n };\n}\n"],"mappings":";;;;;AAaA,MAAM,iBAAiB;AAEvB,MAAM,0BAA0C;CAC9C,MAAM;CACN,SAAS;CACV;AASD,SAAgB,mBACd,QACmB;CACnB,MAAM,EAAE,OAAO,SAAS,SAAS,YAAY;CAC7C,MAAM,UAAU,eAAe,SAAS,WAAW,IAAI,SAAS,CAAC;CAEjE,IAAI;AACJ,KAAI,SAAS,OACX,iBAAgB,gBAAgB,QAAQ,OAAO;UACtC,QACT,iBAAgB,uBAAuB,QAAQ;AAGjD,QAAO;EACL,MAAMA,IAAQ;EACd,GAAG;EACH,MAAM;EACN,SAAS,EACP,YAAY,aACV,QAAQ,MAAM,EACd,SAAS,aAAa,wBACvB,EACF;EACD,UAAU,KAAK,KAAK;EACpB,SAAS,QAAQ;EACjB,aAAa,QAAQ;EACrB,SAAS,QAAQ;EACjB,WAAW,QAAQ;EACnB,iBAAiB;EACjB,WAAW,QAAQ;EACnB,GAAI,QAAQ,SAAS,EAAE,eAAe,QAAQ,QAAQ,GAAG,EAAE;EAC3D,GAAI,gBAAgB,EAAE,SAAS,eAAe,GAAG,EAAE;EACpD;;AAGH,SAAS,uBAAuB,SAA2C;AACzE,QAAO;EACL,SAAS;EACT,eAAe,QAAQ;EACvB,aAAa,QAAQ;EACtB;;AAGH,SAAS,gBACP,SACe;AACf,QAAO;EACL,SAAS;EACT,GAAG;EACJ;;AAGH,SAAS,eAAe,SAGtB;CACA,MAAM,YAAY,QAAQ,IAAI,eAAe;AAC7C,KAAI,cAAc,KAChB,QAAO,EAAE,IAAI,MAAM;CAGrB,MAAM,SAAS,gBAAgB,UAAU,UAAU;AACnD,KAAI,CAAC,OAAO,QACV,QAAO,EAAE,IAAI,MAAM;AAGrB,QAAO;EACL,IAAI,OAAO;EACX,QAAQ;EACT"}
|
|
1
|
+
{"version":3,"file":"envelope.mjs","names":["uuidv7"],"sources":["../../../src/internal/server/envelope.ts"],"sourcesContent":["import type { SessionId } from \"@interfere/types/data/session\";\nimport { sessionIdSchema } from \"@interfere/types/data/session\";\nimport type { Envelope, SessionSource } from \"@interfere/types/sdk/envelope\";\nimport { toError, toExceptions } from \"@interfere/types/sdk/errors\";\nimport type { NextjsContext } from \"@interfere/types/sdk/plugins/context/next\";\nimport type { ErrorMechanism } from \"@interfere/types/sdk/plugins/payload/errors\";\n\nimport { v7 as uuidv7 } from \"uuid\";\n\nimport { PRODUCER_VERSION } from \"../version.js\";\nimport type { ServerCaptureRuntime } from \"./runtime.js\";\nimport type { CaptureErrorContext, NormalizedRequest } from \"./types.js\";\n\nconst SESSION_HEADER = \"x-interfere-session\";\n\nconst DEFAULT_ERROR_MECHANISM: ErrorMechanism = {\n type: \"captureError\",\n handled: true,\n};\n\ninterface BuildErrorEnvelopeParams {\n readonly context?: CaptureErrorContext | undefined;\n readonly error: unknown;\n readonly request: NormalizedRequest | null;\n readonly runtime: ServerCaptureRuntime;\n}\n\nexport function buildErrorEnvelope(\n params: BuildErrorEnvelopeParams\n): Envelope<\"error\"> {\n const { error, request, context, runtime } = params;\n const session = resolveSession(request?.headers ?? new Headers());\n\n let nextjsContext: NextjsContext | undefined;\n if (context?.nextjs) {\n nextjsContext = toNextjsContext(context.nextjs);\n } else if (request) {\n nextjsContext = toNextjsRequestContext(request);\n }\n\n return {\n uuid: uuidv7(),\n v: 0,\n type: \"error\",\n payload: {\n exceptions: toExceptions(\n toError(error),\n context?.mechanism ?? DEFAULT_ERROR_MECHANISM\n ),\n },\n clientTs: Date.now(),\n runtime: runtime.runtime,\n environment: runtime.environment,\n buildId: runtime.buildId,\n releaseId: runtime.releaseId,\n producerVersion: PRODUCER_VERSION,\n sessionId: session.id,\n ...(session.source ? { sessionSource: session.source } : {}),\n ...(nextjsContext ? { context: nextjsContext } : {}),\n };\n}\n\nfunction toNextjsRequestContext(request: NormalizedRequest): NextjsContext {\n return {\n runtime: \"nextjs\",\n requestMethod: request.method,\n requestPath: request.path,\n };\n}\n\nfunction toNextjsContext(\n context: Omit<NextjsContext, \"runtime\">\n): NextjsContext {\n return {\n runtime: \"nextjs\",\n ...context,\n };\n}\n\nfunction resolveSession(headers: Headers): {\n readonly id: SessionId | null;\n readonly source?: SessionSource;\n} {\n const sessionId = headers.get(SESSION_HEADER);\n if (sessionId === null) {\n return { id: null };\n }\n\n const parsed = sessionIdSchema.safeParse(sessionId);\n if (!parsed.success) {\n return { id: null };\n }\n\n return {\n id: parsed.data,\n source: \"header\",\n };\n}\n"],"mappings":";;;;;AAaA,MAAM,iBAAiB;AAEvB,MAAM,0BAA0C;CAC9C,MAAM;CACN,SAAS;CACV;AASD,SAAgB,mBACd,QACmB;CACnB,MAAM,EAAE,OAAO,SAAS,SAAS,YAAY;CAC7C,MAAM,UAAU,eAAe,SAAS,WAAW,IAAI,SAAS,CAAC;CAEjE,IAAI;AACJ,KAAI,SAAS,OACX,iBAAgB,gBAAgB,QAAQ,OAAO;UACtC,QACT,iBAAgB,uBAAuB,QAAQ;AAGjD,QAAO;EACL,MAAMA,IAAQ;EACd,GAAG;EACH,MAAM;EACN,SAAS,EACP,YAAY,aACV,QAAQ,MAAM,EACd,SAAS,aAAa,wBACvB,EACF;EACD,UAAU,KAAK,KAAK;EACpB,SAAS,QAAQ;EACjB,aAAa,QAAQ;EACrB,SAAS,QAAQ;EACjB,WAAW,QAAQ;EACnB,iBAAiB;EACjB,WAAW,QAAQ;EACnB,GAAI,QAAQ,SAAS,EAAE,eAAe,QAAQ,QAAQ,GAAG,EAAE;EAC3D,GAAI,gBAAgB,EAAE,SAAS,eAAe,GAAG,EAAE;EACpD;;AAGH,SAAS,uBAAuB,SAA2C;AACzE,QAAO;EACL,SAAS;EACT,eAAe,QAAQ;EACvB,aAAa,QAAQ;EACtB;;AAGH,SAAS,gBACP,SACe;AACf,QAAO;EACL,SAAS;EACT,GAAG;EACJ;;AAGH,SAAS,eAAe,SAGtB;CACA,MAAM,YAAY,QAAQ,IAAI,eAAe;AAC7C,KAAI,cAAc,KAChB,QAAO,EAAE,IAAI,MAAM;CAGrB,MAAM,SAAS,gBAAgB,UAAU,UAAU;AACnD,KAAI,CAAC,OAAO,QACV,QAAO,EAAE,IAAI,MAAM;AAGrB,QAAO;EACL,IAAI,OAAO;EACX,QAAQ;EACT"}
|
|
@@ -5,7 +5,7 @@ import { Envelope } from "@interfere/types/sdk/envelope";
|
|
|
5
5
|
interface SendEnvelopeInput {
|
|
6
6
|
readonly envelope: Envelope<"error">;
|
|
7
7
|
readonly runtime: ServerCaptureRuntime;
|
|
8
|
-
readonly traceparent?: string;
|
|
8
|
+
readonly traceparent?: string | undefined;
|
|
9
9
|
}
|
|
10
10
|
declare function sendEnvelope(input: SendEnvelopeInput): Promise<void>;
|
|
11
11
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.mjs","names":[],"sources":["../../../src/internal/server/transport.ts"],"sourcesContent":["import type { Envelope } from \"@interfere/types/sdk/envelope\";\n\nimport type { ServerCaptureRuntime } from \"./runtime.js\";\n\nexport interface SendEnvelopeInput {\n readonly envelope: Envelope<\"error\">;\n readonly runtime: ServerCaptureRuntime;\n readonly traceparent?: string;\n}\n\nexport async function sendEnvelope(input: SendEnvelopeInput): Promise<void> {\n const { envelope, runtime, traceparent } = input;\n\n if (runtime.apiKey === null) {\n return;\n }\n\n await fetch(runtime.ingestUrl, {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n \"x-api-key\": runtime.apiKey,\n ...(traceparent ? { traceparent } : {}),\n },\n body: JSON.stringify([envelope]),\n keepalive: true,\n });\n}\n"],"mappings":";AAUA,eAAsB,aAAa,OAAyC;CAC1E,MAAM,EAAE,UAAU,SAAS,gBAAgB;AAE3C,KAAI,QAAQ,WAAW,KACrB;AAGF,OAAM,MAAM,QAAQ,WAAW;EAC7B,QAAQ;EACR,SAAS;GACP,gBAAgB;GAChB,aAAa,QAAQ;GACrB,GAAI,cAAc,EAAE,aAAa,GAAG,EAAE;GACvC;EACD,MAAM,KAAK,UAAU,CAAC,SAAS,CAAC;EAChC,WAAW;EACZ,CAAC"}
|
|
1
|
+
{"version":3,"file":"transport.mjs","names":[],"sources":["../../../src/internal/server/transport.ts"],"sourcesContent":["import type { Envelope } from \"@interfere/types/sdk/envelope\";\n\nimport type { ServerCaptureRuntime } from \"./runtime.js\";\n\nexport interface SendEnvelopeInput {\n readonly envelope: Envelope<\"error\">;\n readonly runtime: ServerCaptureRuntime;\n readonly traceparent?: string | undefined;\n}\n\nexport async function sendEnvelope(input: SendEnvelopeInput): Promise<void> {\n const { envelope, runtime, traceparent } = input;\n\n if (runtime.apiKey === null) {\n return;\n }\n\n await fetch(runtime.ingestUrl, {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n \"x-api-key\": runtime.apiKey,\n ...(traceparent ? { traceparent } : {}),\n },\n body: JSON.stringify([envelope]),\n keepalive: true,\n });\n}\n"],"mappings":";AAUA,eAAsB,aAAa,OAAyC;CAC1E,MAAM,EAAE,UAAU,SAAS,gBAAgB;AAE3C,KAAI,QAAQ,WAAW,KACrB;AAGF,OAAM,MAAM,QAAQ,WAAW;EAC7B,QAAQ;EACR,SAAS;GACP,gBAAgB;GAChB,aAAa,QAAQ;GACrB,GAAI,cAAc,EAAE,aAAa,GAAG,EAAE;GACvC;EACD,MAAM,KAAK,UAAU,CAAC,SAAS,CAAC;EAChC,WAAW;EACZ,CAAC"}
|
package/dist/package.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@interfere/next",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Build software that never breaks.",
|
|
6
6
|
"keywords": [
|
|
@@ -64,10 +64,10 @@
|
|
|
64
64
|
"test": "bun run test:unit"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@interfere/constants": "^
|
|
68
|
-
"@interfere/react": "^
|
|
69
|
-
"@interfere/sdk": "^
|
|
70
|
-
"@interfere/types": "^
|
|
67
|
+
"@interfere/constants": "^8.0.0",
|
|
68
|
+
"@interfere/react": "^8.0.0",
|
|
69
|
+
"@interfere/sdk": "^8.0.0",
|
|
70
|
+
"@interfere/types": "^8.0.0",
|
|
71
71
|
"chalk": "^5.6.2",
|
|
72
72
|
"uuid": "^13.0.0"
|
|
73
73
|
},
|
|
@@ -78,8 +78,8 @@
|
|
|
78
78
|
"react-dom": ">=19"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"@interfere/typescript-config": "^
|
|
82
|
-
"@interfere/vitest-config": "^
|
|
81
|
+
"@interfere/typescript-config": "^8.0.0",
|
|
82
|
+
"@interfere/vitest-config": "^8.0.0",
|
|
83
83
|
"@testing-library/react": "^16.3.2",
|
|
84
84
|
"@types/node": "^24.12.0",
|
|
85
85
|
"@types/react": "19.2.14",
|
|
@@ -88,8 +88,8 @@
|
|
|
88
88
|
"@vitest/browser": "4.1.0",
|
|
89
89
|
"@vitest/browser-playwright": "4.1.0",
|
|
90
90
|
"@vitest/coverage-v8": "^4.0.18",
|
|
91
|
-
"jsdom": "^29.0.
|
|
92
|
-
"next": "^16.1
|
|
91
|
+
"jsdom": "^29.0.1",
|
|
92
|
+
"next": "^16.2.1",
|
|
93
93
|
"playwright": "^1.56.1",
|
|
94
94
|
"react": "^19.2.4",
|
|
95
95
|
"react-dom": "^19.2.4",
|