@frontmcp/utils 1.10.16 → 1.11.0-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.
Files changed (135) hide show
  1. package/README.md +1 -0
  2. package/browser/async-context/browser-async-context.mjs +177 -0
  3. package/browser/async-context/index.mjs +15 -0
  4. package/browser/async-context/overlap-error.mjs +10 -0
  5. package/browser/class-brand/class-brand.mjs +27 -0
  6. package/browser/class-brand/index.mjs +6 -0
  7. package/browser/content/content.mjs +151 -0
  8. package/browser/content/index.mjs +8 -0
  9. package/browser/crypto/browser.mjs +103 -0
  10. package/browser/crypto/encrypted-blob.mjs +119 -0
  11. package/browser/crypto/hmac-signing.mjs +70 -0
  12. package/browser/crypto/index.mjs +281 -0
  13. package/browser/crypto/jwt-alg.mjs +40 -0
  14. package/browser/crypto/key-persistence/factory.mjs +134 -0
  15. package/browser/crypto/key-persistence/index.mjs +26 -0
  16. package/browser/crypto/key-persistence/key-persistence.mjs +185 -0
  17. package/browser/crypto/key-persistence/schemas.mjs +82 -0
  18. package/browser/crypto/pkce/index.mjs +25 -0
  19. package/browser/crypto/pkce/pkce.mjs +59 -0
  20. package/browser/crypto/runtime.mjs +17 -0
  21. package/browser/crypto/secret-persistence/index.mjs +29 -0
  22. package/browser/crypto/secret-persistence/persistence.mjs +181 -0
  23. package/browser/crypto/secret-persistence/schema.mjs +40 -0
  24. package/browser/crypto/web-rsa.mjs +36 -0
  25. package/browser/env/browser-env.mjs +56 -0
  26. package/browser/env/browser-runtime-context.mjs +85 -0
  27. package/browser/env/build-target.mjs +25 -0
  28. package/browser/env/edge-scope.mjs +17 -0
  29. package/browser/env/index.mjs +47 -0
  30. package/browser/env/provider.mjs +46 -0
  31. package/browser/escape/escape.mjs +43 -0
  32. package/browser/escape/index.mjs +9 -0
  33. package/browser/event-emitter/browser-event-emitter.mjs +49 -0
  34. package/browser/event-emitter/index.mjs +5 -0
  35. package/browser/fs/fs.mjs +227 -0
  36. package/browser/fs/index.mjs +65 -0
  37. package/browser/http/cookie.mjs +85 -0
  38. package/browser/http/http.mjs +18 -0
  39. package/browser/http/index.mjs +11 -0
  40. package/browser/index.mjs +526 -0
  41. package/browser/llm/index.mjs +5 -0
  42. package/browser/llm/llm-tool-handlers.mjs +55 -0
  43. package/browser/machine-id/index.mjs +7 -0
  44. package/browser/machine-id/machine-id.mjs +108 -0
  45. package/browser/naming/index.mjs +10 -0
  46. package/browser/naming/naming.mjs +68 -0
  47. package/browser/net/index.mjs +10 -0
  48. package/browser/net/ip-address.mjs +128 -0
  49. package/browser/net/redirect.mjs +7 -0
  50. package/browser/path/browser-path.mjs +47 -0
  51. package/browser/path/index.mjs +24 -0
  52. package/browser/path/path.mjs +13 -0
  53. package/browser/process/child-process.mjs +23 -0
  54. package/browser/process/index.mjs +15 -0
  55. package/browser/process/owned-process.mjs +175 -0
  56. package/browser/process/process-tree.mjs +149 -0
  57. package/browser/process/process-watch.mjs +48 -0
  58. package/browser/redaction/index.mjs +6 -0
  59. package/browser/redaction/redaction.mjs +74 -0
  60. package/browser/regex/index.mjs +3 -0
  61. package/browser/regex/patterns.mjs +167 -0
  62. package/browser/regex/safe-regex.mjs +93 -0
  63. package/browser/serialization/index.mjs +5 -0
  64. package/browser/serialization/serialization.mjs +22 -0
  65. package/browser/stdio-bridge/errors.mjs +27 -0
  66. package/browser/stdio-bridge/index.mjs +24 -0
  67. package/browser/stdio-bridge/list-changed.mjs +21 -0
  68. package/browser/stdio-bridge/state-machine.mjs +211 -0
  69. package/browser/stdio-bridge/stdio-framer.mjs +91 -0
  70. package/browser/stdio-bridge/upstream-client.mjs +189 -0
  71. package/browser/storage/adapters/base.mjs +139 -0
  72. package/browser/storage/adapters/cloudflare-kv.mjs +149 -0
  73. package/browser/storage/adapters/filesystem.mjs +279 -0
  74. package/browser/storage/adapters/index.mjs +23 -0
  75. package/browser/storage/adapters/indexeddb.mjs +198 -0
  76. package/browser/storage/adapters/localstorage.mjs +222 -0
  77. package/browser/storage/adapters/memory.mjs +350 -0
  78. package/browser/storage/adapters/redis.mjs +497 -0
  79. package/browser/storage/adapters/upstash.mjs +299 -0
  80. package/browser/storage/adapters/vercel-kv.mjs +226 -0
  81. package/browser/storage/change-feed.mjs +189 -0
  82. package/browser/storage/encrypted-typed-storage.mjs +329 -0
  83. package/browser/storage/errors.mjs +92 -0
  84. package/browser/storage/factory.mjs +155 -0
  85. package/browser/storage/index.mjs +96 -0
  86. package/browser/storage/namespace.mjs +186 -0
  87. package/browser/storage/redis-error-listener.mjs +32 -0
  88. package/browser/storage/redis-url.mjs +66 -0
  89. package/browser/storage/typed-storage.mjs +171 -0
  90. package/browser/storage/utils/compare-and-delete.mjs +9 -0
  91. package/browser/storage/utils/index.mjs +24 -0
  92. package/browser/storage/utils/pattern.mjs +68 -0
  93. package/browser/storage/utils/ttl.mjs +48 -0
  94. package/browser/uri/index.mjs +19 -0
  95. package/browser/uri/uri-template.mjs +86 -0
  96. package/browser/uri/uri-validation.mjs +18 -0
  97. package/crypto/browser.d.ts +1 -13
  98. package/crypto/browser.js +1 -1
  99. package/crypto/node.js +1 -1
  100. package/crypto/web-rsa.d.ts +13 -0
  101. package/env/browser-runtime-context.js +1 -1
  102. package/env/runtime-context.js +1 -1
  103. package/esm/crypto/browser.mjs +1 -1
  104. package/esm/crypto/node.mjs +1 -1
  105. package/esm/env/browser-runtime-context.mjs +1 -1
  106. package/esm/env/runtime-context.mjs +1 -1
  107. package/esm/index.mjs +1 -1
  108. package/fs/fs.d.ts +20 -4
  109. package/fs/index.d.ts +1 -1
  110. package/index.d.ts +9 -3
  111. package/index.js +1 -1
  112. package/package.json +24 -8
  113. package/process/child-process.d.ts +2 -0
  114. package/process/index.d.ts +6 -0
  115. package/process/owned-process.d.ts +59 -0
  116. package/process/process-tree.d.ts +78 -0
  117. package/process/process-watch.d.ts +41 -0
  118. package/redaction/index.d.ts +2 -0
  119. package/redaction/redaction.d.ts +24 -0
  120. package/stdio-bridge/errors.d.ts +23 -0
  121. package/stdio-bridge/index.d.ts +9 -0
  122. package/stdio-bridge/list-changed.d.ts +3 -0
  123. package/stdio-bridge/state-machine.d.ts +61 -0
  124. package/stdio-bridge/stdio-framer.d.ts +49 -0
  125. package/stdio-bridge/types.d.ts +10 -0
  126. package/stdio-bridge/upstream-client.d.ts +66 -0
  127. package/storage/adapters/base.d.ts +2 -0
  128. package/storage/adapters/memory.d.ts +1 -0
  129. package/storage/adapters/redis.d.ts +3 -0
  130. package/storage/change-feed.d.ts +47 -0
  131. package/storage/factory.d.ts +6 -0
  132. package/storage/index.d.ts +3 -1
  133. package/storage/namespace.d.ts +2 -0
  134. package/storage/types.d.ts +46 -1
  135. package/storage/utils/compare-and-delete.d.ts +2 -0
