@frontmcp/utils 1.10.8 → 1.10.9-rc.2

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.
@@ -1,179 +1 @@
1
- // libs/utils/src/crypto/node.ts
2
- import crypto from "node:crypto";
3
-
4
- // libs/utils/src/crypto/jwt-alg.ts
5
- var JWT_ALG_TO_NODE_DIGEST = {
6
- RS256: "RSA-SHA256",
7
- RS384: "RSA-SHA384",
8
- RS512: "RSA-SHA512",
9
- // For RSA-PSS, Node's crypto.sign/verify uses the digest algorithm + explicit PSS padding options.
10
- PS256: "RSA-SHA256",
11
- PS384: "RSA-SHA384",
12
- PS512: "RSA-SHA512"
13
- };
14
- function jwtAlgToNodeAlg(jwtAlg) {
15
- const nodeAlg = JWT_ALG_TO_NODE_DIGEST[jwtAlg];
16
- if (!nodeAlg) {
17
- throw new Error(`Unsupported JWT algorithm: ${jwtAlg}`);
18
- }
19
- return nodeAlg;
20
- }
21
- function isRsaPssAlg(jwtAlg) {
22
- return jwtAlg.startsWith("PS");
23
- }
24
-
25
- // libs/utils/src/crypto/node.ts
26
- function toUint8Array(buf) {
27
- return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
28
- }
29
- function toBuffer(data) {
30
- if (typeof data === "string") {
31
- return Buffer.from(data, "utf8");
32
- }
33
- return Buffer.from(data);
34
- }
35
- var nodeCrypto = {
36
- randomUUID() {
37
- return crypto.randomUUID();
38
- },
39
- randomBytes(length) {
40
- return toUint8Array(crypto.randomBytes(length));
41
- },
42
- sha256(data) {
43
- const hash = crypto.createHash("sha256").update(toBuffer(data)).digest();
44
- return toUint8Array(hash);
45
- },
46
- sha256Hex(data) {
47
- return crypto.createHash("sha256").update(toBuffer(data)).digest("hex");
48
- },
49
- hmacSha256(key, data) {
50
- const hmac = crypto.createHmac("sha256", Buffer.from(key)).update(Buffer.from(data)).digest();
51
- return toUint8Array(hmac);
52
- },
53
- hkdfSha256(ikm, salt, info, length) {
54
- const ikmBuf = Buffer.from(ikm);
55
- const saltBuf = salt.length > 0 ? Buffer.from(salt) : Buffer.alloc(32);
56
- const prk = crypto.createHmac("sha256", saltBuf).update(ikmBuf).digest();
57
- const hashLen = 32;
58
- const n = Math.ceil(length / hashLen);
59
- const chunks = [];
60
- let prev = Buffer.alloc(0);
61
- for (let i = 1; i <= n; i++) {
62
- prev = crypto.createHmac("sha256", prk).update(Buffer.concat([prev, Buffer.from(info), Buffer.from([i])])).digest();
63
- chunks.push(prev);
64
- }
65
- return toUint8Array(Buffer.concat(chunks).subarray(0, length));
66
- },
67
- encryptAesGcm(key, plaintext, iv) {
68
- const cipher = crypto.createCipheriv("aes-256-gcm", Buffer.from(key), Buffer.from(iv));
69
- const encrypted = Buffer.concat([cipher.update(Buffer.from(plaintext)), cipher.final()]);
70
- const tag = cipher.getAuthTag();
71
- return {
72
- ciphertext: toUint8Array(encrypted),
73
- tag: toUint8Array(tag)
74
- };
75
- },
76
- decryptAesGcm(key, ciphertext, iv, tag) {
77
- const decipher = crypto.createDecipheriv("aes-256-gcm", Buffer.from(key), Buffer.from(iv));
78
- decipher.setAuthTag(Buffer.from(tag));
79
- const decrypted = Buffer.concat([decipher.update(Buffer.from(ciphertext)), decipher.final()]);
80
- return toUint8Array(decrypted);
81
- },
82
- timingSafeEqual(a, b) {
83
- if (a.length !== b.length) return false;
84
- return crypto.timingSafeEqual(Buffer.from(a), Buffer.from(b));
85
- }
86
- };
87
- function generateRsaKeyPair(modulusLength = 2048, alg = "RS256") {
88
- const kid = `rsa-key-${Date.now()}-${crypto.randomBytes(8).toString("hex")}`;
89
- const { privateKey, publicKey } = crypto.generateKeyPairSync("rsa", {
90
- modulusLength
91
- });
92
- const exported = publicKey.export({ format: "jwk" });
93
- const publicJwk = {
94
- ...exported,
95
- kid,
96
- alg,
97
- use: "sig",
98
- kty: "RSA"
99
- };
100
- return { privateKey, publicKey, publicJwk };
101
- }
102
- function rsaSign(algorithm, data, privateKey, options) {
103
- const signingKey = options ? { key: privateKey, ...options } : privateKey;
104
- return crypto.sign(algorithm, data, signingKey);
105
- }
106
- function rsaVerify(jwtAlg, data, publicJwk, signature) {
107
- const publicKey = crypto.createPublicKey({ key: publicJwk, format: "jwk" });
108
- const nodeAlgorithm = jwtAlgToNodeAlg(jwtAlg);
109
- const verifyKey = isRsaPssAlg(jwtAlg) ? {
110
- key: publicKey,
111
- padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
112
- saltLength: crypto.constants.RSA_PSS_SALTLEN_DIGEST
113
- } : publicKey;
114
- return crypto.verify(nodeAlgorithm, data, verifyKey, signature);
115
- }
116
- function rsaSignBase64Url(jwtAlg, data, privateJwk) {
117
- const privateKey = crypto.createPrivateKey({ key: privateJwk, format: "jwk" });
118
- const nodeAlgorithm = jwtAlgToNodeAlg(jwtAlg);
119
- const buf = Buffer.isBuffer(data) ? data : Buffer.from(data);
120
- const sig = isRsaPssAlg(jwtAlg) ? rsaSign(nodeAlgorithm, buf, privateKey, {
121
- padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
122
- saltLength: crypto.constants.RSA_PSS_SALTLEN_DIGEST
123
- }) : rsaSign(nodeAlgorithm, buf, privateKey);
124
- return sig.toString("base64url");
125
- }
126
- function rsaVerifySync(jwtAlg, data, publicJwk, signature) {
127
- try {
128
- const publicKey = crypto.createPublicKey({ key: publicJwk, format: "jwk" });
129
- const dataBuf = Buffer.isBuffer(data) ? data : Buffer.from(data);
130
- const sigBuf = Buffer.isBuffer(signature) ? signature : Buffer.from(signature);
131
- if (jwtAlg === "EdDSA") {
132
- return crypto.verify(null, dataBuf, publicKey, sigBuf);
133
- }
134
- const nodeAlgorithm = jwtAlgToNodeAlg(jwtAlg);
135
- const verifyKey = isRsaPssAlg(jwtAlg) ? {
136
- key: publicKey,
137
- padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
138
- saltLength: crypto.constants.RSA_PSS_SALTLEN_DIGEST
139
- } : publicKey;
140
- return crypto.verify(nodeAlgorithm, dataBuf, verifyKey, sigBuf);
141
- } catch {
142
- return false;
143
- }
144
- }
145
- function pemToPublicJwk(pem) {
146
- const key = crypto.createPublicKey({ key: pem, format: "pem" });
147
- return key.export({ format: "jwk" });
148
- }
149
- function createSignedJwt(payload, privateKey, kid, alg = "RS256") {
150
- const header = { alg, typ: "JWT", kid };
151
- const headerB64 = Buffer.from(JSON.stringify(header)).toString("base64url");
152
- const payloadB64 = Buffer.from(JSON.stringify(payload)).toString("base64url");
153
- const signatureInput = `${headerB64}.${payloadB64}`;
154
- const nodeAlgorithm = jwtAlgToNodeAlg(alg);
155
- const signature = rsaSign(
156
- nodeAlgorithm,
157
- Buffer.from(signatureInput),
158
- privateKey,
159
- isRsaPssAlg(alg) ? {
160
- padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
161
- saltLength: crypto.constants.RSA_PSS_SALTLEN_DIGEST
162
- } : void 0
163
- );
164
- const signatureB64 = signature.toString("base64url");
165
- return `${headerB64}.${payloadB64}.${signatureB64}`;
166
- }
167
- export {
168
- createSignedJwt,
169
- nodeCrypto as cryptoProvider,
170
- generateRsaKeyPair,
171
- isRsaPssAlg,
172
- jwtAlgToNodeAlg,
173
- nodeCrypto,
174
- pemToPublicJwk,
175
- rsaSign,
176
- rsaSignBase64Url,
177
- rsaVerify,
178
- rsaVerifySync
179
- };
1
+ import crypto from"node:crypto";var JWT_ALG_TO_NODE_DIGEST={RS256:"RSA-SHA256",RS384:"RSA-SHA384",RS512:"RSA-SHA512",PS256:"RSA-SHA256",PS384:"RSA-SHA384",PS512:"RSA-SHA512"};function jwtAlgToNodeAlg(jwtAlg){const nodeAlg=JWT_ALG_TO_NODE_DIGEST[jwtAlg];if(!nodeAlg){throw new Error(`Unsupported JWT algorithm: ${jwtAlg}`)}return nodeAlg}function isRsaPssAlg(jwtAlg){return jwtAlg.startsWith("PS")}function toUint8Array(buf){return new Uint8Array(buf.buffer,buf.byteOffset,buf.byteLength)}function toBuffer(data){if(typeof data==="string"){return Buffer.from(data,"utf8")}return Buffer.from(data)}var nodeCrypto={randomUUID(){return crypto.randomUUID()},randomBytes(length){return toUint8Array(crypto.randomBytes(length))},sha256(data){const hash=crypto.createHash("sha256").update(toBuffer(data)).digest();return toUint8Array(hash)},sha256Hex(data){return crypto.createHash("sha256").update(toBuffer(data)).digest("hex")},hmacSha256(key,data){const hmac=crypto.createHmac("sha256",Buffer.from(key)).update(Buffer.from(data)).digest();return toUint8Array(hmac)},hkdfSha256(ikm,salt,info,length){const ikmBuf=Buffer.from(ikm);const saltBuf=salt.length>0?Buffer.from(salt):Buffer.alloc(32);const prk=crypto.createHmac("sha256",saltBuf).update(ikmBuf).digest();const hashLen=32;const n=Math.ceil(length/hashLen);const chunks=[];let prev=Buffer.alloc(0);for(let i=1;i<=n;i++){prev=crypto.createHmac("sha256",prk).update(Buffer.concat([prev,Buffer.from(info),Buffer.from([i])])).digest();chunks.push(prev)}return toUint8Array(Buffer.concat(chunks).subarray(0,length))},encryptAesGcm(key,plaintext,iv){const cipher=crypto.createCipheriv("aes-256-gcm",Buffer.from(key),Buffer.from(iv));const encrypted=Buffer.concat([cipher.update(Buffer.from(plaintext)),cipher.final()]);const tag=cipher.getAuthTag();return{ciphertext:toUint8Array(encrypted),tag:toUint8Array(tag)}},decryptAesGcm(key,ciphertext,iv,tag){const decipher=crypto.createDecipheriv("aes-256-gcm",Buffer.from(key),Buffer.from(iv));decipher.setAuthTag(Buffer.from(tag));const decrypted=Buffer.concat([decipher.update(Buffer.from(ciphertext)),decipher.final()]);return toUint8Array(decrypted)},timingSafeEqual(a,b){if(a.length!==b.length)return false;return crypto.timingSafeEqual(Buffer.from(a),Buffer.from(b))}};function generateRsaKeyPair(modulusLength=2048,alg="RS256"){const kid=`rsa-key-${Date.now()}-${crypto.randomBytes(8).toString("hex")}`;const{privateKey,publicKey}=crypto.generateKeyPairSync("rsa",{modulusLength});const exported=publicKey.export({format:"jwk"});const publicJwk={...exported,kid,alg,use:"sig",kty:"RSA"};return{privateKey,publicKey,publicJwk}}function rsaSign(algorithm,data,privateKey,options){const signingKey=options?{key:privateKey,...options}:privateKey;return crypto.sign(algorithm,data,signingKey)}function rsaVerify(jwtAlg,data,publicJwk,signature){const publicKey=crypto.createPublicKey({key:publicJwk,format:"jwk"});const nodeAlgorithm=jwtAlgToNodeAlg(jwtAlg);const verifyKey=isRsaPssAlg(jwtAlg)?{key:publicKey,padding:crypto.constants.RSA_PKCS1_PSS_PADDING,saltLength:crypto.constants.RSA_PSS_SALTLEN_DIGEST}:publicKey;return crypto.verify(nodeAlgorithm,data,verifyKey,signature)}function rsaSignBase64Url(jwtAlg,data,privateJwk){const privateKey=crypto.createPrivateKey({key:privateJwk,format:"jwk"});const nodeAlgorithm=jwtAlgToNodeAlg(jwtAlg);const buf=Buffer.isBuffer(data)?data:Buffer.from(data);const sig=isRsaPssAlg(jwtAlg)?rsaSign(nodeAlgorithm,buf,privateKey,{padding:crypto.constants.RSA_PKCS1_PSS_PADDING,saltLength:crypto.constants.RSA_PSS_SALTLEN_DIGEST}):rsaSign(nodeAlgorithm,buf,privateKey);return sig.toString("base64url")}function rsaVerifySync(jwtAlg,data,publicJwk,signature){try{const publicKey=crypto.createPublicKey({key:publicJwk,format:"jwk"});const dataBuf=Buffer.isBuffer(data)?data:Buffer.from(data);const sigBuf=Buffer.isBuffer(signature)?signature:Buffer.from(signature);if(jwtAlg==="EdDSA"){return crypto.verify(null,dataBuf,publicKey,sigBuf)}const nodeAlgorithm=jwtAlgToNodeAlg(jwtAlg);const verifyKey=isRsaPssAlg(jwtAlg)?{key:publicKey,padding:crypto.constants.RSA_PKCS1_PSS_PADDING,saltLength:crypto.constants.RSA_PSS_SALTLEN_DIGEST}:publicKey;return crypto.verify(nodeAlgorithm,dataBuf,verifyKey,sigBuf)}catch{return false}}function pemToPublicJwk(pem){const key=crypto.createPublicKey({key:pem,format:"pem"});return key.export({format:"jwk"})}function createSignedJwt(payload,privateKey,kid,alg="RS256"){const header={alg,typ:"JWT",kid};const headerB64=Buffer.from(JSON.stringify(header)).toString("base64url");const payloadB64=Buffer.from(JSON.stringify(payload)).toString("base64url");const signatureInput=`${headerB64}.${payloadB64}`;const nodeAlgorithm=jwtAlgToNodeAlg(alg);const signature=rsaSign(nodeAlgorithm,Buffer.from(signatureInput),privateKey,isRsaPssAlg(alg)?{padding:crypto.constants.RSA_PKCS1_PSS_PADDING,saltLength:crypto.constants.RSA_PSS_SALTLEN_DIGEST}:void 0);const signatureB64=signature.toString("base64url");return`${headerB64}.${payloadB64}.${signatureB64}`}export{createSignedJwt,nodeCrypto as cryptoProvider,generateRsaKeyPair,isRsaPssAlg,jwtAlgToNodeAlg,nodeCrypto,pemToPublicJwk,rsaSign,rsaSignBase64Url,rsaVerify,rsaVerifySync};
@@ -1,70 +1 @@
1
- // libs/utils/src/env/edge-scope.ts
2
- function hasEdgeGlobalScope() {
3
- if (typeof globalThis === "undefined") return false;
4
- if ("EdgeRuntime" in globalThis) return true;
5
- if (!("caches" in globalThis) || "window" in globalThis) return false;
6
- return !isBrowserWorkerScope();
7
- }
8
- function isBrowserWorkerScope() {
9
- const userAgent = typeof navigator === "undefined" ? void 0 : navigator.userAgent;
10
- if (userAgent === void 0 || userAgent === "Cloudflare-Workers") return false;
11
- return ["DedicatedWorkerGlobalScope", "SharedWorkerGlobalScope", "ServiceWorkerGlobalScope"].some(
12
- (scopeName) => scopeName in globalThis
13
- );
14
- }
15
-
16
- // libs/utils/src/env/browser-env.ts
17
- var NODE_ENV_KEY = "NODE_ENV";
18
- function bundlerDefinedNodeEnv() {
19
- try {
20
- return process.env["NODE_ENV"] || void 0;
21
- } catch {
22
- return void 0;
23
- }
24
- }
25
- function getEnv(_key, defaultValue) {
26
- return defaultValue;
27
- }
28
- function getCwd() {
29
- return "/";
30
- }
31
- function getNodeEnv() {
32
- const shim = globalThis.process;
33
- return shim?.env?.[NODE_ENV_KEY] || bundlerDefinedNodeEnv();
34
- }
35
- function isProduction() {
36
- return getNodeEnv() === "production";
37
- }
38
- function isDevelopment() {
39
- return getNodeEnv() === "development";
40
- }
41
- function getEnvFlag(_key) {
42
- return false;
43
- }
44
- function isDebug() {
45
- return false;
46
- }
47
- function setEnv(_key, _value) {
48
- }
49
- function isEdgeRuntime() {
50
- return hasEdgeGlobalScope();
51
- }
52
- function isServerless() {
53
- return false;
54
- }
55
- function supportsAnsi() {
56
- return false;
57
- }
58
- export {
59
- getCwd,
60
- getEnv,
61
- getEnvFlag,
62
- getNodeEnv,
63
- isDebug,
64
- isDevelopment,
65
- isEdgeRuntime,
66
- isProduction,
67
- isServerless,
68
- setEnv,
69
- supportsAnsi
70
- };
1
+ function hasEdgeGlobalScope(){if(typeof globalThis==="undefined")return false;if("EdgeRuntime"in globalThis)return true;if(!("caches"in globalThis)||"window"in globalThis)return false;return!isBrowserWorkerScope()}function isBrowserWorkerScope(){const userAgent=typeof navigator==="undefined"?void 0:navigator.userAgent;if(userAgent===void 0||userAgent==="Cloudflare-Workers")return false;return["DedicatedWorkerGlobalScope","SharedWorkerGlobalScope","ServiceWorkerGlobalScope"].some(scopeName=>scopeName in globalThis)}var NODE_ENV_KEY="NODE_ENV";function bundlerDefinedNodeEnv(){try{return process.env["NODE_ENV"]||void 0}catch{return void 0}}function getEnv(_key,defaultValue){return defaultValue}function getCwd(){return"/"}function getNodeEnv(){const shim=globalThis.process;return shim?.env?.[NODE_ENV_KEY]||bundlerDefinedNodeEnv()}function isProduction(){return getNodeEnv()==="production"}function isDevelopment(){return getNodeEnv()==="development"}function getEnvFlag(_key){return false}function isDebug(){return false}function setEnv(_key,_value){}function isEdgeRuntime(){return hasEdgeGlobalScope()}function isServerless(){return false}function supportsAnsi(){return false}export{getCwd,getEnv,getEnvFlag,getNodeEnv,isDebug,isDevelopment,isEdgeRuntime,isProduction,isServerless,setEnv,supportsAnsi};
@@ -1,100 +1 @@
1
- // libs/utils/src/env/browser-runtime-context.ts
2
- import { z } from "@frontmcp/lazy-zod";
3
-
4
- // libs/utils/src/env/browser-env.ts
5
- var NODE_ENV_KEY = "NODE_ENV";
6
- function bundlerDefinedNodeEnv() {
7
- try {
8
- return process.env["NODE_ENV"] || void 0;
9
- } catch {
10
- return void 0;
11
- }
12
- }
13
- function getNodeEnv() {
14
- const shim = globalThis.process;
15
- return shim?.env?.[NODE_ENV_KEY] || bundlerDefinedNodeEnv();
16
- }
17
-
18
- // libs/utils/src/env/browser-runtime-context.ts
19
- var entryAvailabilitySchema = z.object({
20
- os: z.array(z.string().min(1)).optional(),
21
- platform: z.array(z.string().min(1)).optional(),
22
- runtime: z.array(z.string().min(1)).optional(),
23
- deployment: z.array(z.string().min(1)).optional(),
24
- provider: z.array(z.string().min(1)).optional(),
25
- target: z.array(z.string().min(1)).optional(),
26
- surface: z.array(z.enum(["mcp", "cli", "http-trigger", "job", "agent", "webmcp"])).optional(),
27
- env: z.array(z.string().min(1)).optional()
28
- }).strict();
29
- var PROCESS_AXES = [
30
- { key: "os", ctxKey: "os" },
31
- { key: "platform", ctxKey: "platform" },
32
- { key: "runtime", ctxKey: "runtime" },
33
- { key: "deployment", ctxKey: "deployment" },
34
- { key: "provider", ctxKey: "provider" },
35
- { key: "target", ctxKey: "target" },
36
- { key: "env", ctxKey: "env" }
37
- ];
38
- function isEntryAvailable(availability, ctx, callCtx) {
39
- if (!availability) return true;
40
- for (const { key, ctxKey } of PROCESS_AXES) {
41
- const allowed = availability[key];
42
- if (allowed === void 0) continue;
43
- if (allowed.length === 0) return false;
44
- if (!allowed.includes(ctx[ctxKey])) return false;
45
- }
46
- if (availability.surface !== void 0) {
47
- if (availability.surface.length === 0) return false;
48
- if (callCtx?.surface !== void 0 && !availability.surface.includes(callCtx.surface)) return false;
49
- }
50
- return true;
51
- }
52
- function checkEntryAvailability(availability, ctx, callCtx) {
53
- if (!availability) return { available: true, missingAxes: [] };
54
- const missing = [];
55
- for (const { key, ctxKey } of PROCESS_AXES) {
56
- const allowed = availability[key];
57
- if (allowed === void 0) continue;
58
- if (allowed.length === 0 || !allowed.includes(ctx[ctxKey])) missing.push(key);
59
- }
60
- if (availability.surface !== void 0) {
61
- if (availability.surface.length === 0) missing.push("surface");
62
- else if (callCtx?.surface !== void 0 && !availability.surface.includes(callCtx.surface)) missing.push("surface");
63
- }
64
- return { available: missing.length === 0, missingAxes: missing };
65
- }
66
- function detectRuntimeContext() {
67
- return {
68
- os: "browser",
69
- platform: "browser",
70
- runtime: "browser",
71
- deployment: "standalone",
72
- provider: "bare",
73
- target: "browser",
74
- env: getNodeEnv() || "development"
75
- };
76
- }
77
- var cached;
78
- function getRuntimeContext() {
79
- if (!cached) {
80
- const detected = detectRuntimeContext();
81
- Object.defineProperty(detected, "env", {
82
- get: () => getNodeEnv() || "development",
83
- enumerable: true,
84
- configurable: true
85
- });
86
- cached = detected;
87
- }
88
- return cached;
89
- }
90
- function resetRuntimeContext() {
91
- cached = void 0;
92
- }
93
- export {
94
- checkEntryAvailability,
95
- detectRuntimeContext,
96
- entryAvailabilitySchema,
97
- getRuntimeContext,
98
- isEntryAvailable,
99
- resetRuntimeContext
100
- };
1
+ import{z}from"@frontmcp/lazy-zod";var NODE_ENV_KEY="NODE_ENV";function bundlerDefinedNodeEnv(){try{return process.env["NODE_ENV"]||void 0}catch{return void 0}}function getNodeEnv(){const shim=globalThis.process;return shim?.env?.[NODE_ENV_KEY]||bundlerDefinedNodeEnv()}var entryAvailabilitySchema=z.object({os:z.array(z.string().min(1)).optional(),platform:z.array(z.string().min(1)).optional(),runtime:z.array(z.string().min(1)).optional(),deployment:z.array(z.string().min(1)).optional(),provider:z.array(z.string().min(1)).optional(),target:z.array(z.string().min(1)).optional(),surface:z.array(z.enum(["mcp","cli","http-trigger","job","agent","webmcp"])).optional(),env:z.array(z.string().min(1)).optional()}).strict();var PROCESS_AXES=[{key:"os",ctxKey:"os"},{key:"platform",ctxKey:"platform"},{key:"runtime",ctxKey:"runtime"},{key:"deployment",ctxKey:"deployment"},{key:"provider",ctxKey:"provider"},{key:"target",ctxKey:"target"},{key:"env",ctxKey:"env"}];function isEntryAvailable(availability,ctx,callCtx){if(!availability)return true;for(const{key,ctxKey}of PROCESS_AXES){const allowed=availability[key];if(allowed===void 0)continue;if(allowed.length===0)return false;if(!allowed.includes(ctx[ctxKey]))return false}if(availability.surface!==void 0){if(availability.surface.length===0)return false;if(callCtx?.surface!==void 0&&!availability.surface.includes(callCtx.surface))return false}return true}function checkEntryAvailability(availability,ctx,callCtx){if(!availability)return{available:true,missingAxes:[]};const missing=[];for(const{key,ctxKey}of PROCESS_AXES){const allowed=availability[key];if(allowed===void 0)continue;if(allowed.length===0||!allowed.includes(ctx[ctxKey]))missing.push(key)}if(availability.surface!==void 0){if(availability.surface.length===0)missing.push("surface");else if(callCtx?.surface!==void 0&&!availability.surface.includes(callCtx.surface))missing.push("surface")}return{available:missing.length===0,missingAxes:missing}}function detectRuntimeContext(){return{os:"browser",platform:"browser",runtime:"browser",deployment:"standalone",provider:"bare",target:"browser",env:getNodeEnv()||"development"}}var cached;function getRuntimeContext(){if(!cached){const detected=detectRuntimeContext();Object.defineProperty(detected,"env",{get:()=>getNodeEnv()||"development",enumerable:true,configurable:true});cached=detected}return cached}function resetRuntimeContext(){cached=void 0}export{checkEntryAvailability,detectRuntimeContext,entryAvailabilitySchema,getRuntimeContext,isEntryAvailable,resetRuntimeContext};
@@ -1,70 +1 @@
1
- // libs/utils/src/env/edge-scope.ts
2
- function hasEdgeGlobalScope() {
3
- if (typeof globalThis === "undefined") return false;
4
- if ("EdgeRuntime" in globalThis) return true;
5
- if (!("caches" in globalThis) || "window" in globalThis) return false;
6
- return !isBrowserWorkerScope();
7
- }
8
- function isBrowserWorkerScope() {
9
- const userAgent = typeof navigator === "undefined" ? void 0 : navigator.userAgent;
10
- if (userAgent === void 0 || userAgent === "Cloudflare-Workers") return false;
11
- return ["DedicatedWorkerGlobalScope", "SharedWorkerGlobalScope", "ServiceWorkerGlobalScope"].some(
12
- (scopeName) => scopeName in globalThis
13
- );
14
- }
15
-
16
- // libs/utils/src/env/node-env.ts
17
- function getEnv(key, defaultValue) {
18
- return process.env[key] ?? defaultValue;
19
- }
20
- function getCwd() {
21
- return process.cwd();
22
- }
23
- var NODE_ENV_KEY = "NODE_ENV";
24
- function getNodeEnv() {
25
- return process.env[NODE_ENV_KEY] || process.env["NODE_ENV"] || void 0;
26
- }
27
- function isProduction() {
28
- return getNodeEnv() === "production";
29
- }
30
- function isDevelopment() {
31
- return getNodeEnv() === "development";
32
- }
33
- function getEnvFlag(key) {
34
- const v = process.env[key];
35
- return v === "1" || v === "true";
36
- }
37
- function isDebug() {
38
- return getEnvFlag("DEBUG");
39
- }
40
- function setEnv(key, value) {
41
- process.env[key] = value;
42
- }
43
- function isEdgeRuntime() {
44
- if (hasEdgeGlobalScope()) return true;
45
- return process.env["EDGE_RUNTIME"] !== void 0 && process.env["VERCEL_ENV"] !== void 0;
46
- }
47
- function isServerless() {
48
- return !!(process.env["VERCEL"] || process.env["NETLIFY"] || process.env["CF_PAGES"] || process.env["AWS_LAMBDA_FUNCTION_NAME"] || process.env["AZURE_FUNCTIONS_ENVIRONMENT"] || process.env["K_SERVICE"] || process.env["RAILWAY_ENVIRONMENT"] || process.env["RENDER"] || process.env["FLY_APP_NAME"]);
49
- }
50
- function supportsAnsi() {
51
- if (process.env["NO_COLOR"]) return false;
52
- const forceColor = process.env["FORCE_COLOR"];
53
- if (forceColor !== void 0) {
54
- return forceColor !== "0" && forceColor.toLowerCase() !== "false";
55
- }
56
- return process.stdout?.isTTY === true;
57
- }
58
- export {
59
- getCwd,
60
- getEnv,
61
- getEnvFlag,
62
- getNodeEnv,
63
- isDebug,
64
- isDevelopment,
65
- isEdgeRuntime,
66
- isProduction,
67
- isServerless,
68
- setEnv,
69
- supportsAnsi
70
- };
1
+ function hasEdgeGlobalScope(){if(typeof globalThis==="undefined")return false;if("EdgeRuntime"in globalThis)return true;if(!("caches"in globalThis)||"window"in globalThis)return false;return!isBrowserWorkerScope()}function isBrowserWorkerScope(){const userAgent=typeof navigator==="undefined"?void 0:navigator.userAgent;if(userAgent===void 0||userAgent==="Cloudflare-Workers")return false;return["DedicatedWorkerGlobalScope","SharedWorkerGlobalScope","ServiceWorkerGlobalScope"].some(scopeName=>scopeName in globalThis)}function getEnv(key,defaultValue){return process.env[key]??defaultValue}function getCwd(){return process.cwd()}var NODE_ENV_KEY="NODE_ENV";function getNodeEnv(){return process.env[NODE_ENV_KEY]||process.env["NODE_ENV"]||void 0}function isProduction(){return getNodeEnv()==="production"}function isDevelopment(){return getNodeEnv()==="development"}function getEnvFlag(key){const v=process.env[key];return v==="1"||v==="true"}function isDebug(){return getEnvFlag("DEBUG")}function setEnv(key,value){process.env[key]=value}function isEdgeRuntime(){if(hasEdgeGlobalScope())return true;return process.env["EDGE_RUNTIME"]!==void 0&&process.env["VERCEL_ENV"]!==void 0}function isServerless(){return!!(process.env["VERCEL"]||process.env["NETLIFY"]||process.env["CF_PAGES"]||process.env["AWS_LAMBDA_FUNCTION_NAME"]||process.env["AZURE_FUNCTIONS_ENVIRONMENT"]||process.env["K_SERVICE"]||process.env["RAILWAY_ENVIRONMENT"]||process.env["RENDER"]||process.env["FLY_APP_NAME"])}function supportsAnsi(){if(process.env["NO_COLOR"])return false;const forceColor=process.env["FORCE_COLOR"];if(forceColor!==void 0){return forceColor!=="0"&&forceColor.toLowerCase()!=="false"}return process.stdout?.isTTY===true}export{getCwd,getEnv,getEnvFlag,getNodeEnv,isDebug,isDevelopment,isEdgeRuntime,isProduction,isServerless,setEnv,supportsAnsi};
@@ -1,172 +1,4 @@
1
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
- 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
- };
4
+ var __require=(x=>typeof require!=="undefined"?require:typeof Proxy!=="undefined"?new Proxy(x,{get:(a,b)=>(typeof require!=="undefined"?require:a)[b]}):x)(function(x){if(typeof require!=="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+x+'" is not supported')});import{z}from"@frontmcp/lazy-zod";import{getNodeEnv,isEdgeRuntime,isServerless}from"#env";var cached;function getBuildTarget(){if(cached)return cached;cached=resolveBuildTarget();return cached}function resolveBuildTarget(){const globalAny=globalThis;const fromGlobal=globalAny.FRONTMCP_BUILD_TARGET;if(typeof fromGlobal==="string"&&isKnownTarget(fromGlobal))return fromGlobal;const fromEnv=typeof process!=="undefined"?process.env?.["FRONTMCP_BUILD_TARGET"]:void 0;if(typeof fromEnv==="string"&&isKnownTarget(fromEnv))return fromEnv;return"unknown"}function isKnownTarget(value){return value==="unknown"||value==="node"||value==="distributed"||value==="cli"||value==="vercel"||value==="lambda"||value==="cloudflare"||value==="browser"||value==="sdk"||value==="mcpb"}var cached2;function detectProvider(){if(cached2)return cached2;cached2=detectProviderUncached();return cached2}function detectProviderUncached(){const explicit=process.env["FRONTMCP_PROVIDER"];if(explicit&&isKnownProvider(explicit))return explicit;if(process.env["VERCEL"])return"vercel";if(process.env["AWS_LAMBDA_FUNCTION_NAME"])return"lambda";if(process.env["CF_PAGES"])return"cloudflare";if(process.env["NETLIFY"])return"netlify";if(process.env["AZURE_FUNCTIONS_ENVIRONMENT"])return"azure";if(process.env["K_SERVICE"])return"gcp";if(process.env["FLY_APP_NAME"])return"fly";if(process.env["RENDER"])return"render";if(process.env["RAILWAY_ENVIRONMENT"])return"railway";try{const nodeFs=__require("node:fs");if(nodeFs.existsSync("/.dockerenv"))return"docker"}catch{}return"bare"}function isKnownProvider(value){return value==="bare"||value==="docker"||value==="vercel"||value==="lambda"||value==="cloudflare"||value==="netlify"||value==="azure"||value==="gcp"||value==="fly"||value==="render"||value==="railway"}var entryAvailabilitySchema=z.object({os:z.array(z.string().min(1)).optional(),platform:z.array(z.string().min(1)).optional(),runtime:z.array(z.string().min(1)).optional(),deployment:z.array(z.string().min(1)).optional(),provider:z.array(z.string().min(1)).optional(),target:z.array(z.string().min(1)).optional(),surface:z.array(z.enum(["mcp","cli","http-trigger","job","agent","webmcp"])).optional(),env:z.array(z.string().min(1)).optional()}).strict();var PROCESS_AXES=[{key:"os",ctxKey:"os"},{key:"platform",ctxKey:"platform"},{key:"runtime",ctxKey:"runtime"},{key:"deployment",ctxKey:"deployment"},{key:"provider",ctxKey:"provider"},{key:"target",ctxKey:"target"},{key:"env",ctxKey:"env"}];function isEntryAvailable(availability,ctx,callCtx){if(!availability)return true;for(const{key,ctxKey}of PROCESS_AXES){const allowed=availability[key];if(allowed===void 0)continue;if(allowed.length===0)return false;if(!allowed.includes(ctx[ctxKey]))return false}if(availability.surface!==void 0){if(availability.surface.length===0)return false;if(callCtx?.surface!==void 0&&!availability.surface.includes(callCtx.surface)){return false}}return true}function checkEntryAvailability(availability,ctx,callCtx){if(!availability)return{available:true,missingAxes:[]};const missing=[];for(const{key,ctxKey}of PROCESS_AXES){const allowed=availability[key];if(allowed===void 0)continue;if(allowed.length===0||!allowed.includes(ctx[ctxKey])){missing.push(key)}}if(availability.surface!==void 0){if(availability.surface.length===0){missing.push("surface")}else if(callCtx?.surface!==void 0&&!availability.surface.includes(callCtx.surface)){missing.push("surface")}}return{available:missing.length===0,missingAxes:missing}}function detectRuntime(){if(typeof globalThis!=="undefined"&&"Bun"in globalThis)return"bun";if(typeof globalThis!=="undefined"&&"Deno"in globalThis)return"deno";if(isEdgeRuntime())return"edge";return"node"}function detectDeployment(runtime){const explicit=process.env["FRONTMCP_DEPLOYMENT_MODE"];if(explicit==="distributed")return"distributed";if(explicit==="serverless")return"serverless";if(runtime==="browser")return"browser";if(isServerless())return"serverless";return"standalone"}function detectRuntimeContext(){const runtime=detectRuntime();const os=process.platform;return{os,platform:os,runtime,deployment:detectDeployment(runtime),provider:detectProvider(),target:getBuildTarget(),env:getNodeEnv()||"development"}}var cached3;function getRuntimeContext(){if(!cached3){const detected=detectRuntimeContext();Object.defineProperty(detected,"env",{get:()=>getNodeEnv()||"development",enumerable:true,configurable:true});cached3=detected}return cached3}function resetRuntimeContext(){cached3=void 0}export{checkEntryAvailability,detectRuntimeContext,entryAvailabilitySchema,getRuntimeContext,isEntryAvailable,resetRuntimeContext};
@@ -1,49 +1 @@
1
- // libs/utils/src/event-emitter/browser-event-emitter.ts
2
- var EventEmitter = class {
3
- events = /* @__PURE__ */ new Map();
4
- emit(event, ...args) {
5
- const handlers = this.events.get(event);
6
- if (!handlers || handlers.length === 0) return false;
7
- for (const handler of [...handlers]) {
8
- handler(...args);
9
- }
10
- return true;
11
- }
12
- on(event, handler) {
13
- const list = this.events.get(event) ?? [];
14
- list.push(handler);
15
- this.events.set(event, list);
16
- return this;
17
- }
18
- off(event, handler) {
19
- const list = this.events.get(event);
20
- if (list) {
21
- const idx = list.indexOf(handler);
22
- if (idx >= 0) list.splice(idx, 1);
23
- }
24
- return this;
25
- }
26
- addListener(event, handler) {
27
- return this.on(event, handler);
28
- }
29
- removeListener(event, handler) {
30
- return this.off(event, handler);
31
- }
32
- removeAllListeners(event) {
33
- if (event !== void 0) {
34
- this.events.delete(event);
35
- } else {
36
- this.events.clear();
37
- }
38
- return this;
39
- }
40
- setMaxListeners(_n) {
41
- return this;
42
- }
43
- listenerCount(event) {
44
- return this.events.get(event)?.length ?? 0;
45
- }
46
- };
47
- export {
48
- EventEmitter
49
- };
1
+ var EventEmitter=class{events=new Map;emit(event,...args){const handlers=this.events.get(event);if(!handlers||handlers.length===0)return false;for(const handler of[...handlers]){handler(...args)}return true}on(event,handler){const list=this.events.get(event)??[];list.push(handler);this.events.set(event,list);return this}off(event,handler){const list=this.events.get(event);if(list){const idx=list.indexOf(handler);if(idx>=0)list.splice(idx,1)}return this}addListener(event,handler){return this.on(event,handler)}removeListener(event,handler){return this.off(event,handler)}removeAllListeners(event){if(event!==void 0){this.events.delete(event)}else{this.events.clear()}return this}setMaxListeners(_n){return this}listenerCount(event){return this.events.get(event)?.length??0}};export{EventEmitter};