@frontmcp/utils 1.9.1 → 1.9.3
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/crypto/browser.d.ts +5 -0
- package/crypto/browser.js +33 -5
- package/crypto/node.d.ts +1 -1
- package/env/browser-env.d.ts +6 -0
- package/env/browser-env.js +12 -3
- package/env/browser-runtime-context.d.ts +4 -0
- package/env/browser-runtime-context.js +29 -3
- package/esm/crypto/browser.mjs +27 -4
- package/esm/env/browser-env.mjs +12 -3
- package/esm/env/browser-runtime-context.mjs +29 -3
- package/esm/index.mjs +196 -223
- package/index.d.ts +2 -2
- package/index.js +201 -225
- package/package.json +6 -2
- package/storage/adapters/index.d.ts +1 -1
- package/storage/adapters/redis.d.ts +10 -0
- package/storage/adapters/vercel-kv.d.ts +41 -0
- package/storage/index.d.ts +5 -3
- package/storage/redis-url.d.ts +50 -0
- package/storage/types.d.ts +31 -9
package/crypto/browser.d.ts
CHANGED
|
@@ -11,6 +11,11 @@ import type { CryptoProvider } from './types';
|
|
|
11
11
|
export declare const browserCrypto: CryptoProvider;
|
|
12
12
|
/** Alias for conditional import resolution via `#crypto-provider`. */
|
|
13
13
|
export { browserCrypto as cryptoProvider };
|
|
14
|
+
export declare function rsaVerify(): boolean;
|
|
15
|
+
export declare function rsaSignBase64Url(): string;
|
|
16
|
+
export declare function rsaVerifySync(): boolean;
|
|
17
|
+
export declare function pemToPublicJwk(): JsonWebKey;
|
|
18
|
+
export declare function generateRsaKeyPair(): never;
|
|
14
19
|
export { isRsaPssAlg, jwtAlgToWebCryptoAlg } from './jwt-alg';
|
|
15
20
|
/**
|
|
16
21
|
* Verify an RSA signature using WebCrypto.
|
package/crypto/browser.js
CHANGED
|
@@ -22,16 +22,21 @@ var browser_exports = {};
|
|
|
22
22
|
__export(browser_exports, {
|
|
23
23
|
browserCrypto: () => browserCrypto,
|
|
24
24
|
cryptoProvider: () => browserCrypto,
|
|
25
|
+
generateRsaKeyPair: () => generateRsaKeyPair,
|
|
25
26
|
isRsaPssAlg: () => isRsaPssAlg,
|
|
26
27
|
jwtAlgToWebCryptoAlg: () => jwtAlgToWebCryptoAlg,
|
|
27
|
-
|
|
28
|
+
pemToPublicJwk: () => pemToPublicJwk,
|
|
29
|
+
rsaSignBase64Url: () => rsaSignBase64Url,
|
|
30
|
+
rsaVerify: () => rsaVerify,
|
|
31
|
+
rsaVerifyBrowser: () => rsaVerifyBrowser,
|
|
32
|
+
rsaVerifySync: () => rsaVerifySync
|
|
28
33
|
});
|
|
29
34
|
module.exports = __toCommonJS(browser_exports);
|
|
30
|
-
var
|
|
31
|
-
var import_hmac = require("@noble/hashes/hmac.js");
|
|
35
|
+
var import_aes = require("@noble/ciphers/aes.js");
|
|
32
36
|
var import_hkdf = require("@noble/hashes/hkdf.js");
|
|
37
|
+
var import_hmac = require("@noble/hashes/hmac.js");
|
|
38
|
+
var import_sha2 = require("@noble/hashes/sha2.js");
|
|
33
39
|
var import_utils = require("@noble/hashes/utils.js");
|
|
34
|
-
var import_aes = require("@noble/ciphers/aes.js");
|
|
35
40
|
|
|
36
41
|
// libs/utils/src/crypto/jwt-alg.ts
|
|
37
42
|
function isRsaPssAlg(jwtAlg) {
|
|
@@ -119,6 +124,24 @@ var browserCrypto = {
|
|
|
119
124
|
return constantTimeEqual(a, b);
|
|
120
125
|
}
|
|
121
126
|
};
|
|
127
|
+
function nodeOnly(name) {
|
|
128
|
+
throw new Error(`${name} is only available in Node.js runtimes`);
|
|
129
|
+
}
|
|
130
|
+
function rsaVerify() {
|
|
131
|
+
return nodeOnly("rsaVerify");
|
|
132
|
+
}
|
|
133
|
+
function rsaSignBase64Url() {
|
|
134
|
+
return nodeOnly("rsaSignBase64Url");
|
|
135
|
+
}
|
|
136
|
+
function rsaVerifySync() {
|
|
137
|
+
return nodeOnly("rsaVerifySync");
|
|
138
|
+
}
|
|
139
|
+
function pemToPublicJwk() {
|
|
140
|
+
return nodeOnly("pemToPublicJwk");
|
|
141
|
+
}
|
|
142
|
+
function generateRsaKeyPair() {
|
|
143
|
+
return nodeOnly("generateRsaKeyPair");
|
|
144
|
+
}
|
|
122
145
|
async function rsaVerifyBrowser(jwtAlg, data, publicJwk, signature) {
|
|
123
146
|
if (typeof globalThis.crypto?.subtle === "undefined") {
|
|
124
147
|
throw new Error("WebCrypto API (crypto.subtle) is not available in this environment");
|
|
@@ -154,7 +177,12 @@ function getSaltLength(jwtAlg) {
|
|
|
154
177
|
0 && (module.exports = {
|
|
155
178
|
browserCrypto,
|
|
156
179
|
cryptoProvider,
|
|
180
|
+
generateRsaKeyPair,
|
|
157
181
|
isRsaPssAlg,
|
|
158
182
|
jwtAlgToWebCryptoAlg,
|
|
159
|
-
|
|
183
|
+
pemToPublicJwk,
|
|
184
|
+
rsaSignBase64Url,
|
|
185
|
+
rsaVerify,
|
|
186
|
+
rsaVerifyBrowser,
|
|
187
|
+
rsaVerifySync
|
|
160
188
|
});
|
package/crypto/node.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ export declare function generateRsaKeyPair(modulusLength?: number, alg?: string)
|
|
|
48
48
|
* For RSA-PSS (PS256/PS384/PS512), callers must pass appropriate padding/saltLength options.
|
|
49
49
|
*/
|
|
50
50
|
export declare function rsaSign(algorithm: string, data: Buffer, privateKey: crypto.KeyObject, options?: Omit<crypto.SignKeyObjectInput, 'key'>): Buffer;
|
|
51
|
-
export declare function rsaVerify(jwtAlg: string, data: Buffer, publicJwk: JsonWebKey, signature: Buffer): boolean;
|
|
51
|
+
export declare function rsaVerify(jwtAlg: string, data: Buffer | Uint8Array, publicJwk: JsonWebKey, signature: Buffer | Uint8Array): boolean;
|
|
52
52
|
/**
|
|
53
53
|
* Sign data with an RSA private JWK and return a base64url-encoded signature.
|
|
54
54
|
*
|
package/env/browser-env.d.ts
CHANGED
|
@@ -7,6 +7,12 @@
|
|
|
7
7
|
export declare function getEnv(_key: string): string | undefined;
|
|
8
8
|
export declare function getEnv(_key: string, defaultValue: string): string;
|
|
9
9
|
export declare function getCwd(): string;
|
|
10
|
+
/**
|
|
11
|
+
* The NODE_ENV the page runs with: a `process` shim's live value first, then the value a
|
|
12
|
+
* bundler inlined for `process.env.NODE_ENV`, else none. `isProduction()`, `isDevelopment()`
|
|
13
|
+
* and the runtime context's `env` all read it (#770). As on Node, with no NODE_ENV the
|
|
14
|
+
* runtime context reports `development` while `isDevelopment()` stays false.
|
|
15
|
+
*/
|
|
10
16
|
export declare function getNodeEnv(): string | undefined;
|
|
11
17
|
export declare function isProduction(): boolean;
|
|
12
18
|
export declare function isDevelopment(): boolean;
|
package/env/browser-env.js
CHANGED
|
@@ -50,6 +50,14 @@ function isBrowserWorkerScope() {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
// libs/utils/src/env/browser-env.ts
|
|
53
|
+
var NODE_ENV_KEY = "NODE_ENV";
|
|
54
|
+
function bundlerDefinedNodeEnv() {
|
|
55
|
+
try {
|
|
56
|
+
return process.env["NODE_ENV"] || void 0;
|
|
57
|
+
} catch {
|
|
58
|
+
return void 0;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
53
61
|
function getEnv(_key, defaultValue) {
|
|
54
62
|
return defaultValue;
|
|
55
63
|
}
|
|
@@ -57,13 +65,14 @@ function getCwd() {
|
|
|
57
65
|
return "/";
|
|
58
66
|
}
|
|
59
67
|
function getNodeEnv() {
|
|
60
|
-
|
|
68
|
+
const shim = globalThis.process;
|
|
69
|
+
return shim?.env?.[NODE_ENV_KEY] || bundlerDefinedNodeEnv();
|
|
61
70
|
}
|
|
62
71
|
function isProduction() {
|
|
63
|
-
return
|
|
72
|
+
return getNodeEnv() === "production";
|
|
64
73
|
}
|
|
65
74
|
function isDevelopment() {
|
|
66
|
-
return
|
|
75
|
+
return getNodeEnv() === "development";
|
|
67
76
|
}
|
|
68
77
|
function getEnvFlag(_key) {
|
|
69
78
|
return false;
|
|
@@ -57,5 +57,9 @@ export declare function checkEntryAvailability(availability: EntryAvailability |
|
|
|
57
57
|
missingAxes: (keyof EntryAvailability)[];
|
|
58
58
|
};
|
|
59
59
|
export declare function detectRuntimeContext(): RuntimeContext;
|
|
60
|
+
/**
|
|
61
|
+
* The browser runtime context. Its `env` is read live from the same NODE_ENV as
|
|
62
|
+
* `isProduction()`, defaulting to `development` as on Node (#770).
|
|
63
|
+
*/
|
|
60
64
|
export declare function getRuntimeContext(): RuntimeContext;
|
|
61
65
|
export declare function resetRuntimeContext(): void;
|
|
@@ -29,6 +29,22 @@ __export(browser_runtime_context_exports, {
|
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(browser_runtime_context_exports);
|
|
31
31
|
var import_lazy_zod = require("@frontmcp/lazy-zod");
|
|
32
|
+
|
|
33
|
+
// libs/utils/src/env/browser-env.ts
|
|
34
|
+
var NODE_ENV_KEY = "NODE_ENV";
|
|
35
|
+
function bundlerDefinedNodeEnv() {
|
|
36
|
+
try {
|
|
37
|
+
return process.env["NODE_ENV"] || void 0;
|
|
38
|
+
} catch {
|
|
39
|
+
return void 0;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function getNodeEnv() {
|
|
43
|
+
const shim = globalThis.process;
|
|
44
|
+
return shim?.env?.[NODE_ENV_KEY] || bundlerDefinedNodeEnv();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// libs/utils/src/env/browser-runtime-context.ts
|
|
32
48
|
var entryAvailabilitySchema = import_lazy_zod.z.object({
|
|
33
49
|
os: import_lazy_zod.z.array(import_lazy_zod.z.string().min(1)).optional(),
|
|
34
50
|
platform: import_lazy_zod.z.array(import_lazy_zod.z.string().min(1)).optional(),
|
|
@@ -84,14 +100,24 @@ function detectRuntimeContext() {
|
|
|
84
100
|
deployment: "standalone",
|
|
85
101
|
provider: "bare",
|
|
86
102
|
target: "browser",
|
|
87
|
-
env: "
|
|
103
|
+
env: getNodeEnv() || "development"
|
|
88
104
|
};
|
|
89
105
|
}
|
|
90
|
-
var
|
|
106
|
+
var cached;
|
|
91
107
|
function getRuntimeContext() {
|
|
92
|
-
|
|
108
|
+
if (!cached) {
|
|
109
|
+
const detected = detectRuntimeContext();
|
|
110
|
+
Object.defineProperty(detected, "env", {
|
|
111
|
+
get: () => getNodeEnv() || "development",
|
|
112
|
+
enumerable: true,
|
|
113
|
+
configurable: true
|
|
114
|
+
});
|
|
115
|
+
cached = detected;
|
|
116
|
+
}
|
|
117
|
+
return cached;
|
|
93
118
|
}
|
|
94
119
|
function resetRuntimeContext() {
|
|
120
|
+
cached = void 0;
|
|
95
121
|
}
|
|
96
122
|
// Annotate the CommonJS export names for ESM import in node:
|
|
97
123
|
0 && (module.exports = {
|
package/esm/crypto/browser.mjs
CHANGED
|
@@ -2,11 +2,11 @@ var __frontmcpModule = typeof process !== "undefined" && typeof process.getBuilt
|
|
|
2
2
|
const require = __frontmcpModule ? __frontmcpModule.createRequire(import.meta.url || 'file:///') : undefined;
|
|
3
3
|
// __frontmcpCreateRequire
|
|
4
4
|
// libs/utils/src/crypto/browser.ts
|
|
5
|
-
import {
|
|
6
|
-
import { hmac } from "@noble/hashes/hmac.js";
|
|
5
|
+
import { gcm } from "@noble/ciphers/aes.js";
|
|
7
6
|
import { hkdf } from "@noble/hashes/hkdf.js";
|
|
7
|
+
import { hmac } from "@noble/hashes/hmac.js";
|
|
8
|
+
import { sha256 as sha256Hash } from "@noble/hashes/sha2.js";
|
|
8
9
|
import { randomBytes as nobleRandomBytes } from "@noble/hashes/utils.js";
|
|
9
|
-
import { gcm } from "@noble/ciphers/aes.js";
|
|
10
10
|
|
|
11
11
|
// libs/utils/src/crypto/jwt-alg.ts
|
|
12
12
|
function isRsaPssAlg(jwtAlg) {
|
|
@@ -94,6 +94,24 @@ var browserCrypto = {
|
|
|
94
94
|
return constantTimeEqual(a, b);
|
|
95
95
|
}
|
|
96
96
|
};
|
|
97
|
+
function nodeOnly(name) {
|
|
98
|
+
throw new Error(`${name} is only available in Node.js runtimes`);
|
|
99
|
+
}
|
|
100
|
+
function rsaVerify() {
|
|
101
|
+
return nodeOnly("rsaVerify");
|
|
102
|
+
}
|
|
103
|
+
function rsaSignBase64Url() {
|
|
104
|
+
return nodeOnly("rsaSignBase64Url");
|
|
105
|
+
}
|
|
106
|
+
function rsaVerifySync() {
|
|
107
|
+
return nodeOnly("rsaVerifySync");
|
|
108
|
+
}
|
|
109
|
+
function pemToPublicJwk() {
|
|
110
|
+
return nodeOnly("pemToPublicJwk");
|
|
111
|
+
}
|
|
112
|
+
function generateRsaKeyPair() {
|
|
113
|
+
return nodeOnly("generateRsaKeyPair");
|
|
114
|
+
}
|
|
97
115
|
async function rsaVerifyBrowser(jwtAlg, data, publicJwk, signature) {
|
|
98
116
|
if (typeof globalThis.crypto?.subtle === "undefined") {
|
|
99
117
|
throw new Error("WebCrypto API (crypto.subtle) is not available in this environment");
|
|
@@ -128,7 +146,12 @@ function getSaltLength(jwtAlg) {
|
|
|
128
146
|
export {
|
|
129
147
|
browserCrypto,
|
|
130
148
|
browserCrypto as cryptoProvider,
|
|
149
|
+
generateRsaKeyPair,
|
|
131
150
|
isRsaPssAlg,
|
|
132
151
|
jwtAlgToWebCryptoAlg,
|
|
133
|
-
|
|
152
|
+
pemToPublicJwk,
|
|
153
|
+
rsaSignBase64Url,
|
|
154
|
+
rsaVerify,
|
|
155
|
+
rsaVerifyBrowser,
|
|
156
|
+
rsaVerifySync
|
|
134
157
|
};
|
package/esm/env/browser-env.mjs
CHANGED
|
@@ -17,6 +17,14 @@ function isBrowserWorkerScope() {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
// libs/utils/src/env/browser-env.ts
|
|
20
|
+
var NODE_ENV_KEY = "NODE_ENV";
|
|
21
|
+
function bundlerDefinedNodeEnv() {
|
|
22
|
+
try {
|
|
23
|
+
return process.env["NODE_ENV"] || void 0;
|
|
24
|
+
} catch {
|
|
25
|
+
return void 0;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
20
28
|
function getEnv(_key, defaultValue) {
|
|
21
29
|
return defaultValue;
|
|
22
30
|
}
|
|
@@ -24,13 +32,14 @@ function getCwd() {
|
|
|
24
32
|
return "/";
|
|
25
33
|
}
|
|
26
34
|
function getNodeEnv() {
|
|
27
|
-
|
|
35
|
+
const shim = globalThis.process;
|
|
36
|
+
return shim?.env?.[NODE_ENV_KEY] || bundlerDefinedNodeEnv();
|
|
28
37
|
}
|
|
29
38
|
function isProduction() {
|
|
30
|
-
return
|
|
39
|
+
return getNodeEnv() === "production";
|
|
31
40
|
}
|
|
32
41
|
function isDevelopment() {
|
|
33
|
-
return
|
|
42
|
+
return getNodeEnv() === "development";
|
|
34
43
|
}
|
|
35
44
|
function getEnvFlag(_key) {
|
|
36
45
|
return false;
|
|
@@ -3,6 +3,22 @@ const require = __frontmcpModule ? __frontmcpModule.createRequire(import.meta.ur
|
|
|
3
3
|
// __frontmcpCreateRequire
|
|
4
4
|
// libs/utils/src/env/browser-runtime-context.ts
|
|
5
5
|
import { z } from "@frontmcp/lazy-zod";
|
|
6
|
+
|
|
7
|
+
// libs/utils/src/env/browser-env.ts
|
|
8
|
+
var NODE_ENV_KEY = "NODE_ENV";
|
|
9
|
+
function bundlerDefinedNodeEnv() {
|
|
10
|
+
try {
|
|
11
|
+
return process.env["NODE_ENV"] || void 0;
|
|
12
|
+
} catch {
|
|
13
|
+
return void 0;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function getNodeEnv() {
|
|
17
|
+
const shim = globalThis.process;
|
|
18
|
+
return shim?.env?.[NODE_ENV_KEY] || bundlerDefinedNodeEnv();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// libs/utils/src/env/browser-runtime-context.ts
|
|
6
22
|
var entryAvailabilitySchema = z.object({
|
|
7
23
|
os: z.array(z.string().min(1)).optional(),
|
|
8
24
|
platform: z.array(z.string().min(1)).optional(),
|
|
@@ -58,14 +74,24 @@ function detectRuntimeContext() {
|
|
|
58
74
|
deployment: "standalone",
|
|
59
75
|
provider: "bare",
|
|
60
76
|
target: "browser",
|
|
61
|
-
env: "
|
|
77
|
+
env: getNodeEnv() || "development"
|
|
62
78
|
};
|
|
63
79
|
}
|
|
64
|
-
var
|
|
80
|
+
var cached;
|
|
65
81
|
function getRuntimeContext() {
|
|
66
|
-
|
|
82
|
+
if (!cached) {
|
|
83
|
+
const detected = detectRuntimeContext();
|
|
84
|
+
Object.defineProperty(detected, "env", {
|
|
85
|
+
get: () => getNodeEnv() || "development",
|
|
86
|
+
enumerable: true,
|
|
87
|
+
configurable: true
|
|
88
|
+
});
|
|
89
|
+
cached = detected;
|
|
90
|
+
}
|
|
91
|
+
return cached;
|
|
67
92
|
}
|
|
68
93
|
function resetRuntimeContext() {
|
|
94
|
+
cached = void 0;
|
|
69
95
|
}
|
|
70
96
|
export {
|
|
71
97
|
checkEntryAvailability,
|