@frontmcp/utils 1.12.0-rc.1 → 1.12.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/browser/escape/escape.mjs +25 -0
- package/browser/escape/index.mjs +9 -1
- package/browser/http/index.mjs +4 -0
- package/browser/http/limited-body.mjs +74 -0
- package/browser/index.mjs +28 -2
- package/browser/optional-module/index.mjs +6 -0
- package/browser/optional-module/optional-module.mjs +18 -0
- package/browser/redaction/redaction.mjs +6 -4
- package/browser/stdio-bridge/sse-frames.mjs +3 -1
- package/browser/stdio-bridge/stdio-framer.mjs +4 -1
- package/browser/storage/adapters/filesystem.mjs +31 -9
- package/browser/storage/adapters/memory.mjs +25 -26
- package/browser/storage/factory.mjs +2 -1
- package/browser/storage/index.mjs +2 -1
- package/browser/storage/utils/index.mjs +2 -1
- package/browser/storage/utils/pattern.mjs +71 -24
- package/browser/uri/uri-template.mjs +93 -15
- package/crypto/key-persistence/types.d.ts +4 -1
- package/escape/escape.d.ts +19 -0
- package/escape/index.d.ts +1 -1
- package/esm/index.mjs +1 -1
- package/http/index.d.ts +2 -0
- package/http/limited-body.d.ts +56 -0
- package/index.d.ts +5 -4
- package/index.js +1 -1
- package/optional-module/index.d.ts +1 -0
- package/optional-module/optional-module.d.ts +12 -0
- package/package.json +3 -3
- package/redaction/redaction.d.ts +1 -1
- package/storage/adapters/filesystem.d.ts +11 -0
- package/storage/adapters/memory.d.ts +6 -2
- package/storage/index.d.ts +1 -1
- package/storage/utils/index.d.ts +1 -1
- package/storage/utils/pattern.d.ts +31 -4
package/http/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { validateBaseUrl } from './http';
|
|
2
|
+
export { readBodyWithLimit, readTextWithLimit, ResponseTooLargeError } from './limited-body';
|
|
3
|
+
export type { LimitedBodySource } from './limited-body';
|
|
2
4
|
export { buildSetCookie, parseCookies, getCookie, isLocalhost, isSecureRequest } from './cookie';
|
|
3
5
|
export type { CookieOptions, SecureDetectionRequest } from './cookie';
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read an HTTP response body without holding more than a set number of bytes.
|
|
3
|
+
*
|
|
4
|
+
* `response.text()` and `response.arrayBuffer()` buffer the whole body before a caller can check its size, and the
|
|
5
|
+
* body `fetch` hands over is already decompressed, so a small compressed response can expand without limit. These
|
|
6
|
+
* helpers stop reading, and cancel the body, as soon as the limit is passed.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Thrown when a response body is larger than the limit given to {@link readBodyWithLimit} or
|
|
10
|
+
* {@link readTextWithLimit}.
|
|
11
|
+
*/
|
|
12
|
+
export declare class ResponseTooLargeError extends Error {
|
|
13
|
+
readonly maxBytes: number;
|
|
14
|
+
constructor(maxBytes: number);
|
|
15
|
+
}
|
|
16
|
+
/** The parts of a fetch `Response` the readers use, so tests and wrappers can pass look-alikes. */
|
|
17
|
+
export interface LimitedBodySource {
|
|
18
|
+
readonly headers?: {
|
|
19
|
+
get(name: string): string | null;
|
|
20
|
+
};
|
|
21
|
+
readonly body?: ReadableStream<Uint8Array> | null;
|
|
22
|
+
arrayBuffer?(): Promise<ArrayBuffer>;
|
|
23
|
+
text?(): Promise<string>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Read a response body, failing with {@link ResponseTooLargeError} once it passes `maxBytes`.
|
|
27
|
+
*
|
|
28
|
+
* A `Content-Length` above the limit fails before any byte is read. Otherwise the body stream is read chunk by
|
|
29
|
+
* chunk and cancelled as soon as the running total passes the limit, so at most `maxBytes` plus one chunk is held.
|
|
30
|
+
* The limit applies to the bytes `fetch` delivers, which are already decompressed.
|
|
31
|
+
*
|
|
32
|
+
* A look-alike response without a `body` stream is read with `arrayBuffer()` or `text()` and then checked; only real
|
|
33
|
+
* streams are bounded while reading.
|
|
34
|
+
*
|
|
35
|
+
* @param response - A fetch `Response`, or an object with the same `headers`, `body`, `arrayBuffer` or `text`
|
|
36
|
+
* @param maxBytes - The largest body accepted, in bytes
|
|
37
|
+
* @returns The body bytes
|
|
38
|
+
* @throws ResponseTooLargeError when the body is larger than `maxBytes`
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const res = await fetch(url);
|
|
43
|
+
* const bytes = await readBodyWithLimit(res, 1024 * 1024);
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function readBodyWithLimit(response: LimitedBodySource, maxBytes: number): Promise<Uint8Array>;
|
|
47
|
+
/**
|
|
48
|
+
* Read a response body as UTF-8 text, failing with {@link ResponseTooLargeError} once it passes `maxBytes`.
|
|
49
|
+
* See {@link readBodyWithLimit}.
|
|
50
|
+
*
|
|
51
|
+
* @param response - A fetch `Response`, or an object with the same `headers`, `body`, `arrayBuffer` or `text`
|
|
52
|
+
* @param maxBytes - The largest body accepted, in bytes (of UTF-8, before decoding)
|
|
53
|
+
* @returns The decoded text
|
|
54
|
+
* @throws ResponseTooLargeError when the body is larger than `maxBytes`
|
|
55
|
+
*/
|
|
56
|
+
export declare function readTextWithLimit(response: LimitedBodySource, maxBytes: number): Promise<string>;
|
package/index.d.ts
CHANGED
|
@@ -11,8 +11,8 @@ export { isValidMcpUri, extractUriScheme, isValidMcpUriTemplate, parseUriTemplat
|
|
|
11
11
|
export type { ParsedUriTemplate } from './uri';
|
|
12
12
|
export { trimSlashes, joinPath, pathResolve, pathJoin, basename, dirname, extname, isAbsolute, pathToFileURL, sep, } from './path';
|
|
13
13
|
export { sanitizeToJson, inferMimeType, findNonFiniteNumber, findDroppedKeys } from './content';
|
|
14
|
-
export { validateBaseUrl, buildSetCookie, parseCookies, getCookie, isLocalhost, isSecureRequest } from './http';
|
|
15
|
-
export type { CookieOptions, SecureDetectionRequest } from './http';
|
|
14
|
+
export { validateBaseUrl, buildSetCookie, parseCookies, getCookie, isLocalhost, isSecureRequest, readBodyWithLimit, readTextWithLimit, ResponseTooLargeError, } from './http';
|
|
15
|
+
export type { CookieOptions, SecureDetectionRequest, LimitedBodySource } from './http';
|
|
16
16
|
export { classifyIpAddress, expandIpv6, extractEmbeddedIpv4, isGloballyRoutableIp, parseIpv4, isRedirectResponse, validateOutboundUrl, sendOutboundRequest, outboundFailureCategory, OUTBOUND_TIMEOUT_MS, OUTBOUND_MAX_REQUEST_BYTES, } from './net';
|
|
17
17
|
export type { IpAddressClassification, IpAddressRange, SpecialPurposeIpRange, RedirectCandidate, OutboundTargetOptions, OutboundUrlCheck, OutboundUrlProblem, OutboundRequest, OutboundAnswer, OutboundFailure, OutboundFailureReason, OutboundFailureCategory, OutboundResult, } from './net';
|
|
18
18
|
export { readFile, readFileSync, readFileBuffer, writeFile, appendFile, mkdir, rename, unlink, stat, lstat, chmod, copyFile, cp, readdir, readdirSync, realpath, rm, mkdtemp, symlink, access, fileExists, fileExistsSync, readJSON, writeJSON, ensureDir, ensureDirSync, isDirEmpty, runCmd, watchFile, watchFiles, getSpawnFn, } from './fs';
|
|
@@ -23,8 +23,9 @@ export { DEV_BUFFER_FULL, DEV_ERROR_MESSAGE, DEV_RELOAD_DEADLINE, DEV_SERVER_UNR
|
|
|
23
23
|
export type { BridgeState, BridgeStateMachine, BridgeStateMachineOptions, InflightRequest, JsonRpcFrame, StdioFramer, StdioFramerOptions, BridgeLogger, HttpUpstreamClient, HttpUpstreamOptions, PipeUpstreamOptions, UpstreamClient, UpstreamClientOptions, } from './stdio-bridge';
|
|
24
24
|
export { redactFields, redactJson } from './redaction';
|
|
25
25
|
export type { RedactedFields } from './redaction';
|
|
26
|
-
export { escapeHtml, escapeHtmlAttr, escapeJsString, escapeScriptClose, safeJsonForScript } from './escape';
|
|
26
|
+
export { escapeHtml, escapeHtmlAttr, escapeJsString, escapeScriptClose, safeJsonForScript, escapeControlCharacters, } from './escape';
|
|
27
27
|
export { brandClass, isBrandedInstance } from './class-brand';
|
|
28
|
+
export { registerOptionalModule, requireOptionalModule } from './optional-module';
|
|
28
29
|
export { safeStringify, canonicalJson } from './serialization';
|
|
29
30
|
export { getCrypto, rsaVerify, rsaVerifySync, pemToPublicJwk, generateRsaKeyPair, rsaSignBase64Url, type RsaJwk, type RsaKeyPair, jwtAlgToNodeAlg, isRsaPssAlg, randomUUID, randomBytes, sha256, sha256Hex, sha256Base64url, hmacSha256, hkdfSha256, encryptAesGcm, decryptAesGcm, timingSafeEqual, bytesToHex, base64urlEncode, base64urlDecode, base64Encode, base64Decode, isNode, isBrowser, assertNode, 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, type SignedData, type HmacSigningConfig, signData, verifyData, isSignedData, verifyOrParseData, WEBHOOK_ID_HEADER, WEBHOOK_TIMESTAMP_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_SIGNATURE_TOLERANCE_SECONDS, signingKeyOf, isStandardWebhookSecret, generateStandardWebhookSecret, generateWebhookMessageId, signWebhookMessage, webhookSignatureHeaders, verifyWebhookSignature, type WebhookMessage, type SignedWebhookMessage, type WebhookSignatureCheck, type BaseKeyData, type SecretKeyData, type AsymmetricKeyData, type AnyKeyData, type KeyPersistenceOptions, type CreateKeyPersistenceOptions, type CreateSecretOptions, type CreateAsymmetricOptions, type KeyValidationResult, asymmetricAlgSchema, secretKeyDataSchema, asymmetricKeyDataSchema, anyKeyDataSchema, validateKeyData, parseKeyData, isSecretKeyData, isAsymmetricKeyData, KeyPersistence, createKeyPersistence, createKeyPersistenceWithStorage, } from './crypto';
|
|
30
31
|
export type { CryptoProvider, EncBlob, EncryptedBlob } from './crypto';
|
|
@@ -33,7 +34,7 @@ export { EventEmitter } from './event-emitter';
|
|
|
33
34
|
export { getEnv, getNodeEnv, getCwd, isProduction, isDevelopment, getEnvFlag, isDebug, setEnv, isEdgeRuntime, isServerless, supportsAnsi, getRuntimeContext, resetRuntimeContext, detectRuntimeContext, isEntryAvailable, checkEntryAvailability, entryAvailabilitySchema, } from './env';
|
|
34
35
|
export type { RuntimeContext, EntryAvailability } from './env';
|
|
35
36
|
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';
|
|
36
|
-
export { createStorage, createMemoryStorage, getDetectedStorageType, createChangeFeed, DEFAULT_CHANGE_FEED_COALESCE_MS, DEFAULT_CHANGE_FEED_POLL_INTERVAL_MS, NamespacedStorageImpl, createRootStorage, createNamespacedStorage, buildPrefix, NAMESPACE_SEPARATOR, StorageError, StorageConnectionError, StorageOperationError, StorageNotSupportedError, StorageConfigError, StorageTTLError, StoragePatternError, StorageNotConnectedError, EncryptedStorageError, BaseStorageAdapter, MemoryStorageAdapter, RedisStorageAdapter, createRedisClient, VercelKvStorageAdapter, createVercelKvClient, type VercelKvConnection, 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, attachRedisErrorListener, DEFAULT_REDIS_ERROR_LOG_INTERVAL_MS, mergeRedisUrlFields, describeRedisUrlConflicts, } from './storage';
|
|
37
|
+
export { createStorage, createMemoryStorage, getDetectedStorageType, createChangeFeed, DEFAULT_CHANGE_FEED_COALESCE_MS, DEFAULT_CHANGE_FEED_POLL_INTERVAL_MS, NamespacedStorageImpl, createRootStorage, createNamespacedStorage, buildPrefix, NAMESPACE_SEPARATOR, StorageError, StorageConnectionError, StorageOperationError, StorageNotSupportedError, StorageConfigError, StorageTTLError, StoragePatternError, StorageNotConnectedError, EncryptedStorageError, BaseStorageAdapter, MemoryStorageAdapter, RedisStorageAdapter, createRedisClient, VercelKvStorageAdapter, createVercelKvClient, type VercelKvConnection, UpstashStorageAdapter, FileSystemStorageAdapter, type FileSystemAdapterOptions, TypedStorage, type TypedStorageOptions, type TypedSetOptions, type TypedSetEntry, EncryptedTypedStorage, type EncryptedTypedStorageOptions, type EncryptedSetOptions, type EncryptedSetEntry, type EncryptionKey, type StoredEncryptedBlob, type ClientKeyBinding, createGlobMatcher, globToRegex, matchesPattern, validatePattern, escapeGlob, MAX_TTL_SECONDS, validateTTL, validateOptionalTTL, ttlToExpiresAt, expiresAtToTTL, isExpired, normalizeTTL, attachRedisErrorListener, DEFAULT_REDIS_ERROR_LOG_INTERVAL_MS, mergeRedisUrlFields, describeRedisUrlConflicts, } from './storage';
|
|
37
38
|
export type { StorageAdapter, NamespacedStorage, RootStorage, SetOptions, SetEntry, MessageHandler, Unsubscribe, MemoryAdapterOptions, RedisAdapterOptions, RedisHostConnectionConfig, RedisUrlConnectionConfig, RedisUrlFillInConfig, VercelKvAdapterOptions, UpstashAdapterOptions, SqliteAdapterOptions, StorageType, StorageConfig, RedisErrorListenerOptions, RedisUrlConnection, RedisUrlMerge, RedisUrlSiblingFields, CreateRedisClientOptions, ErrorEmitterClient, ChangeFeed, ChangeFeedKind, ChangeFeedOptions, } from './storage';
|
|
38
39
|
export { processPlatformToolCalls } from './llm';
|
|
39
40
|
export type { CallToolFn, OpenAIToolCallItem, OpenAIToolResponse, ClaudeToolUseBlock, ClaudeToolResultBlock, VercelToolCallInfo, PlatformToolCallsInput, PlatformToolCallsOutput, SupportedPlatform, } from './llm';
|