alepha 0.7.4 → 0.7.6

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.
Files changed (99) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +44 -21
  3. package/cache/redis.cjs +4 -8
  4. package/cache/redis.d.ts +30 -91
  5. package/cache/redis.js +1 -1
  6. package/cache.cjs +4 -8
  7. package/cache.d.ts +190 -259
  8. package/cache.js +1 -1
  9. package/core.cjs +4 -8
  10. package/core.d.ts +950 -925
  11. package/core.js +1 -1
  12. package/datetime.cjs +4 -8
  13. package/datetime.d.ts +151 -140
  14. package/datetime.js +1 -1
  15. package/lock/redis.cjs +7 -49
  16. package/lock/redis.d.ts +17 -14
  17. package/lock/redis.js +1 -47
  18. package/lock.cjs +4 -8
  19. package/lock.d.ts +117 -170
  20. package/lock.js +1 -1
  21. package/package.json +70 -40
  22. package/postgres.cjs +4 -8
  23. package/postgres.d.ts +1314 -4400
  24. package/postgres.js +1 -1
  25. package/queue/redis.cjs +8 -0
  26. package/queue/redis.d.ts +31 -0
  27. package/queue/redis.js +1 -0
  28. package/queue.cjs +4 -8
  29. package/queue.d.ts +162 -205
  30. package/queue.js +1 -1
  31. package/react/auth.cjs +4 -8
  32. package/react/auth.d.ts +167 -280
  33. package/react/auth.js +1 -1
  34. package/react.cjs +4 -8
  35. package/react.d.ts +530 -570
  36. package/react.js +1 -1
  37. package/redis.cjs +4 -8
  38. package/redis.d.ts +59 -132
  39. package/redis.js +1 -1
  40. package/retry.cjs +4 -8
  41. package/retry.d.ts +34 -31
  42. package/retry.js +1 -1
  43. package/scheduler.cjs +4 -8
  44. package/scheduler.d.ts +128 -155
  45. package/scheduler.js +1 -1
  46. package/security.cjs +4 -8
  47. package/security.d.ts +472 -595
  48. package/security.js +1 -1
  49. package/server/cache.cjs +4 -8
  50. package/server/cache.d.ts +73 -39
  51. package/server/cache.js +1 -1
  52. package/server/cookies.cjs +4 -8
  53. package/server/cookies.d.ts +46 -41
  54. package/server/cookies.js +1 -1
  55. package/server/static.cjs +4 -8
  56. package/server/static.d.ts +98 -95
  57. package/server/static.js +1 -1
  58. package/server/swagger.cjs +4 -8
  59. package/server/swagger.d.ts +106 -92
  60. package/server/swagger.js +1 -1
  61. package/server.cjs +4 -8
  62. package/server.d.ts +754 -1025
  63. package/server.js +1 -1
  64. package/testing.cjs +8 -0
  65. package/testing.d.ts +1 -0
  66. package/testing.js +1 -0
  67. package/topic/redis.cjs +8 -0
  68. package/topic/redis.d.ts +45 -0
  69. package/topic/redis.js +1 -0
  70. package/topic.cjs +4 -8
  71. package/topic.d.ts +171 -163
  72. package/topic.js +1 -1
  73. package/vite.cjs +4 -8
  74. package/vite.d.ts +91 -84
  75. package/vite.js +1 -1
  76. package/assets/logo.png +0 -0
  77. package/src/cache/redis.ts +0 -1
  78. package/src/cache.ts +0 -1
  79. package/src/core.ts +0 -1
  80. package/src/datetime.ts +0 -1
  81. package/src/lock/redis.ts +0 -1
  82. package/src/lock.ts +0 -1
  83. package/src/postgres.ts +0 -1
  84. package/src/queue/redis.ts +0 -1
  85. package/src/queue.ts +0 -1
  86. package/src/react/auth.ts +0 -1
  87. package/src/react.ts +0 -1
  88. package/src/redis.ts +0 -1
  89. package/src/retry.ts +0 -1
  90. package/src/scheduler.ts +0 -1
  91. package/src/security.ts +0 -1
  92. package/src/server/cache.ts +0 -1
  93. package/src/server/cookies.ts +0 -1
  94. package/src/server/static.ts +0 -1
  95. package/src/server/swagger.ts +0 -1
  96. package/src/server.ts +0 -1
  97. package/src/topic/redis.ts +0 -1
  98. package/src/topic.ts +0 -1
  99. package/src/vite.ts +0 -1
package/security.d.ts CHANGED
@@ -1,618 +1,491 @@
1
- import * as _alepha_core from '@alepha/core';
2
- import { Static as Static$1, KIND, OPTIONS, Alepha } from '@alepha/core';
3
- import { JWTHeaderParameters, JWSHeaderParameters, FlattenedJWSInput, CryptoKey, KeyObject, JSONWebKeySet, JWTVerifyResult, JWTPayload } from 'jose';
4
- import { DateTimeProvider } from '@alepha/datetime';
1
+ import * as _alepha_core7 from "@alepha/core";
2
+ import * as _alepha_core2 from "@alepha/core";
3
+ import { Alepha, KIND, OPTIONS, Static } from "@alepha/core";
4
+ import { DateTimeProvider } from "@alepha/datetime";
5
+ import { CryptoKey, FlattenedJWSInput, JSONWebKeySet, JWSHeaderParameters, JWTHeaderParameters, JWTPayload, JWTVerifyResult, KeyObject } from "jose";
6
+ import * as _sinclair_typebox8 from "@sinclair/typebox";
7
+ import * as _sinclair_typebox20 from "@sinclair/typebox";
8
+ import * as _sinclair_typebox1 from "@sinclair/typebox";
5
9
 
10
+ //#region src/interfaces/UserAccountInfo.d.ts
6
11
  /**
7
12
  * Represents a User Account extracted from JWT.
8
13
  */
