alepha 0.7.7 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +7 -34
  3. package/batch.cjs +8 -0
  4. package/batch.d.ts +147 -0
  5. package/batch.js +1 -0
  6. package/cache/redis.d.ts +13 -18
  7. package/cache.d.ts +183 -119
  8. package/command.cjs +8 -0
  9. package/command.d.ts +152 -0
  10. package/command.js +1 -0
  11. package/core.d.ts +846 -838
  12. package/datetime.d.ts +78 -78
  13. package/file.cjs +8 -0
  14. package/file.d.ts +46 -0
  15. package/file.js +1 -0
  16. package/lock/redis.d.ts +10 -12
  17. package/lock.d.ts +73 -80
  18. package/package.json +86 -34
  19. package/postgres.d.ts +348 -170
  20. package/queue/redis.d.ts +13 -13
  21. package/queue.d.ts +107 -18
  22. package/react/auth.d.ts +22 -16
  23. package/react/head.d.ts +10 -4
  24. package/react.d.ts +206 -49
  25. package/redis.d.ts +23 -27
  26. package/retry.d.ts +75 -54
  27. package/router.cjs +8 -0
  28. package/router.d.ts +45 -0
  29. package/router.js +1 -0
  30. package/scheduler.d.ts +15 -16
  31. package/security.d.ts +229 -40
  32. package/server/cache.d.ts +7 -8
  33. package/server/compress.cjs +8 -0
  34. package/server/compress.d.ts +26 -0
  35. package/server/compress.js +1 -0
  36. package/server/cookies.d.ts +249 -18
  37. package/server/cors.d.ts +7 -3
  38. package/server/health.d.ts +21 -24
  39. package/server/helmet.cjs +8 -0
  40. package/server/helmet.d.ts +70 -0
  41. package/server/helmet.js +1 -0
  42. package/server/links.d.ts +87 -93
  43. package/server/metrics.cjs +8 -0
  44. package/server/metrics.d.ts +35 -0
  45. package/server/metrics.js +1 -0
  46. package/server/multipart.cjs +8 -0
  47. package/server/multipart.d.ts +46 -0
  48. package/server/multipart.js +1 -0
  49. package/server/proxy.d.ts +11 -11
  50. package/server/static.d.ts +70 -55
  51. package/server/swagger.d.ts +55 -54
  52. package/server.d.ts +273 -123
  53. package/topic/redis.d.ts +22 -23
  54. package/topic.d.ts +26 -19
  55. package/vite.d.ts +59 -36
package/retry.d.ts CHANGED
@@ -1,71 +1,92 @@
1
- import { MaybePromise } from "@alepha/core";
1
+ import { AlephaError, MaybePromise } from "alepha";
2
+ import { DateTimeProvider, DurationLike } from "alepha/datetime";
2
3
 
3
4
  //#region src/descriptors/$retry.d.ts
4
5
 
5
6
  /**
6
- * `$retry` creates a retry descriptor.
7
- *
8
- * It will retry the given function up to `max` times with a delay of `delay` milliseconds between attempts.
9
- *
10
- * @example
11
- * ```ts
12
- * import { $retry } from "@alepha/core";
13
- *
14
- * class MyService {
15
- * fetchData = $retry({
16
- * max: 5, // maximum number of attempts
17
- * delay: 1000, // ms
18
- * when: (error) => error.message.includes("Network Error"),
19
- * handler: async (url: string) => {
20
- * const response = await fetch(url);
21
- * if (!response.ok) {
22
- * throw new Error(`Failed to fetch: ${response.statusText}`);
23
- * }
24
- * return response.json();
25
- * },
26
- * onError: (error, attempt, url) => {
27
- * // error happened, log it or handle it
28
- * console.error(`Attempt ${attempt} failed for ${url}:`, error);
29
- * },
30
- * });
31
- * }
32
- * ```
33
- */
7
+ * Creates a function that automatically retries a handler upon failure,
8
+ * with support for exponential backoff, max duration, and cancellation.
9
+ */
34
10
  declare const $retry: <T extends (...args: any[]) => any>(opts: RetryDescriptorOptions<T>) => RetryDescriptor<T>;
