@jini-ai/capability-providers 0.6.15-rc.2 → 0.6.15
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.
|
@@ -20,8 +20,15 @@ import { createHmac, randomBytes, scryptSync, timingSafeEqual } from 'node:crypt
|
|
|
20
20
|
const SCRYPT_KEYLEN = 64;
|
|
21
21
|
const SCRYPT_SALT_BYTES = 16;
|
|
22
22
|
const DEFAULT_SESSION_TTL_MS = 60 * 60 * 1000;
|
|
23
|
+
function isSessionJwtPayload(parsed) {
|
|
24
|
+
if (!parsed || typeof parsed !== 'object')
|
|
25
|
+
return false;
|
|
26
|
+
const claims = parsed;
|
|
27
|
+
return typeof claims.sub === 'string' && typeof claims.jti === 'string' && typeof claims.exp === 'number';
|
|
28
|
+
}
|
|
23
29
|
function base64url(input) {
|
|
24
|
-
|
|
30
|
+
// Node's own base64url alphabet and unpadded form: the same bytes as translating base64 by hand.
|
|
31
|
+
return input.toString('base64url');
|
|
25
32
|
}
|
|
26
33
|
function base64urlToBuffer(input) {
|
|
27
34
|
const padded = input.replace(/-/g, '+').replace(/_/g, '/');
|
|
@@ -82,13 +89,8 @@ function verifySessionJwt(token, secret) {
|
|
|
82
89
|
catch {
|
|
83
90
|
return { ok: false };
|
|
84
91
|
}
|
|
85
|
-
if (!parsed
|
|
86
|
-
typeof parsed !== 'object' ||
|
|
87
|
-
typeof parsed.sub !== 'string' ||
|
|
88
|
-
typeof parsed.jti !== 'string' ||
|
|
89
|
-
typeof parsed.exp !== 'number') {
|
|
92
|
+
if (!isSessionJwtPayload(parsed))
|
|
90
93
|
return { ok: false };
|
|
91
|
-
}
|
|
92
94
|
return { ok: true, payload: parsed };
|
|
93
95
|
}
|
|
94
96
|
/**
|
|
@@ -134,8 +136,10 @@ export class JwtAuthProvider {
|
|
|
134
136
|
if (this.usersByEmail.has(credentials.email)) {
|
|
135
137
|
throw new Error(`email already registered: ${credentials.email}`);
|
|
136
138
|
}
|
|
139
|
+
const id = this.nextId;
|
|
140
|
+
this.nextId += 1;
|
|
137
141
|
const user = {
|
|
138
|
-
id: `user-${
|
|
142
|
+
id: `user-${id}`,
|
|
139
143
|
email: credentials.email,
|
|
140
144
|
createdAt: this.now(),
|
|
141
145
|
passwordHash: hashPassword(credentials.password),
|
|
@@ -12,8 +12,10 @@ export function createInMemoryAuthProvider(_required, options = {}) {
|
|
|
12
12
|
if (usersByEmail.has(credentials.email)) {
|
|
13
13
|
throw new Error(`email already registered: ${credentials.email}`);
|
|
14
14
|
}
|
|
15
|
+
const id = nextId;
|
|
16
|
+
nextId += 1;
|
|
15
17
|
const user = {
|
|
16
|
-
id: `user-${
|
|
18
|
+
id: `user-${id}`,
|
|
17
19
|
email: credentials.email,
|
|
18
20
|
password: credentials.password,
|
|
19
21
|
createdAt: now(),
|
|
@@ -26,8 +28,10 @@ export function createInMemoryAuthProvider(_required, options = {}) {
|
|
|
26
28
|
if (!user || user.password !== credentials.password) {
|
|
27
29
|
throw new Error('invalid email or password');
|
|
28
30
|
}
|
|
31
|
+
const tokenNumber = nextToken;
|
|
32
|
+
nextToken += 1;
|
|
29
33
|
const session = {
|
|
30
|
-
token: `session-${
|
|
34
|
+
token: `session-${tokenNumber}`,
|
|
31
35
|
userId: user.id,
|
|
32
36
|
expiresAt: now() + sessionTtlMs,
|
|
33
37
|
};
|
|
@@ -8,8 +8,10 @@ export function createInMemoryPaymentsProvider(_required, optional = {}) {
|
|
|
8
8
|
if (input.amountCents <= 0) {
|
|
9
9
|
throw new Error('amountCents must be positive');
|
|
10
10
|
}
|
|
11
|
+
const chargeNumber = nextChargeId;
|
|
12
|
+
nextChargeId += 1;
|
|
11
13
|
const record = {
|
|
12
|
-
id: `charge-${
|
|
14
|
+
id: `charge-${chargeNumber}`,
|
|
13
15
|
status: 'succeeded',
|
|
14
16
|
amountCents: input.amountCents,
|
|
15
17
|
currency: input.currency,
|
|
@@ -22,13 +22,16 @@ export class VisitorAuthConfigurationError extends Error {
|
|
|
22
22
|
this.code = code;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
+
function invalidInput(message) {
|
|
26
|
+
return new VisitorAuthConfigurationError({ code: 'invalid-input', message });
|
|
27
|
+
}
|
|
25
28
|
function parsedSecureUrl(value, label, allowLoopbackHttp) {
|
|
26
29
|
let url;
|
|
27
30
|
try {
|
|
28
31
|
url = new URL(value);
|
|
29
32
|
}
|
|
30
33
|
catch {
|
|
31
|
-
throw
|
|
34
|
+
throw invalidInput(`${label} must be an absolute URL`);
|
|
32
35
|
}
|
|
33
36
|
const secure = isSecureProtocol(url, allowLoopbackHttp);
|
|
34
37
|
if (!secure || url.username || url.password || url.hash) {
|
|
@@ -43,7 +46,7 @@ function isSecureProtocol(url, allowLoopbackHttp) {
|
|
|
43
46
|
}
|
|
44
47
|
function assertNonEmpty(value, label) {
|
|
45
48
|
if (!value.trim()) {
|
|
46
|
-
throw
|
|
49
|
+
throw invalidInput(`${label} must not be empty`);
|
|
47
50
|
}
|
|
48
51
|
}
|
|
49
52
|
function assertProviderAlignment(required) {
|
|
@@ -55,7 +58,7 @@ function assertProviderAlignment(required) {
|
|
|
55
58
|
function validatedTransactionTtl(ttlMs) {
|
|
56
59
|
const resolved = ttlMs ?? DEFAULT_TRANSACTION_TTL_MS;
|
|
57
60
|
if (!Number.isInteger(resolved) || resolved <= 0 || resolved > MAX_TRANSACTION_TTL_MS) {
|
|
58
|
-
throw
|
|
61
|
+
throw invalidInput(`ttlMs must be an integer between 1 and ${MAX_TRANSACTION_TTL_MS}`);
|
|
59
62
|
}
|
|
60
63
|
return resolved;
|
|
61
64
|
}
|
|
@@ -67,21 +70,21 @@ function assertPlanContext(required) {
|
|
|
67
70
|
assertNonEmpty(required.registration.clientSecretRef.id, 'clientSecretRef.id');
|
|
68
71
|
}
|
|
69
72
|
if (!Number.isFinite(required.nowMs)) {
|
|
70
|
-
throw
|
|
73
|
+
throw invalidInput('nowMs must be finite');
|
|
71
74
|
}
|
|
72
75
|
}
|
|
73
76
|
function validatedOidcNonce(protocol, security) {
|
|
74
77
|
if (!OPAQUE_SECURITY_VALUE.test(security.state)) {
|
|
75
|
-
throw
|
|
78
|
+
throw invalidInput('state is malformed or too short');
|
|
76
79
|
}
|
|
77
80
|
if (!PKCE_VALUE.test(security.codeVerifier) || !PKCE_VALUE.test(security.codeChallenge)) {
|
|
78
|
-
throw
|
|
81
|
+
throw invalidInput('PKCE verifier and S256 challenge must be 43-128 URL-safe characters');
|
|
79
82
|
}
|
|
80
83
|
if (protocol !== 'oidc')
|
|
81
84
|
return undefined;
|
|
82
85
|
const nonce = security.nonce;
|
|
83
86
|
if (!nonce || !OPAQUE_SECURITY_VALUE.test(nonce)) {
|
|
84
|
-
throw
|
|
87
|
+
throw invalidInput('OIDC authorization requires a strong nonce');
|
|
85
88
|
}
|
|
86
89
|
return nonce;
|
|
87
90
|
}
|
|
@@ -90,10 +93,10 @@ function assertAuthorizationServerSecurity(required) {
|
|
|
90
93
|
throw new VisitorAuthConfigurationError({ code: 'pkce-s256-required', message: 'visitor-auth requires authorization servers that support PKCE S256' });
|
|
91
94
|
}
|
|
92
95
|
if (required.provider.protocol === 'oidc' && !required.server.issuer) {
|
|
93
|
-
throw
|
|
96
|
+
throw invalidInput('OIDC authorization server metadata must declare an issuer');
|
|
94
97
|
}
|
|
95
98
|
if (required.server.requiresAuthorizationResponseIssuer && !required.server.issuer) {
|
|
96
|
-
throw
|
|
99
|
+
throw invalidInput('authorization response issuer validation requires a configured issuer');
|
|
97
100
|
}
|
|
98
101
|
}
|
|
99
102
|
function configuredAuthorizationUrl(required) {
|
|
@@ -242,7 +245,7 @@ export function evaluateVisitorAuthCallback(required) {
|
|
|
242
245
|
function validatedClockSkew(clockSkewSeconds) {
|
|
243
246
|
const skew = clockSkewSeconds ?? 60;
|
|
244
247
|
if (!Number.isFinite(skew) || skew < 0 || skew > 300) {
|
|
245
|
-
throw
|
|
248
|
+
throw invalidInput('clockSkewSeconds must be between 0 and 300');
|
|
246
249
|
}
|
|
247
250
|
return skew;
|
|
248
251
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/capability-providers",
|
|
3
|
-
"version": "0.6.15
|
|
3
|
+
"version": "0.6.15",
|
|
4
4
|
"description": "Swappable capability-provider ports (auth, storage, payments, db, realtime) as interfaces and DI tokens only; concrete adapters live behind ./adapters/* subpaths.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -94,12 +94,12 @@
|
|
|
94
94
|
"registry": "https://registry.npmjs.org"
|
|
95
95
|
},
|
|
96
96
|
"dependencies": {
|
|
97
|
-
"@jini-ai/core": "^0.6.15
|
|
97
|
+
"@jini-ai/core": "^0.6.15"
|
|
98
98
|
},
|
|
99
99
|
"peerDependencies": {
|
|
100
100
|
"better-sqlite3": "^13.0.0",
|
|
101
101
|
"ws": "^8.18.0",
|
|
102
|
-
"@jini-ai/platform": "^0.6.
|
|
102
|
+
"@jini-ai/platform": "^0.6.10"
|
|
103
103
|
},
|
|
104
104
|
"peerDependenciesMeta": {
|
|
105
105
|
"better-sqlite3": {
|
|
@@ -118,8 +118,8 @@
|
|
|
118
118
|
"@vitest/coverage-v8": "^2.1.9",
|
|
119
119
|
"better-sqlite3": "^13.0.0",
|
|
120
120
|
"ws": "^8.18.0",
|
|
121
|
-
"@jini-ai/
|
|
122
|
-
"@jini-ai/
|
|
121
|
+
"@jini-ai/platform": "0.6.15",
|
|
122
|
+
"@jini-ai/core": "0.6.15"
|
|
123
123
|
},
|
|
124
124
|
"scripts": {
|
|
125
125
|
"build": "tsc -p tsconfig.json",
|