@frontmcp/utils 1.0.0-beta.9 → 1.0.0-rc.1
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/env/browser-runtime-context.d.ts +29 -0
- package/env/index.d.ts +2 -0
- package/env/runtime-context.d.ts +84 -0
- package/esm/index.mjs +59 -9
- package/index.d.ts +2 -1
- package/index.js +76 -21
- package/package.json +6 -2
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime context detection and entry availability matching (Browser version).
|
|
3
|
+
*
|
|
4
|
+
* Returns safe defaults for browser environments.
|
|
5
|
+
* The isEntryAvailable matcher works identically to the Node version.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
export interface RuntimeContext {
|
|
9
|
+
platform: string;
|
|
10
|
+
runtime: string;
|
|
11
|
+
deployment: string;
|
|
12
|
+
env: string;
|
|
13
|
+
}
|
|
14
|
+
export interface EntryAvailability {
|
|
15
|
+
platform?: string[];
|
|
16
|
+
runtime?: string[];
|
|
17
|
+
deployment?: string[];
|
|
18
|
+
env?: string[];
|
|
19
|
+
}
|
|
20
|
+
export declare const entryAvailabilitySchema: z.ZodObject<{
|
|
21
|
+
platform: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
22
|
+
runtime: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
23
|
+
deployment: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
24
|
+
env: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
25
|
+
}, z.core.$strict>;
|
|
26
|
+
export declare function isEntryAvailable(availability: EntryAvailability | undefined, ctx: RuntimeContext): boolean;
|
|
27
|
+
export declare function detectRuntimeContext(): RuntimeContext;
|
|
28
|
+
export declare function getRuntimeContext(): RuntimeContext;
|
|
29
|
+
export declare function resetRuntimeContext(): void;
|
package/env/index.d.ts
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
1
|
export { getEnv, getCwd, isProduction, isDevelopment, getEnvFlag, isDebug, setEnv, isEdgeRuntime, isServerless, supportsAnsi, } from '#env';
|
|
2
|
+
export { getRuntimeContext, resetRuntimeContext, detectRuntimeContext, isEntryAvailable, entryAvailabilitySchema, } from '#runtime-context';
|
|
3
|
+
export type { RuntimeContext, EntryAvailability } from '#runtime-context';
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime context detection and entry availability matching (Node.js version).
|
|
3
|
+
*
|
|
4
|
+
* Provides:
|
|
5
|
+
* - `RuntimeContext` — snapshot of the current platform, runtime, deployment, and env
|
|
6
|
+
* - `EntryAvailability` — declarative constraint for when an entry is available
|
|
7
|
+
* - `getRuntimeContext()` — lazy singleton returning the detected context
|
|
8
|
+
* - `isEntryAvailable()` — pure matcher: does the constraint match the context?
|
|
9
|
+
*/
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
/**
|
|
12
|
+
* Snapshot of the current runtime environment.
|
|
13
|
+
* Detected once and cached for the lifetime of the process.
|
|
14
|
+
*/
|
|
15
|
+
export interface RuntimeContext {
|
|
16
|
+
/** OS platform: 'darwin', 'linux', 'win32', 'freebsd', etc. */
|
|
17
|
+
platform: string;
|
|
18
|
+
/** JavaScript runtime: 'node', 'bun', 'deno', 'edge', 'browser' */
|
|
19
|
+
runtime: string;
|
|
20
|
+
/** Deployment mode: 'serverless' or 'standalone' */
|
|
21
|
+
deployment: string;
|
|
22
|
+
/** NODE_ENV value: 'production', 'development', 'test', etc. */
|
|
23
|
+
env: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Declarative constraint for entry availability.
|
|
27
|
+
*
|
|
28
|
+
* Semantics:
|
|
29
|
+
* - AND across fields: all specified fields must match
|
|
30
|
+
* - OR within arrays: at least one value in the array must match
|
|
31
|
+
* - Omitted field: unconstrained (matches any value)
|
|
32
|
+
* - Empty array: matches nothing (entry is never available)
|
|
33
|
+
* - undefined/empty object: always available
|
|
34
|
+
*
|
|
35
|
+
* @example macOS only
|
|
36
|
+
* ```typescript
|
|
37
|
+
* { platform: ['darwin'] }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example Node.js or Bun, production only
|
|
41
|
+
* ```typescript
|
|
42
|
+
* { runtime: ['node', 'bun'], env: ['production'] }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export interface EntryAvailability {
|
|
46
|
+
/** OS platform constraint: 'darwin', 'linux', 'win32', etc. */
|
|
47
|
+
platform?: string[];
|
|
48
|
+
/** Runtime constraint: 'node', 'browser', 'edge', 'bun', 'deno' */
|
|
49
|
+
runtime?: string[];
|
|
50
|
+
/** Deployment constraint: 'serverless', 'standalone' */
|
|
51
|
+
deployment?: string[];
|
|
52
|
+
/** Environment constraint: 'production', 'development', 'test', etc. */
|
|
53
|
+
env?: string[];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Zod schema for validating EntryAvailability in metadata.
|
|
57
|
+
*/
|
|
58
|
+
export declare const entryAvailabilitySchema: z.ZodObject<{
|
|
59
|
+
platform: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
60
|
+
runtime: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
61
|
+
deployment: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
62
|
+
env: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
63
|
+
}, z.core.$strict>;
|
|
64
|
+
/**
|
|
65
|
+
* Check if an entry is available in the given runtime context.
|
|
66
|
+
*
|
|
67
|
+
* @param availability - The constraint (undefined = always available)
|
|
68
|
+
* @param ctx - The current runtime context
|
|
69
|
+
* @returns true if the entry should be available
|
|
70
|
+
*/
|
|
71
|
+
export declare function isEntryAvailable(availability: EntryAvailability | undefined, ctx: RuntimeContext): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Detect the current runtime context from the environment.
|
|
74
|
+
*/
|
|
75
|
+
export declare function detectRuntimeContext(): RuntimeContext;
|
|
76
|
+
/**
|
|
77
|
+
* Get the current runtime context (lazy singleton).
|
|
78
|
+
* The context is detected on first call and cached for the process lifetime.
|
|
79
|
+
*/
|
|
80
|
+
export declare function getRuntimeContext(): RuntimeContext;
|
|
81
|
+
/**
|
|
82
|
+
* Reset the cached runtime context. For testing only.
|
|
83
|
+
*/
|
|
84
|
+
export declare function resetRuntimeContext(): void;
|
package/esm/index.mjs
CHANGED
|
@@ -554,9 +554,9 @@ function createSecretData(options) {
|
|
|
554
554
|
}
|
|
555
555
|
async function getOrCreateSecret(options) {
|
|
556
556
|
const cacheKey = resolveSecretPath(options);
|
|
557
|
-
const
|
|
558
|
-
if (
|
|
559
|
-
return
|
|
557
|
+
const cached2 = secretCache.get(cacheKey);
|
|
558
|
+
if (cached2) {
|
|
559
|
+
return cached2;
|
|
560
560
|
}
|
|
561
561
|
const existing = generationPromises.get(cacheKey);
|
|
562
562
|
if (existing) {
|
|
@@ -793,8 +793,8 @@ var init_key_persistence = __esm({
|
|
|
793
793
|
*/
|
|
794
794
|
async get(kid) {
|
|
795
795
|
if (this.enableCache) {
|
|
796
|
-
const
|
|
797
|
-
if (
|
|
796
|
+
const cached2 = this.cache.get(kid);
|
|
797
|
+
if (cached2) return cached2;
|
|
798
798
|
}
|
|
799
799
|
const raw = await this.storage.get(kid);
|
|
800
800
|
if (!raw) return null;
|
|
@@ -4277,11 +4277,56 @@ import {
|
|
|
4277
4277
|
getEnvFlag,
|
|
4278
4278
|
isDebug,
|
|
4279
4279
|
setEnv,
|
|
4280
|
-
isEdgeRuntime,
|
|
4281
|
-
isServerless,
|
|
4280
|
+
isEdgeRuntime as isEdgeRuntime2,
|
|
4281
|
+
isServerless as isServerless2,
|
|
4282
4282
|
supportsAnsi
|
|
4283
4283
|
} from "#env";
|
|
4284
4284
|
|
|
4285
|
+
// libs/utils/src/env/runtime-context.ts
|
|
4286
|
+
import { z as z3 } from "zod";
|
|
4287
|
+
import { isEdgeRuntime, isServerless } from "#env";
|
|
4288
|
+
var entryAvailabilitySchema = z3.object({
|
|
4289
|
+
platform: z3.array(z3.string().min(1)).optional(),
|
|
4290
|
+
runtime: z3.array(z3.string().min(1)).optional(),
|
|
4291
|
+
deployment: z3.array(z3.string().min(1)).optional(),
|
|
4292
|
+
env: z3.array(z3.string().min(1)).optional()
|
|
4293
|
+
}).strict();
|
|
4294
|
+
function isEntryAvailable(availability, ctx) {
|
|
4295
|
+
if (!availability) return true;
|
|
4296
|
+
const fields = ["platform", "runtime", "deployment", "env"];
|
|
4297
|
+
for (const field of fields) {
|
|
4298
|
+
const allowed = availability[field];
|
|
4299
|
+
if (allowed === void 0) continue;
|
|
4300
|
+
if (allowed.length === 0) return false;
|
|
4301
|
+
if (!allowed.includes(ctx[field])) return false;
|
|
4302
|
+
}
|
|
4303
|
+
return true;
|
|
4304
|
+
}
|
|
4305
|
+
function detectRuntime() {
|
|
4306
|
+
if (typeof globalThis !== "undefined" && "Bun" in globalThis) return "bun";
|
|
4307
|
+
if (typeof globalThis !== "undefined" && "Deno" in globalThis) return "deno";
|
|
4308
|
+
if (isEdgeRuntime()) return "edge";
|
|
4309
|
+
return "node";
|
|
4310
|
+
}
|
|
4311
|
+
function detectRuntimeContext() {
|
|
4312
|
+
return {
|
|
4313
|
+
platform: process.platform,
|
|
4314
|
+
runtime: detectRuntime(),
|
|
4315
|
+
deployment: isServerless() ? "serverless" : "standalone",
|
|
4316
|
+
env: process.env["NODE_ENV"] || "development"
|
|
4317
|
+
};
|
|
4318
|
+
}
|
|
4319
|
+
var cached;
|
|
4320
|
+
function getRuntimeContext() {
|
|
4321
|
+
if (!cached) {
|
|
4322
|
+
cached = detectRuntimeContext();
|
|
4323
|
+
}
|
|
4324
|
+
return cached;
|
|
4325
|
+
}
|
|
4326
|
+
function resetRuntimeContext() {
|
|
4327
|
+
cached = void 0;
|
|
4328
|
+
}
|
|
4329
|
+
|
|
4285
4330
|
// libs/utils/src/storage/factory.ts
|
|
4286
4331
|
init_errors();
|
|
4287
4332
|
|
|
@@ -5156,12 +5201,14 @@ export {
|
|
|
5156
5201
|
deleteSecret,
|
|
5157
5202
|
deserializeAndDecrypt,
|
|
5158
5203
|
deserializeBlob,
|
|
5204
|
+
detectRuntimeContext,
|
|
5159
5205
|
dirname,
|
|
5160
5206
|
encryptAesGcm,
|
|
5161
5207
|
encryptAndSerialize,
|
|
5162
5208
|
encryptValue,
|
|
5163
5209
|
ensureDir,
|
|
5164
5210
|
ensureMaxLen,
|
|
5211
|
+
entryAvailabilitySchema,
|
|
5165
5212
|
escapeGlob,
|
|
5166
5213
|
escapeHtml,
|
|
5167
5214
|
escapeHtmlAttr,
|
|
@@ -5185,6 +5232,7 @@ export {
|
|
|
5185
5232
|
getEnv2 as getEnv,
|
|
5186
5233
|
getEnvFlag,
|
|
5187
5234
|
getOrCreateSecret,
|
|
5235
|
+
getRuntimeContext,
|
|
5188
5236
|
globToRegex,
|
|
5189
5237
|
hasTemplatePlaceholders,
|
|
5190
5238
|
hkdfSha256,
|
|
@@ -5196,7 +5244,8 @@ export {
|
|
|
5196
5244
|
isDebug,
|
|
5197
5245
|
isDevelopment,
|
|
5198
5246
|
isDirEmpty,
|
|
5199
|
-
isEdgeRuntime,
|
|
5247
|
+
isEdgeRuntime2 as isEdgeRuntime,
|
|
5248
|
+
isEntryAvailable,
|
|
5200
5249
|
isExpired,
|
|
5201
5250
|
isInputLengthSafe,
|
|
5202
5251
|
isNode,
|
|
@@ -5206,7 +5255,7 @@ export {
|
|
|
5206
5255
|
isSecretCached,
|
|
5207
5256
|
isSecretKeyData,
|
|
5208
5257
|
isSecretPersistenceEnabled,
|
|
5209
|
-
isServerless,
|
|
5258
|
+
isServerless2 as isServerless,
|
|
5210
5259
|
isSignedData,
|
|
5211
5260
|
isUriTemplate,
|
|
5212
5261
|
isValidCodeChallenge,
|
|
@@ -5236,6 +5285,7 @@ export {
|
|
|
5236
5285
|
readJSON,
|
|
5237
5286
|
readdir,
|
|
5238
5287
|
rename,
|
|
5288
|
+
resetRuntimeContext,
|
|
5239
5289
|
resolveSecretPath,
|
|
5240
5290
|
rm,
|
|
5241
5291
|
rsaVerify2 as rsaVerify,
|
package/index.d.ts
CHANGED
|
@@ -19,7 +19,8 @@ export { getCrypto, rsaVerify, jwtAlgToNodeAlg, isRsaPssAlg, randomUUID, randomB
|
|
|
19
19
|
export type { CryptoProvider, EncBlob, EncryptedBlob } from './crypto';
|
|
20
20
|
export { AsyncLocalStorage } from './async-context';
|
|
21
21
|
export { EventEmitter } from './event-emitter';
|
|
22
|
-
export { getEnv, getCwd, isProduction, isDevelopment, getEnvFlag, isDebug, setEnv, isEdgeRuntime, isServerless, supportsAnsi, } from './env';
|
|
22
|
+
export { getEnv, getCwd, isProduction, isDevelopment, getEnvFlag, isDebug, setEnv, isEdgeRuntime, isServerless, supportsAnsi, getRuntimeContext, resetRuntimeContext, detectRuntimeContext, isEntryAvailable, entryAvailabilitySchema, } from './env';
|
|
23
|
+
export type { RuntimeContext, EntryAvailability } from './env';
|
|
23
24
|
export { analyzePattern, isPatternSafe, createSafeRegExp, safeTest, safeMatch, safeReplace, safeExec, isInputLengthSafe, DEFAULT_MAX_INPUT_LENGTH, REDOS_THRESHOLDS, trimLeading, trimTrailing, trimBoth, trimChars, extractBracedParams, expandTemplate, hasTemplatePlaceholders, collapseChar, collapseWhitespace, type SafeRegexOptions, type PatternAnalysisResult, } from './regex';
|
|
24
25
|
export { createStorage, createMemoryStorage, getDetectedStorageType, NamespacedStorageImpl, createRootStorage, createNamespacedStorage, buildPrefix, NAMESPACE_SEPARATOR, StorageError, StorageConnectionError, StorageOperationError, StorageNotSupportedError, StorageConfigError, StorageTTLError, StoragePatternError, StorageNotConnectedError, EncryptedStorageError, BaseStorageAdapter, MemoryStorageAdapter, RedisStorageAdapter, VercelKvStorageAdapter, UpstashStorageAdapter, FileSystemStorageAdapter, type FileSystemAdapterOptions, TypedStorage, type TypedStorageOptions, type TypedSetOptions, type TypedSetEntry, EncryptedTypedStorage, type EncryptedTypedStorageOptions, type EncryptedSetOptions, type EncryptedSetEntry, type EncryptionKey, type StoredEncryptedBlob, type ClientKeyBinding, globToRegex, matchesPattern, validatePattern, escapeGlob, MAX_TTL_SECONDS, validateTTL, validateOptionalTTL, ttlToExpiresAt, expiresAtToTTL, isExpired, normalizeTTL, } from './storage';
|
|
25
26
|
export type { StorageAdapter, NamespacedStorage, RootStorage, SetOptions, SetEntry, MessageHandler, Unsubscribe, MemoryAdapterOptions, RedisAdapterOptions, VercelKvAdapterOptions, UpstashAdapterOptions, StorageType, StorageConfig, } from './storage';
|
package/index.js
CHANGED
|
@@ -558,9 +558,9 @@ function createSecretData(options) {
|
|
|
558
558
|
}
|
|
559
559
|
async function getOrCreateSecret(options) {
|
|
560
560
|
const cacheKey = resolveSecretPath(options);
|
|
561
|
-
const
|
|
562
|
-
if (
|
|
563
|
-
return
|
|
561
|
+
const cached2 = secretCache.get(cacheKey);
|
|
562
|
+
if (cached2) {
|
|
563
|
+
return cached2;
|
|
564
564
|
}
|
|
565
565
|
const existing = generationPromises.get(cacheKey);
|
|
566
566
|
if (existing) {
|
|
@@ -798,8 +798,8 @@ var init_key_persistence = __esm({
|
|
|
798
798
|
*/
|
|
799
799
|
async get(kid) {
|
|
800
800
|
if (this.enableCache) {
|
|
801
|
-
const
|
|
802
|
-
if (
|
|
801
|
+
const cached2 = this.cache.get(kid);
|
|
802
|
+
if (cached2) return cached2;
|
|
803
803
|
}
|
|
804
804
|
const raw = await this.storage.get(kid);
|
|
805
805
|
if (!raw) return null;
|
|
@@ -3783,12 +3783,14 @@ __export(index_exports, {
|
|
|
3783
3783
|
deleteSecret: () => deleteSecret,
|
|
3784
3784
|
deserializeAndDecrypt: () => deserializeAndDecrypt,
|
|
3785
3785
|
deserializeBlob: () => deserializeBlob,
|
|
3786
|
+
detectRuntimeContext: () => detectRuntimeContext,
|
|
3786
3787
|
dirname: () => import_path.dirname,
|
|
3787
3788
|
encryptAesGcm: () => encryptAesGcm,
|
|
3788
3789
|
encryptAndSerialize: () => encryptAndSerialize,
|
|
3789
3790
|
encryptValue: () => encryptValue,
|
|
3790
3791
|
ensureDir: () => ensureDir,
|
|
3791
3792
|
ensureMaxLen: () => ensureMaxLen,
|
|
3793
|
+
entryAvailabilitySchema: () => entryAvailabilitySchema,
|
|
3792
3794
|
escapeGlob: () => escapeGlob,
|
|
3793
3795
|
escapeHtml: () => escapeHtml,
|
|
3794
3796
|
escapeHtmlAttr: () => escapeHtmlAttr,
|
|
@@ -3807,11 +3809,12 @@ __export(index_exports, {
|
|
|
3807
3809
|
generatePkcePair: () => generatePkcePair,
|
|
3808
3810
|
generateSecret: () => generateSecret,
|
|
3809
3811
|
getCrypto: () => getCrypto,
|
|
3810
|
-
getCwd: () =>
|
|
3812
|
+
getCwd: () => import_env3.getCwd,
|
|
3811
3813
|
getDetectedStorageType: () => getDetectedStorageType,
|
|
3812
|
-
getEnv: () =>
|
|
3813
|
-
getEnvFlag: () =>
|
|
3814
|
+
getEnv: () => import_env3.getEnv,
|
|
3815
|
+
getEnvFlag: () => import_env3.getEnvFlag,
|
|
3814
3816
|
getOrCreateSecret: () => getOrCreateSecret,
|
|
3817
|
+
getRuntimeContext: () => getRuntimeContext,
|
|
3815
3818
|
globToRegex: () => globToRegex,
|
|
3816
3819
|
hasTemplatePlaceholders: () => hasTemplatePlaceholders,
|
|
3817
3820
|
hkdfSha256: () => hkdfSha256,
|
|
@@ -3820,20 +3823,21 @@ __export(index_exports, {
|
|
|
3820
3823
|
inferMimeType: () => inferMimeType,
|
|
3821
3824
|
isAsymmetricKeyData: () => isAsymmetricKeyData,
|
|
3822
3825
|
isBrowser: () => isBrowser,
|
|
3823
|
-
isDebug: () =>
|
|
3824
|
-
isDevelopment: () =>
|
|
3826
|
+
isDebug: () => import_env3.isDebug,
|
|
3827
|
+
isDevelopment: () => import_env3.isDevelopment,
|
|
3825
3828
|
isDirEmpty: () => isDirEmpty,
|
|
3826
|
-
isEdgeRuntime: () =>
|
|
3829
|
+
isEdgeRuntime: () => import_env3.isEdgeRuntime,
|
|
3830
|
+
isEntryAvailable: () => isEntryAvailable,
|
|
3827
3831
|
isExpired: () => isExpired,
|
|
3828
3832
|
isInputLengthSafe: () => isInputLengthSafe,
|
|
3829
3833
|
isNode: () => isNode,
|
|
3830
3834
|
isPatternSafe: () => isPatternSafe,
|
|
3831
|
-
isProduction: () =>
|
|
3835
|
+
isProduction: () => import_env3.isProduction,
|
|
3832
3836
|
isRsaPssAlg: () => isRsaPssAlg,
|
|
3833
3837
|
isSecretCached: () => isSecretCached,
|
|
3834
3838
|
isSecretKeyData: () => isSecretKeyData,
|
|
3835
3839
|
isSecretPersistenceEnabled: () => isSecretPersistenceEnabled,
|
|
3836
|
-
isServerless: () =>
|
|
3840
|
+
isServerless: () => import_env3.isServerless,
|
|
3837
3841
|
isSignedData: () => isSignedData,
|
|
3838
3842
|
isUriTemplate: () => isUriTemplate,
|
|
3839
3843
|
isValidCodeChallenge: () => isValidCodeChallenge,
|
|
@@ -3863,6 +3867,7 @@ __export(index_exports, {
|
|
|
3863
3867
|
readJSON: () => readJSON,
|
|
3864
3868
|
readdir: () => readdir,
|
|
3865
3869
|
rename: () => rename,
|
|
3870
|
+
resetRuntimeContext: () => resetRuntimeContext,
|
|
3866
3871
|
resolveSecretPath: () => resolveSecretPath,
|
|
3867
3872
|
rm: () => rm,
|
|
3868
3873
|
rsaVerify: () => rsaVerify2,
|
|
@@ -3879,7 +3884,7 @@ __export(index_exports, {
|
|
|
3879
3884
|
secretKeyDataSchema: () => secretKeyDataSchema,
|
|
3880
3885
|
sepFor: () => sepFor,
|
|
3881
3886
|
serializeBlob: () => serializeBlob,
|
|
3882
|
-
setEnv: () =>
|
|
3887
|
+
setEnv: () => import_env3.setEnv,
|
|
3883
3888
|
sha256: () => sha256,
|
|
3884
3889
|
sha256Base64url: () => sha256Base64url,
|
|
3885
3890
|
sha256Hex: () => sha256Hex,
|
|
@@ -3887,7 +3892,7 @@ __export(index_exports, {
|
|
|
3887
3892
|
signData: () => signData,
|
|
3888
3893
|
splitWords: () => splitWords,
|
|
3889
3894
|
stat: () => stat,
|
|
3890
|
-
supportsAnsi: () =>
|
|
3895
|
+
supportsAnsi: () => import_env3.supportsAnsi,
|
|
3891
3896
|
timingSafeEqual: () => timingSafeEqual,
|
|
3892
3897
|
toCase: () => toCase,
|
|
3893
3898
|
trimBoth: () => trimBoth,
|
|
@@ -4469,7 +4474,52 @@ var import_async_context = require("#async-context");
|
|
|
4469
4474
|
var import_event_emitter2 = require("#event-emitter");
|
|
4470
4475
|
|
|
4471
4476
|
// libs/utils/src/env/index.ts
|
|
4477
|
+
var import_env3 = require("#env");
|
|
4478
|
+
|
|
4479
|
+
// libs/utils/src/env/runtime-context.ts
|
|
4480
|
+
var import_zod3 = require("zod");
|
|
4472
4481
|
var import_env2 = require("#env");
|
|
4482
|
+
var entryAvailabilitySchema = import_zod3.z.object({
|
|
4483
|
+
platform: import_zod3.z.array(import_zod3.z.string().min(1)).optional(),
|
|
4484
|
+
runtime: import_zod3.z.array(import_zod3.z.string().min(1)).optional(),
|
|
4485
|
+
deployment: import_zod3.z.array(import_zod3.z.string().min(1)).optional(),
|
|
4486
|
+
env: import_zod3.z.array(import_zod3.z.string().min(1)).optional()
|
|
4487
|
+
}).strict();
|
|
4488
|
+
function isEntryAvailable(availability, ctx) {
|
|
4489
|
+
if (!availability) return true;
|
|
4490
|
+
const fields = ["platform", "runtime", "deployment", "env"];
|
|
4491
|
+
for (const field of fields) {
|
|
4492
|
+
const allowed = availability[field];
|
|
4493
|
+
if (allowed === void 0) continue;
|
|
4494
|
+
if (allowed.length === 0) return false;
|
|
4495
|
+
if (!allowed.includes(ctx[field])) return false;
|
|
4496
|
+
}
|
|
4497
|
+
return true;
|
|
4498
|
+
}
|
|
4499
|
+
function detectRuntime() {
|
|
4500
|
+
if (typeof globalThis !== "undefined" && "Bun" in globalThis) return "bun";
|
|
4501
|
+
if (typeof globalThis !== "undefined" && "Deno" in globalThis) return "deno";
|
|
4502
|
+
if ((0, import_env2.isEdgeRuntime)()) return "edge";
|
|
4503
|
+
return "node";
|
|
4504
|
+
}
|
|
4505
|
+
function detectRuntimeContext() {
|
|
4506
|
+
return {
|
|
4507
|
+
platform: process.platform,
|
|
4508
|
+
runtime: detectRuntime(),
|
|
4509
|
+
deployment: (0, import_env2.isServerless)() ? "serverless" : "standalone",
|
|
4510
|
+
env: process.env["NODE_ENV"] || "development"
|
|
4511
|
+
};
|
|
4512
|
+
}
|
|
4513
|
+
var cached;
|
|
4514
|
+
function getRuntimeContext() {
|
|
4515
|
+
if (!cached) {
|
|
4516
|
+
cached = detectRuntimeContext();
|
|
4517
|
+
}
|
|
4518
|
+
return cached;
|
|
4519
|
+
}
|
|
4520
|
+
function resetRuntimeContext() {
|
|
4521
|
+
cached = void 0;
|
|
4522
|
+
}
|
|
4473
4523
|
|
|
4474
4524
|
// libs/utils/src/storage/factory.ts
|
|
4475
4525
|
init_errors();
|
|
@@ -4631,15 +4681,15 @@ function createNamespacedStorage(adapter, prefix) {
|
|
|
4631
4681
|
|
|
4632
4682
|
// libs/utils/src/storage/factory.ts
|
|
4633
4683
|
init_memory();
|
|
4634
|
-
var
|
|
4684
|
+
var import_env4 = require("#env");
|
|
4635
4685
|
function detectStorageType() {
|
|
4636
|
-
if ((0,
|
|
4686
|
+
if ((0, import_env4.getEnv)("UPSTASH_REDIS_REST_URL") && (0, import_env4.getEnv)("UPSTASH_REDIS_REST_TOKEN")) {
|
|
4637
4687
|
return "upstash";
|
|
4638
4688
|
}
|
|
4639
|
-
if ((0,
|
|
4689
|
+
if ((0, import_env4.getEnv)("KV_REST_API_URL") && (0, import_env4.getEnv)("KV_REST_API_TOKEN")) {
|
|
4640
4690
|
return "vercel-kv";
|
|
4641
4691
|
}
|
|
4642
|
-
if ((0,
|
|
4692
|
+
if ((0, import_env4.getEnv)("REDIS_URL") || (0, import_env4.getEnv)("REDIS_HOST")) {
|
|
4643
4693
|
return "redis";
|
|
4644
4694
|
}
|
|
4645
4695
|
return "memory";
|
|
@@ -4669,10 +4719,10 @@ async function createAdapter(type, config) {
|
|
|
4669
4719
|
}
|
|
4670
4720
|
async function createStorage(config = {}) {
|
|
4671
4721
|
let type = config.type ?? "auto";
|
|
4672
|
-
const fallback = config.fallback ?? ((0,
|
|
4722
|
+
const fallback = config.fallback ?? ((0, import_env4.isProduction)() ? "error" : "memory");
|
|
4673
4723
|
if (type === "auto") {
|
|
4674
4724
|
type = detectStorageType();
|
|
4675
|
-
if (type === "memory" && (0,
|
|
4725
|
+
if (type === "memory" && (0, import_env4.isProduction)()) {
|
|
4676
4726
|
console.warn(
|
|
4677
4727
|
"[storage] Warning: No distributed storage backend detected in production. Using in-memory storage. Set REDIS_URL, UPSTASH_REDIS_REST_URL, or KV_REST_API_URL."
|
|
4678
4728
|
);
|
|
@@ -5346,12 +5396,14 @@ async function processVercel(info, callTool) {
|
|
|
5346
5396
|
deleteSecret,
|
|
5347
5397
|
deserializeAndDecrypt,
|
|
5348
5398
|
deserializeBlob,
|
|
5399
|
+
detectRuntimeContext,
|
|
5349
5400
|
dirname,
|
|
5350
5401
|
encryptAesGcm,
|
|
5351
5402
|
encryptAndSerialize,
|
|
5352
5403
|
encryptValue,
|
|
5353
5404
|
ensureDir,
|
|
5354
5405
|
ensureMaxLen,
|
|
5406
|
+
entryAvailabilitySchema,
|
|
5355
5407
|
escapeGlob,
|
|
5356
5408
|
escapeHtml,
|
|
5357
5409
|
escapeHtmlAttr,
|
|
@@ -5375,6 +5427,7 @@ async function processVercel(info, callTool) {
|
|
|
5375
5427
|
getEnv,
|
|
5376
5428
|
getEnvFlag,
|
|
5377
5429
|
getOrCreateSecret,
|
|
5430
|
+
getRuntimeContext,
|
|
5378
5431
|
globToRegex,
|
|
5379
5432
|
hasTemplatePlaceholders,
|
|
5380
5433
|
hkdfSha256,
|
|
@@ -5387,6 +5440,7 @@ async function processVercel(info, callTool) {
|
|
|
5387
5440
|
isDevelopment,
|
|
5388
5441
|
isDirEmpty,
|
|
5389
5442
|
isEdgeRuntime,
|
|
5443
|
+
isEntryAvailable,
|
|
5390
5444
|
isExpired,
|
|
5391
5445
|
isInputLengthSafe,
|
|
5392
5446
|
isNode,
|
|
@@ -5426,6 +5480,7 @@ async function processVercel(info, callTool) {
|
|
|
5426
5480
|
readJSON,
|
|
5427
5481
|
readdir,
|
|
5428
5482
|
rename,
|
|
5483
|
+
resetRuntimeContext,
|
|
5429
5484
|
resolveSecretPath,
|
|
5430
5485
|
rm,
|
|
5431
5486
|
rsaVerify,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontmcp/utils",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-rc.1",
|
|
4
4
|
"description": "Shared utility functions for FrontMCP - string manipulation, URI handling, path utilities, and more",
|
|
5
5
|
"author": "AgentFront <info@agentfront.dev>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"homepage": "https://github.com/agentfront/frontmcp/blob/main/libs/utils/README.md",
|
|
26
26
|
"engines": {
|
|
27
|
-
"node": ">=
|
|
27
|
+
"node": ">=24.0.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@noble/hashes": "^2.0.1",
|
|
@@ -61,6 +61,10 @@
|
|
|
61
61
|
"browser": "./env/browser-env.js",
|
|
62
62
|
"default": "./env/node-env.js"
|
|
63
63
|
},
|
|
64
|
+
"#runtime-context": {
|
|
65
|
+
"browser": "./env/browser-runtime-context.js",
|
|
66
|
+
"default": "./env/runtime-context.js"
|
|
67
|
+
},
|
|
64
68
|
"#path": {
|
|
65
69
|
"browser": "./path/browser-path.js",
|
|
66
70
|
"default": "./path/node-path.js"
|