@frontmcp/utils 0.0.1 → 0.7.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +110 -0
  3. package/content/content.d.ts +43 -0
  4. package/content/index.d.ts +1 -0
  5. package/crypto/browser.d.ts +11 -0
  6. package/crypto/encrypted-blob.d.ts +157 -0
  7. package/crypto/index.d.ts +98 -0
  8. package/crypto/jwt-alg.d.ts +8 -0
  9. package/crypto/node.d.ts +59 -0
  10. package/crypto/pkce/index.d.ts +9 -0
  11. package/crypto/pkce/pkce.d.ts +140 -0
  12. package/crypto/runtime.d.ts +18 -0
  13. package/crypto/secret-persistence/index.d.ts +25 -0
  14. package/crypto/secret-persistence/persistence.d.ts +97 -0
  15. package/crypto/secret-persistence/schema.d.ts +34 -0
  16. package/crypto/secret-persistence/types.d.ts +65 -0
  17. package/crypto/types.d.ts +61 -0
  18. package/escape/escape.d.ts +101 -0
  19. package/escape/index.d.ts +1 -0
  20. package/esm/index.mjs +3264 -0
  21. package/esm/package.json +53 -0
  22. package/fs/fs.d.ts +254 -0
  23. package/fs/index.d.ts +1 -0
  24. package/http/http.d.ts +20 -0
  25. package/http/index.d.ts +1 -0
  26. package/index.d.ts +18 -0
  27. package/index.js +3425 -0
  28. package/naming/index.d.ts +1 -0
  29. package/naming/naming.d.ts +79 -0
  30. package/package.json +3 -2
  31. package/path/index.d.ts +1 -0
  32. package/path/path.d.ts +34 -0
  33. package/regex/index.d.ts +24 -0
  34. package/regex/patterns.d.ts +155 -0
  35. package/regex/safe-regex.d.ts +179 -0
  36. package/serialization/index.d.ts +1 -0
  37. package/serialization/serialization.d.ts +33 -0
  38. package/storage/adapters/base.d.ts +90 -0
  39. package/storage/adapters/index.d.ts +10 -0
  40. package/storage/adapters/memory.d.ts +99 -0
  41. package/storage/adapters/redis.d.ts +88 -0
  42. package/storage/adapters/upstash.d.ts +81 -0
  43. package/storage/adapters/vercel-kv.d.ts +69 -0
  44. package/storage/errors.d.ts +117 -0
  45. package/storage/factory.d.ts +70 -0
  46. package/storage/index.d.ts +13 -0
  47. package/storage/namespace.d.ts +88 -0
  48. package/storage/types.d.ts +428 -0
  49. package/storage/utils/index.d.ts +5 -0
  50. package/storage/utils/pattern.d.ts +71 -0
  51. package/storage/utils/ttl.d.ts +54 -0
  52. package/uri/index.d.ts +2 -0
  53. package/uri/uri-template.d.ts +92 -0
  54. package/uri/uri-validation.d.ts +46 -0
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@frontmcp/utils",
3
+ "version": "0.7.1",
4
+ "description": "Shared utility functions for FrontMCP - string manipulation, URI handling, path utilities, and more",
5
+ "author": "AgentFront <info@agentfront.dev>",
6
+ "license": "Apache-2.0",
7
+ "keywords": [
8
+ "utils",
9
+ "utilities",
10
+ "uri",
11
+ "url",
12
+ "string",
13
+ "path",
14
+ "typescript",
15
+ "mcp"
16
+ ],
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/agentfront/frontmcp.git",
20
+ "directory": "libs/utils"
21
+ },
22
+ "bugs": {
23
+ "url": "https://github.com/agentfront/frontmcp/issues"
24
+ },
25
+ "homepage": "https://github.com/agentfront/frontmcp/blob/main/libs/utils/README.md",
26
+ "dependencies": {
27
+ "@noble/hashes": "^2.0.1",
28
+ "@noble/ciphers": "^2.1.1",
29
+ "ast-guard": "^2.4.0"
30
+ },
31
+ "type": "module",
32
+ "main": "../index.js",
33
+ "module": "./index.mjs",
34
+ "types": "../index.d.ts",
35
+ "sideEffects": false,
36
+ "exports": {
37
+ "./package.json": "../package.json",
38
+ ".": {
39
+ "require": {
40
+ "types": "../index.d.ts",
41
+ "default": "../index.js"
42
+ },
43
+ "import": {
44
+ "types": "../index.d.ts",
45
+ "default": "./index.mjs"
46
+ }
47
+ }
48
+ },
49
+ "devDependencies": {
50
+ "@types/node": "^24.0.0",
51
+ "typescript": "^5.0.0"
52
+ }
53
+ }
package/fs/fs.d.ts ADDED
@@ -0,0 +1,254 @@
1
+ /**
2
+ * File system utilities for common async operations.
3
+ *
4
+ * Provides Promise-based wrappers for file system operations.
5
+ *
6
+ * **Note:** These functions are Node.js only and will throw an error
7
+ * if called in a browser environment.
8
+ */
9
+ /**
10
+ * Read a file's contents as a string.
11
+ *
12
+ * **Node.js only** - throws an error if called in browser.
13
+ *
14
+ * @param p - Path to file
15
+ * @param encoding - Encoding (default 'utf8')
16
+ * @returns File contents as string
17
+ *
18
+ * @example
19
+ * const content = await readFile('/path/to/file.txt');
20
+ */
21
+ export declare function readFile(p: string, encoding?: BufferEncoding): Promise<string>;
22
+ /**
23
+ * Read a file's contents as a Buffer.
24
+ *
25
+ * **Node.js only** - throws an error if called in browser.
26
+ *
27
+ * @param p - Path to file
28
+ * @returns File contents as Buffer
29
+ *
30
+ * @example
31
+ * const buffer = await readFileBuffer('/path/to/file.bin');
32
+ */
33
+ export declare function readFileBuffer(p: string): Promise<Buffer>;
34
+ /**
35
+ * Write content to a file.
36
+ *
37
+ * **Node.js only** - throws an error if called in browser.
38
+ *
39
+ * @param p - Path to write to
40
+ * @param content - Content to write
41
+ * @param options - Optional mode (permissions)
42
+ *
43
+ * @example
44
+ * await writeFile('/path/to/file.txt', 'hello', { mode: 0o600 });
45
+ */
46
+ export declare function writeFile(p: string, content: string, options?: {
47
+ mode?: number;
48
+ }): Promise<void>;
49
+ /**
50
+ * Create a directory with optional mode (permissions).
51
+ *
52
+ * **Node.js only** - throws an error if called in browser.
53
+ *
54
+ * @param p - Path to directory
55
+ * @param options - Optional recursive and mode settings
56
+ *
57
+ * @example
58
+ * await mkdir('/path/to/dir', { recursive: true, mode: 0o700 });
59
+ */
60
+ export declare function mkdir(p: string, options?: {
61
+ recursive?: boolean;
62
+ mode?: number;
63
+ }): Promise<void>;
64
+ /**
65
+ * Rename/move a file or directory.
66
+ *
67
+ * **Node.js only** - throws an error if called in browser.
68
+ *
69
+ * @param oldPath - Current path
70
+ * @param newPath - New path
71
+ *
72
+ * @example
73
+ * await rename('/path/to/old.txt', '/path/to/new.txt');
74
+ */
75
+ export declare function rename(oldPath: string, newPath: string): Promise<void>;
76
+ /**
77
+ * Delete a file.
78
+ *
79
+ * **Node.js only** - throws an error if called in browser.
80
+ *
81
+ * @param p - Path to file to delete
82
+ *
83
+ * @example
84
+ * await unlink('/path/to/file.txt');
85
+ */
86
+ export declare function unlink(p: string): Promise<void>;
87
+ /**
88
+ * Check if a file exists asynchronously.
89
+ *
90
+ * **Node.js only** - throws an error if called in browser.
91
+ *
92
+ * @param p - Path to check
93
+ * @returns true if file exists, false otherwise
94
+ *
95
+ * @example
96
+ * await fileExists('/path/to/file.txt') // true or false
97
+ */
98
+ export declare function fileExists(p: string): Promise<boolean>;
99
+ /**
100
+ * Read and parse a JSON file.
101
+ *
102
+ * **Node.js only** - throws an error if called in browser.
103
+ *
104
+ * @param jsonPath - Path to JSON file
105
+ * @returns Parsed JSON content, or null if file doesn't exist or is invalid
106
+ *
107
+ * @example
108
+ * const config = await readJSON<Config>('/path/to/config.json');
109
+ */
110
+ export declare function readJSON<T = unknown>(jsonPath: string): Promise<T | null>;
111
+ /**
112
+ * Write an object to a JSON file with pretty formatting.
113
+ *
114
+ * **Node.js only** - throws an error if called in browser.
115
+ *
116
+ * @param p - Path to write to
117
+ * @param obj - Object to serialize
118
+ *
119
+ * @example
120
+ * await writeJSON('/path/to/output.json', { key: 'value' });
121
+ */
122
+ export declare function writeJSON(p: string, obj: unknown): Promise<void>;
123
+ /**
124
+ * Ensure a directory exists, creating it recursively if needed.
125
+ *
126
+ * **Node.js only** - throws an error if called in browser.
127
+ *
128
+ * @param p - Path to directory
129
+ *
130
+ * @example
131
+ * await ensureDir('/path/to/new/directory');
132
+ */
133
+ export declare function ensureDir(p: string): Promise<void>;
134
+ /**
135
+ * Get file/directory stats.
136
+ *
137
+ * **Node.js only** - throws an error if called in browser.
138
+ *
139
+ * @param p - Path to file or directory
140
+ * @returns Stats object with isDirectory(), isFile(), etc.
141
+ *
142
+ * @example
143
+ * const stats = await stat('/path/to/file');
144
+ * if (stats.isDirectory()) { ... }
145
+ */
146
+ export declare function stat(p: string): Promise<import('fs').Stats>;
147
+ /**
148
+ * Copy a file.
149
+ *
150
+ * **Node.js only** - throws an error if called in browser.
151
+ *
152
+ * @param src - Source path
153
+ * @param dest - Destination path
154
+ *
155
+ * @example
156
+ * await copyFile('/path/to/src', '/path/to/dest');
157
+ */
158
+ export declare function copyFile(src: string, dest: string): Promise<void>;
159
+ /**
160
+ * Copy a file or directory recursively.
161
+ *
162
+ * **Node.js only** - throws an error if called in browser.
163
+ *
164
+ * @param src - Source path
165
+ * @param dest - Destination path
166
+ * @param options - Copy options
167
+ *
168
+ * @example
169
+ * await cp('/path/to/src', '/path/to/dest', { recursive: true });
170
+ */
171
+ export declare function cp(src: string, dest: string, options?: {
172
+ recursive?: boolean;
173
+ }): Promise<void>;
174
+ /**
175
+ * List directory contents.
176
+ *
177
+ * **Node.js only** - throws an error if called in browser.
178
+ *
179
+ * @param p - Path to directory
180
+ * @returns Array of file/directory names
181
+ *
182
+ * @example
183
+ * const files = await readdir('/path/to/dir');
184
+ */
185
+ export declare function readdir(p: string): Promise<string[]>;
186
+ /**
187
+ * Remove a file or directory recursively.
188
+ *
189
+ * **Node.js only** - throws an error if called in browser.
190
+ *
191
+ * @param p - Path to remove
192
+ * @param options - Optional recursive flag
193
+ *
194
+ * @example
195
+ * await rm('/path/to/dir', { recursive: true });
196
+ */
197
+ export declare function rm(p: string, options?: {
198
+ recursive?: boolean;
199
+ force?: boolean;
200
+ }): Promise<void>;
201
+ /**
202
+ * Check if a directory is empty.
203
+ *
204
+ * **Node.js only** - throws an error if called in browser.
205
+ *
206
+ * @param dir - Path to directory
207
+ * @returns true if directory is empty or doesn't exist
208
+ *
209
+ * @example
210
+ * await isDirEmpty('/path/to/directory') // true or false
211
+ */
212
+ export declare function isDirEmpty(dir: string): Promise<boolean>;
213
+ /**
214
+ * Create a temporary directory with a unique name.
215
+ *
216
+ * **Node.js only** - throws an error if called in browser.
217
+ *
218
+ * @param prefix - Directory prefix
219
+ * @returns Path to the created directory
220
+ *
221
+ * @example
222
+ * const tmpDir = await mkdtemp('/tmp/myapp-');
223
+ */
224
+ export declare function mkdtemp(prefix: string): Promise<string>;
225
+ /**
226
+ * Check if a file or directory is accessible.
227
+ *
228
+ * **Node.js only** - throws an error if called in browser.
229
+ *
230
+ * @param p - Path to check
231
+ * @param mode - Access mode (default F_OK for existence check)
232
+ * @throws Error if path is not accessible
233
+ *
234
+ * @example
235
+ * await access('/path/to/file'); // throws if not accessible
236
+ */
237
+ export declare function access(p: string, mode?: number): Promise<void>;
238
+ /**
239
+ * Run a command as a child process.
240
+ *
241
+ * **Node.js only** - throws an error if called in browser.
242
+ *
243
+ * @param cmd - Command to run
244
+ * @param args - Command arguments
245
+ * @param opts - Options including cwd
246
+ * @returns Promise that resolves when command completes successfully
247
+ * @throws Error if command exits with non-zero code
248
+ *
249
+ * @example
250
+ * await runCmd('npm', ['install'], { cwd: '/project' });
251
+ */
252
+ export declare function runCmd(cmd: string, args: string[], opts?: {
253
+ cwd?: string;
254
+ }): Promise<void>;
package/fs/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { readFile, readFileBuffer, writeFile, mkdir, rename, unlink, stat, copyFile, cp, readdir, rm, mkdtemp, access, fileExists, readJSON, writeJSON, ensureDir, isDirEmpty, runCmd, } from './fs';
package/http/http.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ /**
2
+ * HTTP utilities for URL validation and request handling.
3
+ *
4
+ * Provides security-focused validation for URLs and HTTP operations.
5
+ */
6
+ /**
7
+ * Validate and normalize a base URL.
8
+ * Only allows http: and https: protocols to prevent SSRF attacks.
9
+ *
10
+ * @param url - URL string to validate
11
+ * @returns Validated URL object
12
+ * @throws Error if URL is invalid or uses unsupported protocol
13
+ *
14
+ * @example
15
+ * validateBaseUrl('https://api.example.com') // URL object
16
+ * validateBaseUrl('http://localhost:3000') // URL object
17
+ * validateBaseUrl('file:///etc/passwd') // throws Error
18
+ * validateBaseUrl('javascript:alert(1)') // throws Error
19
+ */
20
+ export declare function validateBaseUrl(url: string): URL;
@@ -0,0 +1 @@
1
+ export { validateBaseUrl } from './http';
package/index.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @frontmcp/utils
3
+ *
4
+ * Shared utility functions for the FrontMCP ecosystem.
5
+ * Provides generic, protocol-neutral utilities for string manipulation,
6
+ * URI handling, path operations, content processing, and more.
7
+ */
8
+ export { NameCase, splitWords, toCase, sepFor, shortHash, ensureMaxLen, idFromString } from './naming';
9
+ export { isValidMcpUri, extractUriScheme, isValidMcpUriTemplate, ParsedUriTemplate, parseUriTemplate, matchUriTemplate, expandUriTemplate, extractTemplateParams, isUriTemplate, } from './uri';
10
+ export { trimSlashes, joinPath } from './path';
11
+ export { sanitizeToJson, inferMimeType } from './content';
12
+ export { validateBaseUrl } from './http';
13
+ export { readFile, readFileBuffer, writeFile, mkdir, rename, unlink, stat, copyFile, cp, readdir, rm, mkdtemp, access, fileExists, readJSON, writeJSON, ensureDir, isDirEmpty, runCmd, } from './fs';
14
+ export { escapeHtml, escapeHtmlAttr, escapeJsString, escapeScriptClose, safeJsonForScript } from './escape';
15
+ export { safeStringify } from './serialization';
16
+ export { getCrypto, rsaVerify, jwtAlgToNodeAlg, isRsaPssAlg, randomUUID, randomBytes, sha256, sha256Hex, sha256Base64url, hmacSha256, hkdfSha256, encryptAesGcm, decryptAesGcm, timingSafeEqual, bytesToHex, base64urlEncode, base64urlDecode, isNode, isBrowser, assertNode, CryptoProvider, EncBlob, EncryptedBlob, EncryptedBlobError, encryptValue, decryptValue, tryDecryptValue, serializeBlob, deserializeBlob, tryDeserializeBlob, isValidEncryptedBlob, encryptAndSerialize, deserializeAndDecrypt, tryDeserializeAndDecrypt, generateCodeVerifier, generateCodeChallenge, verifyCodeChallenge, generatePkcePair, isValidCodeVerifier, isValidCodeChallenge, MIN_CODE_VERIFIER_LENGTH, MAX_CODE_VERIFIER_LENGTH, DEFAULT_CODE_VERIFIER_LENGTH, PkceError, type PkcePair, type SecretData, type SecretPersistenceOptions, type SecretValidationResult, secretDataSchema, validateSecretData, parseSecretData, isSecretPersistenceEnabled, resolveSecretPath, loadSecret, saveSecret, deleteSecret, generateSecret, createSecretData, getOrCreateSecret, clearCachedSecret, isSecretCached, } from './crypto';
17
+ 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';
18
+ export { createStorage, createMemoryStorage, getDetectedStorageType, StorageAdapter, NamespacedStorage, RootStorage, SetOptions, SetEntry, MessageHandler, Unsubscribe, MemoryAdapterOptions, RedisAdapterOptions, VercelKvAdapterOptions, UpstashAdapterOptions, StorageType, StorageConfig, NamespacedStorageImpl, createRootStorage, createNamespacedStorage, buildPrefix, NAMESPACE_SEPARATOR, StorageError, StorageConnectionError, StorageOperationError, StorageNotSupportedError, StorageConfigError, StorageTTLError, StoragePatternError, StorageNotConnectedError, BaseStorageAdapter, MemoryStorageAdapter, RedisStorageAdapter, VercelKvStorageAdapter, UpstashStorageAdapter, globToRegex, matchesPattern, validatePattern, escapeGlob, MAX_TTL_SECONDS, validateTTL, validateOptionalTTL, ttlToExpiresAt, expiresAtToTTL, isExpired, normalizeTTL, } from './storage';