alepha 0.13.2 → 0.13.3
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/dist/api-files/index.browser.js +80 -0
- package/dist/api-files/index.browser.js.map +1 -0
- package/dist/api-jobs/index.browser.js +56 -0
- package/dist/api-jobs/index.browser.js.map +1 -0
- package/dist/api-notifications/index.browser.js +382 -0
- package/dist/api-notifications/index.browser.js.map +1 -0
- package/dist/api-notifications/index.d.ts +124 -69
- package/dist/api-notifications/index.js +107 -55
- package/dist/api-notifications/index.js.map +1 -1
- package/dist/api-parameters/index.browser.js +29 -0
- package/dist/api-parameters/index.browser.js.map +1 -0
- package/dist/api-users/index.d.ts +16 -3
- package/dist/api-users/index.js +75 -28
- package/dist/api-users/index.js.map +1 -1
- package/dist/api-verifications/index.browser.js +52 -0
- package/dist/api-verifications/index.browser.js.map +1 -0
- package/dist/api-verifications/index.d.ts +117 -95
- package/dist/api-verifications/index.js +1 -1
- package/dist/api-verifications/index.js.map +1 -1
- package/dist/batch/index.js +0 -5
- package/dist/batch/index.js.map +1 -1
- package/dist/bucket/index.js +7 -5
- package/dist/bucket/index.js.map +1 -1
- package/dist/cli/{dist-Dl9Vl7Ur.js → dist-lGnqsKpu.js} +11 -15
- package/dist/cli/dist-lGnqsKpu.js.map +1 -0
- package/dist/cli/index.d.ts +26 -45
- package/dist/cli/index.js +40 -58
- package/dist/cli/index.js.map +1 -1
- package/dist/command/index.d.ts +1 -0
- package/dist/command/index.js +9 -0
- package/dist/command/index.js.map +1 -1
- package/dist/email/index.js +5 -0
- package/dist/email/index.js.map +1 -1
- package/dist/orm/index.js +3 -3
- package/dist/orm/index.js.map +1 -1
- package/dist/redis/index.d.ts +10 -10
- package/dist/security/index.d.ts +28 -28
- package/dist/security/index.js +3 -3
- package/dist/security/index.js.map +1 -1
- package/dist/server/index.d.ts +9 -9
- package/dist/server-auth/index.d.ts +152 -152
- package/dist/server-cookies/index.js +2 -2
- package/dist/server-cookies/index.js.map +1 -1
- package/dist/server-links/index.d.ts +33 -33
- package/dist/server-static/index.js +18 -2
- package/dist/server-static/index.js.map +1 -1
- package/package.json +16 -6
- package/src/api-files/index.browser.ts +17 -0
- package/src/api-jobs/index.browser.ts +15 -0
- package/src/api-notifications/controllers/NotificationController.ts +26 -1
- package/src/api-notifications/index.browser.ts +17 -0
- package/src/api-notifications/index.ts +1 -0
- package/src/api-notifications/schemas/notificationQuerySchema.ts +13 -0
- package/src/api-notifications/services/NotificationService.ts +45 -2
- package/src/api-parameters/index.browser.ts +12 -0
- package/src/api-users/atoms/realmAuthSettingsAtom.ts +3 -1
- package/src/api-users/controllers/UserController.ts +21 -1
- package/src/api-users/primitives/$userRealm.ts +33 -10
- package/src/api-users/providers/UserRealmProvider.ts +1 -0
- package/src/api-users/services/SessionService.ts +2 -0
- package/src/api-users/services/UserService.ts +56 -16
- package/src/api-verifications/index.browser.ts +15 -0
- package/src/api-verifications/index.ts +1 -0
- package/src/batch/providers/BatchProvider.ts +0 -7
- package/src/bucket/index.ts +7 -5
- package/src/cli/apps/AlephaCli.ts +27 -1
- package/src/cli/apps/AlephaPackageBuilderCli.ts +3 -0
- package/src/cli/commands/CoreCommands.ts +6 -2
- package/src/cli/commands/ViteCommands.ts +2 -1
- package/src/cli/services/ProjectUtils.ts +40 -75
- package/src/command/helpers/Asker.ts +10 -0
- package/src/email/index.ts +13 -5
- package/src/orm/providers/drivers/NodeSqliteProvider.ts +3 -3
- package/src/server-cookies/providers/ServerCookiesProvider.ts +2 -1
- package/src/server-static/providers/ServerStaticProvider.ts +18 -3
- package/dist/cli/dist-Dl9Vl7Ur.js.map +0 -1
package/dist/server/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as alepha19 from "alepha";
|
|
2
2
|
import { Alepha, AlephaError, Async, FileLike, KIND, Primitive, Static, StreamLike, TArray, TFile, TObject, TRecord, TSchema, TStream, TString, TVoid } from "alepha";
|
|
3
|
-
import * as
|
|
3
|
+
import * as alepha_logger0 from "alepha/logger";
|
|
4
4
|
import { Readable } from "node:stream";
|
|
5
5
|
import { DateTimeProvider, DurationLike } from "alepha/datetime";
|
|
6
6
|
import { ReadableStream } from "node:stream/web";
|
|
@@ -226,7 +226,7 @@ declare class ServerRequestParser {
|
|
|
226
226
|
//#region src/server/providers/ServerTimingProvider.d.ts
|
|
227
227
|
type TimingMap = Record<string, [number, number]>;
|
|
228
228
|
declare class ServerTimingProvider {
|
|
229
|
-
protected readonly log:
|
|
229
|
+
protected readonly log: alepha_logger0.Logger;
|
|
230
230
|
protected readonly alepha: Alepha;
|
|
231
231
|
options: {
|
|
232
232
|
prefix: string;
|
|
@@ -249,7 +249,7 @@ declare class ServerTimingProvider {
|
|
|
249
249
|
* - $page => React route (for SSR)
|
|
250
250
|
*/
|
|
251
251
|
declare class ServerRouterProvider extends RouterProvider<ServerRouteMatcher> {
|
|
252
|
-
protected readonly log:
|
|
252
|
+
protected readonly log: alepha_logger0.Logger;
|
|
253
253
|
protected readonly alepha: Alepha;
|
|
254
254
|
protected readonly routes: ServerRoute[];
|
|
255
255
|
protected readonly serverTimingProvider: ServerTimingProvider;
|
|
@@ -288,7 +288,7 @@ declare class ServerRouterProvider extends RouterProvider<ServerRouteMatcher> {
|
|
|
288
288
|
* ServerProvider supports both Node.js HTTP requests and Web (Fetch API) requests.
|
|
289
289
|
*/
|
|
290
290
|
declare class ServerProvider {
|
|
291
|
-
protected readonly log:
|
|
291
|
+
protected readonly log: alepha_logger0.Logger;
|
|
292
292
|
protected readonly alepha: Alepha;
|
|
293
293
|
protected readonly dateTimeProvider: DateTimeProvider;
|
|
294
294
|
protected readonly router: ServerRouterProvider;
|
|
@@ -320,7 +320,7 @@ declare class ServerProvider {
|
|
|
320
320
|
//#endregion
|
|
321
321
|
//#region src/server/services/HttpClient.d.ts
|
|
322
322
|
declare class HttpClient {
|
|
323
|
-
protected readonly log:
|
|
323
|
+
protected readonly log: alepha_logger0.Logger;
|
|
324
324
|
protected readonly alepha: Alepha;
|
|
325
325
|
readonly cache: alepha_cache0.CachePrimitiveFn<HttpClientCache, any[]>;
|
|
326
326
|
protected readonly pendingRequests: HttpClientPendingRequests;
|
|
@@ -527,7 +527,7 @@ interface ActionPrimitiveOptions<TConfig extends RequestConfigSchema> extends Om
|
|
|
527
527
|
handler: ServerActionHandler<TConfig>;
|
|
528
528
|
}
|
|
529
529
|
declare class ActionPrimitive<TConfig extends RequestConfigSchema> extends Primitive<ActionPrimitiveOptions<TConfig>> {
|
|
530
|
-
protected readonly log:
|
|
530
|
+
protected readonly log: alepha_logger0.Logger;
|
|
531
531
|
protected readonly env: {
|
|
532
532
|
SERVER_API_PREFIX: string;
|
|
533
533
|
};
|
|
@@ -676,7 +676,7 @@ declare const Bun: any;
|
|
|
676
676
|
declare class BunHttpServerProvider extends ServerProvider {
|
|
677
677
|
protected readonly alepha: Alepha;
|
|
678
678
|
protected readonly dateTimeProvider: DateTimeProvider;
|
|
679
|
-
protected readonly log:
|
|
679
|
+
protected readonly log: alepha_logger0.Logger;
|
|
680
680
|
protected readonly env: {
|
|
681
681
|
SERVER_PORT: number;
|
|
682
682
|
SERVER_HOST: string;
|
|
@@ -701,7 +701,7 @@ declare module "alepha" {
|
|
|
701
701
|
declare class NodeHttpServerProvider extends ServerProvider {
|
|
702
702
|
protected readonly alepha: Alepha;
|
|
703
703
|
protected readonly dateTimeProvider: DateTimeProvider;
|
|
704
|
-
protected readonly log:
|
|
704
|
+
protected readonly log: alepha_logger0.Logger;
|
|
705
705
|
protected readonly env: {
|
|
706
706
|
SERVER_PORT: number;
|
|
707
707
|
SERVER_HOST: string;
|
|
@@ -718,7 +718,7 @@ declare class NodeHttpServerProvider extends ServerProvider {
|
|
|
718
718
|
//#endregion
|
|
719
719
|
//#region src/server/providers/ServerLoggerProvider.d.ts
|
|
720
720
|
declare class ServerLoggerProvider {
|
|
721
|
-
protected readonly log:
|
|
721
|
+
protected readonly log: alepha_logger0.Logger;
|
|
722
722
|
protected readonly alepha: Alepha;
|
|
723
723
|
readonly onRequest: alepha19.HookPrimitive<"server:onRequest">;
|
|
724
724
|
readonly onError: alepha19.HookPrimitive<"server:onError">;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as alepha147 from "alepha";
|
|
2
2
|
import { Alepha, Async, KIND, Primitive, Static } from "alepha";
|
|
3
3
|
import * as alepha_server_cookies0 from "alepha/server/cookies";
|
|
4
4
|
import { Cookies, ServerCookiesProvider } from "alepha/server/cookies";
|
|
@@ -20,82 +20,82 @@ declare const alephaServerAuthRoutes: {
|
|
|
20
20
|
};
|
|
21
21
|
//#endregion
|
|
22
22
|
//#region src/server-auth/schemas/authenticationProviderSchema.d.ts
|
|
23
|
-
declare const authenticationProviderSchema:
|
|
24
|
-
name:
|
|
25
|
-
type:
|
|
23
|
+
declare const authenticationProviderSchema: alepha147.TObject<{
|
|
24
|
+
name: alepha147.TString;
|
|
25
|
+
type: alepha147.TUnsafe<"OAUTH2" | "OIDC" | "CREDENTIALS">;
|
|
26
26
|
}>;
|
|
27
27
|
type AuthenticationProvider = Static<typeof authenticationProviderSchema>;
|
|
28
28
|
//#endregion
|
|
29
29
|
//#region src/server-auth/schemas/tokenResponseSchema.d.ts
|
|
30
|
-
declare const tokenResponseSchema:
|
|
31
|
-
provider:
|
|
32
|
-
access_token:
|
|
33
|
-
issued_at:
|
|
34
|
-
expires_in:
|
|
35
|
-
refresh_token:
|
|
36
|
-
refresh_token_expires_in:
|
|
37
|
-
refresh_expires_in:
|
|
38
|
-
id_token:
|
|
39
|
-
scope:
|
|
40
|
-
user:
|
|
41
|
-
id:
|
|
42
|
-
name:
|
|
43
|
-
email:
|
|
44
|
-
username:
|
|
45
|
-
picture:
|
|
46
|
-
sessionId:
|
|
47
|
-
organizations:
|
|
48
|
-
roles:
|
|
30
|
+
declare const tokenResponseSchema: alepha147.TObject<{
|
|
31
|
+
provider: alepha147.TString;
|
|
32
|
+
access_token: alepha147.TString;
|
|
33
|
+
issued_at: alepha147.TNumber;
|
|
34
|
+
expires_in: alepha147.TOptional<alepha147.TNumber>;
|
|
35
|
+
refresh_token: alepha147.TOptional<alepha147.TString>;
|
|
36
|
+
refresh_token_expires_in: alepha147.TOptional<alepha147.TNumber>;
|
|
37
|
+
refresh_expires_in: alepha147.TOptional<alepha147.TNumber>;
|
|
38
|
+
id_token: alepha147.TOptional<alepha147.TString>;
|
|
39
|
+
scope: alepha147.TOptional<alepha147.TString>;
|
|
40
|
+
user: alepha147.TObject<{
|
|
41
|
+
id: alepha147.TString;
|
|
42
|
+
name: alepha147.TOptional<alepha147.TString>;
|
|
43
|
+
email: alepha147.TOptional<alepha147.TString>;
|
|
44
|
+
username: alepha147.TOptional<alepha147.TString>;
|
|
45
|
+
picture: alepha147.TOptional<alepha147.TString>;
|
|
46
|
+
sessionId: alepha147.TOptional<alepha147.TString>;
|
|
47
|
+
organizations: alepha147.TOptional<alepha147.TArray<alepha147.TString>>;
|
|
48
|
+
roles: alepha147.TOptional<alepha147.TArray<alepha147.TString>>;
|
|
49
49
|
}>;
|
|
50
|
-
api:
|
|
51
|
-
prefix:
|
|
52
|
-
links:
|
|
53
|
-
name:
|
|
54
|
-
group:
|
|
55
|
-
path:
|
|
56
|
-
method:
|
|
57
|
-
requestBodyType:
|
|
58
|
-
service:
|
|
50
|
+
api: alepha147.TObject<{
|
|
51
|
+
prefix: alepha147.TOptional<alepha147.TString>;
|
|
52
|
+
links: alepha147.TArray<alepha147.TObject<{
|
|
53
|
+
name: alepha147.TString;
|
|
54
|
+
group: alepha147.TOptional<alepha147.TString>;
|
|
55
|
+
path: alepha147.TString;
|
|
56
|
+
method: alepha147.TOptional<alepha147.TString>;
|
|
57
|
+
requestBodyType: alepha147.TOptional<alepha147.TString>;
|
|
58
|
+
service: alepha147.TOptional<alepha147.TString>;
|
|
59
59
|
}>>;
|
|
60
60
|
}>;
|
|
61
61
|
}>;
|
|
62
62
|
type TokenResponse = Static<typeof tokenResponseSchema>;
|
|
63
63
|
//#endregion
|
|
64
64
|
//#region src/server-auth/schemas/tokensSchema.d.ts
|
|
65
|
-
declare const tokensSchema:
|
|
66
|
-
provider:
|
|
67
|
-
access_token:
|
|
68
|
-
issued_at:
|
|
69
|
-
expires_in:
|
|
70
|
-
refresh_token:
|
|
71
|
-
refresh_token_expires_in:
|
|
72
|
-
refresh_expires_in:
|
|
73
|
-
id_token:
|
|
74
|
-
scope:
|
|
65
|
+
declare const tokensSchema: alepha147.TObject<{
|
|
66
|
+
provider: alepha147.TString;
|
|
67
|
+
access_token: alepha147.TString;
|
|
68
|
+
issued_at: alepha147.TNumber;
|
|
69
|
+
expires_in: alepha147.TOptional<alepha147.TNumber>;
|
|
70
|
+
refresh_token: alepha147.TOptional<alepha147.TString>;
|
|
71
|
+
refresh_token_expires_in: alepha147.TOptional<alepha147.TNumber>;
|
|
72
|
+
refresh_expires_in: alepha147.TOptional<alepha147.TNumber>;
|
|
73
|
+
id_token: alepha147.TOptional<alepha147.TString>;
|
|
74
|
+
scope: alepha147.TOptional<alepha147.TString>;
|
|
75
75
|
}>;
|
|
76
76
|
type Tokens = Static<typeof tokensSchema>;
|
|
77
77
|
//#endregion
|
|
78
78
|
//#region src/server-auth/schemas/userinfoResponseSchema.d.ts
|
|
79
|
-
declare const userinfoResponseSchema:
|
|
80
|
-
user:
|
|
81
|
-
id:
|
|
82
|
-
name:
|
|
83
|
-
email:
|
|
84
|
-
username:
|
|
85
|
-
picture:
|
|
86
|
-
sessionId:
|
|
87
|
-
organizations:
|
|
88
|
-
roles:
|
|
79
|
+
declare const userinfoResponseSchema: alepha147.TObject<{
|
|
80
|
+
user: alepha147.TOptional<alepha147.TObject<{
|
|
81
|
+
id: alepha147.TString;
|
|
82
|
+
name: alepha147.TOptional<alepha147.TString>;
|
|
83
|
+
email: alepha147.TOptional<alepha147.TString>;
|
|
84
|
+
username: alepha147.TOptional<alepha147.TString>;
|
|
85
|
+
picture: alepha147.TOptional<alepha147.TString>;
|
|
86
|
+
sessionId: alepha147.TOptional<alepha147.TString>;
|
|
87
|
+
organizations: alepha147.TOptional<alepha147.TArray<alepha147.TString>>;
|
|
88
|
+
roles: alepha147.TOptional<alepha147.TArray<alepha147.TString>>;
|
|
89
89
|
}>>;
|
|
90
|
-
api:
|
|
91
|
-
prefix:
|
|
92
|
-
links:
|
|
93
|
-
name:
|
|
94
|
-
group:
|
|
95
|
-
path:
|
|
96
|
-
method:
|
|
97
|
-
requestBodyType:
|
|
98
|
-
service:
|
|
90
|
+
api: alepha147.TObject<{
|
|
91
|
+
prefix: alepha147.TOptional<alepha147.TString>;
|
|
92
|
+
links: alepha147.TArray<alepha147.TObject<{
|
|
93
|
+
name: alepha147.TString;
|
|
94
|
+
group: alepha147.TOptional<alepha147.TString>;
|
|
95
|
+
path: alepha147.TString;
|
|
96
|
+
method: alepha147.TOptional<alepha147.TString>;
|
|
97
|
+
requestBodyType: alepha147.TOptional<alepha147.TString>;
|
|
98
|
+
service: alepha147.TOptional<alepha147.TString>;
|
|
99
99
|
}>>;
|
|
100
100
|
}>;
|
|
101
101
|
}>;
|
|
@@ -108,34 +108,34 @@ declare class ServerAuthProvider {
|
|
|
108
108
|
protected readonly serverCookiesProvider: ServerCookiesProvider;
|
|
109
109
|
protected readonly dateTimeProvider: DateTimeProvider;
|
|
110
110
|
protected readonly serverLinksProvider: ServerLinksProvider;
|
|
111
|
-
protected readonly authorizationCode: alepha_server_cookies0.AbstractCookiePrimitive<
|
|
112
|
-
provider:
|
|
113
|
-
codeVerifier:
|
|
114
|
-
redirectUri:
|
|
115
|
-
state:
|
|
116
|
-
nonce:
|
|
111
|
+
protected readonly authorizationCode: alepha_server_cookies0.AbstractCookiePrimitive<alepha147.TObject<{
|
|
112
|
+
provider: alepha147.TString;
|
|
113
|
+
codeVerifier: alepha147.TOptional<alepha147.TString>;
|
|
114
|
+
redirectUri: alepha147.TOptional<alepha147.TString>;
|
|
115
|
+
state: alepha147.TOptional<alepha147.TString>;
|
|
116
|
+
nonce: alepha147.TOptional<alepha147.TString>;
|
|
117
117
|
}>>;
|
|
118
|
-
readonly tokens: alepha_server_cookies0.AbstractCookiePrimitive<
|
|
119
|
-
provider:
|
|
120
|
-
access_token:
|
|
121
|
-
issued_at:
|
|
122
|
-
expires_in:
|
|
123
|
-
refresh_token:
|
|
124
|
-
refresh_token_expires_in:
|
|
125
|
-
refresh_expires_in:
|
|
126
|
-
id_token:
|
|
127
|
-
scope:
|
|
118
|
+
readonly tokens: alepha_server_cookies0.AbstractCookiePrimitive<alepha147.TObject<{
|
|
119
|
+
provider: alepha147.TString;
|
|
120
|
+
access_token: alepha147.TString;
|
|
121
|
+
issued_at: alepha147.TNumber;
|
|
122
|
+
expires_in: alepha147.TOptional<alepha147.TNumber>;
|
|
123
|
+
refresh_token: alepha147.TOptional<alepha147.TString>;
|
|
124
|
+
refresh_token_expires_in: alepha147.TOptional<alepha147.TNumber>;
|
|
125
|
+
refresh_expires_in: alepha147.TOptional<alepha147.TNumber>;
|
|
126
|
+
id_token: alepha147.TOptional<alepha147.TString>;
|
|
127
|
+
scope: alepha147.TOptional<alepha147.TString>;
|
|
128
128
|
}>>;
|
|
129
129
|
get identities(): Array<AuthPrimitive>;
|
|
130
130
|
getAuthenticationProviders(filters?: {
|
|
131
131
|
realmName?: string;
|
|
132
132
|
}): AuthenticationProvider[];
|
|
133
|
-
protected readonly configure:
|
|
133
|
+
protected readonly configure: alepha147.HookPrimitive<"configure">;
|
|
134
134
|
protected getAccessTokens(tokens: Tokens): string | undefined;
|
|
135
135
|
/**
|
|
136
136
|
* Fill request headers with access token from cookies or fallback to provider's fallback function.
|
|
137
137
|
*/
|
|
138
|
-
protected readonly onRequest:
|
|
138
|
+
protected readonly onRequest: alepha147.HookPrimitive<"server:onRequest">;
|
|
139
139
|
/**
|
|
140
140
|
* Convert cookies to tokens.
|
|
141
141
|
* If the tokens are expired, try to refresh them using the refresh token.
|
|
@@ -146,26 +146,26 @@ declare class ServerAuthProvider {
|
|
|
146
146
|
* Get user information.
|
|
147
147
|
*/
|
|
148
148
|
readonly userinfo: alepha_server0.RoutePrimitive<{
|
|
149
|
-
response:
|
|
150
|
-
user:
|
|
151
|
-
id:
|
|
152
|
-
name:
|
|
153
|
-
email:
|
|
154
|
-
username:
|
|
155
|
-
picture:
|
|
156
|
-
sessionId:
|
|
157
|
-
organizations:
|
|
158
|
-
roles:
|
|
149
|
+
response: alepha147.TObject<{
|
|
150
|
+
user: alepha147.TOptional<alepha147.TObject<{
|
|
151
|
+
id: alepha147.TString;
|
|
152
|
+
name: alepha147.TOptional<alepha147.TString>;
|
|
153
|
+
email: alepha147.TOptional<alepha147.TString>;
|
|
154
|
+
username: alepha147.TOptional<alepha147.TString>;
|
|
155
|
+
picture: alepha147.TOptional<alepha147.TString>;
|
|
156
|
+
sessionId: alepha147.TOptional<alepha147.TString>;
|
|
157
|
+
organizations: alepha147.TOptional<alepha147.TArray<alepha147.TString>>;
|
|
158
|
+
roles: alepha147.TOptional<alepha147.TArray<alepha147.TString>>;
|
|
159
159
|
}>>;
|
|
160
|
-
api:
|
|
161
|
-
prefix:
|
|
162
|
-
links:
|
|
163
|
-
name:
|
|
164
|
-
group:
|
|
165
|
-
path:
|
|
166
|
-
method:
|
|
167
|
-
requestBodyType:
|
|
168
|
-
service:
|
|
160
|
+
api: alepha147.TObject<{
|
|
161
|
+
prefix: alepha147.TOptional<alepha147.TString>;
|
|
162
|
+
links: alepha147.TArray<alepha147.TObject<{
|
|
163
|
+
name: alepha147.TString;
|
|
164
|
+
group: alepha147.TOptional<alepha147.TString>;
|
|
165
|
+
path: alepha147.TString;
|
|
166
|
+
method: alepha147.TOptional<alepha147.TString>;
|
|
167
|
+
requestBodyType: alepha147.TOptional<alepha147.TString>;
|
|
168
|
+
service: alepha147.TOptional<alepha147.TString>;
|
|
169
169
|
}>>;
|
|
170
170
|
}>;
|
|
171
171
|
}>;
|
|
@@ -174,65 +174,65 @@ declare class ServerAuthProvider {
|
|
|
174
174
|
* Refresh a token for internal providers.
|
|
175
175
|
*/
|
|
176
176
|
readonly refresh: alepha_server0.RoutePrimitive<{
|
|
177
|
-
query:
|
|
178
|
-
provider:
|
|
177
|
+
query: alepha147.TObject<{
|
|
178
|
+
provider: alepha147.TString;
|
|
179
179
|
}>;
|
|
180
|
-
body:
|
|
181
|
-
refresh_token:
|
|
182
|
-
access_token:
|
|
180
|
+
body: alepha147.TObject<{
|
|
181
|
+
refresh_token: alepha147.TString;
|
|
182
|
+
access_token: alepha147.TOptional<alepha147.TString>;
|
|
183
183
|
}>;
|
|
184
|
-
response:
|
|
185
|
-
provider:
|
|
186
|
-
access_token:
|
|
187
|
-
issued_at:
|
|
188
|
-
expires_in:
|
|
189
|
-
refresh_token:
|
|
190
|
-
refresh_token_expires_in:
|
|
191
|
-
refresh_expires_in:
|
|
192
|
-
id_token:
|
|
193
|
-
scope:
|
|
184
|
+
response: alepha147.TObject<{
|
|
185
|
+
provider: alepha147.TString;
|
|
186
|
+
access_token: alepha147.TString;
|
|
187
|
+
issued_at: alepha147.TNumber;
|
|
188
|
+
expires_in: alepha147.TOptional<alepha147.TNumber>;
|
|
189
|
+
refresh_token: alepha147.TOptional<alepha147.TString>;
|
|
190
|
+
refresh_token_expires_in: alepha147.TOptional<alepha147.TNumber>;
|
|
191
|
+
refresh_expires_in: alepha147.TOptional<alepha147.TNumber>;
|
|
192
|
+
id_token: alepha147.TOptional<alepha147.TString>;
|
|
193
|
+
scope: alepha147.TOptional<alepha147.TString>;
|
|
194
194
|
}>;
|
|
195
195
|
}>;
|
|
196
196
|
/**
|
|
197
197
|
* Login for local password-based authentication.
|
|
198
198
|
*/
|
|
199
199
|
readonly token: alepha_server0.RoutePrimitive<{
|
|
200
|
-
query:
|
|
201
|
-
provider:
|
|
200
|
+
query: alepha147.TObject<{
|
|
201
|
+
provider: alepha147.TString;
|
|
202
202
|
}>;
|
|
203
|
-
body:
|
|
204
|
-
username:
|
|
205
|
-
password:
|
|
203
|
+
body: alepha147.TObject<{
|
|
204
|
+
username: alepha147.TString;
|
|
205
|
+
password: alepha147.TString;
|
|
206
206
|
}>;
|
|
207
|
-
response:
|
|
208
|
-
provider:
|
|
209
|
-
access_token:
|
|
210
|
-
issued_at:
|
|
211
|
-
expires_in:
|
|
212
|
-
refresh_token:
|
|
213
|
-
refresh_token_expires_in:
|
|
214
|
-
refresh_expires_in:
|
|
215
|
-
id_token:
|
|
216
|
-
scope:
|
|
217
|
-
user:
|
|
218
|
-
id:
|
|
219
|
-
name:
|
|
220
|
-
email:
|
|
221
|
-
username:
|
|
222
|
-
picture:
|
|
223
|
-
sessionId:
|
|
224
|
-
organizations:
|
|
225
|
-
roles:
|
|
207
|
+
response: alepha147.TObject<{
|
|
208
|
+
provider: alepha147.TString;
|
|
209
|
+
access_token: alepha147.TString;
|
|
210
|
+
issued_at: alepha147.TNumber;
|
|
211
|
+
expires_in: alepha147.TOptional<alepha147.TNumber>;
|
|
212
|
+
refresh_token: alepha147.TOptional<alepha147.TString>;
|
|
213
|
+
refresh_token_expires_in: alepha147.TOptional<alepha147.TNumber>;
|
|
214
|
+
refresh_expires_in: alepha147.TOptional<alepha147.TNumber>;
|
|
215
|
+
id_token: alepha147.TOptional<alepha147.TString>;
|
|
216
|
+
scope: alepha147.TOptional<alepha147.TString>;
|
|
217
|
+
user: alepha147.TObject<{
|
|
218
|
+
id: alepha147.TString;
|
|
219
|
+
name: alepha147.TOptional<alepha147.TString>;
|
|
220
|
+
email: alepha147.TOptional<alepha147.TString>;
|
|
221
|
+
username: alepha147.TOptional<alepha147.TString>;
|
|
222
|
+
picture: alepha147.TOptional<alepha147.TString>;
|
|
223
|
+
sessionId: alepha147.TOptional<alepha147.TString>;
|
|
224
|
+
organizations: alepha147.TOptional<alepha147.TArray<alepha147.TString>>;
|
|
225
|
+
roles: alepha147.TOptional<alepha147.TArray<alepha147.TString>>;
|
|
226
226
|
}>;
|
|
227
|
-
api:
|
|
228
|
-
prefix:
|
|
229
|
-
links:
|
|
230
|
-
name:
|
|
231
|
-
group:
|
|
232
|
-
path:
|
|
233
|
-
method:
|
|
234
|
-
requestBodyType:
|
|
235
|
-
service:
|
|
227
|
+
api: alepha147.TObject<{
|
|
228
|
+
prefix: alepha147.TOptional<alepha147.TString>;
|
|
229
|
+
links: alepha147.TArray<alepha147.TObject<{
|
|
230
|
+
name: alepha147.TString;
|
|
231
|
+
group: alepha147.TOptional<alepha147.TString>;
|
|
232
|
+
path: alepha147.TString;
|
|
233
|
+
method: alepha147.TOptional<alepha147.TString>;
|
|
234
|
+
requestBodyType: alepha147.TOptional<alepha147.TString>;
|
|
235
|
+
service: alepha147.TOptional<alepha147.TString>;
|
|
236
236
|
}>>;
|
|
237
237
|
}>;
|
|
238
238
|
}>;
|
|
@@ -241,9 +241,9 @@ declare class ServerAuthProvider {
|
|
|
241
241
|
* Oauth2/OIDC login route.
|
|
242
242
|
*/
|
|
243
243
|
readonly login: alepha_server0.RoutePrimitive<{
|
|
244
|
-
query:
|
|
245
|
-
provider:
|
|
246
|
-
redirect_uri:
|
|
244
|
+
query: alepha147.TObject<{
|
|
245
|
+
provider: alepha147.TString;
|
|
246
|
+
redirect_uri: alepha147.TOptional<alepha147.TString>;
|
|
247
247
|
}>;
|
|
248
248
|
}>;
|
|
249
249
|
/**
|
|
@@ -255,8 +255,8 @@ declare class ServerAuthProvider {
|
|
|
255
255
|
* Logout route for OAuth2/OIDC providers.
|
|
256
256
|
*/
|
|
257
257
|
readonly logout: alepha_server0.RoutePrimitive<{
|
|
258
|
-
query:
|
|
259
|
-
post_logout_redirect_uri:
|
|
258
|
+
query: alepha147.TObject<{
|
|
259
|
+
post_logout_redirect_uri: alepha147.TOptional<alepha147.TString>;
|
|
260
260
|
}>;
|
|
261
261
|
}>;
|
|
262
262
|
protected provider(opts: string | {
|
|
@@ -577,7 +577,7 @@ declare module "alepha" {
|
|
|
577
577
|
* @see {@link ServerAuthProvider}
|
|
578
578
|
* @module alepha.server.auth
|
|
579
579
|
*/
|
|
580
|
-
declare const AlephaServerAuth:
|
|
580
|
+
declare const AlephaServerAuth: alepha147.Service<alepha147.Module>;
|
|
581
581
|
//#endregion
|
|
582
582
|
export { $auth, $authCredentials, $authGithub, $authGoogle, AccessToken, AlephaServerAuth, AuthExternal, AuthInternal, AuthPrimitive, AuthPrimitiveOptions, AuthenticationProvider, Credentials, CredentialsFn, CredentialsOptions, LinkAccountFn, LinkAccountOptions, OAuth2Options, OAuth2Profile, OidcOptions, ServerAuthProvider, TokenResponse, Tokens, UserinfoResponse, WithLinkFn, WithLoginFn, alephaServerAuthRoutes, authenticationProviderSchema, tokenResponseSchema, tokensSchema, userinfoResponseSchema };
|
|
583
583
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $env, $hook, $inject, $module, Alepha, KIND, Primitive, createPrimitive, t } from "alepha";
|
|
1
|
+
import { $env, $hook, $inject, $module, Alepha, AlephaError, KIND, Primitive, createPrimitive, t } from "alepha";
|
|
2
2
|
import { AlephaServer } from "alepha/server";
|
|
3
3
|
import { createCipheriv, createDecipheriv, createHmac, randomBytes, timingSafeEqual } from "node:crypto";
|
|
4
4
|
import { deflateRawSync, inflateRawSync } from "node:zlib";
|
|
@@ -87,7 +87,7 @@ var ServerCookiesProvider = class {
|
|
|
87
87
|
const contextCookies = this.alepha.context.get("request")?.cookies;
|
|
88
88
|
if (cookies) return cookies;
|
|
89
89
|
if (contextCookies) return contextCookies;
|
|
90
|
-
throw new
|
|
90
|
+
throw new AlephaError("Cookie context is not available. This method must be called within a server request cycle.");
|
|
91
91
|
}
|
|
92
92
|
getCookie(name, options, contextCookies) {
|
|
93
93
|
const cookies = this.getCookiesFromContext(contextCookies);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["cookies: Record<string, string>","parts: string[]","cookie: Cookie"],"sources":["../../src/server-cookies/services/CookieParser.ts","../../src/server-cookies/providers/ServerCookiesProvider.ts","../../src/server-cookies/primitives/$cookie.ts","../../src/server-cookies/index.ts"],"sourcesContent":["import type { Cookie } from \"../primitives/$cookie.ts\";\n\nexport class CookieParser {\n public parseRequestCookies(header: string): Record<string, string> {\n const cookies: Record<string, string> = {};\n const parts = header.split(\";\");\n for (const part of parts) {\n const [key, value] = part.split(\"=\");\n if (!key || !value) {\n continue;\n }\n\n cookies[key.trim()] = value.trim();\n }\n\n return cookies;\n }\n\n public serializeResponseCookies(\n cookies: Record<string, Cookie | null>,\n isHttps: boolean,\n ): string[] {\n const headers = [];\n\n for (const [name, cookie] of Object.entries(cookies)) {\n // If the cookie is null, we need to delete it\n if (cookie == null) {\n headers.push(`${name}=; Path=/; Max-Age=0`);\n continue;\n }\n\n if (!cookie.value) {\n continue;\n }\n\n headers.push(this.cookieToString(name, cookie, isHttps));\n }\n\n return headers;\n }\n\n public cookieToString(\n name: string,\n cookie: Cookie,\n isHttps?: boolean,\n ): string {\n const parts: string[] = [];\n\n parts.push(`${name}=${cookie.value}`);\n\n if (cookie.path) {\n parts.push(`Path=${cookie.path}`);\n }\n if (cookie.maxAge) {\n parts.push(`Max-Age=${cookie.maxAge}`);\n }\n if (cookie.secure !== false && isHttps) {\n parts.push(\"Secure\");\n }\n if (cookie.httpOnly) {\n parts.push(\"HttpOnly\");\n }\n if (cookie.sameSite) {\n parts.push(`SameSite=${cookie.sameSite}`);\n }\n if (cookie.domain) {\n parts.push(`Domain=${cookie.domain}`);\n }\n\n return parts.join(\"; \");\n }\n}\n","import {\n createCipheriv,\n createDecipheriv,\n createHmac,\n randomBytes,\n timingSafeEqual,\n} from \"node:crypto\";\nimport { deflateRawSync, inflateRawSync } from \"node:zlib\";\nimport {\n $env,\n $hook,\n $inject,\n Alepha,\n type Static,\n type TSchema,\n t,\n} from \"alepha\";\nimport { DateTimeProvider } from \"alepha/datetime\";\nimport { $logger } from \"alepha/logger\";\nimport { DEFAULT_APP_SECRET } from \"alepha/security\";\nimport type { ServerRequest } from \"alepha/server\";\nimport type {\n Cookie,\n CookiePrimitiveOptions,\n Cookies,\n} from \"../primitives/$cookie.ts\";\nimport { CookieParser } from \"../services/CookieParser.ts\";\n\nconst envSchema = t.object({\n APP_SECRET: t.text({\n default: DEFAULT_APP_SECRET,\n }),\n});\n\nexport class ServerCookiesProvider {\n protected readonly alepha = $inject(Alepha);\n protected readonly log = $logger();\n protected readonly cookieParser = $inject(CookieParser);\n protected readonly dateTimeProvider = $inject(DateTimeProvider);\n protected readonly env = $env(envSchema);\n\n // crypto constants\n protected readonly ALGORITHM = \"aes-256-gcm\";\n protected readonly IV_LENGTH = 16; // For GCM\n protected readonly AUTH_TAG_LENGTH = 16;\n protected readonly SIGNATURE_LENGTH = 32; // For SHA256\n\n public readonly onRequest = $hook({\n on: \"server:onRequest\",\n handler: async ({ request }) => {\n request.cookies = {\n req: this.cookieParser.parseRequestCookies(\n request.headers.cookie ?? \"\",\n ),\n res: {},\n };\n },\n });\n\n public readonly onAction = $hook({\n on: \"action:onRequest\",\n handler: async ({ request }) => {\n request.cookies = {\n req: this.cookieParser.parseRequestCookies(\n request.headers.cookie ?? \"\",\n ),\n res: {},\n };\n },\n });\n\n public readonly onSend = $hook({\n on: \"server:onSend\",\n handler: async ({ request }) => {\n if (request.cookies && Object.keys(request.cookies.res).length > 0) {\n const setCookieHeaders = this.cookieParser.serializeResponseCookies(\n request.cookies.res,\n request.url.protocol === \"https:\",\n );\n if (setCookieHeaders.length > 0) {\n request.reply.headers[\"set-cookie\"] = setCookieHeaders;\n }\n }\n },\n });\n\n protected getCookiesFromContext(cookies?: Cookies): Cookies {\n const contextCookies =\n this.alepha.context.get<ServerRequest>(\"request\")?.cookies;\n if (cookies) return cookies;\n if (contextCookies) return contextCookies;\n throw new Error(\n \"Cookie context is not available. This method must be called within a server request cycle.\",\n );\n }\n\n public getCookie<T extends TSchema>(\n name: string,\n options: CookiePrimitiveOptions<T>,\n contextCookies?: Cookies,\n ): Static<T> | undefined {\n const cookies = this.getCookiesFromContext(contextCookies);\n let rawValue = cookies.req[name];\n\n if (!rawValue) return undefined;\n\n try {\n rawValue = decodeURIComponent(rawValue);\n\n if (options.sign) {\n const signature = rawValue.substring(0, this.SIGNATURE_LENGTH * 2);\n const value = rawValue.substring(this.SIGNATURE_LENGTH * 2);\n const expectedSignature = this.sign(value);\n\n if (\n !timingSafeEqual(\n Buffer.from(signature, \"hex\"),\n Buffer.from(expectedSignature, \"hex\"),\n )\n ) {\n this.log.warn(`Invalid signature for cookie \"${name}\".`);\n return undefined;\n }\n rawValue = value;\n }\n\n if (options.encrypt) {\n rawValue = this.decrypt(rawValue);\n }\n\n if (options.compress) {\n rawValue = inflateRawSync(Buffer.from(rawValue, \"base64\")).toString(\n \"utf8\",\n );\n }\n\n return this.alepha.codec.decode(options.schema, JSON.parse(rawValue));\n } catch (error) {\n this.log.warn(`Failed to parse cookie \"${name}\"`, error);\n // corrupted or invalid cookie, instruct browser to delete it on next response\n this.deleteCookie(name, cookies);\n return undefined;\n }\n }\n\n public setCookie<T extends TSchema>(\n name: string,\n options: CookiePrimitiveOptions<T>,\n data: Static<T>,\n contextCookies?: Cookies,\n ): void {\n const cookies = this.getCookiesFromContext(contextCookies);\n let value = JSON.stringify(this.alepha.codec.decode(options.schema, data));\n\n if (options.compress) {\n value = deflateRawSync(value).toString(\"base64\");\n }\n\n if (options.encrypt) {\n value = this.encrypt(value);\n }\n\n if (options.sign) {\n value = this.sign(value) + value;\n }\n\n const cookie: Cookie = {\n value: encodeURIComponent(value),\n path: options.path ?? \"/\",\n sameSite: options.sameSite ?? \"lax\",\n secure: options.secure ?? this.alepha.isProduction(),\n httpOnly: options.httpOnly,\n domain: options.domain,\n };\n\n if (options.ttl) {\n cookie.maxAge = this.dateTimeProvider.duration(options.ttl).as(\"seconds\");\n }\n\n cookies.res[name] = cookie;\n }\n\n public deleteCookie<T extends TSchema>(\n name: string,\n contextCookies?: Cookies,\n ): void {\n const cookies = this.getCookiesFromContext(contextCookies);\n cookies.res[name] = null;\n }\n\n // --- Crypto & Parsing ---\n\n protected encrypt(text: string): string {\n const iv = randomBytes(this.IV_LENGTH);\n const cipher = createCipheriv(\n this.ALGORITHM,\n Buffer.from(this.secretKey()),\n iv,\n );\n const encrypted = Buffer.concat([\n cipher.update(text, \"utf8\"),\n cipher.final(),\n ]);\n const authTag = cipher.getAuthTag();\n return Buffer.concat([iv, authTag, encrypted]).toString(\"base64\");\n }\n\n protected decrypt(encryptedText: string): string {\n const data = Buffer.from(encryptedText, \"base64\");\n const iv = data.subarray(0, this.IV_LENGTH);\n const authTag = data.subarray(\n this.IV_LENGTH,\n this.IV_LENGTH + this.AUTH_TAG_LENGTH,\n );\n\n const encrypted = data.subarray(this.IV_LENGTH + this.AUTH_TAG_LENGTH);\n const decipher = createDecipheriv(\n this.ALGORITHM,\n Buffer.from(this.secretKey()),\n iv,\n );\n\n decipher.setAuthTag(authTag);\n\n const decrypted = Buffer.concat([\n decipher.update(encrypted),\n decipher.final(),\n ]);\n\n return decrypted.toString(\"utf8\");\n }\n\n public secretKey(): string {\n let secret = this.env.APP_SECRET;\n if (secret.length < 32) {\n // pad secret to 32 bytes\n secret = secret.padEnd(32, \"0\");\n } else if (secret.length > 32) {\n // truncate secret to 32 bytes\n secret = secret.substring(0, 32);\n }\n return secret;\n }\n\n protected sign(data: string): string {\n return createHmac(\"sha256\", this.secretKey()).update(data).digest(\"hex\");\n }\n}\n","import {\n $inject,\n createPrimitive,\n KIND,\n Primitive,\n type Static,\n type TSchema,\n} from \"alepha\";\nimport type { DurationLike } from \"alepha/datetime\";\nimport { ServerCookiesProvider } from \"../providers/ServerCookiesProvider.ts\";\n\n/**\n * Declares a type-safe, configurable HTTP cookie.\n * This primitive provides methods to get, set, and delete the cookie\n * within the server request/response cycle.\n */\nexport const $cookie = <T extends TSchema>(\n options: CookiePrimitiveOptions<T>,\n): AbstractCookiePrimitive<T> => {\n return createPrimitive(CookiePrimitive<T>, options);\n};\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface CookiePrimitiveOptions<T extends TSchema> {\n /** The schema for the cookie's value, used for validation and type safety. */\n schema: T;\n\n /** The name of the cookie. */\n name?: string;\n\n /** The cookie's path. Defaults to \"/\". */\n path?: string;\n\n /** Time-to-live for the cookie. Maps to `Max-Age`. */\n ttl?: DurationLike;\n\n /** If true, the cookie is only sent over HTTPS. Defaults to true in production. */\n secure?: boolean;\n\n /** If true, the cookie cannot be accessed by client-side scripts. */\n httpOnly?: boolean;\n\n /** SameSite policy for the cookie. Defaults to \"lax\". */\n sameSite?: \"strict\" | \"lax\" | \"none\";\n\n /** The domain for the cookie. */\n domain?: string;\n\n /** If true, the cookie value will be compressed using zlib. */\n compress?: boolean;\n\n /** If true, the cookie value will be encrypted. Requires `COOKIE_SECRET` env var. */\n encrypt?: boolean;\n\n /** If true, the cookie will be signed to prevent tampering. Requires `COOKIE_SECRET` env var. */\n sign?: boolean;\n}\n\nexport interface AbstractCookiePrimitive<T extends TSchema> {\n readonly name: string;\n readonly options: CookiePrimitiveOptions<T>;\n set(\n value: Static<T>,\n options?: { cookies?: Cookies; ttl?: DurationLike },\n ): void;\n get(options?: { cookies?: Cookies }): Static<T> | undefined;\n del(options?: { cookies?: Cookies }): void;\n}\n\nexport class CookiePrimitive<T extends TSchema>\n extends Primitive<CookiePrimitiveOptions<T>>\n implements AbstractCookiePrimitive<T>\n{\n protected readonly serverCookiesProvider = $inject(ServerCookiesProvider);\n\n public get schema(): T {\n return this.options.schema;\n }\n\n public get name(): string {\n return this.options.name ?? `${this.config.propertyKey}`;\n }\n\n /**\n * Sets the cookie with the given value in the current request's response.\n */\n public set(\n value: Static<T>,\n options?: { cookies?: Cookies; ttl?: DurationLike },\n ): void {\n this.serverCookiesProvider.setCookie(\n this.name,\n {\n ...this.options,\n ttl: options?.ttl ?? this.options.ttl,\n },\n value,\n options?.cookies,\n );\n }\n\n /**\n * Gets the cookie value from the current request. Returns undefined if not found or invalid.\n */\n public get(options?: { cookies?: Cookies }): Static<T> | undefined {\n return this.serverCookiesProvider.getCookie(\n this.name,\n this.options,\n options?.cookies,\n );\n }\n\n /**\n * Deletes the cookie in the current request's response.\n */\n public del(options?: { cookies?: Cookies }): void {\n this.serverCookiesProvider.deleteCookie(this.name, options?.cookies);\n }\n}\n\n$cookie[KIND] = CookiePrimitive;\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface Cookies {\n req: Record<string, string>;\n res: Record<string, Cookie | null>;\n}\n\nexport interface Cookie {\n value: string;\n path?: string;\n maxAge?: number;\n secure?: boolean;\n httpOnly?: boolean;\n sameSite?: \"strict\" | \"lax\" | \"none\";\n domain?: string;\n}\n","import { $module } from \"alepha\";\nimport { AlephaServer } from \"alepha/server\";\nimport { $cookie, type Cookies } from \"./primitives/$cookie.ts\";\nimport { ServerCookiesProvider } from \"./providers/ServerCookiesProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport * from \"./primitives/$cookie.ts\";\nexport * from \"./providers/ServerCookiesProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\ndeclare module \"alepha/server\" {\n interface ServerRequest {\n cookies: Cookies;\n }\n}\n\n/**\n * Provides HTTP cookie management capabilities for server requests and responses with type-safe cookie primitives.\n *\n * The server-cookies module enables declarative cookie handling using the `$cookie` primitive on class properties.\n * It offers automatic cookie parsing, secure cookie configuration, and seamless integration with server routes\n * for managing user sessions, preferences, and authentication tokens.\n *\n * @see {@link $cookie}\n * @module alepha.server.cookies\n */\nexport const AlephaServerCookies = $module({\n name: \"alepha.server.cookies\",\n primitives: [$cookie],\n services: [AlephaServer, ServerCookiesProvider],\n});\n"],"mappings":";;;;;;;;;AAEA,IAAa,eAAb,MAA0B;CACxB,AAAO,oBAAoB,QAAwC;EACjE,MAAMA,UAAkC,EAAE;EAC1C,MAAM,QAAQ,OAAO,MAAM,IAAI;AAC/B,OAAK,MAAM,QAAQ,OAAO;GACxB,MAAM,CAAC,KAAK,SAAS,KAAK,MAAM,IAAI;AACpC,OAAI,CAAC,OAAO,CAAC,MACX;AAGF,WAAQ,IAAI,MAAM,IAAI,MA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KAAK;GACR,KAAK,SAAS,OAAO,KAAK,QAAQ;GACnC,EACD,OACA,SAAS,QACV;;;;;CAMH,AAAO,IAAI,SAAwD;AACjE,SAAO,KAAK,sBAAsB,UAChC,KAAK,MACL,KAAK,SACL,SAAS,QACV;;;;;CAMH,AAAO,IAAI,SAAuC;AAChD,OAAK,sBAAsB,aAAa,KAAK,MAAM,SAAS,QAAQ;;;AAIxE,QAAQ,QAAQ;;;;;;;;;;;;;;AC7FhB,MAAa,sBAAsB,QAAQ;CACzC,MAAM;CACN,YAAY,CAAC,QAAQ;CACrB,UAAU,CAAC,cAAc,sBAAsB;CAChD,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["cookies: Record<string, string>","parts: string[]","cookie: Cookie"],"sources":["../../src/server-cookies/services/CookieParser.ts","../../src/server-cookies/providers/ServerCookiesProvider.ts","../../src/server-cookies/primitives/$cookie.ts","../../src/server-cookies/index.ts"],"sourcesContent":["import type { Cookie } from \"../primitives/$cookie.ts\";\n\nexport class CookieParser {\n public parseRequestCookies(header: string): Record<string, string> {\n const cookies: Record<string, string> = {};\n const parts = header.split(\";\");\n for (const part of parts) {\n const [key, value] = part.split(\"=\");\n if (!key || !value) {\n continue;\n }\n\n cookies[key.trim()] = value.trim();\n }\n\n return cookies;\n }\n\n public serializeResponseCookies(\n cookies: Record<string, Cookie | null>,\n isHttps: boolean,\n ): string[] {\n const headers = [];\n\n for (const [name, cookie] of Object.entries(cookies)) {\n // If the cookie is null, we need to delete it\n if (cookie == null) {\n headers.push(`${name}=; Path=/; Max-Age=0`);\n continue;\n }\n\n if (!cookie.value) {\n continue;\n }\n\n headers.push(this.cookieToString(name, cookie, isHttps));\n }\n\n return headers;\n }\n\n public cookieToString(\n name: string,\n cookie: Cookie,\n isHttps?: boolean,\n ): string {\n const parts: string[] = [];\n\n parts.push(`${name}=${cookie.value}`);\n\n if (cookie.path) {\n parts.push(`Path=${cookie.path}`);\n }\n if (cookie.maxAge) {\n parts.push(`Max-Age=${cookie.maxAge}`);\n }\n if (cookie.secure !== false && isHttps) {\n parts.push(\"Secure\");\n }\n if (cookie.httpOnly) {\n parts.push(\"HttpOnly\");\n }\n if (cookie.sameSite) {\n parts.push(`SameSite=${cookie.sameSite}`);\n }\n if (cookie.domain) {\n parts.push(`Domain=${cookie.domain}`);\n }\n\n return parts.join(\"; \");\n }\n}\n","import {\n createCipheriv,\n createDecipheriv,\n createHmac,\n randomBytes,\n timingSafeEqual,\n} from \"node:crypto\";\nimport { deflateRawSync, inflateRawSync } from \"node:zlib\";\nimport {\n $env,\n $hook,\n $inject,\n Alepha,\n AlephaError,\n type Static,\n type TSchema,\n t,\n} from \"alepha\";\nimport { DateTimeProvider } from \"alepha/datetime\";\nimport { $logger } from \"alepha/logger\";\nimport { DEFAULT_APP_SECRET } from \"alepha/security\";\nimport type { ServerRequest } from \"alepha/server\";\nimport type {\n Cookie,\n CookiePrimitiveOptions,\n Cookies,\n} from \"../primitives/$cookie.ts\";\nimport { CookieParser } from \"../services/CookieParser.ts\";\n\nconst envSchema = t.object({\n APP_SECRET: t.text({\n default: DEFAULT_APP_SECRET,\n }),\n});\n\nexport class ServerCookiesProvider {\n protected readonly alepha = $inject(Alepha);\n protected readonly log = $logger();\n protected readonly cookieParser = $inject(CookieParser);\n protected readonly dateTimeProvider = $inject(DateTimeProvider);\n protected readonly env = $env(envSchema);\n\n // crypto constants\n protected readonly ALGORITHM = \"aes-256-gcm\";\n protected readonly IV_LENGTH = 16; // For GCM\n protected readonly AUTH_TAG_LENGTH = 16;\n protected readonly SIGNATURE_LENGTH = 32; // For SHA256\n\n public readonly onRequest = $hook({\n on: \"server:onRequest\",\n handler: async ({ request }) => {\n request.cookies = {\n req: this.cookieParser.parseRequestCookies(\n request.headers.cookie ?? \"\",\n ),\n res: {},\n };\n },\n });\n\n public readonly onAction = $hook({\n on: \"action:onRequest\",\n handler: async ({ request }) => {\n request.cookies = {\n req: this.cookieParser.parseRequestCookies(\n request.headers.cookie ?? \"\",\n ),\n res: {},\n };\n },\n });\n\n public readonly onSend = $hook({\n on: \"server:onSend\",\n handler: async ({ request }) => {\n if (request.cookies && Object.keys(request.cookies.res).length > 0) {\n const setCookieHeaders = this.cookieParser.serializeResponseCookies(\n request.cookies.res,\n request.url.protocol === \"https:\",\n );\n if (setCookieHeaders.length > 0) {\n request.reply.headers[\"set-cookie\"] = setCookieHeaders;\n }\n }\n },\n });\n\n protected getCookiesFromContext(cookies?: Cookies): Cookies {\n const contextCookies =\n this.alepha.context.get<ServerRequest>(\"request\")?.cookies;\n if (cookies) return cookies;\n if (contextCookies) return contextCookies;\n throw new AlephaError(\n \"Cookie context is not available. This method must be called within a server request cycle.\",\n );\n }\n\n public getCookie<T extends TSchema>(\n name: string,\n options: CookiePrimitiveOptions<T>,\n contextCookies?: Cookies,\n ): Static<T> | undefined {\n const cookies = this.getCookiesFromContext(contextCookies);\n let rawValue = cookies.req[name];\n\n if (!rawValue) return undefined;\n\n try {\n rawValue = decodeURIComponent(rawValue);\n\n if (options.sign) {\n const signature = rawValue.substring(0, this.SIGNATURE_LENGTH * 2);\n const value = rawValue.substring(this.SIGNATURE_LENGTH * 2);\n const expectedSignature = this.sign(value);\n\n if (\n !timingSafeEqual(\n Buffer.from(signature, \"hex\"),\n Buffer.from(expectedSignature, \"hex\"),\n )\n ) {\n this.log.warn(`Invalid signature for cookie \"${name}\".`);\n return undefined;\n }\n rawValue = value;\n }\n\n if (options.encrypt) {\n rawValue = this.decrypt(rawValue);\n }\n\n if (options.compress) {\n rawValue = inflateRawSync(Buffer.from(rawValue, \"base64\")).toString(\n \"utf8\",\n );\n }\n\n return this.alepha.codec.decode(options.schema, JSON.parse(rawValue));\n } catch (error) {\n this.log.warn(`Failed to parse cookie \"${name}\"`, error);\n // corrupted or invalid cookie, instruct browser to delete it on next response\n this.deleteCookie(name, cookies);\n return undefined;\n }\n }\n\n public setCookie<T extends TSchema>(\n name: string,\n options: CookiePrimitiveOptions<T>,\n data: Static<T>,\n contextCookies?: Cookies,\n ): void {\n const cookies = this.getCookiesFromContext(contextCookies);\n let value = JSON.stringify(this.alepha.codec.decode(options.schema, data));\n\n if (options.compress) {\n value = deflateRawSync(value).toString(\"base64\");\n }\n\n if (options.encrypt) {\n value = this.encrypt(value);\n }\n\n if (options.sign) {\n value = this.sign(value) + value;\n }\n\n const cookie: Cookie = {\n value: encodeURIComponent(value),\n path: options.path ?? \"/\",\n sameSite: options.sameSite ?? \"lax\",\n secure: options.secure ?? this.alepha.isProduction(),\n httpOnly: options.httpOnly,\n domain: options.domain,\n };\n\n if (options.ttl) {\n cookie.maxAge = this.dateTimeProvider.duration(options.ttl).as(\"seconds\");\n }\n\n cookies.res[name] = cookie;\n }\n\n public deleteCookie<T extends TSchema>(\n name: string,\n contextCookies?: Cookies,\n ): void {\n const cookies = this.getCookiesFromContext(contextCookies);\n cookies.res[name] = null;\n }\n\n // --- Crypto & Parsing ---\n\n protected encrypt(text: string): string {\n const iv = randomBytes(this.IV_LENGTH);\n const cipher = createCipheriv(\n this.ALGORITHM,\n Buffer.from(this.secretKey()),\n iv,\n );\n const encrypted = Buffer.concat([\n cipher.update(text, \"utf8\"),\n cipher.final(),\n ]);\n const authTag = cipher.getAuthTag();\n return Buffer.concat([iv, authTag, encrypted]).toString(\"base64\");\n }\n\n protected decrypt(encryptedText: string): string {\n const data = Buffer.from(encryptedText, \"base64\");\n const iv = data.subarray(0, this.IV_LENGTH);\n const authTag = data.subarray(\n this.IV_LENGTH,\n this.IV_LENGTH + this.AUTH_TAG_LENGTH,\n );\n\n const encrypted = data.subarray(this.IV_LENGTH + this.AUTH_TAG_LENGTH);\n const decipher = createDecipheriv(\n this.ALGORITHM,\n Buffer.from(this.secretKey()),\n iv,\n );\n\n decipher.setAuthTag(authTag);\n\n const decrypted = Buffer.concat([\n decipher.update(encrypted),\n decipher.final(),\n ]);\n\n return decrypted.toString(\"utf8\");\n }\n\n public secretKey(): string {\n let secret = this.env.APP_SECRET;\n if (secret.length < 32) {\n // pad secret to 32 bytes\n secret = secret.padEnd(32, \"0\");\n } else if (secret.length > 32) {\n // truncate secret to 32 bytes\n secret = secret.substring(0, 32);\n }\n return secret;\n }\n\n protected sign(data: string): string {\n return createHmac(\"sha256\", this.secretKey()).update(data).digest(\"hex\");\n }\n}\n","import {\n $inject,\n createPrimitive,\n KIND,\n Primitive,\n type Static,\n type TSchema,\n} from \"alepha\";\nimport type { DurationLike } from \"alepha/datetime\";\nimport { ServerCookiesProvider } from \"../providers/ServerCookiesProvider.ts\";\n\n/**\n * Declares a type-safe, configurable HTTP cookie.\n * This primitive provides methods to get, set, and delete the cookie\n * within the server request/response cycle.\n */\nexport const $cookie = <T extends TSchema>(\n options: CookiePrimitiveOptions<T>,\n): AbstractCookiePrimitive<T> => {\n return createPrimitive(CookiePrimitive<T>, options);\n};\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface CookiePrimitiveOptions<T extends TSchema> {\n /** The schema for the cookie's value, used for validation and type safety. */\n schema: T;\n\n /** The name of the cookie. */\n name?: string;\n\n /** The cookie's path. Defaults to \"/\". */\n path?: string;\n\n /** Time-to-live for the cookie. Maps to `Max-Age`. */\n ttl?: DurationLike;\n\n /** If true, the cookie is only sent over HTTPS. Defaults to true in production. */\n secure?: boolean;\n\n /** If true, the cookie cannot be accessed by client-side scripts. */\n httpOnly?: boolean;\n\n /** SameSite policy for the cookie. Defaults to \"lax\". */\n sameSite?: \"strict\" | \"lax\" | \"none\";\n\n /** The domain for the cookie. */\n domain?: string;\n\n /** If true, the cookie value will be compressed using zlib. */\n compress?: boolean;\n\n /** If true, the cookie value will be encrypted. Requires `COOKIE_SECRET` env var. */\n encrypt?: boolean;\n\n /** If true, the cookie will be signed to prevent tampering. Requires `COOKIE_SECRET` env var. */\n sign?: boolean;\n}\n\nexport interface AbstractCookiePrimitive<T extends TSchema> {\n readonly name: string;\n readonly options: CookiePrimitiveOptions<T>;\n set(\n value: Static<T>,\n options?: { cookies?: Cookies; ttl?: DurationLike },\n ): void;\n get(options?: { cookies?: Cookies }): Static<T> | undefined;\n del(options?: { cookies?: Cookies }): void;\n}\n\nexport class CookiePrimitive<T extends TSchema>\n extends Primitive<CookiePrimitiveOptions<T>>\n implements AbstractCookiePrimitive<T>\n{\n protected readonly serverCookiesProvider = $inject(ServerCookiesProvider);\n\n public get schema(): T {\n return this.options.schema;\n }\n\n public get name(): string {\n return this.options.name ?? `${this.config.propertyKey}`;\n }\n\n /**\n * Sets the cookie with the given value in the current request's response.\n */\n public set(\n value: Static<T>,\n options?: { cookies?: Cookies; ttl?: DurationLike },\n ): void {\n this.serverCookiesProvider.setCookie(\n this.name,\n {\n ...this.options,\n ttl: options?.ttl ?? this.options.ttl,\n },\n value,\n options?.cookies,\n );\n }\n\n /**\n * Gets the cookie value from the current request. Returns undefined if not found or invalid.\n */\n public get(options?: { cookies?: Cookies }): Static<T> | undefined {\n return this.serverCookiesProvider.getCookie(\n this.name,\n this.options,\n options?.cookies,\n );\n }\n\n /**\n * Deletes the cookie in the current request's response.\n */\n public del(options?: { cookies?: Cookies }): void {\n this.serverCookiesProvider.deleteCookie(this.name, options?.cookies);\n }\n}\n\n$cookie[KIND] = CookiePrimitive;\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface Cookies {\n req: Record<string, string>;\n res: Record<string, Cookie | null>;\n}\n\nexport interface Cookie {\n value: string;\n path?: string;\n maxAge?: number;\n secure?: boolean;\n httpOnly?: boolean;\n sameSite?: \"strict\" | \"lax\" | \"none\";\n domain?: string;\n}\n","import { $module } from \"alepha\";\nimport { AlephaServer } from \"alepha/server\";\nimport { $cookie, type Cookies } from \"./primitives/$cookie.ts\";\nimport { ServerCookiesProvider } from \"./providers/ServerCookiesProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport * from \"./primitives/$cookie.ts\";\nexport * from \"./providers/ServerCookiesProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\ndeclare module \"alepha/server\" {\n interface ServerRequest {\n cookies: Cookies;\n }\n}\n\n/**\n * Provides HTTP cookie management capabilities for server requests and responses with type-safe cookie primitives.\n *\n * The server-cookies module enables declarative cookie handling using the `$cookie` primitive on class properties.\n * It offers automatic cookie parsing, secure cookie configuration, and seamless integration with server routes\n * for managing user sessions, preferences, and authentication tokens.\n *\n * @see {@link $cookie}\n * @module alepha.server.cookies\n */\nexport const AlephaServerCookies = $module({\n name: \"alepha.server.cookies\",\n primitives: [$cookie],\n services: [AlephaServer, ServerCookiesProvider],\n});\n"],"mappings":";;;;;;;;;AAEA,IAAa,eAAb,MAA0B;CACxB,AAAO,oBAAoB,QAAwC;EACjE,MAAMA,UAAkC,EAAE;EAC1C,MAAM,QAAQ,OAAO,MAAM,IAAI;AAC/B,OAAK,MAAM,QAAQ,OAAO;GACxB,MAAM,CAAC,KAAK,SAAS,KAAK,MAAM,IAAI;AACpC,OAAI,CAAC,OAAO,CAAC,MACX;AAGF,WAAQ,IAAI,MAAM,IAAI,MAAM,MAAM;;AAGpC,SAAO;;CAGT,AAAO,yBACL,SACA,SACU;EACV,MAAM,UAAU,EAAE;AAElB,OAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,QAAQ,EAAE;AAEpD,OAAI,UAAU,MAAM;AAClB,YAAQ,KAAK,GAAG,KAAK,sBAAsB;AAC3C;;AAGF,OAAI,CAAC,OAAO,MACV;AAGF,WAAQ,KAAK,KAAK,eAAe,MAAM,QAAQ,QAAQ,CAAC;;AAG1D,SAAO;;CAGT,AAAO,eACL,MACA,QACA,SACQ;EACR,MAAMC,QAAkB,EAAE;AAE1B,QAAM,KAAK,GAAG,KAAK,GAAG,OAAO,QAAQ;AAErC,MAAI,OAAO,KACT,OAAM,KAAK,QAAQ,OAAO,OAAO;AAEnC,MAAI,OAAO,OACT,OAAM,KAAK,WAAW,OAAO,SAAS;AAExC,MAAI,OAAO,WAAW,SAAS,QAC7B,OAAM,KAAK,SAAS;AAEtB,MAAI,OAAO,SACT,OAAM,KAAK,WAAW;AAExB,MAAI,OAAO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