@frontmcp/utils 1.8.7 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,172 @@
1
+ var __frontmcpModule = typeof process !== "undefined" && typeof process.getBuiltinModule === "function" ? process.getBuiltinModule("module") : undefined;
2
+ const require = __frontmcpModule ? __frontmcpModule.createRequire(import.meta.url || 'file:///') : undefined;
3
+ // __frontmcpCreateRequire
4
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
5
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
6
+ }) : x)(function(x) {
7
+ if (typeof require !== "undefined") return require.apply(this, arguments);
8
+ throw Error('Dynamic require of "' + x + '" is not supported');
9
+ });
10
+
11
+ // libs/utils/src/env/runtime-context.ts
12
+ import { z } from "@frontmcp/lazy-zod";
13
+ import { getNodeEnv, isEdgeRuntime, isServerless } from "#env";
14
+
15
+ // libs/utils/src/env/build-target.ts
16
+ var cached;
17
+ function getBuildTarget() {
18
+ if (cached) return cached;
19
+ cached = resolveBuildTarget();
20
+ return cached;
21
+ }
22
+ function resolveBuildTarget() {
23
+ const globalAny = globalThis;
24
+ const fromGlobal = globalAny.FRONTMCP_BUILD_TARGET;
25
+ if (typeof fromGlobal === "string" && isKnownTarget(fromGlobal)) return fromGlobal;
26
+ const fromEnv = typeof process !== "undefined" ? process.env?.["FRONTMCP_BUILD_TARGET"] : void 0;
27
+ if (typeof fromEnv === "string" && isKnownTarget(fromEnv)) return fromEnv;
28
+ return "unknown";
29
+ }
30
+ function isKnownTarget(value) {
31
+ return value === "unknown" || value === "node" || value === "distributed" || value === "cli" || value === "vercel" || value === "lambda" || value === "cloudflare" || value === "browser" || value === "sdk" || value === "mcpb";
32
+ }
33
+
34
+ // libs/utils/src/env/provider.ts
35
+ var cached2;
36
+ function detectProvider() {
37
+ if (cached2) return cached2;
38
+ cached2 = detectProviderUncached();
39
+ return cached2;
40
+ }
41
+ function detectProviderUncached() {
42
+ const explicit = process.env["FRONTMCP_PROVIDER"];
43
+ if (explicit && isKnownProvider(explicit)) return explicit;
44
+ if (process.env["VERCEL"]) return "vercel";
45
+ if (process.env["AWS_LAMBDA_FUNCTION_NAME"]) return "lambda";
46
+ if (process.env["CF_PAGES"]) return "cloudflare";
47
+ if (process.env["NETLIFY"]) return "netlify";
48
+ if (process.env["AZURE_FUNCTIONS_ENVIRONMENT"]) return "azure";
49
+ if (process.env["K_SERVICE"]) return "gcp";
50
+ if (process.env["FLY_APP_NAME"]) return "fly";
51
+ if (process.env["RENDER"]) return "render";
52
+ if (process.env["RAILWAY_ENVIRONMENT"]) return "railway";
53
+ try {
54
+ const nodeFs = __require("node:fs");
55
+ if (nodeFs.existsSync("/.dockerenv")) return "docker";
56
+ } catch {
57
+ }
58
+ return "bare";
59
+ }
60
+ function isKnownProvider(value) {
61
+ return value === "bare" || value === "docker" || value === "vercel" || value === "lambda" || value === "cloudflare" || value === "netlify" || value === "azure" || value === "gcp" || value === "fly" || value === "render" || value === "railway";
62
+ }
63
+
64
+ // libs/utils/src/env/runtime-context.ts
65
+ var entryAvailabilitySchema = z.object({
66
+ os: z.array(z.string().min(1)).optional(),
67
+ platform: z.array(z.string().min(1)).optional(),
68
+ runtime: z.array(z.string().min(1)).optional(),
69
+ deployment: z.array(z.string().min(1)).optional(),
70
+ provider: z.array(z.string().min(1)).optional(),
71
+ target: z.array(z.string().min(1)).optional(),
72
+ surface: z.array(z.enum(["mcp", "cli", "http-trigger", "job", "agent", "webmcp"])).optional(),
73
+ env: z.array(z.string().min(1)).optional()
74
+ }).strict();
75
+ var PROCESS_AXES = [
76
+ // `os` and `platform` both compare against the same RuntimeContext value
77
+ // — keeping `platform` as a deprecated alias lets pre-#417 metadata
78
+ // continue to match without any code change.
79
+ { key: "os", ctxKey: "os" },
80
+ { key: "platform", ctxKey: "platform" },
81
+ { key: "runtime", ctxKey: "runtime" },
82
+ { key: "deployment", ctxKey: "deployment" },
83
+ { key: "provider", ctxKey: "provider" },
84
+ { key: "target", ctxKey: "target" },
85
+ { key: "env", ctxKey: "env" }
86
+ ];
87
+ function isEntryAvailable(availability, ctx, callCtx) {
88
+ if (!availability) return true;
89
+ for (const { key, ctxKey } of PROCESS_AXES) {
90
+ const allowed = availability[key];
91
+ if (allowed === void 0) continue;
92
+ if (allowed.length === 0) return false;
93
+ if (!allowed.includes(ctx[ctxKey])) return false;
94
+ }
95
+ if (availability.surface !== void 0) {
96
+ if (availability.surface.length === 0) return false;
97
+ if (callCtx?.surface !== void 0 && !availability.surface.includes(callCtx.surface)) {
98
+ return false;
99
+ }
100
+ }
101
+ return true;
102
+ }
103
+ function checkEntryAvailability(availability, ctx, callCtx) {
104
+ if (!availability) return { available: true, missingAxes: [] };
105
+ const missing = [];
106
+ for (const { key, ctxKey } of PROCESS_AXES) {
107
+ const allowed = availability[key];
108
+ if (allowed === void 0) continue;
109
+ if (allowed.length === 0 || !allowed.includes(ctx[ctxKey])) {
110
+ missing.push(key);
111
+ }
112
+ }
113
+ if (availability.surface !== void 0) {
114
+ if (availability.surface.length === 0) {
115
+ missing.push("surface");
116
+ } else if (callCtx?.surface !== void 0 && !availability.surface.includes(callCtx.surface)) {
117
+ missing.push("surface");
118
+ }
119
+ }
120
+ return { available: missing.length === 0, missingAxes: missing };
121
+ }
122
+ function detectRuntime() {
123
+ if (typeof globalThis !== "undefined" && "Bun" in globalThis) return "bun";
124
+ if (typeof globalThis !== "undefined" && "Deno" in globalThis) return "deno";
125
+ if (isEdgeRuntime()) return "edge";
126
+ return "node";
127
+ }
128
+ function detectDeployment(runtime) {
129
+ const explicit = process.env["FRONTMCP_DEPLOYMENT_MODE"];
130
+ if (explicit === "distributed") return "distributed";
131
+ if (explicit === "serverless") return "serverless";
132
+ if (runtime === "browser") return "browser";
133
+ if (isServerless()) return "serverless";
134
+ return "standalone";
135
+ }
136
+ function detectRuntimeContext() {
137
+ const runtime = detectRuntime();
138
+ const os = process.platform;
139
+ return {
140
+ os,
141
+ platform: os,
142
+ runtime,
143
+ deployment: detectDeployment(runtime),
144
+ provider: detectProvider(),
145
+ target: getBuildTarget(),
146
+ env: getNodeEnv() || "development"
147
+ };
148
+ }
149
+ var cached3;
150
+ function getRuntimeContext() {
151
+ if (!cached3) {
152
+ const detected = detectRuntimeContext();
153
+ Object.defineProperty(detected, "env", {
154
+ get: () => getNodeEnv() || "development",
155
+ enumerable: true,
156
+ configurable: true
157
+ });
158
+ cached3 = detected;
159
+ }
160
+ return cached3;
161
+ }
162
+ function resetRuntimeContext() {
163
+ cached3 = void 0;
164
+ }
165
+ export {
166
+ checkEntryAvailability,
167
+ detectRuntimeContext,
168
+ entryAvailabilitySchema,
169
+ getRuntimeContext,
170
+ isEntryAvailable,
171
+ resetRuntimeContext
172
+ };
@@ -1,4 +1,4 @@
1
- const __frontmcpModule = typeof process !== "undefined" && typeof process.getBuiltinModule === "function" ? process.getBuiltinModule("module") : undefined;
1
+ var __frontmcpModule = typeof process !== "undefined" && typeof process.getBuiltinModule === "function" ? process.getBuiltinModule("module") : undefined;
2
2
  const require = __frontmcpModule ? __frontmcpModule.createRequire(import.meta.url || 'file:///') : undefined;
3
3
  // __frontmcpCreateRequire
4
4
  // libs/utils/src/event-emitter/browser-event-emitter.ts
@@ -1,4 +1,4 @@
1
- const __frontmcpModule = typeof process !== "undefined" && typeof process.getBuiltinModule === "function" ? process.getBuiltinModule("module") : undefined;
1
+ var __frontmcpModule = typeof process !== "undefined" && typeof process.getBuiltinModule === "function" ? process.getBuiltinModule("module") : undefined;
2
2
  const require = __frontmcpModule ? __frontmcpModule.createRequire(import.meta.url || 'file:///') : undefined;
3
3
  // __frontmcpCreateRequire
4
4
  // libs/utils/src/event-emitter/node-event-emitter.ts