@rebasepro/server-core 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/api/ast-schema-editor.d.ts +21 -0
- package/dist/api/collections_for_test/callbacks_test_collection.d.ts +2 -0
- package/dist/api/errors.d.ts +53 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/logs-routes.d.ts +37 -0
- package/dist/api/openapi-generator.d.ts +16 -0
- package/dist/api/rest/api-generator.d.ts +68 -0
- package/{src/api/rest/index.ts → dist/api/rest/index.d.ts} +0 -1
- package/dist/api/rest/query-parser.d.ts +6 -0
- package/dist/api/schema-editor-routes.d.ts +3 -0
- package/dist/api/types.d.ts +56 -0
- package/dist/auth/adapter-middleware.d.ts +43 -0
- package/dist/auth/admin-roles-route.d.ts +18 -0
- package/dist/auth/admin-user-ops.d.ts +79 -0
- package/dist/auth/admin-users-route.d.ts +28 -0
- package/dist/auth/api-keys/api-key-middleware.d.ts +39 -0
- package/{src/auth/api-keys/api-key-permission-guard.ts → dist/auth/api-keys/api-key-permission-guard.d.ts} +2 -34
- package/dist/auth/api-keys/api-key-routes.d.ts +20 -0
- package/dist/auth/api-keys/api-key-store.d.ts +35 -0
- package/{src/auth/api-keys/api-key-types.ts → dist/auth/api-keys/api-key-types.d.ts} +0 -6
- package/{src/auth/api-keys/index.ts → dist/auth/api-keys/index.d.ts} +2 -22
- package/dist/auth/apple-oauth.d.ts +30 -0
- package/{src/auth/auth-hooks.ts → dist/auth/auth-hooks.d.ts} +15 -73
- package/dist/auth/bitbucket-oauth.d.ts +11 -0
- package/dist/auth/builtin-auth-adapter.d.ts +55 -0
- package/dist/auth/cookie-utils.d.ts +32 -0
- package/{src/auth/crypto-utils.ts → dist/auth/crypto-utils.d.ts} +1 -16
- package/dist/auth/custom-auth-adapter.d.ts +39 -0
- package/dist/auth/discord-oauth.d.ts +14 -0
- package/dist/auth/facebook-oauth.d.ts +14 -0
- package/dist/auth/github-oauth.d.ts +15 -0
- package/dist/auth/gitlab-oauth.d.ts +13 -0
- package/dist/auth/google-oauth.d.ts +47 -0
- package/{src/auth/index.ts → dist/auth/index.d.ts} +4 -22
- package/{src/auth/interfaces.ts → dist/auth/interfaces.d.ts} +20 -89
- package/dist/auth/jwt.d.ts +67 -0
- package/dist/auth/linkedin-oauth.d.ts +18 -0
- package/dist/auth/magic-link-routes.d.ts +32 -0
- package/dist/auth/mfa-crypto.d.ts +23 -0
- package/dist/auth/mfa-routes.d.ts +7 -0
- package/dist/auth/mfa.d.ts +49 -0
- package/dist/auth/microsoft-oauth.d.ts +16 -0
- package/dist/auth/middleware.d.ts +158 -0
- package/dist/auth/password.d.ts +22 -0
- package/dist/auth/rate-limiter.d.ts +50 -0
- package/dist/auth/reset-password-admin.d.ts +29 -0
- package/dist/auth/rls-scope.d.ts +31 -0
- package/dist/auth/routes.d.ts +66 -0
- package/dist/auth/session-routes.d.ts +29 -0
- package/dist/auth/slack-oauth.d.ts +12 -0
- package/dist/auth/spotify-oauth.d.ts +12 -0
- package/dist/auth/twitter-oauth.d.ts +18 -0
- package/dist/collections/BackendCollectionRegistry.d.ts +13 -0
- package/dist/collections/loader.d.ts +5 -0
- package/dist/cron/cron-loader.d.ts +18 -0
- package/dist/cron/cron-routes.d.ts +14 -0
- package/dist/cron/cron-scheduler.d.ts +106 -0
- package/dist/cron/cron-store.d.ts +32 -0
- package/dist/cron/define-cron.d.ts +28 -0
- package/{src/cron/index.ts → dist/cron/index.d.ts} +1 -0
- package/dist/db/interfaces.d.ts +18 -0
- package/dist/dynamic-import-Dvh-K5fl.js +22 -0
- package/dist/dynamic-import-Dvh-K5fl.js.map +1 -0
- package/dist/email/index.d.ts +6 -0
- package/dist/email/smtp-email-service.d.ts +30 -0
- package/dist/email/templates.d.ts +50 -0
- package/{src/email/types.ts → dist/email/types.d.ts} +40 -36
- package/dist/env.d.ts +102 -0
- package/dist/functions/define-function.d.ts +55 -0
- package/dist/functions/function-loader.d.ts +18 -0
- package/dist/functions/function-routes.d.ts +10 -0
- package/{src/functions/index.ts → dist/functions/index.d.ts} +2 -0
- package/dist/history/history-routes.d.ts +23 -0
- package/{src/history/index.ts → dist/history/index.d.ts} +0 -1
- package/dist/index.d.ts +35 -0
- package/dist/index.es.js +18184 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +48629 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/init/docs.d.ts +4 -0
- package/dist/init/health.d.ts +2 -0
- package/dist/init/middlewares.d.ts +10 -0
- package/dist/init/shutdown.d.ts +65 -0
- package/dist/init/storage.d.ts +5 -0
- package/dist/init.d.ts +344 -0
- package/dist/jwt-BwIn8xmk.js +4200 -0
- package/dist/jwt-BwIn8xmk.js.map +1 -0
- package/dist/logger-BYU66ENZ.js +94 -0
- package/dist/logger-BYU66ENZ.js.map +1 -0
- package/dist/ms-DnYXB-Wd.js +162 -0
- package/dist/ms-DnYXB-Wd.js.map +1 -0
- package/dist/openapi-generator-Z9oYWLf_.js +586 -0
- package/dist/openapi-generator-Z9oYWLf_.js.map +1 -0
- package/dist/schema-editor-routes-D3ef8zu1.js +219 -0
- package/dist/schema-editor-routes-D3ef8zu1.js.map +1 -0
- package/dist/serve-spa.d.ts +36 -0
- package/dist/services/driver-registry.d.ts +78 -0
- package/dist/services/routed-realtime-service.d.ts +43 -0
- package/dist/services/webhook-service.d.ts +29 -0
- package/dist/singleton.d.ts +51 -0
- package/dist/src-B4OLmNVa.js +437 -0
- package/dist/src-B4OLmNVa.js.map +1 -0
- package/dist/src-B5WkP1Rv.js +24778 -0
- package/dist/src-B5WkP1Rv.js.map +1 -0
- package/dist/storage/GCSStorageController.d.ts +43 -0
- package/dist/storage/LocalStorageController.d.ts +46 -0
- package/dist/storage/S3StorageController.d.ts +40 -0
- package/dist/storage/image-transform.d.ts +50 -0
- package/{src/storage/index.ts → dist/storage/index.d.ts} +6 -21
- package/dist/storage/routes.d.ts +70 -0
- package/dist/storage/storage-registry.d.ts +78 -0
- package/dist/storage/tus-handler.d.ts +53 -0
- package/{src/storage/types.ts → dist/storage/types.d.ts} +32 -38
- package/dist/types/index.d.ts +11 -0
- package/dist/utils/dev-port.d.ts +45 -0
- package/dist/utils/dynamic-import.d.ts +25 -0
- package/dist/utils/logger.d.ts +31 -0
- package/dist/utils/logging.d.ts +9 -0
- package/dist/utils/request-id.d.ts +4 -0
- package/dist/utils/request-logger.d.ts +19 -0
- package/{src/utils/sql.ts → dist/utils/sql.d.ts} +5 -16
- package/package.json +49 -22
- package/coverage/clover.xml +0 -3739
- package/coverage/coverage-final.json +0 -31
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -266
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov-report/src/api/ast-schema-editor.ts.html +0 -952
- package/coverage/lcov-report/src/api/errors.ts.html +0 -472
- package/coverage/lcov-report/src/api/graphql/graphql-schema-generator.ts.html +0 -1069
- package/coverage/lcov-report/src/api/graphql/index.html +0 -116
- package/coverage/lcov-report/src/api/index.html +0 -176
- package/coverage/lcov-report/src/api/openapi-generator.ts.html +0 -565
- package/coverage/lcov-report/src/api/rest/api-generator.ts.html +0 -994
- package/coverage/lcov-report/src/api/rest/index.html +0 -131
- package/coverage/lcov-report/src/api/rest/query-parser.ts.html +0 -550
- package/coverage/lcov-report/src/api/schema-editor-routes.ts.html +0 -202
- package/coverage/lcov-report/src/api/server.ts.html +0 -823
- package/coverage/lcov-report/src/auth/admin-routes.ts.html +0 -973
- package/coverage/lcov-report/src/auth/index.html +0 -176
- package/coverage/lcov-report/src/auth/jwt.ts.html +0 -574
- package/coverage/lcov-report/src/auth/middleware.ts.html +0 -745
- package/coverage/lcov-report/src/auth/password.ts.html +0 -310
- package/coverage/lcov-report/src/auth/services.ts.html +0 -2074
- package/coverage/lcov-report/src/collections/index.html +0 -116
- package/coverage/lcov-report/src/collections/loader.ts.html +0 -232
- package/coverage/lcov-report/src/db/auth-schema.ts.html +0 -523
- package/coverage/lcov-report/src/db/data-transformer.ts.html +0 -1753
- package/coverage/lcov-report/src/db/entityService.ts.html +0 -700
- package/coverage/lcov-report/src/db/index.html +0 -146
- package/coverage/lcov-report/src/db/services/EntityFetchService.ts.html +0 -4048
- package/coverage/lcov-report/src/db/services/EntityPersistService.ts.html +0 -883
- package/coverage/lcov-report/src/db/services/RelationService.ts.html +0 -3121
- package/coverage/lcov-report/src/db/services/entity-helpers.ts.html +0 -442
- package/coverage/lcov-report/src/db/services/index.html +0 -176
- package/coverage/lcov-report/src/db/services/index.ts.html +0 -124
- package/coverage/lcov-report/src/generate-drizzle-schema-logic.ts.html +0 -1960
- package/coverage/lcov-report/src/index.html +0 -116
- package/coverage/lcov-report/src/services/driver-registry.ts.html +0 -631
- package/coverage/lcov-report/src/services/index.html +0 -131
- package/coverage/lcov-report/src/services/postgresDataDriver.ts.html +0 -3025
- package/coverage/lcov-report/src/storage/LocalStorageController.ts.html +0 -1189
- package/coverage/lcov-report/src/storage/S3StorageController.ts.html +0 -970
- package/coverage/lcov-report/src/storage/index.html +0 -161
- package/coverage/lcov-report/src/storage/storage-registry.ts.html +0 -646
- package/coverage/lcov-report/src/storage/types.ts.html +0 -451
- package/coverage/lcov-report/src/utils/drizzle-conditions.ts.html +0 -3082
- package/coverage/lcov-report/src/utils/index.html +0 -116
- package/coverage/lcov.info +0 -7179
- package/jest.config.cjs +0 -19
- package/src/api/ast-schema-editor.ts +0 -289
- package/src/api/collections_for_test/callbacks_test_collection.ts +0 -61
- package/src/api/errors.ts +0 -278
- package/src/api/graphql/graphql-schema-generator.ts +0 -383
- package/src/api/graphql/index.ts +0 -2
- package/src/api/index.ts +0 -11
- package/src/api/logs-routes.ts +0 -132
- package/src/api/openapi-generator.ts +0 -727
- package/src/api/rest/api-generator-count.test.ts +0 -126
- package/src/api/rest/api-generator.ts +0 -747
- package/src/api/rest/query-parser.ts +0 -300
- package/src/api/schema-editor-routes.ts +0 -41
- package/src/api/server.ts +0 -271
- package/src/api/types.ts +0 -104
- package/src/auth/adapter-middleware.ts +0 -114
- package/src/auth/admin-roles-route.ts +0 -36
- package/src/auth/admin-user-ops.ts +0 -236
- package/src/auth/admin-users-route.ts +0 -302
- package/src/auth/api-keys/api-key-middleware.ts +0 -133
- package/src/auth/api-keys/api-key-routes.ts +0 -193
- package/src/auth/api-keys/api-key-store.ts +0 -340
- package/src/auth/apple-oauth.ts +0 -122
- package/src/auth/bitbucket-oauth.ts +0 -84
- package/src/auth/builtin-auth-adapter.ts +0 -380
- package/src/auth/custom-auth-adapter.ts +0 -86
- package/src/auth/discord-oauth.ts +0 -85
- package/src/auth/facebook-oauth.ts +0 -74
- package/src/auth/github-oauth.ts +0 -112
- package/src/auth/gitlab-oauth.ts +0 -72
- package/src/auth/google-oauth.ts +0 -223
- package/src/auth/jwt.ts +0 -208
- package/src/auth/linkedin-oauth.ts +0 -83
- package/src/auth/magic-link-routes.ts +0 -167
- package/src/auth/mfa-crypto.ts +0 -91
- package/src/auth/mfa-routes.ts +0 -323
- package/src/auth/mfa.ts +0 -161
- package/src/auth/microsoft-oauth.ts +0 -90
- package/src/auth/middleware.ts +0 -369
- package/src/auth/password.ts +0 -77
- package/src/auth/rate-limiter.ts +0 -225
- package/src/auth/reset-password-admin.ts +0 -160
- package/src/auth/rls-scope.ts +0 -58
- package/src/auth/routes.ts +0 -802
- package/src/auth/session-routes.ts +0 -353
- package/src/auth/slack-oauth.ts +0 -73
- package/src/auth/spotify-oauth.ts +0 -69
- package/src/auth/twitter-oauth.ts +0 -128
- package/src/collections/BackendCollectionRegistry.ts +0 -20
- package/src/collections/loader.ts +0 -50
- package/src/cron/cron-loader.ts +0 -84
- package/src/cron/cron-routes.test.ts +0 -265
- package/src/cron/cron-routes.ts +0 -85
- package/src/cron/cron-scheduler.test.ts +0 -559
- package/src/cron/cron-scheduler.ts +0 -581
- package/src/cron/cron-store.ts +0 -166
- package/src/db/interfaces.ts +0 -60
- package/src/email/index.ts +0 -19
- package/src/email/smtp-email-service.ts +0 -123
- package/src/email/templates.ts +0 -470
- package/src/env.ts +0 -227
- package/src/functions/function-loader.ts +0 -116
- package/src/functions/function-routes.ts +0 -31
- package/src/history/history-routes.ts +0 -129
- package/src/index.ts +0 -70
- package/src/init/docs.ts +0 -47
- package/src/init/health.ts +0 -37
- package/src/init/middlewares.ts +0 -61
- package/src/init/shutdown.ts +0 -56
- package/src/init/storage.ts +0 -57
- package/src/init.ts +0 -1041
- package/src/serve-spa.ts +0 -89
- package/src/services/driver-registry.ts +0 -183
- package/src/services/routed-realtime-service.ts +0 -113
- package/src/services/webhook-service.ts +0 -155
- package/src/singleton.ts +0 -70
- package/src/storage/LocalStorageController.ts +0 -389
- package/src/storage/S3StorageController.ts +0 -300
- package/src/storage/image-transform.ts +0 -218
- package/src/storage/routes.ts +0 -368
- package/src/storage/storage-registry.ts +0 -188
- package/src/storage/tus-handler.ts +0 -315
- package/src/types/index.ts +0 -27
- package/src/utils/dev-port.ts +0 -196
- package/src/utils/logger.ts +0 -143
- package/src/utils/logging.ts +0 -40
- package/src/utils/request-id.ts +0 -40
- package/src/utils/request-logger.ts +0 -72
- package/test/api-generator.test.ts +0 -588
- package/test/api-key-permission-guard.test.ts +0 -144
- package/test/ast-schema-editor.test.ts +0 -89
- package/test/auth-middleware-hono.test.ts +0 -556
- package/test/auth-routes.test.ts +0 -1098
- package/test/backend-hooks-data.test.ts +0 -477
- package/test/custom-auth-adapter.test.ts +0 -189
- package/test/driver-registry.test.ts +0 -282
- package/test/email-templates.test.ts +0 -174
- package/test/env.test.ts +0 -128
- package/test/error-propagation.test.ts +0 -226
- package/test/errors-hono.test.ts +0 -133
- package/test/errors.test.ts +0 -155
- package/test/function-loader.test.ts +0 -127
- package/test/graphql-schema-generator.test.ts +0 -554
- package/test/jwt-security.test.ts +0 -182
- package/test/jwt.test.ts +0 -326
- package/test/mfa.test.ts +0 -197
- package/test/middleware.test.ts +0 -305
- package/test/multi-datasource-routing.test.ts +0 -113
- package/test/password.test.ts +0 -165
- package/test/query-parser.test.ts +0 -233
- package/test/rate-limiter.test.ts +0 -102
- package/test/reset-password-admin.test.ts +0 -113
- package/test/routed-realtime-service.test.ts +0 -86
- package/test/safe-compare.test.ts +0 -66
- package/test/singleton.test.ts +0 -59
- package/test/smtp-email-service.test.ts +0 -169
- package/test/storage-local.test.ts +0 -271
- package/test/storage-registry.test.ts +0 -282
- package/test/storage-routes.test.ts +0 -222
- package/test/storage-s3.test.ts +0 -304
- package/test/transform-auth-response.test.ts +0 -305
- package/test/webhook-service.test.ts +0 -260
- package/tsconfig.json +0 -54
- package/tsconfig.prod.json +0 -23
- package/vite.config.ts +0 -86
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
// Auth module exports
|
|
2
1
|
export * from "./interfaces";
|
|
3
|
-
|
|
4
|
-
export {
|
|
5
|
-
export type { JwtConfig, AccessTokenPayload } from "./jwt";
|
|
6
|
-
|
|
2
|
+
export { configureJwt, generateAccessToken, verifyAccessToken, generateRefreshToken, hashRefreshToken, getRefreshTokenExpiry, getAccessTokenExpiry, generateDownloadToken, verifyDownloadToken } from "./jwt";
|
|
3
|
+
export type { JwtConfig, AccessTokenPayload, DownloadTokenPayload } from "./jwt";
|
|
7
4
|
export { hashPassword, verifyPassword, validatePasswordStrength } from "./password";
|
|
8
5
|
export type { PasswordValidationResult } from "./password";
|
|
9
|
-
|
|
10
6
|
export type { AuthHooks, AuthMethod, ResolvedAuthHooks } from "./auth-hooks";
|
|
11
7
|
export { resolveAuthHooks } from "./auth-hooks";
|
|
12
|
-
|
|
13
8
|
export { generateSecurePassword, generateSecureToken, hashToken, prepareAdminUserValues, finalizeAdminUserCreation } from "./admin-user-ops";
|
|
14
9
|
export type { AdminUserContext, AdminUserPrepareResult } from "./admin-user-ops";
|
|
15
|
-
|
|
16
|
-
// OAuth Providers
|
|
17
10
|
export { createGoogleProvider } from "./google-oauth";
|
|
18
11
|
export type { GoogleProviderConfig } from "./google-oauth";
|
|
19
12
|
export { createLinkedinProvider } from "./linkedin-oauth";
|
|
@@ -27,27 +20,16 @@ export { createGitLabProvider } from "./gitlab-oauth";
|
|
|
27
20
|
export { createBitbucketProvider } from "./bitbucket-oauth";
|
|
28
21
|
export { createSlackProvider } from "./slack-oauth";
|
|
29
22
|
export { createSpotifyProvider } from "./spotify-oauth";
|
|
30
|
-
|
|
31
|
-
export { requireAuth, requireAdmin, optionalAuth, extractUserFromToken, createAuthMiddleware } from "./middleware";
|
|
23
|
+
export { requireAuth, requireAdmin, optionalAuth, extractUserFromToken, createAuthMiddleware, queryTokenAuth, fileTokenAuth } from "./middleware";
|
|
32
24
|
export type { AuthMiddlewareOptions, AuthResult } from "./middleware";
|
|
33
|
-
|
|
34
|
-
|
|
35
25
|
export { createAuthRoutes } from "./routes";
|
|
36
|
-
export type { AuthModuleConfig } from "./routes";
|
|
37
|
-
|
|
26
|
+
export type { AuthModuleConfig, CookieAuthConfig } from "./routes";
|
|
38
27
|
export { mountMagicLinkRoutes } from "./magic-link-routes";
|
|
39
|
-
|
|
40
28
|
export { createResetPasswordRoute } from "./reset-password-admin";
|
|
41
29
|
export type { ResetPasswordRouteConfig } from "./reset-password-admin";
|
|
42
|
-
|
|
43
|
-
|
|
44
30
|
export { createRateLimiter, defaultAuthLimiter, strictAuthLimiter, createApiKeyRateLimiter, apiKeyKeyGenerator } from "./rate-limiter";
|
|
45
|
-
|
|
46
|
-
// API Keys
|
|
47
31
|
export { createApiKeyStore, createApiKeyRoutes, isApiKeyToken, validateApiKey, httpMethodToOperation, isOperationAllowed } from "./api-keys";
|
|
48
32
|
export type { ApiKey, ApiKeyMasked, ApiKeyPermission, ApiKeyWithSecret, CreateApiKeyRequest, UpdateApiKeyRequest, ApiKeyStore, ApiKeyOperation } from "./api-keys";
|
|
49
|
-
|
|
50
|
-
// Auth Adapters
|
|
51
33
|
export { createBuiltinAuthAdapter } from "./builtin-auth-adapter";
|
|
52
34
|
export type { BuiltinAuthAdapterConfig } from "./builtin-auth-adapter";
|
|
53
35
|
export { createCustomAuthAdapter } from "./custom-auth-adapter";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* Authentication Abstraction Interfaces
|
|
5
4
|
*
|
|
@@ -7,7 +6,6 @@ import { z } from "zod";
|
|
|
7
6
|
* Implementations can use different databases (PostgreSQL, MongoDB, etc.) to
|
|
8
7
|
* store user, role, and token data.
|
|
9
8
|
*/
|
|
10
|
-
|
|
11
9
|
/**
|
|
12
10
|
* User data structure
|
|
13
11
|
*/
|
|
@@ -25,7 +23,6 @@ export interface UserData {
|
|
|
25
23
|
createdAt: Date;
|
|
26
24
|
updatedAt: Date;
|
|
27
25
|
}
|
|
28
|
-
|
|
29
26
|
/**
|
|
30
27
|
* Data for creating a new user
|
|
31
28
|
*/
|
|
@@ -38,7 +35,6 @@ export interface CreateUserData {
|
|
|
38
35
|
isAnonymous?: boolean;
|
|
39
36
|
metadata?: Record<string, unknown>;
|
|
40
37
|
}
|
|
41
|
-
|
|
42
38
|
/**
|
|
43
39
|
* User Identity Data (OAuth accounts linked to user)
|
|
44
40
|
*/
|
|
@@ -51,7 +47,6 @@ export interface UserIdentityData {
|
|
|
51
47
|
createdAt: Date;
|
|
52
48
|
updatedAt: Date;
|
|
53
49
|
}
|
|
54
|
-
|
|
55
50
|
/**
|
|
56
51
|
* Standardized profile data returned by an OAuth provider verification payload
|
|
57
52
|
*/
|
|
@@ -63,21 +58,26 @@ export interface OAuthProviderProfile {
|
|
|
63
58
|
/** Whether the OAuth provider has verified the user's email address */
|
|
64
59
|
emailVerified?: boolean;
|
|
65
60
|
}
|
|
66
|
-
|
|
67
61
|
/**
|
|
68
62
|
* Pluggable OAuth Provider integration strategy
|
|
69
63
|
*/
|
|
70
64
|
export interface OAuthProvider<T = unknown> {
|
|
71
65
|
/** The identifier of the provider (e.g. "github", "google") */
|
|
72
66
|
id: string;
|
|
73
|
-
|
|
74
67
|
/** Zod schema validating the expected request payload (e.g. { code: string }) */
|
|
75
68
|
schema: z.ZodSchema<T>;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Verify external tokens/codes and return a standardized user profile.
|
|
71
|
+
*
|
|
72
|
+
* NOTE: Declared as method syntax (not arrow property) intentionally.
|
|
73
|
+
* This makes `OAuthProvider` bivariant in `T`, which is correct because
|
|
74
|
+
* each provider is self-contained — `schema` validates the request body
|
|
75
|
+
* and `verify` consumes the same `T`. Bivariance lets heterogeneous
|
|
76
|
+
* providers (`OAuthProvider<SpecificPayload>`) coexist in a single
|
|
77
|
+
* `OAuthProvider<unknown>[]` array without resorting to `any`.
|
|
78
|
+
*/
|
|
79
|
+
verify(payload: T): Promise<OAuthProviderProfile | null>;
|
|
79
80
|
}
|
|
80
|
-
|
|
81
81
|
/**
|
|
82
82
|
* Role data structure
|
|
83
83
|
*/
|
|
@@ -98,7 +98,6 @@ export interface RoleData {
|
|
|
98
98
|
delete?: boolean;
|
|
99
99
|
}> | null;
|
|
100
100
|
}
|
|
101
|
-
|
|
102
101
|
/**
|
|
103
102
|
* Data for creating a new role
|
|
104
103
|
*/
|
|
@@ -109,7 +108,6 @@ export interface CreateRoleData {
|
|
|
109
108
|
defaultPermissions?: RoleData["defaultPermissions"];
|
|
110
109
|
collectionPermissions?: RoleData["collectionPermissions"];
|
|
111
110
|
}
|
|
112
|
-
|
|
113
111
|
/**
|
|
114
112
|
* Refresh token info
|
|
115
113
|
*/
|
|
@@ -122,7 +120,6 @@ export interface RefreshTokenInfo {
|
|
|
122
120
|
userAgent?: string | null;
|
|
123
121
|
ipAddress?: string | null;
|
|
124
122
|
}
|
|
125
|
-
|
|
126
123
|
/**
|
|
127
124
|
* Password reset token info
|
|
128
125
|
*/
|
|
@@ -130,7 +127,6 @@ export interface PasswordResetTokenInfo {
|
|
|
130
127
|
userId: string;
|
|
131
128
|
expiresAt: Date;
|
|
132
129
|
}
|
|
133
|
-
|
|
134
130
|
/**
|
|
135
131
|
* Magic link token info
|
|
136
132
|
*/
|
|
@@ -138,11 +134,6 @@ export interface MagicLinkTokenInfo {
|
|
|
138
134
|
userId: string;
|
|
139
135
|
expiresAt: Date;
|
|
140
136
|
}
|
|
141
|
-
|
|
142
|
-
// =============================================================================
|
|
143
|
-
// AUTH REPOSITORY INTERFACES
|
|
144
|
-
// =============================================================================
|
|
145
|
-
|
|
146
137
|
/**
|
|
147
138
|
* Options for paginated user listing
|
|
148
139
|
*/
|
|
@@ -160,7 +151,6 @@ export interface ListUsersOptions {
|
|
|
160
151
|
/** Filter by role ID */
|
|
161
152
|
roleId?: string;
|
|
162
153
|
}
|
|
163
|
-
|
|
164
154
|
/**
|
|
165
155
|
* Result of a paginated user listing
|
|
166
156
|
*/
|
|
@@ -171,7 +161,6 @@ export interface PaginatedUsersResult {
|
|
|
171
161
|
limit: number;
|
|
172
162
|
offset: number;
|
|
173
163
|
}
|
|
174
|
-
|
|
175
164
|
/**
|
|
176
165
|
* Abstract user repository interface.
|
|
177
166
|
* Handles all user-related database operations.
|
|
@@ -181,98 +170,82 @@ export interface UserRepository {
|
|
|
181
170
|
* Create a new user
|
|
182
171
|
*/
|
|
183
172
|
createUser(data: CreateUserData): Promise<UserData>;
|
|
184
|
-
|
|
185
173
|
/**
|
|
186
174
|
* Get a user by ID
|
|
187
175
|
*/
|
|
188
176
|
getUserById(id: string): Promise<UserData | null>;
|
|
189
|
-
|
|
190
177
|
/**
|
|
191
178
|
* Get a user by email
|
|
192
179
|
*/
|
|
193
180
|
getUserByEmail(email: string): Promise<UserData | null>;
|
|
194
|
-
|
|
195
181
|
/**
|
|
196
182
|
* Get a user by an OAuth identity
|
|
197
183
|
*/
|
|
198
184
|
getUserByIdentity(provider: string, providerId: string): Promise<UserData | null>;
|
|
199
|
-
|
|
200
185
|
/**
|
|
201
186
|
* Get all identities linked to a user
|
|
202
187
|
*/
|
|
203
188
|
getUserIdentities(userId: string): Promise<UserIdentityData[]>;
|
|
204
|
-
|
|
205
189
|
/**
|
|
206
190
|
* Link a new OAuth identity to a user
|
|
207
191
|
*/
|
|
208
192
|
linkUserIdentity(userId: string, provider: string, providerId: string, profileData?: Record<string, unknown>): Promise<void>;
|
|
209
|
-
|
|
210
193
|
/**
|
|
211
194
|
* Update a user
|
|
212
195
|
*/
|
|
213
196
|
updateUser(id: string, data: Partial<Omit<CreateUserData, "id">>): Promise<UserData | null>;
|
|
214
|
-
|
|
215
197
|
/**
|
|
216
198
|
* Delete a user
|
|
217
199
|
*/
|
|
218
200
|
deleteUser(id: string): Promise<void>;
|
|
219
|
-
|
|
220
201
|
/**
|
|
221
202
|
* List all users (unbounded — use listUsersPaginated for large datasets)
|
|
222
203
|
*/
|
|
223
204
|
listUsers(): Promise<UserData[]>;
|
|
224
|
-
|
|
225
205
|
/**
|
|
226
206
|
* List users with server-side pagination, search, and sorting.
|
|
227
207
|
*/
|
|
228
208
|
listUsersPaginated(options?: ListUsersOptions): Promise<PaginatedUsersResult>;
|
|
229
|
-
|
|
230
209
|
/**
|
|
231
210
|
* Update user's password hash
|
|
232
211
|
*/
|
|
233
212
|
updatePassword(id: string, passwordHash: string): Promise<void>;
|
|
234
|
-
|
|
235
213
|
/**
|
|
236
214
|
* Set email verification status
|
|
237
215
|
*/
|
|
238
216
|
setEmailVerified(id: string, verified: boolean): Promise<void>;
|
|
239
|
-
|
|
240
217
|
/**
|
|
241
218
|
* Set email verification token
|
|
242
219
|
*/
|
|
243
220
|
setVerificationToken(id: string, token: string | null): Promise<void>;
|
|
244
|
-
|
|
245
221
|
/**
|
|
246
222
|
* Find user by email verification token
|
|
247
223
|
*/
|
|
248
224
|
getUserByVerificationToken(token: string): Promise<UserData | null>;
|
|
249
|
-
|
|
250
225
|
/**
|
|
251
226
|
* Get roles for a user
|
|
252
227
|
*/
|
|
253
228
|
getUserRoles(userId: string): Promise<RoleData[]>;
|
|
254
|
-
|
|
255
229
|
/**
|
|
256
230
|
* Get role IDs for a user
|
|
257
231
|
*/
|
|
258
232
|
getUserRoleIds(userId: string): Promise<string[]>;
|
|
259
|
-
|
|
260
233
|
/**
|
|
261
234
|
* Set roles for a user (replaces existing roles)
|
|
262
235
|
*/
|
|
263
236
|
setUserRoles(userId: string, roleIds: string[]): Promise<void>;
|
|
264
|
-
|
|
265
237
|
/**
|
|
266
238
|
* Assign a specific role to a new user
|
|
267
239
|
*/
|
|
268
240
|
assignDefaultRole(userId: string, roleId: string): Promise<void>;
|
|
269
|
-
|
|
270
241
|
/**
|
|
271
242
|
* Get user with their roles
|
|
272
243
|
*/
|
|
273
|
-
getUserWithRoles(userId: string): Promise<{
|
|
244
|
+
getUserWithRoles(userId: string): Promise<{
|
|
245
|
+
user: UserData;
|
|
246
|
+
roles: RoleData[];
|
|
247
|
+
} | null>;
|
|
274
248
|
}
|
|
275
|
-
|
|
276
249
|
/**
|
|
277
250
|
* Abstract role repository interface.
|
|
278
251
|
* Handles all role-related database operations.
|
|
@@ -282,114 +255,85 @@ export interface RoleRepository {
|
|
|
282
255
|
* Get a role by ID
|
|
283
256
|
*/
|
|
284
257
|
getRoleById(id: string): Promise<RoleData | null>;
|
|
285
|
-
|
|
286
258
|
/**
|
|
287
259
|
* List all roles
|
|
288
260
|
*/
|
|
289
261
|
listRoles(): Promise<RoleData[]>;
|
|
290
|
-
|
|
291
262
|
/**
|
|
292
263
|
* Create a new role
|
|
293
264
|
*/
|
|
294
265
|
createRole(data: CreateRoleData): Promise<RoleData>;
|
|
295
|
-
|
|
296
266
|
/**
|
|
297
267
|
* Update a role
|
|
298
268
|
*/
|
|
299
269
|
updateRole(id: string, data: Partial<Omit<RoleData, "id">>): Promise<RoleData | null>;
|
|
300
|
-
|
|
301
270
|
/**
|
|
302
271
|
* Delete a role
|
|
303
272
|
*/
|
|
304
273
|
deleteRole(id: string): Promise<void>;
|
|
305
274
|
}
|
|
306
|
-
|
|
307
275
|
/**
|
|
308
276
|
* Abstract token repository interface.
|
|
309
277
|
* Handles refresh tokens and password reset tokens.
|
|
310
278
|
*/
|
|
311
279
|
export interface TokenRepository {
|
|
312
|
-
// Refresh tokens
|
|
313
|
-
|
|
314
280
|
/**
|
|
315
281
|
* Create a new refresh token
|
|
316
282
|
*/
|
|
317
283
|
createRefreshToken(userId: string, tokenHash: string, expiresAt: Date, userAgent?: string, ipAddress?: string): Promise<void>;
|
|
318
|
-
|
|
319
284
|
/**
|
|
320
285
|
* Find a refresh token by hash
|
|
321
286
|
*/
|
|
322
287
|
findRefreshTokenByHash(tokenHash: string): Promise<RefreshTokenInfo | null>;
|
|
323
|
-
|
|
324
288
|
/**
|
|
325
289
|
* Delete a refresh token by hash
|
|
326
290
|
*/
|
|
327
291
|
deleteRefreshToken(tokenHash: string): Promise<void>;
|
|
328
|
-
|
|
329
292
|
/**
|
|
330
293
|
* Delete all refresh tokens for a user
|
|
331
294
|
*/
|
|
332
295
|
deleteAllRefreshTokensForUser(userId: string): Promise<void>;
|
|
333
|
-
|
|
334
296
|
/**
|
|
335
297
|
* List all refresh tokens for a user
|
|
336
298
|
*/
|
|
337
299
|
listRefreshTokensForUser(userId: string): Promise<RefreshTokenInfo[]>;
|
|
338
|
-
|
|
339
300
|
/**
|
|
340
301
|
* Delete a specific refresh token by its primary key ID
|
|
341
302
|
*/
|
|
342
303
|
deleteRefreshTokenById(id: string, userId: string): Promise<void>;
|
|
343
|
-
|
|
344
|
-
// Password reset tokens
|
|
345
|
-
|
|
346
304
|
/**
|
|
347
305
|
* Create a password reset token
|
|
348
306
|
*/
|
|
349
307
|
createPasswordResetToken(userId: string, tokenHash: string, expiresAt: Date): Promise<void>;
|
|
350
|
-
|
|
351
308
|
/**
|
|
352
309
|
* Find a valid (not expired, not used) password reset token by hash
|
|
353
310
|
*/
|
|
354
311
|
findValidPasswordResetToken(tokenHash: string): Promise<PasswordResetTokenInfo | null>;
|
|
355
|
-
|
|
356
312
|
/**
|
|
357
313
|
* Mark a password reset token as used
|
|
358
314
|
*/
|
|
359
315
|
markPasswordResetTokenUsed(tokenHash: string): Promise<void>;
|
|
360
|
-
|
|
361
316
|
/**
|
|
362
317
|
* Delete all password reset tokens for a user
|
|
363
318
|
*/
|
|
364
319
|
deleteAllPasswordResetTokensForUser(userId: string): Promise<void>;
|
|
365
|
-
|
|
366
320
|
/**
|
|
367
321
|
* Clean up expired tokens
|
|
368
322
|
*/
|
|
369
323
|
deleteExpiredTokens(): Promise<void>;
|
|
370
|
-
|
|
371
|
-
// Magic link tokens
|
|
372
|
-
|
|
373
324
|
/**
|
|
374
325
|
* Create a magic link token
|
|
375
326
|
*/
|
|
376
327
|
createMagicLinkToken(userId: string, tokenHash: string, expiresAt: Date): Promise<void>;
|
|
377
|
-
|
|
378
328
|
/**
|
|
379
329
|
* Find a valid (not expired, not used) magic link token by hash
|
|
380
330
|
*/
|
|
381
331
|
findValidMagicLinkToken(tokenHash: string): Promise<MagicLinkTokenInfo | null>;
|
|
382
|
-
|
|
383
332
|
/**
|
|
384
333
|
* Mark a magic link token as used
|
|
385
334
|
*/
|
|
386
335
|
markMagicLinkTokenUsed(tokenHash: string): Promise<void>;
|
|
387
336
|
}
|
|
388
|
-
|
|
389
|
-
// =============================================================================
|
|
390
|
-
// MFA INTERFACES
|
|
391
|
-
// =============================================================================
|
|
392
|
-
|
|
393
337
|
/**
|
|
394
338
|
* MFA factor data structure
|
|
395
339
|
*/
|
|
@@ -402,7 +346,6 @@ export interface MfaFactor {
|
|
|
402
346
|
createdAt: Date;
|
|
403
347
|
updatedAt: Date;
|
|
404
348
|
}
|
|
405
|
-
|
|
406
349
|
/**
|
|
407
350
|
* MFA challenge information
|
|
408
351
|
*/
|
|
@@ -413,7 +356,6 @@ export interface MfaChallengeInfo {
|
|
|
413
356
|
verifiedAt?: Date;
|
|
414
357
|
ipAddress?: string;
|
|
415
358
|
}
|
|
416
|
-
|
|
417
359
|
/**
|
|
418
360
|
* Recovery code data structure
|
|
419
361
|
*/
|
|
@@ -422,7 +364,6 @@ export interface RecoveryCode {
|
|
|
422
364
|
userId: string;
|
|
423
365
|
usedAt?: Date;
|
|
424
366
|
}
|
|
425
|
-
|
|
426
367
|
/**
|
|
427
368
|
* Abstract MFA repository interface.
|
|
428
369
|
* Handles all MFA-related database operations.
|
|
@@ -432,69 +373,59 @@ export interface MfaRepository {
|
|
|
432
373
|
* Create a new MFA factor for a user
|
|
433
374
|
*/
|
|
434
375
|
createMfaFactor(userId: string, factorType: "totp", secretEncrypted: string, friendlyName?: string): Promise<MfaFactor>;
|
|
435
|
-
|
|
436
376
|
/**
|
|
437
377
|
* Get all MFA factors for a user
|
|
438
378
|
*/
|
|
439
379
|
getMfaFactors(userId: string): Promise<MfaFactor[]>;
|
|
440
|
-
|
|
441
380
|
/**
|
|
442
381
|
* Get a specific MFA factor by ID
|
|
443
382
|
*/
|
|
444
|
-
getMfaFactorById(factorId: string): Promise<(MfaFactor & {
|
|
445
|
-
|
|
383
|
+
getMfaFactorById(factorId: string): Promise<(MfaFactor & {
|
|
384
|
+
secretEncrypted: string;
|
|
385
|
+
}) | null>;
|
|
446
386
|
/**
|
|
447
387
|
* Mark an MFA factor as verified
|
|
448
388
|
*/
|
|
449
389
|
verifyMfaFactor(factorId: string): Promise<void>;
|
|
450
|
-
|
|
451
390
|
/**
|
|
452
391
|
* Delete an MFA factor
|
|
453
392
|
*/
|
|
454
393
|
deleteMfaFactor(factorId: string, userId: string): Promise<void>;
|
|
455
|
-
|
|
456
394
|
/**
|
|
457
395
|
* Create an MFA challenge
|
|
458
396
|
*/
|
|
459
397
|
createMfaChallenge(factorId: string, ipAddress?: string): Promise<MfaChallengeInfo>;
|
|
460
|
-
|
|
461
398
|
/**
|
|
462
399
|
* Get an MFA challenge by ID
|
|
463
400
|
*/
|
|
464
401
|
getMfaChallengeById(challengeId: string): Promise<MfaChallengeInfo | null>;
|
|
465
|
-
|
|
466
402
|
/**
|
|
467
403
|
* Mark an MFA challenge as verified
|
|
468
404
|
*/
|
|
469
405
|
verifyMfaChallenge(challengeId: string): Promise<void>;
|
|
470
|
-
|
|
471
406
|
/**
|
|
472
407
|
* Create recovery codes for a user
|
|
473
408
|
*/
|
|
474
409
|
createRecoveryCodes(userId: string, codeHashes: string[]): Promise<void>;
|
|
475
|
-
|
|
476
410
|
/**
|
|
477
411
|
* Use a recovery code (mark as used)
|
|
478
412
|
*/
|
|
479
413
|
useRecoveryCode(userId: string, codeHash: string): Promise<boolean>;
|
|
480
|
-
|
|
481
414
|
/**
|
|
482
415
|
* Get unused recovery code count for a user
|
|
483
416
|
*/
|
|
484
417
|
getUnusedRecoveryCodeCount(userId: string): Promise<number>;
|
|
485
|
-
|
|
486
418
|
/**
|
|
487
419
|
* Delete all recovery codes for a user
|
|
488
420
|
*/
|
|
489
421
|
deleteAllRecoveryCodes(userId: string): Promise<void>;
|
|
490
|
-
|
|
491
422
|
/**
|
|
492
423
|
* Check if a user has any verified MFA factors
|
|
493
424
|
*/
|
|
494
425
|
hasVerifiedMfaFactors(userId: string): Promise<boolean>;
|
|
495
426
|
}
|
|
496
|
-
|
|
497
427
|
/**
|
|
498
428
|
* Combined auth repository interface for convenience
|
|
499
429
|
*/
|
|
500
|
-
export interface AuthRepository extends UserRepository, RoleRepository, TokenRepository, MfaRepository {
|
|
430
|
+
export interface AuthRepository extends UserRepository, RoleRepository, TokenRepository, MfaRepository {
|
|
431
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export interface JwtConfig {
|
|
2
|
+
secret: string;
|
|
3
|
+
accessExpiresIn?: string;
|
|
4
|
+
refreshExpiresIn?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface AccessTokenPayload {
|
|
7
|
+
userId: string;
|
|
8
|
+
roles: string[];
|
|
9
|
+
uid?: string;
|
|
10
|
+
/** Authentication Assurance Level: aal1 = password/oauth, aal2 = MFA verified */
|
|
11
|
+
aal?: "aal1" | "aal2";
|
|
12
|
+
/** Email claim from the JWT, if present */
|
|
13
|
+
email?: string;
|
|
14
|
+
/** Display name claim from the JWT, if present */
|
|
15
|
+
displayName?: string;
|
|
16
|
+
/** Photo URL claim from the JWT, if present */
|
|
17
|
+
photoURL?: string;
|
|
18
|
+
/** Whether MFA has been verified for this session */
|
|
19
|
+
mfa_verified?: boolean;
|
|
20
|
+
/** Authentication Methods Reference — list of methods used (e.g. 'pwd', 'otp') */
|
|
21
|
+
amr?: string[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Configure JWT settings - call this during initialization.
|
|
25
|
+
* Validates the secret strength to prevent deployment with default/weak secrets.
|
|
26
|
+
*/
|
|
27
|
+
export declare function configureJwt(config: JwtConfig): void;
|
|
28
|
+
/**
|
|
29
|
+
* Generate an access token (short-lived, 1 hour by default)
|
|
30
|
+
*/
|
|
31
|
+
export declare function generateAccessToken(userId: string, roles: string[], aal?: "aal1" | "aal2", customClaims?: Record<string, unknown>): string;
|
|
32
|
+
/**
|
|
33
|
+
* Get the expiration time of an access token in milliseconds from now
|
|
34
|
+
*/
|
|
35
|
+
export declare function getAccessTokenExpiryMs(): number;
|
|
36
|
+
/**
|
|
37
|
+
* Get the expiration timestamp for an access token
|
|
38
|
+
*/
|
|
39
|
+
export declare function getAccessTokenExpiry(): number;
|
|
40
|
+
/**
|
|
41
|
+
* Verify and decode an access token
|
|
42
|
+
*/
|
|
43
|
+
export declare function verifyAccessToken(token: string): AccessTokenPayload | null;
|
|
44
|
+
/**
|
|
45
|
+
* Generate a random refresh token (long-lived, 30 days by default)
|
|
46
|
+
*/
|
|
47
|
+
export declare function generateRefreshToken(): string;
|
|
48
|
+
/**
|
|
49
|
+
* Hash a refresh token for database storage (don't store raw tokens)
|
|
50
|
+
*/
|
|
51
|
+
export declare function hashRefreshToken(token: string): string;
|
|
52
|
+
/**
|
|
53
|
+
* Calculate refresh token expiration date
|
|
54
|
+
*/
|
|
55
|
+
export declare function getRefreshTokenExpiry(): Date;
|
|
56
|
+
export interface DownloadTokenPayload {
|
|
57
|
+
purpose: "file-read";
|
|
58
|
+
path: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Generate a short-lived download token scoped to a specific file path or prefix
|
|
62
|
+
*/
|
|
63
|
+
export declare function generateDownloadToken(path: string, expiresInSeconds?: number): string;
|
|
64
|
+
/**
|
|
65
|
+
* Verify and decode a download token
|
|
66
|
+
*/
|
|
67
|
+
export declare function verifyDownloadToken(token: string): DownloadTokenPayload | null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { OAuthProvider } from "./interfaces";
|
|
2
|
+
export interface LinkedinUserInfo {
|
|
3
|
+
linkedinId: string;
|
|
4
|
+
email: string;
|
|
5
|
+
displayName: string | null;
|
|
6
|
+
photoUrl: string | null;
|
|
7
|
+
emailVerified: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Creates a LinkedIn OAuth Provider integration
|
|
11
|
+
*/
|
|
12
|
+
export declare function createLinkedinProvider(config: {
|
|
13
|
+
clientId: string;
|
|
14
|
+
clientSecret: string;
|
|
15
|
+
}): OAuthProvider<{
|
|
16
|
+
code: string;
|
|
17
|
+
redirectUri: string;
|
|
18
|
+
}>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import type { AuthModuleConfig } from "./routes";
|
|
3
|
+
import type { ResolvedAuthHooks } from "./auth-hooks";
|
|
4
|
+
import type { HonoEnv } from "../api/types";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import type { AuthResponsePayload, TransformAuthResponseContext } from "@rebasepro/types";
|
|
7
|
+
/**
|
|
8
|
+
* Mount magic link routes onto the auth router.
|
|
9
|
+
*
|
|
10
|
+
* Follows the same delegation pattern as `mountMfaRoutes()` and `mountSessionRoutes()`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function mountMagicLinkRoutes(deps: {
|
|
13
|
+
router: Hono<HonoEnv>;
|
|
14
|
+
config: AuthModuleConfig;
|
|
15
|
+
ops: ResolvedAuthHooks;
|
|
16
|
+
parseBody: <T>(schema: z.ZodSchema<T>, body: unknown) => T;
|
|
17
|
+
buildAuthResponse: (user: {
|
|
18
|
+
id: string;
|
|
19
|
+
email: string;
|
|
20
|
+
displayName?: string | null;
|
|
21
|
+
photoUrl?: string | null;
|
|
22
|
+
emailVerified?: boolean;
|
|
23
|
+
isAnonymous?: boolean;
|
|
24
|
+
metadata?: Record<string, unknown> | null;
|
|
25
|
+
}, roleIds: string[], accessToken: string, refreshToken: string, providerId: string) => unknown;
|
|
26
|
+
createSessionAndTokens: (userId: string, userAgent: string, ipAddress: string) => Promise<{
|
|
27
|
+
roleIds: string[];
|
|
28
|
+
accessToken: string;
|
|
29
|
+
refreshToken: string;
|
|
30
|
+
}>;
|
|
31
|
+
applyTransformHook: (response: AuthResponsePayload, method: TransformAuthResponseContext["method"], request: Request, userId: string) => Promise<AuthResponsePayload>;
|
|
32
|
+
}): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Envelope encryption for TOTP secrets using AES-256-GCM.
|
|
3
|
+
*
|
|
4
|
+
* - Derives a 32-byte key via SHA-256 from `MFA_ENCRYPTION_KEY` or `JWT_SECRET`.
|
|
5
|
+
* - Generates a random 12-byte IV per encryption call.
|
|
6
|
+
* - Returns ciphertexts in the format `iv_hex:authTag_hex:ciphertext_hex`.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Encrypt a plaintext TOTP secret.
|
|
12
|
+
*
|
|
13
|
+
* @param plaintext - The Base32 TOTP secret to encrypt.
|
|
14
|
+
* @returns A string in the format `iv_hex:authTag_hex:ciphertext_hex`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function encryptTotpSecret(plaintext: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Decrypt a previously encrypted TOTP secret.
|
|
19
|
+
*
|
|
20
|
+
* @param ciphertext - A string in the format `iv_hex:authTag_hex:ciphertext_hex`.
|
|
21
|
+
* @returns The original Base32 TOTP secret.
|
|
22
|
+
*/
|
|
23
|
+
export declare function decryptTotpSecret(ciphertext: string): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { HonoEnv } from "../api/types";
|
|
4
|
+
import type { AuthModuleConfig } from "./routes";
|
|
5
|
+
import { resolveAuthHooks } from "./auth-hooks";
|
|
6
|
+
import type { AuthResponsePayload, TransformAuthResponseContext } from "@rebasepro/types";
|
|
7
|
+
export declare function mountMfaRoutes(router: Hono<HonoEnv>, config: AuthModuleConfig, ops: ReturnType<typeof resolveAuthHooks>, parseBody: <T>(schema: z.ZodSchema<T>, body: unknown) => T, applyTransformHook?: (response: AuthResponsePayload, method: TransformAuthResponseContext["method"], request: Request, userId: string) => Promise<AuthResponsePayload>): void;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TOTP (Time-based One-Time Password) implementation.
|
|
3
|
+
*
|
|
4
|
+
* Pure Node.js crypto implementation — no external dependencies required.
|
|
5
|
+
* Implements RFC 6238 (TOTP) and RFC 4226 (HOTP).
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Encode a Buffer to Base32 string (RFC 4648)
|
|
9
|
+
*/
|
|
10
|
+
export declare function base32Encode(buffer: Buffer): string;
|
|
11
|
+
/**
|
|
12
|
+
* Decode a Base32 string to Buffer
|
|
13
|
+
*/
|
|
14
|
+
export declare function base32Decode(encoded: string): Buffer;
|
|
15
|
+
/**
|
|
16
|
+
* Generate a TOTP value for the current time step
|
|
17
|
+
*/
|
|
18
|
+
export declare function generateTotp(secret: Buffer, timeStep?: number): string;
|
|
19
|
+
/**
|
|
20
|
+
* Verify a TOTP token with a configurable time window
|
|
21
|
+
*
|
|
22
|
+
* @param secret - The shared secret as a Buffer
|
|
23
|
+
* @param token - The 6-digit TOTP code to verify
|
|
24
|
+
* @param window - Number of time steps to check on each side (default: 1)
|
|
25
|
+
* @returns true if the token is valid within the window
|
|
26
|
+
*/
|
|
27
|
+
export declare function verifyTotp(secret: Buffer, token: string, window?: number): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Generate a new TOTP secret and return the setup information
|
|
30
|
+
*
|
|
31
|
+
* @param issuer - The issuer name (app name) for the QR code
|
|
32
|
+
* @param accountName - The account identifier (usually email)
|
|
33
|
+
* @returns Object with base32 secret and otpauth URI
|
|
34
|
+
*/
|
|
35
|
+
export declare function generateTotpSecret(issuer: string, accountName: string): {
|
|
36
|
+
secret: string;
|
|
37
|
+
uri: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Generate a set of one-time recovery codes
|
|
41
|
+
*
|
|
42
|
+
* @param count - Number of recovery codes to generate (default: 10)
|
|
43
|
+
* @returns Array of formatted recovery code strings (e.g. "A1B2C-D3E4F")
|
|
44
|
+
*/
|
|
45
|
+
export declare function generateRecoveryCodes(count?: number): string[];
|
|
46
|
+
/**
|
|
47
|
+
* Hash a recovery code for storage
|
|
48
|
+
*/
|
|
49
|
+
export declare function hashRecoveryCode(code: string): string;
|