alepha 0.9.2 → 0.9.4
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 +46 -0
- package/batch.d.ts +5 -8
- package/bucket.d.ts +9 -16
- package/cache/redis.d.ts +10 -10
- package/cache.d.ts +3 -7
- package/command.d.ts +19 -17
- package/core.d.ts +188 -340
- package/datetime.d.ts +6 -10
- package/file.d.ts +0 -3
- package/lock/redis.d.ts +3 -6
- package/lock.d.ts +9 -16
- package/{testing.cjs → logger.cjs} +1 -1
- package/logger.d.ts +222 -0
- package/logger.js +1 -0
- package/package.json +50 -49
- package/postgres.d.ts +273 -315
- package/queue/redis.d.ts +1 -3
- package/queue.d.ts +11 -19
- package/react/auth.d.ts +453 -146
- package/react/form.d.ts +119 -69
- package/react/head.d.ts +49 -18
- package/react/i18n.d.ts +61 -27
- package/react.d.ts +304 -212
- package/redis.d.ts +15 -15
- package/retry.d.ts +0 -4
- package/router.d.ts +0 -1
- package/scheduler.d.ts +6 -10
- package/security.d.ts +140 -138
- package/server/cache.d.ts +11 -11
- package/server/compress.d.ts +1 -4
- package/server/cookies.d.ts +45 -19
- package/server/cors.d.ts +4 -8
- package/server/health.d.ts +1 -4
- package/server/helmet.d.ts +28 -28
- package/server/links.d.ts +147 -45
- package/server/metrics.d.ts +5 -9
- package/server/multipart.d.ts +1 -3
- package/server/proxy.d.ts +5 -9
- package/server/security.d.ts +12 -15
- package/server/static.d.ts +6 -10
- package/server/swagger.d.ts +4 -8
- package/server.d.ts +75 -91
- package/topic/redis.d.ts +5 -8
- package/topic.d.ts +4 -12
- package/vite.d.ts +59 -30
- package/testing.d.ts +0 -1
- package/testing.js +0 -1
package/redis.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import
|
|
3
|
-
import * as
|
|
4
|
-
import { Alepha, Logger, Static, TNumber, TObject, TOptional, TString } from "alepha";
|
|
1
|
+
import * as _alepha_core1 from "alepha";
|
|
2
|
+
import { Alepha, Static, TNumber, TObject, TOptional, TString } from "alepha";
|
|
3
|
+
import * as _alepha_logger0 from "alepha/logger";
|
|
5
4
|
import { RedisClientType, SetOptions, createClient } from "@redis/client";
|
|
6
5
|
|
|
7
6
|
//#region src/providers/RedisProvider.d.ts
|
|
@@ -22,13 +21,17 @@ type RedisSetOptions = SetOptions;
|
|
|
22
21
|
* Redis client provider.
|
|
23
22
|
*/
|
|
24
23
|
declare class RedisProvider {
|
|
25
|
-
protected readonly log: Logger;
|
|
24
|
+
protected readonly log: _alepha_logger0.Logger;
|
|
26
25
|
protected readonly alepha: Alepha;
|
|
27
|
-
protected readonly env:
|
|
26
|
+
protected readonly env: {
|
|
27
|
+
REDIS_PASSWORD?: string | undefined;
|
|
28
|
+
REDIS_PORT: number;
|
|
29
|
+
REDIS_HOST: string;
|
|
30
|
+
};
|
|
28
31
|
protected readonly client: RedisClient;
|
|
29
32
|
get publisher(): RedisClient;
|
|
30
|
-
protected readonly start:
|
|
31
|
-
protected readonly stop:
|
|
33
|
+
protected readonly start: _alepha_core1.HookDescriptor<"start">;
|
|
34
|
+
protected readonly stop: _alepha_core1.HookDescriptor<"stop">;
|
|
32
35
|
/**
|
|
33
36
|
* Connect to the Redis server.
|
|
34
37
|
*/
|
|
@@ -51,13 +54,13 @@ declare class RedisProvider {
|
|
|
51
54
|
//#endregion
|
|
52
55
|
//#region src/providers/RedisSubscriberProvider.d.ts
|
|
53
56
|
declare class RedisSubscriberProvider {
|
|
54
|
-
protected readonly log: Logger;
|
|
57
|
+
protected readonly log: _alepha_logger0.Logger;
|
|
55
58
|
protected readonly alepha: Alepha;
|
|
56
59
|
protected readonly redisProvider: RedisProvider;
|
|
57
60
|
protected readonly client: RedisClient;
|
|
58
61
|
get subscriber(): RedisClient;
|
|
59
|
-
protected readonly start:
|
|
60
|
-
protected readonly stop:
|
|
62
|
+
protected readonly start: _alepha_core1.HookDescriptor<"start">;
|
|
63
|
+
protected readonly stop: _alepha_core1.HookDescriptor<"stop">;
|
|
61
64
|
connect(): Promise<void>;
|
|
62
65
|
close(): Promise<void>;
|
|
63
66
|
/**
|
|
@@ -65,7 +68,6 @@ declare class RedisSubscriberProvider {
|
|
|
65
68
|
*/
|
|
66
69
|
protected createClient(): RedisClient;
|
|
67
70
|
}
|
|
68
|
-
//# sourceMappingURL=RedisSubscriberProvider.d.ts.map
|
|
69
71
|
//#endregion
|
|
70
72
|
//#region src/index.d.ts
|
|
71
73
|
/**
|
|
@@ -74,9 +76,7 @@ declare class RedisSubscriberProvider {
|
|
|
74
76
|
* @see {@link RedisProvider}
|
|
75
77
|
* @module alepha.redis
|
|
76
78
|
*/
|
|
77
|
-
declare const AlephaRedis:
|
|
78
|
-
//# sourceMappingURL=index.d.ts.map
|
|
79
|
-
|
|
79
|
+
declare const AlephaRedis: _alepha_core1.Service<_alepha_core1.Module>;
|
|
80
80
|
//#endregion
|
|
81
81
|
export { AlephaRedis, RedisClient, RedisClientOptions, RedisProvider, RedisSetOptions, RedisSubscriberProvider };
|
|
82
82
|
//# sourceMappingURL=index.d.ts.map
|
package/retry.d.ts
CHANGED
|
@@ -84,20 +84,16 @@ interface RetryBackoffOptions {
|
|
|
84
84
|
*/
|
|
85
85
|
jitter?: boolean;
|
|
86
86
|
}
|
|
87
|
-
//# sourceMappingURL=$retry.d.ts.map
|
|
88
87
|
//#endregion
|
|
89
88
|
//#region src/errors/RetryCancelError.d.ts
|
|
90
89
|
declare class RetryCancelError extends AlephaError {
|
|
91
90
|
constructor();
|
|
92
91
|
}
|
|
93
|
-
//# sourceMappingURL=RetryCancelError.d.ts.map
|
|
94
92
|
//#endregion
|
|
95
93
|
//#region src/errors/RetryTimeoutError.d.ts
|
|
96
94
|
declare class RetryTimeoutError extends AlephaError {
|
|
97
95
|
constructor(duration: number);
|
|
98
96
|
}
|
|
99
|
-
//# sourceMappingURL=RetryTimeoutError.d.ts.map
|
|
100
|
-
|
|
101
97
|
//#endregion
|
|
102
98
|
export { $retry, RetryBackoffOptions, RetryCancelError, RetryDescriptor, RetryDescriptorFn, RetryDescriptorOptions, RetryTimeoutError };
|
|
103
99
|
//# sourceMappingURL=index.d.ts.map
|
package/router.d.ts
CHANGED
package/scheduler.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as _alepha_core4 from "alepha";
|
|
2
|
-
import * as _alepha_core0$1 from "alepha";
|
|
3
|
-
import * as _alepha_core0 from "alepha";
|
|
4
2
|
import { Alepha, Async, Descriptor, KIND, Static } from "alepha";
|
|
5
3
|
import * as _alepha_lock0 from "alepha/lock";
|
|
6
4
|
import { DateTime, DateTimeProvider, DurationLike } from "alepha/datetime";
|
|
5
|
+
import * as _alepha_logger0 from "alepha/logger";
|
|
7
6
|
import { Cron } from "cron-schedule";
|
|
8
7
|
import * as dayjs0 from "dayjs";
|
|
9
8
|
|
|
@@ -11,7 +10,7 @@ import * as dayjs0 from "dayjs";
|
|
|
11
10
|
declare class CronProvider {
|
|
12
11
|
protected readonly dt: DateTimeProvider;
|
|
13
12
|
protected readonly alepha: Alepha;
|
|
14
|
-
protected readonly log:
|
|
13
|
+
protected readonly log: _alepha_logger0.Logger;
|
|
15
14
|
protected readonly cronJobs: Array<CronJob>;
|
|
16
15
|
getCronJobs(): Array<CronJob>;
|
|
17
16
|
protected readonly start: _alepha_core4.HookDescriptor<"start">;
|
|
@@ -40,7 +39,6 @@ interface CronJob {
|
|
|
40
39
|
onError?: (error: Error) => void;
|
|
41
40
|
abort: AbortController;
|
|
42
41
|
}
|
|
43
|
-
//# sourceMappingURL=CronProvider.d.ts.map
|
|
44
42
|
//#endregion
|
|
45
43
|
//#region src/descriptors/$scheduler.d.ts
|
|
46
44
|
/**
|
|
@@ -79,14 +77,14 @@ type SchedulerDescriptorOptions = {
|
|
|
79
77
|
*/
|
|
80
78
|
lock?: boolean;
|
|
81
79
|
};
|
|
82
|
-
declare const envSchema:
|
|
83
|
-
SCHEDULER_PREFIX:
|
|
80
|
+
declare const envSchema: _alepha_core4.TObject<{
|
|
81
|
+
SCHEDULER_PREFIX: _alepha_core4.TOptional<_alepha_core4.TString>;
|
|
84
82
|
}>;
|
|
85
83
|
declare module "alepha" {
|
|
86
84
|
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
87
85
|
}
|
|
88
86
|
declare class SchedulerDescriptor extends Descriptor<SchedulerDescriptorOptions> {
|
|
89
|
-
protected readonly log:
|
|
87
|
+
protected readonly log: _alepha_logger0.Logger;
|
|
90
88
|
protected readonly env: {
|
|
91
89
|
SCHEDULER_PREFIX?: string | undefined;
|
|
92
90
|
};
|
|
@@ -111,9 +109,7 @@ interface SchedulerHandlerArguments {
|
|
|
111
109
|
* @see {@link $scheduler}
|
|
112
110
|
* @module alepha.scheduler
|
|
113
111
|
*/
|
|
114
|
-
declare const AlephaScheduler:
|
|
115
|
-
//# sourceMappingURL=index.d.ts.map
|
|
116
|
-
|
|
112
|
+
declare const AlephaScheduler: _alepha_core4.Service<_alepha_core4.Module>;
|
|
117
113
|
//#endregion
|
|
118
114
|
export { $scheduler, AlephaScheduler, SchedulerDescriptor, SchedulerDescriptorOptions, SchedulerHandlerArguments };
|
|
119
115
|
//# sourceMappingURL=index.d.ts.map
|
package/security.d.ts
CHANGED
|
@@ -1,50 +1,37 @@
|
|
|
1
|
-
import * as _alepha_core0$1 from "alepha";
|
|
2
1
|
import * as _alepha_core1 from "alepha";
|
|
3
|
-
import * as _alepha_core0 from "alepha";
|
|
4
2
|
import { Alepha, Descriptor, KIND, Static } from "alepha";
|
|
5
|
-
import
|
|
3
|
+
import * as _alepha_logger1 from "alepha/logger";
|
|
4
|
+
import { DateTimeProvider, Duration, DurationLike } from "alepha/datetime";
|
|
6
5
|
import { CryptoKey, FlattenedJWSInput, JSONWebKeySet, JWSHeaderParameters, JWTHeaderParameters, JWTPayload, JWTVerifyResult, KeyObject } from "jose";
|
|
7
6
|
import * as _sinclair_typebox13 from "@sinclair/typebox";
|
|
8
|
-
import
|
|
7
|
+
import { JWTVerifyOptions } from "jose/jwt/verify";
|
|
9
8
|
|
|
10
|
-
//#region src/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
roles?: string[];
|
|
23
|
-
/**
|
|
24
|
-
* User full name, if available.
|
|
25
|
-
*/
|
|
26
|
-
name?: string;
|
|
27
|
-
/**
|
|
28
|
-
* User email, if available.
|
|
29
|
-
*/
|
|
30
|
-
email?: string;
|
|
31
|
-
/**
|
|
32
|
-
* User profile picture URL, if available.
|
|
33
|
-
*/
|
|
34
|
-
picture?: string;
|
|
35
|
-
/**
|
|
36
|
-
* Organization ID, if available.
|
|
37
|
-
*/
|
|
38
|
-
organization?: string;
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=UserAccountInfo.d.ts.map
|
|
9
|
+
//#region src/schemas/userAccountInfoSchema.d.ts
|
|
10
|
+
declare const userAccountInfoSchema: _sinclair_typebox13.TObject<{
|
|
11
|
+
id: _sinclair_typebox13.TString;
|
|
12
|
+
name: _sinclair_typebox13.TOptional<_sinclair_typebox13.TString>;
|
|
13
|
+
email: _sinclair_typebox13.TOptional<_sinclair_typebox13.TString>;
|
|
14
|
+
username: _sinclair_typebox13.TOptional<_sinclair_typebox13.TString>;
|
|
15
|
+
picture: _sinclair_typebox13.TOptional<_sinclair_typebox13.TString>;
|
|
16
|
+
sessionId: _sinclair_typebox13.TOptional<_sinclair_typebox13.TString>;
|
|
17
|
+
organizations: _sinclair_typebox13.TOptional<_sinclair_typebox13.TArray<_sinclair_typebox13.TString>>;
|
|
18
|
+
roles: _sinclair_typebox13.TOptional<_sinclair_typebox13.TArray<_sinclair_typebox13.TString>>;
|
|
19
|
+
}>;
|
|
20
|
+
type UserAccount = Static<typeof userAccountInfoSchema>;
|
|
41
21
|
//#endregion
|
|
42
22
|
//#region src/interfaces/UserAccountToken.d.ts
|
|
43
|
-
|
|
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 {
|
|
44
28
|
/**
|
|
45
29
|
* Access token for the user.
|
|
46
30
|
*/
|
|
47
31
|
token?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Realm name of the user.
|
|
34
|
+
*/
|
|
48
35
|
realm?: string;
|
|
49
36
|
/**
|
|
50
37
|
* Is user dedicated to his own resources for this scope ?
|
|
@@ -52,7 +39,6 @@ interface UserAccountToken extends UserAccountInfo {
|
|
|
52
39
|
*/
|
|
53
40
|
ownership?: string | boolean;
|
|
54
41
|
}
|
|
55
|
-
//# sourceMappingURL=UserAccountToken.d.ts.map
|
|
56
42
|
//#endregion
|
|
57
43
|
//#region src/schemas/permissionSchema.d.ts
|
|
58
44
|
declare const permissionSchema: _sinclair_typebox13.TObject<{
|
|
@@ -63,30 +49,29 @@ declare const permissionSchema: _sinclair_typebox13.TObject<{
|
|
|
63
49
|
path: _sinclair_typebox13.TOptional<_sinclair_typebox13.TString>;
|
|
64
50
|
}>;
|
|
65
51
|
type Permission = Static<typeof permissionSchema>;
|
|
66
|
-
//# sourceMappingURL=permissionSchema.d.ts.map
|
|
67
52
|
//#endregion
|
|
68
53
|
//#region src/schemas/roleSchema.d.ts
|
|
69
|
-
declare const roleSchema:
|
|
70
|
-
name:
|
|
71
|
-
description:
|
|
72
|
-
default:
|
|
73
|
-
permissions:
|
|
74
|
-
name:
|
|
75
|
-
ownership:
|
|
76
|
-
exclude:
|
|
54
|
+
declare const roleSchema: _sinclair_typebox13.TObject<{
|
|
55
|
+
name: _sinclair_typebox13.TString;
|
|
56
|
+
description: _sinclair_typebox13.TOptional<_sinclair_typebox13.TString>;
|
|
57
|
+
default: _sinclair_typebox13.TOptional<_sinclair_typebox13.TBoolean>;
|
|
58
|
+
permissions: _sinclair_typebox13.TArray<_sinclair_typebox13.TObject<{
|
|
59
|
+
name: _sinclair_typebox13.TString;
|
|
60
|
+
ownership: _sinclair_typebox13.TOptional<_sinclair_typebox13.TBoolean>;
|
|
61
|
+
exclude: _sinclair_typebox13.TOptional<_sinclair_typebox13.TArray<_sinclair_typebox13.TString>>;
|
|
77
62
|
}>>;
|
|
78
63
|
}>;
|
|
79
64
|
type Role = Static<typeof roleSchema>;
|
|
80
|
-
//# sourceMappingURL=roleSchema.d.ts.map
|
|
81
65
|
//#endregion
|
|
82
66
|
//#region src/providers/JwtProvider.d.ts
|
|
83
67
|
/**
|
|
84
68
|
* Provides utilities for working with JSON Web Tokens (JWT).
|
|
85
69
|
*/
|
|
86
70
|
declare class JwtProvider {
|
|
87
|
-
protected readonly log:
|
|
71
|
+
protected readonly log: _alepha_logger1.Logger;
|
|
88
72
|
protected readonly keystore: KeyLoaderHolder[];
|
|
89
73
|
protected readonly dateTimeProvider: DateTimeProvider;
|
|
74
|
+
protected readonly encoder: TextEncoder;
|
|
90
75
|
/**
|
|
91
76
|
* Adds a key loader to the embedded keystore.
|
|
92
77
|
*
|
|
@@ -101,30 +86,17 @@ declare class JwtProvider {
|
|
|
101
86
|
*
|
|
102
87
|
* @return A Promise that resolves with the payload object from the token.
|
|
103
88
|
*/
|
|
104
|
-
parse(token: string): Promise<JwtParseResult>;
|
|
89
|
+
parse(token: string, keyName?: string, options?: JWTVerifyOptions): Promise<JwtParseResult>;
|
|
105
90
|
/**
|
|
106
91
|
* Creates a JWT token with the provided payload and secret key.
|
|
107
92
|
*
|
|
108
93
|
* @param payload - The payload to be encoded in the token.
|
|
109
94
|
* It should include the `realm_access` property which contains an array of roles.
|
|
110
95
|
* @param keyName - The name of the key to use when signing the token.
|
|
111
|
-
* @param signOptions - The options to use when signing the token.
|
|
112
96
|
*
|
|
113
97
|
* @returns The signed JWT token.
|
|
114
98
|
*/
|
|
115
99
|
create(payload: ExtendedJWTPayload, keyName?: string, signOptions?: JwtSignOptions): Promise<string>;
|
|
116
|
-
/**
|
|
117
|
-
* Retrieves the options to use when signing a JWT token.
|
|
118
|
-
*
|
|
119
|
-
* @returns The JWT sign options.
|
|
120
|
-
*/
|
|
121
|
-
signOptions(): JwtSignOptions;
|
|
122
|
-
/**
|
|
123
|
-
* Retrieves the first secret key from the keystore.
|
|
124
|
-
*
|
|
125
|
-
* @protected
|
|
126
|
-
*/
|
|
127
|
-
protected getFirstSecretKey(): string | undefined;
|
|
128
100
|
/**
|
|
129
101
|
* Determines if the provided key is a secret key.
|
|
130
102
|
*
|
|
@@ -132,16 +104,6 @@ declare class JwtProvider {
|
|
|
132
104
|
* @protected
|
|
133
105
|
*/
|
|
134
106
|
protected isSecretKey(key: string): boolean;
|
|
135
|
-
/**
|
|
136
|
-
* Try to find a realm name or something similar in the token.
|
|
137
|
-
*
|
|
138
|
-
* This is useful when the token is not encrypted and API has multiple realms.
|
|
139
|
-
* Instead of trying to verify the token with all keys, we can try to find the key !
|
|
140
|
-
*
|
|
141
|
-
* @param token
|
|
142
|
-
* @protected
|
|
143
|
-
*/
|
|
144
|
-
protected tryToGetKeyLoaderFromToken(token: string): KeyLoaderHolder | undefined;
|
|
145
107
|
}
|
|
146
108
|
type KeyLoader = (protectedHeader?: JWSHeaderParameters, token?: FlattenedJWSInput) => Promise<CryptoKey | KeyObject>;
|
|
147
109
|
interface KeyLoaderHolder {
|
|
@@ -150,13 +112,14 @@ interface KeyLoaderHolder {
|
|
|
150
112
|
secretKey?: string;
|
|
151
113
|
}
|
|
152
114
|
interface JwtSignOptions {
|
|
153
|
-
|
|
154
|
-
protectedHeader?: JWTHeaderParameters;
|
|
155
|
-
expiresIn?: number;
|
|
115
|
+
header?: Partial<JWTHeaderParameters>;
|
|
156
116
|
}
|
|
157
117
|
interface ExtendedJWTPayload extends JWTPayload {
|
|
118
|
+
sid?: string;
|
|
158
119
|
name?: string;
|
|
159
120
|
roles?: string[];
|
|
121
|
+
email?: string;
|
|
122
|
+
organizations?: string[];
|
|
160
123
|
realm_access?: {
|
|
161
124
|
roles: string[];
|
|
162
125
|
};
|
|
@@ -165,7 +128,6 @@ interface JwtParseResult {
|
|
|
165
128
|
keyName: string;
|
|
166
129
|
result: JWTVerifyResult<ExtendedJWTPayload>;
|
|
167
130
|
}
|
|
168
|
-
//# sourceMappingURL=JwtProvider.d.ts.map
|
|
169
131
|
//#endregion
|
|
170
132
|
//#region src/providers/SecurityProvider.d.ts
|
|
171
133
|
declare const envSchema: _alepha_core1.TObject<{
|
|
@@ -175,10 +137,10 @@ declare module "alepha" {
|
|
|
175
137
|
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
176
138
|
}
|
|
177
139
|
declare class SecurityProvider {
|
|
178
|
-
protected readonly UNKNOWN_USER_NAME = "
|
|
140
|
+
protected readonly UNKNOWN_USER_NAME = "Anonymous User";
|
|
179
141
|
protected readonly PERMISSION_REGEXP: RegExp;
|
|
180
142
|
protected readonly PERMISSION_REGEXP_WILDCARD: RegExp;
|
|
181
|
-
protected readonly log:
|
|
143
|
+
protected readonly log: _alepha_logger1.Logger;
|
|
182
144
|
protected readonly jwt: JwtProvider;
|
|
183
145
|
protected readonly env: {
|
|
184
146
|
SECURITY_SECRET_KEY: string;
|
|
@@ -192,8 +154,7 @@ declare class SecurityProvider {
|
|
|
192
154
|
* The realms configured for the security provider.
|
|
193
155
|
*/
|
|
194
156
|
protected readonly realms: Realm[];
|
|
195
|
-
protected configure: _alepha_core1.HookDescriptor<"
|
|
196
|
-
protected ready: _alepha_core1.HookDescriptor<"ready">;
|
|
157
|
+
protected configure: _alepha_core1.HookDescriptor<"start">;
|
|
197
158
|
/**
|
|
198
159
|
* Adds a role to one or more realms.
|
|
199
160
|
*
|
|
@@ -225,7 +186,7 @@ declare class SecurityProvider {
|
|
|
225
186
|
*
|
|
226
187
|
* @returns The user info created from the payload.
|
|
227
188
|
*/
|
|
228
|
-
|
|
189
|
+
createUserFromPayload(payload: JWTPayload, realmName?: string): UserAccount;
|
|
229
190
|
/**
|
|
230
191
|
* Checks if the user has the specified permission.
|
|
231
192
|
*
|
|
@@ -241,7 +202,11 @@ declare class SecurityProvider {
|
|
|
241
202
|
* @param headerOrToken
|
|
242
203
|
* @param permissionLike
|
|
243
204
|
*/
|
|
244
|
-
createUserFromToken(headerOrToken?: string,
|
|
205
|
+
createUserFromToken(headerOrToken?: string, options?: {
|
|
206
|
+
permission?: Permission | string;
|
|
207
|
+
realm?: string;
|
|
208
|
+
verify?: JWTVerifyOptions;
|
|
209
|
+
}): Promise<UserAccountToken>;
|
|
245
210
|
/**
|
|
246
211
|
* Checks if a user has a specific role.
|
|
247
212
|
*
|
|
@@ -285,6 +250,7 @@ declare class SecurityProvider {
|
|
|
285
250
|
* @return The user ID as a string.
|
|
286
251
|
*/
|
|
287
252
|
getIdFromPayload(payload: Record<string, any>): string;
|
|
253
|
+
getSessionIdFromPayload(payload: Record<string, any>): string | undefined;
|
|
288
254
|
/**
|
|
289
255
|
* Retrieves the roles from the provided payload object.
|
|
290
256
|
* @param payload - The payload object from which to extract the roles.
|
|
@@ -292,6 +258,7 @@ declare class SecurityProvider {
|
|
|
292
258
|
*/
|
|
293
259
|
getRolesFromPayload(payload: Record<string, any>): string[];
|
|
294
260
|
getPictureFromPayload(payload: Record<string, any>): string | undefined;
|
|
261
|
+
getUsernameFromPayload(payload: Record<string, any>): string | undefined;
|
|
295
262
|
getEmailFromPayload(payload: Record<string, any>): string | undefined;
|
|
296
263
|
/**
|
|
297
264
|
* Returns the name from the given payload.
|
|
@@ -300,7 +267,7 @@ declare class SecurityProvider {
|
|
|
300
267
|
* @returns The name extracted from the payload, or an empty string if the payload is falsy or no name is found.
|
|
301
268
|
*/
|
|
302
269
|
getNameFromPayload(payload: Record<string, any>): string;
|
|
303
|
-
|
|
270
|
+
getOrganizationsFromPayload(payload: Record<string, any>): string[] | undefined;
|
|
304
271
|
}
|
|
305
272
|
/**
|
|
306
273
|
* A realm definition.
|
|
@@ -313,29 +280,17 @@ interface Realm {
|
|
|
313
280
|
*
|
|
314
281
|
* Can be also a JWKS URL.
|
|
315
282
|
*/
|
|
316
|
-
secret?: string | JSONWebKeySet;
|
|
283
|
+
secret?: string | JSONWebKeySet | (() => string);
|
|
317
284
|
/**
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
* This is useful when you want to use a custom user provider for a specific realm.
|
|
285
|
+
* Create the user account info based on the raw JWT payload.
|
|
286
|
+
* By default, SecurityProvider has his own implementation, but this method allow to override it.
|
|
321
287
|
*/
|
|
322
|
-
|
|
323
|
-
onLoadUser?: (user: UserAccountInfo) => Promise<void> | void;
|
|
324
|
-
}
|
|
325
|
-
interface SecurityUserAccountProvider {
|
|
326
|
-
jwks: string | undefined;
|
|
327
|
-
synchronize(config: RealmConfig): Promise<void>;
|
|
288
|
+
profile?: (raw: Record<string, any>) => UserAccount;
|
|
328
289
|
}
|
|
329
290
|
interface SecurityCheckResult {
|
|
330
291
|
isAuthorized: boolean;
|
|
331
292
|
ownership: string | boolean | undefined;
|
|
332
293
|
}
|
|
333
|
-
interface RealmConfig {
|
|
334
|
-
roles?: Array<Role>;
|
|
335
|
-
smtp?: {
|
|
336
|
-
host?: string;
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
294
|
//#endregion
|
|
340
295
|
//#region src/descriptors/$permission.d.ts
|
|
341
296
|
/**
|
|
@@ -367,50 +322,85 @@ declare class PermissionDescriptor extends Descriptor<PermissionDescriptorOption
|
|
|
367
322
|
/**
|
|
368
323
|
* Check if the user has the permission.
|
|
369
324
|
*/
|
|
370
|
-
can(user:
|
|
325
|
+
can(user: UserAccount): boolean;
|
|
371
326
|
}
|
|
372
|
-
//# sourceMappingURL=$permission.d.ts.map
|
|
373
327
|
//#endregion
|
|
374
328
|
//#region src/descriptors/$realm.d.ts
|
|
375
329
|
/**
|
|
376
330
|
* Create a new realm.
|
|
377
331
|
*/
|
|
378
332
|
declare const $realm: {
|
|
379
|
-
(options
|
|
333
|
+
(options: RealmDescriptorOptions): RealmDescriptor;
|
|
380
334
|
[KIND]: typeof RealmDescriptor;
|
|
381
335
|
};
|
|
382
|
-
|
|
336
|
+
type RealmDescriptorOptions = {
|
|
383
337
|
/**
|
|
384
338
|
* Define the realm name.
|
|
385
|
-
*
|
|
386
|
-
* @default key name
|
|
339
|
+
* If not provided, it will use the property key.
|
|
387
340
|
*/
|
|
388
341
|
name?: string;
|
|
389
342
|
/**
|
|
390
|
-
*
|
|
343
|
+
* Short description about the realm.
|
|
391
344
|
*/
|
|
392
345
|
description?: string;
|
|
393
346
|
/**
|
|
394
347
|
* All roles available in the realm. Role is a string (role name) or a Role object (embedded role).
|
|
395
348
|
*/
|
|
396
349
|
roles?: Array<string | Role>;
|
|
350
|
+
settings?: RealmSettings;
|
|
351
|
+
/**
|
|
352
|
+
* Parse the JWT payload to create a user account info.
|
|
353
|
+
*/
|
|
354
|
+
profile?: (jwtPayload: Record<string, any>) => UserAccount;
|
|
355
|
+
} & (RealmInternal | RealmExternal);
|
|
356
|
+
interface RealmSettings {
|
|
357
|
+
accessToken?: {
|
|
358
|
+
/**
|
|
359
|
+
* Lifetime of the access token.
|
|
360
|
+
* @default 15 minutes
|
|
361
|
+
*/
|
|
362
|
+
expiration?: DurationLike;
|
|
363
|
+
};
|
|
364
|
+
refreshToken?: {
|
|
365
|
+
/**
|
|
366
|
+
* Lifetime of the refresh token.
|
|
367
|
+
* @default 30 days
|
|
368
|
+
*/
|
|
369
|
+
expiration?: DurationLike;
|
|
370
|
+
};
|
|
371
|
+
onCreateSession?: (user: UserAccount, config: {
|
|
372
|
+
expiresIn: number;
|
|
373
|
+
}) => Promise<{
|
|
374
|
+
refreshToken: string;
|
|
375
|
+
sessionId?: string;
|
|
376
|
+
}>;
|
|
377
|
+
onRefreshSession?: (refreshToken: string) => Promise<{
|
|
378
|
+
user: UserAccount;
|
|
379
|
+
expiresIn: number;
|
|
380
|
+
sessionId?: string;
|
|
381
|
+
}>;
|
|
382
|
+
onDeleteSession?: (refreshToken: string) => Promise<void>;
|
|
383
|
+
}
|
|
384
|
+
type RealmInternal = {
|
|
397
385
|
/**
|
|
398
|
-
*
|
|
399
|
-
* Can be a string based secret or a JWKS URL.
|
|
400
|
-
*
|
|
401
|
-
* Note: You can skip this if you are using a user account provider with JWKS.
|
|
386
|
+
* Internal secret to sign JWT tokens and verify them.
|
|
402
387
|
*/
|
|
403
|
-
secret
|
|
388
|
+
secret: string;
|
|
389
|
+
};
|
|
390
|
+
interface RealmExternal {
|
|
404
391
|
/**
|
|
405
|
-
*
|
|
406
|
-
* For example, you can use a KeycloakUserProvider to automatically create realm roles inside Keycloak.
|
|
392
|
+
* URL to the JWKS (JSON Web Key Set) to verify JWT tokens from external providers.
|
|
407
393
|
*/
|
|
408
|
-
|
|
394
|
+
jwks: (() => string) | JSONWebKeySet;
|
|
409
395
|
}
|
|
410
396
|
declare class RealmDescriptor extends Descriptor<RealmDescriptorOptions> {
|
|
411
397
|
protected readonly securityProvider: SecurityProvider;
|
|
398
|
+
protected readonly dateTimeProvider: DateTimeProvider;
|
|
412
399
|
protected readonly jwt: JwtProvider;
|
|
400
|
+
protected readonly log: _alepha_logger1.Logger;
|
|
413
401
|
get name(): string;
|
|
402
|
+
get accessTokenExpiration(): Duration;
|
|
403
|
+
get refreshTokenExpiration(): Duration;
|
|
414
404
|
protected onInit(): void;
|
|
415
405
|
/**
|
|
416
406
|
* Get all roles in the realm.
|
|
@@ -424,12 +414,34 @@ declare class RealmDescriptor extends Descriptor<RealmDescriptorOptions> {
|
|
|
424
414
|
* Get a role by name, throws an error if not found.
|
|
425
415
|
*/
|
|
426
416
|
getRoleByName(name: string): Role;
|
|
417
|
+
parseToken(token: string): Promise<JWTPayload>;
|
|
427
418
|
/**
|
|
428
419
|
* Create a token for the subject.
|
|
429
420
|
*/
|
|
430
|
-
createToken(
|
|
421
|
+
createToken(user: UserAccount, refreshToken?: {
|
|
422
|
+
sid?: string;
|
|
423
|
+
refresh_token?: string;
|
|
424
|
+
refresh_token_expires_in?: number;
|
|
425
|
+
}): Promise<AccessTokenResponse>;
|
|
426
|
+
refreshToken(refreshToken: string, accessToken?: string): Promise<{
|
|
427
|
+
tokens: AccessTokenResponse;
|
|
428
|
+
user: UserAccount;
|
|
429
|
+
}>;
|
|
430
|
+
}
|
|
431
|
+
interface CreateTokenOptions {
|
|
432
|
+
sub: string;
|
|
433
|
+
roles?: string[];
|
|
434
|
+
email?: string;
|
|
435
|
+
}
|
|
436
|
+
interface AccessTokenResponse {
|
|
437
|
+
access_token: string;
|
|
438
|
+
token_type: string;
|
|
439
|
+
expires_in?: number;
|
|
440
|
+
issued_at: number;
|
|
441
|
+
refresh_token?: string;
|
|
442
|
+
refresh_token_expires_in?: number;
|
|
443
|
+
scope?: string;
|
|
431
444
|
}
|
|
432
|
-
//# sourceMappingURL=$realm.d.ts.map
|
|
433
445
|
//#endregion
|
|
434
446
|
//#region src/descriptors/$role.d.ts
|
|
435
447
|
/**
|
|
@@ -463,7 +475,6 @@ declare class RoleDescriptor extends Descriptor<RoleDescriptorOptions> {
|
|
|
463
475
|
*/
|
|
464
476
|
get realm(): string | RealmDescriptor | undefined;
|
|
465
477
|
}
|
|
466
|
-
//# sourceMappingURL=$role.d.ts.map
|
|
467
478
|
//#endregion
|
|
468
479
|
//#region src/descriptors/$serviceAccount.d.ts
|
|
469
480
|
/**
|
|
@@ -500,13 +511,9 @@ type ServiceAccountDescriptorOptions = {
|
|
|
500
511
|
} & ({
|
|
501
512
|
oauth2: Oauth2ServiceAccountDescriptorOptions;
|
|
502
513
|
} | {
|
|
503
|
-
|
|
514
|
+
realm: RealmDescriptor;
|
|
515
|
+
user: UserAccount;
|
|
504
516
|
});
|
|
505
|
-
interface JwtServiceAccountDescriptorOptions {
|
|
506
|
-
secret: string;
|
|
507
|
-
roles?: string[];
|
|
508
|
-
signOptions?: JwtSignOptions;
|
|
509
|
-
}
|
|
510
517
|
interface Oauth2ServiceAccountDescriptorOptions {
|
|
511
518
|
/**
|
|
512
519
|
* Get Token URL.
|
|
@@ -524,36 +531,33 @@ interface Oauth2ServiceAccountDescriptorOptions {
|
|
|
524
531
|
interface ServiceAccountDescriptor {
|
|
525
532
|
token: () => Promise<string>;
|
|
526
533
|
}
|
|
527
|
-
interface AccessTokenResponse {
|
|
528
|
-
access_token: string;
|
|
529
|
-
expires_in: number;
|
|
530
|
-
at: number;
|
|
531
|
-
}
|
|
532
534
|
interface ServiceAccountStore {
|
|
533
535
|
response?: AccessTokenResponse;
|
|
534
536
|
}
|
|
535
|
-
//# sourceMappingURL=$serviceAccount.d.ts.map
|
|
536
537
|
//#endregion
|
|
537
538
|
//#region src/errors/InvalidPermissionError.d.ts
|
|
538
539
|
declare class InvalidPermissionError extends Error {
|
|
539
540
|
constructor(name: string);
|
|
540
541
|
}
|
|
541
|
-
//# sourceMappingURL=InvalidPermissionError.d.ts.map
|
|
542
542
|
//#endregion
|
|
543
543
|
//#region src/errors/SecurityError.d.ts
|
|
544
544
|
declare class SecurityError extends Error {
|
|
545
|
+
name: string;
|
|
545
546
|
readonly status = 403;
|
|
546
|
-
readonly code = "ERR_SECURITY";
|
|
547
547
|
}
|
|
548
|
-
//#
|
|
549
|
-
|
|
548
|
+
//#endregion
|
|
549
|
+
//#region src/providers/CryptoProvider.d.ts
|
|
550
|
+
declare class CryptoProvider {
|
|
551
|
+
hashPassword(password: string): Promise<string>;
|
|
552
|
+
verifyPassword(password: string, stored: string): Promise<boolean>;
|
|
553
|
+
}
|
|
550
554
|
//#endregion
|
|
551
555
|
//#region src/index.d.ts
|
|
552
556
|
declare module "alepha" {
|
|
553
557
|
interface Hooks {
|
|
554
558
|
"security:user:created": {
|
|
555
559
|
realm: string;
|
|
556
|
-
user:
|
|
560
|
+
user: UserAccount;
|
|
557
561
|
};
|
|
558
562
|
}
|
|
559
563
|
}
|
|
@@ -569,9 +573,7 @@ declare module "alepha" {
|
|
|
569
573
|
* @see {@link $permission}
|
|
570
574
|
* @module alepha.security
|
|
571
575
|
*/
|
|
572
|
-
declare const AlephaSecurity:
|
|
573
|
-
//# sourceMappingURL=index.d.ts.map
|
|
574
|
-
|
|
576
|
+
declare const AlephaSecurity: _alepha_core1.Service<_alepha_core1.Module>;
|
|
575
577
|
//#endregion
|
|
576
|
-
export { $permission, $realm, $role, $serviceAccount, AccessTokenResponse, AlephaSecurity, ExtendedJWTPayload, InvalidPermissionError, JwtParseResult, JwtProvider,
|
|
578
|
+
export { $permission, $realm, $role, $serviceAccount, AccessTokenResponse, AlephaSecurity, CreateTokenOptions, CryptoProvider, ExtendedJWTPayload, 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 };
|
|
577
579
|
//# sourceMappingURL=index.d.ts.map
|