@revealui/core 0.3.0 → 0.5.0
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/dist/client/admin/components/AdminDashboard.d.ts.map +1 -1
- package/dist/client/admin/components/AdminDashboard.js +20 -3
- package/dist/client/richtext/index.d.ts.map +1 -1
- package/dist/client/richtext/plugins/FloatingToolbarPlugin.js +1 -3
- package/dist/collections/operations/create.d.ts +2 -1
- package/dist/collections/operations/create.d.ts.map +1 -1
- package/dist/collections/operations/create.js +28 -1
- package/dist/database/type-adapter.d.ts.map +1 -1
- package/dist/features.d.ts +7 -3
- package/dist/features.d.ts.map +1 -1
- package/dist/features.js +2 -0
- package/dist/globals/GlobalOperations.d.ts.map +1 -1
- package/dist/globals/GlobalOperations.js +12 -2
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/license.d.ts +6 -0
- package/dist/license.d.ts.map +1 -1
- package/dist/license.js +14 -1
- package/dist/monitoring/alerts.d.ts +4 -4
- package/dist/monitoring/alerts.d.ts.map +1 -1
- package/dist/plugins/nested-docs.d.ts.map +1 -1
- package/dist/plugins/nested-docs.js +0 -1
- package/dist/queries/queryBuilder.d.ts.map +1 -1
- package/dist/queries/queryBuilder.js +4 -3
- package/dist/richtext/index.d.ts.map +1 -1
- package/dist/storage/vercel-blob.d.ts.map +1 -1
- package/dist/storage/vercel-blob.js +3 -0
- package/dist/types/api.d.ts.map +1 -1
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/core.d.ts +1 -1
- package/dist/types/core.d.ts.map +1 -1
- package/dist/types/extensions.d.ts.map +1 -1
- package/dist/types/frontend.d.ts.map +1 -1
- package/dist/types/legacy.d.ts.map +1 -1
- package/dist/types/query.d.ts.map +1 -1
- package/dist/types/runtime.d.ts +1 -0
- package/dist/types/runtime.d.ts.map +1 -1
- package/dist/utils/error-responses.d.ts.map +1 -1
- package/dist/utils/error-responses.js +2 -3
- package/package.json +23 -23
- package/dist/caching/app-cache.d.ts +0 -242
- package/dist/caching/app-cache.d.ts.map +0 -1
- package/dist/caching/app-cache.js +0 -438
- package/dist/caching/cdn-config.d.ts +0 -155
- package/dist/caching/cdn-config.d.ts.map +0 -1
- package/dist/caching/cdn-config.js +0 -415
- package/dist/caching/edge-cache.d.ts +0 -177
- package/dist/caching/edge-cache.d.ts.map +0 -1
- package/dist/caching/edge-cache.js +0 -414
- package/dist/caching/service-worker.d.ts +0 -157
- package/dist/caching/service-worker.d.ts.map +0 -1
- package/dist/caching/service-worker.js +0 -438
- package/dist/client/admin/utils/auth.d.ts +0 -23
- package/dist/client/admin/utils/auth.d.ts.map +0 -1
- package/dist/client/admin/utils/auth.js +0 -52
- package/dist/client/http/client.d.ts +0 -15
- package/dist/client/http/client.d.ts.map +0 -1
- package/dist/client/http/client.js +0 -49
- package/dist/client/http/fetchBanner.d.ts +0 -18
- package/dist/client/http/fetchBanner.d.ts.map +0 -1
- package/dist/client/http/fetchBanner.js +0 -44
- package/dist/client/http/fetchCard.d.ts +0 -18
- package/dist/client/http/fetchCard.d.ts.map +0 -1
- package/dist/client/http/fetchCard.js +0 -46
- package/dist/client/http/fetchEvents.d.ts +0 -18
- package/dist/client/http/fetchEvents.d.ts.map +0 -1
- package/dist/client/http/fetchEvents.js +0 -44
- package/dist/client/http/fetchHero.d.ts +0 -17
- package/dist/client/http/fetchHero.d.ts.map +0 -1
- package/dist/client/http/fetchHero.js +0 -55
- package/dist/client/http/fetchMainInfos.d.ts +0 -17
- package/dist/client/http/fetchMainInfos.d.ts.map +0 -1
- package/dist/client/http/fetchMainInfos.js +0 -44
- package/dist/client/http/fetchVideos.d.ts +0 -13
- package/dist/client/http/fetchVideos.d.ts.map +0 -1
- package/dist/client/http/fetchVideos.js +0 -36
- package/dist/client/http/index.d.ts +0 -19
- package/dist/client/http/index.d.ts.map +0 -1
- package/dist/client/http/index.js +0 -11
- package/dist/error-handling/circuit-breaker.d.ts +0 -262
- package/dist/error-handling/circuit-breaker.d.ts.map +0 -1
- package/dist/error-handling/circuit-breaker.js +0 -550
- package/dist/error-handling/retry.d.ts +0 -194
- package/dist/error-handling/retry.d.ts.map +0 -1
- package/dist/error-handling/retry.js +0 -455
- package/dist/errors/index.d.ts +0 -23
- package/dist/errors/index.d.ts.map +0 -1
- package/dist/errors/index.js +0 -40
- package/dist/generated/agents/index.d.ts +0 -8
- package/dist/generated/agents/index.d.ts.map +0 -1
- package/dist/generated/agents/index.js +0 -7
- package/dist/generated/components/index.d.ts +0 -8
- package/dist/generated/components/index.d.ts.map +0 -1
- package/dist/generated/components/index.js +0 -7
- package/dist/generated/functions/index.d.ts +0 -8
- package/dist/generated/functions/index.d.ts.map +0 -1
- package/dist/generated/functions/index.js +0 -7
- package/dist/generated/hooks/index.d.ts +0 -8
- package/dist/generated/hooks/index.d.ts.map +0 -1
- package/dist/generated/hooks/index.js +0 -7
- package/dist/generated/plans/index.d.ts +0 -8
- package/dist/generated/plans/index.d.ts.map +0 -1
- package/dist/generated/plans/index.js +0 -7
- package/dist/generated/prompts/index.d.ts +0 -8
- package/dist/generated/prompts/index.d.ts.map +0 -1
- package/dist/generated/prompts/index.js +0 -7
- package/dist/generated/tools/index.d.ts +0 -8
- package/dist/generated/tools/index.d.ts.map +0 -1
- package/dist/generated/tools/index.js +0 -7
- package/dist/generated/types/supabase.d.ts +0 -193
- package/dist/generated/types/supabase.d.ts.map +0 -1
- package/dist/generated/types/supabase.js +0 -5
- package/dist/optimization/asset-optimizer.d.ts +0 -206
- package/dist/optimization/asset-optimizer.d.ts.map +0 -1
- package/dist/optimization/asset-optimizer.js +0 -336
- package/dist/optimization/build-optimizer.d.ts +0 -202
- package/dist/optimization/build-optimizer.d.ts.map +0 -1
- package/dist/optimization/build-optimizer.js +0 -271
- package/dist/optimization/bundle-analyzer.d.ts +0 -98
- package/dist/optimization/bundle-analyzer.d.ts.map +0 -1
- package/dist/optimization/bundle-analyzer.js +0 -346
- package/dist/optimization/code-splitting.d.ts +0 -121
- package/dist/optimization/code-splitting.d.ts.map +0 -1
- package/dist/optimization/code-splitting.js +0 -261
- package/dist/plugin/index.d.ts +0 -12
- package/dist/plugin/index.d.ts.map +0 -1
- package/dist/plugin/index.js +0 -4
- package/dist/security/audit.d.ts +0 -188
- package/dist/security/audit.d.ts.map +0 -1
- package/dist/security/audit.js +0 -433
- package/dist/security/auth.d.ts +0 -110
- package/dist/security/auth.d.ts.map +0 -1
- package/dist/security/auth.js +0 -257
- package/dist/security/authorization.d.ts +0 -211
- package/dist/security/authorization.d.ts.map +0 -1
- package/dist/security/authorization.js +0 -492
- package/dist/security/encryption.d.ts +0 -226
- package/dist/security/encryption.d.ts.map +0 -1
- package/dist/security/encryption.js +0 -534
- package/dist/security/gdpr-storage.d.ts +0 -102
- package/dist/security/gdpr-storage.d.ts.map +0 -1
- package/dist/security/gdpr-storage.js +0 -65
- package/dist/security/gdpr.d.ts +0 -320
- package/dist/security/gdpr.d.ts.map +0 -1
- package/dist/security/gdpr.js +0 -531
- package/dist/security/headers.d.ts +0 -184
- package/dist/security/headers.d.ts.map +0 -1
- package/dist/security/headers.js +0 -420
- package/dist/utils/jwt-validation.d.ts +0 -14
- package/dist/utils/jwt-validation.d.ts.map +0 -1
- package/dist/utils/jwt-validation.js +0 -36
- package/dist/utils/request-headers.d.ts +0 -15
- package/dist/utils/request-headers.d.ts.map +0 -1
- package/dist/utils/request-headers.js +0 -31
package/dist/security/auth.js
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Authentication Utilities
|
|
3
|
-
*
|
|
4
|
-
* OAuth support, password hashing, and two-factor authentication.
|
|
5
|
-
* JWT-based auth was removed — session auth is handled by @revealui/auth.
|
|
6
|
-
*/
|
|
7
|
-
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
8
|
-
/**
|
|
9
|
-
* OAuth provider configurations
|
|
10
|
-
*/
|
|
11
|
-
export const OAuthProviders = {
|
|
12
|
-
google: {
|
|
13
|
-
authorizationUrl: 'https://accounts.google.com/o/oauth2/v2/auth',
|
|
14
|
-
tokenUrl: 'https://oauth2.googleapis.com/token',
|
|
15
|
-
userInfoUrl: 'https://www.googleapis.com/oauth2/v2/userinfo',
|
|
16
|
-
scope: ['openid', 'email', 'profile'],
|
|
17
|
-
},
|
|
18
|
-
github: {
|
|
19
|
-
authorizationUrl: 'https://github.com/login/oauth/authorize',
|
|
20
|
-
tokenUrl: 'https://github.com/login/oauth/access_token',
|
|
21
|
-
userInfoUrl: 'https://api.github.com/user',
|
|
22
|
-
scope: ['user:email'],
|
|
23
|
-
},
|
|
24
|
-
microsoft: {
|
|
25
|
-
authorizationUrl: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',
|
|
26
|
-
tokenUrl: 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
|
|
27
|
-
userInfoUrl: 'https://graph.microsoft.com/v1.0/me',
|
|
28
|
-
scope: ['openid', 'email', 'profile'],
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* OAuth client
|
|
33
|
-
*/
|
|
34
|
-
export class OAuthClient {
|
|
35
|
-
config;
|
|
36
|
-
constructor(config) {
|
|
37
|
-
// Provider defaults fill in missing fields; user-provided config takes precedence
|
|
38
|
-
this.config = {
|
|
39
|
-
...OAuthProviders[config.provider],
|
|
40
|
-
...config,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Get authorization URL
|
|
45
|
-
*/
|
|
46
|
-
getAuthorizationUrl(state) {
|
|
47
|
-
const params = new URLSearchParams({
|
|
48
|
-
client_id: this.config.clientId,
|
|
49
|
-
redirect_uri: this.config.redirectUri,
|
|
50
|
-
response_type: 'code',
|
|
51
|
-
scope: (this.config.scope || []).join(' '),
|
|
52
|
-
});
|
|
53
|
-
if (state) {
|
|
54
|
-
params.append('state', state);
|
|
55
|
-
}
|
|
56
|
-
return `${this.config.authorizationUrl}?${params.toString()}`;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Exchange code for token
|
|
60
|
-
*/
|
|
61
|
-
async exchangeCodeForToken(code) {
|
|
62
|
-
if (!this.config.tokenUrl)
|
|
63
|
-
throw new Error('tokenUrl is required for OAuth');
|
|
64
|
-
const response = await fetch(this.config.tokenUrl, {
|
|
65
|
-
method: 'POST',
|
|
66
|
-
headers: {
|
|
67
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
68
|
-
},
|
|
69
|
-
body: new URLSearchParams({
|
|
70
|
-
client_id: this.config.clientId,
|
|
71
|
-
client_secret: this.config.clientSecret,
|
|
72
|
-
code,
|
|
73
|
-
grant_type: 'authorization_code',
|
|
74
|
-
redirect_uri: this.config.redirectUri,
|
|
75
|
-
}),
|
|
76
|
-
});
|
|
77
|
-
if (!response.ok) {
|
|
78
|
-
let detail = '';
|
|
79
|
-
try {
|
|
80
|
-
const body = await response.text();
|
|
81
|
-
detail = `: ${response.status} ${body.slice(0, 200)}`;
|
|
82
|
-
}
|
|
83
|
-
catch {
|
|
84
|
-
detail = `: ${response.status}`;
|
|
85
|
-
}
|
|
86
|
-
throw new Error(`Failed to exchange code for token${detail}`);
|
|
87
|
-
}
|
|
88
|
-
return response.json();
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Get user info
|
|
92
|
-
*/
|
|
93
|
-
async getUserInfo(accessToken) {
|
|
94
|
-
if (!this.config.userInfoUrl)
|
|
95
|
-
throw new Error('userInfoUrl is required for OAuth');
|
|
96
|
-
const response = await fetch(this.config.userInfoUrl, {
|
|
97
|
-
headers: {
|
|
98
|
-
// biome-ignore lint/style/useNamingConvention: HTTP header convention
|
|
99
|
-
Authorization: `Bearer ${accessToken}`,
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
|
-
if (!response.ok) {
|
|
103
|
-
let detail = '';
|
|
104
|
-
try {
|
|
105
|
-
const body = await response.text();
|
|
106
|
-
detail = `: ${response.status} ${body.slice(0, 200)}`;
|
|
107
|
-
}
|
|
108
|
-
catch {
|
|
109
|
-
detail = `: ${response.status}`;
|
|
110
|
-
}
|
|
111
|
-
throw new Error(`Failed to fetch user info${detail}`);
|
|
112
|
-
}
|
|
113
|
-
return response.json();
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Password hashing utilities
|
|
118
|
-
*
|
|
119
|
-
* Uses PBKDF2 with a random salt for secure password hashing.
|
|
120
|
-
*
|
|
121
|
-
* @deprecated Use `@revealui/auth` instead — it uses bcrypt which is more
|
|
122
|
-
* resistant to GPU brute-force attacks. This PBKDF2 implementation will be
|
|
123
|
-
* removed in a future major version.
|
|
124
|
-
*/
|
|
125
|
-
const PH_ITERATIONS = 100000;
|
|
126
|
-
const PH_KEY_LENGTH = 64;
|
|
127
|
-
const PH_DIGEST = 'sha512';
|
|
128
|
-
/**
|
|
129
|
-
* Hash password with PBKDF2 and random salt
|
|
130
|
-
*/
|
|
131
|
-
async function hashPassword(password) {
|
|
132
|
-
const { pbkdf2, randomBytes: rb } = await import('node:crypto');
|
|
133
|
-
const salt = rb(16).toString('hex');
|
|
134
|
-
return new Promise((resolve, reject) => {
|
|
135
|
-
pbkdf2(password, salt, PH_ITERATIONS, PH_KEY_LENGTH, PH_DIGEST, (err, derivedKey) => {
|
|
136
|
-
if (err)
|
|
137
|
-
reject(err);
|
|
138
|
-
else
|
|
139
|
-
resolve(`${salt}:${derivedKey.toString('hex')}`);
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Verify password against stored hash
|
|
145
|
-
*/
|
|
146
|
-
async function verifyPassword(password, storedHash) {
|
|
147
|
-
const { pbkdf2, timingSafeEqual: tse } = await import('node:crypto');
|
|
148
|
-
const [salt, hash] = storedHash.split(':');
|
|
149
|
-
if (!(salt && hash)) {
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
return new Promise((resolve, reject) => {
|
|
153
|
-
pbkdf2(password, salt, PH_ITERATIONS, PH_KEY_LENGTH, PH_DIGEST, (err, derivedKey) => {
|
|
154
|
-
if (err)
|
|
155
|
-
reject(err);
|
|
156
|
-
else {
|
|
157
|
-
const derived = Buffer.from(derivedKey.toString('hex'), 'utf-8');
|
|
158
|
-
const expected = Buffer.from(hash, 'utf-8');
|
|
159
|
-
if (derived.length !== expected.length) {
|
|
160
|
-
resolve(false);
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
resolve(tse(derived, expected));
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
export const PasswordHasher = {
|
|
170
|
-
hash: hashPassword,
|
|
171
|
-
verify: verifyPassword,
|
|
172
|
-
};
|
|
173
|
-
/**
|
|
174
|
-
* Two-factor authentication
|
|
175
|
-
*/
|
|
176
|
-
/**
|
|
177
|
-
* Base32 encode
|
|
178
|
-
*/
|
|
179
|
-
function base32Encode(buffer) {
|
|
180
|
-
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
|
|
181
|
-
let result = '';
|
|
182
|
-
let bits = 0;
|
|
183
|
-
let value = 0;
|
|
184
|
-
for (const byte of buffer) {
|
|
185
|
-
if (byte === undefined)
|
|
186
|
-
continue;
|
|
187
|
-
value = (value << 8) | byte;
|
|
188
|
-
bits += 8;
|
|
189
|
-
while (bits >= 5) {
|
|
190
|
-
result += alphabet[(value >>> (bits - 5)) & 31];
|
|
191
|
-
bits -= 5;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
if (bits > 0) {
|
|
195
|
-
result += alphabet[(value << (5 - bits)) & 31];
|
|
196
|
-
}
|
|
197
|
-
return result;
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* HMAC-SHA1 implementation for TOTP
|
|
201
|
-
*/
|
|
202
|
-
function totpHmac(key, message) {
|
|
203
|
-
const hmacDigest = createHmac('sha1', key).update(message).digest();
|
|
204
|
-
return new Uint8Array(hmacDigest);
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Generate TOTP secret
|
|
208
|
-
*/
|
|
209
|
-
function generateSecret() {
|
|
210
|
-
const crypto = globalThis.crypto;
|
|
211
|
-
if (!crypto) {
|
|
212
|
-
throw new Error('Crypto API not available');
|
|
213
|
-
}
|
|
214
|
-
const buffer = new Uint8Array(20);
|
|
215
|
-
crypto.getRandomValues(buffer);
|
|
216
|
-
return base32Encode(buffer);
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Generate TOTP code
|
|
220
|
-
*/
|
|
221
|
-
function generateCode(secret, timestamp) {
|
|
222
|
-
const time = Math.floor((timestamp || Date.now()) / 30000);
|
|
223
|
-
const hmacDigest = totpHmac(secret, time.toString());
|
|
224
|
-
// biome-ignore lint/style/noNonNullAssertion: HMAC-SHA1 always produces 20 bytes; buffer indices are guaranteed valid
|
|
225
|
-
const offset = hmacDigest[hmacDigest.length - 1] & 0x0f;
|
|
226
|
-
// biome-ignore lint/style/noNonNullAssertion: HMAC-SHA1 always produces 20 bytes; buffer indices are guaranteed valid
|
|
227
|
-
const b0 = hmacDigest[offset] & 0x7f;
|
|
228
|
-
// biome-ignore lint/style/noNonNullAssertion: HMAC-SHA1 always produces 20 bytes; buffer indices are guaranteed valid
|
|
229
|
-
const b1 = hmacDigest[offset + 1] & 0xff;
|
|
230
|
-
// biome-ignore lint/style/noNonNullAssertion: HMAC-SHA1 always produces 20 bytes; buffer indices are guaranteed valid
|
|
231
|
-
const b2 = hmacDigest[offset + 2] & 0xff;
|
|
232
|
-
// biome-ignore lint/style/noNonNullAssertion: HMAC-SHA1 always produces 20 bytes; buffer indices are guaranteed valid
|
|
233
|
-
const b3 = hmacDigest[offset + 3] & 0xff;
|
|
234
|
-
const code = ((b0 << 24) | (b1 << 16) | (b2 << 8) | b3) % 1000000;
|
|
235
|
-
return code.toString().padStart(6, '0');
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Verify TOTP code
|
|
239
|
-
*/
|
|
240
|
-
function verifyCode(secret, code, window = 1) {
|
|
241
|
-
const timestamp = Date.now();
|
|
242
|
-
// Check current and adjacent time windows
|
|
243
|
-
for (let i = -window; i <= window; i++) {
|
|
244
|
-
const testTime = timestamp + i * 30000;
|
|
245
|
-
const testCode = generateCode(secret, testTime);
|
|
246
|
-
if (testCode.length === code.length &&
|
|
247
|
-
timingSafeEqual(Buffer.from(testCode), Buffer.from(code))) {
|
|
248
|
-
return true;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
return false;
|
|
252
|
-
}
|
|
253
|
-
export const TwoFactorAuth = {
|
|
254
|
-
generateSecret,
|
|
255
|
-
generateCode,
|
|
256
|
-
verifyCode,
|
|
257
|
-
};
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Authorization System
|
|
3
|
-
*
|
|
4
|
-
* Role-Based Access Control (RBAC) and Attribute-Based Access Control (ABAC)
|
|
5
|
-
*/
|
|
6
|
-
export interface Permission {
|
|
7
|
-
resource: string;
|
|
8
|
-
action: string;
|
|
9
|
-
conditions?: Record<string, unknown>;
|
|
10
|
-
}
|
|
11
|
-
export interface Role {
|
|
12
|
-
id: string;
|
|
13
|
-
name: string;
|
|
14
|
-
description?: string;
|
|
15
|
-
permissions: Permission[];
|
|
16
|
-
inherits?: string[];
|
|
17
|
-
}
|
|
18
|
-
export interface Policy {
|
|
19
|
-
id: string;
|
|
20
|
-
name: string;
|
|
21
|
-
effect: 'allow' | 'deny';
|
|
22
|
-
resources: string[];
|
|
23
|
-
actions: string[];
|
|
24
|
-
conditions?: PolicyCondition[];
|
|
25
|
-
priority?: number;
|
|
26
|
-
}
|
|
27
|
-
export interface PolicyCondition {
|
|
28
|
-
field: string;
|
|
29
|
-
operator: 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte' | 'in' | 'contains';
|
|
30
|
-
value: unknown;
|
|
31
|
-
}
|
|
32
|
-
export interface AuthorizationContext {
|
|
33
|
-
user: {
|
|
34
|
-
id: string;
|
|
35
|
-
roles: string[];
|
|
36
|
-
attributes?: Record<string, unknown>;
|
|
37
|
-
};
|
|
38
|
-
resource?: {
|
|
39
|
-
type: string;
|
|
40
|
-
id?: string;
|
|
41
|
-
owner?: string;
|
|
42
|
-
attributes?: Record<string, unknown>;
|
|
43
|
-
};
|
|
44
|
-
environment?: {
|
|
45
|
-
time?: Date;
|
|
46
|
-
ip?: string;
|
|
47
|
-
userAgent?: string;
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Authorization system
|
|
52
|
-
*/
|
|
53
|
-
export declare class AuthorizationSystem {
|
|
54
|
-
private roles;
|
|
55
|
-
private policies;
|
|
56
|
-
/**
|
|
57
|
-
* Register role
|
|
58
|
-
*/
|
|
59
|
-
registerRole(role: Role): void;
|
|
60
|
-
/**
|
|
61
|
-
* Get role
|
|
62
|
-
*/
|
|
63
|
-
getRole(roleId: string): Role | undefined;
|
|
64
|
-
/**
|
|
65
|
-
* Register policy
|
|
66
|
-
*/
|
|
67
|
-
registerPolicy(policy: Policy): void;
|
|
68
|
-
/**
|
|
69
|
-
* Check if user has permission (RBAC)
|
|
70
|
-
*/
|
|
71
|
-
hasPermission(userRoles: string[], resource: string, action: string): boolean;
|
|
72
|
-
/**
|
|
73
|
-
* Check access with policies (ABAC)
|
|
74
|
-
*/
|
|
75
|
-
checkAccess(context: AuthorizationContext, resource: string, action: string): {
|
|
76
|
-
allowed: boolean;
|
|
77
|
-
reason?: string;
|
|
78
|
-
};
|
|
79
|
-
/**
|
|
80
|
-
* Get all permissions for roles
|
|
81
|
-
*/
|
|
82
|
-
private getUserPermissions;
|
|
83
|
-
/**
|
|
84
|
-
* Get applicable policies
|
|
85
|
-
*/
|
|
86
|
-
private getApplicablePolicies;
|
|
87
|
-
/**
|
|
88
|
-
* Match resource pattern
|
|
89
|
-
*/
|
|
90
|
-
private matchesResource;
|
|
91
|
-
/**
|
|
92
|
-
* Match action pattern
|
|
93
|
-
*/
|
|
94
|
-
private matchesAction;
|
|
95
|
-
/**
|
|
96
|
-
* Evaluate policy conditions
|
|
97
|
-
*/
|
|
98
|
-
private evaluateConditions;
|
|
99
|
-
/**
|
|
100
|
-
* Get value from context
|
|
101
|
-
*/
|
|
102
|
-
private getContextValue;
|
|
103
|
-
/**
|
|
104
|
-
* Evaluate single condition
|
|
105
|
-
*/
|
|
106
|
-
private evaluateCondition;
|
|
107
|
-
/**
|
|
108
|
-
* Check if user owns resource
|
|
109
|
-
*/
|
|
110
|
-
ownsResource(userId: string, resource: {
|
|
111
|
-
owner?: string;
|
|
112
|
-
}): boolean;
|
|
113
|
-
/**
|
|
114
|
-
* Clear all roles and policies
|
|
115
|
-
*/
|
|
116
|
-
clear(): void;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Global authorization instance
|
|
120
|
-
*/
|
|
121
|
-
export declare const authorization: AuthorizationSystem;
|
|
122
|
-
/**
|
|
123
|
-
* Common roles — aligned with DB schema (`users.role` column)
|
|
124
|
-
* and `UserRoleSchema` in @revealui/contracts.
|
|
125
|
-
*
|
|
126
|
-
* Values: owner | admin | editor | viewer | agent | contributor
|
|
127
|
-
*/
|
|
128
|
-
export declare const CommonRoles: Record<string, Role>;
|
|
129
|
-
/**
|
|
130
|
-
* Permission builder
|
|
131
|
-
*/
|
|
132
|
-
export declare class PermissionBuilder {
|
|
133
|
-
private permission;
|
|
134
|
-
resource(resource: string): this;
|
|
135
|
-
action(action: string): this;
|
|
136
|
-
conditions(conditions: Record<string, unknown>): this;
|
|
137
|
-
build(): Permission;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Policy builder
|
|
141
|
-
*/
|
|
142
|
-
export declare class PolicyBuilder {
|
|
143
|
-
private policy;
|
|
144
|
-
id(id: string): this;
|
|
145
|
-
name(name: string): this;
|
|
146
|
-
allow(): this;
|
|
147
|
-
deny(): this;
|
|
148
|
-
resources(...resources: string[]): this;
|
|
149
|
-
actions(...actions: string[]): this;
|
|
150
|
-
condition(field: string, operator: PolicyCondition['operator'], value: unknown): this;
|
|
151
|
-
priority(priority: number): this;
|
|
152
|
-
build(): Policy;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Authorization decorators
|
|
156
|
-
*/
|
|
157
|
-
export declare function RequirePermission(resource: string, action: string): (_target: object, _propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
158
|
-
export declare function RequireRole(requiredRole: string): (_target: object, _propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
159
|
-
/**
|
|
160
|
-
* Authorization middleware
|
|
161
|
-
*/
|
|
162
|
-
export declare function createAuthorizationMiddleware<TRequest = unknown>(getUser: (request: TRequest) => {
|
|
163
|
-
id: string;
|
|
164
|
-
roles: string[];
|
|
165
|
-
}, resource: string, action: string): (request: TRequest, next: () => Promise<unknown>) => Promise<unknown>;
|
|
166
|
-
/**
|
|
167
|
-
* Resource ownership check
|
|
168
|
-
*/
|
|
169
|
-
export declare function canAccessResource(userId: string, userRoles: string[], resource: {
|
|
170
|
-
type: string;
|
|
171
|
-
id?: string;
|
|
172
|
-
owner?: string;
|
|
173
|
-
}, action: string): boolean;
|
|
174
|
-
/**
|
|
175
|
-
* Attribute-based access control helper
|
|
176
|
-
*/
|
|
177
|
-
export declare function checkAttributeAccess(context: AuthorizationContext, resource: string, action: string, requiredAttributes?: Record<string, unknown>): boolean;
|
|
178
|
-
/**
|
|
179
|
-
* Permission cache for performance
|
|
180
|
-
*/
|
|
181
|
-
export declare class PermissionCache {
|
|
182
|
-
private cache;
|
|
183
|
-
private ttl;
|
|
184
|
-
private maxEntries;
|
|
185
|
-
constructor(ttl?: number, maxEntries?: number);
|
|
186
|
-
/**
|
|
187
|
-
* Get cached permission
|
|
188
|
-
*/
|
|
189
|
-
get(userId: string, resource: string, action: string): boolean | undefined;
|
|
190
|
-
/**
|
|
191
|
-
* Set cached permission
|
|
192
|
-
*/
|
|
193
|
-
set(userId: string, resource: string, action: string, allowed: boolean): void;
|
|
194
|
-
/**
|
|
195
|
-
* Clear cache for user
|
|
196
|
-
*/
|
|
197
|
-
clearUser(userId: string): void;
|
|
198
|
-
/**
|
|
199
|
-
* Clear all cache
|
|
200
|
-
*/
|
|
201
|
-
clear(): void;
|
|
202
|
-
/**
|
|
203
|
-
* Get cache key
|
|
204
|
-
*/
|
|
205
|
-
private getCacheKey;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Global permission cache
|
|
209
|
-
*/
|
|
210
|
-
export declare const permissionCache: PermissionCache;
|
|
211
|
-
//# sourceMappingURL=authorization.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authorization.d.ts","sourceRoot":"","sources":["../../src/security/authorization.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,CAAC,EAAE,eAAe,EAAE,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,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