alepha 0.15.0 → 0.15.2
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 +43 -98
- package/dist/api/audits/index.d.ts +630 -653
- package/dist/api/audits/index.d.ts.map +1 -1
- package/dist/api/audits/index.js +12 -35
- package/dist/api/audits/index.js.map +1 -1
- package/dist/api/files/index.d.ts +365 -358
- package/dist/api/files/index.d.ts.map +1 -1
- package/dist/api/files/index.js +12 -5
- package/dist/api/files/index.js.map +1 -1
- package/dist/api/jobs/index.d.ts +255 -248
- package/dist/api/jobs/index.d.ts.map +1 -1
- package/dist/api/jobs/index.js +10 -3
- package/dist/api/jobs/index.js.map +1 -1
- package/dist/api/keys/index.d.ts +413 -0
- package/dist/api/keys/index.d.ts.map +1 -0
- package/dist/api/keys/index.js +476 -0
- package/dist/api/keys/index.js.map +1 -0
- package/dist/api/notifications/index.browser.js +4 -4
- package/dist/api/notifications/index.browser.js.map +1 -1
- package/dist/api/notifications/index.d.ts +84 -78
- package/dist/api/notifications/index.d.ts.map +1 -1
- package/dist/api/notifications/index.js +14 -8
- package/dist/api/notifications/index.js.map +1 -1
- package/dist/api/parameters/index.d.ts +528 -535
- package/dist/api/parameters/index.d.ts.map +1 -1
- package/dist/api/parameters/index.js +30 -37
- package/dist/api/parameters/index.js.map +1 -1
- package/dist/api/users/index.d.ts +1221 -910
- package/dist/api/users/index.d.ts.map +1 -1
- package/dist/api/users/index.js +2556 -248
- package/dist/api/users/index.js.map +1 -1
- package/dist/api/verifications/index.d.ts +142 -136
- package/dist/api/verifications/index.d.ts.map +1 -1
- package/dist/api/verifications/index.js +12 -4
- package/dist/api/verifications/index.js.map +1 -1
- package/dist/batch/index.d.ts +142 -162
- package/dist/batch/index.d.ts.map +1 -1
- package/dist/batch/index.js +31 -44
- package/dist/batch/index.js.map +1 -1
- package/dist/bucket/index.d.ts +595 -171
- package/dist/bucket/index.d.ts.map +1 -1
- package/dist/bucket/index.js +1856 -12
- package/dist/bucket/index.js.map +1 -1
- package/dist/cache/core/index.d.ts +225 -53
- package/dist/cache/core/index.d.ts.map +1 -1
- package/dist/cache/core/index.js +213 -7
- package/dist/cache/core/index.js.map +1 -1
- package/dist/cache/redis/index.d.ts +1 -0
- package/dist/cache/redis/index.d.ts.map +1 -1
- package/dist/cache/redis/index.js +6 -2
- package/dist/cache/redis/index.js.map +1 -1
- package/dist/cli/index.d.ts +834 -226
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +2872 -417
- package/dist/cli/index.js.map +1 -1
- package/dist/command/index.d.ts +458 -310
- package/dist/command/index.d.ts.map +1 -1
- package/dist/command/index.js +2011 -76
- package/dist/command/index.js.map +1 -1
- package/dist/core/index.browser.js +309 -97
- package/dist/core/index.browser.js.map +1 -1
- package/dist/core/index.d.ts +796 -701
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +329 -97
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.native.js +309 -97
- package/dist/core/index.native.js.map +1 -1
- package/dist/datetime/index.d.ts +59 -44
- package/dist/datetime/index.d.ts.map +1 -1
- package/dist/datetime/index.js +15 -0
- package/dist/datetime/index.js.map +1 -1
- package/dist/email/index.d.ts +314 -19
- package/dist/email/index.d.ts.map +1 -1
- package/dist/email/index.js +1852 -7
- package/dist/email/index.js.map +1 -1
- package/dist/fake/index.d.ts +5500 -5418
- package/dist/fake/index.d.ts.map +1 -1
- package/dist/fake/index.js +113 -42
- package/dist/fake/index.js.map +1 -1
- package/dist/lock/core/index.d.ts +219 -212
- package/dist/lock/core/index.d.ts.map +1 -1
- package/dist/lock/core/index.js +11 -4
- package/dist/lock/core/index.js.map +1 -1
- package/dist/lock/redis/index.d.ts.map +1 -1
- package/dist/logger/index.d.ts +41 -90
- package/dist/logger/index.d.ts.map +1 -1
- package/dist/logger/index.js +15 -68
- package/dist/logger/index.js.map +1 -1
- package/dist/mcp/index.d.ts +228 -230
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +32 -31
- package/dist/mcp/index.js.map +1 -1
- package/dist/orm/index.browser.js +12 -12
- package/dist/orm/index.browser.js.map +1 -1
- package/dist/orm/index.bun.js +90 -80
- package/dist/orm/index.bun.js.map +1 -1
- package/dist/orm/index.d.ts +1434 -1459
- package/dist/orm/index.d.ts.map +1 -1
- package/dist/orm/index.js +112 -130
- package/dist/orm/index.js.map +1 -1
- package/dist/queue/core/index.d.ts +262 -254
- package/dist/queue/core/index.d.ts.map +1 -1
- package/dist/queue/core/index.js +14 -6
- package/dist/queue/core/index.js.map +1 -1
- package/dist/queue/redis/index.d.ts.map +1 -1
- package/dist/react/auth/index.browser.js +108 -0
- package/dist/react/auth/index.browser.js.map +1 -0
- package/dist/react/auth/index.d.ts +100 -0
- package/dist/react/auth/index.d.ts.map +1 -0
- package/dist/react/auth/index.js +145 -0
- package/dist/react/auth/index.js.map +1 -0
- package/dist/react/core/index.d.ts +469 -0
- package/dist/react/core/index.d.ts.map +1 -0
- package/dist/react/core/index.js +464 -0
- package/dist/react/core/index.js.map +1 -0
- package/dist/react/form/index.d.ts +232 -0
- package/dist/react/form/index.d.ts.map +1 -0
- package/dist/react/form/index.js +432 -0
- package/dist/react/form/index.js.map +1 -0
- package/dist/react/head/index.browser.js +423 -0
- package/dist/react/head/index.browser.js.map +1 -0
- package/dist/react/head/index.d.ts +288 -0
- package/dist/react/head/index.d.ts.map +1 -0
- package/dist/react/head/index.js +465 -0
- package/dist/react/head/index.js.map +1 -0
- package/dist/react/i18n/index.d.ts +175 -0
- package/dist/react/i18n/index.d.ts.map +1 -0
- package/dist/react/i18n/index.js +224 -0
- package/dist/react/i18n/index.js.map +1 -0
- package/dist/react/router/index.browser.js +1980 -0
- package/dist/react/router/index.browser.js.map +1 -0
- package/dist/react/router/index.d.ts +2068 -0
- package/dist/react/router/index.d.ts.map +1 -0
- package/dist/react/router/index.js +4932 -0
- package/dist/react/router/index.js.map +1 -0
- package/dist/react/websocket/index.d.ts +117 -0
- package/dist/react/websocket/index.d.ts.map +1 -0
- package/dist/react/websocket/index.js +107 -0
- package/dist/react/websocket/index.js.map +1 -0
- package/dist/redis/index.bun.js +4 -0
- package/dist/redis/index.bun.js.map +1 -1
- package/dist/redis/index.d.ts +127 -130
- package/dist/redis/index.d.ts.map +1 -1
- package/dist/redis/index.js +16 -25
- package/dist/redis/index.js.map +1 -1
- package/dist/retry/index.d.ts +80 -71
- package/dist/retry/index.d.ts.map +1 -1
- package/dist/retry/index.js +11 -2
- package/dist/retry/index.js.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 +119 -28
- package/dist/scheduler/index.d.ts.map +1 -1
- package/dist/scheduler/index.js +404 -3
- package/dist/scheduler/index.js.map +1 -1
- package/dist/security/index.d.ts +642 -228
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/index.js +1579 -37
- package/dist/security/index.js.map +1 -1
- package/dist/server/auth/index.d.ts +1141 -111
- package/dist/server/auth/index.d.ts.map +1 -1
- package/dist/server/auth/index.js +1261 -25
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/cache/index.d.ts +63 -78
- package/dist/server/cache/index.d.ts.map +1 -1
- package/dist/server/cache/index.js +7 -22
- package/dist/server/cache/index.js.map +1 -1
- package/dist/server/compress/index.d.ts +13 -5
- package/dist/server/compress/index.d.ts.map +1 -1
- package/dist/server/compress/index.js +10 -2
- package/dist/server/compress/index.js.map +1 -1
- package/dist/server/cookies/index.d.ts +46 -22
- package/dist/server/cookies/index.d.ts.map +1 -1
- package/dist/server/cookies/index.js +7 -5
- package/dist/server/cookies/index.js.map +1 -1
- package/dist/server/core/index.d.ts +307 -196
- package/dist/server/core/index.d.ts.map +1 -1
- package/dist/server/core/index.js +271 -38
- package/dist/server/core/index.js.map +1 -1
- package/dist/server/cors/index.d.ts +24 -34
- package/dist/server/cors/index.d.ts.map +1 -1
- package/dist/server/cors/index.js +7 -21
- package/dist/server/cors/index.js.map +1 -1
- package/dist/server/health/index.d.ts +25 -19
- package/dist/server/health/index.d.ts.map +1 -1
- package/dist/server/health/index.js +8 -2
- package/dist/server/health/index.js.map +1 -1
- package/dist/server/helmet/index.d.ts +13 -5
- package/dist/server/helmet/index.d.ts.map +1 -1
- package/dist/server/helmet/index.js +11 -3
- package/dist/server/helmet/index.js.map +1 -1
- package/dist/server/links/index.browser.js +9 -1
- package/dist/server/links/index.browser.js.map +1 -1
- package/dist/server/links/index.d.ts +133 -128
- package/dist/server/links/index.d.ts.map +1 -1
- package/dist/server/links/index.js +24 -11
- package/dist/server/links/index.js.map +1 -1
- package/dist/server/metrics/index.d.ts +524 -4
- package/dist/server/metrics/index.d.ts.map +1 -1
- package/dist/server/metrics/index.js +4472 -7
- package/dist/server/metrics/index.js.map +1 -1
- package/dist/server/multipart/index.d.ts +15 -9
- package/dist/server/multipart/index.d.ts.map +1 -1
- package/dist/server/multipart/index.js +9 -3
- package/dist/server/multipart/index.js.map +1 -1
- package/dist/server/proxy/index.d.ts +110 -104
- package/dist/server/proxy/index.d.ts.map +1 -1
- package/dist/server/proxy/index.js +8 -2
- package/dist/server/proxy/index.js.map +1 -1
- package/dist/server/rate-limit/index.d.ts +46 -51
- package/dist/server/rate-limit/index.d.ts.map +1 -1
- package/dist/server/rate-limit/index.js +18 -55
- package/dist/server/rate-limit/index.js.map +1 -1
- package/dist/server/static/index.d.ts +181 -48
- package/dist/server/static/index.d.ts.map +1 -1
- package/dist/server/static/index.js +1848 -5
- package/dist/server/static/index.js.map +1 -1
- package/dist/server/swagger/index.d.ts +348 -53
- package/dist/server/swagger/index.d.ts.map +1 -1
- package/dist/server/swagger/index.js +1849 -6
- package/dist/server/swagger/index.js.map +1 -1
- package/dist/sms/index.d.ts +312 -18
- package/dist/sms/index.d.ts.map +1 -1
- package/dist/sms/index.js +1854 -10
- package/dist/sms/index.js.map +1 -1
- package/dist/system/index.browser.js +496 -0
- package/dist/system/index.browser.js.map +1 -0
- package/dist/system/index.d.ts +1158 -0
- package/dist/system/index.d.ts.map +1 -0
- package/dist/{file → system}/index.js +412 -20
- package/dist/system/index.js.map +1 -0
- package/dist/thread/index.d.ts +82 -73
- package/dist/thread/index.d.ts.map +1 -1
- package/dist/thread/index.js +13 -4
- package/dist/thread/index.js.map +1 -1
- package/dist/topic/core/index.d.ts +330 -323
- package/dist/topic/core/index.d.ts.map +1 -1
- package/dist/topic/core/index.js +12 -5
- package/dist/topic/core/index.js.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 +163 -5825
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +130 -477
- package/dist/vite/index.js.map +1 -1
- package/dist/websocket/index.browser.js +3 -3
- package/dist/websocket/index.browser.js.map +1 -1
- package/dist/websocket/index.d.ts +287 -283
- package/dist/websocket/index.d.ts.map +1 -1
- package/dist/websocket/index.js +15 -11
- package/dist/websocket/index.js.map +1 -1
- package/package.json +86 -17
- package/src/api/audits/index.ts +10 -33
- package/src/api/files/__tests__/$bucket.spec.ts +1 -1
- package/src/api/files/controllers/AdminFileStatsController.spec.ts +1 -1
- package/src/api/files/controllers/FileController.spec.ts +1 -1
- package/src/api/files/index.ts +10 -3
- package/src/api/files/jobs/FileJobs.spec.ts +1 -1
- package/src/api/files/services/FileService.spec.ts +1 -1
- package/src/api/jobs/index.ts +10 -3
- package/src/api/keys/controllers/AdminApiKeyController.ts +75 -0
- package/src/api/keys/controllers/ApiKeyController.ts +103 -0
- package/src/api/keys/entities/apiKeyEntity.ts +41 -0
- package/src/api/keys/index.ts +49 -0
- package/src/api/keys/schemas/adminApiKeyQuerySchema.ts +7 -0
- package/src/api/keys/schemas/adminApiKeyResourceSchema.ts +17 -0
- package/src/api/keys/schemas/createApiKeyBodySchema.ts +7 -0
- package/src/api/keys/schemas/createApiKeyResponseSchema.ts +11 -0
- package/src/api/keys/schemas/listApiKeyResponseSchema.ts +15 -0
- package/src/api/keys/schemas/revokeApiKeyParamsSchema.ts +5 -0
- package/src/api/keys/schemas/revokeApiKeyResponseSchema.ts +5 -0
- package/src/api/keys/services/ApiKeyService.spec.ts +553 -0
- package/src/api/keys/services/ApiKeyService.ts +306 -0
- package/src/api/logs/TODO.md +52 -0
- package/src/api/notifications/index.ts +10 -4
- package/src/api/parameters/index.ts +9 -30
- package/src/api/parameters/primitives/$config.ts +12 -4
- package/src/api/parameters/services/ConfigStore.ts +9 -3
- package/src/api/users/__tests__/ApiKeys-integration.spec.ts +1035 -0
- package/src/api/users/__tests__/ApiKeys.spec.ts +401 -0
- package/src/api/users/index.ts +14 -3
- package/src/api/users/primitives/$realm.ts +33 -5
- package/src/api/users/providers/RealmProvider.ts +1 -12
- package/src/api/users/services/SessionService.ts +1 -11
- package/src/api/verifications/controllers/VerificationController.ts +2 -0
- package/src/api/verifications/index.ts +10 -4
- package/src/batch/index.ts +9 -36
- package/src/batch/primitives/$batch.ts +0 -8
- package/src/batch/providers/BatchProvider.ts +29 -2
- package/src/bucket/__tests__/shared.ts +1 -1
- package/src/bucket/index.ts +13 -6
- package/src/bucket/primitives/$bucket.ts +1 -1
- package/src/bucket/providers/LocalFileStorageProvider.ts +1 -1
- package/src/bucket/providers/MemoryFileStorageProvider.ts +1 -1
- package/src/cache/core/__tests__/shared.ts +30 -0
- package/src/cache/core/index.ts +11 -6
- package/src/cache/core/primitives/$cache.spec.ts +5 -0
- package/src/cache/core/providers/CacheProvider.ts +17 -0
- package/src/cache/core/providers/MemoryCacheProvider.ts +300 -1
- package/src/cache/redis/__tests__/cache-redis.spec.ts +5 -0
- package/src/cache/redis/providers/RedisCacheProvider.ts +9 -0
- package/src/cli/apps/AlephaCli.ts +3 -16
- package/src/cli/apps/AlephaPackageBuilderCli.ts +10 -2
- package/src/cli/atoms/appEntryOptions.ts +13 -0
- package/src/cli/atoms/buildOptions.ts +1 -1
- package/src/cli/atoms/changelogOptions.ts +1 -1
- package/src/cli/commands/build.ts +64 -52
- package/src/cli/commands/db.ts +17 -11
- package/src/cli/commands/deploy.ts +1 -1
- package/src/cli/commands/dev.ts +13 -49
- package/src/cli/commands/gen/env.ts +6 -3
- package/src/cli/commands/gen/openapi.ts +5 -2
- package/src/cli/commands/init.spec.ts +544 -0
- package/src/cli/commands/init.ts +101 -58
- package/src/cli/commands/lint.ts +8 -2
- package/src/cli/commands/typecheck.ts +11 -0
- package/src/cli/defineConfig.ts +9 -0
- package/src/cli/index.ts +2 -1
- package/src/cli/providers/AppEntryProvider.ts +131 -0
- package/src/cli/providers/ViteBuildProvider.ts +40 -0
- package/src/cli/providers/ViteDevServerProvider.ts +378 -0
- package/src/cli/services/AlephaCliUtils.ts +39 -93
- package/src/cli/services/PackageManagerUtils.ts +140 -17
- package/src/cli/services/ProjectScaffolder.ts +169 -101
- package/src/cli/services/ViteUtils.ts +82 -0
- package/src/cli/{assets/claudeMd.ts → templates/agentMd.ts} +41 -28
- package/src/cli/{assets → templates}/apiHelloControllerTs.ts +2 -1
- package/src/cli/{assets → templates}/biomeJson.ts +2 -1
- package/src/cli/{assets → templates}/dummySpecTs.ts +2 -1
- package/src/cli/{assets → templates}/editorconfig.ts +2 -1
- package/src/cli/templates/gitignore.ts +39 -0
- package/src/cli/{assets → templates}/mainBrowserTs.ts +2 -1
- package/src/cli/templates/mainCss.ts +33 -0
- package/src/cli/templates/mainServerTs.ts +33 -0
- package/src/cli/{assets → templates}/tsconfigJson.ts +2 -1
- package/src/cli/templates/webAppRouterTs.ts +50 -0
- package/src/cli/templates/webHelloComponentTsx.ts +20 -0
- package/src/command/helpers/Runner.spec.ts +4 -0
- package/src/command/helpers/Runner.ts +3 -21
- package/src/command/index.ts +12 -4
- package/src/command/providers/CliProvider.spec.ts +1067 -0
- package/src/command/providers/CliProvider.ts +203 -40
- package/src/core/Alepha.ts +3 -9
- package/src/core/__tests__/Alepha-start.spec.ts +4 -4
- package/src/core/helpers/jsonSchemaToTypeBox.spec.ts +771 -0
- package/src/core/helpers/jsonSchemaToTypeBox.ts +62 -10
- package/src/core/index.shared.ts +1 -0
- package/src/core/index.ts +20 -0
- package/src/core/primitives/$module.ts +12 -0
- package/src/core/providers/EventManager.spec.ts +0 -71
- package/src/core/providers/EventManager.ts +3 -15
- package/src/core/providers/Json.ts +2 -14
- package/src/core/providers/KeylessJsonSchemaCodec.spec.ts +257 -0
- package/src/core/providers/KeylessJsonSchemaCodec.ts +396 -14
- package/src/core/providers/SchemaValidator.spec.ts +236 -0
- package/src/datetime/index.ts +15 -0
- package/src/email/index.ts +10 -5
- package/src/email/providers/LocalEmailProvider.spec.ts +1 -1
- package/src/email/providers/LocalEmailProvider.ts +1 -1
- package/src/fake/__tests__/keyName.example.ts +1 -1
- package/src/fake/__tests__/keyName.spec.ts +5 -5
- package/src/fake/index.ts +9 -6
- package/src/fake/providers/FakeProvider.spec.ts +258 -40
- package/src/fake/providers/FakeProvider.ts +133 -19
- package/src/lock/core/index.ts +11 -4
- package/src/logger/index.ts +17 -66
- package/src/logger/providers/PrettyFormatterProvider.ts +0 -9
- package/src/mcp/errors/McpError.ts +30 -0
- package/src/mcp/index.ts +13 -27
- package/src/mcp/transports/SseMcpTransport.ts +6 -7
- package/src/orm/__tests__/PostgresProvider.spec.ts +2 -2
- package/src/orm/index.browser.ts +2 -2
- package/src/orm/index.bun.ts +4 -2
- package/src/orm/index.ts +21 -47
- package/src/orm/providers/DrizzleKitProvider.ts +3 -5
- package/src/orm/providers/drivers/BunSqliteProvider.ts +1 -0
- package/src/orm/services/Repository.ts +18 -3
- package/src/queue/core/index.ts +14 -6
- package/src/react/auth/__tests__/$auth.spec.ts +202 -0
- package/src/react/auth/hooks/useAuth.ts +32 -0
- package/src/react/auth/index.browser.ts +13 -0
- package/src/react/auth/index.shared.ts +2 -0
- package/src/react/auth/index.ts +48 -0
- package/src/react/auth/providers/ReactAuthProvider.ts +16 -0
- package/src/react/auth/services/ReactAuth.ts +135 -0
- package/src/react/core/__tests__/Router.spec.tsx +169 -0
- package/src/react/core/components/ClientOnly.tsx +49 -0
- package/src/react/core/components/ErrorBoundary.tsx +73 -0
- package/src/react/core/contexts/AlephaContext.ts +7 -0
- package/src/react/core/contexts/AlephaProvider.tsx +42 -0
- package/src/react/core/hooks/useAction.browser.spec.tsx +569 -0
- package/src/react/core/hooks/useAction.ts +480 -0
- package/src/react/core/hooks/useAlepha.ts +26 -0
- package/src/react/core/hooks/useClient.ts +17 -0
- package/src/react/core/hooks/useEvents.ts +51 -0
- package/src/react/core/hooks/useInject.ts +12 -0
- package/src/react/core/hooks/useStore.ts +52 -0
- package/src/react/core/index.ts +90 -0
- package/src/react/form/components/FormState.tsx +17 -0
- package/src/react/form/errors/FormValidationError.ts +18 -0
- package/src/react/form/hooks/useForm.browser.spec.tsx +366 -0
- package/src/react/form/hooks/useForm.ts +47 -0
- package/src/react/form/hooks/useFormState.ts +130 -0
- package/src/react/form/index.ts +44 -0
- package/src/react/form/services/FormModel.ts +614 -0
- package/src/react/head/helpers/SeoExpander.spec.ts +203 -0
- package/src/react/head/helpers/SeoExpander.ts +142 -0
- package/src/react/head/hooks/useHead.spec.tsx +288 -0
- package/src/react/head/hooks/useHead.ts +62 -0
- package/src/react/head/index.browser.ts +26 -0
- package/src/react/head/index.ts +44 -0
- package/src/react/head/interfaces/Head.ts +105 -0
- package/src/react/head/primitives/$head.ts +25 -0
- package/src/react/head/providers/BrowserHeadProvider.browser.spec.ts +196 -0
- package/src/react/head/providers/BrowserHeadProvider.ts +212 -0
- package/src/react/head/providers/HeadProvider.ts +168 -0
- package/src/react/head/providers/ServerHeadProvider.ts +31 -0
- package/src/react/i18n/__tests__/integration.spec.tsx +239 -0
- package/src/react/i18n/components/Localize.spec.tsx +357 -0
- package/src/react/i18n/components/Localize.tsx +35 -0
- package/src/react/i18n/hooks/useI18n.browser.spec.tsx +438 -0
- package/src/react/i18n/hooks/useI18n.ts +18 -0
- package/src/react/i18n/index.ts +41 -0
- package/src/react/i18n/primitives/$dictionary.ts +69 -0
- package/src/react/i18n/providers/I18nProvider.spec.ts +389 -0
- package/src/react/i18n/providers/I18nProvider.ts +278 -0
- package/src/react/router/__tests__/page-head-browser.browser.spec.ts +95 -0
- package/src/react/router/__tests__/page-head.spec.ts +48 -0
- package/src/react/router/__tests__/seo-head.spec.ts +125 -0
- package/src/react/router/atoms/ssrManifestAtom.ts +58 -0
- package/src/react/router/components/ErrorViewer.tsx +872 -0
- package/src/react/router/components/Link.tsx +23 -0
- package/src/react/router/components/NestedView.tsx +223 -0
- package/src/react/router/components/NotFound.tsx +30 -0
- package/src/react/router/constants/PAGE_PRELOAD_KEY.ts +6 -0
- package/src/react/router/contexts/RouterLayerContext.ts +12 -0
- package/src/react/router/errors/Redirection.ts +28 -0
- package/src/react/router/hooks/useActive.ts +52 -0
- package/src/react/router/hooks/useQueryParams.ts +63 -0
- package/src/react/router/hooks/useRouter.ts +20 -0
- package/src/react/router/hooks/useRouterState.ts +11 -0
- package/src/react/router/index.browser.ts +45 -0
- package/src/react/router/index.shared.ts +19 -0
- package/src/react/router/index.ts +142 -0
- package/src/react/router/primitives/$page.browser.spec.tsx +851 -0
- package/src/react/router/primitives/$page.spec.tsx +708 -0
- package/src/react/router/primitives/$page.ts +497 -0
- package/src/react/router/providers/ReactBrowserProvider.ts +309 -0
- package/src/react/router/providers/ReactBrowserRendererProvider.ts +25 -0
- package/src/react/router/providers/ReactBrowserRouterProvider.ts +168 -0
- package/src/react/router/providers/ReactPageProvider.ts +726 -0
- package/src/react/router/providers/ReactServerProvider.spec.tsx +316 -0
- package/src/react/router/providers/ReactServerProvider.ts +558 -0
- package/src/react/router/providers/ReactServerTemplateProvider.ts +979 -0
- package/src/react/router/providers/SSRManifestProvider.ts +334 -0
- package/src/react/router/services/ReactPageServerService.ts +48 -0
- package/src/react/router/services/ReactPageService.ts +27 -0
- package/src/react/router/services/ReactRouter.ts +262 -0
- package/src/react/websocket/hooks/useRoom.tsx +242 -0
- package/src/react/websocket/index.ts +7 -0
- package/src/redis/__tests__/redis.spec.ts +13 -0
- package/src/redis/index.ts +9 -25
- package/src/redis/providers/BunRedisProvider.ts +9 -0
- package/src/redis/providers/NodeRedisProvider.ts +8 -0
- package/src/redis/providers/RedisProvider.ts +16 -0
- package/src/retry/index.ts +11 -2
- package/src/router/index.ts +15 -0
- package/src/scheduler/index.ts +11 -2
- package/src/security/__tests__/BasicAuth.spec.ts +2 -0
- package/src/security/__tests__/ServerSecurityProvider.spec.ts +13 -5
- package/src/security/index.ts +15 -10
- package/src/security/interfaces/IssuerResolver.ts +27 -0
- package/src/security/primitives/$issuer.ts +55 -0
- package/src/security/providers/SecurityProvider.ts +179 -0
- package/src/security/providers/ServerBasicAuthProvider.ts +6 -2
- package/src/security/providers/ServerSecurityProvider.ts +36 -22
- package/src/server/auth/index.ts +12 -7
- package/src/server/cache/index.ts +7 -22
- package/src/server/compress/index.ts +10 -2
- package/src/server/cookies/index.ts +7 -5
- package/src/server/cookies/primitives/$cookie.ts +33 -11
- package/src/server/core/index.ts +17 -7
- package/src/server/core/interfaces/ServerRequest.ts +83 -1
- package/src/server/core/primitives/$action.spec.ts +1 -1
- package/src/server/core/primitives/$action.ts +8 -3
- package/src/server/core/providers/BunHttpServerProvider.ts +1 -1
- package/src/server/core/providers/NodeHttpServerProvider.spec.ts +125 -0
- package/src/server/core/providers/NodeHttpServerProvider.ts +77 -22
- package/src/server/core/providers/ServerLoggerProvider.ts +2 -2
- package/src/server/core/providers/ServerProvider.ts +9 -12
- package/src/server/core/services/ServerRequestParser.spec.ts +520 -0
- package/src/server/core/services/ServerRequestParser.ts +306 -13
- package/src/server/cors/index.ts +7 -21
- package/src/server/cors/primitives/$cors.ts +6 -2
- package/src/server/health/index.ts +8 -2
- package/src/server/helmet/index.ts +11 -3
- package/src/server/links/atoms/apiLinksAtom.ts +7 -0
- package/src/server/links/index.browser.ts +2 -0
- package/src/server/links/index.ts +13 -6
- package/src/server/metrics/index.ts +10 -3
- package/src/server/multipart/index.ts +9 -3
- package/src/server/proxy/index.ts +8 -2
- package/src/server/rate-limit/index.ts +21 -25
- package/src/server/rate-limit/primitives/$rateLimit.ts +6 -2
- package/src/server/rate-limit/providers/ServerRateLimitProvider.spec.ts +38 -14
- package/src/server/rate-limit/providers/ServerRateLimitProvider.ts +22 -56
- package/src/server/static/index.ts +8 -2
- package/src/server/static/providers/ServerStaticProvider.ts +1 -1
- package/src/server/swagger/index.ts +9 -4
- package/src/server/swagger/providers/ServerSwaggerProvider.ts +1 -1
- package/src/sms/index.ts +9 -5
- package/src/sms/providers/LocalSmsProvider.spec.ts +1 -1
- package/src/sms/providers/LocalSmsProvider.ts +1 -1
- package/src/system/index.browser.ts +11 -0
- package/src/system/index.ts +62 -0
- package/src/{file → system}/providers/FileSystemProvider.ts +16 -0
- package/src/{file → system}/providers/MemoryFileSystemProvider.ts +116 -3
- package/src/system/providers/MemoryShellProvider.ts +164 -0
- package/src/{file → system}/providers/NodeFileSystemProvider.spec.ts +2 -2
- package/src/{file → system}/providers/NodeFileSystemProvider.ts +36 -0
- package/src/system/providers/NodeShellProvider.ts +184 -0
- package/src/system/providers/ShellProvider.ts +74 -0
- package/src/{file → system}/services/FileDetector.spec.ts +2 -2
- package/src/thread/index.ts +11 -2
- package/src/topic/core/index.ts +12 -5
- package/src/vite/index.ts +3 -2
- package/src/vite/tasks/buildClient.ts +2 -8
- package/src/vite/tasks/buildServer.ts +84 -21
- package/src/vite/tasks/copyAssets.ts +5 -4
- package/src/vite/tasks/generateSitemap.ts +64 -23
- package/src/vite/tasks/index.ts +0 -2
- package/src/vite/tasks/prerenderPages.ts +49 -24
- package/src/websocket/index.ts +12 -8
- package/dist/file/index.d.ts +0 -839
- package/dist/file/index.d.ts.map +0 -1
- package/dist/file/index.js.map +0 -1
- package/src/cli/assets/indexHtml.ts +0 -15
- package/src/cli/assets/mainServerTs.ts +0 -24
- package/src/cli/assets/webAppRouterTs.ts +0 -15
- package/src/cli/assets/webHelloComponentTsx.ts +0 -16
- package/src/cli/commands/format.ts +0 -23
- package/src/file/index.ts +0 -43
- package/src/vite/helpers/boot.ts +0 -117
- package/src/vite/plugins/viteAlephaDev.ts +0 -177
- package/src/vite/tasks/devServer.ts +0 -71
- package/src/vite/tasks/runAlepha.ts +0 -270
- /package/dist/orm/{chunk-DtkW-qnP.js → chunk-DH6iiROE.js} +0 -0
- /package/src/cli/{assets → templates}/apiIndexTs.ts +0 -0
- /package/src/cli/{assets → templates}/webIndexTs.ts +0 -0
- /package/src/{file → system}/errors/FileError.ts +0 -0
- /package/src/{file → system}/services/FileDetector.ts +0 -0
package/dist/security/index.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import * as alepha3 from "alepha";
|
|
2
2
|
import { Alepha, KIND, Primitive, Static } from "alepha";
|
|
3
3
|
import { FetchOptions, ServerRequest, ServerRouterProvider, UnauthorizedError } from "alepha/server";
|
|
4
|
-
import * as
|
|
4
|
+
import * as alepha_logger0 from "alepha/logger";
|
|
5
5
|
import { DateTimeProvider, Duration, DurationLike } from "alepha/datetime";
|
|
6
|
-
import { CryptoKey, FlattenedJWSInput, JSONWebKeySet, JWSHeaderParameters, JWTHeaderParameters, JWTPayload, JWTVerifyResult, KeyObject } from "jose";
|
|
7
|
-
import { JWTVerifyOptions } from "jose/jwt/verify";
|
|
8
6
|
|
|
9
7
|
//#region ../../src/security/schemas/userAccountInfoSchema.d.ts
|
|
10
8
|
declare const userAccountInfoSchema: alepha3.TObject<{
|
|
@@ -26,17 +24,17 @@ type UserAccount = Static<typeof userAccountInfoSchema>;
|
|
|
26
24
|
*/
|
|
27
25
|
interface UserAccountToken extends UserAccount {
|
|
28
26
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
* Access token for the user.
|
|
28
|
+
*/
|
|
31
29
|
token?: string;
|
|
32
30
|
/**
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
* Realm name of the user.
|
|
32
|
+
*/
|
|
35
33
|
realm?: string;
|
|
36
34
|
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
* Is user dedicated to his own resources for this scope ?
|
|
36
|
+
* Mostly, Admin is false and Customer is true.
|
|
37
|
+
*/
|
|
40
38
|
ownership?: string | boolean;
|
|
41
39
|
}
|
|
42
40
|
//#endregion
|
|
@@ -63,56 +61,84 @@ declare class SecurityError extends Error {
|
|
|
63
61
|
readonly status = 403;
|
|
64
62
|
}
|
|
65
63
|
//#endregion
|
|
64
|
+
//#region ../../src/security/interfaces/IssuerResolver.d.ts
|
|
65
|
+
/**
|
|
66
|
+
* User info that a resolver returns.
|
|
67
|
+
* This is the input to `SecurityProvider.createUser()`.
|
|
68
|
+
*/
|
|
69
|
+
type UserInfo = Omit<UserAccount, "sessionId"> & {
|
|
70
|
+
sessionId?: string;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Resolver definition for authenticating users from requests.
|
|
74
|
+
*/
|
|
75
|
+
interface IssuerResolver {
|
|
76
|
+
/**
|
|
77
|
+
* Priority (lower = first). Default: 100
|
|
78
|
+
*/
|
|
79
|
+
priority?: number;
|
|
80
|
+
/**
|
|
81
|
+
* Resolve user from HTTP request.
|
|
82
|
+
* Return UserInfo if authenticated, null to try next resolver.
|
|
83
|
+
* Throw UnauthorizedError to stop chain.
|
|
84
|
+
*/
|
|
85
|
+
onRequest: (req: ServerRequest) => Promise<UserInfo | null>;
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
66
88
|
//#region ../../src/security/providers/ServerBasicAuthProvider.d.ts
|
|
67
89
|
interface BasicAuthOptions {
|
|
68
90
|
username: string;
|
|
69
91
|
password: string;
|
|
70
92
|
}
|
|
71
93
|
interface BasicAuthPrimitiveConfig extends BasicAuthOptions {
|
|
72
|
-
/**
|
|
94
|
+
/**
|
|
95
|
+
* Name identifier for this basic auth (default: property key).
|
|
96
|
+
*/
|
|
73
97
|
name?: string;
|
|
74
|
-
/**
|
|
98
|
+
/**
|
|
99
|
+
* Path patterns to match (supports wildcards like /devtools/*).
|
|
100
|
+
*/
|
|
75
101
|
paths?: string[];
|
|
76
102
|
}
|
|
77
103
|
declare class ServerBasicAuthProvider {
|
|
78
104
|
protected readonly alepha: Alepha;
|
|
79
|
-
protected readonly log:
|
|
105
|
+
protected readonly log: alepha_logger0.Logger;
|
|
80
106
|
protected readonly routerProvider: ServerRouterProvider;
|
|
81
107
|
protected readonly realm = "Secure Area";
|
|
82
108
|
/**
|
|
83
|
-
|
|
84
|
-
|
|
109
|
+
* Registered basic auth primitives with their configurations
|
|
110
|
+
*/
|
|
85
111
|
readonly registeredAuths: BasicAuthPrimitiveConfig[];
|
|
86
112
|
/**
|
|
87
|
-
|
|
88
|
-
|
|
113
|
+
* Register a basic auth configuration (called by primitives)
|
|
114
|
+
*/
|
|
89
115
|
registerAuth(config: BasicAuthPrimitiveConfig): void;
|
|
90
116
|
readonly onStart: alepha3.HookPrimitive<"start">;
|
|
91
117
|
/**
|
|
92
|
-
|
|
93
|
-
|
|
118
|
+
* Hook into server:onRequest to check basic auth
|
|
119
|
+
*/
|
|
94
120
|
readonly onRequest: alepha3.HookPrimitive<"server:onRequest">;
|
|
95
121
|
/**
|
|
96
|
-
|
|
97
|
-
|
|
122
|
+
* Hook into action:onRequest to check basic auth for actions
|
|
123
|
+
*/
|
|
98
124
|
readonly onActionRequest: alepha3.HookPrimitive<"action:onRequest">;
|
|
99
125
|
/**
|
|
100
|
-
|
|
101
|
-
|
|
126
|
+
* Check basic authentication
|
|
127
|
+
*/
|
|
102
128
|
checkAuth(request: ServerRequest, options: BasicAuthOptions): void;
|
|
103
129
|
/**
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
130
|
+
* Performs a timing-safe comparison of credentials to prevent timing attacks.
|
|
131
|
+
* Always compares both username and password to avoid leaking which one is wrong.
|
|
132
|
+
*/
|
|
107
133
|
protected timingSafeCredentialCheck(inputUsername: string, inputPassword: string, expectedUsername: string, expectedPassword: string): boolean;
|
|
108
134
|
/**
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
135
|
+
* Compares two buffers in constant time, handling different lengths safely.
|
|
136
|
+
* Returns 1 if equal, 0 if not equal.
|
|
137
|
+
*/
|
|
112
138
|
protected safeCompare(input: Buffer, expected: Buffer): number;
|
|
113
139
|
/**
|
|
114
|
-
|
|
115
|
-
|
|
140
|
+
* Send WWW-Authenticate header
|
|
141
|
+
*/
|
|
116
142
|
protected sendAuthRequired(request: ServerRequest): void;
|
|
117
143
|
}
|
|
118
144
|
declare const isBasicAuth: (value: unknown) => value is {
|
|
@@ -138,51 +164,376 @@ declare class BasicAuthPrimitive extends Primitive<BasicAuthPrimitiveConfig> imp
|
|
|
138
164
|
get name(): string;
|
|
139
165
|
protected onInit(): void;
|
|
140
166
|
/**
|
|
141
|
-
|
|
142
|
-
|
|
167
|
+
* Checks basic auth for the given request using this primitive's configuration.
|
|
168
|
+
*/
|
|
143
169
|
check(request: ServerRequest, options?: BasicAuthOptions): void;
|
|
144
170
|
}
|
|
145
171
|
//#endregion
|
|
172
|
+
//#region ../../../../node_modules/jose/dist/types/types.d.ts
|
|
173
|
+
/** Generic JSON Web Key Parameters. */
|
|
174
|
+
interface JWKParameters {
|
|
175
|
+
/** JWK "kty" (Key Type) Parameter */
|
|
176
|
+
kty?: string;
|
|
177
|
+
/**
|
|
178
|
+
* JWK "alg" (Algorithm) Parameter
|
|
179
|
+
*
|
|
180
|
+
* @see {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}
|
|
181
|
+
*/
|
|
182
|
+
alg?: string;
|
|
183
|
+
/** JWK "key_ops" (Key Operations) Parameter */
|
|
184
|
+
key_ops?: string[];
|
|
185
|
+
/** JWK "ext" (Extractable) Parameter */
|
|
186
|
+
ext?: boolean;
|
|
187
|
+
/** JWK "use" (Public Key Use) Parameter */
|
|
188
|
+
use?: string;
|
|
189
|
+
/** JWK "x5c" (X.509 Certificate Chain) Parameter */
|
|
190
|
+
x5c?: string[];
|
|
191
|
+
/** JWK "x5t" (X.509 Certificate SHA-1 Thumbprint) Parameter */
|
|
192
|
+
x5t?: string;
|
|
193
|
+
/** JWK "x5t#S256" (X.509 Certificate SHA-256 Thumbprint) Parameter */
|
|
194
|
+
'x5t#S256'?: string;
|
|
195
|
+
/** JWK "x5u" (X.509 URL) Parameter */
|
|
196
|
+
x5u?: string;
|
|
197
|
+
/** JWK "kid" (Key ID) Parameter */
|
|
198
|
+
kid?: string;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* JSON Web Key ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK}). "RSA", "EC", "OKP", "AKP", and
|
|
202
|
+
* "oct" key types are supported.
|
|
203
|
+
*
|
|
204
|
+
* @see {@link JWK_AKP_Public}
|
|
205
|
+
* @see {@link JWK_AKP_Private}
|
|
206
|
+
* @see {@link JWK_OKP_Public}
|
|
207
|
+
* @see {@link JWK_OKP_Private}
|
|
208
|
+
* @see {@link JWK_EC_Public}
|
|
209
|
+
* @see {@link JWK_EC_Private}
|
|
210
|
+
* @see {@link JWK_RSA_Public}
|
|
211
|
+
* @see {@link JWK_RSA_Private}
|
|
212
|
+
* @see {@link JWK_oct}
|
|
213
|
+
*/
|
|
214
|
+
interface JWK extends JWKParameters {
|
|
215
|
+
/**
|
|
216
|
+
* - EC JWK "crv" (Curve) Parameter
|
|
217
|
+
* - OKP JWK "crv" (The Subtype of Key Pair) Parameter
|
|
218
|
+
*/
|
|
219
|
+
crv?: string;
|
|
220
|
+
/**
|
|
221
|
+
* - Private RSA JWK "d" (Private Exponent) Parameter
|
|
222
|
+
* - Private EC JWK "d" (ECC Private Key) Parameter
|
|
223
|
+
* - Private OKP JWK "d" (The Private Key) Parameter
|
|
224
|
+
*/
|
|
225
|
+
d?: string;
|
|
226
|
+
/** Private RSA JWK "dp" (First Factor CRT Exponent) Parameter */
|
|
227
|
+
dp?: string;
|
|
228
|
+
/** Private RSA JWK "dq" (Second Factor CRT Exponent) Parameter */
|
|
229
|
+
dq?: string;
|
|
230
|
+
/** RSA JWK "e" (Exponent) Parameter */
|
|
231
|
+
e?: string;
|
|
232
|
+
/** Oct JWK "k" (Key Value) Parameter */
|
|
233
|
+
k?: string;
|
|
234
|
+
/** RSA JWK "n" (Modulus) Parameter */
|
|
235
|
+
n?: string;
|
|
236
|
+
/** Private RSA JWK "p" (First Prime Factor) Parameter */
|
|
237
|
+
p?: string;
|
|
238
|
+
/** Private RSA JWK "q" (Second Prime Factor) Parameter */
|
|
239
|
+
q?: string;
|
|
240
|
+
/** Private RSA JWK "qi" (First CRT Coefficient) Parameter */
|
|
241
|
+
qi?: string;
|
|
242
|
+
/**
|
|
243
|
+
* - EC JWK "x" (X Coordinate) Parameter
|
|
244
|
+
* - OKP JWK "x" (The public key) Parameter
|
|
245
|
+
*/
|
|
246
|
+
x?: string;
|
|
247
|
+
/** EC JWK "y" (Y Coordinate) Parameter */
|
|
248
|
+
y?: string;
|
|
249
|
+
/** AKP JWK "pub" (Public Key) Parameter */
|
|
250
|
+
pub?: string;
|
|
251
|
+
/** AKP JWK "priv" (Private key) Parameter */
|
|
252
|
+
priv?: string;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Flattened JWS definition for verify function inputs, allows payload as {@link !Uint8Array} for
|
|
256
|
+
* detached signature validation.
|
|
257
|
+
*/
|
|
258
|
+
interface FlattenedJWSInput {
|
|
259
|
+
/**
|
|
260
|
+
* The "header" member MUST be present and contain the value JWS Unprotected Header when the JWS
|
|
261
|
+
* Unprotected Header value is non- empty; otherwise, it MUST be absent. This value is represented
|
|
262
|
+
* as an unencoded JSON object, rather than as a string. These Header Parameter values are not
|
|
263
|
+
* integrity protected.
|
|
264
|
+
*/
|
|
265
|
+
header?: JWSHeaderParameters;
|
|
266
|
+
/**
|
|
267
|
+
* The "payload" member MUST be present and contain the value BASE64URL(JWS Payload). When RFC7797
|
|
268
|
+
* "b64": false is used the value passed may also be a {@link !Uint8Array}.
|
|
269
|
+
*/
|
|
270
|
+
payload: string | Uint8Array;
|
|
271
|
+
/**
|
|
272
|
+
* The "protected" member MUST be present and contain the value BASE64URL(UTF8(JWS Protected
|
|
273
|
+
* Header)) when the JWS Protected Header value is non-empty; otherwise, it MUST be absent. These
|
|
274
|
+
* Header Parameter values are integrity protected.
|
|
275
|
+
*/
|
|
276
|
+
protected?: string;
|
|
277
|
+
/** The "signature" member MUST be present and contain the value BASE64URL(JWS Signature). */
|
|
278
|
+
signature: string;
|
|
279
|
+
}
|
|
280
|
+
/** Header Parameters common to JWE and JWS */
|
|
281
|
+
interface JoseHeaderParameters {
|
|
282
|
+
/** "kid" (Key ID) Header Parameter */
|
|
283
|
+
kid?: string;
|
|
284
|
+
/** "x5t" (X.509 Certificate SHA-1 Thumbprint) Header Parameter */
|
|
285
|
+
x5t?: string;
|
|
286
|
+
/** "x5c" (X.509 Certificate Chain) Header Parameter */
|
|
287
|
+
x5c?: string[];
|
|
288
|
+
/** "x5u" (X.509 URL) Header Parameter */
|
|
289
|
+
x5u?: string;
|
|
290
|
+
/** "jku" (JWK Set URL) Header Parameter */
|
|
291
|
+
jku?: string;
|
|
292
|
+
/** "jwk" (JSON Web Key) Header Parameter */
|
|
293
|
+
jwk?: Pick<JWK, 'kty' | 'crv' | 'x' | 'y' | 'e' | 'n' | 'alg' | 'pub'>;
|
|
294
|
+
/** "typ" (Type) Header Parameter */
|
|
295
|
+
typ?: string;
|
|
296
|
+
/** "cty" (Content Type) Header Parameter */
|
|
297
|
+
cty?: string;
|
|
298
|
+
}
|
|
299
|
+
/** Recognized JWS Header Parameters, any other Header Members may also be present. */
|
|
300
|
+
interface JWSHeaderParameters extends JoseHeaderParameters {
|
|
301
|
+
/**
|
|
302
|
+
* JWS "alg" (Algorithm) Header Parameter
|
|
303
|
+
*
|
|
304
|
+
* @see {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}
|
|
305
|
+
*/
|
|
306
|
+
alg?: string;
|
|
307
|
+
/**
|
|
308
|
+
* This JWS Extension Header Parameter modifies the JWS Payload representation and the JWS Signing
|
|
309
|
+
* Input computation as per {@link https://www.rfc-editor.org/rfc/rfc7797 RFC7797}.
|
|
310
|
+
*/
|
|
311
|
+
b64?: boolean;
|
|
312
|
+
/** JWS "crit" (Critical) Header Parameter */
|
|
313
|
+
crit?: string[];
|
|
314
|
+
/** Any other JWS Header member. */
|
|
315
|
+
[propName: string]: unknown;
|
|
316
|
+
}
|
|
317
|
+
/** Shared Interface with a "crit" property for all sign, verify, encrypt and decrypt operations. */
|
|
318
|
+
interface CritOption {
|
|
319
|
+
/**
|
|
320
|
+
* An object with keys representing recognized "crit" (Critical) Header Parameter names. The value
|
|
321
|
+
* for those is either `true` or `false`. `true` when the Header Parameter MUST be integrity
|
|
322
|
+
* protected, `false` when it's irrelevant.
|
|
323
|
+
*
|
|
324
|
+
* This makes the "Extension Header Parameter "..." is not recognized" error go away.
|
|
325
|
+
*
|
|
326
|
+
* Use this when a given JWS/JWT/JWE profile requires the use of proprietary non-registered "crit"
|
|
327
|
+
* (Critical) Header Parameters. This will only make sure the Header Parameter is syntactically
|
|
328
|
+
* correct when provided and that it is optionally integrity protected. It will not process the
|
|
329
|
+
* Header Parameter in any way or reject the operation if it is missing. You MUST still verify the
|
|
330
|
+
* Header Parameter was present and process it according to the profile's validation steps after
|
|
331
|
+
* the operation succeeds.
|
|
332
|
+
*
|
|
333
|
+
* The JWS extension Header Parameter `b64` is always recognized and processed properly. No other
|
|
334
|
+
* registered Header Parameters that need this kind of default built-in treatment are currently
|
|
335
|
+
* available.
|
|
336
|
+
*/
|
|
337
|
+
crit?: {
|
|
338
|
+
[propName: string]: boolean;
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
/** JWT Claims Set verification options. */
|
|
342
|
+
interface JWTClaimVerificationOptions {
|
|
343
|
+
/**
|
|
344
|
+
* Expected JWT "aud" (Audience) Claim value(s).
|
|
345
|
+
*
|
|
346
|
+
* This option makes the JWT "aud" (Audience) Claim presence required.
|
|
347
|
+
*/
|
|
348
|
+
audience?: string | string[];
|
|
349
|
+
/**
|
|
350
|
+
* Clock skew tolerance
|
|
351
|
+
*
|
|
352
|
+
* - In seconds when number (e.g. 5)
|
|
353
|
+
* - Resolved into a number of seconds when a string (e.g. "5 seconds", "10 minutes", "2 hours").
|
|
354
|
+
*
|
|
355
|
+
* Used when validating the JWT "nbf" (Not Before) and "exp" (Expiration Time) claims, and when
|
|
356
|
+
* validating the "iat" (Issued At) claim if the {@link maxTokenAge `maxTokenAge` option} is set.
|
|
357
|
+
*/
|
|
358
|
+
clockTolerance?: string | number;
|
|
359
|
+
/**
|
|
360
|
+
* Expected JWT "iss" (Issuer) Claim value(s).
|
|
361
|
+
*
|
|
362
|
+
* This option makes the JWT "iss" (Issuer) Claim presence required.
|
|
363
|
+
*/
|
|
364
|
+
issuer?: string | string[];
|
|
365
|
+
/**
|
|
366
|
+
* Maximum time elapsed (in seconds) from the JWT "iat" (Issued At) Claim value.
|
|
367
|
+
*
|
|
368
|
+
* - In seconds when number (e.g. 5)
|
|
369
|
+
* - Resolved into a number of seconds when a string (e.g. "5 seconds", "10 minutes", "2 hours").
|
|
370
|
+
*
|
|
371
|
+
* This option makes the JWT "iat" (Issued At) Claim presence required.
|
|
372
|
+
*/
|
|
373
|
+
maxTokenAge?: string | number;
|
|
374
|
+
/**
|
|
375
|
+
* Expected JWT "sub" (Subject) Claim value.
|
|
376
|
+
*
|
|
377
|
+
* This option makes the JWT "sub" (Subject) Claim presence required.
|
|
378
|
+
*/
|
|
379
|
+
subject?: string;
|
|
380
|
+
/**
|
|
381
|
+
* Expected JWT "typ" (Type) Header Parameter value.
|
|
382
|
+
*
|
|
383
|
+
* This option makes the JWT "typ" (Type) Header Parameter presence required.
|
|
384
|
+
*/
|
|
385
|
+
typ?: string;
|
|
386
|
+
/** Date to use when comparing NumericDate claims, defaults to `new Date()`. */
|
|
387
|
+
currentDate?: Date;
|
|
388
|
+
/**
|
|
389
|
+
* Array of required Claim Names that must be present in the JWT Claims Set. Default is that: if
|
|
390
|
+
* the {@link issuer `issuer` option} is set, then JWT "iss" (Issuer) Claim must be present; if the
|
|
391
|
+
* {@link audience `audience` option} is set, then JWT "aud" (Audience) Claim must be present; if
|
|
392
|
+
* the {@link subject `subject` option} is set, then JWT "sub" (Subject) Claim must be present; if
|
|
393
|
+
* the {@link maxTokenAge `maxTokenAge` option} is set, then JWT "iat" (Issued At) Claim must be
|
|
394
|
+
* present.
|
|
395
|
+
*/
|
|
396
|
+
requiredClaims?: string[];
|
|
397
|
+
}
|
|
398
|
+
/** JWS Verification options. */
|
|
399
|
+
interface VerifyOptions extends CritOption {
|
|
400
|
+
/**
|
|
401
|
+
* A list of accepted JWS "alg" (Algorithm) Header Parameter values. By default all "alg"
|
|
402
|
+
* (Algorithm) values applicable for the used key/secret are allowed.
|
|
403
|
+
*
|
|
404
|
+
* > [!NOTE]\
|
|
405
|
+
* > Unsecured JWTs (`{ "alg": "none" }`) are never accepted by this API.
|
|
406
|
+
*/
|
|
407
|
+
algorithms?: string[];
|
|
408
|
+
}
|
|
409
|
+
/** Recognized JWT Claims Set members, any other members may also be present. */
|
|
410
|
+
interface JWTPayload {
|
|
411
|
+
/**
|
|
412
|
+
* JWT Issuer
|
|
413
|
+
*
|
|
414
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.1 RFC7519#section-4.1.1}
|
|
415
|
+
*/
|
|
416
|
+
iss?: string;
|
|
417
|
+
/**
|
|
418
|
+
* JWT Subject
|
|
419
|
+
*
|
|
420
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.2 RFC7519#section-4.1.2}
|
|
421
|
+
*/
|
|
422
|
+
sub?: string;
|
|
423
|
+
/**
|
|
424
|
+
* JWT Audience
|
|
425
|
+
*
|
|
426
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.3 RFC7519#section-4.1.3}
|
|
427
|
+
*/
|
|
428
|
+
aud?: string | string[];
|
|
429
|
+
/**
|
|
430
|
+
* JWT ID
|
|
431
|
+
*
|
|
432
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.7 RFC7519#section-4.1.7}
|
|
433
|
+
*/
|
|
434
|
+
jti?: string;
|
|
435
|
+
/**
|
|
436
|
+
* JWT Not Before
|
|
437
|
+
*
|
|
438
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.5 RFC7519#section-4.1.5}
|
|
439
|
+
*/
|
|
440
|
+
nbf?: number;
|
|
441
|
+
/**
|
|
442
|
+
* JWT Expiration Time
|
|
443
|
+
*
|
|
444
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.4 RFC7519#section-4.1.4}
|
|
445
|
+
*/
|
|
446
|
+
exp?: number;
|
|
447
|
+
/**
|
|
448
|
+
* JWT Issued At
|
|
449
|
+
*
|
|
450
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.6 RFC7519#section-4.1.6}
|
|
451
|
+
*/
|
|
452
|
+
iat?: number;
|
|
453
|
+
/** Any other JWT Claim Set member. */
|
|
454
|
+
[propName: string]: unknown;
|
|
455
|
+
}
|
|
456
|
+
/** Signed JSON Web Token (JWT) verification result */
|
|
457
|
+
interface JWTVerifyResult<PayloadType = JWTPayload> {
|
|
458
|
+
/** JWT Claims Set. */
|
|
459
|
+
payload: PayloadType & JWTPayload;
|
|
460
|
+
/** JWS Protected Header. */
|
|
461
|
+
protectedHeader: JWTHeaderParameters;
|
|
462
|
+
}
|
|
463
|
+
/** Recognized Compact JWS Header Parameters, any other Header Members may also be present. */
|
|
464
|
+
interface CompactJWSHeaderParameters extends JWSHeaderParameters {
|
|
465
|
+
alg: string;
|
|
466
|
+
}
|
|
467
|
+
/** Recognized Signed JWT Header Parameters, any other Header Members may also be present. */
|
|
468
|
+
interface JWTHeaderParameters extends CompactJWSHeaderParameters {
|
|
469
|
+
b64?: true;
|
|
470
|
+
}
|
|
471
|
+
/** JSON Web Key Set */
|
|
472
|
+
interface JSONWebKeySet {
|
|
473
|
+
keys: JWK[];
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* {@link !KeyObject} is a representation of a key/secret available in the Node.js runtime. You may
|
|
477
|
+
* use the Node.js runtime APIs {@link !createPublicKey}, {@link !createPrivateKey}, and
|
|
478
|
+
* {@link !createSecretKey} to obtain a {@link !KeyObject} from your existing key material.
|
|
479
|
+
*/
|
|
480
|
+
interface KeyObject {
|
|
481
|
+
type: string;
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* {@link !CryptoKey} is a representation of a key/secret available in all supported runtimes. In
|
|
485
|
+
* addition to the {@link key/import Key Import Functions} you may use the
|
|
486
|
+
* {@link !SubtleCrypto.importKey} API to obtain a {@link !CryptoKey} from your existing key
|
|
487
|
+
* material.
|
|
488
|
+
*/
|
|
489
|
+
type CryptoKey = Extract<Awaited<ReturnType<typeof crypto.subtle.generateKey>>, {
|
|
490
|
+
type: string;
|
|
491
|
+
}>;
|
|
492
|
+
//#endregion
|
|
493
|
+
//#region ../../../../node_modules/jose/dist/types/jwt/verify.d.ts
|
|
494
|
+
/** Combination of JWS Verification options and JWT Claims Set verification options. */
|
|
495
|
+
interface JWTVerifyOptions extends VerifyOptions, JWTClaimVerificationOptions {}
|
|
496
|
+
//#endregion
|
|
146
497
|
//#region ../../src/security/providers/JwtProvider.d.ts
|
|
147
498
|
/**
|
|
148
499
|
* Provides utilities for working with JSON Web Tokens (JWT).
|
|
149
500
|
*/
|
|
150
501
|
declare class JwtProvider {
|
|
151
|
-
protected readonly log:
|
|
502
|
+
protected readonly log: alepha_logger0.Logger;
|
|
152
503
|
protected readonly keystore: KeyLoaderHolder[];
|
|
153
504
|
protected readonly dateTimeProvider: DateTimeProvider;
|
|
154
505
|
protected readonly encoder: TextEncoder;
|
|
155
506
|
/**
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
507
|
+
* Adds a key loader to the embedded keystore.
|
|
508
|
+
*
|
|
509
|
+
* @param name
|
|
510
|
+
* @param secretKeyOrJwks
|
|
511
|
+
*/
|
|
161
512
|
setKeyLoader(name: string, secretKeyOrJwks: string | JSONWebKeySet): void;
|
|
162
513
|
/**
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
514
|
+
* Retrieves the payload from a JSON Web Token (JWT).
|
|
515
|
+
*
|
|
516
|
+
* @param token - The JWT to extract the payload from.
|
|
517
|
+
*
|
|
518
|
+
* @return A Promise that resolves with the payload object from the token.
|
|
519
|
+
*/
|
|
169
520
|
parse(token: string, keyName?: string, options?: JWTVerifyOptions): Promise<JwtParseResult>;
|
|
170
521
|
/**
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
522
|
+
* Creates a JWT token with the provided payload and secret key.
|
|
523
|
+
*
|
|
524
|
+
* @param payload - The payload to be encoded in the token.
|
|
525
|
+
* It should include the `realm_access` property which contains an array of roles.
|
|
526
|
+
* @param keyName - The name of the key to use when signing the token.
|
|
527
|
+
*
|
|
528
|
+
* @returns The signed JWT token.
|
|
529
|
+
*/
|
|
179
530
|
create(payload: ExtendedJWTPayload, keyName?: string, signOptions?: JwtSignOptions): Promise<string>;
|
|
180
531
|
/**
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
532
|
+
* Determines if the provided key is a secret key.
|
|
533
|
+
*
|
|
534
|
+
* @param key
|
|
535
|
+
* @protected
|
|
536
|
+
*/
|
|
186
537
|
protected isSecretKey(key: string): boolean;
|
|
187
538
|
}
|
|
188
539
|
type KeyLoader = (protectedHeader?: JWSHeaderParameters, token?: FlattenedJWSInput) => Promise<CryptoKey | KeyObject>;
|
|
@@ -244,7 +595,7 @@ declare class SecurityProvider {
|
|
|
244
595
|
protected readonly UNKNOWN_USER_NAME = "Anonymous User";
|
|
245
596
|
protected readonly PERMISSION_REGEXP: RegExp;
|
|
246
597
|
protected readonly PERMISSION_REGEXP_WILDCARD: RegExp;
|
|
247
|
-
protected readonly log:
|
|
598
|
+
protected readonly log: alepha_logger0.Logger;
|
|
248
599
|
protected readonly jwt: JwtProvider;
|
|
249
600
|
protected readonly env: {
|
|
250
601
|
APP_SECRET: string;
|
|
@@ -252,122 +603,162 @@ declare class SecurityProvider {
|
|
|
252
603
|
protected readonly alepha: Alepha;
|
|
253
604
|
get secretKey(): string;
|
|
254
605
|
/**
|
|
255
|
-
|
|
256
|
-
|
|
606
|
+
* The permissions configured for the security provider.
|
|
607
|
+
*/
|
|
257
608
|
protected readonly permissions: Permission[];
|
|
258
609
|
/**
|
|
259
|
-
|
|
260
|
-
|
|
610
|
+
* The realms configured for the security provider.
|
|
611
|
+
*/
|
|
261
612
|
protected readonly realms: Realm[];
|
|
262
613
|
protected start: alepha3.HookPrimitive<"start">;
|
|
263
614
|
/**
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
615
|
+
* Creates a default JWT resolver for a realm.
|
|
616
|
+
*/
|
|
617
|
+
protected createDefaultJwtResolver(realmName: string): IssuerResolver;
|
|
618
|
+
/**
|
|
619
|
+
* Adds a role to one or more realms.
|
|
620
|
+
*
|
|
621
|
+
* @param role
|
|
622
|
+
* @param realms
|
|
623
|
+
*/
|
|
269
624
|
createRole(role: Role, ...realms: string[]): Role;
|
|
270
625
|
/**
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
626
|
+
* Adds a permission to the security provider.
|
|
627
|
+
*
|
|
628
|
+
* @param raw - The permission to add.
|
|
629
|
+
*/
|
|
275
630
|
createPermission(raw: Permission | string): Permission;
|
|
276
631
|
createRealm(realm: Realm): void;
|
|
277
632
|
/**
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
633
|
+
* Updates the roles for a realm then synchronizes the user account provider if available.
|
|
634
|
+
*
|
|
635
|
+
* Only available when the app is started.
|
|
636
|
+
*
|
|
637
|
+
* @param realm - The realm to update the roles for.
|
|
638
|
+
* @param roles - The roles to update.
|
|
639
|
+
*/
|
|
285
640
|
updateRealm(realm: string, roles: Role[]): Promise<void>;
|
|
286
641
|
/**
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
642
|
+
* Creates a user account from the provided payload.
|
|
643
|
+
*
|
|
644
|
+
* @param payload - The payload to create the user account from.
|
|
645
|
+
* @param [realmName] - The realm containing the roles. Default is all.
|
|
646
|
+
*
|
|
647
|
+
* @returns The user info created from the payload.
|
|
648
|
+
*/
|
|
294
649
|
createUserFromPayload(payload: JWTPayload, realmName?: string): UserAccount;
|
|
295
650
|
/**
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
651
|
+
* Generic user creation from any source (JWT, API key, etc.).
|
|
652
|
+
* Handles permission checking, ownership, default roles.
|
|
653
|
+
*/
|
|
654
|
+
createUser(userInfo: UserInfo, options?: {
|
|
655
|
+
realm?: string;
|
|
656
|
+
permission?: Permission | string;
|
|
657
|
+
}): UserAccountToken;
|
|
658
|
+
/**
|
|
659
|
+
* Register a resolver to a realm.
|
|
660
|
+
* Resolvers are sorted by priority (lower = first).
|
|
661
|
+
*/
|
|
662
|
+
registerResolver(resolver: IssuerResolver, realmName?: string): void;
|
|
663
|
+
/**
|
|
664
|
+
* Get a realm by name.
|
|
665
|
+
* Throws if realm not found.
|
|
666
|
+
*/
|
|
667
|
+
getRealm(realmName?: string): Realm;
|
|
668
|
+
/**
|
|
669
|
+
* Resolve user from request using registered resolvers.
|
|
670
|
+
* Returns undefined if no resolver could authenticate (no auth provided).
|
|
671
|
+
* Throws UnauthorizedError if auth was provided but invalid.
|
|
672
|
+
*
|
|
673
|
+
* Note: This method tries resolvers from ALL realms to find a match,
|
|
674
|
+
* regardless of the `realm` option. The `realm` option is only used for
|
|
675
|
+
* permission checking after the user is resolved.
|
|
676
|
+
*/
|
|
677
|
+
resolveUserFromServerRequest(req: {
|
|
678
|
+
url: URL | string;
|
|
679
|
+
headers: {
|
|
680
|
+
authorization?: string;
|
|
681
|
+
};
|
|
682
|
+
}, options?: {
|
|
683
|
+
realm?: string;
|
|
684
|
+
permission?: Permission | string;
|
|
685
|
+
}): Promise<UserAccountToken | undefined>;
|
|
686
|
+
/**
|
|
687
|
+
* Checks if the user has the specified permission.
|
|
688
|
+
*
|
|
689
|
+
* Bonus: we check also if the user has "ownership" flag.
|
|
690
|
+
*
|
|
691
|
+
* @param permissionLike - The permission to check for.
|
|
692
|
+
* @param roleEntries - The roles to check for the permission.
|
|
693
|
+
*/
|
|
303
694
|
checkPermission(permissionLike: string | Permission, ...roleEntries: string[]): SecurityCheckResult;
|
|
304
695
|
/**
|
|
305
|
-
|
|
306
|
-
|
|
696
|
+
* Creates a user account from the provided payload.
|
|
697
|
+
*/
|
|
307
698
|
createUserFromToken(headerOrToken?: string, options?: {
|
|
308
699
|
permission?: Permission | string;
|
|
309
700
|
realm?: string;
|
|
310
701
|
verify?: JWTVerifyOptions;
|
|
311
702
|
}): Promise<UserAccountToken>;
|
|
312
703
|
/**
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
704
|
+
* Checks if a user has a specific role.
|
|
705
|
+
*
|
|
706
|
+
* @param roleName - The role to check for.
|
|
707
|
+
* @param permission - The permission to check for.
|
|
708
|
+
* @returns True if the user has the role, false otherwise.
|
|
709
|
+
*/
|
|
319
710
|
can(roleName: string, permission: string | Permission): boolean;
|
|
320
711
|
/**
|
|
321
|
-
|
|
322
|
-
|
|
712
|
+
* Checks if a user has ownership of a specific permission.
|
|
713
|
+
*/
|
|
323
714
|
ownership(roleName: string, permission: string | Permission): string | boolean | undefined;
|
|
324
715
|
/**
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
716
|
+
* Converts a permission object to a string.
|
|
717
|
+
*
|
|
718
|
+
* @param permission
|
|
719
|
+
*/
|
|
329
720
|
permissionToString(permission: Permission | string): string;
|
|
330
721
|
getRealms(): Realm[];
|
|
331
722
|
/**
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
723
|
+
* Retrieves the user account from the provided user ID.
|
|
724
|
+
*
|
|
725
|
+
* @param realm
|
|
726
|
+
*/
|
|
336
727
|
getRoles(realm?: string): Role[];
|
|
337
728
|
/**
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
729
|
+
* Returns all permissions.
|
|
730
|
+
*
|
|
731
|
+
* @param user - Filter permissions by user.
|
|
732
|
+
*
|
|
733
|
+
* @return An array containing all permissions.
|
|
734
|
+
*/
|
|
344
735
|
getPermissions(user?: {
|
|
345
736
|
roles?: Array<Role | string>;
|
|
346
737
|
realm?: string;
|
|
347
738
|
}): Permission[];
|
|
348
739
|
/**
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
740
|
+
* Retrieves the user ID from the provided payload object.
|
|
741
|
+
*
|
|
742
|
+
* @param payload - The payload object from which to extract the user ID.
|
|
743
|
+
* @return The user ID as a string.
|
|
744
|
+
*/
|
|
354
745
|
getIdFromPayload(payload: Record<string, any>): string;
|
|
355
746
|
getSessionIdFromPayload(payload: Record<string, any>): string | undefined;
|
|
356
747
|
/**
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
748
|
+
* Retrieves the roles from the provided payload object.
|
|
749
|
+
* @param payload - The payload object from which to extract the roles.
|
|
750
|
+
* @return An array of role strings.
|
|
751
|
+
*/
|
|
361
752
|
getRolesFromPayload(payload: Record<string, any>): string[];
|
|
362
753
|
getPictureFromPayload(payload: Record<string, any>): string | undefined;
|
|
363
754
|
getUsernameFromPayload(payload: Record<string, any>): string | undefined;
|
|
364
755
|
getEmailFromPayload(payload: Record<string, any>): string | undefined;
|
|
365
756
|
/**
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
757
|
+
* Returns the name from the given payload.
|
|
758
|
+
*
|
|
759
|
+
* @param payload - The payload object.
|
|
760
|
+
* @returns The name extracted from the payload, or an empty string if the payload is falsy or no name is found.
|
|
761
|
+
*/
|
|
371
762
|
getNameFromPayload(payload: Record<string, any>): string;
|
|
372
763
|
getOrganizationsFromPayload(payload: Record<string, any>): string[] | undefined;
|
|
373
764
|
}
|
|
@@ -378,16 +769,20 @@ interface Realm {
|
|
|
378
769
|
name: string;
|
|
379
770
|
roles: Role[];
|
|
380
771
|
/**
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
772
|
+
* The secret key for the realm.
|
|
773
|
+
*
|
|
774
|
+
* Can be also a JWKS URL.
|
|
775
|
+
*/
|
|
385
776
|
secret?: string | JSONWebKeySet | (() => string);
|
|
386
777
|
/**
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
778
|
+
* Create the user account info based on the raw JWT payload.
|
|
779
|
+
* By default, SecurityProvider has his own implementation, but this method allow to override it.
|
|
780
|
+
*/
|
|
390
781
|
profile?: (raw: Record<string, any>) => UserAccount;
|
|
782
|
+
/**
|
|
783
|
+
* Custom resolvers for this realm (sorted by priority).
|
|
784
|
+
*/
|
|
785
|
+
resolvers?: IssuerResolver[];
|
|
391
786
|
}
|
|
392
787
|
interface SecurityCheckResult {
|
|
393
788
|
isAuthorized: boolean;
|
|
@@ -407,40 +802,44 @@ declare const $issuer: {
|
|
|
407
802
|
};
|
|
408
803
|
type IssuerPrimitiveOptions = {
|
|
409
804
|
/**
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
805
|
+
* Define the issuer name.
|
|
806
|
+
* If not provided, it will use the property key.
|
|
807
|
+
*/
|
|
413
808
|
name?: string;
|
|
414
809
|
/**
|
|
415
|
-
|
|
416
|
-
|
|
810
|
+
* Short description about the issuer.
|
|
811
|
+
*/
|
|
417
812
|
description?: string;
|
|
418
813
|
/**
|
|
419
|
-
|
|
420
|
-
|
|
814
|
+
* All roles available in the issuer. Role is a string (role name) or a Role object (embedded role).
|
|
815
|
+
*/
|
|
421
816
|
roles?: Array<string | Role>;
|
|
422
817
|
/**
|
|
423
|
-
|
|
424
|
-
|
|
818
|
+
* Issuer settings.
|
|
819
|
+
*/
|
|
425
820
|
settings?: IssuerSettings;
|
|
426
821
|
/**
|
|
427
|
-
|
|
428
|
-
|
|
822
|
+
* Parse the JWT payload to create a user account info.
|
|
823
|
+
*/
|
|
429
824
|
profile?: (jwtPayload: Record<string, any>) => UserAccount;
|
|
825
|
+
/**
|
|
826
|
+
* Custom resolvers (in addition to default JWT resolver).
|
|
827
|
+
*/
|
|
828
|
+
resolvers?: IssuerResolver[];
|
|
430
829
|
} & (IssuerInternal | IssuerExternal);
|
|
431
830
|
interface IssuerSettings {
|
|
432
831
|
accessToken?: {
|
|
433
832
|
/**
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
833
|
+
* Lifetime of the access token.
|
|
834
|
+
* @default 15 minutes
|
|
835
|
+
*/
|
|
437
836
|
expiration?: DurationLike;
|
|
438
837
|
};
|
|
439
838
|
refreshToken?: {
|
|
440
839
|
/**
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
840
|
+
* Lifetime of the refresh token.
|
|
841
|
+
* @default 30 days
|
|
842
|
+
*/
|
|
444
843
|
expiration?: DurationLike;
|
|
445
844
|
};
|
|
446
845
|
onCreateSession?: (user: UserAccount, config: {
|
|
@@ -458,41 +857,50 @@ interface IssuerSettings {
|
|
|
458
857
|
}
|
|
459
858
|
type IssuerInternal = {
|
|
460
859
|
/**
|
|
461
|
-
|
|
462
|
-
|
|
860
|
+
* Internal secret to sign JWT tokens and verify them.
|
|
861
|
+
*/
|
|
463
862
|
secret: string;
|
|
464
863
|
};
|
|
465
864
|
interface IssuerExternal {
|
|
466
865
|
/**
|
|
467
|
-
|
|
468
|
-
|
|
866
|
+
* URL to the JWKS (JSON Web Key Set) to verify JWT tokens from external providers.
|
|
867
|
+
*/
|
|
469
868
|
jwks: (() => string) | JSONWebKeySet;
|
|
470
869
|
}
|
|
471
870
|
declare class IssuerPrimitive extends Primitive<IssuerPrimitiveOptions> {
|
|
472
871
|
protected readonly securityProvider: SecurityProvider;
|
|
473
872
|
protected readonly dateTimeProvider: DateTimeProvider;
|
|
474
873
|
protected readonly jwt: JwtProvider;
|
|
475
|
-
protected readonly log:
|
|
874
|
+
protected readonly log: alepha_logger0.Logger;
|
|
476
875
|
get name(): string;
|
|
477
876
|
get accessTokenExpiration(): Duration;
|
|
478
877
|
get refreshTokenExpiration(): Duration;
|
|
479
878
|
protected onInit(): void;
|
|
480
879
|
/**
|
|
481
|
-
|
|
482
|
-
|
|
880
|
+
* Creates the default JWT resolver.
|
|
881
|
+
*/
|
|
882
|
+
protected createJwtResolver(): IssuerResolver;
|
|
883
|
+
/**
|
|
884
|
+
* Register a resolver to this issuer.
|
|
885
|
+
* Resolvers are sorted by priority (lower = first).
|
|
886
|
+
*/
|
|
887
|
+
registerResolver(resolver: IssuerResolver): void;
|
|
888
|
+
/**
|
|
889
|
+
* Get all roles in the issuer.
|
|
890
|
+
*/
|
|
483
891
|
getRoles(): Role[];
|
|
484
892
|
/**
|
|
485
|
-
|
|
486
|
-
|
|
893
|
+
* Set all roles in the issuer.
|
|
894
|
+
*/
|
|
487
895
|
setRoles(roles: Role[]): Promise<void>;
|
|
488
896
|
/**
|
|
489
|
-
|
|
490
|
-
|
|
897
|
+
* Get a role by name, throws an error if not found.
|
|
898
|
+
*/
|
|
491
899
|
getRoleByName(name: string): Role;
|
|
492
900
|
parseToken(token: string): Promise<JWTPayload>;
|
|
493
901
|
/**
|
|
494
|
-
|
|
495
|
-
|
|
902
|
+
* Create a token for the subject.
|
|
903
|
+
*/
|
|
496
904
|
createToken(user: UserAccount, refreshToken?: {
|
|
497
905
|
sid?: string;
|
|
498
906
|
refresh_token?: string;
|
|
@@ -528,16 +936,16 @@ declare const $permission: {
|
|
|
528
936
|
};
|
|
529
937
|
interface PermissionPrimitiveOptions {
|
|
530
938
|
/**
|
|
531
|
-
|
|
532
|
-
|
|
939
|
+
* Name of the permission. Use Property name is not provided.
|
|
940
|
+
*/
|
|
533
941
|
name?: string;
|
|
534
942
|
/**
|
|
535
|
-
|
|
536
|
-
|
|
943
|
+
* Group of the permission. Use Class name is not provided.
|
|
944
|
+
*/
|
|
537
945
|
group?: string;
|
|
538
946
|
/**
|
|
539
|
-
|
|
540
|
-
|
|
947
|
+
* Describe the permission.
|
|
948
|
+
*/
|
|
541
949
|
description?: string;
|
|
542
950
|
}
|
|
543
951
|
declare class PermissionPrimitive extends Primitive<PermissionPrimitiveOptions> {
|
|
@@ -547,8 +955,8 @@ declare class PermissionPrimitive extends Primitive<PermissionPrimitiveOptions>
|
|
|
547
955
|
toString(): string;
|
|
548
956
|
protected onInit(): void;
|
|
549
957
|
/**
|
|
550
|
-
|
|
551
|
-
|
|
958
|
+
* Check if the user has the permission.
|
|
959
|
+
*/
|
|
552
960
|
can(user?: UserAccount): boolean;
|
|
553
961
|
}
|
|
554
962
|
//#endregion
|
|
@@ -562,12 +970,12 @@ declare const $role: {
|
|
|
562
970
|
};
|
|
563
971
|
interface RolePrimitiveOptions {
|
|
564
972
|
/**
|
|
565
|
-
|
|
566
|
-
|
|
973
|
+
* Name of the role.
|
|
974
|
+
*/
|
|
567
975
|
name?: string;
|
|
568
976
|
/**
|
|
569
|
-
|
|
570
|
-
|
|
977
|
+
* Describe the role.
|
|
978
|
+
*/
|
|
571
979
|
description?: string;
|
|
572
980
|
issuer?: string | IssuerPrimitive;
|
|
573
981
|
permissions?: Array<string | {
|
|
@@ -581,8 +989,8 @@ declare class RolePrimitive extends Primitive<RolePrimitiveOptions> {
|
|
|
581
989
|
get name(): string;
|
|
582
990
|
protected onInit(): void;
|
|
583
991
|
/**
|
|
584
|
-
|
|
585
|
-
|
|
992
|
+
* Get the issuer of the role.
|
|
993
|
+
*/
|
|
586
994
|
get issuer(): string | IssuerPrimitive | undefined;
|
|
587
995
|
can(permission: string | PermissionPrimitive): boolean;
|
|
588
996
|
check(permission: string | PermissionPrimitive): SecurityCheckResult;
|
|
@@ -628,16 +1036,16 @@ type ServiceAccountPrimitiveOptions = {
|
|
|
628
1036
|
});
|
|
629
1037
|
interface Oauth2ServiceAccountPrimitiveOptions {
|
|
630
1038
|
/**
|
|
631
|
-
|
|
632
|
-
|
|
1039
|
+
* Get Token URL.
|
|
1040
|
+
*/
|
|
633
1041
|
url: string;
|
|
634
1042
|
/**
|
|
635
|
-
|
|
636
|
-
|
|
1043
|
+
* Client ID.
|
|
1044
|
+
*/
|
|
637
1045
|
clientId: string;
|
|
638
1046
|
/**
|
|
639
|
-
|
|
640
|
-
|
|
1047
|
+
* Client Secret.
|
|
1048
|
+
*/
|
|
641
1049
|
clientSecret: string;
|
|
642
1050
|
}
|
|
643
1051
|
interface ServiceAccountPrimitive {
|
|
@@ -656,25 +1064,26 @@ declare class CryptoProvider {
|
|
|
656
1064
|
//#endregion
|
|
657
1065
|
//#region ../../src/security/providers/ServerSecurityProvider.d.ts
|
|
658
1066
|
declare class ServerSecurityProvider {
|
|
659
|
-
protected readonly log:
|
|
1067
|
+
protected readonly log: alepha_logger0.Logger;
|
|
660
1068
|
protected readonly securityProvider: SecurityProvider;
|
|
661
1069
|
protected readonly jwtProvider: JwtProvider;
|
|
662
1070
|
protected readonly alepha: Alepha;
|
|
1071
|
+
protected readonly resolvers: Array<ServerSecurityUserResolver>;
|
|
663
1072
|
protected readonly onConfigure: alepha3.HookPrimitive<"configure">;
|
|
664
1073
|
protected readonly onActionRequest: alepha3.HookPrimitive<"action:onRequest">;
|
|
665
1074
|
protected readonly onRequest: alepha3.HookPrimitive<"server:onRequest">;
|
|
666
1075
|
protected check(user: UserAccountToken, secure: ServerRouteSecure): void;
|
|
667
1076
|
/**
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
1077
|
+
* Get the user account token for a local action call.
|
|
1078
|
+
* There are three possible sources for the user:
|
|
1079
|
+
* - `options.user`: the user passed in the options
|
|
1080
|
+
* - `"system"`: the system user from the state (you MUST set state `server.security.system.user`)
|
|
1081
|
+
* - `"context"`: the user from the request context (you MUST be in an HTTP request context)
|
|
1082
|
+
*
|
|
1083
|
+
* Priority order: `options.user` > `"system"` > `"context"`.
|
|
1084
|
+
*
|
|
1085
|
+
* In testing environment, if no user is provided, a test user is created based on the SecurityProvider's roles.
|
|
1086
|
+
*/
|
|
678
1087
|
protected createUserFromLocalFunctionContext(options: {
|
|
679
1088
|
user?: UserAccountToken | "system" | "context";
|
|
680
1089
|
}, permission?: Permission): UserAccountToken;
|
|
@@ -685,6 +1094,7 @@ type ServerRouteSecure = {
|
|
|
685
1094
|
realm?: string;
|
|
686
1095
|
basic?: BasicAuthOptions;
|
|
687
1096
|
};
|
|
1097
|
+
type ServerSecurityUserResolver = (request: ServerRequest) => Promise<UserAccountToken | undefined>;
|
|
688
1098
|
//#endregion
|
|
689
1099
|
//#region ../../src/security/index.d.ts
|
|
690
1100
|
declare module "alepha" {
|
|
@@ -696,17 +1106,17 @@ declare module "alepha" {
|
|
|
696
1106
|
}
|
|
697
1107
|
interface State {
|
|
698
1108
|
/**
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
1109
|
+
* Real (or fake) user account, used for internal actions.
|
|
1110
|
+
*
|
|
1111
|
+
* If you define this, you assume that all actions are executed by this user by default.
|
|
1112
|
+
* > To force a different user, you need to pass it explicitly in the options.
|
|
1113
|
+
*/
|
|
704
1114
|
"alepha.server.security.system.user"?: UserAccountToken;
|
|
705
1115
|
/**
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
1116
|
+
* The authenticated user account attached to the server request state.
|
|
1117
|
+
*
|
|
1118
|
+
* @internal
|
|
1119
|
+
*/
|
|
710
1120
|
"alepha.server.request.user"?: UserAccount;
|
|
711
1121
|
}
|
|
712
1122
|
}
|
|
@@ -719,36 +1129,40 @@ declare module "alepha/server" {
|
|
|
719
1129
|
}
|
|
720
1130
|
interface ServerRoute {
|
|
721
1131
|
/**
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
1132
|
+
* If true, the route will be protected by the security provider.
|
|
1133
|
+
* All actions are secure by default, but you can disable it for specific actions.
|
|
1134
|
+
*/
|
|
725
1135
|
secure?: boolean | ServerRouteSecure;
|
|
726
1136
|
}
|
|
727
1137
|
interface ClientRequestOptions extends FetchOptions {
|
|
728
1138
|
/**
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
1139
|
+
* Forward user from the previous request.
|
|
1140
|
+
* If "system", use system user. @see {ServerSecurityProvider.localSystemUser}
|
|
1141
|
+
* If "context", use the user from the current context (e.g. request).
|
|
1142
|
+
*
|
|
1143
|
+
* @default "system" if provided, else "context" if available.
|
|
1144
|
+
*/
|
|
735
1145
|
user?: UserAccountToken | "system" | "context";
|
|
736
1146
|
}
|
|
737
1147
|
}
|
|
738
1148
|
/**
|
|
739
|
-
*
|
|
1149
|
+
* | type | quality | stability |
|
|
1150
|
+
* |------|---------|-----------|
|
|
1151
|
+
* | backend | epic | stable |
|
|
740
1152
|
*
|
|
741
|
-
*
|
|
742
|
-
* on class properties. It offers JWT-based authentication, fine-grained permissions, service accounts, and seamless
|
|
743
|
-
* integration with various authentication providers and user management systems.
|
|
1153
|
+
* Complete authentication and authorization system with JWT, RBAC, and multi-issuer support.
|
|
744
1154
|
*
|
|
745
|
-
*
|
|
746
|
-
*
|
|
1155
|
+
* **Features:**
|
|
1156
|
+
* - JWT token issuer with role definitions
|
|
1157
|
+
* - Role-based access control (RBAC)
|
|
1158
|
+
* - Fine-grained permissions
|
|
1159
|
+
* - HTTP Basic Authentication
|
|
1160
|
+
* - Service-to-service authentication
|
|
1161
|
+
* - Multi-issuer support for federated auth
|
|
1162
|
+
* - JWKS (JSON Web Key Set) for external issuers
|
|
1163
|
+
* - Token refresh logic
|
|
1164
|
+
* - User profile extraction from JWT
|
|
747
1165
|
*
|
|
748
|
-
* @see {@link $issuer}
|
|
749
|
-
* @see {@link $role}
|
|
750
|
-
* @see {@link $permission}
|
|
751
|
-
* @see {@link $basicAuth}
|
|
752
1166
|
* @module alepha.security
|
|
753
1167
|
*/
|
|
754
1168
|
declare const AlephaSecurity: alepha3.Service<alepha3.Module>;
|
|
@@ -757,5 +1171,5 @@ declare const AlephaSecurity: alepha3.Service<alepha3.Module>;
|
|
|
757
1171
|
*/
|
|
758
1172
|
declare const AlephaServerSecurity: alepha3.Service<alepha3.Module>;
|
|
759
1173
|
//#endregion
|
|
760
|
-
export { $basicAuth, $issuer, $permission, $role, $serviceAccount, AbstractBasicAuthPrimitive, AccessTokenResponse, AlephaSecurity, AlephaServerSecurity, BasicAuthOptions, BasicAuthPrimitive, BasicAuthPrimitiveConfig, CreateTokenOptions, CryptoProvider, DEFAULT_APP_SECRET, ExtendedJWTPayload, InvalidCredentialsError, InvalidPermissionError, IssuerExternal, IssuerInternal, IssuerPrimitive, IssuerPrimitiveOptions, IssuerSettings, JwtParseResult, JwtProvider, JwtSignOptions, KeyLoader, KeyLoaderHolder, Oauth2ServiceAccountPrimitiveOptions, Permission, PermissionPrimitive, PermissionPrimitiveOptions, Realm, Role, RolePrimitive, RolePrimitiveOptions, SecurityCheckResult, SecurityError, SecurityProvider, ServerBasicAuthProvider, ServerRouteSecure, ServerSecurityProvider, ServiceAccountPrimitive, ServiceAccountPrimitiveOptions, ServiceAccountStore, UserAccount, UserAccountToken, isBasicAuth, permissionSchema, roleSchema, userAccountInfoSchema };
|
|
1174
|
+
export { $basicAuth, $issuer, $permission, $role, $serviceAccount, AbstractBasicAuthPrimitive, AccessTokenResponse, AlephaSecurity, AlephaServerSecurity, BasicAuthOptions, BasicAuthPrimitive, BasicAuthPrimitiveConfig, CreateTokenOptions, CryptoProvider, DEFAULT_APP_SECRET, ExtendedJWTPayload, InvalidCredentialsError, InvalidPermissionError, IssuerExternal, IssuerInternal, IssuerPrimitive, IssuerPrimitiveOptions, IssuerResolver, IssuerSettings, JwtParseResult, JwtProvider, JwtSignOptions, KeyLoader, KeyLoaderHolder, Oauth2ServiceAccountPrimitiveOptions, Permission, PermissionPrimitive, PermissionPrimitiveOptions, Realm, Role, RolePrimitive, RolePrimitiveOptions, SecurityCheckResult, SecurityError, SecurityProvider, ServerBasicAuthProvider, ServerRouteSecure, ServerSecurityProvider, ServerSecurityUserResolver, ServiceAccountPrimitive, ServiceAccountPrimitiveOptions, ServiceAccountStore, UserAccount, UserAccountToken, UserInfo, isBasicAuth, permissionSchema, roleSchema, userAccountInfoSchema };
|
|
761
1175
|
//# sourceMappingURL=index.d.ts.map
|