alepha 0.7.5 → 0.7.7

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