9
14
  interface UserAccountInfo {
10
- /**
11
- * ID of user account. Based on JWT.sub.
12
- */
13
- id: string;
14
- /**
15
- * Represents the roles assigned to a user.
16
- */
17
- roles?: string[];
18
- /**
19
- * User full name, if available.
20
- */
21
- name?: string;
22
- /**
23
- * User email, if available.
24
- */
25
- email?: string;
26
- /**
27
- * User profile picture URL, if available.
28
- */
29
- picture?: string;
30
- /**
31
- * Organization ID, if available.
32
- */
33
- organization?: string;
34
- }
35
-
36
- /** Symbol key applied to readonly types */
37
- declare const ReadonlyKind: unique symbol;
38
- /** Symbol key applied to optional types */
39
- declare const OptionalKind: unique symbol;
40
- /** Symbol key applied to types */
41
- declare const Hint: unique symbol;
42
- /** Symbol key applied to types */
43
- declare const Kind: unique symbol;
44
-
45
- type TReadonly<T extends TSchema> = T & {
46
- [ReadonlyKind]: 'Readonly';
47
- };
48
-
49
- type StringFormatOption = 'date-time' | 'time' | 'date' | 'email' | 'idn-email' | 'hostname' | 'idn-hostname' | 'ipv4' | 'ipv6' | 'uri' | 'uri-reference' | 'iri' | 'uuid' | 'iri-reference' | 'uri-template' | 'json-pointer' | 'relative-json-pointer' | 'regex' | ({} & string);
50
- type StringContentEncodingOption = '7bit' | '8bit' | 'binary' | 'quoted-printable' | 'base64' | ({} & string);
51
- interface StringOptions extends SchemaOptions {
52
- /** The maximum string length */
53
- maxLength?: number;
54
- /** The minimum string length */
55
- minLength?: number;
56
- /** A regular expression pattern this string should match */
57
- pattern?: string;
58
- /** A format this string should match */
59
- format?: StringFormatOption;
60
- /** The content encoding for this string */
61
- contentEncoding?: StringContentEncodingOption;
62
- /** The content media type for this string */
63
- contentMediaType?: string;
64
- }
65
- interface TString extends TSchema, StringOptions {
66
- [Kind]: 'String';
67
- static: string;
68
- type: 'string';
69
- }
70
-
71
- interface TBoolean extends TSchema {
72
- [Kind]: 'Boolean';
73
- static: boolean;
74
- type: 'boolean';
75
- }
76
-
77
- type TOptional<T extends TSchema> = T & {
78
- [OptionalKind]: 'Optional';
79
- };
80
-
81
- /** Creates a static type from a TypeBox type */
82
- type Static<Type extends TSchema, Params extends unknown[] = [], Result = (Type & {
83
- params: Params;
84
- })['static']> = Result;
85
-
86
- type ReadonlyOptionalPropertyKeys<T extends TProperties> = {
87
- [K in keyof T]: T[K] extends TReadonly<TSchema> ? (T[K] extends TOptional<T[K]> ? K : never) : never;
88
- }[keyof T];
89
- type ReadonlyPropertyKeys<T extends TProperties> = {
90
- [K in keyof T]: T[K] extends TReadonly<TSchema> ? (T[K] extends TOptional<T[K]> ? never : K) : never;
91
- }[keyof T];
92
- type OptionalPropertyKeys<T extends TProperties> = {
93
- [K in keyof T]: T[K] extends TOptional<TSchema> ? (T[K] extends TReadonly<T[K]> ? never : K) : never;
94
- }[keyof T];
95
- type RequiredPropertyKeys<T extends TProperties> = keyof Omit<T, ReadonlyOptionalPropertyKeys<T> | ReadonlyPropertyKeys<T> | OptionalPropertyKeys<T>>;
96
- type ObjectStaticProperties<T extends TProperties, R extends Record<keyof any, unknown>> = Evaluate<(Readonly<Partial<Pick<R, ReadonlyOptionalPropertyKeys<T>>>> & Readonly<Pick<R, ReadonlyPropertyKeys<T>>> & Partial<Pick<R, OptionalPropertyKeys<T>>> & Required<Pick<R, RequiredPropertyKeys<T>>>)>;
97
- type ObjectStatic<T extends TProperties, P extends unknown[]> = ObjectStaticProperties<T, {
98
- [K in keyof T]: Static<T[K], P>;
15
+ /**
16
+ * ID of user account. Based on JWT.sub.
17
+ */
18
+ id: string;
19
+ /**
20
+ * Represents the roles assigned to a user.
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
+ //#endregion
41
+ //#region src/schemas/permissionSchema.d.ts
42
+ declare const permissionSchema: _sinclair_typebox8.TObject<{
43
+ name: _sinclair_typebox8.TString;
44
+ group: _sinclair_typebox8.TOptional<_sinclair_typebox8.TString>;
45
+ description: _sinclair_typebox8.TOptional<_sinclair_typebox8.TString>;
46
+ method: _sinclair_typebox8.TOptional<_sinclair_typebox8.TString>;
47
+ path: _sinclair_typebox8.TOptional<_sinclair_typebox8.TString>;
48
+ contentType: _sinclair_typebox8.TOptional<_sinclair_typebox8.TString>;
99
49
  }>;
100
- type TPropertyKey = string | number;
101
- type TProperties = Record<TPropertyKey, TSchema>;
102
- type TAdditionalProperties = undefined | TSchema | boolean;
103
- interface ObjectOptions extends SchemaOptions {
104
- /** Additional property constraints for this object */
105
- additionalProperties?: TAdditionalProperties;
106
- /** The minimum number of properties allowed on this object */
107
- minProperties?: number;
108
- /** The maximum number of properties allowed on this object */
109
- maxProperties?: number;
110
- }
111
- interface TObject<T extends TProperties = TProperties> extends TSchema, ObjectOptions {
112
- [Kind]: 'Object';
113
- static: ObjectStatic<T, this['params']>;
114
- additionalProperties?: TAdditionalProperties;
115
- type: 'object';
116
- properties: T;
117
- required?: string[];
118
- }
119
-
120
- type Evaluate<T> = T extends infer O ? {
121
- [K in keyof O]: O[K];
122
- } : never;
123
- type Ensure<T> = T extends infer U ? U : never;
124
-
125
- interface ArrayOptions extends SchemaOptions {
126
- /** The minimum number of items in this array */
127
- minItems?: number;
128
- /** The maximum number of items in this array */
129
- maxItems?: number;
130
- /** Should this schema contain unique items */
131
- uniqueItems?: boolean;
132
- /** A schema for which some elements should match */
133
- contains?: TSchema;
134
- /** A minimum number of contains schema matches */
135
- minContains?: number;
136
- /** A maximum number of contains schema matches */
137
- maxContains?: number;
138
- }
139
- type ArrayStatic<T extends TSchema, P extends unknown[]> = Ensure<Static<T, P>[]>;
140
- interface TArray<T extends TSchema = TSchema> extends TSchema, ArrayOptions {
141
- [Kind]: 'Array';
142
- static: ArrayStatic<T, this['params']>;
143
- type: 'array';
144
- items: T;
145
- }
146
-
147
- interface SchemaOptions {
148
- $schema?: string;
149
- /** Id for this schema */
150
- $id?: string;
151
- /** Title of this schema */
152
- title?: string;
153
- /** Description of this schema */
154
- description?: string;
155
- /** Default value for this schema */
156
- default?: any;
157
- /** Example values matching this schema */
158
- examples?: any;
159
- /** Optional annotation for readOnly */
160
- readOnly?: boolean;
161
- /** Optional annotation for writeOnly */
162
- writeOnly?: boolean;
163
- [prop: string]: any;
164
- }
165
- interface TKind {
166
- [Kind]: string;
167
- }
168
- interface TSchema extends TKind, SchemaOptions {
169
- [ReadonlyKind]?: string;
170
- [OptionalKind]?: string;
171
- [Hint]?: string;
172
- params: unknown[];
173
- static: unknown;
174
- }
175
-
176
- declare const permissionSchema: TObject<{
177
- name: TString;
178
- group: TOptional<TString>;
179
- description: TOptional<TString>;
180
- method: TOptional<TString>;
181
- path: TOptional<TString>;
182
- contentType: TOptional<TString>;
183
- }>;
184
- type Permission = Static$1<typeof permissionSchema>;
185
-
50
+ type Permission = Static<typeof permissionSchema>;
51
+ //#endregion
52
+ //#region src/descriptors/$permission.d.ts
186
53
  declare const KEY$2 = "PERMISSION";
