alepha 0.7.6 → 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/LICENSE +21 -21
- package/README.md +44 -44
- package/batch.cjs +8 -0
- package/batch.d.ts +114 -0
- package/batch.js +1 -0
- package/cache/redis.d.ts +15 -18
- package/cache.d.ts +115 -119
- package/command.cjs +8 -0
- package/command.d.ts +154 -0
- package/command.js +1 -0
- package/core.d.ts +800 -795
- package/datetime.d.ts +76 -76
- package/lock/redis.d.ts +12 -12
- package/lock.d.ts +70 -75
- package/package.json +102 -29
- package/postgres.d.ts +385 -278
- package/queue/redis.d.ts +15 -13
- package/queue.d.ts +16 -13
- package/react/auth.d.ts +16 -16
- package/react/head.cjs +8 -0
- package/react/head.d.ts +92 -0
- package/react/head.js +1 -0
- package/react.d.ts +90 -116
- package/redis.d.ts +20 -27
- package/retry.d.ts +74 -54
- package/scheduler.d.ts +14 -13
- package/security.d.ts +38 -41
- package/server/cache.d.ts +9 -7
- package/server/compress.cjs +8 -0
- package/server/compress.d.ts +26 -0
- package/server/compress.js +1 -0
- package/server/cookies.d.ts +71 -14
- package/server/cors.cjs +8 -0
- package/server/cors.d.ts +29 -0
- package/server/cors.js +1 -0
- package/server/health.cjs +8 -0
- package/server/health.d.ts +42 -0
- package/server/health.js +1 -0
- package/server/helmet.cjs +8 -0
- package/server/helmet.d.ts +72 -0
- package/server/helmet.js +1 -0
- package/server/links.cjs +8 -0
- package/server/links.d.ts +179 -0
- package/server/links.js +1 -0
- package/server/metrics.cjs +8 -0
- package/server/metrics.d.ts +37 -0
- package/server/metrics.js +1 -0
- package/server/multipart.cjs +8 -0
- package/server/multipart.d.ts +48 -0
- package/server/multipart.js +1 -0
- package/server/proxy.cjs +8 -0
- package/server/proxy.d.ts +41 -0
- package/server/proxy.js +1 -0
- package/server/static.d.ts +63 -51
- package/server/swagger.d.ts +50 -50
- package/server.d.ts +220 -437
- package/topic/redis.d.ts +24 -23
- package/topic.d.ts +9 -19
- package/vite.d.ts +8 -1
package/scheduler.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import * as _alepha_core9 from "
|
|
2
|
-
import * as
|
|
3
|
-
import { Alepha, Async, KIND, OPTIONS, Static } from "
|
|
4
|
-
import * as _alepha_lock8 from "
|
|
5
|
-
import { DateTime, DateTimeProvider, DurationLike, Interval } from "
|
|
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:
|
|
83
|
-
SCHEDULER_PREFIX:
|
|
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:
|
|
89
|
+
protected readonly log: _alepha_core0.Logger;
|
|
90
90
|
protected readonly env: {
|
|
91
91
|
SCHEDULER_PREFIX?: string | undefined;
|
|
92
92
|
};
|
|
@@ -94,10 +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:
|
|
98
|
-
protected readonly start:
|
|
99
|
-
protected readonly stop:
|
|
100
|
-
protected createContextId(): string;
|
|
97
|
+
protected readonly configure: _alepha_core0.HookDescriptor<"configure">;
|
|
98
|
+
protected readonly start: _alepha_core0.HookDescriptor<"start">;
|
|
99
|
+
protected readonly stop: _alepha_core0.HookDescriptor<"stop">;
|
|
101
100
|
/**
|
|
102
101
|
* Get the schedulers.
|
|
103
102
|
*/
|
|
@@ -155,6 +154,8 @@ declare class AlephaScheduler {
|
|
|
155
154
|
readonly name = "alepha.scheduler";
|
|
156
155
|
readonly $services: (alepha: Alepha) => Alepha;
|
|
157
156
|
}
|
|
157
|
+
//# sourceMappingURL=index.d.ts.map
|
|
158
|
+
|
|
158
159
|
//#endregion
|
|
159
160
|
export { $scheduler, AlephaScheduler, Scheduler, SchedulerDescriptor, SchedulerDescriptorOptions, SchedulerDescriptorProvider, SchedulerHandlerArguments, isScheduler };
|
|
160
161
|
//# sourceMappingURL=index.d.ts.map
|
package/security.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
3
|
-
import { Alepha, KIND, OPTIONS, Static } from "
|
|
4
|
-
import { DateTimeProvider } from "
|
|
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
|
|
7
|
-
import * as _sinclair_typebox20 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,17 +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:
|
|
43
|
-
name:
|
|
44
|
-
group:
|
|
45
|
-
description:
|
|
46
|
-
method:
|
|
47
|
-
path:
|
|
48
|
-
contentType: _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>;
|
|
49
48
|
}>;
|
|
50
49
|
type Permission = Static<typeof permissionSchema>;
|
|
50
|
+
//# sourceMappingURL=permissionSchema.d.ts.map
|
|
51
51
|
//#endregion
|
|
52
52
|
//#region src/descriptors/$permission.d.ts
|
|
53
53
|
declare const KEY$2 = "PERMISSION";
|
|
@@ -96,9 +96,6 @@ interface UserAccountToken extends UserAccountInfo {
|
|
|
96
96
|
* Access token for the user.
|
|
97
97
|
*/
|
|
98
98
|
token?: string;
|
|
99
|
-
/**
|
|
100
|
-
*
|
|
101
|
-
*/
|
|
102
99
|
realm?: string;
|
|
103
100
|
/**
|
|
104
101
|
* Is user dedicated to his own resources for this scope ?
|
|
@@ -106,26 +103,28 @@ interface UserAccountToken extends UserAccountInfo {
|
|
|
106
103
|
*/
|
|
107
104
|
ownership?: string | boolean;
|
|
108
105
|
}
|
|
106
|
+
//# sourceMappingURL=UserAccountToken.d.ts.map
|
|
109
107
|
//#endregion
|
|
110
108
|
//#region src/schemas/roleSchema.d.ts
|
|
111
|
-
declare const roleSchema:
|
|
112
|
-
name:
|
|
113
|
-
description:
|
|
114
|
-
default:
|
|
115
|
-
permissions:
|
|
116
|
-
name:
|
|
117
|
-
ownership:
|
|
118
|
-
exclude:
|
|
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>>;
|
|
119
117
|
}>>;
|
|
120
118
|
}>;
|
|
121
119
|
type Role = Static<typeof roleSchema>;
|
|
120
|
+
//# sourceMappingURL=roleSchema.d.ts.map
|
|
122
121
|
//#endregion
|
|
123
122
|
//#region src/providers/JwtProvider.d.ts
|
|
124
123
|
/**
|
|
125
124
|
* Provides utilities for working with JSON Web Tokens (JWT).
|
|
126
125
|
*/
|
|
127
126
|
declare class JwtProvider {
|
|
128
|
-
protected readonly log:
|
|
127
|
+
protected readonly log: _alepha_core15.Logger;
|
|
129
128
|
protected readonly keystore: KeyLoaderHolder[];
|
|
130
129
|
protected readonly dateTimeProvider: DateTimeProvider;
|
|
131
130
|
/**
|
|
@@ -206,10 +205,11 @@ interface JwtParseResult {
|
|
|
206
205
|
keyName: string;
|
|
207
206
|
result: JWTVerifyResult<ExtendedJWTPayload>;
|
|
208
207
|
}
|
|
208
|
+
//# sourceMappingURL=JwtProvider.d.ts.map
|
|
209
209
|
//#endregion
|
|
210
210
|
//#region src/providers/SecurityProvider.d.ts
|
|
211
|
-
declare const envSchema:
|
|
212
|
-
SECURITY_SECRET_KEY:
|
|
211
|
+
declare const envSchema: _alepha_core16.TObject<{
|
|
212
|
+
SECURITY_SECRET_KEY: _alepha_core16.TString;
|
|
213
213
|
}>;
|
|
214
214
|
declare module "alepha" {
|
|
215
215
|
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
@@ -218,7 +218,7 @@ declare class SecurityProvider {
|
|
|
218
218
|
protected readonly UNKNOWN_USER_NAME = "Unknown User";
|
|
219
219
|
protected readonly PERMISSION_REGEXP: RegExp;
|
|
220
220
|
protected readonly PERMISSION_REGEXP_WILDCARD: RegExp;
|
|
221
|
-
protected readonly log:
|
|
221
|
+
protected readonly log: _alepha_core16.Logger;
|
|
222
222
|
protected readonly jwt: JwtProvider;
|
|
223
223
|
protected readonly env: {
|
|
224
224
|
SECURITY_SECRET_KEY: string;
|
|
@@ -236,7 +236,7 @@ declare class SecurityProvider {
|
|
|
236
236
|
* Create realms.
|
|
237
237
|
*/
|
|
238
238
|
protected createRealms(): Realm[];
|
|
239
|
-
protected configure:
|
|
239
|
+
protected configure: _alepha_core16.HookDescriptor<"configure">;
|
|
240
240
|
/**
|
|
241
241
|
* Processes all $permission descriptors.
|
|
242
242
|
*/
|
|
@@ -249,7 +249,7 @@ declare class SecurityProvider {
|
|
|
249
249
|
* Processes all $role descriptors.
|
|
250
250
|
*/
|
|
251
251
|
protected processRoleDescriptors(): void;
|
|
252
|
-
protected ready:
|
|
252
|
+
protected ready: _alepha_core16.HookDescriptor<"ready">;
|
|
253
253
|
/**
|
|
254
254
|
* Updates the roles for a realm then synchronizes the user account provider if available.
|
|
255
255
|
*
|
|
@@ -361,13 +361,7 @@ declare class SecurityProvider {
|
|
|
361
361
|
* A realm definition.
|
|
362
362
|
*/
|
|
363
363
|
interface Realm {
|
|
364
|
-
/**
|
|
365
|
-
*
|
|
366
|
-
*/
|
|
367
364
|
name: string;
|
|
368
|
-
/**
|
|
369
|
-
*
|
|
370
|
-
*/
|
|
371
365
|
roles: Role[];
|
|
372
366
|
/**
|
|
373
367
|
* The secret key for the realm.
|
|
@@ -464,9 +458,6 @@ interface RoleDescriptorOptions {
|
|
|
464
458
|
* Describe the role.
|
|
465
459
|
*/
|
|
466
460
|
description?: string;
|
|
467
|
-
/**
|
|
468
|
-
*
|
|
469
|
-
*/
|
|
470
461
|
permissions?: Array<string | {
|
|
471
462
|
name: string;
|
|
472
463
|
ownership?: boolean;
|
|
@@ -495,7 +486,7 @@ declare const $role: {
|
|
|
495
486
|
*
|
|
496
487
|
* @example
|
|
497
488
|
* ```ts
|
|
498
|
-
* import { $serviceAccount } from "
|
|
489
|
+
* import { $serviceAccount } from "alepha/security";
|
|
499
490
|
*
|
|
500
491
|
* class MyService {
|
|
501
492
|
* serviceAccount = $serviceAccount({
|
|
@@ -552,20 +543,24 @@ interface AccessTokenResponse {
|
|
|
552
543
|
interface ServiceAccountStore {
|
|
553
544
|
response?: AccessTokenResponse;
|
|
554
545
|
}
|
|
546
|
+
//# sourceMappingURL=$serviceAccount.d.ts.map
|
|
555
547
|
//#endregion
|
|
556
548
|
//#region src/errors/InvalidPermissionError.d.ts
|
|
557
549
|
declare class InvalidPermissionError extends Error {
|
|
558
550
|
constructor(name: string);
|
|
559
551
|
}
|
|
552
|
+
//# sourceMappingURL=InvalidPermissionError.d.ts.map
|
|
560
553
|
//#endregion
|
|
561
554
|
//#region src/errors/SecurityError.d.ts
|
|
562
555
|
declare class SecurityError extends Error {
|
|
563
556
|
readonly status = 403;
|
|
564
557
|
readonly code = "ERR_SECURITY";
|
|
565
558
|
}
|
|
559
|
+
//# sourceMappingURL=SecurityError.d.ts.map
|
|
560
|
+
|
|
566
561
|
//#endregion
|
|
567
562
|
//#region src/index.d.ts
|
|
568
|
-
declare module "alepha
|
|
563
|
+
declare module "alepha" {
|
|
569
564
|
interface Hooks {
|
|
570
565
|
"security:user:created": {
|
|
571
566
|
realm: string;
|
|
@@ -577,6 +572,8 @@ declare class AlephaSecurity {
|
|
|
577
572
|
readonly name = "alepha.security";
|
|
578
573
|
readonly $services: (alepha: Alepha) => Alepha;
|
|
579
574
|
}
|
|
575
|
+
//# sourceMappingURL=index.d.ts.map
|
|
576
|
+
|
|
580
577
|
//#endregion
|
|
581
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 };
|
|
582
579
|
//# sourceMappingURL=index.d.ts.map
|
package/server/cache.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Cache, CacheDescriptorOptions, CacheDescriptorProvider } from "
|
|
2
|
-
import { ServerHandler, ServerRequestConfig } from "
|
|
3
|
-
import * as _alepha_core1 from "
|
|
4
|
-
import { Alepha, Module, OPTIONS } from "
|
|
5
|
-
import { DateTimeProvider, DurationLike } from "
|
|
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" {
|
|
@@ -55,8 +55,8 @@ type RouteLike = {
|
|
|
55
55
|
*
|
|
56
56
|
* @example
|
|
57
57
|
* ```ts
|
|
58
|
-
* import { Alepha } from "
|
|
59
|
-
* import { $action } from "
|
|
58
|
+
* import { Alepha } from "alepha";
|
|
59
|
+
* import { $action } from "alepha/server";
|
|
60
60
|
* import { AlephaServerCache } from "alepha/server/cache";
|
|
61
61
|
*
|
|
62
62
|
* class ApiServer {
|
|
@@ -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'
|
package/server/cookies.d.ts
CHANGED
|
@@ -1,33 +1,59 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { DurationLike } from "@alepha/datetime";
|
|
4
|
-
import "@alepha/server";
|
|
1
|
+
import { Alepha, HookDescriptor, KIND, Logger, Module, OPTIONS, Static, TObject, TOptional, TSchema, TString } from "alepha";
|
|
2
|
+
import { DateTimeProvider, DurationLike } from "alepha/datetime";
|
|
5
3
|
|
|
6
4
|
//#region src/descriptors/$cookie.d.ts
|
|
5
|
+
declare const KEY = "COOKIE";
|
|
7
6
|
interface CookieDescriptorOptions<T extends TSchema> {
|
|
7
|
+
/** The schema for the cookie's value, used for validation and type safety. */
|
|
8
8
|
schema: T;
|
|
9
|
-
name
|
|
9
|
+
/** The name of the cookie. */
|
|
10
|
+
name?: string;
|
|
11
|
+
/** The cookie's path. Defaults to "/". */
|
|
10
12
|
path?: string;
|
|
13
|
+
/** Time-to-live for the cookie. Maps to `Max-Age`. */
|
|
11
14
|
ttl?: DurationLike;
|
|
15
|
+
/** If true, the cookie is only sent over HTTPS. Defaults to true in production. */
|
|
12
16
|
secure?: boolean;
|
|
17
|
+
/** If true, the cookie cannot be accessed by client-side scripts. */
|
|
13
18
|
httpOnly?: boolean;
|
|
19
|
+
/** SameSite policy for the cookie. Defaults to "lax". */
|
|
14
20
|
sameSite?: "strict" | "lax" | "none";
|
|
21
|
+
/** The domain for the cookie. */
|
|
15
22
|
domain?: string;
|
|
23
|
+
/** If true, the cookie value will be compressed using zlib. */
|
|
16
24
|
compress?: boolean;
|
|
25
|
+
/** If true, the cookie value will be encrypted. Requires `COOKIE_SECRET` env var. */
|
|
17
26
|
encrypt?: boolean;
|
|
27
|
+
/** If true, the cookie will be signed to prevent tampering. Requires `COOKIE_SECRET` env var. */
|
|
18
28
|
sign?: boolean;
|
|
19
29
|
}
|
|
20
30
|
interface CookieDescriptor<T extends TSchema> {
|
|
21
|
-
[KIND]:
|
|
31
|
+
[KIND]: typeof KEY;
|
|
22
32
|
[OPTIONS]: CookieDescriptorOptions<T>;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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;
|
|
26
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
|
+
*/
|
|
27
52
|
declare const $cookie: {
|
|
28
53
|
<T extends TSchema>(options: CookieDescriptorOptions<T>): CookieDescriptor<T>;
|
|
29
54
|
[KIND]: string;
|
|
30
55
|
};
|
|
56
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
31
57
|
interface Cookies {
|
|
32
58
|
req: Record<string, string>;
|
|
33
59
|
res: Record<string, Cookie | null>;
|
|
@@ -43,19 +69,50 @@ interface Cookie {
|
|
|
43
69
|
}
|
|
44
70
|
//#endregion
|
|
45
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
|
+
}
|
|
46
78
|
declare class ServerCookiesProvider {
|
|
47
|
-
readonly
|
|
48
|
-
readonly
|
|
49
|
-
|
|
50
|
-
|
|
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[];
|
|
51
103
|
}
|
|
52
104
|
//#endregion
|
|
53
105
|
//#region src/index.d.ts
|
|
106
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
54
107
|
declare module "alepha/server" {
|
|
55
108
|
interface ServerRequest {
|
|
56
109
|
cookies: Cookies;
|
|
57
110
|
}
|
|
58
111
|
}
|
|
112
|
+
declare class AlephaServerCookies implements Module {
|
|
113
|
+
readonly name = "alepha.server.cookies";
|
|
114
|
+
readonly $services: (alepha: Alepha) => void;
|
|
115
|
+
}
|
|
59
116
|
//#endregion
|
|
60
|
-
export { $cookie, Cookie, CookieDescriptor, CookieDescriptorOptions, Cookies, ServerCookiesProvider };
|
|
117
|
+
export { $cookie, AlephaServerCookies, Cookie, CookieDescriptor, CookieDescriptorOptions, Cookies, ServerCookiesProvider };
|
|
61
118
|
//# sourceMappingURL=index.d.ts.map
|
package/server/cors.cjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var m = require('@alepha/server-cors');
|
|
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/server/cors.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ServerRouterProvider } from "alepha/server";
|
|
2
|
+
import { Alepha, HookDescriptor, Module } from "alepha";
|
|
3
|
+
|
|
4
|
+
//#region src/providers/ServerCorsProvider.d.ts
|
|
5
|
+
declare class ServerCorsProvider {
|
|
6
|
+
protected readonly serverRouterProvider: ServerRouterProvider;
|
|
7
|
+
options: CorsOptions;
|
|
8
|
+
protected readonly onRoute: HookDescriptor<"server:onRoute">;
|
|
9
|
+
protected readonly onRequest: HookDescriptor<"server:onRequest">;
|
|
10
|
+
isOriginAllowed(origin: string | undefined, allowed: CorsOptions["origin"]): boolean;
|
|
11
|
+
}
|
|
12
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
13
|
+
interface CorsOptions {
|
|
14
|
+
origin?: string | string[] | ((origin: string | undefined) => boolean);
|
|
15
|
+
methods: string[];
|
|
16
|
+
headers: string[];
|
|
17
|
+
credentials?: boolean;
|
|
18
|
+
maxAge?: number;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/index.d.ts
|
|
22
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
23
|
+
declare class AlephaServerCors implements Module {
|
|
24
|
+
readonly name = "alepha.server.cors";
|
|
25
|
+
readonly $services: (alepha: Alepha) => void;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { AlephaServerCors, CorsOptions, ServerCorsProvider };
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
package/server/cors.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@alepha/server-cors'
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var m = require('@alepha/server-health');
|
|
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,42 @@
|
|
|
1
|
+
import { RouteDescriptor } from "alepha/server";
|
|
2
|
+
import { Alepha, TBoolean, TNumber, TObject, TString } from "alepha";
|
|
3
|
+
import { DateTimeProvider } from "alepha/datetime";
|
|
4
|
+
|
|
5
|
+
//#region src/providers/ServerHealthProvider.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Register `/health` endpoint.
|
|
9
|
+
*
|
|
10
|
+
* - Provides basic health information about the server.
|
|
11
|
+
*/
|
|
12
|
+
declare class ServerHealthProvider {
|
|
13
|
+
protected readonly time: DateTimeProvider;
|
|
14
|
+
protected readonly alepha: Alepha;
|
|
15
|
+
readonly health: RouteDescriptor<{
|
|
16
|
+
response: TObject<{
|
|
17
|
+
message: TString;
|
|
18
|
+
uptime: TNumber;
|
|
19
|
+
date: TString;
|
|
20
|
+
ready: TBoolean;
|
|
21
|
+
}>;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/index.d.ts
|
|
26
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
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
|
+
*/
|
|
36
|
+
declare class AlephaServerHealth {
|
|
37
|
+
readonly name = "alepha.server.health";
|
|
38
|
+
readonly $services: (alepha: Alepha) => void;
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { AlephaServerHealth, ServerHealthProvider };
|
|
42
|
+
//# sourceMappingURL=index.d.ts.map
|
package/server/health.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@alepha/server-health'
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Alepha, HookDescriptor, Module } from "alepha";
|
|
2
|
+
|
|
3
|
+
//#region src/providers/ServerHelmetProvider.d.ts
|
|
4
|
+
type CspDirective = string | string[];
|
|
5
|
+
interface CspOptions {
|
|
6
|
+
directives: {
|
|
7
|
+
"default-src"?: CspDirective;
|
|
8
|
+
"script-src"?: CspDirective;
|
|
9
|
+
"style-src"?: CspDirective;
|
|
10
|
+
"img-src"?: CspDirective;
|
|
11
|
+
"connect-src"?: CspDirective;
|
|
12
|
+
"font-src"?: CspDirective;
|
|
13
|
+
"object-src"?: CspDirective;
|
|
14
|
+
"media-src"?: CspDirective;
|
|
15
|
+
"frame-src"?: CspDirective;
|
|
16
|
+
sandbox?: CspDirective | boolean;
|
|
17
|
+
"report-uri"?: string;
|
|
18
|
+
"child-src"?: CspDirective;
|
|
19
|
+
"form-action"?: CspDirective;
|
|
20
|
+
"frame-ancestors"?: CspDirective;
|
|
21
|
+
"plugin-types"?: CspDirective;
|
|
22
|
+
"base-uri"?: CspDirective;
|
|
23
|
+
[key: string]: CspDirective | undefined | boolean;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
interface HstsOptions {
|
|
27
|
+
maxAge?: number;
|
|
28
|
+
includeSubDomains?: boolean;
|
|
29
|
+
preload?: boolean;
|
|
30
|
+
}
|
|
31
|
+
interface HelmetOptions {
|
|
32
|
+
isSecure?: boolean;
|
|
33
|
+
strictTransportSecurity?: HstsOptions | false;
|
|
34
|
+
xContentTypeOptions?: false;
|
|
35
|
+
xFrameOptions?: "DENY" | "SAMEORIGIN" | false;
|
|
36
|
+
xXssProtection?: false;
|
|
37
|
+
contentSecurityPolicy?: CspOptions | false;
|
|
38
|
+
referrerPolicy?: "no-referrer" | "no-referrer-when-downgrade" | "origin" | "origin-when-cross-origin" | "same-origin" | "strict-origin" | "strict-origin-when-cross-origin" | "unsafe-url" | false;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Provides a configurable way to apply essential HTTP security headers
|
|
42
|
+
* to every server response, without external dependencies.
|
|
43
|
+
*/
|
|
44
|
+
declare class ServerHelmetProvider {
|
|
45
|
+
protected readonly alepha: Alepha;
|
|
46
|
+
/**
|
|
47
|
+
* The configuration options. These can be overridden during
|
|
48
|
+
* the application's configuration phase using `alepha.configure()`.
|
|
49
|
+
*/
|
|
50
|
+
options: HelmetOptions;
|
|
51
|
+
private buildHeaders;
|
|
52
|
+
protected readonly onResponse: HookDescriptor<"server:onResponse">;
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/index.d.ts
|
|
56
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
57
|
+
/**
|
|
58
|
+
* Alepha Server Helmet Module
|
|
59
|
+
*
|
|
60
|
+
* Automatically adds important HTTP security headers to every response
|
|
61
|
+
* to help protect your application from common web vulnerabilities.
|
|
62
|
+
*
|
|
63
|
+
* @see {@link ServerHelmetProvider}
|
|
64
|
+
* @module alepha.server.helmet
|
|
65
|
+
*/
|
|
66
|
+
declare class AlephaServerHelmet implements Module {
|
|
67
|
+
readonly name = "alepha.server.helmet";
|
|
68
|
+
readonly $services: (alepha: Alepha) => void;
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { AlephaServerHelmet, CspOptions, HelmetOptions, HstsOptions, ServerHelmetProvider };
|
|
72
|
+
//# sourceMappingURL=index.d.ts.map
|
package/server/helmet.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@alepha/server-helmet'
|
package/server/links.cjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var m = require('@alepha/server-links');
|
|
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
|
+
});
|