35
- /**
36
- * Retry Descriptor options.
37
- */
11
+ // ---------------------------------------------------------------------------------------------------------------------
12
+ // TODO: move to RetryProvider
13
+ declare const createRetryHandler: <T extends (...args: any[]) => any>(opts: RetryDescriptorOptions<T>, dateTimeProvider: DateTimeProvider, appAbortController?: AbortController) => RetryDescriptor<T>;
14
+ // ---------------------------------------------------------------------------------------------------------------------
15
+ interface RetryBackoffOptions {
16
+ /**
17
+ * Initial delay in milliseconds.
18
+ *
19
+ * @default 200
20
+ */
21
+ initial?: number;
22
+ /**
23
+ * Multiplier for each subsequent delay.
24
+ *
25
+ * @default 2
26
+ */
27
+ factor?: number;
28
+ /**
29
+ * Maximum delay in milliseconds.
30
+ */
31
+ max?: number;
32
+ /**
33
+ * If true, adds a random jitter to the delay to prevent thundering herd.
34
+ *
35
+ * @default true
36
+ */
37
+ jitter?: boolean;
38
+ }
38
39
  interface RetryDescriptorOptions<T extends (...args: any[]) => any> {
39
40
  /**
40
- * Maximum number of attempts.
41
- *
42
- * @default 3
43
- */
41
+ * The function to retry.
42
+ */
43
+ handler: T;
44
+ /**
45
+ * The maximum number of attempts.
46
+ *
47
+ * @default 3
48
+ */
44
49
  max?: number;
45
50
  /**
46
- * Delay in milliseconds.
47
- *
48
- * @default 0
49
- */
50
- delay?: number;
51
+ * The backoff strategy for delays between retries.
52
+ * Can be a fixed number (in ms) or a configuration object for exponential backoff.
53
+ *
54
+ * @default { initial: 200, factor: 2, jitter: true }
55
+ */
56
+ backoff?: number | RetryBackoffOptions;
57
+ /**
58
+ * An overall time limit for all retry attempts combined.
59
+ *
60
+ * e.g., `[5, 'seconds']`
61
+ */
62
+ maxDuration?: DurationLike;
51
63
  /**
52
- * Optional condition to determine when to retry.
53
- */
64
+ * A function that determines if a retry should be attempted based on the error.
65
+ *
66
+ * @default (error) => true (retries on any error)
67
+ */
54
68
  when?: (error: Error) => boolean;
55
69
  /**
56
- * The function to retry.
57
- */
58
- handler: T;
70
+ * A custom callback for when a retry attempt fails.
71
+ * This is called before the delay.
72
+ */
73
+ onError?: (error: Error, attempt: number, ...args: Parameters<T>) => void;
59
74
  /**
60
- * Optional error handler.
61
- *
62
- * This will be called when an error occurs.
63
- *
64
- * @default undefined
65
- */
66
- onError?: (error: Error, attempt: number, ...parameters: Parameters<T>) => void;
75
+ * An AbortSignal to allow for external cancellation of the retry loop.
76
+ */
77
+ signal?: AbortSignal;
67
78
  }
68
79
  type RetryDescriptor<T extends (...args: any[]) => any> = (...parameters: Parameters<T>) => MaybePromise<ReturnType<T>>;
69
80
  //#endregion
70
- export { $retry, RetryDescriptor, RetryDescriptorOptions };
81
+ //#region src/errors/RetryCancelError.d.ts
82
+ declare class RetryCancelError extends AlephaError {
83
+ constructor();
84
+ }
85
+ //#endregion
86
+ //#region src/errors/RetryTimeoutError.d.ts
87
+ declare class RetryTimeoutError extends AlephaError {
88
+ constructor(duration: number);
89
+ }
90
+ //#endregion
91
+ export { $retry, RetryBackoffOptions, RetryCancelError, RetryDescriptor, RetryDescriptorOptions, RetryTimeoutError, createRetryHandler };
71
92
  //# sourceMappingURL=index.d.ts.map
