alepha 0.8.0 → 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.
package/react.d.ts CHANGED
@@ -1,16 +1,17 @@
1
1
  import * as _alepha_core11 from "alepha";
2
- import * as _alepha_core18 from "alepha";
2
+ import * as _alepha_core24 from "alepha";
3
3
  import * as _alepha_core16 from "alepha";
4
4
  import * as _alepha_core1 from "alepha";
5
5
  import { Alepha, Async, KIND, Module, OPTIONS, Service, Static, TObject, TSchema } from "alepha";
6
6
  import { ApiLinksResponse, ServerHandler, ServerRequest, ServerRouterProvider, ServerTimingProvider } from "alepha/server";
7
7
  import { ServerRouteCache } from "alepha/server/cache";
8
8
  import { ClientScope, HttpVirtualClient, LinkProvider } from "alepha/server/links";
9
+ import * as react20 from "react";
9
10
  import * as react23 from "react";
10
- import * as react24 from "react";
11
11
  import React, { AnchorHTMLAttributes, ErrorInfo, FC, PropsWithChildren, ReactNode } from "react";
12
+ import * as react_jsx_runtime18 from "react/jsx-runtime";
13
+ import * as react_jsx_runtime21 from "react/jsx-runtime";
12
14
  import * as react_jsx_runtime22 from "react/jsx-runtime";
13
- import * as react_jsx_runtime20 from "react/jsx-runtime";
14
15
  import { ServerStaticProvider } from "alepha/server/static";
15
16
  import { Route, RouterProvider } from "alepha/router";
16
17
  import { Root } from "react-dom/client";
@@ -34,6 +35,13 @@ declare const ClientOnly: (props: PropsWithChildren<ClientOnlyProps>) => ReactNo
34
35
  //#endregion
35
36
  //#region src/descriptors/$page.d.ts
36
37
  declare const KEY = "PAGE";
38
+ /**
39
+ * Main descriptor for defining a React route in the application.
40
+ */
41
+ declare const $page: {
42
+ <TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = any, TPropsParent extends object = TPropsParentDefault>(options: PageDescriptorOptions<TConfig, TProps, TPropsParent>): PageDescriptor<TConfig, TProps, TPropsParent>;
43
+ [KIND]: string;
44
+ };
37
45
  interface PageConfigSchema {
38
46
  query?: TSchema;
39
47
  params?: TSchema;
@@ -138,13 +146,6 @@ interface PageDescriptor<TConfig extends PageConfigSchema = PageConfigSchema, TP
138
146
  */
139
147
  render: (options?: PageDescriptorRenderOptions) => Promise<PageDescriptorRenderResult>;
140
148
  }