187
54
  interface PermissionDescriptorOptions {
188
- /**
189
- * Name of the permission. Use Property name is not provided.
190
- */
191
- name?: string;
192
- /**
193
- * Group of the permission. Use Class name is not provided.
194
- */
195
- group?: string;
196
- /**
197
- * Describe the permission.
198
- */
199
- description?: string;
200
- /**
201
- * HTTP method of the permission. When available.
202
- */
203
- method?: string;
204
- /**
205
- * URL of the permission. When available.
206
- */
207
- url?: string;
55
+ /**
56
+ * Name of the permission. Use Property name is not provided.
57
+ */
58
+ name?: string;
59
+ /**
60
+ * Group of the permission. Use Class name is not provided.
61
+ */
62
+ group?: string;
63
+ /**
64
+ * Describe the permission.
65
+ */
66
+ description?: string;
67
+ /**
68
+ * HTTP method of the permission. When available.
69
+ */
70
+ method?: string;
71
+ /**
72
+ * URL of the permission. When available.
73
+ */
74
+ url?: string;
208
75
  }
209
76
  interface PermissionDescriptor {
210
- [KIND]: typeof KEY$2;
211
- [OPTIONS]: PermissionDescriptorOptions;
212
- /**
213
- * Get the permission object.
214
- */
215
- (): Permission;
216
- /**
217
- * Check if the user has the permission.
218
- */
219
- can(user: UserAccountInfo): boolean;
77
+ [KIND]: typeof KEY$2;
78
+ [OPTIONS]: PermissionDescriptorOptions;
79
+ /**
80
+ * Get the permission object.
81
+ */
82
+ (): Permission;
83
+ /**
84
+ * Check if the user has the permission.
85
+ */
86
+ can(user: UserAccountInfo): boolean;
220
87
  }
221
88
  declare const $permission: {
222
- (options?: PermissionDescriptorOptions): PermissionDescriptor;
223
- [KIND]: string;
89
+ (options?: PermissionDescriptorOptions): PermissionDescriptor;
90
+ [KIND]: string;
224
91
  };
225
-
92
+ //#endregion
93
+ //#region src/interfaces/UserAccountToken.d.ts
226
94
  interface UserAccountToken extends UserAccountInfo {
227
- /**
228
- * Access token for the user.
229
- */
230
- token?: string;
231
- /**
232
- *
233
- */
234
- realm?: string;
235
- /**
236
- * Is user dedicated to his own resources for this scope ?
237
- * Mostly, Admin is false and Customer is true.
238
- */
239
- ownership?: string | boolean;
240
- }
241
-
242
- declare const roleSchema: TObject<{
243
- name: TString;
244
- description: TOptional<TString>;
245
- default: TOptional<TBoolean>;
246
- permissions: TArray<TObject<{
247
- name: TString;
248
- ownership: TOptional<TBoolean>;
249
- exclude: TOptional<TArray<TString>>;
250
- }>>;
95
+ /**
96
+ * Access token for the user.
97
+ */
98
+ token?: string;
99
+ /**
100
+ *
101
+ */
102
+ realm?: string;
103
+ /**
104
+ * Is user dedicated to his own resources for this scope ?
105
+ * Mostly, Admin is false and Customer is true.
106
+ */
107
+ ownership?: string | boolean;
108
+ }
109
+ //#endregion
110
+ //#region src/schemas/roleSchema.d.ts
111
+ declare const roleSchema: _sinclair_typebox20.TObject<{
112
+ name: _sinclair_typebox20.TString;
113
+ description: _sinclair_typebox20.TOptional<_sinclair_typebox20.TString>;
114
+ default: _sinclair_typebox20.TOptional<_sinclair_typebox20.TBoolean>;
115
+ permissions: _sinclair_typebox20.TArray<_sinclair_typebox20.TObject<{
116
+ name: _sinclair_typebox20.TString;
117
+ ownership: _sinclair_typebox20.TOptional<_sinclair_typebox20.TBoolean>;
118
+ exclude: _sinclair_typebox20.TOptional<_sinclair_typebox20.TArray<_sinclair_typebox20.TString>>;
119
+ }>>;
251
120
  }>;