@@ -4,8 +4,10 @@
4
4
  * Unified storage abstraction with pluggable backends.
5
5
  * Supports Memory (dev), Redis (prod), Vercel KV (edge), and Upstash (edge + pub/sub).
6
6
  */
7
- export type { StorageAdapter, NamespacedStorage, RootStorage, SetOptions, SetEntry, MessageHandler, Unsubscribe, MemoryAdapterOptions, RedisAdapterOptions, RedisHostConnectionConfig, RedisUrlConnectionConfig, RedisUrlFillInConfig, VercelKvAdapterOptions, UpstashAdapterOptions, StorageType, StorageConfig, } from './types';
7
+ export type { StorageAdapter, NamespacedStorage, RootStorage, SetOptions, SetEntry, MessageHandler, Unsubscribe, MemoryAdapterOptions, RedisAdapterOptions, RedisHostConnectionConfig, RedisUrlConnectionConfig, RedisUrlFillInConfig, VercelKvAdapterOptions, UpstashAdapterOptions, SqliteAdapterOptions, StorageType, StorageConfig, } from './types';
8
8
  export { createStorage, createMemoryStorage, getDetectedStorageType } from './factory';
9
+ export { createChangeFeed, DEFAULT_CHANGE_FEED_COALESCE_MS, DEFAULT_CHANGE_FEED_POLL_INTERVAL_MS } from './change-feed';
10
+ export type { ChangeFeed, ChangeFeedKind, ChangeFeedOptions } from './change-feed';
9
11
  export { attachRedisErrorListener, DEFAULT_REDIS_ERROR_LOG_INTERVAL_MS } from './redis-error-listener';
