alepha 0.14.3 → 0.15.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/README.md +2 -5
- package/dist/api/audits/index.d.ts +620 -811
- package/dist/api/audits/index.d.ts.map +1 -1
- package/dist/api/files/index.d.ts +185 -377
- package/dist/api/files/index.d.ts.map +1 -1
- package/dist/api/files/index.js +0 -1
- package/dist/api/files/index.js.map +1 -1
- package/dist/api/jobs/index.d.ts +245 -435
- package/dist/api/jobs/index.d.ts.map +1 -1
- package/dist/api/notifications/index.d.ts +238 -429
- package/dist/api/notifications/index.d.ts.map +1 -1
- package/dist/api/parameters/index.d.ts +236 -427
- package/dist/api/parameters/index.d.ts.map +1 -1
- package/dist/api/users/index.browser.js +1 -2
- package/dist/api/users/index.browser.js.map +1 -1
- package/dist/api/users/index.d.ts +1010 -1196
- package/dist/api/users/index.d.ts.map +1 -1
- package/dist/api/users/index.js +178 -151
- package/dist/api/users/index.js.map +1 -1
- package/dist/api/verifications/index.d.ts +17 -17
- package/dist/api/verifications/index.d.ts.map +1 -1
- package/dist/batch/index.d.ts +122 -122
- package/dist/batch/index.d.ts.map +1 -1
- package/dist/batch/index.js +1 -2
- package/dist/batch/index.js.map +1 -1
- package/dist/bucket/index.d.ts +163 -163
- package/dist/bucket/index.d.ts.map +1 -1
- package/dist/cache/core/index.d.ts +46 -46
- package/dist/cache/core/index.d.ts.map +1 -1
- package/dist/cache/redis/index.d.ts.map +1 -1
- package/dist/cli/index.d.ts +384 -285
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +1113 -623
- package/dist/cli/index.js.map +1 -1
- package/dist/command/index.d.ts +299 -300
- package/dist/command/index.d.ts.map +1 -1
- package/dist/command/index.js +13 -9
- package/dist/command/index.js.map +1 -1
- package/dist/core/index.browser.js +445 -103
- package/dist/core/index.browser.js.map +1 -1
- package/dist/core/index.d.ts +733 -625
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +446 -103
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.native.js +445 -103
- package/dist/core/index.native.js.map +1 -1
- package/dist/datetime/index.d.ts +44 -44
- package/dist/datetime/index.d.ts.map +1 -1
- package/dist/datetime/index.js +4 -4
- package/dist/datetime/index.js.map +1 -1
- package/dist/email/index.d.ts +97 -50
- package/dist/email/index.d.ts.map +1 -1
- package/dist/email/index.js +129 -33
- package/dist/email/index.js.map +1 -1
- package/dist/fake/index.d.ts +7981 -14
- package/dist/fake/index.d.ts.map +1 -1
- package/dist/file/index.d.ts +523 -390
- package/dist/file/index.d.ts.map +1 -1
- package/dist/file/index.js +253 -1
- package/dist/file/index.js.map +1 -1
- package/dist/lock/core/index.d.ts +208 -208
- package/dist/lock/core/index.d.ts.map +1 -1
- package/dist/lock/redis/index.d.ts.map +1 -1
- package/dist/logger/index.d.ts +25 -26
- package/dist/logger/index.d.ts.map +1 -1
- package/dist/logger/index.js +12 -2
- package/dist/logger/index.js.map +1 -1
- package/dist/mcp/index.d.ts +197 -197
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/orm/chunk-DtkW-qnP.js +38 -0
- package/dist/orm/index.browser.js.map +1 -1
- package/dist/orm/index.bun.js +2814 -0
- package/dist/orm/index.bun.js.map +1 -0
- package/dist/orm/index.d.ts +1228 -1216
- package/dist/orm/index.d.ts.map +1 -1
- package/dist/orm/index.js +2041 -1967
- package/dist/orm/index.js.map +1 -1
- package/dist/queue/core/index.d.ts +248 -248
- package/dist/queue/core/index.d.ts.map +1 -1
- package/dist/queue/redis/index.d.ts.map +1 -1
- package/dist/redis/index.bun.js +285 -0
- package/dist/redis/index.bun.js.map +1 -0
- package/dist/redis/index.d.ts +118 -136
- package/dist/redis/index.d.ts.map +1 -1
- package/dist/redis/index.js +18 -38
- package/dist/redis/index.js.map +1 -1
- package/dist/retry/index.d.ts +69 -69
- package/dist/retry/index.d.ts.map +1 -1
- package/dist/router/index.d.ts +6 -6
- package/dist/router/index.d.ts.map +1 -1
- package/dist/scheduler/index.d.ts +25 -25
- package/dist/scheduler/index.d.ts.map +1 -1
- package/dist/security/index.browser.js +5 -1
- package/dist/security/index.browser.js.map +1 -1
- package/dist/security/index.d.ts +417 -254
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/index.js +386 -86
- package/dist/security/index.js.map +1 -1
- package/dist/server/auth/index.d.ts +110 -110
- package/dist/server/auth/index.d.ts.map +1 -1
- package/dist/server/auth/index.js +20 -20
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/cache/index.d.ts +62 -47
- package/dist/server/cache/index.d.ts.map +1 -1
- package/dist/server/cache/index.js +56 -3
- package/dist/server/cache/index.js.map +1 -1
- package/dist/server/compress/index.d.ts +6 -0
- package/dist/server/compress/index.d.ts.map +1 -1
- package/dist/server/compress/index.js +36 -1
- package/dist/server/compress/index.js.map +1 -1
- package/dist/server/cookies/index.d.ts +6 -6
- package/dist/server/cookies/index.d.ts.map +1 -1
- package/dist/server/cookies/index.js +3 -3
- package/dist/server/cookies/index.js.map +1 -1
- package/dist/server/core/index.browser.js +2 -2
- package/dist/server/core/index.browser.js.map +1 -1
- package/dist/server/core/index.d.ts +242 -150
- package/dist/server/core/index.d.ts.map +1 -1
- package/dist/server/core/index.js +294 -125
- package/dist/server/core/index.js.map +1 -1
- package/dist/server/cors/index.d.ts +11 -12
- package/dist/server/cors/index.d.ts.map +1 -1
- package/dist/server/health/index.d.ts +0 -1
- package/dist/server/health/index.d.ts.map +1 -1
- package/dist/server/helmet/index.d.ts +2 -2
- package/dist/server/helmet/index.d.ts.map +1 -1
- package/dist/server/links/index.browser.js.map +1 -1
- package/dist/server/links/index.d.ts +123 -124
- package/dist/server/links/index.d.ts.map +1 -1
- package/dist/server/links/index.js +1 -2
- package/dist/server/links/index.js.map +1 -1
- package/dist/server/metrics/index.d.ts.map +1 -1
- package/dist/server/multipart/index.d.ts +6 -6
- package/dist/server/multipart/index.d.ts.map +1 -1
- package/dist/server/proxy/index.d.ts +102 -103
- package/dist/server/proxy/index.d.ts.map +1 -1
- package/dist/server/rate-limit/index.d.ts +16 -16
- package/dist/server/rate-limit/index.d.ts.map +1 -1
- package/dist/server/static/index.d.ts +44 -44
- package/dist/server/static/index.d.ts.map +1 -1
- package/dist/server/static/index.js +4 -0
- package/dist/server/static/index.js.map +1 -1
- package/dist/server/swagger/index.d.ts +48 -49
- package/dist/server/swagger/index.d.ts.map +1 -1
- package/dist/server/swagger/index.js +3 -5
- package/dist/server/swagger/index.js.map +1 -1
- package/dist/sms/index.d.ts +13 -11
- package/dist/sms/index.d.ts.map +1 -1
- package/dist/sms/index.js +7 -7
- package/dist/sms/index.js.map +1 -1
- package/dist/thread/index.d.ts +71 -72
- package/dist/thread/index.d.ts.map +1 -1
- package/dist/topic/core/index.d.ts +318 -318
- package/dist/topic/core/index.d.ts.map +1 -1
- package/dist/topic/redis/index.d.ts +6 -6
- package/dist/topic/redis/index.d.ts.map +1 -1
- package/dist/vite/index.d.ts +5805 -249
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +599 -513
- package/dist/vite/index.js.map +1 -1
- package/dist/websocket/index.browser.js +6 -6
- package/dist/websocket/index.browser.js.map +1 -1
- package/dist/websocket/index.d.ts +247 -247
- package/dist/websocket/index.d.ts.map +1 -1
- package/dist/websocket/index.js +6 -6
- package/dist/websocket/index.js.map +1 -1
- package/package.json +9 -14
- package/src/api/files/controllers/AdminFileStatsController.ts +0 -1
- package/src/api/users/atoms/realmAuthSettingsAtom.ts +5 -0
- package/src/api/users/controllers/{UserRealmController.ts → RealmController.ts} +11 -11
- package/src/api/users/entities/users.ts +1 -1
- package/src/api/users/index.ts +8 -8
- package/src/api/users/primitives/{$userRealm.ts → $realm.ts} +17 -19
- package/src/api/users/providers/{UserRealmProvider.ts → RealmProvider.ts} +26 -30
- package/src/api/users/schemas/{userRealmConfigSchema.ts → realmConfigSchema.ts} +2 -2
- package/src/api/users/services/CredentialService.ts +7 -7
- package/src/api/users/services/IdentityService.ts +4 -4
- package/src/api/users/services/RegistrationService.spec.ts +25 -27
- package/src/api/users/services/RegistrationService.ts +38 -27
- package/src/api/users/services/SessionCrudService.ts +3 -3
- package/src/api/users/services/SessionService.spec.ts +3 -3
- package/src/api/users/services/SessionService.ts +28 -9
- package/src/api/users/services/UserService.ts +7 -7
- package/src/batch/providers/BatchProvider.ts +1 -2
- package/src/cli/apps/AlephaCli.ts +0 -2
- package/src/cli/apps/AlephaPackageBuilderCli.ts +38 -19
- package/src/cli/assets/apiHelloControllerTs.ts +18 -0
- package/src/cli/assets/apiIndexTs.ts +16 -0
- package/src/cli/assets/claudeMd.ts +303 -0
- package/src/cli/assets/mainBrowserTs.ts +2 -2
- package/src/cli/assets/mainServerTs.ts +24 -0
- package/src/cli/assets/webAppRouterTs.ts +15 -0
- package/src/cli/assets/webHelloComponentTsx.ts +16 -0
- package/src/cli/assets/webIndexTs.ts +16 -0
- package/src/cli/atoms/buildOptions.ts +88 -0
- package/src/cli/commands/build.ts +70 -87
- package/src/cli/commands/db.ts +21 -22
- package/src/cli/commands/deploy.ts +17 -5
- package/src/cli/commands/dev.ts +22 -14
- package/src/cli/commands/format.ts +8 -2
- package/src/cli/commands/gen/env.ts +53 -0
- package/src/cli/commands/gen/openapi.ts +1 -1
- package/src/cli/commands/gen/resource.ts +15 -0
- package/src/cli/commands/gen.ts +7 -1
- package/src/cli/commands/init.ts +74 -30
- package/src/cli/commands/lint.ts +8 -2
- package/src/cli/commands/test.ts +8 -3
- package/src/cli/commands/typecheck.ts +5 -1
- package/src/cli/commands/verify.ts +5 -3
- package/src/cli/defineConfig.ts +49 -7
- package/src/cli/index.ts +0 -1
- package/src/cli/services/AlephaCliUtils.ts +39 -589
- package/src/cli/services/PackageManagerUtils.ts +301 -0
- package/src/cli/services/ProjectScaffolder.ts +306 -0
- package/src/command/helpers/Runner.spec.ts +2 -2
- package/src/command/helpers/Runner.ts +16 -4
- package/src/command/primitives/$command.ts +0 -6
- package/src/command/providers/CliProvider.ts +1 -3
- package/src/core/Alepha.ts +42 -0
- package/src/core/__tests__/Alepha-graph.spec.ts +4 -0
- package/src/core/index.shared.ts +1 -0
- package/src/core/index.ts +2 -0
- package/src/core/primitives/$hook.ts +6 -2
- package/src/core/primitives/$module.spec.ts +4 -0
- package/src/core/providers/AlsProvider.ts +1 -1
- package/src/core/providers/CodecManager.spec.ts +12 -6
- package/src/core/providers/CodecManager.ts +26 -6
- package/src/core/providers/EventManager.ts +169 -13
- package/src/core/providers/KeylessJsonSchemaCodec.spec.ts +621 -0
- package/src/core/providers/KeylessJsonSchemaCodec.ts +407 -0
- package/src/core/providers/StateManager.spec.ts +27 -16
- package/src/email/providers/LocalEmailProvider.spec.ts +111 -87
- package/src/email/providers/LocalEmailProvider.ts +52 -15
- package/src/email/providers/NodemailerEmailProvider.ts +167 -56
- package/src/file/errors/FileError.ts +7 -0
- package/src/file/index.ts +9 -1
- package/src/file/providers/MemoryFileSystemProvider.ts +393 -0
- package/src/logger/index.ts +15 -3
- package/src/mcp/transports/StdioMcpTransport.ts +1 -1
- package/src/orm/index.browser.ts +1 -19
- package/src/orm/index.bun.ts +77 -0
- package/src/orm/index.shared-server.ts +22 -0
- package/src/orm/index.shared.ts +15 -0
- package/src/orm/index.ts +13 -39
- package/src/orm/providers/drivers/BunPostgresProvider.ts +3 -5
- package/src/orm/providers/drivers/BunSqliteProvider.ts +1 -1
- package/src/orm/providers/drivers/CloudflareD1Provider.ts +4 -0
- package/src/orm/providers/drivers/DatabaseProvider.ts +4 -0
- package/src/orm/providers/drivers/PglitePostgresProvider.ts +4 -0
- package/src/orm/services/Repository.ts +8 -0
- package/src/queue/core/providers/WorkerProvider.spec.ts +48 -32
- package/src/redis/index.bun.ts +35 -0
- package/src/redis/providers/BunRedisProvider.ts +12 -43
- package/src/redis/providers/BunRedisSubscriberProvider.ts +2 -3
- package/src/redis/providers/NodeRedisProvider.ts +16 -34
- package/src/{server/security → security}/__tests__/BasicAuth.spec.ts +11 -11
- package/src/{server/security → security}/__tests__/ServerSecurityProvider-realm.spec.ts +21 -16
- package/src/{server/security/providers → security/__tests__}/ServerSecurityProvider.spec.ts +5 -5
- package/src/security/index.browser.ts +5 -0
- package/src/security/index.ts +90 -7
- package/src/security/primitives/{$realm.spec.ts → $issuer.spec.ts} +11 -11
- package/src/security/primitives/{$realm.ts → $issuer.ts} +20 -17
- package/src/security/primitives/$role.ts +5 -5
- package/src/security/primitives/$serviceAccount.spec.ts +5 -5
- package/src/security/primitives/$serviceAccount.ts +3 -3
- package/src/{server/security → security}/providers/ServerSecurityProvider.ts +5 -7
- package/src/server/auth/primitives/$auth.ts +10 -10
- package/src/server/auth/primitives/$authCredentials.ts +3 -3
- package/src/server/auth/primitives/$authGithub.ts +3 -3
- package/src/server/auth/primitives/$authGoogle.ts +3 -3
- package/src/server/auth/providers/ServerAuthProvider.ts +13 -13
- package/src/server/cache/providers/ServerCacheProvider.spec.ts +183 -0
- package/src/server/cache/providers/ServerCacheProvider.ts +95 -10
- package/src/server/compress/providers/ServerCompressProvider.ts +61 -2
- package/src/server/cookies/providers/ServerCookiesProvider.ts +3 -3
- package/src/server/core/helpers/ServerReply.ts +2 -2
- package/src/server/core/providers/NodeHttpServerProvider.ts +25 -6
- package/src/server/core/providers/ServerBodyParserProvider.ts +19 -23
- package/src/server/core/providers/ServerLoggerProvider.ts +23 -19
- package/src/server/core/providers/ServerProvider.ts +155 -22
- package/src/server/core/providers/ServerRouterProvider.ts +259 -115
- package/src/server/core/providers/ServerTimingProvider.ts +2 -2
- package/src/server/links/index.ts +1 -1
- package/src/server/links/providers/LinkProvider.ts +1 -1
- package/src/server/static/providers/ServerStaticProvider.ts +10 -0
- package/src/server/swagger/index.ts +1 -1
- package/src/server/swagger/providers/ServerSwaggerProvider.ts +5 -8
- package/src/sms/providers/LocalSmsProvider.spec.ts +153 -111
- package/src/sms/providers/LocalSmsProvider.ts +8 -7
- package/src/vite/helpers/boot.ts +28 -17
- package/src/vite/helpers/importViteReact.ts +13 -0
- package/src/vite/index.ts +1 -21
- package/src/vite/plugins/viteAlephaDev.ts +16 -1
- package/src/vite/plugins/viteAlephaSsrPreload.ts +222 -0
- package/src/vite/tasks/buildClient.ts +11 -0
- package/src/vite/tasks/buildServer.ts +59 -4
- package/src/vite/tasks/devServer.ts +71 -0
- package/src/vite/tasks/generateCloudflare.ts +7 -0
- package/src/vite/tasks/index.ts +2 -1
- package/dist/server/security/index.browser.js +0 -13
- package/dist/server/security/index.browser.js.map +0 -1
- package/dist/server/security/index.d.ts +0 -173
- package/dist/server/security/index.d.ts.map +0 -1
- package/dist/server/security/index.js +0 -311
- package/dist/server/security/index.js.map +0 -1
- package/src/cli/assets/appRouterTs.ts +0 -9
- package/src/cli/assets/mainTs.ts +0 -13
- package/src/cli/assets/viteConfigTs.ts +0 -14
- package/src/cli/commands/run.ts +0 -24
- package/src/server/security/index.browser.ts +0 -10
- package/src/server/security/index.ts +0 -94
- package/src/vite/plugins/viteAlepha.ts +0 -37
- package/src/vite/plugins/viteAlephaBuild.ts +0 -281
- /package/src/{server/security → security}/primitives/$basicAuth.ts +0 -0
- /package/src/{server/security → security}/providers/ServerBasicAuthProvider.ts +0 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
4
|
+
import type { Plugin } from "vite";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Preload manifest mapping short keys to source paths.
|
|
8
|
+
* Generated at build time, consumed by SSRManifestProvider at runtime.
|
|
9
|
+
*/
|
|
10
|
+
export interface PreloadManifest {
|
|
11
|
+
[key: string]: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Vite plugin that generates a preload manifest for SSR module preloading.
|
|
16
|
+
*
|
|
17
|
+
* Instead of injecting source paths directly into $page definitions (which would
|
|
18
|
+
* leak component paths in the browser bundle), this plugin:
|
|
19
|
+
*
|
|
20
|
+
* 1. Collects all lazy import paths from $page definitions during transform
|
|
21
|
+
* 2. Generates a manifest file mapping short keys to resolved source paths
|
|
22
|
+
* 3. Injects only the short key into $page definitions
|
|
23
|
+
*
|
|
24
|
+
* The manifest is written to `.vite/preload-manifest.json` alongside Vite's
|
|
25
|
+
* other manifests. The CLI build command moves all manifests to
|
|
26
|
+
* `dist/server/.ssr/` where SSRManifestProvider loads them at runtime.
|
|
27
|
+
*
|
|
28
|
+
* Before:
|
|
29
|
+
* ```typescript
|
|
30
|
+
* $page({
|
|
31
|
+
* path: '/users/:id',
|
|
32
|
+
* lazy: () => import('./UserDetail.tsx'),
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* After:
|
|
37
|
+
* ```typescript
|
|
38
|
+
* $page({
|
|
39
|
+
* path: '/users/:id',
|
|
40
|
+
* lazy: () => import('./UserDetail.tsx'),
|
|
41
|
+
* [Symbol.for("alepha.page.preload")]: "a1b2c3",
|
|
42
|
+
* })
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* Manifest (.alepha/preload-manifest.json):
|
|
46
|
+
* ```json
|
|
47
|
+
* {
|
|
48
|
+
* "a1b2c3": "src/pages/UserDetail.tsx"
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export function viteAlephaSsrPreload(): Plugin {
|
|
53
|
+
let root = "";
|
|
54
|
+
const preloadMap = new Map<string, string>(); // key -> sourcePath
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Generate a short hash key for a source path.
|
|
58
|
+
* Uses first 8 chars of MD5 hash for brevity while avoiding collisions.
|
|
59
|
+
*/
|
|
60
|
+
function generateKey(sourcePath: string): string {
|
|
61
|
+
return createHash("md5").update(sourcePath).digest("hex").slice(0, 8);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
name: "alepha-preload",
|
|
66
|
+
configResolved(config) {
|
|
67
|
+
root = config.root;
|
|
68
|
+
},
|
|
69
|
+
transform(code, id) {
|
|
70
|
+
// Only process TypeScript/JavaScript files
|
|
71
|
+
if (!id.match(/\.[tj]sx?$/)) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Skip node_modules
|
|
76
|
+
if (id.includes("node_modules")) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Quick check if file contains $page with lazy
|
|
81
|
+
if (!code.includes("$page") || !code.includes("lazy")) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Collect all insertions first, then apply in reverse order
|
|
86
|
+
const insertions: Array<{ position: number; text: string }> = [];
|
|
87
|
+
|
|
88
|
+
// Find all $page({ occurrences
|
|
89
|
+
const pageStartRegex = /\$page\s*\(\s*\{/g;
|
|
90
|
+
let pageMatch: RegExpExecArray | null = pageStartRegex.exec(code);
|
|
91
|
+
|
|
92
|
+
while (pageMatch !== null) {
|
|
93
|
+
const startIndex = pageMatch.index;
|
|
94
|
+
const objectStartIndex = startIndex + pageMatch[0].length - 1; // Position of '{'
|
|
95
|
+
|
|
96
|
+
// Find the matching closing brace using brace counting
|
|
97
|
+
let braceCount = 1;
|
|
98
|
+
let i = objectStartIndex + 1;
|
|
99
|
+
while (i < code.length && braceCount > 0) {
|
|
100
|
+
if (code[i] === "{") braceCount++;
|
|
101
|
+
else if (code[i] === "}") braceCount--;
|
|
102
|
+
i++;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Malformed, skip
|
|
106
|
+
if (braceCount !== 0) {
|
|
107
|
+
pageMatch = pageStartRegex.exec(code);
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const objectEndIndex = i - 1; // Position of matching '}'
|
|
112
|
+
const pageContent = code.slice(objectStartIndex, objectEndIndex + 1);
|
|
113
|
+
|
|
114
|
+
// Skip if already has preload symbol
|
|
115
|
+
if (pageContent.includes("alepha.page.preload")) {
|
|
116
|
+
pageMatch = pageStartRegex.exec(code);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Find lazy: () => import('...') within this $page block
|
|
121
|
+
const lazyRegex =
|
|
122
|
+
/lazy\s*:\s*\(\s*\)\s*=>\s*import\s*\(\s*['"]([^'"]+)['"]\s*\)/;
|
|
123
|
+
const lazyMatch = lazyRegex.exec(pageContent);
|
|
124
|
+
|
|
125
|
+
if (!lazyMatch) {
|
|
126
|
+
pageMatch = pageStartRegex.exec(code);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const importPath = lazyMatch[1];
|
|
131
|
+
|
|
132
|
+
// Resolve the import path relative to the current file
|
|
133
|
+
const currentDir = dirname(id);
|
|
134
|
+
let resolvedPath: string;
|
|
135
|
+
|
|
136
|
+
if (importPath.startsWith(".")) {
|
|
137
|
+
// Relative import
|
|
138
|
+
resolvedPath = resolve(currentDir, importPath);
|
|
139
|
+
} else if (importPath.startsWith("/")) {
|
|
140
|
+
// Absolute import from root
|
|
141
|
+
resolvedPath = resolve(root, importPath.slice(1));
|
|
142
|
+
} else {
|
|
143
|
+
// Package import - skip preloading for external packages
|
|
144
|
+
pageMatch = pageStartRegex.exec(code);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Make path relative to root for SSR manifest lookup
|
|
149
|
+
let relativePath = relative(root, resolvedPath);
|
|
150
|
+
|
|
151
|
+
// Normalize path separators for cross-platform compatibility
|
|
152
|
+
relativePath = relativePath.replace(/\\/g, "/");
|
|
153
|
+
|
|
154
|
+
// Handle extension - Vite resolves .jsx imports to .tsx files
|
|
155
|
+
// Try to use .tsx when the source has .jsx since TypeScript is more common
|
|
156
|
+
if (!relativePath.match(/\.[tj]sx?$/)) {
|
|
157
|
+
relativePath = `${relativePath}.tsx`;
|
|
158
|
+
} else if (relativePath.endsWith(".jsx")) {
|
|
159
|
+
// Import said .jsx but actual file is likely .tsx
|
|
160
|
+
relativePath = relativePath.replace(/\.jsx$/, ".tsx");
|
|
161
|
+
} else if (relativePath.endsWith(".js")) {
|
|
162
|
+
// Import said .js but actual file is likely .ts
|
|
163
|
+
relativePath = relativePath.replace(/\.js$/, ".ts");
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Generate short key and store mapping
|
|
167
|
+
const key = generateKey(relativePath);
|
|
168
|
+
preloadMap.set(key, relativePath);
|
|
169
|
+
|
|
170
|
+
// Check if we need a comma (look at character before closing brace)
|
|
171
|
+
const beforeBrace = code.slice(0, objectEndIndex).trimEnd();
|
|
172
|
+
const needsComma = !beforeBrace.endsWith(",");
|
|
173
|
+
// Use Symbol.for() so it can be looked up at runtime without importing
|
|
174
|
+
// Only inject the short key, not the full path
|
|
175
|
+
const preloadProperty = `${needsComma ? "," : ""} [Symbol.for("alepha.page.preload")]: "${key}"`;
|
|
176
|
+
|
|
177
|
+
insertions.push({ position: objectEndIndex, text: preloadProperty });
|
|
178
|
+
|
|
179
|
+
pageMatch = pageStartRegex.exec(code);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (insertions.length === 0) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Apply insertions in reverse order to preserve positions
|
|
187
|
+
let result = code;
|
|
188
|
+
for (let j = insertions.length - 1; j >= 0; j--) {
|
|
189
|
+
const { position, text } = insertions[j];
|
|
190
|
+
result = result.slice(0, position) + text + result.slice(position);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return {
|
|
194
|
+
code: result,
|
|
195
|
+
map: null,
|
|
196
|
+
};
|
|
197
|
+
},
|
|
198
|
+
writeBundle(options) {
|
|
199
|
+
// Only process client build (outputs to dist/public or similar)
|
|
200
|
+
// Skip server build which outputs to dist/server
|
|
201
|
+
const outDir = options.dir || "";
|
|
202
|
+
if (outDir.includes("server")) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Write the preload manifest to the same .vite directory Vite uses
|
|
207
|
+
// The CLI build command will move all manifests to dist/server/.ssr/
|
|
208
|
+
if (preloadMap.size > 0) {
|
|
209
|
+
const viteDir = join(outDir, ".vite");
|
|
210
|
+
|
|
211
|
+
// Ensure .vite directory exists
|
|
212
|
+
if (!existsSync(viteDir)) {
|
|
213
|
+
mkdirSync(viteDir, { recursive: true });
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const manifest: PreloadManifest = Object.fromEntries(preloadMap);
|
|
217
|
+
const manifestPath = join(viteDir, "preload-manifest.json");
|
|
218
|
+
writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
}
|
|
@@ -2,6 +2,8 @@ import type { UserConfig } from "vite";
|
|
|
2
2
|
import { analyzer as viteAnalyzer } from "vite-bundle-analyzer";
|
|
3
3
|
import { createBufferedLogger } from "../helpers/createBufferedLogger.ts";
|
|
4
4
|
import { importVite } from "../helpers/importVite.ts";
|
|
5
|
+
import { importViteReact } from "../helpers/importViteReact.ts";
|
|
6
|
+
import { viteAlephaSsrPreload } from "../plugins/viteAlephaSsrPreload.ts";
|
|
5
7
|
import {
|
|
6
8
|
type ViteCompressOptions,
|
|
7
9
|
viteCompress,
|
|
@@ -62,6 +64,12 @@ export async function buildClient(opts: BuildClientOptions): Promise<void> {
|
|
|
62
64
|
const { build: viteBuild, mergeConfig } = await importVite();
|
|
63
65
|
const plugins: any[] = [];
|
|
64
66
|
|
|
67
|
+
const viteReact = await importViteReact();
|
|
68
|
+
if (viteReact) plugins.push(viteReact());
|
|
69
|
+
|
|
70
|
+
// Add preload plugin for SSR module preloading
|
|
71
|
+
plugins.push(viteAlephaSsrPreload());
|
|
72
|
+
|
|
65
73
|
const compress: ViteCompressOptions | undefined = opts.precompress
|
|
66
74
|
? typeof opts.precompress === "object"
|
|
67
75
|
? opts.precompress
|
|
@@ -93,6 +101,9 @@ export async function buildClient(opts: BuildClientOptions): Promise<void> {
|
|
|
93
101
|
build: {
|
|
94
102
|
chunkSizeWarningLimit: 1000,
|
|
95
103
|
outDir: opts.dist,
|
|
104
|
+
// Generate manifest for SSR module preloading
|
|
105
|
+
manifest: true,
|
|
106
|
+
ssrManifest: true,
|
|
96
107
|
rollupOptions: {
|
|
97
108
|
output: {
|
|
98
109
|
entryFileNames: "entry.[hash].js",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readFile, writeFile } from "node:fs/promises";
|
|
1
|
+
import { readFile, rm, writeFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { AlephaError } from "alepha";
|
|
4
4
|
import type * as vite from "vite";
|
|
@@ -6,6 +6,8 @@ import type { UserConfig } from "vite";
|
|
|
6
6
|
import { analyzer as viteAnalyzer } from "vite-bundle-analyzer";
|
|
7
7
|
import { createBufferedLogger } from "../helpers/createBufferedLogger.ts";
|
|
8
8
|
import { importVite } from "../helpers/importVite.ts";
|
|
9
|
+
import { importViteReact } from "../helpers/importViteReact.ts";
|
|
10
|
+
import { viteAlephaSsrPreload } from "../plugins/viteAlephaSsrPreload.ts";
|
|
9
11
|
import { generateExternals } from "./generateExternals.ts";
|
|
10
12
|
|
|
11
13
|
export interface BuildServerOptions {
|
|
@@ -41,6 +43,11 @@ export interface BuildServerOptions {
|
|
|
41
43
|
* @default false
|
|
42
44
|
*/
|
|
43
45
|
silent?: boolean;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Add more entry point conditions for SSR module resolution (e.g., "bun").
|
|
49
|
+
*/
|
|
50
|
+
conditions?: string[];
|
|
44
51
|
}
|
|
45
52
|
|
|
46
53
|
export interface BuildServerResult {
|
|
@@ -63,6 +70,13 @@ export async function buildServer(
|
|
|
63
70
|
const { build: viteBuild, mergeConfig } = await importVite();
|
|
64
71
|
const plugins: any[] = [];
|
|
65
72
|
|
|
73
|
+
const viteReact = await importViteReact();
|
|
74
|
+
if (viteReact && opts.clientDir) {
|
|
75
|
+
plugins.push(viteReact());
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
plugins.push(viteAlephaSsrPreload());
|
|
79
|
+
|
|
66
80
|
if (opts.stats) {
|
|
67
81
|
plugins.push(
|
|
68
82
|
viteAnalyzer({
|
|
@@ -74,6 +88,11 @@ export async function buildServer(
|
|
|
74
88
|
// Create buffered logger for silent mode
|
|
75
89
|
const logger = opts.silent ? createBufferedLogger() : undefined;
|
|
76
90
|
|
|
91
|
+
const conditions = ["node", "import", "module", "default"];
|
|
92
|
+
if (opts.conditions) {
|
|
93
|
+
conditions.unshift(...opts.conditions);
|
|
94
|
+
}
|
|
95
|
+
|
|
77
96
|
const viteBuildServerConfig: UserConfig = {
|
|
78
97
|
mode: "production",
|
|
79
98
|
logLevel: opts.silent ? "silent" : undefined,
|
|
@@ -83,15 +102,16 @@ export async function buildServer(
|
|
|
83
102
|
publicDir: false,
|
|
84
103
|
ssr: {
|
|
85
104
|
noExternal: true,
|
|
105
|
+
resolve: { conditions },
|
|
86
106
|
},
|
|
87
107
|
build: {
|
|
88
|
-
sourcemap: true,
|
|
108
|
+
sourcemap: true,
|
|
89
109
|
ssr: opts.entry,
|
|
90
110
|
outDir: `${opts.distDir}/server`,
|
|
91
111
|
minify: true,
|
|
92
112
|
chunkSizeWarningLimit: 10000,
|
|
93
113
|
rollupOptions: {
|
|
94
|
-
external: [
|
|
114
|
+
external: [/^bun(:|$)/, /^cloudflare:/],
|
|
95
115
|
output: {
|
|
96
116
|
entryFileNames: "[hash].js",
|
|
97
117
|
chunkFileNames: "[hash].js",
|
|
@@ -138,6 +158,29 @@ export async function buildServer(
|
|
|
138
158
|
template = `__alepha.set("alepha.react.server.template", \`${index.replace(/>\s*</g, "><").trim()}\`);\n`;
|
|
139
159
|
}
|
|
140
160
|
|
|
161
|
+
// Embed SSR manifests if client was built
|
|
162
|
+
// This bundles all manifest data into index.js for serverless deployments
|
|
163
|
+
let manifest = "";
|
|
164
|
+
if (opts.clientDir) {
|
|
165
|
+
const viteDir = `${opts.distDir}/${opts.clientDir}/.vite`;
|
|
166
|
+
const ssrManifest = await loadJsonFile(`${viteDir}/ssr-manifest.json`);
|
|
167
|
+
const clientManifest = await loadJsonFile(`${viteDir}/manifest.json`);
|
|
168
|
+
const preloadManifest = await loadJsonFile(
|
|
169
|
+
`${viteDir}/preload-manifest.json`,
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
const combined = {
|
|
173
|
+
ssr: ssrManifest,
|
|
174
|
+
client: clientManifest,
|
|
175
|
+
preload: preloadManifest,
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
manifest = `__alepha.set("alepha.react.ssr.manifest", ${JSON.stringify(combined)});\n`;
|
|
179
|
+
|
|
180
|
+
// Remove .vite directory - no longer needed at runtime
|
|
181
|
+
await rm(viteDir, { recursive: true, force: true });
|
|
182
|
+
}
|
|
183
|
+
|
|
141
184
|
const warning =
|
|
142
185
|
"// This file was automatically generated. DO NOT MODIFY." +
|
|
143
186
|
"\n" +
|
|
@@ -145,12 +188,24 @@ export async function buildServer(
|
|
|
145
188
|
|
|
146
189
|
await writeFile(
|
|
147
190
|
`${opts.distDir}/index.js`,
|
|
148
|
-
`${warning}\
|
|
191
|
+
`${warning}\n${template}${manifest}import './server/${entryFile}';\n`.trim(),
|
|
149
192
|
);
|
|
150
193
|
|
|
151
194
|
return { entryFile };
|
|
152
195
|
}
|
|
153
196
|
|
|
197
|
+
/**
|
|
198
|
+
* Load a JSON file, returning undefined if it doesn't exist.
|
|
199
|
+
*/
|
|
200
|
+
async function loadJsonFile(path: string): Promise<any> {
|
|
201
|
+
try {
|
|
202
|
+
const content = await readFile(path, "utf-8");
|
|
203
|
+
return JSON.parse(content);
|
|
204
|
+
} catch {
|
|
205
|
+
return undefined;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
154
209
|
/**
|
|
155
210
|
* Extract entry filename from Vite build result.
|
|
156
211
|
*/
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { InlineConfig } from "vite";
|
|
2
|
+
import { importVite } from "../helpers/importVite.ts";
|
|
3
|
+
import { importViteReact } from "../helpers/importViteReact.ts";
|
|
4
|
+
import { viteAlephaDev } from "../plugins/viteAlephaDev.ts";
|
|
5
|
+
import { viteAlephaSsrPreload } from "../plugins/viteAlephaSsrPreload.ts";
|
|
6
|
+
|
|
7
|
+
export interface DevServerOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Path to the server entry file.
|
|
10
|
+
* If not provided, will auto-detect.
|
|
11
|
+
*/
|
|
12
|
+
entry?: string;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Port to run the dev server on.
|
|
16
|
+
*/
|
|
17
|
+
port?: number;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Host to bind the dev server to.
|
|
21
|
+
*/
|
|
22
|
+
host?: string | boolean;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Enable debug logging.
|
|
26
|
+
*/
|
|
27
|
+
debug?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Start Vite development server with Alepha plugins.
|
|
32
|
+
*
|
|
33
|
+
* This task starts the Vite dev server with all required plugins:
|
|
34
|
+
* - @vitejs/plugin-react (JSX/TSX compilation)
|
|
35
|
+
* - viteAlephaDev (Alepha server integration)
|
|
36
|
+
* - viteAlephaSsrPreload (SSR module preloading)
|
|
37
|
+
*/
|
|
38
|
+
export async function devServer(opts: DevServerOptions = {}): Promise<void> {
|
|
39
|
+
const { createServer, mergeConfig } = await importVite();
|
|
40
|
+
const plugins: any[] = [];
|
|
41
|
+
|
|
42
|
+
// Add React plugin for JSX/TSX compilation
|
|
43
|
+
const viteReact = await importViteReact();
|
|
44
|
+
if (viteReact) plugins.push(viteReact());
|
|
45
|
+
|
|
46
|
+
// Add SSR preload plugin
|
|
47
|
+
plugins.push(viteAlephaSsrPreload());
|
|
48
|
+
|
|
49
|
+
// Add Alepha dev plugin
|
|
50
|
+
plugins.push(
|
|
51
|
+
await viteAlephaDev({
|
|
52
|
+
serverEntry: opts.entry,
|
|
53
|
+
debug: opts.debug,
|
|
54
|
+
}),
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const config: InlineConfig = {
|
|
58
|
+
plugins,
|
|
59
|
+
server: {
|
|
60
|
+
port: opts.port,
|
|
61
|
+
host: opts.host,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const server = await createServer(mergeConfig(config, {}));
|
|
66
|
+
await server.listen();
|
|
67
|
+
|
|
68
|
+
console.log(""); // blank line
|
|
69
|
+
server.printUrls();
|
|
70
|
+
server.bindCLIShortcuts({ print: true });
|
|
71
|
+
}
|
|
@@ -45,6 +45,13 @@ export async function generateCloudflare(
|
|
|
45
45
|
main: "./main.cloudflare.js",
|
|
46
46
|
compatibility_flags: ["nodejs_compat"],
|
|
47
47
|
compatibility_date: "2025-11-17",
|
|
48
|
+
no_bundle: true,
|
|
49
|
+
rules: [
|
|
50
|
+
{
|
|
51
|
+
type: "ESModule",
|
|
52
|
+
globs: ["index.js", "server/*.js"],
|
|
53
|
+
},
|
|
54
|
+
],
|
|
48
55
|
...opts.config,
|
|
49
56
|
};
|
|
50
57
|
|
package/src/vite/tasks/index.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Build tasks for Alepha applications.
|
|
3
3
|
*
|
|
4
4
|
* These tasks can be used by:
|
|
5
|
-
* - Vite plugins (viteAlephaDev,
|
|
5
|
+
* - Vite plugins (viteAlephaDev, viteAlephaSsrPreload)
|
|
6
6
|
* - CLI commands (alepha build, alepha dev)
|
|
7
7
|
*
|
|
8
8
|
* Each task is a standalone async function with explicit inputs and outputs.
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
export * from "./buildClient.ts";
|
|
14
14
|
export * from "./buildServer.ts";
|
|
15
15
|
export * from "./copyAssets.ts";
|
|
16
|
+
export * from "./devServer.ts";
|
|
16
17
|
export * from "./generateCloudflare.ts";
|
|
17
18
|
export * from "./generateDocker.ts";
|
|
18
19
|
export * from "./generateExternals.ts";
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { $module } from "alepha";
|
|
2
|
-
import { AlephaSecurity } from "alepha/security";
|
|
3
|
-
import { AlephaServer } from "alepha/server";
|
|
4
|
-
|
|
5
|
-
//#region ../../src/server/security/index.browser.ts
|
|
6
|
-
const AlephaServerSecurity = $module({
|
|
7
|
-
name: "alepha.server.security",
|
|
8
|
-
services: [AlephaServer, AlephaSecurity]
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
12
|
-
export { AlephaServerSecurity };
|
|
13
|
-
//# sourceMappingURL=index.browser.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.browser.js","names":[],"sources":["../../../src/server/security/index.browser.ts"],"sourcesContent":["import { $module } from \"alepha\";\nimport { AlephaSecurity } from \"alepha/security\";\nimport { AlephaServer } from \"alepha/server\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport const AlephaServerSecurity = $module({\n name: \"alepha.server.security\",\n services: [AlephaServer, AlephaSecurity],\n});\n"],"mappings":";;;;;AAMA,MAAa,uBAAuB,QAAQ;CAC1C,MAAM;CACN,UAAU,CAAC,cAAc,eAAe;CACzC,CAAC"}
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import * as alepha1 from "alepha";
|
|
2
|
-
import { Alepha, KIND, Primitive } from "alepha";
|
|
3
|
-
import { JwtProvider, Permission, SecurityProvider, UserAccount, UserAccountToken } from "alepha/security";
|
|
4
|
-
import { FetchOptions, ServerRequest, ServerRouterProvider } from "alepha/server";
|
|
5
|
-
import * as alepha_logger0 from "alepha/logger";
|
|
6
|
-
|
|
7
|
-
//#region ../../src/server/security/providers/ServerBasicAuthProvider.d.ts
|
|
8
|
-
interface BasicAuthOptions {
|
|
9
|
-
username: string;
|
|
10
|
-
password: string;
|
|
11
|
-
}
|
|
12
|
-
interface BasicAuthPrimitiveConfig extends BasicAuthOptions {
|
|
13
|
-
/** Name identifier for this basic auth (default: property key) */
|
|
14
|
-
name?: string;
|
|
15
|
-
/** Path patterns to match (supports wildcards like /devtools/*) */
|
|
16
|
-
paths?: string[];
|
|
17
|
-
}
|
|
18
|
-
declare class ServerBasicAuthProvider {
|
|
19
|
-
protected readonly alepha: Alepha;
|
|
20
|
-
protected readonly log: alepha_logger0.Logger;
|
|
21
|
-
protected readonly routerProvider: ServerRouterProvider;
|
|
22
|
-
protected readonly realm = "Secure Area";
|
|
23
|
-
/**
|
|
24
|
-
* Registered basic auth primitives with their configurations
|
|
25
|
-
*/
|
|
26
|
-
readonly registeredAuths: BasicAuthPrimitiveConfig[];
|
|
27
|
-
/**
|
|
28
|
-
* Register a basic auth configuration (called by primitives)
|
|
29
|
-
*/
|
|
30
|
-
registerAuth(config: BasicAuthPrimitiveConfig): void;
|
|
31
|
-
readonly onStart: alepha1.HookPrimitive<"start">;
|
|
32
|
-
/**
|
|
33
|
-
* Hook into server:onRequest to check basic auth
|
|
34
|
-
*/
|
|
35
|
-
readonly onRequest: alepha1.HookPrimitive<"server:onRequest">;
|
|
36
|
-
/**
|
|
37
|
-
* Hook into action:onRequest to check basic auth for actions
|
|
38
|
-
*/
|
|
39
|
-
readonly onActionRequest: alepha1.HookPrimitive<"action:onRequest">;
|
|
40
|
-
/**
|
|
41
|
-
* Check basic authentication
|
|
42
|
-
*/
|
|
43
|
-
checkAuth(request: ServerRequest, options: BasicAuthOptions): void;
|
|
44
|
-
/**
|
|
45
|
-
* Performs a timing-safe comparison of credentials to prevent timing attacks.
|
|
46
|
-
* Always compares both username and password to avoid leaking which one is wrong.
|
|
47
|
-
*/
|
|
48
|
-
protected timingSafeCredentialCheck(inputUsername: string, inputPassword: string, expectedUsername: string, expectedPassword: string): boolean;
|
|
49
|
-
/**
|
|
50
|
-
* Compares two buffers in constant time, handling different lengths safely.
|
|
51
|
-
* Returns 1 if equal, 0 if not equal.
|
|
52
|
-
*/
|
|
53
|
-
protected safeCompare(input: Buffer, expected: Buffer): number;
|
|
54
|
-
/**
|
|
55
|
-
* Send WWW-Authenticate header
|
|
56
|
-
*/
|
|
57
|
-
protected sendAuthRequired(request: ServerRequest): void;
|
|
58
|
-
}
|
|
59
|
-
declare const isBasicAuth: (value: unknown) => value is {
|
|
60
|
-
basic: BasicAuthOptions;
|
|
61
|
-
};
|
|
62
|
-
//#endregion
|
|
63
|
-
//#region ../../src/server/security/providers/ServerSecurityProvider.d.ts
|
|
64
|
-
declare class ServerSecurityProvider {
|
|
65
|
-
protected readonly log: alepha_logger0.Logger;
|
|
66
|
-
protected readonly securityProvider: SecurityProvider;
|
|
67
|
-
protected readonly jwtProvider: JwtProvider;
|
|
68
|
-
protected readonly alepha: Alepha;
|
|
69
|
-
protected readonly onConfigure: alepha1.HookPrimitive<"configure">;
|
|
70
|
-
protected readonly onActionRequest: alepha1.HookPrimitive<"action:onRequest">;
|
|
71
|
-
protected readonly onRequest: alepha1.HookPrimitive<"server:onRequest">;
|
|
72
|
-
protected check(user: UserAccountToken, secure: ServerRouteSecure): void;
|
|
73
|
-
/**
|
|
74
|
-
* Get the user account token for a local action call.
|
|
75
|
-
* There are three possible sources for the user:
|
|
76
|
-
* - `options.user`: the user passed in the options
|
|
77
|
-
* - `"system"`: the system user from the state (you MUST set state `server.security.system.user`)
|
|
78
|
-
* - `"context"`: the user from the request context (you MUST be in an HTTP request context)
|
|
79
|
-
*
|
|
80
|
-
* Priority order: `options.user` > `"system"` > `"context"`.
|
|
81
|
-
*
|
|
82
|
-
* In testing environment, if no user is provided, a test user is created based on the SecurityProvider's roles.
|
|
83
|
-
*/
|
|
84
|
-
protected createUserFromLocalFunctionContext(options: {
|
|
85
|
-
user?: UserAccountToken | "system" | "context";
|
|
86
|
-
}, permission?: Permission): UserAccountToken;
|
|
87
|
-
protected createTestUser(): UserAccountToken;
|
|
88
|
-
protected readonly onClientRequest: alepha1.HookPrimitive<"client:onRequest">;
|
|
89
|
-
}
|
|
90
|
-
type ServerRouteSecure = {
|
|
91
|
-
realm?: string;
|
|
92
|
-
basic?: BasicAuthOptions;
|
|
93
|
-
};
|
|
94
|
-
//#endregion
|
|
95
|
-
//#region ../../src/server/security/primitives/$basicAuth.d.ts
|
|
96
|
-
/**
|
|
97
|
-
* Declares HTTP Basic Authentication for server routes.
|
|
98
|
-
* This primitive provides methods to protect routes with username/password authentication.
|
|
99
|
-
*/
|
|
100
|
-
declare const $basicAuth: {
|
|
101
|
-
(options: BasicAuthPrimitiveConfig): AbstractBasicAuthPrimitive;
|
|
102
|
-
[KIND]: typeof BasicAuthPrimitive;
|
|
103
|
-
};
|
|
104
|
-
interface AbstractBasicAuthPrimitive {
|
|
105
|
-
readonly name: string;
|
|
106
|
-
readonly options: BasicAuthPrimitiveConfig;
|
|
107
|
-
check(request: ServerRequest, options?: BasicAuthOptions): void;
|
|
108
|
-
}
|
|
109
|
-
declare class BasicAuthPrimitive extends Primitive<BasicAuthPrimitiveConfig> implements AbstractBasicAuthPrimitive {
|
|
110
|
-
protected readonly serverBasicAuthProvider: ServerBasicAuthProvider;
|
|
111
|
-
get name(): string;
|
|
112
|
-
protected onInit(): void;
|
|
113
|
-
/**
|
|
114
|
-
* Checks basic auth for the given request using this primitive's configuration.
|
|
115
|
-
*/
|
|
116
|
-
check(request: ServerRequest, options?: BasicAuthOptions): void;
|
|
117
|
-
}
|
|
118
|
-
//#endregion
|
|
119
|
-
//#region ../../src/server/security/index.d.ts
|
|
120
|
-
declare module "alepha" {
|
|
121
|
-
interface State {
|
|
122
|
-
/**
|
|
123
|
-
* Real (or fake) user account, used for internal actions.
|
|
124
|
-
*
|
|
125
|
-
* If you define this, you assume that all actions are executed by this user by default.
|
|
126
|
-
* > To force a different user, you need to pass it explicitly in the options.
|
|
127
|
-
*/
|
|
128
|
-
"alepha.server.security.system.user"?: UserAccountToken;
|
|
129
|
-
/**
|
|
130
|
-
* The authenticated user account attached to the server request state.
|
|
131
|
-
*
|
|
132
|
-
* @internal
|
|
133
|
-
*/
|
|
134
|
-
"alepha.server.request.user"?: UserAccount;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
declare module "alepha/server" {
|
|
138
|
-
interface ServerRequest<TConfig> {
|
|
139
|
-
user?: UserAccountToken;
|
|
140
|
-
}
|
|
141
|
-
interface ServerActionRequest<TConfig> {
|
|
142
|
-
user: UserAccountToken;
|
|
143
|
-
}
|
|
144
|
-
interface ServerRoute {
|
|
145
|
-
/**
|
|
146
|
-
* If true, the route will be protected by the security provider.
|
|
147
|
-
* All actions are secure by default, but you can disable it for specific actions.
|
|
148
|
-
*/
|
|
149
|
-
secure?: boolean | ServerRouteSecure;
|
|
150
|
-
}
|
|
151
|
-
interface ClientRequestOptions extends FetchOptions {
|
|
152
|
-
/**
|
|
153
|
-
* Forward user from the previous request.
|
|
154
|
-
* If "system", use system user. @see {ServerSecurityProvider.localSystemUser}
|
|
155
|
-
* If "context", use the user from the current context (e.g. request).
|
|
156
|
-
*
|
|
157
|
-
* @default "system" if provided, else "context" if available.
|
|
158
|
-
*/
|
|
159
|
-
user?: UserAccountToken | "system" | "context";
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Plugin for Alepha Server that provides security features. Based on the Alepha Security module.
|
|
164
|
-
*
|
|
165
|
-
* By default, all $action will be guarded by a permission check.
|
|
166
|
-
*
|
|
167
|
-
* @see {@link ServerSecurityProvider}
|
|
168
|
-
* @module alepha.server.security
|
|
169
|
-
*/
|
|
170
|
-
declare const AlephaServerSecurity: alepha1.Service<alepha1.Module>;
|
|
171
|
-
//#endregion
|
|
172
|
-
export { $basicAuth, AbstractBasicAuthPrimitive, AlephaServerSecurity, BasicAuthOptions, BasicAuthPrimitive, BasicAuthPrimitiveConfig, ServerBasicAuthProvider, ServerRouteSecure, ServerSecurityProvider, isBasicAuth };
|
|
173
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/server/security/providers/ServerBasicAuthProvider.ts","../../../src/server/security/providers/ServerSecurityProvider.ts","../../../src/server/security/primitives/$basicAuth.ts","../../../src/server/security/index.ts"],"sourcesContent":[],"mappings":"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"}
|