252
- type Role = Static$1<typeof roleSchema>;
253
-
121
+ type Role = Static<typeof roleSchema>;
122
+ //#endregion
123
+ //#region src/providers/JwtProvider.d.ts
254
124
  /**
255
125
  * Provides utilities for working with JSON Web Tokens (JWT).
256
126
  */
257
127
  declare class JwtProvider {
258
- protected readonly log: _alepha_core.Logger;
259
- protected readonly keystore: KeyLoaderHolder[];
260
- protected readonly dateTimeProvider: DateTimeProvider;
261
- /**
262
- * Adds a key loader to the embedded keystore.
263
- *
264
- * @param name
265
- * @param secretKeyOrJwks
266
- */
267
- setKeyLoader(name: string, secretKeyOrJwks: string | JSONWebKeySet): void;
268
- /**
269
- * Retrieves the payload from a JSON Web Token (JWT).
270
- *
271
- * @param token - The JWT to extract the payload from.
272
- *
273
- * @return A Promise that resolves with the payload object from the token.
274
- */
275
- parse(token: string): Promise<JwtParseResult>;
276
- /**
277
- * Creates a JWT token with the provided payload and secret key.
278
- *
279
- * @param payload - The payload to be encoded in the token.
280
- * It should include the `realm_access` property which contains an array of roles.
281
- * @param keyName - The name of the key to use when signing the token.
282
- * @param signOptions - The options to use when signing the token.
283
- *
284
- * @returns The signed JWT token.
285
- */
286
- create(payload: ExtendedJWTPayload, keyName?: string, signOptions?: JwtSignOptions): Promise<string>;
287
- /**
288
- * Retrieves the options to use when signing a JWT token.
289
- *
290
- * @returns The JWT sign options.
291
- */
292
- signOptions(): JwtSignOptions;
293
- /**
294
- * Retrieves the first secret key from the keystore.
295
- *
296
- * @protected
297
- */
298
- protected getFirstSecretKey(): string | undefined;
299
- /**
300
- * Determines if the provided key is a secret key.
301
- *
302
- * @param key
303
- * @protected
304
- */
305
- protected isSecretKey(key: string): boolean;
306
- /**
307
- * Try to find a realm name or something similar in the token.
308
- *
309
- * This is useful when the token is not encrypted and API has multiple realms.
310
- * Instead of trying to verify the token with all keys, we can try to find the key !
311
- *
312
- * @param token
313
- * @protected
314
- */
315
- protected tryToGetKeyLoaderFromToken(token: string): KeyLoaderHolder | undefined;
128
+ protected readonly log: _alepha_core7.Logger;
129
+ protected readonly keystore: KeyLoaderHolder[];
130
+ protected readonly dateTimeProvider: DateTimeProvider;
131
+ /**
132
+ * Adds a key loader to the embedded keystore.
133
+ *
134
+ * @param name
135
+ * @param secretKeyOrJwks
136
+ */
137
+ setKeyLoader(name: string, secretKeyOrJwks: string | JSONWebKeySet): void;
138
+ /**
139
+ * Retrieves the payload from a JSON Web Token (JWT).
140
+ *
141
+ * @param token - The JWT to extract the payload from.
142
+ *
143
+ * @return A Promise that resolves with the payload object from the token.
144
+ */
145
+ parse(token: string): Promise<JwtParseResult>;
146
+ /**
147
+ * Creates a JWT token with the provided payload and secret key.
148
+ *
149
+ * @param payload - The payload to be encoded in the token.
150
+ * It should include the `realm_access` property which contains an array of roles.
151
+ * @param keyName - The name of the key to use when signing the token.
152
+ * @param signOptions - The options to use when signing the token.
153
+ *
154
+ * @returns The signed JWT token.
155
+ */
156
+ create(payload: ExtendedJWTPayload, keyName?: string, signOptions?: JwtSignOptions): Promise<string>;
157
+ /**
158
+ * Retrieves the options to use when signing a JWT token.
159
+ *
160
+ * @returns The JWT sign options.
161
+ */
162
+ signOptions(): JwtSignOptions;
163
+ /**
164
+ * Retrieves the first secret key from the keystore.
165
+ *
166
+ * @protected
167
+ */
168
+ protected getFirstSecretKey(): string | undefined;
169
+ /**
170
+ * Determines if the provided key is a secret key.
171
+ *
172
+ * @param key
173
+ * @protected
174
+ */
175
+ protected isSecretKey(key: string): boolean;
176
+ /**
177
+ * Try to find a realm name or something similar in the token.
178
+ *
179
+ * This is useful when the token is not encrypted and API has multiple realms.
180
+ * Instead of trying to verify the token with all keys, we can try to find the key !
181
+ *
182
+ * @param token
183
+ * @protected
184
+ */
185
+ protected tryToGetKeyLoaderFromToken(token: string): KeyLoaderHolder | undefined;
316
186
  }
317
187
  type KeyLoader = (protectedHeader?: JWSHeaderParameters, token?: FlattenedJWSInput) => Promise<CryptoKey | KeyObject>;
318
188
  interface KeyLoaderHolder {
319
- name: string;
320
- keyLoader: KeyLoader;
321
- secretKey?: string;
189
+ name: string;
190
+ keyLoader: KeyLoader;
191
+ secretKey?: string;
322
192
  }
323
193
  interface JwtSignOptions {
324
- issuedAt?: boolean;
325
- protectedHeader?: JWTHeaderParameters;
326
- expiresIn?: number;
194
+ issuedAt?: boolean;
195
+ protectedHeader?: JWTHeaderParameters;
196
+ expiresIn?: number;
327
197
  }
