alepha 0.13.0 → 0.13.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/dist/api-jobs/index.d.ts +26 -26
- package/dist/api-users/index.d.ts +1 -1
- package/dist/cli/{dist-Sz2EXvQX.cjs → dist-Dl9Vl7Ur.js} +17 -13
- package/dist/cli/{dist-BBPjuQ56.js.map → dist-Dl9Vl7Ur.js.map} +1 -1
- package/dist/cli/index.d.ts +3 -11
- package/dist/cli/index.js +106 -74
- package/dist/cli/index.js.map +1 -1
- package/dist/email/index.js +71 -73
- package/dist/email/index.js.map +1 -1
- package/dist/orm/index.d.ts +1 -1
- package/dist/orm/index.js.map +1 -1
- package/dist/queue/index.d.ts +4 -4
- package/dist/retry/index.d.ts +1 -1
- package/dist/retry/index.js +2 -2
- package/dist/retry/index.js.map +1 -1
- package/dist/scheduler/index.d.ts +6 -6
- package/dist/security/index.d.ts +28 -28
- package/dist/server/index.js +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server-health/index.d.ts +17 -17
- package/dist/server-metrics/index.js +170 -174
- package/dist/server-metrics/index.js.map +1 -1
- package/dist/server-security/index.d.ts +9 -9
- package/dist/vite/index.js +4 -5
- package/dist/vite/index.js.map +1 -1
- package/dist/websocket/index.d.ts +7 -7
- package/package.json +52 -103
- package/src/cli/apps/AlephaPackageBuilderCli.ts +7 -2
- package/src/cli/assets/appRouterTs.ts +9 -0
- package/src/cli/assets/indexHtml.ts +2 -1
- package/src/cli/assets/mainBrowserTs.ts +10 -0
- package/src/cli/commands/CoreCommands.ts +6 -5
- package/src/cli/commands/DrizzleCommands.ts +65 -57
- package/src/cli/commands/VerifyCommands.ts +1 -1
- package/src/cli/services/ProjectUtils.ts +44 -38
- package/src/orm/providers/DrizzleKitProvider.ts +1 -1
- package/src/retry/descriptors/$retry.ts +5 -3
- package/src/server/providers/NodeHttpServerProvider.ts +1 -1
- package/src/vite/helpers/boot.ts +3 -3
- package/dist/api-files/index.cjs +0 -1293
- package/dist/api-files/index.cjs.map +0 -1
- package/dist/api-files/index.d.cts +0 -829
- package/dist/api-jobs/index.cjs +0 -274
- package/dist/api-jobs/index.cjs.map +0 -1
- package/dist/api-jobs/index.d.cts +0 -654
- package/dist/api-notifications/index.cjs +0 -380
- package/dist/api-notifications/index.cjs.map +0 -1
- package/dist/api-notifications/index.d.cts +0 -289
- package/dist/api-parameters/index.cjs +0 -66
- package/dist/api-parameters/index.cjs.map +0 -1
- package/dist/api-parameters/index.d.cts +0 -84
- package/dist/api-users/index.cjs +0 -6009
- package/dist/api-users/index.cjs.map +0 -1
- package/dist/api-users/index.d.cts +0 -4740
- package/dist/api-verifications/index.cjs +0 -407
- package/dist/api-verifications/index.cjs.map +0 -1
- package/dist/api-verifications/index.d.cts +0 -207
- package/dist/batch/index.cjs +0 -408
- package/dist/batch/index.cjs.map +0 -1
- package/dist/batch/index.d.cts +0 -330
- package/dist/bin/index.cjs +0 -17
- package/dist/bin/index.cjs.map +0 -1
- package/dist/bin/index.d.cts +0 -1
- package/dist/bucket/index.cjs +0 -303
- package/dist/bucket/index.cjs.map +0 -1
- package/dist/bucket/index.d.cts +0 -355
- package/dist/cache/index.cjs +0 -241
- package/dist/cache/index.cjs.map +0 -1
- package/dist/cache/index.d.cts +0 -202
- package/dist/cache-redis/index.cjs +0 -84
- package/dist/cache-redis/index.cjs.map +0 -1
- package/dist/cache-redis/index.d.cts +0 -40
- package/dist/cli/chunk-DSlc6foC.cjs +0 -43
- package/dist/cli/dist-BBPjuQ56.js +0 -2778
- package/dist/cli/dist-Sz2EXvQX.cjs.map +0 -1
- package/dist/cli/index.cjs +0 -1241
- package/dist/cli/index.cjs.map +0 -1
- package/dist/cli/index.d.cts +0 -422
- package/dist/command/index.cjs +0 -693
- package/dist/command/index.cjs.map +0 -1
- package/dist/command/index.d.cts +0 -340
- package/dist/core/index.cjs +0 -2264
- package/dist/core/index.cjs.map +0 -1
- package/dist/core/index.d.cts +0 -1927
- package/dist/datetime/index.cjs +0 -318
- package/dist/datetime/index.cjs.map +0 -1
- package/dist/datetime/index.d.cts +0 -145
- package/dist/email/index.cjs +0 -10874
- package/dist/email/index.cjs.map +0 -1
- package/dist/email/index.d.cts +0 -186
- package/dist/fake/index.cjs +0 -34641
- package/dist/fake/index.cjs.map +0 -1
- package/dist/fake/index.d.cts +0 -74
- package/dist/file/index.cjs +0 -1212
- package/dist/file/index.cjs.map +0 -1
- package/dist/file/index.d.cts +0 -698
- package/dist/lock/index.cjs +0 -226
- package/dist/lock/index.cjs.map +0 -1
- package/dist/lock/index.d.cts +0 -361
- package/dist/lock-redis/index.cjs +0 -113
- package/dist/lock-redis/index.cjs.map +0 -1
- package/dist/lock-redis/index.d.cts +0 -24
- package/dist/logger/index.cjs +0 -521
- package/dist/logger/index.cjs.map +0 -1
- package/dist/logger/index.d.cts +0 -281
- package/dist/orm/index.cjs +0 -2986
- package/dist/orm/index.cjs.map +0 -1
- package/dist/orm/index.d.cts +0 -2213
- package/dist/queue/index.cjs +0 -1044
- package/dist/queue/index.cjs.map +0 -1
- package/dist/queue/index.d.cts +0 -1265
- package/dist/queue-redis/index.cjs +0 -873
- package/dist/queue-redis/index.cjs.map +0 -1
- package/dist/queue-redis/index.d.cts +0 -82
- package/dist/redis/index.cjs +0 -153
- package/dist/redis/index.cjs.map +0 -1
- package/dist/redis/index.d.cts +0 -82
- package/dist/retry/index.cjs +0 -146
- package/dist/retry/index.cjs.map +0 -1
- package/dist/retry/index.d.cts +0 -172
- package/dist/router/index.cjs +0 -111
- package/dist/router/index.cjs.map +0 -1
- package/dist/router/index.d.cts +0 -46
- package/dist/scheduler/index.cjs +0 -576
- package/dist/scheduler/index.cjs.map +0 -1
- package/dist/scheduler/index.d.cts +0 -145
- package/dist/security/index.cjs +0 -2402
- package/dist/security/index.cjs.map +0 -1
- package/dist/security/index.d.cts +0 -598
- package/dist/server/index.cjs +0 -1680
- package/dist/server/index.cjs.map +0 -1
- package/dist/server/index.d.cts +0 -810
- package/dist/server-auth/index.cjs +0 -3146
- package/dist/server-auth/index.cjs.map +0 -1
- package/dist/server-auth/index.d.cts +0 -1164
- package/dist/server-cache/index.cjs +0 -252
- package/dist/server-cache/index.cjs.map +0 -1
- package/dist/server-cache/index.d.cts +0 -164
- package/dist/server-compress/index.cjs +0 -141
- package/dist/server-compress/index.cjs.map +0 -1
- package/dist/server-compress/index.d.cts +0 -38
- package/dist/server-cookies/index.cjs +0 -234
- package/dist/server-cookies/index.cjs.map +0 -1
- package/dist/server-cookies/index.d.cts +0 -144
- package/dist/server-cors/index.cjs +0 -201
- package/dist/server-cors/index.cjs.map +0 -1
- package/dist/server-cors/index.d.cts +0 -140
- package/dist/server-health/index.cjs +0 -62
- package/dist/server-health/index.cjs.map +0 -1
- package/dist/server-health/index.d.cts +0 -58
- package/dist/server-helmet/index.cjs +0 -131
- package/dist/server-helmet/index.cjs.map +0 -1
- package/dist/server-helmet/index.d.cts +0 -97
- package/dist/server-links/index.cjs +0 -992
- package/dist/server-links/index.cjs.map +0 -1
- package/dist/server-links/index.d.cts +0 -513
- package/dist/server-metrics/index.cjs +0 -4535
- package/dist/server-metrics/index.cjs.map +0 -1
- package/dist/server-metrics/index.d.cts +0 -35
- package/dist/server-multipart/index.cjs +0 -237
- package/dist/server-multipart/index.cjs.map +0 -1
- package/dist/server-multipart/index.d.cts +0 -50
- package/dist/server-proxy/index.cjs +0 -186
- package/dist/server-proxy/index.cjs.map +0 -1
- package/dist/server-proxy/index.d.cts +0 -234
- package/dist/server-rate-limit/index.cjs +0 -241
- package/dist/server-rate-limit/index.cjs.map +0 -1
- package/dist/server-rate-limit/index.d.cts +0 -183
- package/dist/server-security/index.cjs +0 -316
- package/dist/server-security/index.cjs.map +0 -1
- package/dist/server-security/index.d.cts +0 -173
- package/dist/server-static/index.cjs +0 -170
- package/dist/server-static/index.cjs.map +0 -1
- package/dist/server-static/index.d.cts +0 -121
- package/dist/server-swagger/index.cjs +0 -1021
- package/dist/server-swagger/index.cjs.map +0 -1
- package/dist/server-swagger/index.d.cts +0 -382
- package/dist/sms/index.cjs +0 -221
- package/dist/sms/index.cjs.map +0 -1
- package/dist/sms/index.d.cts +0 -130
- package/dist/thread/index.cjs +0 -350
- package/dist/thread/index.cjs.map +0 -1
- package/dist/thread/index.d.cts +0 -260
- package/dist/topic/index.cjs +0 -282
- package/dist/topic/index.cjs.map +0 -1
- package/dist/topic/index.d.cts +0 -523
- package/dist/topic-redis/index.cjs +0 -71
- package/dist/topic-redis/index.cjs.map +0 -1
- package/dist/topic-redis/index.d.cts +0 -42
- package/dist/vite/index.cjs +0 -1077
- package/dist/vite/index.cjs.map +0 -1
- package/dist/vite/index.d.cts +0 -542
- package/dist/websocket/index.cjs +0 -1117
- package/dist/websocket/index.cjs.map +0 -1
- package/dist/websocket/index.d.cts +0 -861
|
@@ -1,598 +0,0 @@
|
|
|
1
|
-
import * as alepha28 from "alepha";
|
|
2
|
-
import { Alepha, Descriptor, KIND, Static } from "alepha";
|
|
3
|
-
import * as alepha_logger1 from "alepha/logger";
|
|
4
|
-
import { CryptoKey, FlattenedJWSInput, JSONWebKeySet, JWSHeaderParameters, JWTHeaderParameters, JWTPayload, JWTVerifyResult, KeyObject } from "jose";
|
|
5
|
-
import { JWTVerifyOptions } from "jose/jwt/verify";
|
|
6
|
-
import { DateTimeProvider, Duration, DurationLike } from "alepha/datetime";
|
|
7
|
-
import { UnauthorizedError } from "alepha/server";
|
|
8
|
-
|
|
9
|
-
//#region src/security/schemas/userAccountInfoSchema.d.ts
|
|
10
|
-
declare const userAccountInfoSchema: alepha28.TObject<{
|
|
11
|
-
id: alepha28.TString;
|
|
12
|
-
name: alepha28.TOptional<alepha28.TString>;
|
|
13
|
-
email: alepha28.TOptional<alepha28.TString>;
|
|
14
|
-
username: alepha28.TOptional<alepha28.TString>;
|
|
15
|
-
picture: alepha28.TOptional<alepha28.TString>;
|
|
16
|
-
sessionId: alepha28.TOptional<alepha28.TString>;
|
|
17
|
-
organizations: alepha28.TOptional<alepha28.TArray<alepha28.TString>>;
|
|
18
|
-
roles: alepha28.TOptional<alepha28.TArray<alepha28.TString>>;
|
|
19
|
-
}>;
|
|
20
|
-
type UserAccount = Static<typeof userAccountInfoSchema>;
|
|
21
|
-
//#endregion
|
|
22
|
-
//#region src/security/interfaces/UserAccountToken.d.ts
|
|
23
|
-
/**
|
|
24
|
-
* Add contextual metadata to a user account info.
|
|
25
|
-
* E.g. UserAccountToken is a UserAccountInfo during a request.
|
|
26
|
-
*/
|
|
27
|
-
interface UserAccountToken extends UserAccount {
|
|
28
|
-
/**
|
|
29
|
-
* Access token for the user.
|
|
30
|
-
*/
|
|
31
|
-
token?: string;
|
|
32
|
-
/**
|
|
33
|
-
* Realm name of the user.
|
|
34
|
-
*/
|
|
35
|
-
realm?: string;
|
|
36
|
-
/**
|
|
37
|
-
* Is user dedicated to his own resources for this scope ?
|
|
38
|
-
* Mostly, Admin is false and Customer is true.
|
|
39
|
-
*/
|
|
40
|
-
ownership?: string | boolean;
|
|
41
|
-
}
|
|
42
|
-
//#endregion
|
|
43
|
-
//#region src/security/schemas/permissionSchema.d.ts
|
|
44
|
-
declare const permissionSchema: alepha28.TObject<{
|
|
45
|
-
name: alepha28.TString;
|
|
46
|
-
group: alepha28.TOptional<alepha28.TString>;
|
|
47
|
-
description: alepha28.TOptional<alepha28.TString>;
|
|
48
|
-
method: alepha28.TOptional<alepha28.TString>;
|
|
49
|
-
path: alepha28.TOptional<alepha28.TString>;
|
|
50
|
-
}>;
|
|
51
|
-
type Permission = Static<typeof permissionSchema>;
|
|
52
|
-
//#endregion
|
|
53
|
-
//#region src/security/schemas/roleSchema.d.ts
|
|
54
|
-
declare const roleSchema: alepha28.TObject<{
|
|
55
|
-
name: alepha28.TString;
|
|
56
|
-
description: alepha28.TOptional<alepha28.TString>;
|
|
57
|
-
default: alepha28.TOptional<alepha28.TBoolean>;
|
|
58
|
-
permissions: alepha28.TArray<alepha28.TObject<{
|
|
59
|
-
name: alepha28.TString;
|
|
60
|
-
ownership: alepha28.TOptional<alepha28.TBoolean>;
|
|
61
|
-
exclude: alepha28.TOptional<alepha28.TArray<alepha28.TString>>;
|
|
62
|
-
}>>;
|
|
63
|
-
}>;
|
|
64
|
-
type Role = Static<typeof roleSchema>;
|
|
65
|
-
//#endregion
|
|
66
|
-
//#region src/security/providers/JwtProvider.d.ts
|
|
67
|
-
/**
|
|
68
|
-
* Provides utilities for working with JSON Web Tokens (JWT).
|
|
69
|
-
*/
|
|
70
|
-
declare class JwtProvider {
|
|
71
|
-
protected readonly log: alepha_logger1.Logger;
|
|
72
|
-
protected readonly keystore: KeyLoaderHolder[];
|
|
73
|
-
protected readonly dateTimeProvider: DateTimeProvider;
|
|
74
|
-
protected readonly encoder: TextEncoder;
|
|
75
|
-
/**
|
|
76
|
-
* Adds a key loader to the embedded keystore.
|
|
77
|
-
*
|
|
78
|
-
* @param name
|
|
79
|
-
* @param secretKeyOrJwks
|
|
80
|
-
*/
|
|
81
|
-
setKeyLoader(name: string, secretKeyOrJwks: string | JSONWebKeySet): void;
|
|
82
|
-
/**
|
|
83
|
-
* Retrieves the payload from a JSON Web Token (JWT).
|
|
84
|
-
*
|
|
85
|
-
* @param token - The JWT to extract the payload from.
|
|
86
|
-
*
|
|
87
|
-
* @return A Promise that resolves with the payload object from the token.
|
|
88
|
-
*/
|
|
89
|
-
parse(token: string, keyName?: string, options?: JWTVerifyOptions): Promise<JwtParseResult>;
|
|
90
|
-
/**
|
|
91
|
-
* Creates a JWT token with the provided payload and secret key.
|
|
92
|
-
*
|
|
93
|
-
* @param payload - The payload to be encoded in the token.
|
|
94
|
-
* It should include the `realm_access` property which contains an array of roles.
|
|
95
|
-
* @param keyName - The name of the key to use when signing the token.
|
|
96
|
-
*
|
|
97
|
-
* @returns The signed JWT token.
|
|
98
|
-
*/
|
|
99
|
-
create(payload: ExtendedJWTPayload, keyName?: string, signOptions?: JwtSignOptions): Promise<string>;
|
|
100
|
-
/**
|
|
101
|
-
* Determines if the provided key is a secret key.
|
|
102
|
-
*
|
|
103
|
-
* @param key
|
|
104
|
-
* @protected
|
|
105
|
-
*/
|
|
106
|
-
protected isSecretKey(key: string): boolean;
|
|
107
|
-
}
|
|
108
|
-
type KeyLoader = (protectedHeader?: JWSHeaderParameters, token?: FlattenedJWSInput) => Promise<CryptoKey | KeyObject>;
|
|
109
|
-
interface KeyLoaderHolder {
|
|
110
|
-
name: string;
|
|
111
|
-
keyLoader: KeyLoader;
|
|
112
|
-
secretKey?: string;
|
|
113
|
-
}
|
|
114
|
-
interface JwtSignOptions {
|
|
115
|
-
header?: Partial<JWTHeaderParameters>;
|
|
116
|
-
}
|
|
117
|
-
interface ExtendedJWTPayload extends JWTPayload {
|
|
118
|
-
sid?: string;
|
|
119
|
-
name?: string;
|
|
120
|
-
roles?: string[];
|
|
121
|
-
email?: string;
|
|
122
|
-
organizations?: string[];
|
|
123
|
-
realm_access?: {
|
|
124
|
-
roles: string[];
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
interface JwtParseResult {
|
|
128
|
-
keyName: string;
|
|
129
|
-
result: JWTVerifyResult<ExtendedJWTPayload>;
|
|
130
|
-
}
|
|
131
|
-
//#endregion
|
|
132
|
-
//#region src/security/providers/SecurityProvider.d.ts
|
|
133
|
-
declare const DEFAULT_APP_SECRET = "05759934015388327323179852515731";
|
|
134
|
-
declare const envSchema: alepha28.TObject<{
|
|
135
|
-
APP_SECRET: alepha28.TString;
|
|
136
|
-
}>;
|
|
137
|
-
declare module "alepha" {
|
|
138
|
-
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
139
|
-
}
|
|
140
|
-
declare class SecurityProvider {
|
|
141
|
-
protected readonly UNKNOWN_USER_NAME = "Anonymous User";
|
|
142
|
-
protected readonly PERMISSION_REGEXP: RegExp;
|
|
143
|
-
protected readonly PERMISSION_REGEXP_WILDCARD: RegExp;
|
|
144
|
-
protected readonly log: alepha_logger1.Logger;
|
|
145
|
-
protected readonly jwt: JwtProvider;
|
|
146
|
-
protected readonly env: {
|
|
147
|
-
APP_SECRET: string;
|
|
148
|
-
};
|
|
149
|
-
protected readonly alepha: Alepha;
|
|
150
|
-
get secretKey(): string;
|
|
151
|
-
/**
|
|
152
|
-
* The permissions configured for the security provider.
|
|
153
|
-
*/
|
|
154
|
-
protected readonly permissions: Permission[];
|
|
155
|
-
/**
|
|
156
|
-
* The realms configured for the security provider.
|
|
157
|
-
*/
|
|
158
|
-
protected readonly realms: Realm[];
|
|
159
|
-
protected start: alepha28.HookDescriptor<"start">;
|
|
160
|
-
/**
|
|
161
|
-
* Adds a role to one or more realms.
|
|
162
|
-
*
|
|
163
|
-
* @param role
|
|
164
|
-
* @param realms
|
|
165
|
-
*/
|
|
166
|
-
createRole(role: Role, ...realms: string[]): Role;
|
|
167
|
-
/**
|
|
168
|
-
* Adds a permission to the security provider.
|
|
169
|
-
*
|
|
170
|
-
* @param raw - The permission to add.
|
|
171
|
-
*/
|
|
172
|
-
createPermission(raw: Permission | string): Permission;
|
|
173
|
-
createRealm(realm: Realm): void;
|
|
174
|
-
/**
|
|
175
|
-
* Updates the roles for a realm then synchronizes the user account provider if available.
|
|
176
|
-
*
|
|
177
|
-
* Only available when the app is started.
|
|
178
|
-
*
|
|
179
|
-
* @param realm - The realm to update the roles for.
|
|
180
|
-
* @param roles - The roles to update.
|
|
181
|
-
*/
|
|
182
|
-
updateRealm(realm: string, roles: Role[]): Promise<void>;
|
|
183
|
-
/**
|
|
184
|
-
* Creates a user account from the provided payload.
|
|
185
|
-
*
|
|
186
|
-
* @param payload - The payload to create the user account from.
|
|
187
|
-
* @param [realmName] - The realm containing the roles. Default is all.
|
|
188
|
-
*
|
|
189
|
-
* @returns The user info created from the payload.
|
|
190
|
-
*/
|
|
191
|
-
createUserFromPayload(payload: JWTPayload, realmName?: string): UserAccount;
|
|
192
|
-
/**
|
|
193
|
-
* Checks if the user has the specified permission.
|
|
194
|
-
*
|
|
195
|
-
* Bonus: we check also if the user has "ownership" flag.
|
|
196
|
-
*
|
|
197
|
-
* @param permissionLike - The permission to check for.
|
|
198
|
-
* @param roleEntries - The roles to check for the permission.
|
|
199
|
-
*/
|
|
200
|
-
checkPermission(permissionLike: string | Permission, ...roleEntries: string[]): SecurityCheckResult;
|
|
201
|
-
/**
|
|
202
|
-
* Creates a user account from the provided payload.
|
|
203
|
-
*/
|
|
204
|
-
createUserFromToken(headerOrToken?: string, options?: {
|
|
205
|
-
permission?: Permission | string;
|
|
206
|
-
realm?: string;
|
|
207
|
-
verify?: JWTVerifyOptions;
|
|
208
|
-
}): Promise<UserAccountToken>;
|
|
209
|
-
/**
|
|
210
|
-
* Checks if a user has a specific role.
|
|
211
|
-
*
|
|
212
|
-
* @param roleName - The role to check for.
|
|
213
|
-
* @param permission - The permission to check for.
|
|
214
|
-
* @returns True if the user has the role, false otherwise.
|
|
215
|
-
*/
|
|
216
|
-
can(roleName: string, permission: string | Permission): boolean;
|
|
217
|
-
/**
|
|
218
|
-
* Checks if a user has ownership of a specific permission.
|
|
219
|
-
*/
|
|
220
|
-
ownership(roleName: string, permission: string | Permission): string | boolean | undefined;
|
|
221
|
-
/**
|
|
222
|
-
* Converts a permission object to a string.
|
|
223
|
-
*
|
|
224
|
-
* @param permission
|
|
225
|
-
*/
|
|
226
|
-
permissionToString(permission: Permission | string): string;
|
|
227
|
-
getRealms(): Realm[];
|
|
228
|
-
/**
|
|
229
|
-
* Retrieves the user account from the provided user ID.
|
|
230
|
-
*
|
|
231
|
-
* @param realm
|
|
232
|
-
*/
|
|
233
|
-
getRoles(realm?: string): Role[];
|
|
234
|
-
/**
|
|
235
|
-
* Returns all permissions.
|
|
236
|
-
*
|
|
237
|
-
* @param user - Filter permissions by user.
|
|
238
|
-
*
|
|
239
|
-
* @return An array containing all permissions.
|
|
240
|
-
*/
|
|
241
|
-
getPermissions(user?: {
|
|
242
|
-
roles?: Array<Role | string>;
|
|
243
|
-
realm?: string;
|
|
244
|
-
}): Permission[];
|
|
245
|
-
/**
|
|
246
|
-
* Retrieves the user ID from the provided payload object.
|
|
247
|
-
*
|
|
248
|
-
* @param payload - The payload object from which to extract the user ID.
|
|
249
|
-
* @return The user ID as a string.
|
|
250
|
-
*/
|
|
251
|
-
getIdFromPayload(payload: Record<string, any>): string;
|
|
252
|
-
getSessionIdFromPayload(payload: Record<string, any>): string | undefined;
|
|
253
|
-
/**
|
|
254
|
-
* Retrieves the roles from the provided payload object.
|
|
255
|
-
* @param payload - The payload object from which to extract the roles.
|
|
256
|
-
* @return An array of role strings.
|
|
257
|
-
*/
|
|
258
|
-
getRolesFromPayload(payload: Record<string, any>): string[];
|
|
259
|
-
getPictureFromPayload(payload: Record<string, any>): string | undefined;
|
|
260
|
-
getUsernameFromPayload(payload: Record<string, any>): string | undefined;
|
|
261
|
-
getEmailFromPayload(payload: Record<string, any>): string | undefined;
|
|
262
|
-
/**
|
|
263
|
-
* Returns the name from the given payload.
|
|
264
|
-
*
|
|
265
|
-
* @param payload - The payload object.
|
|
266
|
-
* @returns The name extracted from the payload, or an empty string if the payload is falsy or no name is found.
|
|
267
|
-
*/
|
|
268
|
-
getNameFromPayload(payload: Record<string, any>): string;
|
|
269
|
-
getOrganizationsFromPayload(payload: Record<string, any>): string[] | undefined;
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* A realm definition.
|
|
273
|
-
*/
|
|
274
|
-
interface Realm {
|
|
275
|
-
name: string;
|
|
276
|
-
roles: Role[];
|
|
277
|
-
/**
|
|
278
|
-
* The secret key for the realm.
|
|
279
|
-
*
|
|
280
|
-
* Can be also a JWKS URL.
|
|
281
|
-
*/
|
|
282
|
-
secret?: string | JSONWebKeySet | (() => string);
|
|
283
|
-
/**
|
|
284
|
-
* Create the user account info based on the raw JWT payload.
|
|
285
|
-
* By default, SecurityProvider has his own implementation, but this method allow to override it.
|
|
286
|
-
*/
|
|
287
|
-
profile?: (raw: Record<string, any>) => UserAccount;
|
|
288
|
-
}
|
|
289
|
-
interface SecurityCheckResult {
|
|
290
|
-
isAuthorized: boolean;
|
|
291
|
-
ownership: string | boolean | undefined;
|
|
292
|
-
}
|
|
293
|
-
//#endregion
|
|
294
|
-
//#region src/security/descriptors/$permission.d.ts
|
|
295
|
-
/**
|
|
296
|
-
* Create a new permission.
|
|
297
|
-
*/
|
|
298
|
-
declare const $permission: {
|
|
299
|
-
(options?: PermissionDescriptorOptions): PermissionDescriptor;
|
|
300
|
-
[KIND]: typeof PermissionDescriptor;
|
|
301
|
-
};
|
|
302
|
-
interface PermissionDescriptorOptions {
|
|
303
|
-
/**
|
|
304
|
-
* Name of the permission. Use Property name is not provided.
|
|
305
|
-
*/
|
|
306
|
-
name?: string;
|
|
307
|
-
/**
|
|
308
|
-
* Group of the permission. Use Class name is not provided.
|
|
309
|
-
*/
|
|
310
|
-
group?: string;
|
|
311
|
-
/**
|
|
312
|
-
* Describe the permission.
|
|
313
|
-
*/
|
|
314
|
-
description?: string;
|
|
315
|
-
}
|
|
316
|
-
declare class PermissionDescriptor extends Descriptor<PermissionDescriptorOptions> {
|
|
317
|
-
protected readonly securityProvider: SecurityProvider;
|
|
318
|
-
get name(): string;
|
|
319
|
-
get group(): string;
|
|
320
|
-
toString(): string;
|
|
321
|
-
protected onInit(): void;
|
|
322
|
-
/**
|
|
323
|
-
* Check if the user has the permission.
|
|
324
|
-
*/
|
|
325
|
-
can(user: UserAccount): boolean;
|
|
326
|
-
}
|
|
327
|
-
//#endregion
|
|
328
|
-
//#region src/security/descriptors/$realm.d.ts
|
|
329
|
-
/**
|
|
330
|
-
* Create a new realm.
|
|
331
|
-
*/
|
|
332
|
-
declare const $realm: {
|
|
333
|
-
(options: RealmDescriptorOptions): RealmDescriptor;
|
|
334
|
-
[KIND]: typeof RealmDescriptor;
|
|
335
|
-
};
|
|
336
|
-
type RealmDescriptorOptions = {
|
|
337
|
-
/**
|
|
338
|
-
* Define the realm name.
|
|
339
|
-
* If not provided, it will use the property key.
|
|
340
|
-
*/
|
|
341
|
-
name?: string;
|
|
342
|
-
/**
|
|
343
|
-
* Short description about the realm.
|
|
344
|
-
*/
|
|
345
|
-
description?: string;
|
|
346
|
-
/**
|
|
347
|
-
* All roles available in the realm. Role is a string (role name) or a Role object (embedded role).
|
|
348
|
-
*/
|
|
349
|
-
roles?: Array<string | Role>;
|
|
350
|
-
/**
|
|
351
|
-
* Realm settings.
|
|
352
|
-
*/
|
|
353
|
-
settings?: RealmSettings;
|
|
354
|
-
/**
|
|
355
|
-
* Parse the JWT payload to create a user account info.
|
|
356
|
-
*/
|
|
357
|
-
profile?: (jwtPayload: Record<string, any>) => UserAccount;
|
|
358
|
-
} & (RealmInternal | RealmExternal);
|
|
359
|
-
interface RealmSettings {
|
|
360
|
-
accessToken?: {
|
|
361
|
-
/**
|
|
362
|
-
* Lifetime of the access token.
|
|
363
|
-
* @default 15 minutes
|
|
364
|
-
*/
|
|
365
|
-
expiration?: DurationLike;
|
|
366
|
-
};
|
|
367
|
-
refreshToken?: {
|
|
368
|
-
/**
|
|
369
|
-
* Lifetime of the refresh token.
|
|
370
|
-
* @default 30 days
|
|
371
|
-
*/
|
|
372
|
-
expiration?: DurationLike;
|
|
373
|
-
};
|
|
374
|
-
onCreateSession?: (user: UserAccount, config: {
|
|
375
|
-
expiresIn: number;
|
|
376
|
-
}) => Promise<{
|
|
377
|
-
refreshToken: string;
|
|
378
|
-
sessionId?: string;
|
|
379
|
-
}>;
|
|
380
|
-
onRefreshSession?: (refreshToken: string) => Promise<{
|
|
381
|
-
user: UserAccount;
|
|
382
|
-
expiresIn: number;
|
|
383
|
-
sessionId?: string;
|
|
384
|
-
}>;
|
|
385
|
-
onDeleteSession?: (refreshToken: string) => Promise<void>;
|
|
386
|
-
}
|
|
387
|
-
type RealmInternal = {
|
|
388
|
-
/**
|
|
389
|
-
* Internal secret to sign JWT tokens and verify them.
|
|
390
|
-
*/
|
|
391
|
-
secret: string;
|
|
392
|
-
};
|
|
393
|
-
interface RealmExternal {
|
|
394
|
-
/**
|
|
395
|
-
* URL to the JWKS (JSON Web Key Set) to verify JWT tokens from external providers.
|
|
396
|
-
*/
|
|
397
|
-
jwks: (() => string) | JSONWebKeySet;
|
|
398
|
-
}
|
|
399
|
-
declare class RealmDescriptor extends Descriptor<RealmDescriptorOptions> {
|
|
400
|
-
protected readonly securityProvider: SecurityProvider;
|
|
401
|
-
protected readonly dateTimeProvider: DateTimeProvider;
|
|
402
|
-
protected readonly jwt: JwtProvider;
|
|
403
|
-
protected readonly log: alepha_logger1.Logger;
|
|
404
|
-
get name(): string;
|
|
405
|
-
get accessTokenExpiration(): Duration;
|
|
406
|
-
get refreshTokenExpiration(): Duration;
|
|
407
|
-
protected onInit(): void;
|
|
408
|
-
/**
|
|
409
|
-
* Get all roles in the realm.
|
|
410
|
-
*/
|
|
411
|
-
getRoles(): Role[];
|
|
412
|
-
/**
|
|
413
|
-
* Set all roles in the realm.
|
|
414
|
-
*/
|
|
415
|
-
setRoles(roles: Role[]): Promise<void>;
|
|
416
|
-
/**
|
|
417
|
-
* Get a role by name, throws an error if not found.
|
|
418
|
-
*/
|
|
419
|
-
getRoleByName(name: string): Role;
|
|
420
|
-
parseToken(token: string): Promise<JWTPayload>;
|
|
421
|
-
/**
|
|
422
|
-
* Create a token for the subject.
|
|
423
|
-
*/
|
|
424
|
-
createToken(user: UserAccount, refreshToken?: {
|
|
425
|
-
sid?: string;
|
|
426
|
-
refresh_token?: string;
|
|
427
|
-
refresh_token_expires_in?: number;
|
|
428
|
-
}): Promise<AccessTokenResponse>;
|
|
429
|
-
refreshToken(refreshToken: string, accessToken?: string): Promise<{
|
|
430
|
-
tokens: AccessTokenResponse;
|
|
431
|
-
user: UserAccount;
|
|
432
|
-
}>;
|
|
433
|
-
}
|
|
434
|
-
interface CreateTokenOptions {
|
|
435
|
-
sub: string;
|
|
436
|
-
roles?: string[];
|
|
437
|
-
email?: string;
|
|
438
|
-
}
|
|
439
|
-
interface AccessTokenResponse {
|
|
440
|
-
access_token: string;
|
|
441
|
-
token_type: string;
|
|
442
|
-
expires_in?: number;
|
|
443
|
-
issued_at: number;
|
|
444
|
-
refresh_token?: string;
|
|
445
|
-
refresh_token_expires_in?: number;
|
|
446
|
-
scope?: string;
|
|
447
|
-
}
|
|
448
|
-
//#endregion
|
|
449
|
-
//#region src/security/descriptors/$role.d.ts
|
|
450
|
-
/**
|
|
451
|
-
* Create a new role.
|
|
452
|
-
*/
|
|
453
|
-
declare const $role: {
|
|
454
|
-
(options?: RoleDescriptorOptions): RoleDescriptor;
|
|
455
|
-
[KIND]: typeof RoleDescriptor;
|
|
456
|
-
};
|
|
457
|
-
interface RoleDescriptorOptions {
|
|
458
|
-
/**
|
|
459
|
-
* Name of the role.
|
|
460
|
-
*/
|
|
461
|
-
name?: string;
|
|
462
|
-
/**
|
|
463
|
-
* Describe the role.
|
|
464
|
-
*/
|
|
465
|
-
description?: string;
|
|
466
|
-
realm?: string | RealmDescriptor;
|
|
467
|
-
permissions?: Array<string | {
|
|
468
|
-
name: string;
|
|
469
|
-
ownership?: boolean;
|
|
470
|
-
exclude?: string[];
|
|
471
|
-
}>;
|
|
472
|
-
}
|
|
473
|
-
declare class RoleDescriptor extends Descriptor<RoleDescriptorOptions> {
|
|
474
|
-
protected readonly securityProvider: SecurityProvider;
|
|
475
|
-
get name(): string;
|
|
476
|
-
protected onInit(): void;
|
|
477
|
-
/**
|
|
478
|
-
* Get the realm of the role.
|
|
479
|
-
*/
|
|
480
|
-
get realm(): string | RealmDescriptor | undefined;
|
|
481
|
-
can(permission: string | PermissionDescriptor): boolean;
|
|
482
|
-
check(permission: string | PermissionDescriptor): SecurityCheckResult;
|
|
483
|
-
}
|
|
484
|
-
//#endregion
|
|
485
|
-
//#region src/security/descriptors/$serviceAccount.d.ts
|
|
486
|
-
/**
|
|
487
|
-
* Allow to get an access token for a service account.
|
|
488
|
-
*
|
|
489
|
-
* You have some options to configure the service account:
|
|
490
|
-
* - a OAUTH2 URL using client credentials grant type
|
|
491
|
-
* - a JWT secret shared between the services
|
|
492
|
-
*
|
|
493
|
-
* @example
|
|
494
|
-
* ```ts
|
|
495
|
-
* import { $serviceAccount } from "alepha/security";
|
|
496
|
-
*
|
|
497
|
-
* class MyService {
|
|
498
|
-
* serviceAccount = $serviceAccount({
|
|
499
|
-
* oauth2: {
|
|
500
|
-
* url: "https://example.com/oauth2/token",
|
|
501
|
-
* clientId: "your-client-id",
|
|
502
|
-
* clientSecret: "your-client-secret",
|
|
503
|
-
* }
|
|
504
|
-
* });
|
|
505
|
-
*
|
|
506
|
-
* async fetchData() {
|
|
507
|
-
* const token = await this.serviceAccount.token();
|
|
508
|
-
* // or
|
|
509
|
-
* const response = await this.serviceAccount.fetch("https://api.example.com/data");
|
|
510
|
-
* }
|
|
511
|
-
* }
|
|
512
|
-
* ```
|
|
513
|
-
*/
|
|
514
|
-
declare const $serviceAccount: (options: ServiceAccountDescriptorOptions) => ServiceAccountDescriptor;
|
|
515
|
-
type ServiceAccountDescriptorOptions = {
|
|
516
|
-
gracePeriod?: number;
|
|
517
|
-
} & ({
|
|
518
|
-
oauth2: Oauth2ServiceAccountDescriptorOptions;
|
|
519
|
-
} | {
|
|
520
|
-
realm: RealmDescriptor;
|
|
521
|
-
user: UserAccount;
|
|
522
|
-
});
|
|
523
|
-
interface Oauth2ServiceAccountDescriptorOptions {
|
|
524
|
-
/**
|
|
525
|
-
* Get Token URL.
|
|
526
|
-
*/
|
|
527
|
-
url: string;
|
|
528
|
-
/**
|
|
529
|
-
* Client ID.
|
|
530
|
-
*/
|
|
531
|
-
clientId: string;
|
|
532
|
-
/**
|
|
533
|
-
* Client Secret.
|
|
534
|
-
*/
|
|
535
|
-
clientSecret: string;
|
|
536
|
-
}
|
|
537
|
-
interface ServiceAccountDescriptor {
|
|
538
|
-
token: () => Promise<string>;
|
|
539
|
-
}
|
|
540
|
-
interface ServiceAccountStore {
|
|
541
|
-
response?: AccessTokenResponse;
|
|
542
|
-
}
|
|
543
|
-
//#endregion
|
|
544
|
-
//#region src/security/errors/InvalidCredentialsError.d.ts
|
|
545
|
-
/**
|
|
546
|
-
* Error thrown when the provided credentials are invalid.
|
|
547
|
-
*
|
|
548
|
-
* Message can not be changed to avoid leaking information.
|
|
549
|
-
* Cause is omitted for the same reason.
|
|
550
|
-
*/
|
|
551
|
-
declare class InvalidCredentialsError extends UnauthorizedError {
|
|
552
|
-
readonly name = "UnauthorizedError";
|
|
553
|
-
constructor();
|
|
554
|
-
}
|
|
555
|
-
//#endregion
|
|
556
|
-
//#region src/security/errors/InvalidPermissionError.d.ts
|
|
557
|
-
declare class InvalidPermissionError extends Error {
|
|
558
|
-
constructor(name: string);
|
|
559
|
-
}
|
|
560
|
-
//#endregion
|
|
561
|
-
//#region src/security/errors/SecurityError.d.ts
|
|
562
|
-
declare class SecurityError extends Error {
|
|
563
|
-
name: string;
|
|
564
|
-
readonly status = 403;
|
|
565
|
-
}
|
|
566
|
-
//#endregion
|
|
567
|
-
//#region src/security/providers/CryptoProvider.d.ts
|
|
568
|
-
declare class CryptoProvider {
|
|
569
|
-
hashPassword(password: string): Promise<string>;
|
|
570
|
-
verifyPassword(password: string, stored: string): Promise<boolean>;
|
|
571
|
-
randomUUID(): string;
|
|
572
|
-
}
|
|
573
|
-
//#endregion
|
|
574
|
-
//#region src/security/index.d.ts
|
|
575
|
-
declare module "alepha" {
|
|
576
|
-
interface Hooks {
|
|
577
|
-
"security:user:created": {
|
|
578
|
-
realm: string;
|
|
579
|
-
user: UserAccount;
|
|
580
|
-
};
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
/**
|
|
584
|
-
* Provides comprehensive authentication and authorization capabilities with JWT tokens, role-based access control, and user management.
|
|
585
|
-
*
|
|
586
|
-
* The security module enables building secure applications using descriptors like `$realm`, `$role`, and `$permission`
|
|
587
|
-
* on class properties. It offers JWT-based authentication, fine-grained permissions, service accounts, and seamless
|
|
588
|
-
* integration with various authentication providers and user management systems.
|
|
589
|
-
*
|
|
590
|
-
* @see {@link $realm}
|
|
591
|
-
* @see {@link $role}
|
|
592
|
-
* @see {@link $permission}
|
|
593
|
-
* @module alepha.security
|
|
594
|
-
*/
|
|
595
|
-
declare const AlephaSecurity: alepha28.Service<alepha28.Module>;
|
|
596
|
-
//#endregion
|
|
597
|
-
export { $permission, $realm, $role, $serviceAccount, AccessTokenResponse, AlephaSecurity, CreateTokenOptions, CryptoProvider, DEFAULT_APP_SECRET, ExtendedJWTPayload, InvalidCredentialsError, InvalidPermissionError, JwtParseResult, JwtProvider, JwtSignOptions, KeyLoader, KeyLoaderHolder, Oauth2ServiceAccountDescriptorOptions, Permission, PermissionDescriptor, PermissionDescriptorOptions, Realm, RealmDescriptor, RealmDescriptorOptions, RealmExternal, RealmInternal, RealmSettings, Role, RoleDescriptor, RoleDescriptorOptions, SecurityCheckResult, SecurityError, SecurityProvider, ServiceAccountDescriptor, ServiceAccountDescriptorOptions, ServiceAccountStore, UserAccount, UserAccountToken, permissionSchema, roleSchema, userAccountInfoSchema };
|
|
598
|
-
//# sourceMappingURL=index.d.cts.map
|