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.js
CHANGED
|
@@ -3,8 +3,6 @@ import { $action, AlephaServer, ForbiddenError, HttpError, ServerRouterProvider,
|
|
|
3
3
|
import { createSecretKey, randomBytes, randomUUID, scrypt, timingSafeEqual } from "node:crypto";
|
|
4
4
|
import { $logger } from "alepha/logger";
|
|
5
5
|
import { DateTimeProvider } from "alepha/datetime";
|
|
6
|
-
import { SignJWT, createLocalJWKSet, createRemoteJWKSet, jwtVerify } from "jose";
|
|
7
|
-
import { JWTClaimValidationFailed, JWTExpired } from "jose/errors";
|
|
8
6
|
import { promisify } from "node:util";
|
|
9
7
|
|
|
10
8
|
//#region ../../src/security/providers/ServerBasicAuthProvider.ts
|
|
@@ -152,6 +150,1419 @@ var SecurityError = class extends Error {
|
|
|
152
150
|
status = 403;
|
|
153
151
|
};
|
|
154
152
|
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/buffer_utils.js
|
|
155
|
+
const encoder = new TextEncoder();
|
|
156
|
+
const decoder = new TextDecoder();
|
|
157
|
+
const MAX_INT32 = 2 ** 32;
|
|
158
|
+
function concat(...buffers) {
|
|
159
|
+
const size = buffers.reduce((acc, { length }) => acc + length, 0);
|
|
160
|
+
const buf = new Uint8Array(size);
|
|
161
|
+
let i = 0;
|
|
162
|
+
for (const buffer of buffers) {
|
|
163
|
+
buf.set(buffer, i);
|
|
164
|
+
i += buffer.length;
|
|
165
|
+
}
|
|
166
|
+
return buf;
|
|
167
|
+
}
|
|
168
|
+
function encode$1(string) {
|
|
169
|
+
const bytes = new Uint8Array(string.length);
|
|
170
|
+
for (let i = 0; i < string.length; i++) {
|
|
171
|
+
const code = string.charCodeAt(i);
|
|
172
|
+
if (code > 127) throw new TypeError("non-ASCII string encountered in encode()");
|
|
173
|
+
bytes[i] = code;
|
|
174
|
+
}
|
|
175
|
+
return bytes;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/base64.js
|
|
180
|
+
function encodeBase64(input) {
|
|
181
|
+
if (Uint8Array.prototype.toBase64) return input.toBase64();
|
|
182
|
+
const CHUNK_SIZE = 32768;
|
|
183
|
+
const arr = [];
|
|
184
|
+
for (let i = 0; i < input.length; i += CHUNK_SIZE) arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
|
|
185
|
+
return btoa(arr.join(""));
|
|
186
|
+
}
|
|
187
|
+
function decodeBase64(encoded) {
|
|
188
|
+
if (Uint8Array.fromBase64) return Uint8Array.fromBase64(encoded);
|
|
189
|
+
const binary = atob(encoded);
|
|
190
|
+
const bytes = new Uint8Array(binary.length);
|
|
191
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
192
|
+
return bytes;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region ../../../../node_modules/jose/dist/webapi/util/base64url.js
|
|
197
|
+
function decode(input) {
|
|
198
|
+
if (Uint8Array.fromBase64) return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), { alphabet: "base64url" });
|
|
199
|
+
let encoded = input;
|
|
200
|
+
if (encoded instanceof Uint8Array) encoded = decoder.decode(encoded);
|
|
201
|
+
encoded = encoded.replace(/-/g, "+").replace(/_/g, "/");
|
|
202
|
+
try {
|
|
203
|
+
return decodeBase64(encoded);
|
|
204
|
+
} catch {
|
|
205
|
+
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function encode(input) {
|
|
209
|
+
let unencoded = input;
|
|
210
|
+
if (typeof unencoded === "string") unencoded = encoder.encode(unencoded);
|
|
211
|
+
if (Uint8Array.prototype.toBase64) return unencoded.toBase64({
|
|
212
|
+
alphabet: "base64url",
|
|
213
|
+
omitPadding: true
|
|
214
|
+
});
|
|
215
|
+
return encodeBase64(unencoded).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
//#endregion
|
|
219
|
+
//#region ../../../../node_modules/jose/dist/webapi/util/errors.js
|
|
220
|
+
var JOSEError = class extends Error {
|
|
221
|
+
static code = "ERR_JOSE_GENERIC";
|
|
222
|
+
code = "ERR_JOSE_GENERIC";
|
|
223
|
+
constructor(message, options) {
|
|
224
|
+
super(message, options);
|
|
225
|
+
this.name = this.constructor.name;
|
|
226
|
+
Error.captureStackTrace?.(this, this.constructor);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
var JWTClaimValidationFailed = class extends JOSEError {
|
|
230
|
+
static code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
231
|
+
code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
232
|
+
claim;
|
|
233
|
+
reason;
|
|
234
|
+
payload;
|
|
235
|
+
constructor(message, payload, claim = "unspecified", reason = "unspecified") {
|
|
236
|
+
super(message, { cause: {
|
|
237
|
+
claim,
|
|
238
|
+
reason,
|
|
239
|
+
payload
|
|
240
|
+
} });
|
|
241
|
+
this.claim = claim;
|
|
242
|
+
this.reason = reason;
|
|
243
|
+
this.payload = payload;
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
var JWTExpired = class extends JOSEError {
|
|
247
|
+
static code = "ERR_JWT_EXPIRED";
|
|
248
|
+
code = "ERR_JWT_EXPIRED";
|
|
249
|
+
claim;
|
|
250
|
+
reason;
|
|
251
|
+
payload;
|
|
252
|
+
constructor(message, payload, claim = "unspecified", reason = "unspecified") {
|
|
253
|
+
super(message, { cause: {
|
|
254
|
+
claim,
|
|
255
|
+
reason,
|
|
256
|
+
payload
|
|
257
|
+
} });
|
|
258
|
+
this.claim = claim;
|
|
259
|
+
this.reason = reason;
|
|
260
|
+
this.payload = payload;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
var JOSEAlgNotAllowed = class extends JOSEError {
|
|
264
|
+
static code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
265
|
+
code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
266
|
+
};
|
|
267
|
+
var JOSENotSupported = class extends JOSEError {
|
|
268
|
+
static code = "ERR_JOSE_NOT_SUPPORTED";
|
|
269
|
+
code = "ERR_JOSE_NOT_SUPPORTED";
|
|
270
|
+
};
|
|
271
|
+
var JWSInvalid = class extends JOSEError {
|
|
272
|
+
static code = "ERR_JWS_INVALID";
|
|
273
|
+
code = "ERR_JWS_INVALID";
|
|
274
|
+
};
|
|
275
|
+
var JWTInvalid = class extends JOSEError {
|
|
276
|
+
static code = "ERR_JWT_INVALID";
|
|
277
|
+
code = "ERR_JWT_INVALID";
|
|
278
|
+
};
|
|
279
|
+
var JWKSInvalid = class extends JOSEError {
|
|
280
|
+
static code = "ERR_JWKS_INVALID";
|
|
281
|
+
code = "ERR_JWKS_INVALID";
|
|
282
|
+
};
|
|
283
|
+
var JWKSNoMatchingKey = class extends JOSEError {
|
|
284
|
+
static code = "ERR_JWKS_NO_MATCHING_KEY";
|
|
285
|
+
code = "ERR_JWKS_NO_MATCHING_KEY";
|
|
286
|
+
constructor(message = "no applicable key found in the JSON Web Key Set", options) {
|
|
287
|
+
super(message, options);
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
var JWKSMultipleMatchingKeys = class extends JOSEError {
|
|
291
|
+
[Symbol.asyncIterator];
|
|
292
|
+
static code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
|
|
293
|
+
code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
|
|
294
|
+
constructor(message = "multiple matching keys found in the JSON Web Key Set", options) {
|
|
295
|
+
super(message, options);
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
var JWKSTimeout = class extends JOSEError {
|
|
299
|
+
static code = "ERR_JWKS_TIMEOUT";
|
|
300
|
+
code = "ERR_JWKS_TIMEOUT";
|
|
301
|
+
constructor(message = "request timed out", options) {
|
|
302
|
+
super(message, options);
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
var JWSSignatureVerificationFailed = class extends JOSEError {
|
|
306
|
+
static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
307
|
+
code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
308
|
+
constructor(message = "signature verification failed", options) {
|
|
309
|
+
super(message, options);
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
//#endregion
|
|
314
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/crypto_key.js
|
|
315
|
+
const unusable = (name, prop = "algorithm.name") => /* @__PURE__ */ new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
316
|
+
const isAlgorithm = (algorithm, name) => algorithm.name === name;
|
|
317
|
+
function getHashLength(hash) {
|
|
318
|
+
return parseInt(hash.name.slice(4), 10);
|
|
319
|
+
}
|
|
320
|
+
function getNamedCurve(alg) {
|
|
321
|
+
switch (alg) {
|
|
322
|
+
case "ES256": return "P-256";
|
|
323
|
+
case "ES384": return "P-384";
|
|
324
|
+
case "ES512": return "P-521";
|
|
325
|
+
default: throw new Error("unreachable");
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
function checkUsage(key, usage) {
|
|
329
|
+
if (usage && !key.usages.includes(usage)) throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
|
|
330
|
+
}
|
|
331
|
+
function checkSigCryptoKey(key, alg, usage) {
|
|
332
|
+
switch (alg) {
|
|
333
|
+
case "HS256":
|
|
334
|
+
case "HS384":
|
|
335
|
+
case "HS512": {
|
|
336
|
+
if (!isAlgorithm(key.algorithm, "HMAC")) throw unusable("HMAC");
|
|
337
|
+
const expected = parseInt(alg.slice(2), 10);
|
|
338
|
+
if (getHashLength(key.algorithm.hash) !== expected) throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
case "RS256":
|
|
342
|
+
case "RS384":
|
|
343
|
+
case "RS512": {
|
|
344
|
+
if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5")) throw unusable("RSASSA-PKCS1-v1_5");
|
|
345
|
+
const expected = parseInt(alg.slice(2), 10);
|
|
346
|
+
if (getHashLength(key.algorithm.hash) !== expected) throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
case "PS256":
|
|
350
|
+
case "PS384":
|
|
351
|
+
case "PS512": {
|
|
352
|
+
if (!isAlgorithm(key.algorithm, "RSA-PSS")) throw unusable("RSA-PSS");
|
|
353
|
+
const expected = parseInt(alg.slice(2), 10);
|
|
354
|
+
if (getHashLength(key.algorithm.hash) !== expected) throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
case "Ed25519":
|
|
358
|
+
case "EdDSA":
|
|
359
|
+
if (!isAlgorithm(key.algorithm, "Ed25519")) throw unusable("Ed25519");
|
|
360
|
+
break;
|
|
361
|
+
case "ML-DSA-44":
|
|
362
|
+
case "ML-DSA-65":
|
|
363
|
+
case "ML-DSA-87":
|
|
364
|
+
if (!isAlgorithm(key.algorithm, alg)) throw unusable(alg);
|
|
365
|
+
break;
|
|
366
|
+
case "ES256":
|
|
367
|
+
case "ES384":
|
|
368
|
+
case "ES512": {
|
|
369
|
+
if (!isAlgorithm(key.algorithm, "ECDSA")) throw unusable("ECDSA");
|
|
370
|
+
const expected = getNamedCurve(alg);
|
|
371
|
+
if (key.algorithm.namedCurve !== expected) throw unusable(expected, "algorithm.namedCurve");
|
|
372
|
+
break;
|
|
373
|
+
}
|
|
374
|
+
default: throw new TypeError("CryptoKey does not support this operation");
|
|
375
|
+
}
|
|
376
|
+
checkUsage(key, usage);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
//#endregion
|
|
380
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/invalid_key_input.js
|
|
381
|
+
function message(msg, actual, ...types) {
|
|
382
|
+
types = types.filter(Boolean);
|
|
383
|
+
if (types.length > 2) {
|
|
384
|
+
const last = types.pop();
|
|
385
|
+
msg += `one of type ${types.join(", ")}, or ${last}.`;
|
|
386
|
+
} else if (types.length === 2) msg += `one of type ${types[0]} or ${types[1]}.`;
|
|
387
|
+
else msg += `of type ${types[0]}.`;
|
|
388
|
+
if (actual == null) msg += ` Received ${actual}`;
|
|
389
|
+
else if (typeof actual === "function" && actual.name) msg += ` Received function ${actual.name}`;
|
|
390
|
+
else if (typeof actual === "object" && actual != null) {
|
|
391
|
+
if (actual.constructor?.name) msg += ` Received an instance of ${actual.constructor.name}`;
|
|
392
|
+
}
|
|
393
|
+
return msg;
|
|
394
|
+
}
|
|
395
|
+
const invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
|
|
396
|
+
const withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
397
|
+
|
|
398
|
+
//#endregion
|
|
399
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/is_key_like.js
|
|
400
|
+
const isCryptoKey = (key) => {
|
|
401
|
+
if (key?.[Symbol.toStringTag] === "CryptoKey") return true;
|
|
402
|
+
try {
|
|
403
|
+
return key instanceof CryptoKey;
|
|
404
|
+
} catch {
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
const isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject";
|
|
409
|
+
const isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
|
|
410
|
+
|
|
411
|
+
//#endregion
|
|
412
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/is_disjoint.js
|
|
413
|
+
function isDisjoint(...headers) {
|
|
414
|
+
const sources = headers.filter(Boolean);
|
|
415
|
+
if (sources.length === 0 || sources.length === 1) return true;
|
|
416
|
+
let acc;
|
|
417
|
+
for (const header of sources) {
|
|
418
|
+
const parameters = Object.keys(header);
|
|
419
|
+
if (!acc || acc.size === 0) {
|
|
420
|
+
acc = new Set(parameters);
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
for (const parameter of parameters) {
|
|
424
|
+
if (acc.has(parameter)) return false;
|
|
425
|
+
acc.add(parameter);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return true;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
//#endregion
|
|
432
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/is_object.js
|
|
433
|
+
const isObjectLike = (value) => typeof value === "object" && value !== null;
|
|
434
|
+
function isObject(input) {
|
|
435
|
+
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") return false;
|
|
436
|
+
if (Object.getPrototypeOf(input) === null) return true;
|
|
437
|
+
let proto = input;
|
|
438
|
+
while (Object.getPrototypeOf(proto) !== null) proto = Object.getPrototypeOf(proto);
|
|
439
|
+
return Object.getPrototypeOf(input) === proto;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
//#endregion
|
|
443
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/check_key_length.js
|
|
444
|
+
function checkKeyLength(alg, key) {
|
|
445
|
+
if (alg.startsWith("RS") || alg.startsWith("PS")) {
|
|
446
|
+
const { modulusLength } = key.algorithm;
|
|
447
|
+
if (typeof modulusLength !== "number" || modulusLength < 2048) throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
//#endregion
|
|
452
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/jwk_to_key.js
|
|
453
|
+
function subtleMapping(jwk) {
|
|
454
|
+
let algorithm;
|
|
455
|
+
let keyUsages;
|
|
456
|
+
switch (jwk.kty) {
|
|
457
|
+
case "AKP":
|
|
458
|
+
switch (jwk.alg) {
|
|
459
|
+
case "ML-DSA-44":
|
|
460
|
+
case "ML-DSA-65":
|
|
461
|
+
case "ML-DSA-87":
|
|
462
|
+
algorithm = { name: jwk.alg };
|
|
463
|
+
keyUsages = jwk.priv ? ["sign"] : ["verify"];
|
|
464
|
+
break;
|
|
465
|
+
default: throw new JOSENotSupported("Invalid or unsupported JWK \"alg\" (Algorithm) Parameter value");
|
|
466
|
+
}
|
|
467
|
+
break;
|
|
468
|
+
case "RSA":
|
|
469
|
+
switch (jwk.alg) {
|
|
470
|
+
case "PS256":
|
|
471
|
+
case "PS384":
|
|
472
|
+
case "PS512":
|
|
473
|
+
algorithm = {
|
|
474
|
+
name: "RSA-PSS",
|
|
475
|
+
hash: `SHA-${jwk.alg.slice(-3)}`
|
|
476
|
+
};
|
|
477
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
478
|
+
break;
|
|
479
|
+
case "RS256":
|
|
480
|
+
case "RS384":
|
|
481
|
+
case "RS512":
|
|
482
|
+
algorithm = {
|
|
483
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
484
|
+
hash: `SHA-${jwk.alg.slice(-3)}`
|
|
485
|
+
};
|
|
486
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
487
|
+
break;
|
|
488
|
+
case "RSA-OAEP":
|
|
489
|
+
case "RSA-OAEP-256":
|
|
490
|
+
case "RSA-OAEP-384":
|
|
491
|
+
case "RSA-OAEP-512":
|
|
492
|
+
algorithm = {
|
|
493
|
+
name: "RSA-OAEP",
|
|
494
|
+
hash: `SHA-${parseInt(jwk.alg.slice(-3), 10) || 1}`
|
|
495
|
+
};
|
|
496
|
+
keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
|
|
497
|
+
break;
|
|
498
|
+
default: throw new JOSENotSupported("Invalid or unsupported JWK \"alg\" (Algorithm) Parameter value");
|
|
499
|
+
}
|
|
500
|
+
break;
|
|
501
|
+
case "EC":
|
|
502
|
+
switch (jwk.alg) {
|
|
503
|
+
case "ES256":
|
|
504
|
+
algorithm = {
|
|
505
|
+
name: "ECDSA",
|
|
506
|
+
namedCurve: "P-256"
|
|
507
|
+
};
|
|
508
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
509
|
+
break;
|
|
510
|
+
case "ES384":
|
|
511
|
+
algorithm = {
|
|
512
|
+
name: "ECDSA",
|
|
513
|
+
namedCurve: "P-384"
|
|
514
|
+
};
|
|
515
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
516
|
+
break;
|
|
517
|
+
case "ES512":
|
|
518
|
+
algorithm = {
|
|
519
|
+
name: "ECDSA",
|
|
520
|
+
namedCurve: "P-521"
|
|
521
|
+
};
|
|
522
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
523
|
+
break;
|
|
524
|
+
case "ECDH-ES":
|
|
525
|
+
case "ECDH-ES+A128KW":
|
|
526
|
+
case "ECDH-ES+A192KW":
|
|
527
|
+
case "ECDH-ES+A256KW":
|
|
528
|
+
algorithm = {
|
|
529
|
+
name: "ECDH",
|
|
530
|
+
namedCurve: jwk.crv
|
|
531
|
+
};
|
|
532
|
+
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
533
|
+
break;
|
|
534
|
+
default: throw new JOSENotSupported("Invalid or unsupported JWK \"alg\" (Algorithm) Parameter value");
|
|
535
|
+
}
|
|
536
|
+
break;
|
|
537
|
+
case "OKP":
|
|
538
|
+
switch (jwk.alg) {
|
|
539
|
+
case "Ed25519":
|
|
540
|
+
case "EdDSA":
|
|
541
|
+
algorithm = { name: "Ed25519" };
|
|
542
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
543
|
+
break;
|
|
544
|
+
case "ECDH-ES":
|
|
545
|
+
case "ECDH-ES+A128KW":
|
|
546
|
+
case "ECDH-ES+A192KW":
|
|
547
|
+
case "ECDH-ES+A256KW":
|
|
548
|
+
algorithm = { name: jwk.crv };
|
|
549
|
+
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
550
|
+
break;
|
|
551
|
+
default: throw new JOSENotSupported("Invalid or unsupported JWK \"alg\" (Algorithm) Parameter value");
|
|
552
|
+
}
|
|
553
|
+
break;
|
|
554
|
+
default: throw new JOSENotSupported("Invalid or unsupported JWK \"kty\" (Key Type) Parameter value");
|
|
555
|
+
}
|
|
556
|
+
return {
|
|
557
|
+
algorithm,
|
|
558
|
+
keyUsages
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
async function jwkToKey(jwk) {
|
|
562
|
+
if (!jwk.alg) throw new TypeError("\"alg\" argument is required when \"jwk.alg\" is not present");
|
|
563
|
+
const { algorithm, keyUsages } = subtleMapping(jwk);
|
|
564
|
+
const keyData = { ...jwk };
|
|
565
|
+
if (keyData.kty !== "AKP") delete keyData.alg;
|
|
566
|
+
delete keyData.use;
|
|
567
|
+
return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
//#endregion
|
|
571
|
+
//#region ../../../../node_modules/jose/dist/webapi/key/import.js
|
|
572
|
+
async function importJWK(jwk, alg, options) {
|
|
573
|
+
if (!isObject(jwk)) throw new TypeError("JWK must be an object");
|
|
574
|
+
let ext;
|
|
575
|
+
alg ??= jwk.alg;
|
|
576
|
+
ext ??= options?.extractable ?? jwk.ext;
|
|
577
|
+
switch (jwk.kty) {
|
|
578
|
+
case "oct":
|
|
579
|
+
if (typeof jwk.k !== "string" || !jwk.k) throw new TypeError("missing \"k\" (Key Value) Parameter value");
|
|
580
|
+
return decode(jwk.k);
|
|
581
|
+
case "RSA":
|
|
582
|
+
if ("oth" in jwk && jwk.oth !== void 0) throw new JOSENotSupported("RSA JWK \"oth\" (Other Primes Info) Parameter value is not supported");
|
|
583
|
+
return jwkToKey({
|
|
584
|
+
...jwk,
|
|
585
|
+
alg,
|
|
586
|
+
ext
|
|
587
|
+
});
|
|
588
|
+
case "AKP":
|
|
589
|
+
if (typeof jwk.alg !== "string" || !jwk.alg) throw new TypeError("missing \"alg\" (Algorithm) Parameter value");
|
|
590
|
+
if (alg !== void 0 && alg !== jwk.alg) throw new TypeError("JWK alg and alg option value mismatch");
|
|
591
|
+
return jwkToKey({
|
|
592
|
+
...jwk,
|
|
593
|
+
ext
|
|
594
|
+
});
|
|
595
|
+
case "EC":
|
|
596
|
+
case "OKP": return jwkToKey({
|
|
597
|
+
...jwk,
|
|
598
|
+
alg,
|
|
599
|
+
ext
|
|
600
|
+
});
|
|
601
|
+
default: throw new JOSENotSupported("Unsupported \"kty\" (Key Type) Parameter value");
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
//#endregion
|
|
606
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/validate_crit.js
|
|
607
|
+
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
608
|
+
if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) throw new Err("\"crit\" (Critical) Header Parameter MUST be integrity protected");
|
|
609
|
+
if (!protectedHeader || protectedHeader.crit === void 0) return /* @__PURE__ */ new Set();
|
|
610
|
+
if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) throw new Err("\"crit\" (Critical) Header Parameter MUST be an array of non-empty strings when present");
|
|
611
|
+
let recognized;
|
|
612
|
+
if (recognizedOption !== void 0) recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
|
|
613
|
+
else recognized = recognizedDefault;
|
|
614
|
+
for (const parameter of protectedHeader.crit) {
|
|
615
|
+
if (!recognized.has(parameter)) throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
|
|
616
|
+
if (joseHeader[parameter] === void 0) throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
617
|
+
if (recognized.get(parameter) && protectedHeader[parameter] === void 0) throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
618
|
+
}
|
|
619
|
+
return new Set(protectedHeader.crit);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
//#endregion
|
|
623
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/validate_algorithms.js
|
|
624
|
+
function validateAlgorithms(option, algorithms) {
|
|
625
|
+
if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) throw new TypeError(`"${option}" option must be an array of strings`);
|
|
626
|
+
if (!algorithms) return;
|
|
627
|
+
return new Set(algorithms);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
//#endregion
|
|
631
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/is_jwk.js
|
|
632
|
+
const isJWK = (key) => isObject(key) && typeof key.kty === "string";
|
|
633
|
+
const isPrivateJWK = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
|
|
634
|
+
const isPublicJWK = (key) => key.kty !== "oct" && key.d === void 0 && key.priv === void 0;
|
|
635
|
+
const isSecretJWK = (key) => key.kty === "oct" && typeof key.k === "string";
|
|
636
|
+
|
|
637
|
+
//#endregion
|
|
638
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/normalize_key.js
|
|
639
|
+
let cache;
|
|
640
|
+
const handleJWK = async (key, jwk, alg, freeze = false) => {
|
|
641
|
+
cache ||= /* @__PURE__ */ new WeakMap();
|
|
642
|
+
let cached = cache.get(key);
|
|
643
|
+
if (cached?.[alg]) return cached[alg];
|
|
644
|
+
const cryptoKey = await jwkToKey({
|
|
645
|
+
...jwk,
|
|
646
|
+
alg
|
|
647
|
+
});
|
|
648
|
+
if (freeze) Object.freeze(key);
|
|
649
|
+
if (!cached) cache.set(key, { [alg]: cryptoKey });
|
|
650
|
+
else cached[alg] = cryptoKey;
|
|
651
|
+
return cryptoKey;
|
|
652
|
+
};
|
|
653
|
+
const handleKeyObject = (keyObject, alg) => {
|
|
654
|
+
cache ||= /* @__PURE__ */ new WeakMap();
|
|
655
|
+
let cached = cache.get(keyObject);
|
|
656
|
+
if (cached?.[alg]) return cached[alg];
|
|
657
|
+
const isPublic = keyObject.type === "public";
|
|
658
|
+
const extractable = isPublic ? true : false;
|
|
659
|
+
let cryptoKey;
|
|
660
|
+
if (keyObject.asymmetricKeyType === "x25519") {
|
|
661
|
+
switch (alg) {
|
|
662
|
+
case "ECDH-ES":
|
|
663
|
+
case "ECDH-ES+A128KW":
|
|
664
|
+
case "ECDH-ES+A192KW":
|
|
665
|
+
case "ECDH-ES+A256KW": break;
|
|
666
|
+
default: throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
667
|
+
}
|
|
668
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ["deriveBits"]);
|
|
669
|
+
}
|
|
670
|
+
if (keyObject.asymmetricKeyType === "ed25519") {
|
|
671
|
+
if (alg !== "EdDSA" && alg !== "Ed25519") throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
672
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [isPublic ? "verify" : "sign"]);
|
|
673
|
+
}
|
|
674
|
+
switch (keyObject.asymmetricKeyType) {
|
|
675
|
+
case "ml-dsa-44":
|
|
676
|
+
case "ml-dsa-65":
|
|
677
|
+
case "ml-dsa-87":
|
|
678
|
+
if (alg !== keyObject.asymmetricKeyType.toUpperCase()) throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
679
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [isPublic ? "verify" : "sign"]);
|
|
680
|
+
}
|
|
681
|
+
if (keyObject.asymmetricKeyType === "rsa") {
|
|
682
|
+
let hash;
|
|
683
|
+
switch (alg) {
|
|
684
|
+
case "RSA-OAEP":
|
|
685
|
+
hash = "SHA-1";
|
|
686
|
+
break;
|
|
687
|
+
case "RS256":
|
|
688
|
+
case "PS256":
|
|
689
|
+
case "RSA-OAEP-256":
|
|
690
|
+
hash = "SHA-256";
|
|
691
|
+
break;
|
|
692
|
+
case "RS384":
|
|
693
|
+
case "PS384":
|
|
694
|
+
case "RSA-OAEP-384":
|
|
695
|
+
hash = "SHA-384";
|
|
696
|
+
break;
|
|
697
|
+
case "RS512":
|
|
698
|
+
case "PS512":
|
|
699
|
+
case "RSA-OAEP-512":
|
|
700
|
+
hash = "SHA-512";
|
|
701
|
+
break;
|
|
702
|
+
default: throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
703
|
+
}
|
|
704
|
+
if (alg.startsWith("RSA-OAEP")) return keyObject.toCryptoKey({
|
|
705
|
+
name: "RSA-OAEP",
|
|
706
|
+
hash
|
|
707
|
+
}, extractable, isPublic ? ["encrypt"] : ["decrypt"]);
|
|
708
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
709
|
+
name: alg.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
|
|
710
|
+
hash
|
|
711
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
712
|
+
}
|
|
713
|
+
if (keyObject.asymmetricKeyType === "ec") {
|
|
714
|
+
const namedCurve = new Map([
|
|
715
|
+
["prime256v1", "P-256"],
|
|
716
|
+
["secp384r1", "P-384"],
|
|
717
|
+
["secp521r1", "P-521"]
|
|
718
|
+
]).get(keyObject.asymmetricKeyDetails?.namedCurve);
|
|
719
|
+
if (!namedCurve) throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
720
|
+
if (alg === "ES256" && namedCurve === "P-256") cryptoKey = keyObject.toCryptoKey({
|
|
721
|
+
name: "ECDSA",
|
|
722
|
+
namedCurve
|
|
723
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
724
|
+
if (alg === "ES384" && namedCurve === "P-384") cryptoKey = keyObject.toCryptoKey({
|
|
725
|
+
name: "ECDSA",
|
|
726
|
+
namedCurve
|
|
727
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
728
|
+
if (alg === "ES512" && namedCurve === "P-521") cryptoKey = keyObject.toCryptoKey({
|
|
729
|
+
name: "ECDSA",
|
|
730
|
+
namedCurve
|
|
731
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
732
|
+
if (alg.startsWith("ECDH-ES")) cryptoKey = keyObject.toCryptoKey({
|
|
733
|
+
name: "ECDH",
|
|
734
|
+
namedCurve
|
|
735
|
+
}, extractable, isPublic ? [] : ["deriveBits"]);
|
|
736
|
+
}
|
|
737
|
+
if (!cryptoKey) throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
738
|
+
if (!cached) cache.set(keyObject, { [alg]: cryptoKey });
|
|
739
|
+
else cached[alg] = cryptoKey;
|
|
740
|
+
return cryptoKey;
|
|
741
|
+
};
|
|
742
|
+
async function normalizeKey(key, alg) {
|
|
743
|
+
if (key instanceof Uint8Array) return key;
|
|
744
|
+
if (isCryptoKey(key)) return key;
|
|
745
|
+
if (isKeyObject(key)) {
|
|
746
|
+
if (key.type === "secret") return key.export();
|
|
747
|
+
if ("toCryptoKey" in key && typeof key.toCryptoKey === "function") try {
|
|
748
|
+
return handleKeyObject(key, alg);
|
|
749
|
+
} catch (err) {
|
|
750
|
+
if (err instanceof TypeError) throw err;
|
|
751
|
+
}
|
|
752
|
+
return handleJWK(key, key.export({ format: "jwk" }), alg);
|
|
753
|
+
}
|
|
754
|
+
if (isJWK(key)) {
|
|
755
|
+
if (key.k) return decode(key.k);
|
|
756
|
+
return handleJWK(key, key, alg, true);
|
|
757
|
+
}
|
|
758
|
+
throw new Error("unreachable");
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
//#endregion
|
|
762
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/check_key_type.js
|
|
763
|
+
const tag = (key) => key?.[Symbol.toStringTag];
|
|
764
|
+
const jwkMatchesOp = (alg, key, usage) => {
|
|
765
|
+
if (key.use !== void 0) {
|
|
766
|
+
let expected;
|
|
767
|
+
switch (usage) {
|
|
768
|
+
case "sign":
|
|
769
|
+
case "verify":
|
|
770
|
+
expected = "sig";
|
|
771
|
+
break;
|
|
772
|
+
case "encrypt":
|
|
773
|
+
case "decrypt":
|
|
774
|
+
expected = "enc";
|
|
775
|
+
break;
|
|
776
|
+
}
|
|
777
|
+
if (key.use !== expected) throw new TypeError(`Invalid key for this operation, its "use" must be "${expected}" when present`);
|
|
778
|
+
}
|
|
779
|
+
if (key.alg !== void 0 && key.alg !== alg) throw new TypeError(`Invalid key for this operation, its "alg" must be "${alg}" when present`);
|
|
780
|
+
if (Array.isArray(key.key_ops)) {
|
|
781
|
+
let expectedKeyOp;
|
|
782
|
+
switch (true) {
|
|
783
|
+
case usage === "sign" || usage === "verify":
|
|
784
|
+
case alg === "dir":
|
|
785
|
+
case alg.includes("CBC-HS"):
|
|
786
|
+
expectedKeyOp = usage;
|
|
787
|
+
break;
|
|
788
|
+
case alg.startsWith("PBES2"):
|
|
789
|
+
expectedKeyOp = "deriveBits";
|
|
790
|
+
break;
|
|
791
|
+
case /^A\d{3}(?:GCM)?(?:KW)?$/.test(alg):
|
|
792
|
+
if (!alg.includes("GCM") && alg.endsWith("KW")) expectedKeyOp = usage === "encrypt" ? "wrapKey" : "unwrapKey";
|
|
793
|
+
else expectedKeyOp = usage;
|
|
794
|
+
break;
|
|
795
|
+
case usage === "encrypt" && alg.startsWith("RSA"):
|
|
796
|
+
expectedKeyOp = "wrapKey";
|
|
797
|
+
break;
|
|
798
|
+
case usage === "decrypt":
|
|
799
|
+
expectedKeyOp = alg.startsWith("RSA") ? "unwrapKey" : "deriveBits";
|
|
800
|
+
break;
|
|
801
|
+
}
|
|
802
|
+
if (expectedKeyOp && key.key_ops?.includes?.(expectedKeyOp) === false) throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${expectedKeyOp}" when present`);
|
|
803
|
+
}
|
|
804
|
+
return true;
|
|
805
|
+
};
|
|
806
|
+
const symmetricTypeCheck = (alg, key, usage) => {
|
|
807
|
+
if (key instanceof Uint8Array) return;
|
|
808
|
+
if (isJWK(key)) {
|
|
809
|
+
if (isSecretJWK(key) && jwkMatchesOp(alg, key, usage)) return;
|
|
810
|
+
throw new TypeError(`JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present`);
|
|
811
|
+
}
|
|
812
|
+
if (!isKeyLike(key)) throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
|
|
813
|
+
if (key.type !== "secret") throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
|
|
814
|
+
};
|
|
815
|
+
const asymmetricTypeCheck = (alg, key, usage) => {
|
|
816
|
+
if (isJWK(key)) switch (usage) {
|
|
817
|
+
case "decrypt":
|
|
818
|
+
case "sign":
|
|
819
|
+
if (isPrivateJWK(key) && jwkMatchesOp(alg, key, usage)) return;
|
|
820
|
+
throw new TypeError(`JSON Web Key for this operation must be a private JWK`);
|
|
821
|
+
case "encrypt":
|
|
822
|
+
case "verify":
|
|
823
|
+
if (isPublicJWK(key) && jwkMatchesOp(alg, key, usage)) return;
|
|
824
|
+
throw new TypeError(`JSON Web Key for this operation must be a public JWK`);
|
|
825
|
+
}
|
|
826
|
+
if (!isKeyLike(key)) throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
827
|
+
if (key.type === "secret") throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
828
|
+
if (key.type === "public") switch (usage) {
|
|
829
|
+
case "sign": throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
|
|
830
|
+
case "decrypt": throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
|
|
831
|
+
}
|
|
832
|
+
if (key.type === "private") switch (usage) {
|
|
833
|
+
case "verify": throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
834
|
+
case "encrypt": throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
function checkKeyType(alg, key, usage) {
|
|
838
|
+
switch (alg.substring(0, 2)) {
|
|
839
|
+
case "A1":
|
|
840
|
+
case "A2":
|
|
841
|
+
case "di":
|
|
842
|
+
case "HS":
|
|
843
|
+
case "PB":
|
|
844
|
+
symmetricTypeCheck(alg, key, usage);
|
|
845
|
+
break;
|
|
846
|
+
default: asymmetricTypeCheck(alg, key, usage);
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
//#endregion
|
|
851
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/subtle_dsa.js
|
|
852
|
+
function subtleAlgorithm(alg, algorithm) {
|
|
853
|
+
const hash = `SHA-${alg.slice(-3)}`;
|
|
854
|
+
switch (alg) {
|
|
855
|
+
case "HS256":
|
|
856
|
+
case "HS384":
|
|
857
|
+
case "HS512": return {
|
|
858
|
+
hash,
|
|
859
|
+
name: "HMAC"
|
|
860
|
+
};
|
|
861
|
+
case "PS256":
|
|
862
|
+
case "PS384":
|
|
863
|
+
case "PS512": return {
|
|
864
|
+
hash,
|
|
865
|
+
name: "RSA-PSS",
|
|
866
|
+
saltLength: parseInt(alg.slice(-3), 10) >> 3
|
|
867
|
+
};
|
|
868
|
+
case "RS256":
|
|
869
|
+
case "RS384":
|
|
870
|
+
case "RS512": return {
|
|
871
|
+
hash,
|
|
872
|
+
name: "RSASSA-PKCS1-v1_5"
|
|
873
|
+
};
|
|
874
|
+
case "ES256":
|
|
875
|
+
case "ES384":
|
|
876
|
+
case "ES512": return {
|
|
877
|
+
hash,
|
|
878
|
+
name: "ECDSA",
|
|
879
|
+
namedCurve: algorithm.namedCurve
|
|
880
|
+
};
|
|
881
|
+
case "Ed25519":
|
|
882
|
+
case "EdDSA": return { name: "Ed25519" };
|
|
883
|
+
case "ML-DSA-44":
|
|
884
|
+
case "ML-DSA-65":
|
|
885
|
+
case "ML-DSA-87": return { name: alg };
|
|
886
|
+
default: throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
//#endregion
|
|
891
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/get_sign_verify_key.js
|
|
892
|
+
async function getSigKey(alg, key, usage) {
|
|
893
|
+
if (key instanceof Uint8Array) {
|
|
894
|
+
if (!alg.startsWith("HS")) throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
895
|
+
return crypto.subtle.importKey("raw", key, {
|
|
896
|
+
hash: `SHA-${alg.slice(-3)}`,
|
|
897
|
+
name: "HMAC"
|
|
898
|
+
}, false, [usage]);
|
|
899
|
+
}
|
|
900
|
+
checkSigCryptoKey(key, alg, usage);
|
|
901
|
+
return key;
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
//#endregion
|
|
905
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/verify.js
|
|
906
|
+
async function verify(alg, key, signature, data) {
|
|
907
|
+
const cryptoKey = await getSigKey(alg, key, "verify");
|
|
908
|
+
checkKeyLength(alg, cryptoKey);
|
|
909
|
+
const algorithm = subtleAlgorithm(alg, cryptoKey.algorithm);
|
|
910
|
+
try {
|
|
911
|
+
return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
|
|
912
|
+
} catch {
|
|
913
|
+
return false;
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
//#endregion
|
|
918
|
+
//#region ../../../../node_modules/jose/dist/webapi/jws/flattened/verify.js
|
|
919
|
+
async function flattenedVerify(jws, key, options) {
|
|
920
|
+
if (!isObject(jws)) throw new JWSInvalid("Flattened JWS must be an object");
|
|
921
|
+
if (jws.protected === void 0 && jws.header === void 0) throw new JWSInvalid("Flattened JWS must have either of the \"protected\" or \"header\" members");
|
|
922
|
+
if (jws.protected !== void 0 && typeof jws.protected !== "string") throw new JWSInvalid("JWS Protected Header incorrect type");
|
|
923
|
+
if (jws.payload === void 0) throw new JWSInvalid("JWS Payload missing");
|
|
924
|
+
if (typeof jws.signature !== "string") throw new JWSInvalid("JWS Signature missing or incorrect type");
|
|
925
|
+
if (jws.header !== void 0 && !isObject(jws.header)) throw new JWSInvalid("JWS Unprotected Header incorrect type");
|
|
926
|
+
let parsedProt = {};
|
|
927
|
+
if (jws.protected) try {
|
|
928
|
+
const protectedHeader = decode(jws.protected);
|
|
929
|
+
parsedProt = JSON.parse(decoder.decode(protectedHeader));
|
|
930
|
+
} catch {
|
|
931
|
+
throw new JWSInvalid("JWS Protected Header is invalid");
|
|
932
|
+
}
|
|
933
|
+
if (!isDisjoint(parsedProt, jws.header)) throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
934
|
+
const joseHeader = {
|
|
935
|
+
...parsedProt,
|
|
936
|
+
...jws.header
|
|
937
|
+
};
|
|
938
|
+
const extensions = validateCrit(JWSInvalid, new Map([["b64", true]]), options?.crit, parsedProt, joseHeader);
|
|
939
|
+
let b64 = true;
|
|
940
|
+
if (extensions.has("b64")) {
|
|
941
|
+
b64 = parsedProt.b64;
|
|
942
|
+
if (typeof b64 !== "boolean") throw new JWSInvalid("The \"b64\" (base64url-encode payload) Header Parameter must be a boolean");
|
|
943
|
+
}
|
|
944
|
+
const { alg } = joseHeader;
|
|
945
|
+
if (typeof alg !== "string" || !alg) throw new JWSInvalid("JWS \"alg\" (Algorithm) Header Parameter missing or invalid");
|
|
946
|
+
const algorithms = options && validateAlgorithms("algorithms", options.algorithms);
|
|
947
|
+
if (algorithms && !algorithms.has(alg)) throw new JOSEAlgNotAllowed("\"alg\" (Algorithm) Header Parameter value not allowed");
|
|
948
|
+
if (b64) {
|
|
949
|
+
if (typeof jws.payload !== "string") throw new JWSInvalid("JWS Payload must be a string");
|
|
950
|
+
} else if (typeof jws.payload !== "string" && !(jws.payload instanceof Uint8Array)) throw new JWSInvalid("JWS Payload must be a string or an Uint8Array instance");
|
|
951
|
+
let resolvedKey = false;
|
|
952
|
+
if (typeof key === "function") {
|
|
953
|
+
key = await key(parsedProt, jws);
|
|
954
|
+
resolvedKey = true;
|
|
955
|
+
}
|
|
956
|
+
checkKeyType(alg, key, "verify");
|
|
957
|
+
const data = concat(jws.protected !== void 0 ? encode$1(jws.protected) : new Uint8Array(), encode$1("."), typeof jws.payload === "string" ? b64 ? encode$1(jws.payload) : encoder.encode(jws.payload) : jws.payload);
|
|
958
|
+
let signature;
|
|
959
|
+
try {
|
|
960
|
+
signature = decode(jws.signature);
|
|
961
|
+
} catch {
|
|
962
|
+
throw new JWSInvalid("Failed to base64url decode the signature");
|
|
963
|
+
}
|
|
964
|
+
const k = await normalizeKey(key, alg);
|
|
965
|
+
if (!await verify(alg, k, signature, data)) throw new JWSSignatureVerificationFailed();
|
|
966
|
+
let payload;
|
|
967
|
+
if (b64) try {
|
|
968
|
+
payload = decode(jws.payload);
|
|
969
|
+
} catch {
|
|
970
|
+
throw new JWSInvalid("Failed to base64url decode the payload");
|
|
971
|
+
}
|
|
972
|
+
else if (typeof jws.payload === "string") payload = encoder.encode(jws.payload);
|
|
973
|
+
else payload = jws.payload;
|
|
974
|
+
const result = { payload };
|
|
975
|
+
if (jws.protected !== void 0) result.protectedHeader = parsedProt;
|
|
976
|
+
if (jws.header !== void 0) result.unprotectedHeader = jws.header;
|
|
977
|
+
if (resolvedKey) return {
|
|
978
|
+
...result,
|
|
979
|
+
key: k
|
|
980
|
+
};
|
|
981
|
+
return result;
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
//#endregion
|
|
985
|
+
//#region ../../../../node_modules/jose/dist/webapi/jws/compact/verify.js
|
|
986
|
+
async function compactVerify(jws, key, options) {
|
|
987
|
+
if (jws instanceof Uint8Array) jws = decoder.decode(jws);
|
|
988
|
+
if (typeof jws !== "string") throw new JWSInvalid("Compact JWS must be a string or Uint8Array");
|
|
989
|
+
const { 0: protectedHeader, 1: payload, 2: signature, length } = jws.split(".");
|
|
990
|
+
if (length !== 3) throw new JWSInvalid("Invalid Compact JWS");
|
|
991
|
+
const verified = await flattenedVerify({
|
|
992
|
+
payload,
|
|
993
|
+
protected: protectedHeader,
|
|
994
|
+
signature
|
|
995
|
+
}, key, options);
|
|
996
|
+
const result = {
|
|
997
|
+
payload: verified.payload,
|
|
998
|
+
protectedHeader: verified.protectedHeader
|
|
999
|
+
};
|
|
1000
|
+
if (typeof key === "function") return {
|
|
1001
|
+
...result,
|
|
1002
|
+
key: verified.key
|
|
1003
|
+
};
|
|
1004
|
+
return result;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
//#endregion
|
|
1008
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/jwt_claims_set.js
|
|
1009
|
+
const epoch = (date) => Math.floor(date.getTime() / 1e3);
|
|
1010
|
+
const minute = 60;
|
|
1011
|
+
const hour = minute * 60;
|
|
1012
|
+
const day = hour * 24;
|
|
1013
|
+
const week = day * 7;
|
|
1014
|
+
const year = day * 365.25;
|
|
1015
|
+
const REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
|
|
1016
|
+
function secs(str) {
|
|
1017
|
+
const matched = REGEX.exec(str);
|
|
1018
|
+
if (!matched || matched[4] && matched[1]) throw new TypeError("Invalid time period format");
|
|
1019
|
+
const value = parseFloat(matched[2]);
|
|
1020
|
+
const unit = matched[3].toLowerCase();
|
|
1021
|
+
let numericDate;
|
|
1022
|
+
switch (unit) {
|
|
1023
|
+
case "sec":
|
|
1024
|
+
case "secs":
|
|
1025
|
+
case "second":
|
|
1026
|
+
case "seconds":
|
|
1027
|
+
case "s":
|
|
1028
|
+
numericDate = Math.round(value);
|
|
1029
|
+
break;
|
|
1030
|
+
case "minute":
|
|
1031
|
+
case "minutes":
|
|
1032
|
+
case "min":
|
|
1033
|
+
case "mins":
|
|
1034
|
+
case "m":
|
|
1035
|
+
numericDate = Math.round(value * minute);
|
|
1036
|
+
break;
|
|
1037
|
+
case "hour":
|
|
1038
|
+
case "hours":
|
|
1039
|
+
case "hr":
|
|
1040
|
+
case "hrs":
|
|
1041
|
+
case "h":
|
|
1042
|
+
numericDate = Math.round(value * hour);
|
|
1043
|
+
break;
|
|
1044
|
+
case "day":
|
|
1045
|
+
case "days":
|
|
1046
|
+
case "d":
|
|
1047
|
+
numericDate = Math.round(value * day);
|
|
1048
|
+
break;
|
|
1049
|
+
case "week":
|
|
1050
|
+
case "weeks":
|
|
1051
|
+
case "w":
|
|
1052
|
+
numericDate = Math.round(value * week);
|
|
1053
|
+
break;
|
|
1054
|
+
default:
|
|
1055
|
+
numericDate = Math.round(value * year);
|
|
1056
|
+
break;
|
|
1057
|
+
}
|
|
1058
|
+
if (matched[1] === "-" || matched[4] === "ago") return -numericDate;
|
|
1059
|
+
return numericDate;
|
|
1060
|
+
}
|
|
1061
|
+
function validateInput(label, input) {
|
|
1062
|
+
if (!Number.isFinite(input)) throw new TypeError(`Invalid ${label} input`);
|
|
1063
|
+
return input;
|
|
1064
|
+
}
|
|
1065
|
+
const normalizeTyp = (value) => {
|
|
1066
|
+
if (value.includes("/")) return value.toLowerCase();
|
|
1067
|
+
return `application/${value.toLowerCase()}`;
|
|
1068
|
+
};
|
|
1069
|
+
const checkAudiencePresence = (audPayload, audOption) => {
|
|
1070
|
+
if (typeof audPayload === "string") return audOption.includes(audPayload);
|
|
1071
|
+
if (Array.isArray(audPayload)) return audOption.some(Set.prototype.has.bind(new Set(audPayload)));
|
|
1072
|
+
return false;
|
|
1073
|
+
};
|
|
1074
|
+
function validateClaimsSet(protectedHeader, encodedPayload, options = {}) {
|
|
1075
|
+
let payload;
|
|
1076
|
+
try {
|
|
1077
|
+
payload = JSON.parse(decoder.decode(encodedPayload));
|
|
1078
|
+
} catch {}
|
|
1079
|
+
if (!isObject(payload)) throw new JWTInvalid("JWT Claims Set must be a top-level JSON object");
|
|
1080
|
+
const { typ } = options;
|
|
1081
|
+
if (typ && (typeof protectedHeader.typ !== "string" || normalizeTyp(protectedHeader.typ) !== normalizeTyp(typ))) throw new JWTClaimValidationFailed("unexpected \"typ\" JWT header value", payload, "typ", "check_failed");
|
|
1082
|
+
const { requiredClaims = [], issuer, subject, audience, maxTokenAge } = options;
|
|
1083
|
+
const presenceCheck = [...requiredClaims];
|
|
1084
|
+
if (maxTokenAge !== void 0) presenceCheck.push("iat");
|
|
1085
|
+
if (audience !== void 0) presenceCheck.push("aud");
|
|
1086
|
+
if (subject !== void 0) presenceCheck.push("sub");
|
|
1087
|
+
if (issuer !== void 0) presenceCheck.push("iss");
|
|
1088
|
+
for (const claim of new Set(presenceCheck.reverse())) if (!(claim in payload)) throw new JWTClaimValidationFailed(`missing required "${claim}" claim`, payload, claim, "missing");
|
|
1089
|
+
if (issuer && !(Array.isArray(issuer) ? issuer : [issuer]).includes(payload.iss)) throw new JWTClaimValidationFailed("unexpected \"iss\" claim value", payload, "iss", "check_failed");
|
|
1090
|
+
if (subject && payload.sub !== subject) throw new JWTClaimValidationFailed("unexpected \"sub\" claim value", payload, "sub", "check_failed");
|
|
1091
|
+
if (audience && !checkAudiencePresence(payload.aud, typeof audience === "string" ? [audience] : audience)) throw new JWTClaimValidationFailed("unexpected \"aud\" claim value", payload, "aud", "check_failed");
|
|
1092
|
+
let tolerance;
|
|
1093
|
+
switch (typeof options.clockTolerance) {
|
|
1094
|
+
case "string":
|
|
1095
|
+
tolerance = secs(options.clockTolerance);
|
|
1096
|
+
break;
|
|
1097
|
+
case "number":
|
|
1098
|
+
tolerance = options.clockTolerance;
|
|
1099
|
+
break;
|
|
1100
|
+
case "undefined":
|
|
1101
|
+
tolerance = 0;
|
|
1102
|
+
break;
|
|
1103
|
+
default: throw new TypeError("Invalid clockTolerance option type");
|
|
1104
|
+
}
|
|
1105
|
+
const { currentDate } = options;
|
|
1106
|
+
const now = epoch(currentDate || /* @__PURE__ */ new Date());
|
|
1107
|
+
if ((payload.iat !== void 0 || maxTokenAge) && typeof payload.iat !== "number") throw new JWTClaimValidationFailed("\"iat\" claim must be a number", payload, "iat", "invalid");
|
|
1108
|
+
if (payload.nbf !== void 0) {
|
|
1109
|
+
if (typeof payload.nbf !== "number") throw new JWTClaimValidationFailed("\"nbf\" claim must be a number", payload, "nbf", "invalid");
|
|
1110
|
+
if (payload.nbf > now + tolerance) throw new JWTClaimValidationFailed("\"nbf\" claim timestamp check failed", payload, "nbf", "check_failed");
|
|
1111
|
+
}
|
|
1112
|
+
if (payload.exp !== void 0) {
|
|
1113
|
+
if (typeof payload.exp !== "number") throw new JWTClaimValidationFailed("\"exp\" claim must be a number", payload, "exp", "invalid");
|
|
1114
|
+
if (payload.exp <= now - tolerance) throw new JWTExpired("\"exp\" claim timestamp check failed", payload, "exp", "check_failed");
|
|
1115
|
+
}
|
|
1116
|
+
if (maxTokenAge) {
|
|
1117
|
+
const age = now - payload.iat;
|
|
1118
|
+
const max = typeof maxTokenAge === "number" ? maxTokenAge : secs(maxTokenAge);
|
|
1119
|
+
if (age - tolerance > max) throw new JWTExpired("\"iat\" claim timestamp check failed (too far in the past)", payload, "iat", "check_failed");
|
|
1120
|
+
if (age < 0 - tolerance) throw new JWTClaimValidationFailed("\"iat\" claim timestamp check failed (it should be in the past)", payload, "iat", "check_failed");
|
|
1121
|
+
}
|
|
1122
|
+
return payload;
|
|
1123
|
+
}
|
|
1124
|
+
var JWTClaimsBuilder = class {
|
|
1125
|
+
#payload;
|
|
1126
|
+
constructor(payload) {
|
|
1127
|
+
if (!isObject(payload)) throw new TypeError("JWT Claims Set MUST be an object");
|
|
1128
|
+
this.#payload = structuredClone(payload);
|
|
1129
|
+
}
|
|
1130
|
+
data() {
|
|
1131
|
+
return encoder.encode(JSON.stringify(this.#payload));
|
|
1132
|
+
}
|
|
1133
|
+
get iss() {
|
|
1134
|
+
return this.#payload.iss;
|
|
1135
|
+
}
|
|
1136
|
+
set iss(value) {
|
|
1137
|
+
this.#payload.iss = value;
|
|
1138
|
+
}
|
|
1139
|
+
get sub() {
|
|
1140
|
+
return this.#payload.sub;
|
|
1141
|
+
}
|
|
1142
|
+
set sub(value) {
|
|
1143
|
+
this.#payload.sub = value;
|
|
1144
|
+
}
|
|
1145
|
+
get aud() {
|
|
1146
|
+
return this.#payload.aud;
|
|
1147
|
+
}
|
|
1148
|
+
set aud(value) {
|
|
1149
|
+
this.#payload.aud = value;
|
|
1150
|
+
}
|
|
1151
|
+
set jti(value) {
|
|
1152
|
+
this.#payload.jti = value;
|
|
1153
|
+
}
|
|
1154
|
+
set nbf(value) {
|
|
1155
|
+
if (typeof value === "number") this.#payload.nbf = validateInput("setNotBefore", value);
|
|
1156
|
+
else if (value instanceof Date) this.#payload.nbf = validateInput("setNotBefore", epoch(value));
|
|
1157
|
+
else this.#payload.nbf = epoch(/* @__PURE__ */ new Date()) + secs(value);
|
|
1158
|
+
}
|
|
1159
|
+
set exp(value) {
|
|
1160
|
+
if (typeof value === "number") this.#payload.exp = validateInput("setExpirationTime", value);
|
|
1161
|
+
else if (value instanceof Date) this.#payload.exp = validateInput("setExpirationTime", epoch(value));
|
|
1162
|
+
else this.#payload.exp = epoch(/* @__PURE__ */ new Date()) + secs(value);
|
|
1163
|
+
}
|
|
1164
|
+
set iat(value) {
|
|
1165
|
+
if (value === void 0) this.#payload.iat = epoch(/* @__PURE__ */ new Date());
|
|
1166
|
+
else if (value instanceof Date) this.#payload.iat = validateInput("setIssuedAt", epoch(value));
|
|
1167
|
+
else if (typeof value === "string") this.#payload.iat = validateInput("setIssuedAt", epoch(/* @__PURE__ */ new Date()) + secs(value));
|
|
1168
|
+
else this.#payload.iat = validateInput("setIssuedAt", value);
|
|
1169
|
+
}
|
|
1170
|
+
};
|
|
1171
|
+
|
|
1172
|
+
//#endregion
|
|
1173
|
+
//#region ../../../../node_modules/jose/dist/webapi/jwt/verify.js
|
|
1174
|
+
async function jwtVerify(jwt, key, options) {
|
|
1175
|
+
const verified = await compactVerify(jwt, key, options);
|
|
1176
|
+
if (verified.protectedHeader.crit?.includes("b64") && verified.protectedHeader.b64 === false) throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
1177
|
+
const result = {
|
|
1178
|
+
payload: validateClaimsSet(verified.protectedHeader, verified.payload, options),
|
|
1179
|
+
protectedHeader: verified.protectedHeader
|
|
1180
|
+
};
|
|
1181
|
+
if (typeof key === "function") return {
|
|
1182
|
+
...result,
|
|
1183
|
+
key: verified.key
|
|
1184
|
+
};
|
|
1185
|
+
return result;
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
//#endregion
|
|
1189
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/sign.js
|
|
1190
|
+
async function sign(alg, key, data) {
|
|
1191
|
+
const cryptoKey = await getSigKey(alg, key, "sign");
|
|
1192
|
+
checkKeyLength(alg, cryptoKey);
|
|
1193
|
+
const signature = await crypto.subtle.sign(subtleAlgorithm(alg, cryptoKey.algorithm), cryptoKey, data);
|
|
1194
|
+
return new Uint8Array(signature);
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
//#endregion
|
|
1198
|
+
//#region ../../../../node_modules/jose/dist/webapi/jws/flattened/sign.js
|
|
1199
|
+
var FlattenedSign = class {
|
|
1200
|
+
#payload;
|
|
1201
|
+
#protectedHeader;
|
|
1202
|
+
#unprotectedHeader;
|
|
1203
|
+
constructor(payload) {
|
|
1204
|
+
if (!(payload instanceof Uint8Array)) throw new TypeError("payload must be an instance of Uint8Array");
|
|
1205
|
+
this.#payload = payload;
|
|
1206
|
+
}
|
|
1207
|
+
setProtectedHeader(protectedHeader) {
|
|
1208
|
+
if (this.#protectedHeader) throw new TypeError("setProtectedHeader can only be called once");
|
|
1209
|
+
this.#protectedHeader = protectedHeader;
|
|
1210
|
+
return this;
|
|
1211
|
+
}
|
|
1212
|
+
setUnprotectedHeader(unprotectedHeader) {
|
|
1213
|
+
if (this.#unprotectedHeader) throw new TypeError("setUnprotectedHeader can only be called once");
|
|
1214
|
+
this.#unprotectedHeader = unprotectedHeader;
|
|
1215
|
+
return this;
|
|
1216
|
+
}
|
|
1217
|
+
async sign(key, options) {
|
|
1218
|
+
if (!this.#protectedHeader && !this.#unprotectedHeader) throw new JWSInvalid("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
|
|
1219
|
+
if (!isDisjoint(this.#protectedHeader, this.#unprotectedHeader)) throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
1220
|
+
const joseHeader = {
|
|
1221
|
+
...this.#protectedHeader,
|
|
1222
|
+
...this.#unprotectedHeader
|
|
1223
|
+
};
|
|
1224
|
+
const extensions = validateCrit(JWSInvalid, new Map([["b64", true]]), options?.crit, this.#protectedHeader, joseHeader);
|
|
1225
|
+
let b64 = true;
|
|
1226
|
+
if (extensions.has("b64")) {
|
|
1227
|
+
b64 = this.#protectedHeader.b64;
|
|
1228
|
+
if (typeof b64 !== "boolean") throw new JWSInvalid("The \"b64\" (base64url-encode payload) Header Parameter must be a boolean");
|
|
1229
|
+
}
|
|
1230
|
+
const { alg } = joseHeader;
|
|
1231
|
+
if (typeof alg !== "string" || !alg) throw new JWSInvalid("JWS \"alg\" (Algorithm) Header Parameter missing or invalid");
|
|
1232
|
+
checkKeyType(alg, key, "sign");
|
|
1233
|
+
let payloadS;
|
|
1234
|
+
let payloadB;
|
|
1235
|
+
if (b64) {
|
|
1236
|
+
payloadS = encode(this.#payload);
|
|
1237
|
+
payloadB = encode$1(payloadS);
|
|
1238
|
+
} else {
|
|
1239
|
+
payloadB = this.#payload;
|
|
1240
|
+
payloadS = "";
|
|
1241
|
+
}
|
|
1242
|
+
let protectedHeaderString;
|
|
1243
|
+
let protectedHeaderBytes;
|
|
1244
|
+
if (this.#protectedHeader) {
|
|
1245
|
+
protectedHeaderString = encode(JSON.stringify(this.#protectedHeader));
|
|
1246
|
+
protectedHeaderBytes = encode$1(protectedHeaderString);
|
|
1247
|
+
} else {
|
|
1248
|
+
protectedHeaderString = "";
|
|
1249
|
+
protectedHeaderBytes = new Uint8Array();
|
|
1250
|
+
}
|
|
1251
|
+
const data = concat(protectedHeaderBytes, encode$1("."), payloadB);
|
|
1252
|
+
const jws = {
|
|
1253
|
+
signature: encode(await sign(alg, await normalizeKey(key, alg), data)),
|
|
1254
|
+
payload: payloadS
|
|
1255
|
+
};
|
|
1256
|
+
if (this.#unprotectedHeader) jws.header = this.#unprotectedHeader;
|
|
1257
|
+
if (this.#protectedHeader) jws.protected = protectedHeaderString;
|
|
1258
|
+
return jws;
|
|
1259
|
+
}
|
|
1260
|
+
};
|
|
1261
|
+
|
|
1262
|
+
//#endregion
|
|
1263
|
+
//#region ../../../../node_modules/jose/dist/webapi/jws/compact/sign.js
|
|
1264
|
+
var CompactSign = class {
|
|
1265
|
+
#flattened;
|
|
1266
|
+
constructor(payload) {
|
|
1267
|
+
this.#flattened = new FlattenedSign(payload);
|
|
1268
|
+
}
|
|
1269
|
+
setProtectedHeader(protectedHeader) {
|
|
1270
|
+
this.#flattened.setProtectedHeader(protectedHeader);
|
|
1271
|
+
return this;
|
|
1272
|
+
}
|
|
1273
|
+
async sign(key, options) {
|
|
1274
|
+
const jws = await this.#flattened.sign(key, options);
|
|
1275
|
+
if (jws.payload === void 0) throw new TypeError("use the flattened module for creating JWS with b64: false");
|
|
1276
|
+
return `${jws.protected}.${jws.payload}.${jws.signature}`;
|
|
1277
|
+
}
|
|
1278
|
+
};
|
|
1279
|
+
|
|
1280
|
+
//#endregion
|
|
1281
|
+
//#region ../../../../node_modules/jose/dist/webapi/jwt/sign.js
|
|
1282
|
+
var SignJWT = class {
|
|
1283
|
+
#protectedHeader;
|
|
1284
|
+
#jwt;
|
|
1285
|
+
constructor(payload = {}) {
|
|
1286
|
+
this.#jwt = new JWTClaimsBuilder(payload);
|
|
1287
|
+
}
|
|
1288
|
+
setIssuer(issuer) {
|
|
1289
|
+
this.#jwt.iss = issuer;
|
|
1290
|
+
return this;
|
|
1291
|
+
}
|
|
1292
|
+
setSubject(subject) {
|
|
1293
|
+
this.#jwt.sub = subject;
|
|
1294
|
+
return this;
|
|
1295
|
+
}
|
|
1296
|
+
setAudience(audience) {
|
|
1297
|
+
this.#jwt.aud = audience;
|
|
1298
|
+
return this;
|
|
1299
|
+
}
|
|
1300
|
+
setJti(jwtId) {
|
|
1301
|
+
this.#jwt.jti = jwtId;
|
|
1302
|
+
return this;
|
|
1303
|
+
}
|
|
1304
|
+
setNotBefore(input) {
|
|
1305
|
+
this.#jwt.nbf = input;
|
|
1306
|
+
return this;
|
|
1307
|
+
}
|
|
1308
|
+
setExpirationTime(input) {
|
|
1309
|
+
this.#jwt.exp = input;
|
|
1310
|
+
return this;
|
|
1311
|
+
}
|
|
1312
|
+
setIssuedAt(input) {
|
|
1313
|
+
this.#jwt.iat = input;
|
|
1314
|
+
return this;
|
|
1315
|
+
}
|
|
1316
|
+
setProtectedHeader(protectedHeader) {
|
|
1317
|
+
this.#protectedHeader = protectedHeader;
|
|
1318
|
+
return this;
|
|
1319
|
+
}
|
|
1320
|
+
async sign(key, options) {
|
|
1321
|
+
const sig = new CompactSign(this.#jwt.data());
|
|
1322
|
+
sig.setProtectedHeader(this.#protectedHeader);
|
|
1323
|
+
if (Array.isArray(this.#protectedHeader?.crit) && this.#protectedHeader.crit.includes("b64") && this.#protectedHeader.b64 === false) throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
1324
|
+
return sig.sign(key, options);
|
|
1325
|
+
}
|
|
1326
|
+
};
|
|
1327
|
+
|
|
1328
|
+
//#endregion
|
|
1329
|
+
//#region ../../../../node_modules/jose/dist/webapi/jwks/local.js
|
|
1330
|
+
function getKtyFromAlg(alg) {
|
|
1331
|
+
switch (typeof alg === "string" && alg.slice(0, 2)) {
|
|
1332
|
+
case "RS":
|
|
1333
|
+
case "PS": return "RSA";
|
|
1334
|
+
case "ES": return "EC";
|
|
1335
|
+
case "Ed": return "OKP";
|
|
1336
|
+
case "ML": return "AKP";
|
|
1337
|
+
default: throw new JOSENotSupported("Unsupported \"alg\" value for a JSON Web Key Set");
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
function isJWKSLike(jwks) {
|
|
1341
|
+
return jwks && typeof jwks === "object" && Array.isArray(jwks.keys) && jwks.keys.every(isJWKLike);
|
|
1342
|
+
}
|
|
1343
|
+
function isJWKLike(key) {
|
|
1344
|
+
return isObject(key);
|
|
1345
|
+
}
|
|
1346
|
+
var LocalJWKSet = class {
|
|
1347
|
+
#jwks;
|
|
1348
|
+
#cached = /* @__PURE__ */ new WeakMap();
|
|
1349
|
+
constructor(jwks) {
|
|
1350
|
+
if (!isJWKSLike(jwks)) throw new JWKSInvalid("JSON Web Key Set malformed");
|
|
1351
|
+
this.#jwks = structuredClone(jwks);
|
|
1352
|
+
}
|
|
1353
|
+
jwks() {
|
|
1354
|
+
return this.#jwks;
|
|
1355
|
+
}
|
|
1356
|
+
async getKey(protectedHeader, token) {
|
|
1357
|
+
const { alg, kid } = {
|
|
1358
|
+
...protectedHeader,
|
|
1359
|
+
...token?.header
|
|
1360
|
+
};
|
|
1361
|
+
const kty = getKtyFromAlg(alg);
|
|
1362
|
+
const candidates = this.#jwks.keys.filter((jwk) => {
|
|
1363
|
+
let candidate = kty === jwk.kty;
|
|
1364
|
+
if (candidate && typeof kid === "string") candidate = kid === jwk.kid;
|
|
1365
|
+
if (candidate && (typeof jwk.alg === "string" || kty === "AKP")) candidate = alg === jwk.alg;
|
|
1366
|
+
if (candidate && typeof jwk.use === "string") candidate = jwk.use === "sig";
|
|
1367
|
+
if (candidate && Array.isArray(jwk.key_ops)) candidate = jwk.key_ops.includes("verify");
|
|
1368
|
+
if (candidate) switch (alg) {
|
|
1369
|
+
case "ES256":
|
|
1370
|
+
candidate = jwk.crv === "P-256";
|
|
1371
|
+
break;
|
|
1372
|
+
case "ES384":
|
|
1373
|
+
candidate = jwk.crv === "P-384";
|
|
1374
|
+
break;
|
|
1375
|
+
case "ES512":
|
|
1376
|
+
candidate = jwk.crv === "P-521";
|
|
1377
|
+
break;
|
|
1378
|
+
case "Ed25519":
|
|
1379
|
+
case "EdDSA":
|
|
1380
|
+
candidate = jwk.crv === "Ed25519";
|
|
1381
|
+
break;
|
|
1382
|
+
}
|
|
1383
|
+
return candidate;
|
|
1384
|
+
});
|
|
1385
|
+
const { 0: jwk, length } = candidates;
|
|
1386
|
+
if (length === 0) throw new JWKSNoMatchingKey();
|
|
1387
|
+
if (length !== 1) {
|
|
1388
|
+
const error = new JWKSMultipleMatchingKeys();
|
|
1389
|
+
const _cached = this.#cached;
|
|
1390
|
+
error[Symbol.asyncIterator] = async function* () {
|
|
1391
|
+
for (const jwk of candidates) try {
|
|
1392
|
+
yield await importWithAlgCache(_cached, jwk, alg);
|
|
1393
|
+
} catch {}
|
|
1394
|
+
};
|
|
1395
|
+
throw error;
|
|
1396
|
+
}
|
|
1397
|
+
return importWithAlgCache(this.#cached, jwk, alg);
|
|
1398
|
+
}
|
|
1399
|
+
};
|
|
1400
|
+
async function importWithAlgCache(cache, jwk, alg) {
|
|
1401
|
+
const cached = cache.get(jwk) || cache.set(jwk, {}).get(jwk);
|
|
1402
|
+
if (cached[alg] === void 0) {
|
|
1403
|
+
const key = await importJWK({
|
|
1404
|
+
...jwk,
|
|
1405
|
+
ext: true
|
|
1406
|
+
}, alg);
|
|
1407
|
+
if (key instanceof Uint8Array || key.type !== "public") throw new JWKSInvalid("JSON Web Key Set members must be public keys");
|
|
1408
|
+
cached[alg] = key;
|
|
1409
|
+
}
|
|
1410
|
+
return cached[alg];
|
|
1411
|
+
}
|
|
1412
|
+
function createLocalJWKSet(jwks) {
|
|
1413
|
+
const set = new LocalJWKSet(jwks);
|
|
1414
|
+
const localJWKSet = async (protectedHeader, token) => set.getKey(protectedHeader, token);
|
|
1415
|
+
Object.defineProperties(localJWKSet, { jwks: {
|
|
1416
|
+
value: () => structuredClone(set.jwks()),
|
|
1417
|
+
enumerable: false,
|
|
1418
|
+
configurable: false,
|
|
1419
|
+
writable: false
|
|
1420
|
+
} });
|
|
1421
|
+
return localJWKSet;
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
//#endregion
|
|
1425
|
+
//#region ../../../../node_modules/jose/dist/webapi/jwks/remote.js
|
|
1426
|
+
function isCloudflareWorkers() {
|
|
1427
|
+
return typeof WebSocketPair !== "undefined" || typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers" || typeof EdgeRuntime !== "undefined" && EdgeRuntime === "vercel";
|
|
1428
|
+
}
|
|
1429
|
+
let USER_AGENT;
|
|
1430
|
+
if (typeof navigator === "undefined" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) USER_AGENT = `jose/v6.1.3`;
|
|
1431
|
+
const customFetch = Symbol();
|
|
1432
|
+
async function fetchJwks(url, headers, signal, fetchImpl = fetch) {
|
|
1433
|
+
const response = await fetchImpl(url, {
|
|
1434
|
+
method: "GET",
|
|
1435
|
+
signal,
|
|
1436
|
+
redirect: "manual",
|
|
1437
|
+
headers
|
|
1438
|
+
}).catch((err) => {
|
|
1439
|
+
if (err.name === "TimeoutError") throw new JWKSTimeout();
|
|
1440
|
+
throw err;
|
|
1441
|
+
});
|
|
1442
|
+
if (response.status !== 200) throw new JOSEError("Expected 200 OK from the JSON Web Key Set HTTP response");
|
|
1443
|
+
try {
|
|
1444
|
+
return await response.json();
|
|
1445
|
+
} catch {
|
|
1446
|
+
throw new JOSEError("Failed to parse the JSON Web Key Set HTTP response as JSON");
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
const jwksCache = Symbol();
|
|
1450
|
+
function isFreshJwksCache(input, cacheMaxAge) {
|
|
1451
|
+
if (typeof input !== "object" || input === null) return false;
|
|
1452
|
+
if (!("uat" in input) || typeof input.uat !== "number" || Date.now() - input.uat >= cacheMaxAge) return false;
|
|
1453
|
+
if (!("jwks" in input) || !isObject(input.jwks) || !Array.isArray(input.jwks.keys) || !Array.prototype.every.call(input.jwks.keys, isObject)) return false;
|
|
1454
|
+
return true;
|
|
1455
|
+
}
|
|
1456
|
+
var RemoteJWKSet = class {
|
|
1457
|
+
#url;
|
|
1458
|
+
#timeoutDuration;
|
|
1459
|
+
#cooldownDuration;
|
|
1460
|
+
#cacheMaxAge;
|
|
1461
|
+
#jwksTimestamp;
|
|
1462
|
+
#pendingFetch;
|
|
1463
|
+
#headers;
|
|
1464
|
+
#customFetch;
|
|
1465
|
+
#local;
|
|
1466
|
+
#cache;
|
|
1467
|
+
constructor(url, options) {
|
|
1468
|
+
if (!(url instanceof URL)) throw new TypeError("url must be an instance of URL");
|
|
1469
|
+
this.#url = new URL(url.href);
|
|
1470
|
+
this.#timeoutDuration = typeof options?.timeoutDuration === "number" ? options?.timeoutDuration : 5e3;
|
|
1471
|
+
this.#cooldownDuration = typeof options?.cooldownDuration === "number" ? options?.cooldownDuration : 3e4;
|
|
1472
|
+
this.#cacheMaxAge = typeof options?.cacheMaxAge === "number" ? options?.cacheMaxAge : 6e5;
|
|
1473
|
+
this.#headers = new Headers(options?.headers);
|
|
1474
|
+
if (USER_AGENT && !this.#headers.has("User-Agent")) this.#headers.set("User-Agent", USER_AGENT);
|
|
1475
|
+
if (!this.#headers.has("accept")) {
|
|
1476
|
+
this.#headers.set("accept", "application/json");
|
|
1477
|
+
this.#headers.append("accept", "application/jwk-set+json");
|
|
1478
|
+
}
|
|
1479
|
+
this.#customFetch = options?.[customFetch];
|
|
1480
|
+
if (options?.[jwksCache] !== void 0) {
|
|
1481
|
+
this.#cache = options?.[jwksCache];
|
|
1482
|
+
if (isFreshJwksCache(options?.[jwksCache], this.#cacheMaxAge)) {
|
|
1483
|
+
this.#jwksTimestamp = this.#cache.uat;
|
|
1484
|
+
this.#local = createLocalJWKSet(this.#cache.jwks);
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
pendingFetch() {
|
|
1489
|
+
return !!this.#pendingFetch;
|
|
1490
|
+
}
|
|
1491
|
+
coolingDown() {
|
|
1492
|
+
return typeof this.#jwksTimestamp === "number" ? Date.now() < this.#jwksTimestamp + this.#cooldownDuration : false;
|
|
1493
|
+
}
|
|
1494
|
+
fresh() {
|
|
1495
|
+
return typeof this.#jwksTimestamp === "number" ? Date.now() < this.#jwksTimestamp + this.#cacheMaxAge : false;
|
|
1496
|
+
}
|
|
1497
|
+
jwks() {
|
|
1498
|
+
return this.#local?.jwks();
|
|
1499
|
+
}
|
|
1500
|
+
async getKey(protectedHeader, token) {
|
|
1501
|
+
if (!this.#local || !this.fresh()) await this.reload();
|
|
1502
|
+
try {
|
|
1503
|
+
return await this.#local(protectedHeader, token);
|
|
1504
|
+
} catch (err) {
|
|
1505
|
+
if (err instanceof JWKSNoMatchingKey) {
|
|
1506
|
+
if (this.coolingDown() === false) {
|
|
1507
|
+
await this.reload();
|
|
1508
|
+
return this.#local(protectedHeader, token);
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
throw err;
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
async reload() {
|
|
1515
|
+
if (this.#pendingFetch && isCloudflareWorkers()) this.#pendingFetch = void 0;
|
|
1516
|
+
this.#pendingFetch ||= fetchJwks(this.#url.href, this.#headers, AbortSignal.timeout(this.#timeoutDuration), this.#customFetch).then((json) => {
|
|
1517
|
+
this.#local = createLocalJWKSet(json);
|
|
1518
|
+
if (this.#cache) {
|
|
1519
|
+
this.#cache.uat = Date.now();
|
|
1520
|
+
this.#cache.jwks = json;
|
|
1521
|
+
}
|
|
1522
|
+
this.#jwksTimestamp = Date.now();
|
|
1523
|
+
this.#pendingFetch = void 0;
|
|
1524
|
+
}).catch((err) => {
|
|
1525
|
+
this.#pendingFetch = void 0;
|
|
1526
|
+
throw err;
|
|
1527
|
+
});
|
|
1528
|
+
await this.#pendingFetch;
|
|
1529
|
+
}
|
|
1530
|
+
};
|
|
1531
|
+
function createRemoteJWKSet(url, options) {
|
|
1532
|
+
const set = new RemoteJWKSet(url, options);
|
|
1533
|
+
const remoteJWKSet = async (protectedHeader, token) => set.getKey(protectedHeader, token);
|
|
1534
|
+
Object.defineProperties(remoteJWKSet, {
|
|
1535
|
+
coolingDown: {
|
|
1536
|
+
get: () => set.coolingDown(),
|
|
1537
|
+
enumerable: true,
|
|
1538
|
+
configurable: false
|
|
1539
|
+
},
|
|
1540
|
+
fresh: {
|
|
1541
|
+
get: () => set.fresh(),
|
|
1542
|
+
enumerable: true,
|
|
1543
|
+
configurable: false
|
|
1544
|
+
},
|
|
1545
|
+
reload: {
|
|
1546
|
+
value: () => set.reload(),
|
|
1547
|
+
enumerable: true,
|
|
1548
|
+
configurable: false,
|
|
1549
|
+
writable: false
|
|
1550
|
+
},
|
|
1551
|
+
reloading: {
|
|
1552
|
+
get: () => set.pendingFetch(),
|
|
1553
|
+
enumerable: true,
|
|
1554
|
+
configurable: false
|
|
1555
|
+
},
|
|
1556
|
+
jwks: {
|
|
1557
|
+
value: () => set.jwks(),
|
|
1558
|
+
enumerable: true,
|
|
1559
|
+
configurable: false,
|
|
1560
|
+
writable: false
|
|
1561
|
+
}
|
|
1562
|
+
});
|
|
1563
|
+
return remoteJWKSet;
|
|
1564
|
+
}
|
|
1565
|
+
|
|
155
1566
|
//#endregion
|
|
156
1567
|
//#region ../../src/security/providers/JwtProvider.ts
|
|
157
1568
|
/**
|
|
@@ -310,13 +1721,32 @@ var SecurityProvider = class {
|
|
|
310
1721
|
on: "start",
|
|
311
1722
|
handler: async () => {
|
|
312
1723
|
if (this.alepha.isProduction() && this.secretKey === DEFAULT_APP_SECRET) this.log.warn("Using default APP_SECRET in production is not recommended. Please set a strong APP_SECRET value.");
|
|
313
|
-
for (const realm of this.realms)
|
|
314
|
-
|
|
315
|
-
|
|
1724
|
+
for (const realm of this.realms) {
|
|
1725
|
+
if (realm.secret) {
|
|
1726
|
+
const secret = typeof realm.secret === "function" ? realm.secret() : realm.secret;
|
|
1727
|
+
this.jwt.setKeyLoader(realm.name, secret);
|
|
1728
|
+
}
|
|
1729
|
+
if (!realm.resolvers || realm.resolvers.length === 0) this.registerResolver(this.createDefaultJwtResolver(realm.name), realm.name);
|
|
316
1730
|
}
|
|
317
1731
|
}
|
|
318
1732
|
});
|
|
319
1733
|
/**
|
|
1734
|
+
* Creates a default JWT resolver for a realm.
|
|
1735
|
+
*/
|
|
1736
|
+
createDefaultJwtResolver(realmName) {
|
|
1737
|
+
return {
|
|
1738
|
+
priority: 100,
|
|
1739
|
+
onRequest: async (req) => {
|
|
1740
|
+
const auth = req.headers.authorization;
|
|
1741
|
+
if (!auth?.startsWith("Bearer ")) return null;
|
|
1742
|
+
const token = auth.slice(7);
|
|
1743
|
+
if (!token.includes(".")) return null;
|
|
1744
|
+
const { result } = await this.jwt.parse(token, realmName);
|
|
1745
|
+
return this.createUserFromPayload(result.payload, realmName);
|
|
1746
|
+
}
|
|
1747
|
+
};
|
|
1748
|
+
}
|
|
1749
|
+
/**
|
|
320
1750
|
* Adds a role to one or more realms.
|
|
321
1751
|
*
|
|
322
1752
|
* @param role
|
|
@@ -435,6 +1865,82 @@ var SecurityProvider = class {
|
|
|
435
1865
|
};
|
|
436
1866
|
}
|
|
437
1867
|
/**
|
|
1868
|
+
* Generic user creation from any source (JWT, API key, etc.).
|
|
1869
|
+
* Handles permission checking, ownership, default roles.
|
|
1870
|
+
*/
|
|
1871
|
+
createUser(userInfo, options = {}) {
|
|
1872
|
+
const realmRoles = this.getRoles(options.realm).filter((it) => it.default);
|
|
1873
|
+
const roles = [...userInfo.roles ?? []];
|
|
1874
|
+
for (const role of realmRoles) if (!roles.includes(role.name)) roles.push(role.name);
|
|
1875
|
+
let ownership;
|
|
1876
|
+
if (options.permission) {
|
|
1877
|
+
const check = this.checkPermission(options.permission, ...roles);
|
|
1878
|
+
if (!check.isAuthorized) throw new SecurityError(`User is not allowed to access '${this.permissionToString(options.permission)}'`);
|
|
1879
|
+
ownership = check.ownership;
|
|
1880
|
+
}
|
|
1881
|
+
return {
|
|
1882
|
+
...userInfo,
|
|
1883
|
+
roles,
|
|
1884
|
+
ownership,
|
|
1885
|
+
realm: options.realm
|
|
1886
|
+
};
|
|
1887
|
+
}
|
|
1888
|
+
/**
|
|
1889
|
+
* Register a resolver to a realm.
|
|
1890
|
+
* Resolvers are sorted by priority (lower = first).
|
|
1891
|
+
*/
|
|
1892
|
+
registerResolver(resolver, realmName) {
|
|
1893
|
+
const realm = this.getRealm(realmName);
|
|
1894
|
+
if (!realm.resolvers) realm.resolvers = [];
|
|
1895
|
+
realm.resolvers.push(resolver);
|
|
1896
|
+
realm.resolvers.sort((a, b) => (a.priority ?? 100) - (b.priority ?? 100));
|
|
1897
|
+
}
|
|
1898
|
+
/**
|
|
1899
|
+
* Get a realm by name.
|
|
1900
|
+
* Throws if realm not found.
|
|
1901
|
+
*/
|
|
1902
|
+
getRealm(realmName) {
|
|
1903
|
+
const realm = realmName ? this.realms.find((it) => it.name === realmName) : this.realms[0];
|
|
1904
|
+
if (!realm) throw new RealmNotFoundError(realmName ?? "default");
|
|
1905
|
+
return realm;
|
|
1906
|
+
}
|
|
1907
|
+
/**
|
|
1908
|
+
* Resolve user from request using registered resolvers.
|
|
1909
|
+
* Returns undefined if no resolver could authenticate (no auth provided).
|
|
1910
|
+
* Throws UnauthorizedError if auth was provided but invalid.
|
|
1911
|
+
*
|
|
1912
|
+
* Note: This method tries resolvers from ALL realms to find a match,
|
|
1913
|
+
* regardless of the `realm` option. The `realm` option is only used for
|
|
1914
|
+
* permission checking after the user is resolved.
|
|
1915
|
+
*/
|
|
1916
|
+
async resolveUserFromServerRequest(req, options = {}) {
|
|
1917
|
+
const allResolvers = [];
|
|
1918
|
+
for (const realm of this.realms) for (const resolver of realm.resolvers ?? []) allResolvers.push({
|
|
1919
|
+
resolver,
|
|
1920
|
+
realmName: realm.name
|
|
1921
|
+
});
|
|
1922
|
+
allResolvers.sort((a, b) => (a.resolver.priority ?? 100) - (b.resolver.priority ?? 100));
|
|
1923
|
+
for (const { resolver, realmName } of allResolvers) {
|
|
1924
|
+
let userInfo;
|
|
1925
|
+
try {
|
|
1926
|
+
userInfo = await resolver.onRequest(req);
|
|
1927
|
+
} catch {
|
|
1928
|
+
continue;
|
|
1929
|
+
}
|
|
1930
|
+
if (userInfo) {
|
|
1931
|
+
const user = this.createUser(userInfo, {
|
|
1932
|
+
realm: realmName,
|
|
1933
|
+
permission: options.permission
|
|
1934
|
+
});
|
|
1935
|
+
await this.alepha.events.emit("security:user:created", {
|
|
1936
|
+
realm: realmName,
|
|
1937
|
+
user
|
|
1938
|
+
});
|
|
1939
|
+
return user;
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
/**
|
|
438
1944
|
* Checks if the user has the specified permission.
|
|
439
1945
|
*
|
|
440
1946
|
* Bonus: we check also if the user has "ownership" flag.
|
|
@@ -444,12 +1950,12 @@ var SecurityProvider = class {
|
|
|
444
1950
|
*/
|
|
445
1951
|
checkPermission(permissionLike, ...roleEntries) {
|
|
446
1952
|
const roles = roleEntries.map((it) => {
|
|
447
|
-
const role = this.getRoles().find((role
|
|
1953
|
+
const role = this.getRoles().find((role) => role.name === it);
|
|
448
1954
|
if (!role) throw new SecurityError(`Role '${it}' not found`);
|
|
449
1955
|
return role;
|
|
450
1956
|
});
|
|
451
1957
|
const permission = this.permissionToString(permissionLike);
|
|
452
|
-
if (roles.find((it) => it.permissions.find((it
|
|
1958
|
+
if (roles.find((it) => it.permissions.find((it) => it.name === "*" && !it.exclude && !it.ownership))) return {
|
|
453
1959
|
isAuthorized: true,
|
|
454
1960
|
ownership: false
|
|
455
1961
|
};
|
|
@@ -696,7 +2202,7 @@ var IssuerPrimitive = class extends Primitive {
|
|
|
696
2202
|
onInit() {
|
|
697
2203
|
const roles = this.options.roles?.map((it) => {
|
|
698
2204
|
if (typeof it === "string") {
|
|
699
|
-
const role = this.getRoles().find((role
|
|
2205
|
+
const role = this.getRoles().find((role) => role.name === it);
|
|
700
2206
|
if (!role) throw new SecurityError(`Role '${it}' not found`);
|
|
701
2207
|
return role;
|
|
702
2208
|
}
|
|
@@ -706,8 +2212,34 @@ var IssuerPrimitive = class extends Primitive {
|
|
|
706
2212
|
name: this.name,
|
|
707
2213
|
profile: this.options.profile,
|
|
708
2214
|
secret: "jwks" in this.options ? this.options.jwks : this.options.secret,
|
|
709
|
-
roles
|
|
2215
|
+
roles,
|
|
2216
|
+
resolvers: []
|
|
710
2217
|
});
|
|
2218
|
+
for (const resolver of this.options.resolvers ?? []) this.registerResolver(resolver);
|
|
2219
|
+
this.registerResolver(this.createJwtResolver());
|
|
2220
|
+
}
|
|
2221
|
+
/**
|
|
2222
|
+
* Creates the default JWT resolver.
|
|
2223
|
+
*/
|
|
2224
|
+
createJwtResolver() {
|
|
2225
|
+
return {
|
|
2226
|
+
priority: 100,
|
|
2227
|
+
onRequest: async (req) => {
|
|
2228
|
+
const auth = req.headers.authorization;
|
|
2229
|
+
if (!auth?.startsWith("Bearer ")) return null;
|
|
2230
|
+
const token = auth.slice(7);
|
|
2231
|
+
if (!token.includes(".")) return null;
|
|
2232
|
+
const { result } = await this.jwt.parse(token, this.name);
|
|
2233
|
+
return this.securityProvider.createUserFromPayload(result.payload, this.name);
|
|
2234
|
+
}
|
|
2235
|
+
};
|
|
2236
|
+
}
|
|
2237
|
+
/**
|
|
2238
|
+
* Register a resolver to this issuer.
|
|
2239
|
+
* Resolvers are sorted by priority (lower = first).
|
|
2240
|
+
*/
|
|
2241
|
+
registerResolver(resolver) {
|
|
2242
|
+
this.securityProvider.registerResolver(resolver, this.name);
|
|
711
2243
|
}
|
|
712
2244
|
/**
|
|
713
2245
|
* Get all roles in the issuer.
|
|
@@ -746,8 +2278,8 @@ var IssuerPrimitive = class extends Primitive {
|
|
|
746
2278
|
const create = this.options.settings?.onCreateSession;
|
|
747
2279
|
if (create) {
|
|
748
2280
|
const expiresIn = this.refreshTokenExpiration.asSeconds();
|
|
749
|
-
const { refreshToken
|
|
750
|
-
refresh_token = refreshToken
|
|
2281
|
+
const { refreshToken, sessionId } = await create(user, { expiresIn });
|
|
2282
|
+
refresh_token = refreshToken;
|
|
751
2283
|
refresh_token_expires_in = expiresIn;
|
|
752
2284
|
sid = sessionId;
|
|
753
2285
|
} else {
|
|
@@ -792,13 +2324,13 @@ var IssuerPrimitive = class extends Primitive {
|
|
|
792
2324
|
}
|
|
793
2325
|
async refreshToken(refreshToken, accessToken) {
|
|
794
2326
|
if (this.options.settings?.onRefreshSession) {
|
|
795
|
-
const { user
|
|
2327
|
+
const { user, expiresIn, sessionId } = await this.options.settings.onRefreshSession(refreshToken);
|
|
796
2328
|
return {
|
|
797
|
-
user
|
|
798
|
-
tokens: await this.createToken(user
|
|
2329
|
+
user,
|
|
2330
|
+
tokens: await this.createToken(user, {
|
|
799
2331
|
sid: sessionId,
|
|
800
2332
|
refresh_token: refreshToken,
|
|
801
|
-
refresh_token_expires_in: expiresIn
|
|
2333
|
+
refresh_token_expires_in: expiresIn
|
|
802
2334
|
})
|
|
803
2335
|
};
|
|
804
2336
|
}
|
|
@@ -952,6 +2484,7 @@ var ServerSecurityProvider = class {
|
|
|
952
2484
|
securityProvider = $inject(SecurityProvider);
|
|
953
2485
|
jwtProvider = $inject(JwtProvider);
|
|
954
2486
|
alepha = $inject(Alepha);
|
|
2487
|
+
resolvers = [];
|
|
955
2488
|
onConfigure = $hook({
|
|
956
2489
|
on: "configure",
|
|
957
2490
|
handler: async () => {
|
|
@@ -996,15 +2529,23 @@ var ServerSecurityProvider = class {
|
|
|
996
2529
|
}
|
|
997
2530
|
if (isBasicAuth(route.secure)) return;
|
|
998
2531
|
const permission = this.securityProvider.getPermissions().find((it) => it.path === route.path && it.method === route.method);
|
|
999
|
-
|
|
1000
|
-
this.log.trace("Skipping security check for route - no authorization header and not secure");
|
|
1001
|
-
return;
|
|
1002
|
-
}
|
|
2532
|
+
const realm = typeof route.secure === "object" ? route.secure.realm : void 0;
|
|
1003
2533
|
try {
|
|
1004
|
-
request.user = await this.securityProvider.
|
|
2534
|
+
request.user = await this.securityProvider.resolveUserFromServerRequest(request, {
|
|
2535
|
+
permission,
|
|
2536
|
+
realm
|
|
2537
|
+
});
|
|
2538
|
+
if (!request.user) {
|
|
2539
|
+
if (route.secure || permission) {
|
|
2540
|
+
if (!request.headers.authorization) throw new InvalidTokenError("Invalid authorization header, maybe token is missing ?");
|
|
2541
|
+
throw new UnauthorizedError("Authentication required");
|
|
2542
|
+
}
|
|
2543
|
+
this.log.trace("Skipping security check for route - no auth provided and not required");
|
|
2544
|
+
return;
|
|
2545
|
+
}
|
|
1005
2546
|
if (typeof route.secure === "object") this.check(request.user, route.secure);
|
|
1006
2547
|
this.alepha.store.set("alepha.server.request.user", this.alepha.codec.decode(userAccountInfoSchema, request.user));
|
|
1007
|
-
this.log.trace("User set from request
|
|
2548
|
+
this.log.trace("User set from request", {
|
|
1008
2549
|
user: request.user,
|
|
1009
2550
|
permission
|
|
1010
2551
|
});
|
|
@@ -1039,11 +2580,8 @@ var ServerSecurityProvider = class {
|
|
|
1039
2580
|
if (type === "system") user = fromSystem;
|
|
1040
2581
|
else if (type === "context") user = fromContext;
|
|
1041
2582
|
else user = fromOptions ?? fromContext ?? fromSystem;
|
|
1042
|
-
if (!user)
|
|
1043
|
-
|
|
1044
|
-
throw new UnauthorizedError("User is required for calling this action");
|
|
1045
|
-
}
|
|
1046
|
-
const roles = user.roles ?? (this.alepha.isTest() ? this.securityProvider.getRoles().map((role) => role.name) : []);
|
|
2583
|
+
if (!user) throw new UnauthorizedError("User is required for calling this action");
|
|
2584
|
+
const roles = user.roles ?? [];
|
|
1047
2585
|
let ownership;
|
|
1048
2586
|
if (permission) {
|
|
1049
2587
|
const result = this.securityProvider.checkPermission(permission, ...roles);
|
|
@@ -1066,7 +2604,7 @@ var ServerSecurityProvider = class {
|
|
|
1066
2604
|
on: "client:onRequest",
|
|
1067
2605
|
handler: async ({ request, options }) => {
|
|
1068
2606
|
if (!this.alepha.isTest()) return;
|
|
1069
|
-
if (
|
|
2607
|
+
if (!options.user) return;
|
|
1070
2608
|
request.headers = new Headers(request.headers);
|
|
1071
2609
|
if (!request.headers.has("authorization")) {
|
|
1072
2610
|
const test = this.createTestUser();
|
|
@@ -1224,19 +2762,23 @@ const roleSchema = t.object({
|
|
|
1224
2762
|
//#endregion
|
|
1225
2763
|
//#region ../../src/security/index.ts
|
|
1226
2764
|
/**
|
|
1227
|
-
*
|
|
2765
|
+
* | type | quality | stability |
|
|
2766
|
+
* |------|---------|-----------|
|
|
2767
|
+
* | backend | epic | stable |
|
|
1228
2768
|
*
|
|
1229
|
-
*
|
|
1230
|
-
* on class properties. It offers JWT-based authentication, fine-grained permissions, service accounts, and seamless
|
|
1231
|
-
* integration with various authentication providers and user management systems.
|
|
2769
|
+
* Complete authentication and authorization system with JWT, RBAC, and multi-issuer support.
|
|
1232
2770
|
*
|
|
1233
|
-
*
|
|
1234
|
-
*
|
|
2771
|
+
* **Features:**
|
|
2772
|
+
* - JWT token issuer with role definitions
|
|
2773
|
+
* - Role-based access control (RBAC)
|
|
2774
|
+
* - Fine-grained permissions
|
|
2775
|
+
* - HTTP Basic Authentication
|
|
2776
|
+
* - Service-to-service authentication
|
|
2777
|
+
* - Multi-issuer support for federated auth
|
|
2778
|
+
* - JWKS (JSON Web Key Set) for external issuers
|
|
2779
|
+
* - Token refresh logic
|
|
2780
|
+
* - User profile extraction from JWT
|
|
1235
2781
|
*
|
|
1236
|
-
* @see {@link $issuer}
|
|
1237
|
-
* @see {@link $role}
|
|
1238
|
-
* @see {@link $permission}
|
|
1239
|
-
* @see {@link $basicAuth}
|
|
1240
2782
|
* @module alepha.security
|
|
1241
2783
|
*/
|
|
1242
2784
|
const AlephaSecurity = $module({
|