10
12
  export type { RedisErrorListenerOptions, ErrorEmitterClient } from './redis-error-listener';
11
13
  export { mergeRedisUrlFields, describeRedisUrlConflicts } from './redis-url';
@@ -68,8 +68,10 @@ export declare class NamespacedStorageImpl implements NamespacedStorage {
68
68
  incrBy(key: string, amount: number): Promise<number>;
69
69
  deleteIfEquals(key: string, expectedValue: string): Promise<boolean>;
70
70
  expireIfEquals(key: string, expectedValue: string, ttlSeconds: number): Promise<boolean>;
71
+ setIfEquals(key: string, expectedValue: string, value: string): Promise<boolean>;
71
72
  publish(channel: string, message: string): Promise<number>;
72
73
  subscribe(channel: string, handler: MessageHandler): Promise<Unsubscribe>;
74
+ onPubSubReconnect(listener: () => void): () => void;
73
75
  supportsPubSub(): boolean;
74
76
  }
75
77
  /**
@@ -224,6 +224,22 @@ export interface StorageAdapter {
224
224
  * @throws StorageNotSupportedError if the backend has no atomic compare-and-expire
225
225
  */
226
226
  expireIfEquals?(key: string, expectedValue: string, ttlSeconds: number): Promise<boolean>;
227
+ /**
228
+ * Atomically replace a key's value only while it still holds `expectedValue` (compare-and-set).
229
+ * Like a plain `set(key, value)`, the key has no TTL afterwards.
230
+ *
231
+ * @param key - Storage key
232
+ * @param expectedValue - The exact value the key must hold
233
+ * @param value - The value to store
234
+ * @returns true if this call stored `value`, false if the key was missing or held another value
235
+ * @throws StorageNotSupportedError if the backend has no atomic compare-and-set
236
+ */
237
+ setIfEquals?(key: string, expectedValue: string, value: string): Promise<boolean>;
238
+ /**
239
+ * A number that changes whenever another connection commits a write (SQLite's `PRAGMA data_version`),
240
+ * so a change feed can tell cheaply that another process wrote. Only the SQLite adapter has it.
241
+ */
242
+ dataVersion?(): Promise<number>;
227
243
  /**
228
244
  * Publish a message to a channel.
229
245
  * Not all adapters support pub/sub (e.g., Vercel KV doesn't).
@@ -244,6 +260,13 @@ export interface StorageAdapter {
244
260
  * @throws StorageNotSupportedError if adapter doesn't support pub/sub
245
261
  */
246
262
  subscribe(channel: string, handler: MessageHandler): Promise<Unsubscribe>;
263
+ /**
264
+ * Call `listener` each time the pub/sub connection is back after it was lost. The messages published while it
265
+ * was down were missed, so a subscriber that must not miss a change re-reads the state. Only Redis has it.
266
+ *
267
+ * @returns The function that stops calling `listener`
268
+ */
269
+ onPubSubReconnect?(listener: () => void): () => void;
247
270
  /**
248
271
  * Check if this adapter supports pub/sub.
249
272
  *
@@ -290,6 +313,8 @@ export interface NamespacedStorage extends StorageAdapter {
290
313
  deleteIfEquals(key: string, expectedValue: string): Promise<boolean>;
291
314
  /** {@link StorageAdapter.expireIfEquals}; throws StorageNotSupportedError when the adapter has none. */
