alepha 0.7.7 → 0.8.0

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/retry.d.ts CHANGED
@@ -1,71 +1,91 @@
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
 
6
+ // TODO: move to RetryProvider
5
7
  /**
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
- */
8
+ * Creates a function that automatically retries a handler upon failure,
9
+ * with support for exponential backoff, max duration, and cancellation.
10
+ */
34
11
  declare const $retry: <T extends (...args: any[]) => any>(opts: RetryDescriptorOptions<T>) => RetryDescriptor<T>;
35
- /**
36
- * Retry Descriptor options.
37
- */
12
+ declare const createRetryHandler: <T extends (...args: any[]) => any>(opts: RetryDescriptorOptions<T>, dateTimeProvider: DateTimeProvider, appAbortController?: AbortController) => RetryDescriptor<T>;
13
+ // ---------------------------------------------------------------------------------------------------------------------
14
+ interface RetryBackoffOptions {
15
+ /**
16
+ * Initial delay in milliseconds.
17
+ *
18
+ * @default 200
19
+ */
20
+ initial?: number;
21
+ /**
22
+ * Multiplier for each subsequent delay.
23
+ *
24
+ * @default 2
25
+ */
26
+ factor?: number;
27
+ /**
28
+ * Maximum delay in milliseconds.
29
+ */
30
+ max?: number;
31
+ /**
32
+ * If true, adds a random jitter to the delay to prevent thundering herd.
33
+ *
34
+ * @default true
35
+ */
36
+ jitter?: boolean;
37
+ }
38
38
  interface RetryDescriptorOptions<T extends (...args: any[]) => any> {
39
39
  /**
40
- * Maximum number of attempts.
41
- *
42
- * @default 3
43
- */
40
+ * The function to retry.
41
+ */
42
+ handler: T;
43
+ /**
44
+ * The maximum number of attempts.
45
+ *
46
+ * @default 3
47
+ */
44
48
  max?: number;
45
49
  /**
46
- * Delay in milliseconds.
47
- *
48
- * @default 0
49
- */
50
- delay?: number;
50
+ * The backoff strategy for delays between retries.
51
+ * Can be a fixed number (in ms) or a configuration object for exponential backoff.
52
+ *
53
+ * @default { initial: 200, factor: 2, jitter: true }
54
+ */
55
+ backoff?: number | RetryBackoffOptions;
56
+ /**
57
+ * An overall time limit for all retry attempts combined.
58
+ *
59
+ * e.g., `[5, 'seconds']`
60
+ */
61
+ maxDuration?: DurationLike;
51
62
  /**
52
- * Optional condition to determine when to retry.
53
- */
63
+ * A function that determines if a retry should be attempted based on the error.
64
+ *
65
+ * @default (error) => true (retries on any error)
66
+ */
54
67
  when?: (error: Error) => boolean;
55
68
  /**
56
- * The function to retry.
57
- */
58
- handler: T;
69
+ * A custom callback for when a retry attempt fails.
70
+ * This is called before the delay.
71
+ */
72
+ onError?: (error: Error, attempt: number, ...args: Parameters<T>) => void;
59
73
  /**
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;
74
+ * An AbortSignal to allow for external cancellation of the retry loop.
75
+ */
76
+ signal?: AbortSignal;
67
77
  }
68
78
  type RetryDescriptor<T extends (...args: any[]) => any> = (...parameters: Parameters<T>) => MaybePromise<ReturnType<T>>;
69
79
  //#endregion
70
- export { $retry, RetryDescriptor, RetryDescriptorOptions };
80
+ //#region src/errors/RetryCancelError.d.ts
81
+ declare class RetryCancelError extends AlephaError {
82
+ constructor();
83
+ }
84
+ //#endregion
85
+ //#region src/errors/RetryTimeoutError.d.ts
86
+ declare class RetryTimeoutError extends AlephaError {
87
+ constructor(duration: number);
88
+ }
89
+ //#endregion
90
+ export { $retry, RetryBackoffOptions, RetryCancelError, RetryDescriptor, RetryDescriptorOptions, RetryTimeoutError, createRetryHandler };
71
91
  //# sourceMappingURL=index.d.ts.map
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
@@ -77,16 +76,17 @@ declare class CronProvider {
77
76
  }) => Promise<void>): CronJob;
78
77
  run(task: CronJob, now?: dayjs10.Dayjs): void;
79
78
  }