141
- /**
142
- * Main descriptor for defining a React route in the application.
143
- */
144
- declare const $page: {
145
- <TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = any, TPropsParent extends object = TPropsParentDefault>(options: PageDescriptorOptions<TConfig, TProps, TPropsParent>): PageDescriptor<TConfig, TProps, TPropsParent>;
146
- [KIND]: string;
147
- };
148
149
  interface PageDescriptorRenderOptions {
149
150
  params?: Record<string, string>;
150
151
  query?: Record<string, string>;
@@ -231,6 +232,7 @@ interface Layer {
231
232
  index: number;
232
233
  path: string;
233
234
  route?: PageRoute;
235
+ cache?: boolean;
234
236
  }
235
237
  type PreviousLayerData = Omit<Layer, "element" | "index" | "path">;
236
238
  interface AnchorProps {
@@ -252,6 +254,7 @@ interface RouterStackItem {
252
254
  config?: Record<string, any>;
253
255
  props?: Record<string, any>;
254
256
  error?: Error;
257
+ cache?: boolean;
255
258
  }
256
259
  interface RouterRenderResult {
257
260
  state: RouterState;
@@ -281,11 +284,11 @@ interface BrowserRoute extends Route {
281
284
  page: PageRoute;
282
285
  }
283
286
  declare class BrowserRouterProvider extends RouterProvider<BrowserRoute> {
284
- protected readonly log: _alepha_core18.Logger;
287
+ protected readonly log: _alepha_core24.Logger;
285
288
  protected readonly alepha: Alepha;
286
289
  protected readonly pageDescriptorProvider: PageDescriptorProvider;
287
290
  add(entry: PageRouteEntry): void;
288
- protected readonly configure: _alepha_core18.HookDescriptor<"configure">;
291
+ protected readonly configure: _alepha_core24.HookDescriptor<"configure">;
289
292
  transition(url: URL, options?: TransitionOptions): Promise<RouterRenderResult>;
290
293
  root(state: RouterState, context: PageReactContext): ReactNode;
291
294
  }
@@ -304,7 +307,9 @@ declare class ReactBrowserProvider {
304
307
  state: RouterState;
305
308
  get document(): Document;
306
309
  get history(): History;
310
+ get location(): Location;
307
311
  get url(): string;
312
+ pushState(url: string, replace?: boolean): void;
308
313
  invalidate(props?: Record<string, any>): Promise<void>;
309
314
  go(url: string, options?: RouterGoOptions): Promise<void>;
310
315
  protected render(options?: {
@@ -373,7 +378,7 @@ interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
373
378
  to: string | PageDescriptor;
374
379
  children?: React.ReactNode;
375
380
  }
376
- declare const Link: (props: LinkProps) => react_jsx_runtime22.JSX.Element | null;
381
+ declare const Link: (props: LinkProps) => react_jsx_runtime18.JSX.Element | null;
377
382
  //#endregion
378
383
  //#region src/components/NestedView.d.ts
379
384
  interface NestedViewProps {
@@ -400,7 +405,11 @@ interface NestedViewProps {
400
405
  * }
401
406
  * ```
402
407
  */
403
- declare const NestedView: (props: NestedViewProps) => react_jsx_runtime20.JSX.Element;
408
+ declare const NestedView: (props: NestedViewProps) => react_jsx_runtime21.JSX.Element;
409
+ //#endregion
410
+ //#region src/components/NotFound.d.ts
411
+ declare function NotFoundPage(): react_jsx_runtime22.JSX.Element;
412
+ //# sourceMappingURL=NotFound.d.ts.map
404
413
  //#endregion
405
414
  //#region src/contexts/RouterContext.d.ts
406
415
  interface RouterContextValue {
@@ -408,7 +417,7 @@ interface RouterContextValue {
408
417
  state: RouterState;
409
418
  context: PageReactContext;
410
419
  }
411
- declare const RouterContext: react23.Context<RouterContextValue | undefined>;
420
+ declare const RouterContext: react20.Context<RouterContextValue | undefined>;
412
421
  //# sourceMappingURL=RouterContext.d.ts.map
413
422
  //#endregion
414
423
  //#region src/contexts/RouterLayerContext.d.ts
@@ -416,18 +425,21 @@ interface RouterLayerContextValue {
416
425
  index: number;
417
426
  path: string;
418
427
  }
419
- declare const RouterLayerContext: react24.Context<RouterLayerContextValue | undefined>;
428
+ declare const RouterLayerContext: react23.Context<RouterLayerContextValue | undefined>;
420
429
  //# sourceMappingURL=RouterLayerContext.d.ts.map
421
430
  //#endregion
422
431
  //#region src/hooks/RouterHookApi.d.ts
423
432
  declare class RouterHookApi {
424
433
  private readonly pages;
434
+ private readonly context;
425
435
  private readonly state;
426
436
  private readonly layer;
427
437
  private readonly browser?;
428
- constructor(pages: PageRoute[], state: RouterState, layer: {
438
+ constructor(pages: PageRoute[], context: PageReactContext, state: RouterState, layer: {
429
439
  path: string;
430
440
  }, browser?: ReactBrowserProvider | undefined);
441
+ getURL(): URL;
442
+ get location(): Location;
431
443
  get current(): RouterState;
432
444
  get pathname(): string;
433
445
  get query(): Record<string, string>;
@@ -547,8 +559,8 @@ declare const envSchema: _alepha_core1.TObject<{
547
559
  declare module "alepha" {
548
560
  interface Env extends Partial<Static<typeof envSchema>> {}
549
561
  interface State {
550
- "ReactServerProvider.template"?: string;
551
- "ReactServerProvider.ssr"?: boolean;
562
+ "react.server.template"?: string;
563
+ "react.server.ssr"?: boolean;
552
564
  }
553
565
  }
554
566
  declare class ReactServerProvider {
@@ -633,10 +645,132 @@ declare module "alepha" {
633
645
  }
634
646
  }
635
647
  /**
636
- * Alepha React Module
648
+ * Provides full-stack React development with declarative routing, server-side rendering, and client-side hydration.
637
649
  *
638
- * Alepha React Module contains a router for client-side navigation and server-side rendering.
639
- * Routes can be defined using the `$page` descriptor.
650
+ * The React module enables building modern React applications using the `$page` descriptor on class properties.
651
+ * It delivers seamless server-side rendering, automatic code splitting, and client-side navigation with full
652
+ * type safety and schema validation for route parameters and data.
653
+ *
654
+ * **Key Features:**
655
+ * - Declarative page definition with `$page` descriptor
656
+ * - Server-side rendering (SSR) with automatic hydration
657
+ * - Type-safe routing with parameter validation
658
+ * - Schema-based data resolution and validation
659
+ * - SEO-friendly meta tag management
660
+ * - Automatic code splitting and lazy loading
661
+ * - Client-side navigation with browser history
662
+ *
663
+ * **Basic Usage:**
664
+ * ```ts
665
+ * import { Alepha, run, t } from "alepha";
666
+ * import { AlephaReact, $page } from "alepha/react";
667
+ *
668
+ * class AppRoutes {
669
+ * // Home page
670
+ * home = $page({
671
+ * path: "/",
672
+ * component: () => (
673
+ * <div>
674
+ * <h1>Welcome to Alepha</h1>
675
+ * <p>Build amazing React applications!</p>
676
+ * </div>
677
+ * ),
678
+ * });
679
+ *
680
+ * // About page with meta tags
681
+ * about = $page({
682
+ * path: "/about",
683
+ * head: {
684
+ * title: "About Us",
685
+ * description: "Learn more about our mission",
686
+ * },
687
+ * component: () => (
688
+ * <div>
689
+ * <h1>About Us</h1>
690
+ * <p>Learn more about our mission.</p>
691
+ * </div>
692
+ * ),
693
+ * });
694
+ * }
695
+ *
696
+ * const alepha = Alepha.create()
697
+ * .with(AlephaReact)
698
+ * .with(AppRoutes);
699
+ *
700
+ * run(alepha);
701
+ * ```
702
+ *
703
+ * **Dynamic Routes with Parameters:**
704
+ * ```tsx
705
+ * class UserRoutes {
706
+ * userProfile = $page({
707
+ * path: "/users/:id",
708
+ * schema: {
709
+ * params: t.object({
710
+ * id: t.string(),
711
+ * }),
712
+ * },
713
+ * resolve: async ({ params }) => {
714
+ * // Fetch user data server-side
715
+ * const user = await getUserById(params.id);
716
+ * return { user };
717
+ * },
718
+ * head: ({ user }) => ({
719
+ * title: `${user.name} - Profile`,
720
+ * description: `View ${user.name}'s profile`,
721
+ * }),
722
+ * component: ({ user }) => (
723
+ * <div>
724
+ * <h1>{user.name}</h1>
725
+ * <p>Email: {user.email}</p>
726
+ * </div>
727
+ * ),
728
+ * });
729
+ *
730
+ * userSettings = $page({
731
+ * path: "/users/:id/settings",
732
+ * schema: {
733
+ * params: t.object({
734
+ * id: t.string(),
735
+ * }),
736
+ * },
737
+ * component: ({ params }) => (
738
+ * <UserSettings userId={params.id} />
739
+ * ),
740
+ * });
741
+ * }
742
+ * ```
743
+ *
744
+ * **Static Generation:**
745
+ * ```tsx
746
+ * class BlogRoutes {
747
+ * blogPost = $page({
748
+ * path: "/blog/:slug",
749
+ * schema: {
750
+ * params: t.object({
751
+ * slug: t.string(),
752
+ * }),
753
+ * },
754
+ * static: {
755
+ * entries: [
756
+ * { params: { slug: "getting-started" } },
757
+ * { params: { slug: "advanced-features" } },
758
+ * { params: { slug: "deployment" } },
759
+ * ],
760
+ * },
761
+ * resolve: ({ params }) => {
762
+ * const post = getBlogPost(params.slug);
763
+ * return { post };
764
+ * },
765
+ * component: ({ post }) => (
766
+ * <article>
767
+ * <h1>{post.title}</h1>
768
+ * <div>{post.content}</div>
769
+ * </article>
770
+ * ),
771
+ * });
772
+ * }
773
+ * ```
640
774
  *
641
775
  * @see {@link $page}
642
776
  * @module alepha.react
@@ -648,5 +782,5 @@ declare class AlephaReact implements Module {
648
782
  //# sourceMappingURL=index.d.ts.map
649
783
 
650
784
  //#endregion
651
- export { $page, AlephaReact, AnchorProps, ClientOnly, CreateLayersResult, ErrorBoundary, HrefLike, Layer, Link, NestedView, PageConfigSchema, PageDescriptor, PageDescriptorOptions, PageDescriptorProvider, PageDescriptorRenderOptions, PageDescriptorRenderResult, PageReactContext, PageRequest, PageRequestConfig, PageResolve, PageRoute, PageRouteEntry, PreviousLayerData, ReactBrowserProvider, ReactHydrationState, ReactServerProvider, RedirectionError, RouterContext, RouterContextValue, RouterGoOptions, RouterHookApi, RouterLayerContext, RouterLayerContextValue, RouterRenderResult, RouterStackItem, RouterState, TPropsDefault, TPropsParentDefault, TransitionOptions, UseActiveHook, UseQueryParamsHookOptions, VirtualRouter, isPageRoute, useActive, useAlepha, useClient, useInject, useQueryParams, useRouter, useRouterEvents, useRouterState };
785
+ export { $page, AlephaReact, AnchorProps, ClientOnly, CreateLayersResult, ErrorBoundary, HrefLike, Layer, Link, NestedView, NotFoundPage as NotFound, PageConfigSchema, PageDescriptor, PageDescriptorOptions, PageDescriptorProvider, PageDescriptorRenderOptions, PageDescriptorRenderResult, PageReactContext, PageRequest, PageRequestConfig, PageResolve, PageRoute, PageRouteEntry, PreviousLayerData, ReactBrowserProvider, ReactHydrationState, ReactServerProvider, RedirectionError, RouterContext, RouterContextValue, RouterGoOptions, RouterHookApi, RouterLayerContext, RouterLayerContextValue, RouterRenderResult, RouterStackItem, RouterState, TPropsDefault, TPropsParentDefault, TransitionOptions, UseActiveHook, UseQueryParamsHookOptions, VirtualRouter, isPageRoute, useActive, useAlepha, useClient, useInject, useQueryParams, useRouter, useRouterEvents, useRouterState };
652
786
  //# sourceMappingURL=index.d.ts.map
package/redis.d.ts CHANGED
@@ -15,6 +15,9 @@ type RedisClient = RedisClientType<{}, {}, {}, 3, {
15
15
  }>;
16
16
  type RedisClientOptions = Parameters<typeof createClient>[0];
17
17
  type RedisSetOptions = SetOptions;
18
+ /**
19
+ * Redis client provider.
20
+ */
18
21
  declare class RedisProvider {
19
22
  protected readonly log: Logger;
20
23
  protected readonly alepha: Alepha;
package/retry.d.ts CHANGED
@@ -3,12 +3,13 @@ import { DateTimeProvider, DurationLike } from "alepha/datetime";
3
3
 
4
4
  //#region src/descriptors/$retry.d.ts
5
5
 
6
- // TODO: move to RetryProvider
7
6
  /**
8
7
  * Creates a function that automatically retries a handler upon failure,
9
8
  * with support for exponential backoff, max duration, and cancellation.
10
9
  */
11
10
  declare const $retry: <T extends (...args: any[]) => any>(opts: RetryDescriptorOptions<T>) => RetryDescriptor<T>;
11
+ // ---------------------------------------------------------------------------------------------------------------------
12
+ // TODO: move to RetryProvider
12
13
  declare const createRetryHandler: <T extends (...args: any[]) => any>(opts: RetryDescriptorOptions<T>, dateTimeProvider: DateTimeProvider, appAbortController?: AbortController) => RetryDescriptor<T>;
13
14
  // ---------------------------------------------------------------------------------------------------------------------
14
15
  interface RetryBackoffOptions {
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
@@ -15,7 +15,6 @@ declare const $scheduler: {
15
15
  (options: SchedulerDescriptorOptions): SchedulerDescriptor;
16
16
  [KIND]: string;
17
17
  };
18
- declare const isScheduler: (value: any) => value is SchedulerDescriptor;
19
18
  type SchedulerDescriptorOptions = {
20
19
  /**
21
20
  * Function to run on schedule.
@@ -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}
@@ -157,5 +154,5 @@ declare class AlephaScheduler {
157
154
  //# sourceMappingURL=index.d.ts.map
158
155
 
159
156
  //#endregion
160
- export { $scheduler, AlephaScheduler, Scheduler, SchedulerDescriptor, SchedulerDescriptorOptions, SchedulerDescriptorProvider, SchedulerHandlerArguments, isScheduler };
157
+ export { $scheduler, AlephaScheduler, Scheduler, SchedulerDescriptor, SchedulerDescriptorOptions, SchedulerDescriptorProvider, SchedulerHandlerArguments };
161
158
  //# sourceMappingURL=index.d.ts.map
package/security.d.ts CHANGED
@@ -51,6 +51,13 @@ type Permission = Static<typeof permissionSchema>;
51
51
  //#endregion
52
52
  //#region src/descriptors/$permission.d.ts
53
53
  declare const KEY$2 = "PERMISSION";
54
+ /**
55
+ *
56
+ */
57
+ declare const $permission: {
58
+ (options?: PermissionDescriptorOptions): PermissionDescriptor;
59
+ [KIND]: string;
60
+ };
54
61
  interface PermissionDescriptorOptions {
55
62
  /**
56
63
  * Name of the permission. Use Property name is not provided.
@@ -85,10 +92,6 @@ interface PermissionDescriptor {
85
92
  */
86
93
  can(user: UserAccountInfo): boolean;
87
94
  }
88
- declare const $permission: {
89
- (options?: PermissionDescriptorOptions): PermissionDescriptor;
90
- [KIND]: string;
91
- };
92
95
  //#endregion
93
96
  //#region src/interfaces/UserAccountToken.d.ts
94
97
  interface UserAccountToken extends UserAccountInfo {
@@ -394,6 +397,14 @@ interface RealmConfig {
394
397
  //#endregion
395
398
  //#region src/descriptors/$realm.d.ts
396
399
  declare const KEY$1 = "REALM";
400
+ /**
401
+ *
402
+ * @param options
403
+ */
404
+ declare const $realm: {
405
+ (options?: RealmDescriptorOptions): RealmDescriptor;
406
+ [KIND]: string;
407
+ };
397
408
  interface RealmDescriptorOptions {
398
409
  /**
399
410
  * Define the realm name.
@@ -442,13 +453,16 @@ interface RealmDescriptor {
442
453
  */
443
454
  createToken(subject: string, roles?: string[]): Promise<string>;
444
455
  }
445
- declare const $realm: {
446
- (options?: RealmDescriptorOptions): RealmDescriptor;
447
- [KIND]: string;
448
- };
449
456
  //#endregion
450
457
  //#region src/descriptors/$role.d.ts
451
458
  declare const KEY = "ROLE";
459
+ /**
460
+ *
461
+ */
462
+ declare const $role: {
463
+ (options?: RoleDescriptorOptions): RoleDescriptor;
464
+ [KIND]: string;
465
+ };
452
466
  interface RoleDescriptorOptions {
453
467
  /**
454
468
  * Name of the role.
@@ -471,10 +485,6 @@ interface RoleDescriptor {
471
485
  */
472
486
  (): Role;
473
487
  }
474
- declare const $role: {
475
- (options?: RoleDescriptorOptions): RoleDescriptor;
476
- [KIND]: string;
477
- };
478
488
  //#endregion
479
489
  //#region src/descriptors/$serviceAccount.d.ts
480
490
  /**
@@ -568,6 +578,175 @@ declare module "alepha" {
568
578
  };
569
579
  }
570
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
+ */
571
750
  declare class AlephaSecurity {
572
751
  readonly name = "alepha.security";
573
752
  readonly $services: (alepha: Alepha) => Alepha;
package/server/cache.d.ts CHANGED
@@ -46,9 +46,6 @@ type RouteLike = {
46
46
  //#endregion
47
47
  //#region src/index.d.ts
48
48
  /**
49
- * # Alepha Server Cache Module
50
- *
51
- * @description
52
49
  * Plugin for Alepha Server that provides server-side caching capabilities.
53
50
  * It uses the Alepha Cache module to cache responses from server actions ($action).
54
51
  * It also provides a ETag-based cache invalidation mechanism.