292
315
  expireIfEquals(key: string, expectedValue: string, ttlSeconds: number): Promise<boolean>;
316
+ /** {@link StorageAdapter.setIfEquals}; throws StorageNotSupportedError when the adapter has none. */
317
+ setIfEquals(key: string, expectedValue: string, value: string): Promise<boolean>;
293
318
  /**
294
319
  * Get the underlying root adapter (for advanced use).
295
320
  * Use with caution - operations bypass namespace prefixing.
@@ -457,10 +482,25 @@ export interface CloudflareKvAdapterOptions {
457
482
  /** Key prefix applied to all keys. @default '' */
458
483
  keyPrefix?: string;
459
484
  }
485
+ /** SQLite adapter options (type 'sqlite', from `@frontmcp/storage-sqlite`): processes on one file share its keys. */
486
+ export interface SqliteAdapterOptions {
487
+ /** Path to the database file; its directory is created if missing. */
488
+ path: string;
489
+ /** Write-ahead log: readers don't wait for the writer. Needs a local filesystem. @default true */
490
+ walMode?: boolean;
491
+ /** How long an operation waits for another process's lock before failing with `SQLITE_BUSY`. @default 5000 */
492
+ busyTimeoutMs?: number;
493
+ /** How often expired keys are purged, in milliseconds; 0 turns the sweep off. @default 60000 */
494
+ ttlCleanupIntervalMs?: number;
495
+ /** Encrypt values at rest with AES-256-GCM, from a key derived with HKDF-SHA256. */
496
+ encryption?: {
497
+ secret: string;
498
+ };
499
+ }
460
500
  /**
461
501
  * Storage backend type.
462
502
  */
463
- export type StorageType = 'memory' | 'redis' | 'vercel-kv' | 'upstash' | 'cloudflare-kv' | 'auto';
503
+ export type StorageType = 'memory' | 'redis' | 'vercel-kv' | 'upstash' | 'cloudflare-kv' | 'sqlite' | 'auto';
464
504
  /**
465
505
  * Configuration for createStorage factory.
466
506
  */
@@ -471,6 +511,7 @@ export interface StorageConfig {
471
511
  * - 'redis': Redis (production)
472
512
  * - 'vercel-kv': Vercel KV (edge deployment, no pub/sub)
473
513
  * - 'upstash': Upstash Redis (edge deployment, with pub/sub)
514
+ * - 'sqlite': A local SQLite file, shared by the processes on one machine (no pub/sub)
474
515
  * - 'auto': Auto-detect based on environment variables
475
516
  * @default 'auto'
476
517
  */
@@ -495,6 +536,10 @@ export interface StorageConfig {
495
536
  * Upstash adapter options (when type='upstash').
496
537
  */
497
538
  upstash?: UpstashAdapterOptions;
539
+ /**
540
+ * SQLite adapter options (when type='sqlite').
541
+ */
542
+ sqlite?: SqliteAdapterOptions;
498
543
  /**
499
544
  * Root namespace prefix for all keys.
500
545
  * Applied on top of any adapter-specific prefix.
@@ -2,3 +2,5 @@
2
2
  export declare const COMPARE_AND_DELETE_SCRIPT = "if redis.call('GET', KEYS[1]) == ARGV[1] then return redis.call('DEL', KEYS[1]) end return 0";
3
3
  /** Redis Lua script for `expireIfEquals`: sets KEYS[1]'s TTL to ARGV[2] seconds only while it holds ARGV[1]. */
4
4
  export declare const COMPARE_AND_EXPIRE_SCRIPT = "if redis.call('GET', KEYS[1]) == ARGV[1] then return redis.call('EXPIRE', KEYS[1], ARGV[2]) end return 0";
5
+ /** Redis Lua script for `setIfEquals`: sets KEYS[1] to ARGV[2] only while it holds ARGV[1], returning 1 or 0. */
6
+ export declare const COMPARE_AND_SET_SCRIPT = "if redis.call('GET', KEYS[1]) == ARGV[1] then redis.call('SET', KEYS[1], ARGV[2]) return 1 end return 0";