package/router.cjs ADDED
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+ var m = require('@alepha/router');
3
+ Object.keys(m).forEach(function (k) {
4
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
5
+ enumerable: true,
6
+ get: function () { return m[k]; }
7
+ });
8
+ });
package/router.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ //#region src/providers/RouterProvider.d.ts
2
+ declare class RouterProvider<T extends Route = Route> {
3
+ protected routePathRegex: RegExp;
4
+ protected tree: Tree<T>;
5
+ readonly routes: T[];
6
+ push(route: T): void;
7
+ match(path: string): RouteMatch<T>;
8
+ protected createRouteMatch(path: string): RouteMatch<T>;
9
+ protected mapParams(match: RouteMatch<T>): RouteMatch<T>;
10
+ protected createParts(path: string): string[];
11
+ }
12
+ interface RouteMatch<T extends Route> {
13
+ route?: T;
14
+ params?: Record<string, string>;
15
+ }
16
+ interface Route {
17
+ path: string;
18
+ /**
19
+ * Rename a param in the route.
20
+ * This is automatically filled when you have scenarios like:
21
+ * `/customers/:id` and `/customers/:userId/payments`
22
+ *
23
+ * In this case, `:id` will be renamed to `:userId` in the second route.
24
+ */
25
+ mapParams?: Record<string, string>;
26
+ }
27
+ interface Tree<T extends Route> {
28
+ route?: T;
29
+ children: {
30
+ [key: string]: Tree<T>;
31
+ };
32
+ param?: {
33
+ route?: T;
34
+ name: string;
35
+ children: {
36
+ [key: string]: Tree<T>;
37
+ };
38
+ };
39
+ wildcard?: {
40
+ route: T;
41
+ };
42
+ }
43
+ //#endregion
44
+ export { Route, RouteMatch, RouterProvider, Tree };
45
+ //# sourceMappingURL=index.d.ts.map
package/router.js ADDED
@@ -0,0 +1 @@
1
+ export * from '@alepha/router'
package/scheduler.d.ts CHANGED
@@ -1,10 +1,9 @@
1
- import * as _alepha_core9 from "@alepha/core";
2
- import * as _alepha_core2 from "@alepha/core";
3
- import { Alepha, Async, KIND, OPTIONS, Static } from "@alepha/core";
4
- import * as _alepha_lock8 from "@alepha/lock";
5
- import { DateTime, DateTimeProvider, DurationLike, Interval } from "@alepha/datetime";
1
+ import * as _alepha_core9 from "alepha";
2
+ import * as _alepha_core0 from "alepha";
3
+ import { Alepha, Async, KIND, OPTIONS, Static } from "alepha";
4
+ import * as _alepha_lock8 from "alepha/lock";
5
+ import { DateTime, DateTimeProvider, DurationLike, Interval } from "alepha/datetime";
6
6
  import { Cron } from "cron-schedule";
7
- import * as _sinclair_typebox0 from "@sinclair/typebox";
8
7
  import * as dayjs10 from "dayjs";
9
8
 
10
9
  //#region src/descriptors/$scheduler.d.ts
@@ -16,7 +15,6 @@ declare const $scheduler: {
16
15
  (options: SchedulerDescriptorOptions): SchedulerDescriptor;
17
16
  [KIND]: string;
18
17
  };