328
198
  interface ExtendedJWTPayload extends JWTPayload {
329
- name?: string;
330
- roles?: string[];
331
- realm_access?: {
332
- roles: string[];
333
- };
199
+ name?: string;
200
+ roles?: string[];
201
+ realm_access?: {
202
+ roles: string[];
203
+ };
334
204
  }
335
205
  interface JwtParseResult {
336
- keyName: string;
337
- result: JWTVerifyResult<ExtendedJWTPayload>;
206
+ keyName: string;
207
+ result: JWTVerifyResult<ExtendedJWTPayload>;
338
208
  }
339
-
340
- declare const envSchema: _alepha_core.TObject<{
341
- SECURITY_SECRET_KEY: TString;
209
+ //#endregion
210
+ //#region src/providers/SecurityProvider.d.ts
211
+ declare const envSchema: _alepha_core2.TObject<{
212
+ SECURITY_SECRET_KEY: _sinclair_typebox1.TString;
342
213
  }>;
343
214
  declare module "alepha" {
344
- interface Env extends Partial<Static$1<typeof envSchema>> {
345
- }
215
+ interface Env extends Partial<Static<typeof envSchema>> {}
346
216
  }
347
217
  declare class SecurityProvider {
348
- protected readonly UNKNOWN_USER_NAME = "Unknown User";
349
- protected readonly PERMISSION_REGEXP: RegExp;
350
- protected readonly PERMISSION_REGEXP_WILDCARD: RegExp;
351
- protected readonly log: _alepha_core.Logger;
352
- protected readonly jwt: JwtProvider;
353
- protected readonly env: {
354
- SECURITY_SECRET_KEY: string;
355
- };
356
- protected readonly alepha: Alepha;
357
- /**
358
- * The permissions configured for the security provider.
359
- */
360
- protected readonly permissions: Permission[];
361
- /**
362
- * The realms configured for the security provider.
363
- */
364
- protected readonly realms: Realm[];
365
- /**
366
- * Create realms.
367
- */
368
- protected createRealms(): Realm[];
369
- protected configure: _alepha_core.HookDescriptor<"configure">;
370
- /**
371
- * Processes all $permission descriptors.
372
- */
373
- protected processPermissionDescriptors(): void;
374
- /**
375
- * Processes all $realm descriptors.
376
- */
377
- protected processRealmDescriptors(): void;
378
- /**
379
- * Processes all $role descriptors.
380
- */
381
- protected processRoleDescriptors(): void;
382
- protected ready: _alepha_core.HookDescriptor<"ready">;
383
- /**
384
- * Updates the roles for a realm then synchronizes the user account provider if available.
385
- *
386
- * Only available when the app is started.
387
- *
388
- * @param realm - The realm to update the roles for.
389
- * @param roles - The roles to update.
390
- */
391
- updateRealm(realm: string, roles: Role[]): Promise<void>;
392
- /**
393
- * Adds a role to one or more realms.
394
- *
395
- * @param role
396
- * @param realms
397
- */
398
- createRole(role: Role, ...realms: string[]): Role;
399
- /**
400
- * Adds a permission to the security provider.
401
- *
402
- * @param raw - The permission to add.
403
- */
404
- createPermission(raw: Permission | string): Permission;
405
- /**
406
- * Creates a user account from the provided payload.
407
- *
408
- * @param payload - The payload to create the user account from.
409
- * @param [realmName] - The realm containing the roles. Default is all.
410
- *
411
- * @returns The user info created from the payload.
412
- */
413
- createInfoFromPayload(payload: JWTPayload, realmName?: string): UserAccountInfo;
414
- /**
415
- * Checks if the user has the specified permission.
416
- *
417
- * Bonus: we check also if the user has "ownership" flag.
418
- *
419
- * @param permissionLike - The permission to check for.
420
- * @param roleEntries - The roles to check for the permission.
421
- */
422
- checkPermission(permissionLike: string | Permission, ...roleEntries: string[]): SecurityCheckResult;
423
- /**
424
- * Creates a user account from the provided payload.
425
- *
426
- * @param headerOrToken
427
- * @param permissionLike
428
- */
429
- createUserFromToken(headerOrToken?: string, permissionLike?: Permission | string): Promise<UserAccountToken>;
430
- /**
431
- * Checks if a user has a specific role.
432
- *
433
- * @param roleName - The role to check for.
434
- * @param permission - The permission to check for.
435
- * @returns True if the user has the role, false otherwise.
436
- */
437
- can(roleName: string, permission: string | Permission): boolean;
438
- /**
439
- * Checks if a user has ownership of a specific permission.
440
- */
441
- ownership(roleName: string, permission: string | Permission): string | boolean | undefined;
442
- /**
443
- * Converts a permission object to a string.
444
- *
445
- * @param permission
446
- */
447
- permissionToString(permission: Permission | string): string;
448
- getRealms(): Realm[];
449
- /**
450
- * Retrieves the user account from the provided user ID.
451
- *
452
- * @param realm
453
- */
454
- getRoles(realm?: string): Role[];
455
- /**
456
- * Returns all permissions.
457
- *
458
- * @param user - Filter permissions by user.
459
- *
460
- * @return An array containing all permissions.
461
- */
462
- getPermissions(user?: {
463
- roles?: Array<Role | string>;
464
- realm?: string;
465
- }): Permission[];
466
- /**
467
- * Retrieves the user ID from the provided payload object.
468
- *
469
- * @param payload - The payload object from which to extract the user ID.
470
- * @return The user ID as a string.
471
- */
472
- getIdFromPayload(payload: Record<string, any>): string;
473
- /**
474
- * Retrieves the roles from the provided payload object.
475
- * @param payload - The payload object from which to extract the roles.
476
- * @return An array of role strings.
477
- */
478
- getRolesFromPayload(payload: Record<string, any>): string[];
479
- getPictureFromPayload(payload: Record<string, any>): string | undefined;
480
- getEmailFromPayload(payload: Record<string, any>): string | undefined;
481
- /**
482
- * Returns the name from the given payload.
483
- *
484
- * @param payload - The payload object.
485
- * @returns The name extracted from the payload, or an empty string if the payload is falsy or no name is found.
486
- */
487
- getNameFromPayload(payload: Record<string, any>): string;
488
- getOrganizationFromPayload(payload: Record<string, any>): string | undefined;
218
+ protected readonly UNKNOWN_USER_NAME = "Unknown User";
219
+ protected readonly PERMISSION_REGEXP: RegExp;
220
+ protected readonly PERMISSION_REGEXP_WILDCARD: RegExp;
221
+ protected readonly log: _alepha_core2.Logger;
222
+ protected readonly jwt: JwtProvider;
223
+ protected readonly env: {
224
+ SECURITY_SECRET_KEY: string;
225
+ };
226
+ protected readonly alepha: Alepha;
227
+ /**
228
+ * The permissions configured for the security provider.
229
+ */
230
+ protected readonly permissions: Permission[];
231
+ /**
232
+ * The realms configured for the security provider.
233
+ */
234
+ protected readonly realms: Realm[];
235
+ /**
236
+ * Create realms.
237
+ */
238
+ protected createRealms(): Realm[];
239
+ protected configure: _alepha_core2.HookDescriptor<"configure">;
240
+ /**
241
+ * Processes all $permission descriptors.
242
+ */
243
+ protected processPermissionDescriptors(): void;
244
+ /**
245
+ * Processes all $realm descriptors.
246
+ */
247
+ protected processRealmDescriptors(): void;
248
+ /**
249
+ * Processes all $role descriptors.
250
+ */
251
+ protected processRoleDescriptors(): void;
252
+ protected ready: _alepha_core2.HookDescriptor<"ready">;
253
+ /**
254
+ * Updates the roles for a realm then synchronizes the user account provider if available.
255
+ *
256
+ * Only available when the app is started.
257
+ *
258
+ * @param realm - The realm to update the roles for.
259
+ * @param roles - The roles to update.
260
+ */
261
+ updateRealm(realm: string, roles: Role[]): Promise<void>;
262
+ /**
263
+ * Adds a role to one or more realms.
264
+ *
265
+ * @param role
266
+ * @param realms
267
+ */
268
+ createRole(role: Role, ...realms: string[]): Role;
269
+ /**
270
+ * Adds a permission to the security provider.
271
+ *
272
+ * @param raw - The permission to add.
273
+ */
274
+ createPermission(raw: Permission | string): Permission;
275
+ /**
276
+ * Creates a user account from the provided payload.
277
+ *
278
+ * @param payload - The payload to create the user account from.
279
+ * @param [realmName] - The realm containing the roles. Default is all.
280
+ *
281
+ * @returns The user info created from the payload.
282
+ */
283
+ createInfoFromPayload(payload: JWTPayload, realmName?: string): UserAccountInfo;
284
+ /**
285
+ * Checks if the user has the specified permission.
286
+ *
287
+ * Bonus: we check also if the user has "ownership" flag.
288
+ *
289
+ * @param permissionLike - The permission to check for.
290
+ * @param roleEntries - The roles to check for the permission.
291
+ */
292
+ checkPermission(permissionLike: string | Permission, ...roleEntries: string[]): SecurityCheckResult;
293
+ /**
294
+ * Creates a user account from the provided payload.
295
+ *
296
+ * @param headerOrToken
297
+ * @param permissionLike
298
+ */
299
+ createUserFromToken(headerOrToken?: string, permissionLike?: Permission | string): Promise<UserAccountToken>;
300
+ /**
301
+ * Checks if a user has a specific role.
302
+ *
303
+ * @param roleName - The role to check for.
304
+ * @param permission - The permission to check for.
305
+ * @returns True if the user has the role, false otherwise.
306
+ */
307
+ can(roleName: string, permission: string | Permission): boolean;
308
+ /**
309
+ * Checks if a user has ownership of a specific permission.
310
+ */
311
+ ownership(roleName: string, permission: string | Permission): string | boolean | undefined;
312
+ /**
313
+ * Converts a permission object to a string.
314
+ *
315
+ * @param permission
316
+ */
317
+ permissionToString(permission: Permission | string): string;
318
+ getRealms(): Realm[];
319
+ /**
320
+ * Retrieves the user account from the provided user ID.
321
+ *
322
+ * @param realm
323
+ */
324
+ getRoles(realm?: string): Role[];
325
+ /**
326
+ * Returns all permissions.
327
+ *
328
+ * @param user - Filter permissions by user.
329
+ *
330
+ * @return An array containing all permissions.
331
+ */
332
+ getPermissions(user?: {
333
+ roles?: Array<Role | string>;
334
+ realm?: string;
335
+ }): Permission[];
336
+ /**
337
+ * Retrieves the user ID from the provided payload object.
338
+ *
339
+ * @param payload - The payload object from which to extract the user ID.
340
+ * @return The user ID as a string.
341
+ */
342
+ getIdFromPayload(payload: Record<string, any>): string;
343
+ /**
344
+ * Retrieves the roles from the provided payload object.
345
+ * @param payload - The payload object from which to extract the roles.
346
+ * @return An array of role strings.
347
+ */
348
+ getRolesFromPayload(payload: Record<string, any>): string[];
349
+ getPictureFromPayload(payload: Record<string, any>): string | undefined;
350
+ getEmailFromPayload(payload: Record<string, any>): string | undefined;
351
+ /**
352
+ * Returns the name from the given payload.
353
+ *
354
+ * @param payload - The payload object.
355
+ * @returns The name extracted from the payload, or an empty string if the payload is falsy or no name is found.
356
+ */
357
+ getNameFromPayload(payload: Record<string, any>): string;
358
+ getOrganizationFromPayload(payload: Record<string, any>): string | undefined;
489
359
  }
490
360
  /**
491
361
  * A realm definition.
492
362
  */
493
363
  interface Realm {
494
- /**
495
- *
496
- */
497
- name: string;
498
- /**
499
- *
500
- */
501
- roles: Role[];
502
- /**
503
- * The secret key for the realm.
504
- *
505
- * Can be also a JWKS URL.
506
- */
507
- secret?: string | JSONWebKeySet;
508
- /**
509
- * Attach a user provider to the realm.
510
- *
511
- * This is useful when you want to use a custom user provider for a specific realm.
512
- */
513
- userAccountProvider?: SecurityUserAccountProvider;
514
- onLoadUser?: (user: UserAccountInfo) => Promise<void> | void;
364
+ /**
365
+ *
366
+ */
367
+ name: string;
368
+ /**
369
+ *
370
+ */
371
+ roles: Role[];
372
+ /**
373
+ * The secret key for the realm.
374
+ *
375
+ * Can be also a JWKS URL.
376
+ */
377
+ secret?: string | JSONWebKeySet;
378
+ /**
379
+ * Attach a user provider to the realm.
380
+ *
381
+ * This is useful when you want to use a custom user provider for a specific realm.
382
+ */
383
+ userAccountProvider?: SecurityUserAccountProvider;
384
+ onLoadUser?: (user: UserAccountInfo) => Promise<void> | void;
515
385
  }
516
386
  interface SecurityUserAccountProvider {
517
- jwks: string | undefined;
518
- synchronize(config: RealmConfig): Promise<void>;
387
+ jwks: string | undefined;
388
+ synchronize(config: RealmConfig): Promise<void>;
519
389
  }
520
390
  interface SecurityCheckResult {
521
- isAuthorized: boolean;
522
- ownership: string | boolean | undefined;
391
+ isAuthorized: boolean;
392
+ ownership: string | boolean | undefined;
523
393
  }
524
394
  interface RealmConfig {
525
- roles?: Array<Role>;
526
- smtp?: {
527
- host?: string;
528
- };
395
+ roles?: Array<Role>;
396
+ smtp?: {
397
+ host?: string;
398
+ };
529
399
  }
530
-
400
+ //#endregion
401
+ //#region src/descriptors/$realm.d.ts
531
402
  declare const KEY$1 = "REALM";
532
403
  interface RealmDescriptorOptions {
533
- /**
534
- * Define the realm name.
535
- *
536
- * @default key name
537
- */
538
- name?: string;
539
- /**
540
- * Describe the realm.
541
- */
542
- description?: string;
543
- /**
544
- * All roles available in the realm. Role is a string (role name) or a Role object (embedded role).
545
- */
546
- roles?: Array<string | Role>;
547
- /**
548
- * In order to verify user of the realm, a secret is required.
549
- * Can be a string based secret or a JWKS URL.
550
- *
551
- * Note: You can skip this if you are using a user account provider with JWKS.
552
- */
553
- secret?: string | JSONWebKeySet | (() => string);
554
- /**
555
- * Attach a user account provider to the realm to manage roles.
556
- * For example, you can use a KeycloakUserProvider to automatically create realm roles inside Keycloak.
557
- */
558
- userAccountProvider?: SecurityUserAccountProvider | (() => SecurityUserAccountProvider);
404
+ /**
405
+ * Define the realm name.
406
+ *
407
+ * @default key name
408
+ */
409
+ name?: string;
410
+ /**
411
+ * Describe the realm.
412
+ */
413
+ description?: string;
414
+ /**
415
+ * All roles available in the realm. Role is a string (role name) or a Role object (embedded role).
416
+ */
417
+ roles?: Array<string | Role>;
418
+ /**
419
+ * In order to verify user of the realm, a secret is required.
420
+ * Can be a string based secret or a JWKS URL.
421
+ *
422
+ * Note: You can skip this if you are using a user account provider with JWKS.
423
+ */
424
+ secret?: string | JSONWebKeySet | (() => string);
425
+ /**
426
+ * Attach a user account provider to the realm to manage roles.
427
+ * For example, you can use a KeycloakUserProvider to automatically create realm roles inside Keycloak.
428
+ */
429
+ userAccountProvider?: SecurityUserAccountProvider | (() => SecurityUserAccountProvider);
559
430
  }
560
431
  interface RealmDescriptor {
561
- [KIND]: typeof KEY$1;
562
- [OPTIONS]: RealmDescriptorOptions;
563
- /**
564
- * Get all roles in the realm.
565
- */
566
- getRoles(): Role[];
567
- /**
568
- * Set all roles in the realm.
569
- */
570
- setRoles(roles: Role[]): Promise<void>;
571
- /**
572
- * Get a role by name, throws an error if not found.
573
- */
574
- getRoleByName(name: string): Role;
575
- /**
576
- * Create a token for the subject.
577
- */
578
- createToken(subject: string, roles?: string[]): Promise<string>;
432
+ [KIND]: typeof KEY$1;
433
+ [OPTIONS]: RealmDescriptorOptions;
434
+ /**
435
+ * Get all roles in the realm.
436
+ */
437
+ getRoles(): Role[];
438
+ /**
439
+ * Set all roles in the realm.
440
+ */
441
+ setRoles(roles: Role[]): Promise<void>;
442
+ /**
443
+ * Get a role by name, throws an error if not found.
444
+ */
445
+ getRoleByName(name: string): Role;
446
+ /**
447
+ * Create a token for the subject.
448
+ */
449
+ createToken(subject: string, roles?: string[]): Promise<string>;
579
450
  }
580
451
  declare const $realm: {
581
- (options?: RealmDescriptorOptions): RealmDescriptor;
582
- [KIND]: string;
452
+ (options?: RealmDescriptorOptions): RealmDescriptor;
453
+ [KIND]: string;
583
454
  };
584
-
455
+ //#endregion
456
+ //#region src/descriptors/$role.d.ts
585
457
  declare const KEY = "ROLE";
586
458
  interface RoleDescriptorOptions {
587
- /**
588
- * Name of the role.
589
- */
590
- name?: string;
591
- /**
592
- * Describe the role.
593
- */
594
- description?: string;
595
- /**
596
- *
597
- */
598
- permissions?: Array<string | {
599
- name: string;
600
- ownership?: boolean;
601
- }>;
459
+ /**
460
+ * Name of the role.
461
+ */
462
+ name?: string;
463
+ /**
464
+ * Describe the role.
465
+ */
466
+ description?: string;
467
+ /**
468
+ *
469
+ */
470
+ permissions?: Array<string | {
471
+ name: string;
472
+ ownership?: boolean;
473
+ }>;
602
474
  }
603
475
  interface RoleDescriptor {
604
- [KIND]: typeof KEY;
605
- [OPTIONS]: RoleDescriptorOptions;
606
- /**
607
- * Get the role object.
608
- */
609
- (): Role;
476
+ [KIND]: typeof KEY;
477
+ [OPTIONS]: RoleDescriptorOptions;
478
+ /**
479
+ * Get the role object.
480
+ */
481
+ (): Role;
610
482
  }
611
483
  declare const $role: {
612
- (options?: RoleDescriptorOptions): RoleDescriptor;
613
- [KIND]: string;
484
+ (options?: RoleDescriptorOptions): RoleDescriptor;
485
+ [KIND]: string;
614
486
  };
615
-
487
+ //#endregion
488
+ //#region src/descriptors/$serviceAccount.d.ts
616
489
  /**
617
490
  * Allow to get an access token for a service account.
618
491
  *
@@ -643,63 +516,67 @@ declare const $role: {
643
516
  */
644
517
  declare const $serviceAccount: (options: ServiceAccountDescriptorOptions) => ServiceAccountDescriptor;
645
518
  type ServiceAccountDescriptorOptions = {
646
- gracePeriod?: number;
519
+ gracePeriod?: number;
647
520
  } & ({
648
- oauth2: Oauth2ServiceAccountDescriptorOptions;
521
+ oauth2: Oauth2ServiceAccountDescriptorOptions;
649
522
  } | {
650
- jwt: JwtServiceAccountDescriptorOptions;
523
+ jwt: JwtServiceAccountDescriptorOptions;
651
524
  });
652
525
  interface JwtServiceAccountDescriptorOptions {
653
- secret: string;
654
- roles?: string[];
655
- signOptions?: JwtSignOptions;
526
+ secret: string;
527
+ roles?: string[];
528
+ signOptions?: JwtSignOptions;
656
529
  }
657
530
  interface Oauth2ServiceAccountDescriptorOptions {
658
- /**
659
- * Get Token URL.
660
- */
661
- url: string;
662
- /**
663
- * Client ID.
664
- */
665
- clientId: string;
666
- /**
667
- * Client Secret.
668
- */
669
- clientSecret: string;
531
+ /**
532
+ * Get Token URL.
533
+ */
534
+ url: string;
535
+ /**
536
+ * Client ID.
537
+ */
538
+ clientId: string;
539
+ /**
540
+ * Client Secret.
541
+ */
542
+ clientSecret: string;
670
543
  }
671
544
  interface ServiceAccountDescriptor {
672
- token: () => Promise<string>;
545
+ token: () => Promise<string>;
673
546
  }
674
547
  interface AccessTokenResponse {
675
- access_token: string;
676
- expires_in: number;
677
- at: number;
548
+ access_token: string;
549
+ expires_in: number;
550
+ at: number;
678
551
  }
679
552
  interface ServiceAccountStore {
680
- response?: AccessTokenResponse;
553
+ response?: AccessTokenResponse;
681
554
  }
682
-
555
+ //#endregion
556
+ //#region src/errors/InvalidPermissionError.d.ts
683
557
  declare class InvalidPermissionError extends Error {
684
- constructor(name: string);
558
+ constructor(name: string);
685
559
  }
686
-
560
+ //#endregion
561
+ //#region src/errors/SecurityError.d.ts
687
562
  declare class SecurityError extends Error {
688
- readonly status = 403;
689
- readonly code = "ERR_SECURITY";
563
+ readonly status = 403;
564
+ readonly code = "ERR_SECURITY";
690
565
  }
691
-
566
+ //#endregion
567
+ //#region src/index.d.ts
692
568
  declare module "alepha/core" {
693
- interface Hooks {
694
- "security:user:created": {
695
- realm: string;
696
- user: UserAccountInfo;
697
- };
698
- }
569
+ interface Hooks {
570
+ "security:user:created": {
571
+ realm: string;
572
+ user: UserAccountInfo;
573
+ };
574
+ }
699
575
  }
700
576
  declare class AlephaSecurity {
701
- readonly name = "alepha.security";
702
- readonly $services: (alepha: Alepha) => Alepha;
577
+ readonly name = "alepha.security";
578
+ readonly $services: (alepha: Alepha) => Alepha;
703
579
  }
704
-
705
- export { $permission, $realm, $role, $serviceAccount, type AccessTokenResponse, AlephaSecurity, type ExtendedJWTPayload, InvalidPermissionError, type JwtParseResult, JwtProvider, type JwtServiceAccountDescriptorOptions, type JwtSignOptions, type KeyLoader, type KeyLoaderHolder, type Oauth2ServiceAccountDescriptorOptions, type Permission, type PermissionDescriptor, type PermissionDescriptorOptions, type Realm, type RealmConfig, type RealmDescriptor, type RealmDescriptorOptions, type Role, type RoleDescriptor, type RoleDescriptorOptions, type SecurityCheckResult, SecurityError, SecurityProvider, type SecurityUserAccountProvider, type ServiceAccountDescriptor, type ServiceAccountDescriptorOptions, type ServiceAccountStore, type UserAccountInfo, type UserAccountToken, permissionSchema, roleSchema };
580
+ //#endregion
581
+ export { $permission, $realm, $role, $serviceAccount, AccessTokenResponse, AlephaSecurity, ExtendedJWTPayload, InvalidPermissionError, JwtParseResult, JwtProvider, JwtServiceAccountDescriptorOptions, JwtSignOptions, KeyLoader, KeyLoaderHolder, Oauth2ServiceAccountDescriptorOptions, Permission, PermissionDescriptor, PermissionDescriptorOptions, Realm, RealmConfig, RealmDescriptor, RealmDescriptorOptions, Role, RoleDescriptor, RoleDescriptorOptions, SecurityCheckResult, SecurityError, SecurityProvider, SecurityUserAccountProvider, ServiceAccountDescriptor, ServiceAccountDescriptorOptions, ServiceAccountStore, UserAccountInfo, UserAccountToken, permissionSchema, roleSchema };
582
+ //# sourceMappingURL=index.d.ts.map