alepha 0.8.1 → 0.9.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/README.md +47 -17
- package/batch.d.ts +83 -117
- package/bucket.cjs +8 -0
- package/bucket.d.ts +194 -0
- package/bucket.js +1 -0
- package/cache/redis.d.ts +14 -14
- package/cache.d.ts +101 -238
- package/command.d.ts +66 -71
- package/core.d.ts +1003 -851
- package/datetime.d.ts +90 -116
- package/file.d.ts +23 -13
- package/lock/redis.d.ts +11 -11
- package/lock.d.ts +121 -111
- package/package.json +54 -40
- package/postgres.d.ts +218 -393
- package/queue/redis.d.ts +13 -13
- package/queue.d.ts +84 -198
- package/react/auth.d.ts +47 -53
- package/react/head.d.ts +4 -7
- package/react.d.ts +47 -183
- package/redis.d.ts +31 -16
- package/retry.d.ts +70 -59
- package/router.d.ts +9 -9
- package/scheduler.d.ts +54 -93
- package/security.d.ts +95 -276
- package/server/cache.d.ts +22 -28
- package/server/compress.d.ts +16 -7
- package/server/cookies.d.ts +65 -233
- package/server/cors.d.ts +15 -13
- package/server/health.d.ts +23 -23
- package/server/helmet.d.ts +17 -18
- package/server/links.d.ts +108 -88
- package/server/metrics.d.ts +25 -21
- package/server/multipart.d.ts +12 -14
- package/server/proxy.d.ts +22 -17
- package/server/security.cjs +8 -0
- package/server/security.d.ts +90 -0
- package/server/security.js +1 -0
- package/server/static.d.ts +63 -67
- package/server/swagger.d.ts +73 -62
- package/server.d.ts +250 -446
- package/topic/redis.d.ts +25 -24
- package/topic.d.ts +68 -115
package/scheduler.d.ts
CHANGED
|
@@ -1,19 +1,54 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _alepha_core4 from "alepha";
|
|
2
|
+
import * as _alepha_core0$1 from "alepha";
|
|
2
3
|
import * as _alepha_core0 from "alepha";
|
|
3
|
-
import { Alepha, Async,
|
|
4
|
-
import * as
|
|
5
|
-
import { DateTime, DateTimeProvider, DurationLike
|
|
4
|
+
import { Alepha, Async, Descriptor, KIND, Static } from "alepha";
|
|
5
|
+
import * as _alepha_lock0 from "alepha/lock";
|
|
6
|
+
import { DateTime, DateTimeProvider, DurationLike } from "alepha/datetime";
|
|
6
7
|
import { Cron } from "cron-schedule";
|
|
7
|
-
import * as
|
|
8
|
+
import * as dayjs0 from "dayjs";
|
|
8
9
|
|
|
10
|
+
//#region src/providers/CronProvider.d.ts
|
|
11
|
+
declare class CronProvider {
|
|
12
|
+
protected readonly dt: DateTimeProvider;
|
|
13
|
+
protected readonly alepha: Alepha;
|
|
14
|
+
protected readonly log: _alepha_core4.Logger;
|
|
15
|
+
protected readonly cronJobs: Array<CronJob>;
|
|
16
|
+
getCronJobs(): Array<CronJob>;
|
|
17
|
+
protected readonly start: _alepha_core4.HookDescriptor<"start">;
|
|
18
|
+
protected readonly stop: _alepha_core4.HookDescriptor<"stop">;
|
|
19
|
+
protected boot(name: string | CronJob): void;
|
|
20
|
+
abort(name: string | CronJob): void;
|
|
21
|
+
/**
|
|
22
|
+
* Registers a cron job.
|
|
23
|
+
*
|
|
24
|
+
* It's automatically done when using the `$scheduler` descriptor but can also be used manually.
|
|
25
|
+
*/
|
|
26
|
+
createCronJob(name: string, expression: string, handler: (context: {
|
|
27
|
+
now: DateTime;
|
|
28
|
+
}) => Promise<void>, start?: boolean): void;
|
|
29
|
+
protected run(task: CronJob, now?: dayjs0.Dayjs): void;
|
|
30
|
+
}
|
|
31
|
+
interface CronJob {
|
|
32
|
+
name: string;
|
|
33
|
+
expression: string;
|
|
34
|
+
handler: (context: {
|
|
35
|
+
now: DateTime;
|
|
36
|
+
}) => Promise<void>;
|
|
37
|
+
cron: Cron;
|
|
38
|
+
loop: boolean;
|
|
39
|
+
running?: boolean;
|
|
40
|
+
onError?: (error: Error) => void;
|
|
41
|
+
abort: AbortController;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=CronProvider.d.ts.map
|
|
44
|
+
//#endregion
|
|
9
45
|
//#region src/descriptors/$scheduler.d.ts
|
|
10
|
-
declare const KEY = "SCHEDULER";
|
|
11
46
|
/**
|
|
12
47
|
* Scheduler descriptor.
|
|
13
48
|
*/
|
|
14
49
|
declare const $scheduler: {
|
|
15
50
|
(options: SchedulerDescriptorOptions): SchedulerDescriptor;
|
|
16
|
-
[KIND]:
|
|
51
|
+
[KIND]: typeof SchedulerDescriptor;
|
|
17
52
|
};
|
|
18
53
|
type SchedulerDescriptorOptions = {
|
|
19
54
|
/**
|
|
@@ -44,100 +79,29 @@ type SchedulerDescriptorOptions = {
|
|
|
44
79
|
*/
|
|
45
80
|
lock?: boolean;
|
|
46
81
|
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
[OPTIONS]: SchedulerDescriptorOptions;
|
|
50
|
-
(): Promise<void>;
|
|
51
|
-
}
|
|
52
|
-
interface SchedulerHandlerArguments {
|
|
53
|
-
now: DateTime;
|
|
54
|
-
}
|
|
55
|
-
//#endregion
|
|
56
|
-
//#region src/providers/CronScheduler.d.ts
|
|
57
|
-
interface CronJob {
|
|
58
|
-
handler: (context: {
|
|
59
|
-
now: DateTime;
|
|
60
|
-
}) => Promise<void>;
|
|
61
|
-
cron: Cron;
|
|
62
|
-
loop: boolean;
|
|
63
|
-
running?: boolean;
|
|
64
|
-
onError?: (error: Error) => void;
|
|
65
|
-
abort: AbortController;
|
|
66
|
-
}
|
|
67
|
-
declare class CronProvider {
|
|
68
|
-
protected readonly dt: DateTimeProvider;
|
|
69
|
-
protected readonly alepha: Alepha;
|
|
70
|
-
protected readonly log: _alepha_core9.Logger;
|
|
71
|
-
start(cron: CronJob): void;
|
|
72
|
-
stop(cron: CronJob): void;
|
|
73
|
-
create(expression: string, handler: (context: {
|
|
74
|
-
now: DateTime;
|
|
75
|
-
}) => Promise<void>): CronJob;
|
|
76
|
-
run(task: CronJob, now?: dayjs10.Dayjs): void;
|
|
77
|
-
}
|
|
78
|
-
//# sourceMappingURL=CronScheduler.d.ts.map
|
|
79
|
-
//#endregion
|
|
80
|
-
//#region src/providers/SchedulerDescriptorProvider.d.ts
|
|
81
|
-
declare const envSchema: _alepha_core0.TObject<{
|
|
82
|
-
SCHEDULER_PREFIX: _alepha_core0.TOptional<_alepha_core0.TString>;
|
|
82
|
+
declare const envSchema: _alepha_core0$1.TObject<{
|
|
83
|
+
SCHEDULER_PREFIX: _alepha_core0$1.TOptional<_alepha_core0$1.TString>;
|
|
83
84
|
}>;
|
|
84
85
|
declare module "alepha" {
|
|
85
86
|
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
86
87
|
}
|
|
87
|
-
declare class
|
|
88
|
-
protected readonly log: _alepha_core0.Logger;
|
|
88
|
+
declare class SchedulerDescriptor extends Descriptor<SchedulerDescriptorOptions> {
|
|
89
|
+
protected readonly log: _alepha_core0$1.Logger;
|
|
89
90
|
protected readonly env: {
|
|
90
91
|
SCHEDULER_PREFIX?: string | undefined;
|
|
91
92
|
};
|
|
92
93
|
protected readonly alepha: Alepha;
|
|
93
94
|
protected readonly dateTimeProvider: DateTimeProvider;
|
|
94
95
|
protected readonly cronProvider: CronProvider;
|
|
95
|
-
|
|
96
|
-
protected
|
|
97
|
-
|
|
98
|
-
protected
|
|
99
|
-
/**
|
|
100
|
-
* Get the schedulers.
|
|
101
|
-
*/
|
|
102
|
-
getSchedulers(): Scheduler[];
|
|
103
|
-
/**
|
|
104
|
-
* Process scheduler descriptors.
|
|
105
|
-
*
|
|
106
|
-
* @protected
|
|
107
|
-
*/
|
|
108
|
-
protected processSchedulerDescriptors(): void;
|
|
109
|
-
/**
|
|
110
|
-
* Create a scheduler.
|
|
111
|
-
*
|
|
112
|
-
* @param options - The scheduler options.
|
|
113
|
-
* @param instance - The instance of the scheduler.
|
|
114
|
-
* @param key - Property key name.
|
|
115
|
-
* @protected
|
|
116
|
-
*/
|
|
117
|
-
protected createScheduler(options: SchedulerDescriptorOptions, instance: any, key: string): Scheduler;
|
|
118
|
-
protected createHandler(name: string, options: SchedulerDescriptorOptions): (args: SchedulerHandlerArguments) => Promise<void>;
|
|
119
|
-
trigger(name: string): Promise<void>;
|
|
120
|
-
protected runLock: _alepha_lock8.LockDescriptor<(options: SchedulerDescriptorOptions & {
|
|
121
|
-
name: string;
|
|
122
|
-
args: SchedulerHandlerArguments;
|
|
123
|
-
}) => Promise<void>>;
|
|
124
|
-
/**
|
|
125
|
-
* Prefix the scheduler key.
|
|
126
|
-
*/
|
|
96
|
+
get name(): string;
|
|
97
|
+
protected onInit(): void;
|
|
98
|
+
trigger(): Promise<void>;
|
|
99
|
+
protected schedulerLock: _alepha_lock0.LockDescriptor<(args: SchedulerHandlerArguments) => Promise<void>>;
|
|
127
100
|
protected prefix(key: string): string;
|
|
128
|
-
/**
|
|
129
|
-
*
|
|
130
|
-
* @param options
|
|
131
|
-
* @protected
|
|
132
|
-
*/
|
|
133
101
|
protected getLockGracePeriod(options: SchedulerDescriptorOptions): number;
|
|
134
102
|
}
|
|
135
|
-
interface
|
|
136
|
-
|
|
137
|
-
options: SchedulerDescriptorOptions;
|
|
138
|
-
trigger: (args: SchedulerHandlerArguments) => Promise<void>;
|
|
139
|
-
cron?: CronJob;
|
|
140
|
-
interval?: Interval;
|
|
103
|
+
interface SchedulerHandlerArguments {
|
|
104
|
+
now: DateTime;
|
|
141
105
|
}
|
|
142
106
|
//#endregion
|
|
143
107
|
//#region src/index.d.ts
|
|
@@ -147,12 +111,9 @@ interface Scheduler {
|
|
|
147
111
|
* @see {@link $scheduler}
|
|
148
112
|
* @module alepha.scheduler
|
|
149
113
|
*/
|
|
150
|
-
declare
|
|
151
|
-
readonly name = "alepha.scheduler";
|
|
152
|
-
readonly $services: (alepha: Alepha) => Alepha;
|
|
153
|
-
}
|
|
114
|
+
declare const AlephaScheduler: _alepha_core0.ModuleDescriptor;
|
|
154
115
|
//# sourceMappingURL=index.d.ts.map
|
|
155
116
|
|
|
156
117
|
//#endregion
|
|
157
|
-
export { $scheduler, AlephaScheduler,
|
|
118
|
+
export { $scheduler, AlephaScheduler, SchedulerDescriptor, SchedulerDescriptorOptions, SchedulerHandlerArguments };
|
|
158
119
|
//# sourceMappingURL=index.d.ts.map
|
package/security.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
3
|
-
import
|
|
1
|
+
import * as _alepha_core0$1 from "alepha";
|
|
2
|
+
import * as _alepha_core1 from "alepha";
|
|
3
|
+
import * as _alepha_core0 from "alepha";
|
|
4
|
+
import { Alepha, Descriptor, KIND, Static } from "alepha";
|
|
4
5
|
import { DateTimeProvider } from "alepha/datetime";
|
|
5
6
|
import { CryptoKey, FlattenedJWSInput, JSONWebKeySet, JWSHeaderParameters, JWTHeaderParameters, JWTPayload, JWTVerifyResult, KeyObject } from "jose";
|
|
6
|
-
import * as
|
|
7
|
-
import * as
|
|
7
|
+
import * as _sinclair_typebox13 from "@sinclair/typebox";
|
|
8
|
+
import * as _sinclair_typebox0 from "@sinclair/typebox";
|
|
8
9
|
|
|
9
10
|
//#region src/interfaces/UserAccountInfo.d.ts
|
|
10
11
|
/**
|
|
@@ -38,61 +39,6 @@ interface UserAccountInfo {
|
|
|
38
39
|
}
|
|
39
40
|
//# sourceMappingURL=UserAccountInfo.d.ts.map
|
|
40
41
|
//#endregion
|
|
41
|
-
//#region src/schemas/permissionSchema.d.ts
|
|
42
|
-
declare const permissionSchema: _sinclair_typebox22.TObject<{
|
|
43
|
-
name: _sinclair_typebox22.TString;
|
|
44
|
-
group: _sinclair_typebox22.TOptional<_sinclair_typebox22.TString>;
|
|
45
|
-
description: _sinclair_typebox22.TOptional<_sinclair_typebox22.TString>;
|
|
46
|
-
method: _sinclair_typebox22.TOptional<_sinclair_typebox22.TString>;
|
|
47
|
-
path: _sinclair_typebox22.TOptional<_sinclair_typebox22.TString>;
|
|
48
|
-
}>;
|
|
49
|
-
type Permission = Static<typeof permissionSchema>;
|
|
50
|
-
//# sourceMappingURL=permissionSchema.d.ts.map
|
|
51
|
-
//#endregion
|
|
52
|
-
//#region src/descriptors/$permission.d.ts
|
|
53
|
-
declare const KEY$2 = "PERMISSION";
|
|
54
|
-
/**
|
|
55
|
-
*
|
|
56
|
-
*/
|
|
57
|
-
declare const $permission: {
|
|
58
|
-
(options?: PermissionDescriptorOptions): PermissionDescriptor;
|
|
59
|
-
[KIND]: string;
|
|
60
|
-
};
|
|
61
|
-
interface PermissionDescriptorOptions {
|
|
62
|
-
/**
|
|
63
|
-
* Name of the permission. Use Property name is not provided.
|
|
64
|
-
*/
|
|
65
|
-
name?: string;
|
|
66
|
-
/**
|
|
67
|
-
* Group of the permission. Use Class name is not provided.
|
|
68
|
-
*/
|
|
69
|
-
group?: string;
|
|
70
|
-
/**
|
|
71
|
-
* Describe the permission.
|
|
72
|
-
*/
|
|
73
|
-
description?: string;
|
|
74
|
-
/**
|
|
75
|
-
* HTTP method of the permission. When available.
|
|
76
|
-
*/
|
|
77
|
-
method?: string;
|
|
78
|
-
/**
|
|
79
|
-
* URL of the permission. When available.
|
|
80
|
-
*/
|
|
81
|
-
url?: string;
|
|
82
|
-
}
|
|
83
|
-
interface PermissionDescriptor {
|
|
84
|
-
[KIND]: typeof KEY$2;
|
|
85
|
-
[OPTIONS]: PermissionDescriptorOptions;
|
|
86
|
-
/**
|
|
87
|
-
* Get the permission object.
|
|
88
|
-
*/
|
|
89
|
-
(): Permission;
|
|
90
|
-
/**
|
|
91
|
-
* Check if the user has the permission.
|
|
92
|
-
*/
|
|
93
|
-
can(user: UserAccountInfo): boolean;
|
|
94
|
-
}
|
|
95
|
-
//#endregion
|
|
96
42
|
//#region src/interfaces/UserAccountToken.d.ts
|
|
97
43
|
interface UserAccountToken extends UserAccountInfo {
|
|
98
44
|
/**
|
|
@@ -108,15 +54,26 @@ interface UserAccountToken extends UserAccountInfo {
|
|
|
108
54
|
}
|
|
109
55
|
//# sourceMappingURL=UserAccountToken.d.ts.map
|
|
110
56
|
//#endregion
|
|
57
|
+
//#region src/schemas/permissionSchema.d.ts
|
|
58
|
+
declare const permissionSchema: _sinclair_typebox13.TObject<{
|
|
59
|
+
name: _sinclair_typebox13.TString;
|
|
60
|
+
group: _sinclair_typebox13.TOptional<_sinclair_typebox13.TString>;
|
|
61
|
+
description: _sinclair_typebox13.TOptional<_sinclair_typebox13.TString>;
|
|
62
|
+
method: _sinclair_typebox13.TOptional<_sinclair_typebox13.TString>;
|
|
63
|
+
path: _sinclair_typebox13.TOptional<_sinclair_typebox13.TString>;
|
|
64
|
+
}>;
|
|
65
|
+
type Permission = Static<typeof permissionSchema>;
|
|
66
|
+
//# sourceMappingURL=permissionSchema.d.ts.map
|
|
67
|
+
//#endregion
|
|
111
68
|
//#region src/schemas/roleSchema.d.ts
|
|
112
|
-
declare const roleSchema:
|
|
113
|
-
name:
|
|
114
|
-
description:
|
|
115
|
-
default:
|
|
116
|
-
permissions:
|
|
117
|
-
name:
|
|
118
|
-
ownership:
|
|
119
|
-
exclude:
|
|
69
|
+
declare const roleSchema: _sinclair_typebox0.TObject<{
|
|
70
|
+
name: _sinclair_typebox0.TString;
|
|
71
|
+
description: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
|
|
72
|
+
default: _sinclair_typebox0.TOptional<_sinclair_typebox0.TBoolean>;
|
|
73
|
+
permissions: _sinclair_typebox0.TArray<_sinclair_typebox0.TObject<{
|
|
74
|
+
name: _sinclair_typebox0.TString;
|
|
75
|
+
ownership: _sinclair_typebox0.TOptional<_sinclair_typebox0.TBoolean>;
|
|
76
|
+
exclude: _sinclair_typebox0.TOptional<_sinclair_typebox0.TArray<_sinclair_typebox0.TString>>;
|
|
120
77
|
}>>;
|
|
121
78
|
}>;
|
|
122
79
|
type Role = Static<typeof roleSchema>;
|
|
@@ -127,7 +84,7 @@ type Role = Static<typeof roleSchema>;
|
|
|
127
84
|
* Provides utilities for working with JSON Web Tokens (JWT).
|
|
128
85
|
*/
|
|
129
86
|
declare class JwtProvider {
|
|
130
|
-
protected readonly log:
|
|
87
|
+
protected readonly log: _alepha_core0$1.Logger;
|
|
131
88
|
protected readonly keystore: KeyLoaderHolder[];
|
|
132
89
|
protected readonly dateTimeProvider: DateTimeProvider;
|
|
133
90
|
/**
|
|
@@ -211,8 +168,8 @@ interface JwtParseResult {
|
|
|
211
168
|
//# sourceMappingURL=JwtProvider.d.ts.map
|
|
212
169
|
//#endregion
|
|
213
170
|
//#region src/providers/SecurityProvider.d.ts
|
|
214
|
-
declare const envSchema:
|
|
215
|
-
SECURITY_SECRET_KEY:
|
|
171
|
+
declare const envSchema: _alepha_core1.TObject<{
|
|
172
|
+
SECURITY_SECRET_KEY: _alepha_core1.TString;
|
|
216
173
|
}>;
|
|
217
174
|
declare module "alepha" {
|
|
218
175
|
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
@@ -221,7 +178,7 @@ declare class SecurityProvider {
|
|
|
221
178
|
protected readonly UNKNOWN_USER_NAME = "Unknown User";
|
|
222
179
|
protected readonly PERMISSION_REGEXP: RegExp;
|
|
223
180
|
protected readonly PERMISSION_REGEXP_WILDCARD: RegExp;
|
|
224
|
-
protected readonly log:
|
|
181
|
+
protected readonly log: _alepha_core1.Logger;
|
|
225
182
|
protected readonly jwt: JwtProvider;
|
|
226
183
|
protected readonly env: {
|
|
227
184
|
SECURITY_SECRET_KEY: string;
|
|
@@ -235,33 +192,8 @@ declare class SecurityProvider {
|
|
|
235
192
|
* The realms configured for the security provider.
|
|
236
193
|
*/
|
|
237
194
|
protected readonly realms: Realm[];
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
*/
|
|
241
|
-
protected createRealms(): Realm[];
|
|
242
|
-
protected configure: _alepha_core16.HookDescriptor<"configure">;
|
|
243
|
-
/**
|
|
244
|
-
* Processes all $permission descriptors.
|
|
245
|
-
*/
|
|
246
|
-
protected processPermissionDescriptors(): void;
|
|
247
|
-
/**
|
|
248
|
-
* Processes all $realm descriptors.
|
|
249
|
-
*/
|
|
250
|
-
protected processRealmDescriptors(): void;
|
|
251
|
-
/**
|
|
252
|
-
* Processes all $role descriptors.
|
|
253
|
-
*/
|
|
254
|
-
protected processRoleDescriptors(): void;
|
|
255
|
-
protected ready: _alepha_core16.HookDescriptor<"ready">;
|
|
256
|
-
/**
|
|
257
|
-
* Updates the roles for a realm then synchronizes the user account provider if available.
|
|
258
|
-
*
|
|
259
|
-
* Only available when the app is started.
|
|
260
|
-
*
|
|
261
|
-
* @param realm - The realm to update the roles for.
|
|
262
|
-
* @param roles - The roles to update.
|
|
263
|
-
*/
|
|
264
|
-
updateRealm(realm: string, roles: Role[]): Promise<void>;
|
|
195
|
+
protected configure: _alepha_core1.HookDescriptor<"configure">;
|
|
196
|
+
protected ready: _alepha_core1.HookDescriptor<"ready">;
|
|
265
197
|
/**
|
|
266
198
|
* Adds a role to one or more realms.
|
|
267
199
|
*
|
|
@@ -275,6 +207,16 @@ declare class SecurityProvider {
|
|
|
275
207
|
* @param raw - The permission to add.
|
|
276
208
|
*/
|
|
277
209
|
createPermission(raw: Permission | string): Permission;
|
|
210
|
+
createRealm(realm: Realm): void;
|
|
211
|
+
/**
|
|
212
|
+
* Updates the roles for a realm then synchronizes the user account provider if available.
|
|
213
|
+
*
|
|
214
|
+
* Only available when the app is started.
|
|
215
|
+
*
|
|
216
|
+
* @param realm - The realm to update the roles for.
|
|
217
|
+
* @param roles - The roles to update.
|
|
218
|
+
*/
|
|
219
|
+
updateRealm(realm: string, roles: Role[]): Promise<void>;
|
|
278
220
|
/**
|
|
279
221
|
* Creates a user account from the provided payload.
|
|
280
222
|
*
|
|
@@ -299,7 +241,7 @@ declare class SecurityProvider {
|
|
|
299
241
|
* @param headerOrToken
|
|
300
242
|
* @param permissionLike
|
|
301
243
|
*/
|
|
302
|
-
createUserFromToken(headerOrToken?: string,
|
|
244
|
+
createUserFromToken(headerOrToken?: string, permission?: Permission | string): Promise<UserAccountToken>;
|
|
303
245
|
/**
|
|
304
246
|
* Checks if a user has a specific role.
|
|
305
247
|
*
|
|
@@ -395,15 +337,47 @@ interface RealmConfig {
|
|
|
395
337
|
};
|
|
396
338
|
}
|
|
397
339
|
//#endregion
|
|
340
|
+
//#region src/descriptors/$permission.d.ts
|
|
341
|
+
/**
|
|
342
|
+
* Create a new permission.
|
|
343
|
+
*/
|
|
344
|
+
declare const $permission: {
|
|
345
|
+
(options?: PermissionDescriptorOptions): PermissionDescriptor;
|
|
346
|
+
[KIND]: typeof PermissionDescriptor;
|
|
347
|
+
};
|
|
348
|
+
interface PermissionDescriptorOptions {
|
|
349
|
+
/**
|
|
350
|
+
* Name of the permission. Use Property name is not provided.
|
|
351
|
+
*/
|
|
352
|
+
name?: string;
|
|
353
|
+
/**
|
|
354
|
+
* Group of the permission. Use Class name is not provided.
|
|
355
|
+
*/
|
|
356
|
+
group?: string;
|
|
357
|
+
/**
|
|
358
|
+
* Describe the permission.
|
|
359
|
+
*/
|
|
360
|
+
description?: string;
|
|
361
|
+
}
|
|
362
|
+
declare class PermissionDescriptor extends Descriptor<PermissionDescriptorOptions> {
|
|
363
|
+
protected readonly securityProvider: SecurityProvider;
|
|
364
|
+
get name(): string;
|
|
365
|
+
get group(): string;
|
|
366
|
+
protected onInit(): void;
|
|
367
|
+
/**
|
|
368
|
+
* Check if the user has the permission.
|
|
369
|
+
*/
|
|
370
|
+
can(user: UserAccountInfo): boolean;
|
|
371
|
+
}
|
|
372
|
+
//# sourceMappingURL=$permission.d.ts.map
|
|
373
|
+
//#endregion
|
|
398
374
|
//#region src/descriptors/$realm.d.ts
|
|
399
|
-
declare const KEY$1 = "REALM";
|
|
400
375
|
/**
|
|
401
|
-
*
|
|
402
|
-
* @param options
|
|
376
|
+
* Create a new realm.
|
|
403
377
|
*/
|
|
404
378
|
declare const $realm: {
|
|
405
379
|
(options?: RealmDescriptorOptions): RealmDescriptor;
|
|
406
|
-
[KIND]:
|
|
380
|
+
[KIND]: typeof RealmDescriptor;
|
|
407
381
|
};
|
|
408
382
|
interface RealmDescriptorOptions {
|
|
409
383
|
/**
|
|
@@ -433,9 +407,11 @@ interface RealmDescriptorOptions {
|
|
|
433
407
|
*/
|
|
434
408
|
userAccountProvider?: SecurityUserAccountProvider | (() => SecurityUserAccountProvider);
|
|
435
409
|
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
410
|
+
declare class RealmDescriptor extends Descriptor<RealmDescriptorOptions> {
|
|
411
|
+
protected readonly securityProvider: SecurityProvider;
|
|
412
|
+
protected readonly jwt: JwtProvider;
|
|
413
|
+
get name(): string;
|
|
414
|
+
protected onInit(): void;
|
|
439
415
|
/**
|
|
440
416
|
* Get all roles in the realm.
|
|
441
417
|
*/
|
|
@@ -453,15 +429,15 @@ interface RealmDescriptor {
|
|
|
453
429
|
*/
|
|
454
430
|
createToken(subject: string, roles?: string[]): Promise<string>;
|
|
455
431
|
}
|
|
432
|
+
//# sourceMappingURL=$realm.d.ts.map
|
|
456
433
|
//#endregion
|
|
457
434
|
//#region src/descriptors/$role.d.ts
|
|
458
|
-
declare const KEY = "ROLE";
|
|
459
435
|
/**
|
|
460
|
-
*
|
|
436
|
+
* Create a new role.
|
|
461
437
|
*/
|
|
462
438
|
declare const $role: {
|
|
463
439
|
(options?: RoleDescriptorOptions): RoleDescriptor;
|
|
464
|
-
[KIND]:
|
|
440
|
+
[KIND]: typeof RoleDescriptor;
|
|
465
441
|
};
|
|
466
442
|
interface RoleDescriptorOptions {
|
|
467
443
|
/**
|
|
@@ -472,19 +448,22 @@ interface RoleDescriptorOptions {
|
|
|
472
448
|
* Describe the role.
|
|
473
449
|
*/
|
|
474
450
|
description?: string;
|
|
451
|
+
realm?: string | RealmDescriptor;
|
|
475
452
|
permissions?: Array<string | {
|
|
476
453
|
name: string;
|
|
477
454
|
ownership?: boolean;
|
|
478
455
|
}>;
|
|
479
456
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
457
|
+
declare class RoleDescriptor extends Descriptor<RoleDescriptorOptions> {
|
|
458
|
+
protected readonly securityProvider: SecurityProvider;
|
|
459
|
+
get name(): string;
|
|
460
|
+
protected onInit(): void;
|
|
483
461
|
/**
|
|
484
|
-
* Get the role
|
|
462
|
+
* Get the realm of the role.
|
|
485
463
|
*/
|
|
486
|
-
():
|
|
464
|
+
get realm(): string | RealmDescriptor | undefined;
|
|
487
465
|
}
|
|
466
|
+
//# sourceMappingURL=$role.d.ts.map
|
|
488
467
|
//#endregion
|
|
489
468
|
//#region src/descriptors/$serviceAccount.d.ts
|
|
490
469
|
/**
|
|
@@ -585,172 +564,12 @@ declare module "alepha" {
|
|
|
585
564
|
* on class properties. It offers JWT-based authentication, fine-grained permissions, service accounts, and seamless
|
|
586
565
|
* integration with various authentication providers and user management systems.
|
|
587
566
|
*
|
|
588
|
-
* **Key Features:**
|
|
589
|
-
* - Declarative realm definition with `$realm` descriptor for user authentication
|
|
590
|
-
* - Role-based access control with `$role` descriptor
|
|
591
|
-
* - Fine-grained permissions with `$permission` descriptor
|
|
592
|
-
* - Service account management with `$serviceAccount` descriptor
|
|
593
|
-
* - JWT token generation and validation
|
|
594
|
-
* - OAuth integration and external provider support
|
|
595
|
-
* - User session management and security hooks
|
|
596
|
-
*
|
|
597
|
-
* **Basic Usage:**
|
|
598
|
-
* ```ts
|
|
599
|
-
* import { Alepha, run, t } from "alepha";
|
|
600
|
-
* import { AlephaSecurity, $realm, $role, $permission } from "alepha/security";
|
|
601
|
-
*
|
|
602
|
-
* // Define user roles
|
|
603
|
-
* const adminRole = $role({
|
|
604
|
-
* name: "admin",
|
|
605
|
-
* description: "Administrator with full access",
|
|
606
|
-
* });
|
|
607
|
-
*
|
|
608
|
-
* const userRole = $role({
|
|
609
|
-
* name: "user",
|
|
610
|
-
* description: "Regular user with limited access",
|
|
611
|
-
* });
|
|
612
|
-
*
|
|
613
|
-
* // Define permissions
|
|
614
|
-
* const readUsersPermission = $permission({
|
|
615
|
-
* name: "users:read",
|
|
616
|
-
* description: "Read user information",
|
|
617
|
-
* });
|
|
618
|
-
*
|
|
619
|
-
* const writeUsersPermission = $permission({
|
|
620
|
-
* name: "users:write",
|
|
621
|
-
* description: "Create and update users",
|
|
622
|
-
* });
|
|
623
|
-
*
|
|
624
|
-
* // Define authentication realm
|
|
625
|
-
* class AuthSystem {
|
|
626
|
-
* userRealm = $realm({
|
|
627
|
-
* name: "users",
|
|
628
|
-
* roles: [adminRole, userRole],
|
|
629
|
-
* permissions: [readUsersPermission, writeUsersPermission],
|
|
630
|
-
* authenticate: async (token: string) => {
|
|
631
|
-
* // Validate user token and return user info
|
|
632
|
-
* const user = await validateUserToken(token);
|
|
633
|
-
* return {
|
|
634
|
-
* id: user.id,
|
|
635
|
-
* email: user.email,
|
|
636
|
-
* roles: user.roles,
|
|
637
|
-
* permissions: user.permissions,
|
|
638
|
-
* };
|
|
639
|
-
* },
|
|
640
|
-
* });
|
|
641
|
-
* }
|
|
642
|
-
*
|
|
643
|
-
* const alepha = Alepha.create()
|
|
644
|
-
* .with(AlephaSecurity)
|
|
645
|
-
* .with(AuthSystem);
|
|
646
|
-
*
|
|
647
|
-
* run(alepha);
|
|
648
|
-
* ```
|
|
649
|
-
*
|
|
650
|
-
* **OAuth Integration:**
|
|
651
|
-
* ```ts
|
|
652
|
-
* import { $serviceAccount } from "alepha/security";
|
|
653
|
-
*
|
|
654
|
-
* class OAuthSystem {
|
|
655
|
-
* googleAuth = $realm({
|
|
656
|
-
* name: "google-oauth",
|
|
657
|
-
* provider: "oauth",
|
|
658
|
-
* config: {
|
|
659
|
-
* clientId: process.env.GOOGLE_CLIENT_ID,
|
|
660
|
-
* clientSecret: process.env.GOOGLE_CLIENT_SECRET,
|
|
661
|
-
* redirectUri: "https://myapp.com/auth/callback",
|
|
662
|
-
* scope: ["email", "profile"],
|
|
663
|
-
* },
|
|
664
|
-
* authenticate: async (oauthToken: string) => {
|
|
665
|
-
* const userInfo = await fetchGoogleUserInfo(oauthToken);
|
|
666
|
-
* return {
|
|
667
|
-
* id: userInfo.sub,
|
|
668
|
-
* email: userInfo.email,
|
|
669
|
-
* name: userInfo.name,
|
|
670
|
-
* roles: ["user"],
|
|
671
|
-
* };
|
|
672
|
-
* },
|
|
673
|
-
* });
|
|
674
|
-
*
|
|
675
|
-
* serviceAccount = $serviceAccount({
|
|
676
|
-
* name: "api-service",
|
|
677
|
-
* permissions: ["api:read", "api:write"],
|
|
678
|
-
* secret: process.env.SERVICE_ACCOUNT_SECRET,
|
|
679
|
-
* });
|
|
680
|
-
* }
|
|
681
|
-
* ```
|
|
682
|
-
*
|
|
683
|
-
* **Role and Permission Management:**
|
|
684
|
-
* ```ts
|
|
685
|
-
* class PermissionSystem {
|
|
686
|
-
* // Define hierarchical roles
|
|
687
|
-
* superAdminRole = $role({
|
|
688
|
-
* name: "super-admin",
|
|
689
|
-
* inherits: [adminRole],
|
|
690
|
-
* permissions: ["*"], // All permissions
|
|
691
|
-
* });
|
|
692
|
-
*
|
|
693
|
-
* moderatorRole = $role({
|
|
694
|
-
* name: "moderator",
|
|
695
|
-
* inherits: [userRole],
|
|
696
|
-
* permissions: ["posts:moderate", "comments:moderate"],
|
|
697
|
-
* });
|
|
698
|
-
*
|
|
699
|
-
* // Define resource-specific permissions
|
|
700
|
-
* postPermissions = [
|
|
701
|
-
* $permission({ name: "posts:create", description: "Create posts" }),
|
|
702
|
-
* $permission({ name: "posts:edit", description: "Edit posts" }),
|
|
703
|
-
* $permission({ name: "posts:delete", description: "Delete posts" }),
|
|
704
|
-
* $permission({ name: "posts:moderate", description: "Moderate posts" }),
|
|
705
|
-
* ];
|
|
706
|
-
*
|
|
707
|
-
* // Check permissions in application logic
|
|
708
|
-
* async checkUserPermission(userId: string, permission: string) {
|
|
709
|
-
* const user = await this.userRealm.getUser(userId);
|
|
710
|
-
* return user.permissions.includes(permission);
|
|
711
|
-
* }
|
|
712
|
-
* }
|
|
713
|
-
* ```
|
|
714
|
-
*
|
|
715
|
-
* **JWT Token Management:**
|
|
716
|
-
* ```ts
|
|
717
|
-
* class TokenSystem {
|
|
718
|
-
* userTokens = $realm({
|
|
719
|
-
* name: "jwt-tokens",
|
|
720
|
-
* jwtConfig: {
|
|
721
|
-
* secret: process.env.JWT_SECRET,
|
|
722
|
-
* expiresIn: "24h",
|
|
723
|
-
* issuer: "myapp.com",
|
|
724
|
-
* audience: "myapp-users",
|
|
725
|
-
* },
|
|
726
|
-
* authenticate: async (jwtToken: string) => {
|
|
727
|
-
* // JWT validation is handled automatically
|
|
728
|
-
* // Return user data from token payload
|
|
729
|
-
* return jwtToken.payload;
|
|
730
|
-
* },
|
|
731
|
-
* });
|
|
732
|
-
*
|
|
733
|
-
* async generateUserToken(user: { id: string; email: string; roles: string[] }) {
|
|
734
|
-
* return await this.userTokens.generateToken({
|
|
735
|
-
* sub: user.id,
|
|
736
|
-
* email: user.email,
|
|
737
|
-
* roles: user.roles,
|
|
738
|
-
* iat: Date.now(),
|
|
739
|
-
* });
|
|
740
|
-
* }
|
|
741
|
-
* }
|
|
742
|
-
* ```
|
|
743
|
-
*
|
|
744
567
|
* @see {@link $realm}
|
|
745
568
|
* @see {@link $role}
|
|
746
569
|
* @see {@link $permission}
|
|
747
|
-
* @see {@link $serviceAccount}
|
|
748
570
|
* @module alepha.security
|
|
749
571
|
*/
|
|
750
|
-
declare
|
|
751
|
-
readonly name = "alepha.security";
|
|
752
|
-
readonly $services: (alepha: Alepha) => Alepha;
|
|
753
|
-
}
|
|
572
|
+
declare const AlephaSecurity: _alepha_core0.ModuleDescriptor;
|
|
754
573
|
//# sourceMappingURL=index.d.ts.map
|
|
755
574
|
|
|
756
575
|
//#endregion
|