79
+ //# sourceMappingURL=CronScheduler.d.ts.map
80
80
  //#endregion
81
81
  //#region src/providers/SchedulerDescriptorProvider.d.ts
82
- declare const envSchema: _alepha_core2.TObject<{
83
- SCHEDULER_PREFIX: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
82
+ declare const envSchema: _alepha_core0.TObject<{
83
+ SCHEDULER_PREFIX: _alepha_core0.TOptional<_alepha_core0.TString>;
84
84
  }>;
85
85
  declare module "alepha" {
86
86
  interface Env extends Partial<Static<typeof envSchema>> {}
87
87
  }
88
88
  declare class SchedulerDescriptorProvider {
89
- protected readonly log: _alepha_core2.Logger;
89
+ protected readonly log: _alepha_core0.Logger;
90
90
  protected readonly env: {
91
91
  SCHEDULER_PREFIX?: string | undefined;
92
92
  };
@@ -94,9 +94,9 @@ declare class SchedulerDescriptorProvider {
94
94
  protected readonly dateTimeProvider: DateTimeProvider;
95
95
  protected readonly cronProvider: CronProvider;
96
96
  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">;
97
+ protected readonly configure: _alepha_core0.HookDescriptor<"configure">;
98
+ protected readonly start: _alepha_core0.HookDescriptor<"start">;
99
+ protected readonly stop: _alepha_core0.HookDescriptor<"stop">;
100
100
  /**
101
101
  * Get the schedulers.
102
102
  */
@@ -154,6 +154,8 @@ declare class AlephaScheduler {
154
154
  readonly name = "alepha.scheduler";
155
155
  readonly $services: (alepha: Alepha) => Alepha;
156
156
  }
157
+ //# sourceMappingURL=index.d.ts.map
158
+
157
159
  //#endregion
158
160
  export { $scheduler, AlephaScheduler, Scheduler, SchedulerDescriptor, SchedulerDescriptorOptions, SchedulerDescriptorProvider, SchedulerHandlerArguments, isScheduler };
159
161
  //# 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,16 +36,18 @@ 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";
@@ -102,26 +103,28 @@ interface UserAccountToken extends UserAccountInfo {
102
103
  */
103
104
  ownership?: string | boolean;
104
105
  }
106
+ //# sourceMappingURL=UserAccountToken.d.ts.map
105
107
  //#endregion
106
108
  //#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>>;
109
+ declare const roleSchema: _sinclair_typebox1.TObject<{
110
+ name: _sinclair_typebox1.TString;
111
+ description: _sinclair_typebox1.TOptional<_sinclair_typebox1.TString>;
112
+ default: _sinclair_typebox1.TOptional<_sinclair_typebox1.TBoolean>;
113
+ permissions: _sinclair_typebox1.TArray<_sinclair_typebox1.TObject<{
114
+ name: _sinclair_typebox1.TString;
115
+ ownership: _sinclair_typebox1.TOptional<_sinclair_typebox1.TBoolean>;
116
+ exclude: _sinclair_typebox1.TOptional<_sinclair_typebox1.TArray<_sinclair_typebox1.TString>>;
115
117
  }>>;
116
118
  }>;
117
119
  type Role = Static<typeof roleSchema>;
120
+ //# sourceMappingURL=roleSchema.d.ts.map
118
121
  //#endregion
119
122
  //#region src/providers/JwtProvider.d.ts
120
123
  /**
121
124
  * Provides utilities for working with JSON Web Tokens (JWT).
122
125
  */
123
126
  declare class JwtProvider {
124
- protected readonly log: _alepha_core7.Logger;
127
+ protected readonly log: _alepha_core15.Logger;
125
128
  protected readonly keystore: KeyLoaderHolder[];
126
129
  protected readonly dateTimeProvider: DateTimeProvider;
127
130
  /**
@@ -202,10 +205,11 @@ interface JwtParseResult {
202
205
  keyName: string;
203
206
  result: JWTVerifyResult<ExtendedJWTPayload>;
204
207
  }
208
+ //# sourceMappingURL=JwtProvider.d.ts.map
205
209
  //#endregion
206
210
  //#region src/providers/SecurityProvider.d.ts
207
- declare const envSchema: _alepha_core2.TObject<{
208
- SECURITY_SECRET_KEY: _sinclair_typebox1.TString;
211
+ declare const envSchema: _alepha_core16.TObject<{
212
+ SECURITY_SECRET_KEY: _alepha_core16.TString;
209
213
  }>;
210
214
  declare module "alepha" {
211
215
  interface Env extends Partial<Static<typeof envSchema>> {}
@@ -214,7 +218,7 @@ declare class SecurityProvider {
214
218
  protected readonly UNKNOWN_USER_NAME = "Unknown User";
215
219
  protected readonly PERMISSION_REGEXP: RegExp;
216
220
  protected readonly PERMISSION_REGEXP_WILDCARD: RegExp;
217
- protected readonly log: _alepha_core2.Logger;
221
+ protected readonly log: _alepha_core16.Logger;
218
222
  protected readonly jwt: JwtProvider;
219
223
  protected readonly env: {
220
224
  SECURITY_SECRET_KEY: string;
@@ -232,7 +236,7 @@ declare class SecurityProvider {
232
236
  * Create realms.
233
237
  */
234
238
  protected createRealms(): Realm[];
235
- protected configure: _alepha_core2.HookDescriptor<"configure">;
239
+ protected configure: _alepha_core16.HookDescriptor<"configure">;
236
240
  /**
237
241
  * Processes all $permission descriptors.
238
242
  */
@@ -245,7 +249,7 @@ declare class SecurityProvider {
245
249
  * Processes all $role descriptors.
246
250
  */
247
251
  protected processRoleDescriptors(): void;
248
- protected ready: _alepha_core2.HookDescriptor<"ready">;
252
+ protected ready: _alepha_core16.HookDescriptor<"ready">;
249
253
  /**
250
254
  * Updates the roles for a realm then synchronizes the user account provider if available.
251
255
  *
@@ -482,7 +486,7 @@ declare const $role: {
482
486
  *
483
487
  * @example
484
488
  * ```ts
485
- * import { $serviceAccount } from "@alepha/security";
489
+ * import { $serviceAccount } from "alepha/security";
486
490
  *
487
491
  * class MyService {
488
492
  * serviceAccount = $serviceAccount({
@@ -539,20 +543,24 @@ interface AccessTokenResponse {
539
543
  interface ServiceAccountStore {
540
544
  response?: AccessTokenResponse;
541
545
  }
546
+ //# sourceMappingURL=$serviceAccount.d.ts.map
542
547
  //#endregion
543
548
  //#region src/errors/InvalidPermissionError.d.ts
544
549
  declare class InvalidPermissionError extends Error {
545
550
  constructor(name: string);
546
551
  }
552
+ //# sourceMappingURL=InvalidPermissionError.d.ts.map
547
553
  //#endregion
548
554
  //#region src/errors/SecurityError.d.ts
549
555
  declare class SecurityError extends Error {
550
556
  readonly status = 403;
551
557
  readonly code = "ERR_SECURITY";
552
558
  }
559
+ //# sourceMappingURL=SecurityError.d.ts.map
560
+
553
561
  //#endregion
554
562
  //#region src/index.d.ts
555
- declare module "alepha/core" {
563
+ declare module "alepha" {
556
564
  interface Hooks {
557
565
  "security:user:created": {
558
566
  realm: string;
@@ -564,6 +572,8 @@ declare class AlephaSecurity {
564
572
  readonly name = "alepha.security";
565
573
  readonly $services: (alepha: Alepha) => Alepha;
566
574
  }
575
+ //# sourceMappingURL=index.d.ts.map
576
+
567
577
  //#endregion
568
578
  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
579
  //# sourceMappingURL=index.d.ts.map
package/server/cache.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { Cache, CacheDescriptorOptions, CacheDescriptorProvider } from "@alepha/cache";
2
- import { ServerHandler, ServerRequestConfig } from "@alepha/server";
3
- import * as _alepha_core1 from "@alepha/core";
4
- import { Alepha, Module, OPTIONS } from "@alepha/core";
5
- import { DateTimeProvider, DurationLike } from "@alepha/datetime";
1
+ import { Cache, CacheDescriptorOptions, CacheDescriptorProvider } from "alepha/cache";
2
+ import { ServerHandler, ServerRequestConfig } from "alepha/server";
3
+ import * as _alepha_core1 from "alepha";
4
+ import { Alepha, Module, OPTIONS } from "alepha";
5
+ import { DateTimeProvider, DurationLike } from "alepha/datetime";
6
6
 
7
7
  //#region src/providers/ServerCacheProvider.d.ts
8
8
  declare module "alepha/server" {
@@ -80,6 +80,8 @@ declare class AlephaServerCache implements Module {
80
80
  readonly name = "alepha.server.cache";
81
81
  readonly $services: (alepha: Alepha) => Alepha;
82
82
  }
83
+ //# sourceMappingURL=index.d.ts.map
84
+
83
85
  //#endregion
84
86
  export { AlephaServerCache, ServerCacheProvider, ServerRouteCache };
85
87
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+ var m = require('@alepha/server-compress');
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
+ });
@@ -0,0 +1,26 @@
1
+ import { ServerResponse } from "alepha/server";
2
+ import { Transform } from "node:stream";
3
+ import { Alepha, HookDescriptor, Module } from "alepha";
4
+
5
+ //#region src/providers/ServerCompressProvider.d.ts
6
+ declare class ServerCompressProvider {
7
+ compressors: Record<string, {
8
+ compress: (...args: any[]) => Promise<Buffer>;
9
+ stream: (options?: any) => Transform;
10
+ } | undefined>;
11
+ readonly onResponse: HookDescriptor<"server:onResponse">;
12
+ protected isAllowedContentType(contentType: string | undefined): boolean;
13
+ protected compress(encoding: keyof typeof (void 0).compressors, response: ServerResponse): Promise<void>;
14
+ protected getParams(encoding: keyof typeof (void 0).compressors): Record<number, any>;
15
+ protected setHeaders(response: ServerResponse, encoding: keyof typeof (void 0).compressors): void;
16
+ }
17
+ //#endregion
18
+ //#region src/index.d.ts
19
+ // ---------------------------------------------------------------------------------------------------------------------
20
+ declare class AlephaServerCompress implements Module {
21
+ readonly name = "alepha.server.compress";
22
+ readonly $services: (alepha: Alepha) => void;
23
+ }
24
+ //#endregion
25
+ export { AlephaServerCompress, ServerCompressProvider };
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ export * from '@alepha/server-compress'
@@ -1,32 +1,59 @@
1
- import * as _alepha_core1 from "@alepha/core";
2
- import { KIND, OPTIONS, Static, TSchema } from "@alepha/core";
3
- import { DurationLike } from "@alepha/datetime";
1
+ import { Alepha, HookDescriptor, KIND, Logger, Module, OPTIONS, Static, TObject, TOptional, TSchema, TString } from "alepha";
2
+ import { DateTimeProvider, DurationLike } from "alepha/datetime";
4
3
 
5
4
  //#region src/descriptors/$cookie.d.ts
5
+ declare const KEY = "COOKIE";
6
6
  interface CookieDescriptorOptions<T extends TSchema> {
7
+ /** The schema for the cookie's value, used for validation and type safety. */
7
8
  schema: T;
8
- name: string;
9
+ /** The name of the cookie. */
10
+ name?: string;
11
+ /** The cookie's path. Defaults to "/". */
9
12
  path?: string;
13
+ /** Time-to-live for the cookie. Maps to `Max-Age`. */
10
14
  ttl?: DurationLike;
15
+ /** If true, the cookie is only sent over HTTPS. Defaults to true in production. */
11
16
  secure?: boolean;
17
+ /** If true, the cookie cannot be accessed by client-side scripts. */
12
18
  httpOnly?: boolean;
19
+ /** SameSite policy for the cookie. Defaults to "lax". */
13
20
  sameSite?: "strict" | "lax" | "none";
21
+ /** The domain for the cookie. */
14
22
  domain?: string;
23
+ /** If true, the cookie value will be compressed using zlib. */
15
24
  compress?: boolean;
25
+ /** If true, the cookie value will be encrypted. Requires `COOKIE_SECRET` env var. */
16
26
  encrypt?: boolean;
27
+ /** If true, the cookie will be signed to prevent tampering. Requires `COOKIE_SECRET` env var. */
17
28
  sign?: boolean;
18
29
  }
19
30
  interface CookieDescriptor<T extends TSchema> {
20
- [KIND]: "COOKIE";
31
+ [KIND]: typeof KEY;
21
32
  [OPTIONS]: CookieDescriptorOptions<T>;
22
- set: (cookies: Cookies, value: Static<T>) => void;
23
- get: (cookies: Cookies) => Static<T> | undefined;
24
- del: (cookies: Cookies) => void;
33
+ schema: T;
34
+ /** Sets the cookie with the given value in the current request's response. */
35
+ set: (value: Static<T>, options?: {
36
+ cookies?: Cookies;
37
+ }) => void;
38
+ /** Gets the cookie value from the current request. Returns undefined if not found or invalid. */
39
+ get: (options?: {
40
+ cookies?: Cookies;
41
+ }) => Static<T> | undefined;
42
+ /** Deletes the cookie in the current request's response. */
43
+ del: (options?: {
44
+ cookies?: Cookies;
45
+ }) => void;
25
46
  }
47
+ /**
48
+ * Declares a type-safe, configurable HTTP cookie.
49
+ * This descriptor provides methods to get, set, and delete the cookie
50
+ * within the server request/response cycle.
51
+ */
26
52
  declare const $cookie: {
27
53
  <T extends TSchema>(options: CookieDescriptorOptions<T>): CookieDescriptor<T>;
28
54
  [KIND]: string;
29
55
  };
56
+ // ---------------------------------------------------------------------------------------------------------------------
30
57
  interface Cookies {
31
58
  req: Record<string, string>;
32
59
  res: Record<string, Cookie | null>;
@@ -42,22 +69,49 @@ interface Cookie {
42
69
  }
43
70
  //#endregion
44
71
  //#region src/providers/ServerCookiesProvider.d.ts
72
+ declare const envSchema: TObject<{
73
+ COOKIE_SECRET: TOptional<TString>;
74
+ }>;
75
+ declare module "alepha" {
76
+ interface Env extends Partial<Static<typeof envSchema>> {}
77
+ }
45
78
  declare class ServerCookiesProvider {
46
- readonly onRequest: _alepha_core1.HookDescriptor<"server:onRequest">;
47
- readonly onSend: _alepha_core1.HookDescriptor<"server:onSend">;
48
- fromHeader(header: string): Record<string, string>;
49
- toHeader(cookies: Record<string, Cookie | null>, isHttps?: boolean): string[];
79
+ protected readonly alepha: Alepha;
80
+ protected readonly log: Logger;
81
+ protected readonly env: Static<typeof envSchema>;
82
+ protected readonly dateTimeProvider: DateTimeProvider;
83
+ // Crypto constants
84
+ protected readonly ALGORITHM = "aes-256-gcm";
85
+ protected readonly IV_LENGTH = 16;
86
+ protected readonly AUTH_TAG_LENGTH = 16;
87
+ protected readonly SIGNATURE_LENGTH = 32;
88
+ protected readonly configure: HookDescriptor<"configure">;
89
+ protected createApi<T extends TSchema>(name: string, options: CookieDescriptorOptions<T>): CookieDescriptor<T>;
90
+ readonly onRequest: HookDescriptor<"server:onRequest">;
91
+ readonly onSend: HookDescriptor<"server:onSend">;
92
+ protected getCookiesFromContext(cookies?: Cookies): Cookies;
93
+ protected getCookie<T extends TSchema>(name: string, options: CookieDescriptorOptions<T>, contextCookies?: Cookies): Static<T> | undefined;
94
+ protected setCookie<T extends TSchema>(name: string, options: CookieDescriptorOptions<T>, data: Static<T>, contextCookies?: Cookies): void;
95
+ protected deleteCookie<T extends TSchema>(name: string, contextCookies?: Cookies): void;
96
+ // --- Crypto & Parsing ---
97
+ protected encrypt(text: string): string;
98
+ protected decrypt(encryptedText: string): string;
99
+ secretKey(): string;
100
+ protected sign(data: string): string;
101
+ protected parseRequestCookies(header: string): Record<string, string>;
102
+ protected serializeResponseCookies(cookies: Record<string, Cookie | null>, isHttps: boolean): string[];
50
103
  }
51
104
  //#endregion
52
105
  //#region src/index.d.ts
106
+ // ---------------------------------------------------------------------------------------------------------------------
53
107
  declare module "alepha/server" {
54
108
  interface ServerRequest {
55
109
  cookies: Cookies;
56
110
  }
57
111
  }
58
- declare class AlephaServerCookies {
112
+ declare class AlephaServerCookies implements Module {
59
113
  readonly name = "alepha.server.cookies";
60
- readonly $services: (alepha: any) => void;
114
+ readonly $services: (alepha: Alepha) => void;
61
115
  }
62
116
  //#endregion
63
117
  export { $cookie, AlephaServerCookies, Cookie, CookieDescriptor, CookieDescriptorOptions, Cookies, ServerCookiesProvider };
package/server/cors.d.ts CHANGED
@@ -1,12 +1,15 @@
1
- import * as _alepha_core0 from "@alepha/core";
2
- import { Alepha, Module } from "@alepha/core";
1
+ import { ServerRouterProvider } from "alepha/server";
2
+ import { Alepha, HookDescriptor, Module } from "alepha";
3
3
 
4
4
  //#region src/providers/ServerCorsProvider.d.ts
5
5
  declare class ServerCorsProvider {
6
+ protected readonly serverRouterProvider: ServerRouterProvider;
6
7
  options: CorsOptions;
7
- protected readonly onRequest: _alepha_core0.HookDescriptor<"server:onRequest">;
8
+ protected readonly onRoute: HookDescriptor<"server:onRoute">;
9
+ protected readonly onRequest: HookDescriptor<"server:onRequest">;
8
10
  isOriginAllowed(origin: string | undefined, allowed: CorsOptions["origin"]): boolean;
9
11
  }
12
+ // ---------------------------------------------------------------------------------------------------------------------
10
13
  interface CorsOptions {
11
14
  origin?: string | string[] | ((origin: string | undefined) => boolean);
12
15
  methods: string[];
@@ -16,6 +19,7 @@ interface CorsOptions {
16
19
  }
17
20
  //#endregion
18
21
  //#region src/index.d.ts
22
+ // ---------------------------------------------------------------------------------------------------------------------
19
23
  declare class AlephaServerCors implements Module {
20
24
  readonly name = "alepha.server.cors";
21
25
  readonly $services: (alepha: Alepha) => void;
@@ -1,41 +1,41 @@
1
- import * as _alepha_server5 from "@alepha/server";
2
- import { Alepha } from "@alepha/core";
3
- import { DateTimeProvider } from "@alepha/datetime";
4
- import * as _sinclair_typebox0 from "@sinclair/typebox";
1
+ import { RouteDescriptor } from "alepha/server";
2
+ import { Alepha, TBoolean, TNumber, TObject, TString } from "alepha";
3
+ import { DateTimeProvider } from "alepha/datetime";
5
4
 
6
5
  //#region src/providers/ServerHealthProvider.d.ts
7
6
 
8
7
  /**
9
- * Register `/health` endpoint.
10
- *
11
- * - Provides basic health information about the server.
12
- */
8
+ * Register `/health` endpoint.
9
+ *
10
+ * - Provides basic health information about the server.
11
+ */
13
12
  declare class ServerHealthProvider {
14
- protected readonly dateTimeProvider: DateTimeProvider;
13
+ protected readonly time: DateTimeProvider;
15
14
  protected readonly alepha: Alepha;
16
- readonly health: _alepha_server5.RouteDescriptor<{
17
- response: _sinclair_typebox0.TObject<{
18
- message: _sinclair_typebox0.TString;
19
- uptime: _sinclair_typebox0.TNumber;
20
- date: _sinclair_typebox0.TString;
21
- ready: _sinclair_typebox0.TBoolean;
15
+ readonly health: RouteDescriptor<{
16
+ response: TObject<{
17
+ message: TString;
18
+ uptime: TNumber;
19
+ date: TString;
20
+ ready: TBoolean;
22
21
  }>;
23
22
  }>;
24
23
  }
25
24
  //#endregion
26
25
  //#region src/index.d.ts
26
+ // ---------------------------------------------------------------------------------------------------------------------
27
27
  /**
28
- * Alepha Server Health Module
29
- *
30
- * @description
31
- * Plugin for Alepha Server that provides health-check endpoints.
32
- *
33
- * @see {@link ServerHealthProvider}
34
- * @module alepha.server.health
35
- */
28
+ * Alepha Server Health Module
29
+ *
30
+ * @description
31
+ * Plugin for Alepha Server that provides health-check endpoints.
32
+ *
33
+ * @see {@link ServerHealthProvider}
34
+ * @module alepha.server.health
35
+ */
36
36
  declare class AlephaServerHealth {
37
37
  readonly name = "alepha.server.health";
38
- readonly $services: (alepha: any) => void;
38
+ readonly $services: (alepha: Alepha) => void;
39
39
  }
40
40
  //#endregion
41
41
  export { AlephaServerHealth, ServerHealthProvider };
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+ var m = require('@alepha/server-helmet');
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
+ });