19
- declare const isScheduler: (value: any) => value is SchedulerDescriptor;
20
18
  type SchedulerDescriptorOptions = {
21
19
  /**
22
20
  * Function to run on schedule.
@@ -77,16 +75,17 @@ declare class CronProvider {
77
75
  }) => Promise<void>): CronJob;
78
76
  run(task: CronJob, now?: dayjs10.Dayjs): void;
79
77
  }
78
+ //# sourceMappingURL=CronScheduler.d.ts.map
80
79
  //#endregion
81
80
  //#region src/providers/SchedulerDescriptorProvider.d.ts
82
- declare const envSchema: _alepha_core2.TObject<{
83
- SCHEDULER_PREFIX: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
81
+ declare const envSchema: _alepha_core0.TObject<{
82
+ SCHEDULER_PREFIX: _alepha_core0.TOptional<_alepha_core0.TString>;
84
83
  }>;
85
84
  declare module "alepha" {
86
85
  interface Env extends Partial<Static<typeof envSchema>> {}
87
86
  }
88
87
  declare class SchedulerDescriptorProvider {
89
- protected readonly log: _alepha_core2.Logger;
88
+ protected readonly log: _alepha_core0.Logger;
90
89
  protected readonly env: {
91
90
  SCHEDULER_PREFIX?: string | undefined;
92
91
  };
@@ -94,9 +93,9 @@ declare class SchedulerDescriptorProvider {
94
93
  protected readonly dateTimeProvider: DateTimeProvider;
95
94
  protected readonly cronProvider: CronProvider;
96
95
  protected readonly schedulers: Scheduler[];
97
- protected readonly configure: _alepha_core2.HookDescriptor<"configure">;
98
- protected readonly start: _alepha_core2.HookDescriptor<"start">;
99
- protected readonly stop: _alepha_core2.HookDescriptor<"stop">;
96
+ protected readonly configure: _alepha_core0.HookDescriptor<"configure">;
97
+ protected readonly start: _alepha_core0.HookDescriptor<"start">;
98
+ protected readonly stop: _alepha_core0.HookDescriptor<"stop">;
100
99
  /**
101
100
  * Get the schedulers.
102
101
  */
@@ -143,8 +142,6 @@ interface Scheduler {
143
142
  //#endregion
144
143
  //#region src/index.d.ts
145
144
  /**
146
- * Alepha Scheduler Module
147
- *
148
145
  * Generic interface for scheduling tasks.
149
146
  *
150
147
  * @see {@link $scheduler}
@@ -154,6 +151,8 @@ declare class AlephaScheduler {
154
151
  readonly name = "alepha.scheduler";
155
152
  readonly $services: (alepha: Alepha) => Alepha;
156
153
  }
154
+ //# sourceMappingURL=index.d.ts.map
155
+
157
156
  //#endregion
158
- export { $scheduler, AlephaScheduler, Scheduler, SchedulerDescriptor, SchedulerDescriptorOptions, SchedulerDescriptorProvider, SchedulerHandlerArguments, isScheduler };
157
+ export { $scheduler, AlephaScheduler, Scheduler, SchedulerDescriptor, SchedulerDescriptorOptions, SchedulerDescriptorProvider, SchedulerHandlerArguments };
159
158
  //# sourceMappingURL=index.d.ts.map
package/security.d.ts CHANGED
@@ -1,10 +1,9 @@
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";
1
+ import * as _alepha_core15 from "alepha";
2
+ import * as _alepha_core16 from "alepha";
3
+ import { Alepha, KIND, OPTIONS, Static } from "alepha";
4
+ import { DateTimeProvider } from "alepha/datetime";
5
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";
6
+ import * as _sinclair_typebox22 from "@sinclair/typebox";
8
7
  import * as _sinclair_typebox1 from "@sinclair/typebox";
9
8
 
10
9
  //#region src/interfaces/UserAccountInfo.d.ts
@@ -37,19 +36,28 @@ interface UserAccountInfo {
37
36
  */
38
37
  organization?: string;
39
38
  }
39
+ //# sourceMappingURL=UserAccountInfo.d.ts.map
40
40
  //#endregion
41
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>;
42
+ declare const permissionSchema: _sinclair_typebox22.TObject<{
43
+ name: _sinclair_typebox22.TString;
44
+ group: _sinclair_typebox22.TOptional<_sinclair_typebox22.TString>;
45
+ description: _sinclair_typebox22.TOptional<_sinclair_typebox22.TString>;
46
+ method: _sinclair_typebox22.TOptional<_sinclair_typebox22.TString>;
47
+ path: _sinclair_typebox22.TOptional<_sinclair_typebox22.TString>;
48
48
  }>;
49
49
  type Permission = Static<typeof permissionSchema>;
50
+ //# sourceMappingURL=permissionSchema.d.ts.map
50
51
  //#endregion
51
52
  //#region src/descriptors/$permission.d.ts
52
53
  declare const KEY$2 = "PERMISSION";
54
+ /**
55
+ *
56
+ */
57
+ declare const $permission: {
58
+ (options?: PermissionDescriptorOptions): PermissionDescriptor;
59
+ [KIND]: string;
60
+ };
53
61
  interface PermissionDescriptorOptions {
54
62
  /**
55
63
  * Name of the permission. Use Property name is not provided.
@@ -84,10 +92,6 @@ interface PermissionDescriptor {
84
92
  */
85
93
  can(user: UserAccountInfo): boolean;
86
94
  }
87
- declare const $permission: {
88
- (options?: PermissionDescriptorOptions): PermissionDescriptor;
89
- [KIND]: string;
90
- };
91
95
  //#endregion
92
96
  //#region src/interfaces/UserAccountToken.d.ts
93
97
  interface UserAccountToken extends UserAccountInfo {
@@ -102,26 +106,28 @@ interface UserAccountToken extends UserAccountInfo {
102
106
  */
103
107
  ownership?: string | boolean;
104
108
  }
109
+ //# sourceMappingURL=UserAccountToken.d.ts.map
105
110
  //#endregion
106
111
  //#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>>;
112
+ declare const roleSchema: _sinclair_typebox1.TObject<{
113
+ name: _sinclair_typebox1.TString;
114
+ description: _sinclair_typebox1.TOptional<_sinclair_typebox1.TString>;
115
+ default: _sinclair_typebox1.TOptional<_sinclair_typebox1.TBoolean>;
116
+ permissions: _sinclair_typebox1.TArray<_sinclair_typebox1.TObject<{
117
+ name: _sinclair_typebox1.TString;
118
+ ownership: _sinclair_typebox1.TOptional<_sinclair_typebox1.TBoolean>;
119
+ exclude: _sinclair_typebox1.TOptional<_sinclair_typebox1.TArray<_sinclair_typebox1.TString>>;
115
120
  }>>;
116
121
  }>;
117
122
  type Role = Static<typeof roleSchema>;
123
+ //# sourceMappingURL=roleSchema.d.ts.map
118
124
  //#endregion
119
125
  //#region src/providers/JwtProvider.d.ts
120
126
  /**
121
127
  * Provides utilities for working with JSON Web Tokens (JWT).
122
128
  */
123
129
  declare class JwtProvider {
124
- protected readonly log: _alepha_core7.Logger;
130
+ protected readonly log: _alepha_core15.Logger;
125
131
  protected readonly keystore: KeyLoaderHolder[];
126
132
  protected readonly dateTimeProvider: DateTimeProvider;
127
133
  /**
@@ -202,10 +208,11 @@ interface JwtParseResult {
202
208
  keyName: string;
203
209
  result: JWTVerifyResult<ExtendedJWTPayload>;
204
210
  }
211
+ //# sourceMappingURL=JwtProvider.d.ts.map
205
212
  //#endregion
206
213
  //#region src/providers/SecurityProvider.d.ts
207
- declare const envSchema: _alepha_core2.TObject<{
208
- SECURITY_SECRET_KEY: _sinclair_typebox1.TString;
214
+ declare const envSchema: _alepha_core16.TObject<{
215
+ SECURITY_SECRET_KEY: _alepha_core16.TString;
209
216
  }>;
210
217
  declare module "alepha" {
211
218
  interface Env extends Partial<Static<typeof envSchema>> {}
@@ -214,7 +221,7 @@ declare class SecurityProvider {
214
221
  protected readonly UNKNOWN_USER_NAME = "Unknown User";
215
222
  protected readonly PERMISSION_REGEXP: RegExp;
216
223
  protected readonly PERMISSION_REGEXP_WILDCARD: RegExp;
217
- protected readonly log: _alepha_core2.Logger;
224
+ protected readonly log: _alepha_core16.Logger;
218
225
  protected readonly jwt: JwtProvider;
219
226
  protected readonly env: {
220
227
  SECURITY_SECRET_KEY: string;
@@ -232,7 +239,7 @@ declare class SecurityProvider {
232
239
  * Create realms.
233
240
  */
234
241
  protected createRealms(): Realm[];
235
- protected configure: _alepha_core2.HookDescriptor<"configure">;
242
+ protected configure: _alepha_core16.HookDescriptor<"configure">;
236
243
  /**
237
244
  * Processes all $permission descriptors.
238
245
  */
@@ -245,7 +252,7 @@ declare class SecurityProvider {
245
252
  * Processes all $role descriptors.
246
253
  */
247
254
  protected processRoleDescriptors(): void;
248
- protected ready: _alepha_core2.HookDescriptor<"ready">;
255
+ protected ready: _alepha_core16.HookDescriptor<"ready">;
249
256
  /**
250
257
  * Updates the roles for a realm then synchronizes the user account provider if available.
251
258
  *
@@ -390,6 +397,14 @@ interface RealmConfig {
390
397
  //#endregion
391
398
  //#region src/descriptors/$realm.d.ts
392
399
  declare const KEY$1 = "REALM";
400
+ /**
401
+ *
402
+ * @param options
403
+ */
404
+ declare const $realm: {
405
+ (options?: RealmDescriptorOptions): RealmDescriptor;
406
+ [KIND]: string;
407
+ };
393
408
  interface RealmDescriptorOptions {
394
409
  /**
395
410
  * Define the realm name.
@@ -438,13 +453,16 @@ interface RealmDescriptor {
438
453
  */
439
454
  createToken(subject: string, roles?: string[]): Promise<string>;
440
455
  }
441
- declare const $realm: {
442
- (options?: RealmDescriptorOptions): RealmDescriptor;
443
- [KIND]: string;
444
- };
445
456
  //#endregion
446
457
  //#region src/descriptors/$role.d.ts
447
458
  declare const KEY = "ROLE";
459
+ /**
460
+ *
461
+ */
462
+ declare const $role: {
463
+ (options?: RoleDescriptorOptions): RoleDescriptor;
464
+ [KIND]: string;
465
+ };
448
466
  interface RoleDescriptorOptions {
449
467
  /**
450
468
  * Name of the role.
@@ -467,10 +485,6 @@ interface RoleDescriptor {
467
485
  */
468
486
  (): Role;
469
487
  }
470
- declare const $role: {
471
- (options?: RoleDescriptorOptions): RoleDescriptor;
472
- [KIND]: string;
473
- };
474
488
  //#endregion
475
489
  //#region src/descriptors/$serviceAccount.d.ts
476
490
  /**
@@ -482,7 +496,7 @@ declare const $role: {
482
496
  *
483
497
  * @example
484
498
  * ```ts
485
- * import { $serviceAccount } from "@alepha/security";
499
+ * import { $serviceAccount } from "alepha/security";
486
500
  *
487
501
  * class MyService {
488
502
  * serviceAccount = $serviceAccount({
@@ -539,20 +553,24 @@ interface AccessTokenResponse {
539
553
  interface ServiceAccountStore {
540
554
  response?: AccessTokenResponse;
541
555
  }
556
+ //# sourceMappingURL=$serviceAccount.d.ts.map
542
557
  //#endregion
543
558
  //#region src/errors/InvalidPermissionError.d.ts
544
559
  declare class InvalidPermissionError extends Error {
545
560
  constructor(name: string);
546
561
  }
562
+ //# sourceMappingURL=InvalidPermissionError.d.ts.map
547
563
  //#endregion
548
564
  //#region src/errors/SecurityError.d.ts
549
565
  declare class SecurityError extends Error {
550
566
  readonly status = 403;
551
567
  readonly code = "ERR_SECURITY";
552
568
  }
569
+ //# sourceMappingURL=SecurityError.d.ts.map
570
+
553
571
  //#endregion
554
572
  //#region src/index.d.ts
555
- declare module "alepha/core" {
573
+ declare module "alepha" {
556
574
  interface Hooks {
557
575
  "security:user:created": {
558
576
  realm: string;
@@ -560,10 +578,181 @@ declare module "alepha/core" {
560
578
  };
561
579
  }
562
580
  }
581
+ /**
582
+ * Provides comprehensive authentication and authorization capabilities with JWT tokens, role-based access control, and user management.
583
+ *
584
+ * The security module enables building secure applications using descriptors like `$realm`, `$role`, and `$permission`
585
+ * on class properties. It offers JWT-based authentication, fine-grained permissions, service accounts, and seamless
586
+ * integration with various authentication providers and user management systems.
587
+ *
588
+ * **Key Features:**
589
+ * - Declarative realm definition with `$realm` descriptor for user authentication
590
+ * - Role-based access control with `$role` descriptor
591
+ * - Fine-grained permissions with `$permission` descriptor
592
+ * - Service account management with `$serviceAccount` descriptor
593
+ * - JWT token generation and validation
594
+ * - OAuth integration and external provider support
595
+ * - User session management and security hooks
596
+ *
597
+ * **Basic Usage:**
598
+ * ```ts
599
+ * import { Alepha, run, t } from "alepha";
600
+ * import { AlephaSecurity, $realm, $role, $permission } from "alepha/security";
601
+ *
602
+ * // Define user roles
603
+ * const adminRole = $role({
604
+ * name: "admin",
605
+ * description: "Administrator with full access",
606
+ * });
607
+ *
608
+ * const userRole = $role({
609
+ * name: "user",
610
+ * description: "Regular user with limited access",
611
+ * });
612
+ *
613
+ * // Define permissions
614
+ * const readUsersPermission = $permission({
615
+ * name: "users:read",
616
+ * description: "Read user information",
617
+ * });
618
+ *
619
+ * const writeUsersPermission = $permission({
620
+ * name: "users:write",
621
+ * description: "Create and update users",
622
+ * });
623
+ *
624
+ * // Define authentication realm
625
+ * class AuthSystem {
626
+ * userRealm = $realm({
627
+ * name: "users",
628
+ * roles: [adminRole, userRole],
629
+ * permissions: [readUsersPermission, writeUsersPermission],
630
+ * authenticate: async (token: string) => {
631
+ * // Validate user token and return user info
632
+ * const user = await validateUserToken(token);
633
+ * return {
634
+ * id: user.id,
635
+ * email: user.email,
636
+ * roles: user.roles,
637
+ * permissions: user.permissions,
638
+ * };
639
+ * },
640
+ * });
641
+ * }
642
+ *
643
+ * const alepha = Alepha.create()
644
+ * .with(AlephaSecurity)
645
+ * .with(AuthSystem);
646
+ *
647
+ * run(alepha);
648
+ * ```
649
+ *
650
+ * **OAuth Integration:**
651
+ * ```ts
652
+ * import { $serviceAccount } from "alepha/security";
653
+ *
654
+ * class OAuthSystem {
655
+ * googleAuth = $realm({
656
+ * name: "google-oauth",
657
+ * provider: "oauth",
658
+ * config: {
659
+ * clientId: process.env.GOOGLE_CLIENT_ID,
660
+ * clientSecret: process.env.GOOGLE_CLIENT_SECRET,
661
+ * redirectUri: "https://myapp.com/auth/callback",
662
+ * scope: ["email", "profile"],
663
+ * },
664
+ * authenticate: async (oauthToken: string) => {
665
+ * const userInfo = await fetchGoogleUserInfo(oauthToken);
666
+ * return {
667
+ * id: userInfo.sub,
668
+ * email: userInfo.email,
669
+ * name: userInfo.name,
670
+ * roles: ["user"],
671
+ * };
672
+ * },
673
+ * });
674
+ *
675
+ * serviceAccount = $serviceAccount({
676
+ * name: "api-service",
677
+ * permissions: ["api:read", "api:write"],
678
+ * secret: process.env.SERVICE_ACCOUNT_SECRET,
679
+ * });
680
+ * }
681
+ * ```
682
+ *
683
+ * **Role and Permission Management:**
684
+ * ```ts
685
+ * class PermissionSystem {
686
+ * // Define hierarchical roles
687
+ * superAdminRole = $role({
688
+ * name: "super-admin",
689
+ * inherits: [adminRole],
690
+ * permissions: ["*"], // All permissions
691
+ * });
692
+ *
693
+ * moderatorRole = $role({
694
+ * name: "moderator",
695
+ * inherits: [userRole],
696
+ * permissions: ["posts:moderate", "comments:moderate"],
697
+ * });
698
+ *
699
+ * // Define resource-specific permissions
700
+ * postPermissions = [
701
+ * $permission({ name: "posts:create", description: "Create posts" }),
702
+ * $permission({ name: "posts:edit", description: "Edit posts" }),
703
+ * $permission({ name: "posts:delete", description: "Delete posts" }),
704
+ * $permission({ name: "posts:moderate", description: "Moderate posts" }),
705
+ * ];
706
+ *
707
+ * // Check permissions in application logic
708
+ * async checkUserPermission(userId: string, permission: string) {
709
+ * const user = await this.userRealm.getUser(userId);
710
+ * return user.permissions.includes(permission);
711
+ * }
712
+ * }
713
+ * ```
714
+ *
715
+ * **JWT Token Management:**
716
+ * ```ts
717
+ * class TokenSystem {
718
+ * userTokens = $realm({
719
+ * name: "jwt-tokens",
720
+ * jwtConfig: {
721
+ * secret: process.env.JWT_SECRET,
722
+ * expiresIn: "24h",
723
+ * issuer: "myapp.com",
724
+ * audience: "myapp-users",
725
+ * },
726
+ * authenticate: async (jwtToken: string) => {
727
+ * // JWT validation is handled automatically
728
+ * // Return user data from token payload
729
+ * return jwtToken.payload;
730
+ * },
731
+ * });
732
+ *
733
+ * async generateUserToken(user: { id: string; email: string; roles: string[] }) {
734
+ * return await this.userTokens.generateToken({
735
+ * sub: user.id,
736
+ * email: user.email,
737
+ * roles: user.roles,
738
+ * iat: Date.now(),
739
+ * });
740
+ * }
741
+ * }
742
+ * ```
743
+ *
744
+ * @see {@link $realm}
745
+ * @see {@link $role}
746
+ * @see {@link $permission}
747
+ * @see {@link $serviceAccount}
748
+ * @module alepha.security
749
+ */
563
750
  declare class AlephaSecurity {
564
751
  readonly name = "alepha.security";
565
752
  readonly $services: (alepha: Alepha) => Alepha;
566
753
  }
754
+ //# sourceMappingURL=index.d.ts.map
755
+
567
756
  //#endregion
568
757
  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
758
  //# sourceMappingURL=index.d.ts.map