@lastshotlabs/bunshot 0.0.27 → 0.0.28
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/.oclif.manifest.json +39 -0
- package/README.md +8282 -2147
- package/dist/cli/commands/init.js +690 -0
- package/dist/cli/index.js +6 -0
- package/dist/cli.js +4 -4
- package/dist/packages/bunshot-admin/src/index.d.ts +15 -0
- package/dist/packages/bunshot-admin/src/index.js +11 -0
- package/dist/packages/bunshot-admin/src/lib/resourceTypes.d.ts +8 -0
- package/dist/packages/bunshot-admin/src/lib/resourceTypes.js +33 -0
- package/dist/packages/bunshot-admin/src/lib/typedRoute.d.ts +14 -0
- package/dist/packages/bunshot-admin/src/lib/typedRoute.js +17 -0
- package/dist/packages/bunshot-admin/src/plugin.d.ts +4 -0
- package/dist/packages/bunshot-admin/src/plugin.js +46 -0
- package/dist/packages/bunshot-admin/src/providers/auth0Access.d.ts +6 -0
- package/dist/packages/bunshot-admin/src/providers/auth0Access.js +32 -0
- package/dist/packages/bunshot-admin/src/routes/admin.d.ts +10 -0
- package/dist/packages/bunshot-admin/src/routes/admin.js +923 -0
- package/dist/packages/bunshot-admin/src/routes/mail.d.ts +6 -0
- package/dist/packages/bunshot-admin/src/routes/mail.js +114 -0
- package/dist/packages/bunshot-admin/src/routes/permissions.d.ts +8 -0
- package/dist/packages/bunshot-admin/src/routes/permissions.js +315 -0
- package/dist/packages/bunshot-admin/src/types/config.d.ts +16 -0
- package/dist/packages/bunshot-admin/src/types/config.js +37 -0
- package/dist/packages/bunshot-admin/src/types/env.d.ts +14 -0
- package/dist/packages/bunshot-admin/src/types/provider.d.ts +1 -0
- package/dist/packages/bunshot-admin/src/types/provider.js +4 -0
- package/dist/packages/bunshot-auth/src/adapters/memoryAuth.d.ts +66 -0
- package/dist/packages/bunshot-auth/src/adapters/memoryAuth.js +1063 -0
- package/dist/packages/bunshot-auth/src/adapters/mongoAuth.d.ts +2 -0
- package/dist/packages/bunshot-auth/src/adapters/mongoAuth.js +536 -0
- package/dist/packages/bunshot-auth/src/adapters/sqliteAuth.d.ts +88 -0
- package/dist/packages/bunshot-auth/src/adapters/sqliteAuth.js +1366 -0
- package/dist/packages/bunshot-auth/src/admin/bunshotAccess.d.ts +2 -0
- package/dist/packages/bunshot-auth/src/admin/bunshotAccess.js +23 -0
- package/dist/packages/bunshot-auth/src/admin/bunshotUsers.d.ts +5 -0
- package/dist/packages/bunshot-auth/src/admin/bunshotUsers.js +131 -0
- package/dist/packages/bunshot-auth/src/bootstrap.d.ts +38 -0
- package/dist/packages/bunshot-auth/src/bootstrap.js +384 -0
- package/dist/packages/bunshot-auth/src/config/appConfig.d.ts +3 -0
- package/dist/packages/bunshot-auth/src/config/appConfig.js +4 -0
- package/dist/packages/bunshot-auth/src/config/authConfig.d.ts +478 -0
- package/dist/packages/bunshot-auth/src/config/authConfig.js +46 -0
- package/dist/packages/bunshot-auth/src/config/configLock.d.ts +2 -0
- package/dist/packages/bunshot-auth/src/config/configLock.js +10 -0
- package/dist/packages/bunshot-auth/src/index.d.ts +25 -0
- package/dist/packages/bunshot-auth/src/index.js +23 -0
- package/dist/packages/bunshot-auth/src/infra/mongo.d.ts +15 -0
- package/dist/packages/bunshot-auth/src/infra/mongo.js +44 -0
- package/dist/packages/bunshot-auth/src/infra/queue.d.ts +14 -0
- package/dist/packages/bunshot-auth/src/infra/queue.js +27 -0
- package/dist/packages/bunshot-auth/src/infra/redis.d.ts +5 -0
- package/dist/packages/bunshot-auth/src/infra/redis.js +15 -0
- package/dist/packages/bunshot-auth/src/infra/signing.d.ts +7 -0
- package/dist/packages/bunshot-auth/src/infra/signing.js +8 -0
- package/dist/packages/bunshot-auth/src/lib/accountLockout.d.ts +34 -0
- package/dist/packages/bunshot-auth/src/lib/accountLockout.js +244 -0
- package/dist/packages/bunshot-auth/src/lib/adapterTiers.d.ts +1 -0
- package/dist/packages/bunshot-auth/src/lib/adapterTiers.js +1 -0
- package/dist/packages/bunshot-auth/src/lib/authAdapter.d.ts +1 -0
- package/dist/packages/bunshot-auth/src/lib/authAdapter.js +1 -0
- package/dist/packages/bunshot-auth/src/lib/authContext.d.ts +15 -0
- package/dist/packages/bunshot-auth/src/lib/authContext.js +1 -0
- package/dist/packages/bunshot-auth/src/lib/authEventBus.d.ts +4 -0
- package/dist/packages/bunshot-auth/src/lib/authEventBus.js +15 -0
- package/dist/packages/bunshot-auth/src/lib/authRateLimit.d.ts +28 -0
- package/dist/packages/bunshot-auth/src/lib/authRateLimit.js +205 -0
- package/dist/{lib → packages/bunshot-auth/src/lib}/breachedPassword.d.ts +8 -2
- package/dist/{lib → packages/bunshot-auth/src/lib}/breachedPassword.js +22 -9
- package/dist/packages/bunshot-auth/src/lib/cache.d.ts +12 -0
- package/dist/packages/bunshot-auth/src/lib/cache.js +120 -0
- package/dist/packages/bunshot-auth/src/lib/clientIp.d.ts +4 -0
- package/dist/{lib → packages/bunshot-auth/src/lib}/clientIp.js +14 -7
- package/dist/packages/bunshot-auth/src/lib/cookieOptions.d.ts +27 -0
- package/dist/packages/bunshot-auth/src/lib/cookieOptions.js +33 -0
- package/dist/packages/bunshot-auth/src/lib/credentialStuffing.d.ts +40 -0
- package/dist/packages/bunshot-auth/src/lib/credentialStuffing.js +221 -0
- package/dist/packages/bunshot-auth/src/lib/deletionCancelToken.d.ts +19 -0
- package/dist/packages/bunshot-auth/src/lib/deletionCancelToken.js +148 -0
- package/dist/packages/bunshot-auth/src/lib/emailTemplates.d.ts +23 -0
- package/dist/packages/bunshot-auth/src/lib/emailTemplates.js +265 -0
- package/dist/packages/bunshot-auth/src/lib/emailVerification.d.ts +30 -0
- package/dist/packages/bunshot-auth/src/lib/emailVerification.js +200 -0
- package/dist/packages/bunshot-auth/src/lib/env.d.ts +1 -0
- package/dist/packages/bunshot-auth/src/lib/env.js +3 -0
- package/dist/packages/bunshot-auth/src/lib/fingerprint.js +36 -0
- package/dist/{lib → packages/bunshot-auth/src/lib}/groups.d.ts +15 -16
- package/dist/{lib → packages/bunshot-auth/src/lib}/groups.js +22 -34
- package/dist/packages/bunshot-auth/src/lib/jwks.d.ts +28 -0
- package/dist/packages/bunshot-auth/src/lib/jwks.js +79 -0
- package/dist/packages/bunshot-auth/src/lib/jwt.d.ts +12 -0
- package/dist/packages/bunshot-auth/src/lib/jwt.js +86 -0
- package/dist/{lib → packages/bunshot-auth/src/lib}/logger.js +3 -3
- package/dist/{lib → packages/bunshot-auth/src/lib}/m2m.d.ts +5 -4
- package/dist/{lib → packages/bunshot-auth/src/lib}/m2m.js +6 -10
- package/dist/packages/bunshot-auth/src/lib/magicLink.d.ts +13 -0
- package/dist/packages/bunshot-auth/src/lib/magicLink.js +145 -0
- package/dist/packages/bunshot-auth/src/lib/mfaChallenge.d.ts +60 -0
- package/dist/packages/bunshot-auth/src/lib/mfaChallenge.js +419 -0
- package/dist/packages/bunshot-auth/src/lib/oauth.d.ts +82 -0
- package/dist/packages/bunshot-auth/src/lib/oauth.js +177 -0
- package/dist/packages/bunshot-auth/src/lib/oauthCode.d.ts +19 -0
- package/dist/packages/bunshot-auth/src/lib/oauthCode.js +182 -0
- package/dist/packages/bunshot-auth/src/lib/oauthReauth.d.ts +19 -0
- package/dist/packages/bunshot-auth/src/lib/oauthReauth.js +255 -0
- package/dist/packages/bunshot-auth/src/lib/organization.d.ts +66 -0
- package/dist/packages/bunshot-auth/src/lib/organization.js +225 -0
- package/dist/packages/bunshot-auth/src/lib/passwordHistory.d.ts +12 -0
- package/dist/packages/bunshot-auth/src/lib/passwordHistory.js +31 -0
- package/dist/packages/bunshot-auth/src/lib/resetPassword.d.ts +20 -0
- package/dist/packages/bunshot-auth/src/lib/resetPassword.js +148 -0
- package/dist/packages/bunshot-auth/src/lib/roles.d.ts +9 -0
- package/dist/packages/bunshot-auth/src/lib/roles.js +93 -0
- package/dist/packages/bunshot-auth/src/lib/saml.d.ts +29 -0
- package/dist/packages/bunshot-auth/src/lib/saml.js +73 -0
- package/dist/packages/bunshot-auth/src/lib/samlRequestId.d.ts +13 -0
- package/dist/packages/bunshot-auth/src/lib/samlRequestId.js +129 -0
- package/dist/{lib → packages/bunshot-auth/src/lib}/scim.d.ts +7 -7
- package/dist/{lib → packages/bunshot-auth/src/lib}/scim.js +15 -13
- package/dist/packages/bunshot-auth/src/lib/securityEventWiring.d.ts +22 -0
- package/dist/packages/bunshot-auth/src/lib/securityEventWiring.js +65 -0
- package/dist/packages/bunshot-auth/src/lib/session.d.ts +45 -0
- package/dist/packages/bunshot-auth/src/lib/session.js +1211 -0
- package/dist/packages/bunshot-auth/src/lib/storeInfra.d.ts +26 -0
- package/dist/packages/bunshot-auth/src/lib/storeInfra.js +18 -0
- package/dist/{lib → packages/bunshot-auth/src/lib}/suspension.d.ts +3 -2
- package/dist/{lib → packages/bunshot-auth/src/lib}/suspension.js +2 -5
- package/dist/packages/bunshot-auth/src/lib/validateAdapter.d.ts +16 -0
- package/dist/packages/bunshot-auth/src/lib/validateAdapter.js +161 -0
- package/dist/packages/bunshot-auth/src/middleware/bearerAuth.d.ts +13 -0
- package/dist/packages/bunshot-auth/src/middleware/bearerAuth.js +58 -0
- package/dist/{middleware → packages/bunshot-auth/src/middleware}/csrf.d.ts +5 -4
- package/dist/packages/bunshot-auth/src/middleware/csrf.js +138 -0
- package/dist/packages/bunshot-auth/src/middleware/identify.d.ts +4 -0
- package/dist/packages/bunshot-auth/src/middleware/identify.js +124 -0
- package/dist/{middleware → packages/bunshot-auth/src/middleware}/requireMfaSetup.d.ts +2 -2
- package/dist/{middleware → packages/bunshot-auth/src/middleware}/requireMfaSetup.js +10 -8
- package/dist/{middleware → packages/bunshot-auth/src/middleware}/requireRole.d.ts +2 -2
- package/dist/{middleware → packages/bunshot-auth/src/middleware}/requireRole.js +20 -16
- package/dist/{middleware → packages/bunshot-auth/src/middleware}/requireScope.d.ts +2 -2
- package/dist/{middleware → packages/bunshot-auth/src/middleware}/requireScope.js +6 -6
- package/dist/{middleware → packages/bunshot-auth/src/middleware}/requireStepUp.d.ts +2 -2
- package/dist/{middleware → packages/bunshot-auth/src/middleware}/requireStepUp.js +8 -7
- package/dist/{middleware → packages/bunshot-auth/src/middleware}/requireVerifiedEmail.d.ts +2 -2
- package/dist/{middleware → packages/bunshot-auth/src/middleware}/requireVerifiedEmail.js +7 -6
- package/dist/packages/bunshot-auth/src/middleware/scimAuth.d.ts +8 -0
- package/dist/packages/bunshot-auth/src/middleware/scimAuth.js +29 -0
- package/dist/packages/bunshot-auth/src/middleware/userAuth.d.ts +3 -0
- package/dist/packages/bunshot-auth/src/middleware/userAuth.js +6 -0
- package/dist/{models → packages/bunshot-auth/src/models}/AuthUser.d.ts +12 -8
- package/dist/packages/bunshot-auth/src/models/AuthUser.js +53 -0
- package/dist/packages/bunshot-auth/src/models/Group.d.ts +19 -0
- package/dist/packages/bunshot-auth/src/models/Group.js +22 -0
- package/dist/{models → packages/bunshot-auth/src/models}/GroupMembership.d.ts +6 -8
- package/dist/packages/bunshot-auth/src/models/GroupMembership.js +19 -0
- package/dist/{models → packages/bunshot-auth/src/models}/M2MClient.d.ts +1 -1
- package/dist/{models → packages/bunshot-auth/src/models}/M2MClient.js +5 -5
- package/dist/packages/bunshot-auth/src/models/TenantRole.d.ts +13 -0
- package/dist/packages/bunshot-auth/src/models/TenantRole.js +17 -0
- package/dist/packages/bunshot-auth/src/plugin.d.ts +4 -0
- package/dist/packages/bunshot-auth/src/plugin.js +274 -0
- package/dist/packages/bunshot-auth/src/routes/auth.d.ts +15 -0
- package/dist/packages/bunshot-auth/src/routes/auth.js +1624 -0
- package/dist/packages/bunshot-auth/src/routes/groups.d.ts +4 -0
- package/dist/packages/bunshot-auth/src/routes/groups.js +481 -0
- package/dist/packages/bunshot-auth/src/routes/m2m.d.ts +2 -0
- package/dist/packages/bunshot-auth/src/routes/m2m.js +145 -0
- package/dist/packages/bunshot-auth/src/routes/mfa.d.ts +6 -0
- package/dist/packages/bunshot-auth/src/routes/mfa.js +991 -0
- package/dist/packages/bunshot-auth/src/routes/oauth.d.ts +3 -0
- package/dist/packages/bunshot-auth/src/routes/oauth.js +1727 -0
- package/dist/packages/bunshot-auth/src/routes/oidc.d.ts +2 -0
- package/dist/packages/bunshot-auth/src/routes/oidc.js +84 -0
- package/dist/packages/bunshot-auth/src/routes/organizations.d.ts +3 -0
- package/dist/packages/bunshot-auth/src/routes/organizations.js +741 -0
- package/dist/packages/bunshot-auth/src/routes/passkey.d.ts +2 -0
- package/dist/packages/bunshot-auth/src/routes/passkey.js +199 -0
- package/dist/packages/bunshot-auth/src/routes/saml.d.ts +2 -0
- package/dist/packages/bunshot-auth/src/routes/saml.js +226 -0
- package/dist/packages/bunshot-auth/src/routes/scim.d.ts +3 -0
- package/dist/packages/bunshot-auth/src/routes/scim.js +588 -0
- package/dist/packages/bunshot-auth/src/runtime.d.ts +52 -0
- package/dist/packages/bunshot-auth/src/runtime.js +11 -0
- package/dist/{schemas → packages/bunshot-auth/src/schemas}/auth.d.ts +4 -5
- package/dist/packages/bunshot-auth/src/schemas/auth.js +24 -0
- package/dist/packages/bunshot-auth/src/schemas/error.d.ts +10 -0
- package/dist/packages/bunshot-auth/src/schemas/error.js +10 -0
- package/dist/packages/bunshot-auth/src/schemas/success.d.ts +10 -0
- package/dist/packages/bunshot-auth/src/schemas/success.js +10 -0
- package/dist/packages/bunshot-auth/src/services/auth.d.ts +39 -0
- package/dist/packages/bunshot-auth/src/services/auth.js +378 -0
- package/dist/{services → packages/bunshot-auth/src/services}/mfa.d.ts +41 -17
- package/dist/{services → packages/bunshot-auth/src/services}/mfa.js +259 -183
- package/dist/packages/bunshot-auth/src/testing.d.ts +31 -0
- package/dist/packages/bunshot-auth/src/testing.js +23 -0
- package/dist/packages/bunshot-auth/src/types/adapter.d.ts +1 -0
- package/dist/packages/bunshot-auth/src/types/adapter.js +1 -0
- package/dist/packages/bunshot-auth/src/types/config.d.ts +152 -0
- package/dist/packages/bunshot-auth/src/types/config.js +179 -0
- package/dist/{routes → packages/bunshot-auth/src/types}/groups.d.ts +2 -3
- package/dist/packages/bunshot-auth/src/types/groups.js +1 -0
- package/dist/packages/bunshot-auth/src/types/oauthCode.d.ts +6 -0
- package/dist/packages/bunshot-auth/src/types/oauthCode.js +1 -0
- package/dist/packages/bunshot-auth/src/types/oauthReauth.d.ts +13 -0
- package/dist/packages/bunshot-auth/src/types/oauthReauth.js +1 -0
- package/dist/packages/bunshot-auth/src/types/redis.d.ts +1 -0
- package/dist/packages/bunshot-auth/src/types/redis.js +1 -0
- package/dist/packages/bunshot-auth/src/types/saml.d.ts +10 -0
- package/dist/packages/bunshot-auth/src/types/saml.js +1 -0
- package/dist/packages/bunshot-auth/src/types/session.d.ts +18 -0
- package/dist/packages/bunshot-auth/src/types/session.js +1 -0
- package/dist/packages/bunshot-auth/src/types/store.d.ts +1 -0
- package/dist/packages/bunshot-auth/src/types/store.js +1 -0
- package/dist/packages/bunshot-core/src/adminProvider.d.ts +95 -0
- package/dist/packages/bunshot-core/src/adminProvider.js +1 -0
- package/dist/packages/bunshot-core/src/auditLog.d.ts +34 -0
- package/dist/packages/bunshot-core/src/auditLog.js +1 -0
- package/dist/packages/bunshot-core/src/auth-adapter.d.ts +227 -0
- package/dist/packages/bunshot-core/src/auth-adapter.js +4 -0
- package/dist/packages/bunshot-core/src/authVariables.d.ts +14 -0
- package/dist/packages/bunshot-core/src/authVariables.js +4 -0
- package/dist/packages/bunshot-core/src/cache.d.ts +12 -0
- package/dist/packages/bunshot-core/src/cache.js +21 -0
- package/dist/{lib → packages/bunshot-core/src}/captcha.d.ts +1 -10
- package/dist/packages/bunshot-core/src/captcha.js +1 -0
- package/dist/packages/bunshot-core/src/clearRegistry.d.ts +6 -0
- package/dist/packages/bunshot-core/src/clearRegistry.js +17 -0
- package/dist/packages/bunshot-core/src/clientIp.d.ts +3 -0
- package/dist/packages/bunshot-core/src/clientIp.js +45 -0
- package/dist/packages/bunshot-core/src/configLock.d.ts +4 -0
- package/dist/packages/bunshot-core/src/configLock.js +7 -0
- package/dist/packages/bunshot-core/src/configValidation.d.ts +22 -0
- package/dist/packages/bunshot-core/src/configValidation.js +39 -0
- package/dist/packages/bunshot-core/src/constants.js +10 -0
- package/dist/packages/bunshot-core/src/context/bunshotContext.d.ts +232 -0
- package/dist/packages/bunshot-core/src/context/bunshotContext.js +1 -0
- package/dist/packages/bunshot-core/src/context/contextAccess.d.ts +3 -0
- package/dist/packages/bunshot-core/src/context/contextAccess.js +16 -0
- package/dist/packages/bunshot-core/src/context/contextStore.d.ts +16 -0
- package/dist/packages/bunshot-core/src/context/contextStore.js +31 -0
- package/dist/packages/bunshot-core/src/context/frameworkConfig.d.ts +38 -0
- package/dist/packages/bunshot-core/src/context/frameworkConfig.js +1 -0
- package/dist/packages/bunshot-core/src/context/index.d.ts +4 -0
- package/dist/packages/bunshot-core/src/context/index.js +2 -0
- package/dist/packages/bunshot-core/src/context.d.ts +40 -0
- package/dist/packages/bunshot-core/src/context.js +35 -0
- package/dist/packages/bunshot-core/src/coreContracts.d.ts +47 -0
- package/dist/packages/bunshot-core/src/coreContracts.js +1 -0
- package/dist/packages/bunshot-core/src/coreRegistrar.d.ts +6 -0
- package/dist/packages/bunshot-core/src/coreRegistrar.js +42 -0
- package/dist/{lib → packages/bunshot-core/src}/createRoute.d.ts +4 -30
- package/dist/{lib → packages/bunshot-core/src}/createRoute.js +39 -88
- package/dist/packages/bunshot-core/src/cronRegistry.d.ts +11 -0
- package/dist/packages/bunshot-core/src/cronRegistry.js +1 -0
- package/dist/packages/bunshot-core/src/crypto.d.ts +43 -0
- package/dist/packages/bunshot-core/src/crypto.js +74 -0
- package/dist/packages/bunshot-core/src/csrf.d.ts +8 -0
- package/dist/packages/bunshot-core/src/csrf.js +1 -0
- package/dist/packages/bunshot-core/src/defaults/defaultFingerprint.d.ts +7 -0
- package/dist/packages/bunshot-core/src/defaults/defaultFingerprint.js +19 -0
- package/dist/packages/bunshot-core/src/defaults/memoryCacheAdapter.d.ts +6 -0
- package/dist/packages/bunshot-core/src/defaults/memoryCacheAdapter.js +40 -0
- package/dist/packages/bunshot-core/src/defaults/memoryRateLimit.d.ts +6 -0
- package/dist/packages/bunshot-core/src/defaults/memoryRateLimit.js +24 -0
- package/dist/packages/bunshot-core/src/emailTemplates.d.ts +5 -0
- package/dist/packages/bunshot-core/src/emailTemplates.js +10 -0
- package/dist/{lib/HttpError.d.ts → packages/bunshot-core/src/errors.d.ts} +4 -1
- package/dist/{lib/HttpError.js → packages/bunshot-core/src/errors.js} +7 -1
- package/dist/packages/bunshot-core/src/eventBus.d.ts +270 -0
- package/dist/packages/bunshot-core/src/eventBus.js +143 -0
- package/dist/packages/bunshot-core/src/idempotency.d.ts +18 -0
- package/dist/packages/bunshot-core/src/idempotency.js +1 -0
- package/dist/packages/bunshot-core/src/index.d.ts +60 -0
- package/dist/packages/bunshot-core/src/index.js +34 -0
- package/dist/packages/bunshot-core/src/mail.d.ts +14 -0
- package/dist/packages/bunshot-core/src/mail.js +8 -0
- package/dist/packages/bunshot-core/src/memoryEviction.d.ts +24 -0
- package/dist/packages/bunshot-core/src/memoryEviction.js +52 -0
- package/dist/packages/bunshot-core/src/pagination.d.ts +45 -0
- package/dist/packages/bunshot-core/src/pagination.js +61 -0
- package/dist/packages/bunshot-core/src/permissions.d.ts +64 -0
- package/dist/packages/bunshot-core/src/permissions.js +27 -0
- package/dist/packages/bunshot-core/src/plugin.d.ts +44 -0
- package/dist/packages/bunshot-core/src/plugin.js +1 -0
- package/dist/packages/bunshot-core/src/rateLimit.d.ts +5 -0
- package/dist/packages/bunshot-core/src/rateLimit.js +18 -0
- package/dist/packages/bunshot-core/src/redis.d.ts +21 -0
- package/dist/packages/bunshot-core/src/redis.js +1 -0
- package/dist/packages/bunshot-core/src/routeAuth.d.ts +5 -0
- package/dist/packages/bunshot-core/src/routeAuth.js +11 -0
- package/dist/packages/bunshot-core/src/routeOverrides.d.ts +24 -0
- package/dist/packages/bunshot-core/src/routeOverrides.js +25 -0
- package/dist/packages/bunshot-core/src/routerAdapter.d.ts +6 -0
- package/dist/packages/bunshot-core/src/routerAdapter.js +56 -0
- package/dist/packages/bunshot-core/src/secrets.d.ts +48 -0
- package/dist/packages/bunshot-core/src/secrets.js +8 -0
- package/dist/packages/bunshot-core/src/signing.d.ts +41 -0
- package/dist/packages/bunshot-core/src/signing.js +1 -0
- package/dist/packages/bunshot-core/src/sse.d.ts +36 -0
- package/dist/packages/bunshot-core/src/sse.js +1 -0
- package/dist/packages/bunshot-core/src/storageAdapter.js +1 -0
- package/dist/packages/bunshot-core/src/storeInfra.d.ts +44 -0
- package/dist/packages/bunshot-core/src/storeInfra.js +18 -0
- package/dist/packages/bunshot-core/src/storeType.d.ts +7 -0
- package/dist/packages/bunshot-core/src/storeType.js +1 -0
- package/dist/packages/bunshot-core/src/testing.d.ts +1 -0
- package/dist/packages/bunshot-core/src/testing.js +1 -0
- package/dist/packages/bunshot-core/src/uploadRegistry.d.ts +23 -0
- package/dist/packages/bunshot-core/src/uploadRegistry.js +4 -0
- package/dist/packages/bunshot-core/src/userResolver.d.ts +5 -0
- package/dist/packages/bunshot-core/src/userResolver.js +14 -0
- package/dist/packages/bunshot-core/src/wsMessages.d.ts +42 -0
- package/dist/packages/bunshot-core/src/wsMessages.js +4 -0
- package/dist/packages/bunshot-permissions/src/adapters/memory.d.ts +7 -0
- package/dist/packages/bunshot-permissions/src/adapters/memory.js +73 -0
- package/dist/packages/bunshot-permissions/src/index.d.ts +10 -0
- package/dist/packages/bunshot-permissions/src/index.js +5 -0
- package/dist/packages/bunshot-permissions/src/lib/bootstrap.d.ts +7 -0
- package/dist/packages/bunshot-permissions/src/lib/bootstrap.js +12 -0
- package/dist/packages/bunshot-permissions/src/lib/evaluator.d.ts +10 -0
- package/dist/packages/bunshot-permissions/src/lib/evaluator.js +165 -0
- package/dist/packages/bunshot-permissions/src/lib/registry.d.ts +2 -0
- package/dist/packages/bunshot-permissions/src/lib/registry.js +31 -0
- package/dist/packages/bunshot-permissions/src/lib/validation.d.ts +1 -0
- package/dist/packages/bunshot-permissions/src/lib/validation.js +1 -0
- package/dist/packages/bunshot-permissions/src/types/adapter.d.ts +1 -0
- package/dist/packages/bunshot-permissions/src/types/adapter.js +1 -0
- package/dist/packages/bunshot-permissions/src/types/evaluator.d.ts +1 -0
- package/dist/packages/bunshot-permissions/src/types/evaluator.js +1 -0
- package/dist/packages/bunshot-permissions/src/types/models.d.ts +1 -0
- package/dist/packages/bunshot-permissions/src/types/models.js +1 -0
- package/dist/packages/bunshot-permissions/src/types/registry.d.ts +1 -0
- package/dist/packages/bunshot-permissions/src/types/registry.js +1 -0
- package/dist/packages/bunshot-postgres/src/adapter.d.ts +6 -0
- package/dist/packages/bunshot-postgres/src/adapter.js +794 -0
- package/dist/packages/bunshot-postgres/src/connection.d.ts +15 -0
- package/dist/packages/bunshot-postgres/src/connection.js +16 -0
- package/dist/packages/bunshot-postgres/src/index.d.ts +4 -0
- package/dist/packages/bunshot-postgres/src/index.js +2 -0
- package/dist/packages/bunshot-postgres/src/schema.d.ts +997 -0
- package/dist/packages/bunshot-postgres/src/schema.js +105 -0
- package/dist/src/app.d.ts +230 -0
- package/dist/src/app.js +182 -0
- package/dist/src/cli/commands/init.d.ts +10 -0
- package/dist/src/cli/commands/init.js +709 -0
- package/dist/src/cli/index.d.ts +1 -0
- package/dist/src/cli/index.js +3 -0
- package/dist/src/entrypoints/mongo.d.ts +6 -0
- package/dist/src/entrypoints/mongo.js +4 -0
- package/dist/src/entrypoints/queue.d.ts +2 -0
- package/dist/src/entrypoints/queue.js +1 -0
- package/dist/src/entrypoints/redis.d.ts +1 -0
- package/dist/src/entrypoints/redis.js +1 -0
- package/dist/{adapters → src/framework/adapters}/localStorage.d.ts +1 -1
- package/dist/{adapters → src/framework/adapters}/localStorage.js +10 -10
- package/dist/src/framework/adapters/memoryStorage.d.ts +2 -0
- package/dist/src/framework/adapters/memoryStorage.js +45 -0
- package/dist/{adapters → src/framework/adapters}/s3Storage.d.ts +1 -1
- package/dist/{adapters → src/framework/adapters}/s3Storage.js +12 -12
- package/dist/src/framework/admin/bunshotAccess.d.ts +2 -0
- package/dist/src/framework/admin/bunshotAccess.js +23 -0
- package/dist/src/framework/admin/bunshotUsers.d.ts +2 -0
- package/dist/src/framework/admin/bunshotUsers.js +103 -0
- package/dist/src/framework/admin/index.d.ts +7 -0
- package/dist/src/framework/admin/index.js +21 -0
- package/dist/src/framework/boundaryAdapters/cacheFactories.d.ts +13 -0
- package/dist/src/framework/boundaryAdapters/cacheFactories.js +86 -0
- package/dist/src/framework/boundaryAdapters/index.d.ts +2 -0
- package/dist/src/framework/boundaryAdapters/index.js +1 -0
- package/dist/src/framework/boundaryAdapters.d.ts +17 -0
- package/dist/src/framework/boundaryAdapters.js +62 -0
- package/dist/src/framework/buildContext.d.ts +33 -0
- package/dist/src/framework/buildContext.js +119 -0
- package/dist/src/framework/config/schema.d.ts +447 -0
- package/dist/src/framework/config/schema.js +528 -0
- package/dist/src/framework/createInfrastructure.d.ts +76 -0
- package/dist/src/framework/createInfrastructure.js +221 -0
- package/dist/src/framework/lib/auditLog.d.ts +23 -0
- package/dist/src/framework/lib/auditLog.js +416 -0
- package/dist/src/framework/lib/captcha.d.ts +11 -0
- package/dist/{lib → src/framework/lib}/captcha.js +13 -10
- package/dist/{lib → src/framework/lib}/createDtoMapper.js +4 -4
- package/dist/src/framework/lib/createRoute.d.ts +1 -0
- package/dist/src/framework/lib/createRoute.js +2 -0
- package/dist/{lib → src/framework/lib}/idempotency.d.ts +2 -6
- package/dist/src/framework/lib/idempotency.js +74 -0
- package/dist/src/framework/lib/logger.d.ts +3 -0
- package/dist/src/framework/lib/logger.js +14 -0
- package/dist/src/framework/lib/metrics.d.ts +34 -0
- package/dist/{lib → src/framework/lib}/metrics.js +49 -57
- package/dist/src/framework/lib/pagination.d.ts +42 -0
- package/dist/src/framework/lib/pagination.js +51 -0
- package/dist/src/framework/lib/redisTransport.d.ts +38 -0
- package/dist/src/framework/lib/redisTransport.js +107 -0
- package/dist/src/framework/lib/resolveUserId.d.ts +2 -0
- package/dist/src/framework/lib/resolveUserId.js +5 -0
- package/dist/src/framework/lib/sseCollision.d.ts +6 -0
- package/dist/src/framework/lib/sseCollision.js +26 -0
- package/dist/src/framework/lib/storageAdapter.d.ts +1 -0
- package/dist/src/framework/lib/storageAdapter.js +1 -0
- package/dist/{lib → src/framework/lib}/stripUnreferencedSchemas.js +4 -4
- package/dist/src/framework/lib/tenant.d.ts +21 -0
- package/dist/src/framework/lib/tenant.js +70 -0
- package/dist/{lib → src/framework/lib}/upload.d.ts +11 -10
- package/dist/src/framework/lib/upload.js +132 -0
- package/dist/src/framework/lib/uploadRegistry.d.ts +23 -0
- package/dist/src/framework/lib/uploadRegistry.js +34 -0
- package/dist/{lib → src/framework/lib}/validate.d.ts +1 -1
- package/dist/{lib → src/framework/lib}/validate.js +2 -2
- package/dist/src/framework/lib/ws.d.ts +19 -0
- package/dist/src/framework/lib/ws.js +130 -0
- package/dist/src/framework/lib/wsHeartbeat.d.ts +12 -0
- package/dist/src/framework/lib/wsHeartbeat.js +53 -0
- package/dist/src/framework/lib/wsMessages.d.ts +25 -0
- package/dist/src/framework/lib/wsMessages.js +45 -0
- package/dist/src/framework/lib/wsNamespace.d.ts +17 -0
- package/dist/src/framework/lib/wsNamespace.js +19 -0
- package/dist/src/framework/lib/wsPresence.d.ts +17 -0
- package/dist/src/framework/lib/wsPresence.js +84 -0
- package/dist/src/framework/lib/wsTransport.d.ts +38 -0
- package/dist/src/framework/lib/wsTransport.js +9 -0
- package/dist/{lib → src/framework/lib}/zodToMongoose.d.ts +1 -1
- package/dist/{lib → src/framework/lib}/zodToMongoose.js +11 -11
- package/dist/{middleware → src/framework/middleware}/auditLog.d.ts +4 -3
- package/dist/src/framework/middleware/auditLog.js +42 -0
- package/dist/{middleware → src/framework/middleware}/botProtection.d.ts +2 -2
- package/dist/{middleware → src/framework/middleware}/botProtection.js +8 -9
- package/dist/src/framework/middleware/cacheResponse.d.ts +35 -0
- package/dist/src/framework/middleware/cacheResponse.js +126 -0
- package/dist/{middleware → src/framework/middleware}/captcha.d.ts +2 -3
- package/dist/src/framework/middleware/captcha.js +37 -0
- package/dist/{middleware → src/framework/middleware}/errorHandler.d.ts +1 -1
- package/dist/{middleware → src/framework/middleware}/errorHandler.js +2 -2
- package/dist/src/framework/middleware/index.js +1 -0
- package/dist/{middleware → src/framework/middleware}/logger.d.ts +1 -1
- package/dist/src/framework/middleware/metrics.d.ts +12 -0
- package/dist/src/framework/middleware/metrics.js +26 -0
- package/dist/{middleware → src/framework/middleware}/rateLimit.d.ts +2 -2
- package/dist/src/framework/middleware/rateLimit.js +22 -0
- package/dist/src/framework/middleware/requestId.d.ts +3 -0
- package/dist/{middleware → src/framework/middleware}/requestId.js +2 -2
- package/dist/{middleware → src/framework/middleware}/requestLogger.d.ts +3 -3
- package/dist/{middleware → src/framework/middleware}/requestLogger.js +17 -12
- package/dist/{middleware → src/framework/middleware}/requestSigning.d.ts +2 -2
- package/dist/{middleware → src/framework/middleware}/requestSigning.js +18 -20
- package/dist/src/framework/middleware/tenant.d.ts +14 -0
- package/dist/{middleware → src/framework/middleware}/tenant.js +31 -27
- package/dist/src/framework/middleware/upload.d.ts +5 -0
- package/dist/{middleware → src/framework/middleware}/upload.js +4 -4
- package/dist/{middleware → src/framework/middleware}/webhookAuth.d.ts +3 -3
- package/dist/{middleware → src/framework/middleware}/webhookAuth.js +11 -12
- package/dist/src/framework/models/AuditLog.d.ts +21 -0
- package/dist/src/framework/models/AuditLog.js +31 -0
- package/dist/src/framework/mountMiddleware.d.ts +91 -0
- package/dist/src/framework/mountMiddleware.js +128 -0
- package/dist/src/framework/mountOptionalEndpoints.d.ts +103 -0
- package/dist/src/framework/mountOptionalEndpoints.js +47 -0
- package/dist/src/framework/mountRoutes.d.ts +21 -0
- package/dist/src/framework/mountRoutes.js +144 -0
- package/dist/src/framework/persistence/cronRegistry.d.ts +28 -0
- package/dist/src/framework/persistence/cronRegistry.js +139 -0
- package/dist/src/framework/persistence/idempotency.d.ts +26 -0
- package/dist/src/framework/persistence/idempotency.js +178 -0
- package/dist/src/framework/persistence/index.d.ts +6 -0
- package/dist/src/framework/persistence/index.js +8 -0
- package/dist/src/framework/persistence/storeInfra.d.ts +9 -0
- package/dist/src/framework/persistence/storeInfra.js +1 -0
- package/dist/src/framework/persistence/uploadRegistry.d.ts +35 -0
- package/dist/src/framework/persistence/uploadRegistry.js +235 -0
- package/dist/src/framework/persistence/wsMessages.d.ts +22 -0
- package/dist/src/framework/persistence/wsMessages.js +296 -0
- package/dist/src/framework/preloadSchemas.d.ts +24 -0
- package/dist/src/framework/preloadSchemas.js +42 -0
- package/dist/src/framework/registerBoundaryAdapters.d.ts +23 -0
- package/dist/src/framework/registerBoundaryAdapters.js +46 -0
- package/dist/src/framework/routes/admin.d.ts +9 -0
- package/dist/src/framework/routes/admin.js +361 -0
- package/dist/src/framework/routes/health.d.ts +1 -0
- package/dist/src/framework/routes/health.js +21 -0
- package/dist/src/framework/routes/home.d.ts +1 -0
- package/dist/src/framework/routes/home.js +18 -0
- package/dist/src/framework/routes/jobs.d.ts +3 -0
- package/dist/{routes → src/framework/routes}/jobs.js +128 -103
- package/dist/src/framework/routes/metrics.d.ts +10 -0
- package/dist/src/framework/routes/metrics.js +57 -0
- package/dist/{routes → src/framework/routes}/uploads.d.ts +3 -3
- package/dist/src/framework/routes/uploads.js +262 -0
- package/dist/src/framework/runPluginLifecycle.d.ts +27 -0
- package/dist/src/framework/runPluginLifecycle.js +121 -0
- package/dist/src/framework/secrets/frameworkSecretSchema.d.ts +58 -0
- package/dist/src/framework/secrets/frameworkSecretSchema.js +20 -0
- package/dist/src/framework/secrets/index.d.ts +9 -0
- package/dist/src/framework/secrets/index.js +7 -0
- package/dist/src/framework/secrets/providers/envProvider.d.ts +15 -0
- package/dist/src/framework/secrets/providers/envProvider.js +18 -0
- package/dist/src/framework/secrets/providers/fileProvider.d.ts +8 -0
- package/dist/src/framework/secrets/providers/fileProvider.js +82 -0
- package/dist/src/framework/secrets/providers/ssmProvider.d.ts +20 -0
- package/dist/src/framework/secrets/providers/ssmProvider.js +127 -0
- package/dist/src/framework/secrets/resolveSecretBundle.d.ts +53 -0
- package/dist/src/framework/secrets/resolveSecretBundle.js +84 -0
- package/dist/src/framework/secrets/resolveSecrets.d.ts +18 -0
- package/dist/src/framework/secrets/resolveSecrets.js +34 -0
- package/dist/src/framework/sse/index.d.ts +21 -0
- package/dist/src/framework/sse/index.js +109 -0
- package/dist/src/framework/ws/index.d.ts +11 -0
- package/dist/src/framework/ws/index.js +8 -0
- package/dist/src/index.d.ts +87 -0
- package/dist/src/index.js +58 -0
- package/dist/src/lib/appConfig.d.ts +7 -0
- package/dist/src/lib/appConfig.js +27 -0
- package/dist/src/lib/appMeta.d.ts +7 -0
- package/dist/src/lib/appMeta.js +3 -0
- package/dist/src/lib/authConfig.d.ts +532 -0
- package/dist/{lib/appConfig.js → src/lib/authConfig.js} +75 -17
- package/dist/{lib → src/lib}/context.d.ts +6 -12
- package/dist/{lib → src/lib}/context.js +5 -5
- package/dist/src/lib/logger.d.ts +1 -0
- package/dist/src/lib/logger.js +1 -0
- package/dist/src/lib/mongo.d.ts +58 -0
- package/dist/src/lib/mongo.js +96 -0
- package/dist/src/lib/queue.d.ts +72 -0
- package/dist/src/lib/queue.js +152 -0
- package/dist/src/lib/redis.d.ts +28 -0
- package/dist/src/lib/redis.js +72 -0
- package/dist/{lib → src/lib}/signing.d.ts +2 -2
- package/dist/src/lib/signing.js +210 -0
- package/dist/src/lib/signingConfig.d.ts +40 -0
- package/dist/src/lib/signingConfig.js +28 -0
- package/dist/src/server.d.ts +146 -0
- package/dist/src/server.js +469 -0
- package/dist/src/shared/lib/HttpError.d.ts +1 -0
- package/dist/src/shared/lib/HttpError.js +2 -0
- package/dist/src/shared/lib/constants.d.ts +10 -0
- package/dist/src/shared/lib/crypto.d.ts +43 -0
- package/dist/src/shared/lib/crypto.js +74 -0
- package/dist/src/shared/lib/signing.d.ts +52 -0
- package/dist/{lib → src/shared/lib}/signing.js +35 -8
- package/dist/src/testing.d.ts +34 -0
- package/dist/src/testing.js +93 -0
- package/package.json +60 -24
- package/dist/adapters/memoryAuth.d.ts +0 -52
- package/dist/adapters/memoryAuth.js +0 -749
- package/dist/adapters/memoryStorage.d.ts +0 -3
- package/dist/adapters/memoryStorage.js +0 -44
- package/dist/adapters/mongoAuth.d.ts +0 -2
- package/dist/adapters/mongoAuth.js +0 -403
- package/dist/adapters/sqliteAuth.d.ts +0 -72
- package/dist/adapters/sqliteAuth.js +0 -858
- package/dist/app.d.ts +0 -559
- package/dist/app.js +0 -651
- package/dist/entrypoints/mongo.d.ts +0 -5
- package/dist/entrypoints/mongo.js +0 -4
- package/dist/entrypoints/queue.d.ts +0 -2
- package/dist/entrypoints/queue.js +0 -1
- package/dist/entrypoints/redis.d.ts +0 -1
- package/dist/entrypoints/redis.js +0 -1
- package/dist/index.d.ts +0 -117
- package/dist/index.js +0 -88
- package/dist/lib/appConfig.d.ts +0 -275
- package/dist/lib/auditLog.d.ts +0 -58
- package/dist/lib/auditLog.js +0 -218
- package/dist/lib/authAdapter.d.ts +0 -246
- package/dist/lib/authAdapter.js +0 -7
- package/dist/lib/authRateLimit.d.ts +0 -13
- package/dist/lib/authRateLimit.js +0 -117
- package/dist/lib/clientIp.d.ts +0 -14
- package/dist/lib/credentialStuffing.d.ts +0 -31
- package/dist/lib/credentialStuffing.js +0 -77
- package/dist/lib/crypto.d.ts +0 -11
- package/dist/lib/crypto.js +0 -22
- package/dist/lib/deletionCancelToken.d.ts +0 -12
- package/dist/lib/deletionCancelToken.js +0 -88
- package/dist/lib/emailVerification.d.ts +0 -19
- package/dist/lib/emailVerification.js +0 -129
- package/dist/lib/fingerprint.js +0 -36
- package/dist/lib/idempotency.js +0 -182
- package/dist/lib/jwks.d.ts +0 -25
- package/dist/lib/jwks.js +0 -51
- package/dist/lib/jwt.d.ts +0 -15
- package/dist/lib/jwt.js +0 -111
- package/dist/lib/metrics.d.ts +0 -14
- package/dist/lib/mfaChallenge.d.ts +0 -55
- package/dist/lib/mfaChallenge.js +0 -398
- package/dist/lib/mongo.d.ts +0 -39
- package/dist/lib/mongo.js +0 -124
- package/dist/lib/oauth.d.ts +0 -40
- package/dist/lib/oauth.js +0 -101
- package/dist/lib/oauthCode.d.ts +0 -15
- package/dist/lib/oauthCode.js +0 -95
- package/dist/lib/pagination.d.ts +0 -119
- package/dist/lib/pagination.js +0 -166
- package/dist/lib/queue.d.ts +0 -37
- package/dist/lib/queue.js +0 -117
- package/dist/lib/redis.d.ts +0 -9
- package/dist/lib/redis.js +0 -61
- package/dist/lib/resetPassword.d.ts +0 -12
- package/dist/lib/resetPassword.js +0 -93
- package/dist/lib/roles.d.ts +0 -7
- package/dist/lib/roles.js +0 -49
- package/dist/lib/saml.d.ts +0 -25
- package/dist/lib/saml.js +0 -64
- package/dist/lib/securityEvents.d.ts +0 -28
- package/dist/lib/securityEvents.js +0 -26
- package/dist/lib/session.d.ts +0 -49
- package/dist/lib/session.js +0 -597
- package/dist/lib/tenant.d.ts +0 -15
- package/dist/lib/tenant.js +0 -65
- package/dist/lib/upload.js +0 -112
- package/dist/lib/uploadRegistry.d.ts +0 -18
- package/dist/lib/uploadRegistry.js +0 -83
- package/dist/lib/ws.d.ts +0 -22
- package/dist/lib/ws.js +0 -96
- package/dist/lib/wsHeartbeat.d.ts +0 -12
- package/dist/lib/wsHeartbeat.js +0 -57
- package/dist/lib/wsMessages.d.ts +0 -40
- package/dist/lib/wsMessages.js +0 -330
- package/dist/lib/wsPresence.d.ts +0 -25
- package/dist/lib/wsPresence.js +0 -99
- package/dist/middleware/auditLog.js +0 -39
- package/dist/middleware/bearerAuth.d.ts +0 -2
- package/dist/middleware/bearerAuth.js +0 -11
- package/dist/middleware/cacheResponse.d.ts +0 -15
- package/dist/middleware/cacheResponse.js +0 -178
- package/dist/middleware/captcha.js +0 -36
- package/dist/middleware/csrf.js +0 -129
- package/dist/middleware/identify.d.ts +0 -3
- package/dist/middleware/identify.js +0 -122
- package/dist/middleware/index.js +0 -1
- package/dist/middleware/metrics.d.ts +0 -9
- package/dist/middleware/metrics.js +0 -26
- package/dist/middleware/rateLimit.js +0 -22
- package/dist/middleware/requestId.d.ts +0 -3
- package/dist/middleware/scimAuth.d.ts +0 -8
- package/dist/middleware/scimAuth.js +0 -29
- package/dist/middleware/tenant.d.ts +0 -5
- package/dist/middleware/upload.d.ts +0 -5
- package/dist/middleware/userAuth.d.ts +0 -3
- package/dist/middleware/userAuth.js +0 -6
- package/dist/models/AuditLog.d.ts +0 -30
- package/dist/models/AuditLog.js +0 -39
- package/dist/models/AuthUser.js +0 -55
- package/dist/models/Group.d.ts +0 -21
- package/dist/models/Group.js +0 -28
- package/dist/models/GroupMembership.js +0 -25
- package/dist/models/TenantRole.d.ts +0 -15
- package/dist/models/TenantRole.js +0 -23
- package/dist/routes/auth.d.ts +0 -12
- package/dist/routes/auth.js +0 -744
- package/dist/routes/groups.js +0 -346
- package/dist/routes/health.d.ts +0 -1
- package/dist/routes/health.js +0 -22
- package/dist/routes/home.d.ts +0 -1
- package/dist/routes/home.js +0 -16
- package/dist/routes/jobs.d.ts +0 -2
- package/dist/routes/m2m.d.ts +0 -2
- package/dist/routes/m2m.js +0 -72
- package/dist/routes/metrics.d.ts +0 -8
- package/dist/routes/metrics.js +0 -55
- package/dist/routes/mfa.d.ts +0 -5
- package/dist/routes/mfa.js +0 -628
- package/dist/routes/oauth.d.ts +0 -2
- package/dist/routes/oauth.js +0 -520
- package/dist/routes/oidc.d.ts +0 -2
- package/dist/routes/oidc.js +0 -29
- package/dist/routes/passkey.d.ts +0 -1
- package/dist/routes/passkey.js +0 -157
- package/dist/routes/saml.d.ts +0 -2
- package/dist/routes/saml.js +0 -86
- package/dist/routes/scim.d.ts +0 -2
- package/dist/routes/scim.js +0 -255
- package/dist/routes/uploads.js +0 -227
- package/dist/schemas/auth.js +0 -30
- package/dist/server.d.ts +0 -57
- package/dist/server.js +0 -112
- package/dist/services/auth.d.ts +0 -29
- package/dist/services/auth.js +0 -238
- package/dist/ws/index.d.ts +0 -10
- package/dist/ws/index.js +0 -39
- package/docs/sections/adding-middleware/full.md +0 -35
- package/docs/sections/adding-models/full.md +0 -125
- package/docs/sections/adding-models/overview.md +0 -13
- package/docs/sections/adding-routes/full.md +0 -182
- package/docs/sections/adding-routes/overview.md +0 -23
- package/docs/sections/auth-flow/full.md +0 -790
- package/docs/sections/auth-flow/overview.md +0 -10
- package/docs/sections/auth-security-examples/full.md +0 -388
- package/docs/sections/authentication/full.md +0 -130
- package/docs/sections/authentication/overview.md +0 -5
- package/docs/sections/cli/full.md +0 -42
- package/docs/sections/configuration/full.md +0 -172
- package/docs/sections/configuration/overview.md +0 -18
- package/docs/sections/configuration-example/full.md +0 -117
- package/docs/sections/configuration-example/overview.md +0 -30
- package/docs/sections/documentation/full.md +0 -171
- package/docs/sections/environment-variables/full.md +0 -55
- package/docs/sections/exports/full.md +0 -123
- package/docs/sections/extending-context/full.md +0 -59
- package/docs/sections/header.md +0 -3
- package/docs/sections/installation/full.md +0 -6
- package/docs/sections/jobs/full.md +0 -140
- package/docs/sections/jobs/overview.md +0 -15
- package/docs/sections/logging/full.md +0 -83
- package/docs/sections/metrics/full.md +0 -131
- package/docs/sections/mongodb-connections/full.md +0 -45
- package/docs/sections/mongodb-connections/overview.md +0 -7
- package/docs/sections/multi-tenancy/full.md +0 -66
- package/docs/sections/multi-tenancy/overview.md +0 -15
- package/docs/sections/oauth/full.md +0 -189
- package/docs/sections/oauth/overview.md +0 -16
- package/docs/sections/package-development/full.md +0 -7
- package/docs/sections/pagination/full.md +0 -93
- package/docs/sections/passkey-login/full.md +0 -90
- package/docs/sections/passkey-login/overview.md +0 -1
- package/docs/sections/peer-dependencies/full.md +0 -47
- package/docs/sections/quick-start/full.md +0 -43
- package/docs/sections/response-caching/full.md +0 -117
- package/docs/sections/response-caching/overview.md +0 -13
- package/docs/sections/roles/full.md +0 -225
- package/docs/sections/roles/overview.md +0 -14
- package/docs/sections/running-without-redis/full.md +0 -16
- package/docs/sections/running-without-redis-or-mongodb/full.md +0 -60
- package/docs/sections/signing/full.md +0 -203
- package/docs/sections/stack/full.md +0 -10
- package/docs/sections/uploads/full.md +0 -208
- package/docs/sections/versioning/full.md +0 -85
- package/docs/sections/webhook-auth/full.md +0 -100
- package/docs/sections/websocket/full.md +0 -196
- package/docs/sections/websocket/overview.md +0 -5
- package/docs/sections/websocket-rooms/full.md +0 -102
- package/docs/sections/websocket-rooms/overview.md +0 -5
- /package/dist/{lib/storageAdapter.js → packages/bunshot-admin/src/types/env.js} +0 -0
- /package/dist/{lib → packages/bunshot-auth/src/lib}/fingerprint.d.ts +0 -0
- /package/dist/{lib → packages/bunshot-auth/src/lib}/logger.d.ts +0 -0
- /package/dist/{lib → packages/bunshot-core/src}/constants.d.ts +0 -0
- /package/dist/{lib → packages/bunshot-core/src}/storageAdapter.d.ts +0 -0
- /package/dist/{lib → src/framework/lib}/createDtoMapper.d.ts +0 -0
- /package/dist/{lib → src/framework/lib}/stripUnreferencedSchemas.d.ts +0 -0
- /package/dist/{middleware → src/framework/middleware}/cors.d.ts +0 -0
- /package/dist/{middleware → src/framework/middleware}/cors.js +0 -0
- /package/dist/{middleware → src/framework/middleware}/index.d.ts +0 -0
- /package/dist/{middleware → src/framework/middleware}/logger.js +0 -0
- /package/dist/{lib → src/shared/lib}/constants.js +0 -0
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
### Auth Flow
|
|
2
|
-
|
|
3
|
-
Sessions are backed by Redis (default), MongoDB, SQLite, or memory. Each login creates an independent session keyed by UUID, so multiple devices stay logged in simultaneously.
|
|
4
|
-
|
|
5
|
-
- **Browser clients**: `POST /auth/login` sets an HttpOnly cookie automatically
|
|
6
|
-
- **API clients**: Read `token` from the response body, send `x-user-token: <token>` header
|
|
7
|
-
|
|
8
|
-
Features include session management (list/revoke), current user endpoint (`GET /auth/me`), email verification (opt-in, with `required` gate), password reset (fire-and-forget, dual-keyed rate limiting), refresh tokens (short-lived access + long-lived refresh with rotation), MFA (TOTP via Google Authenticator, email OTP, WebAuthn, recovery codes), account deletion (immediate or queued BullMQ with grace period and cancel endpoint), custom auth adapters, rate limiting on all auth endpoints, bot protection (fingerprint rate limiting + CIDR blocklist), configurable primary field (email/username/phone), and CSRF protection.
|
|
9
|
-
|
|
10
|
-
Protect routes with `userAuth`, `requireRole("admin")`, and `requireVerifiedEmail` middleware.
|
|
@@ -1,388 +0,0 @@
|
|
|
1
|
-
### Auth Security Examples
|
|
2
|
-
|
|
3
|
-
Five reference configurations covering common security postures. Each is a real `createServer` call you can adapt — not a checklist of options to mix and match blindly, since the right combination depends on what you're building.
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
#### Fintech / Healthcare — maximum security
|
|
8
|
-
|
|
9
|
-
Strict everything. MFA is mandatory for every user, sessions are short, passwords must be strong, and the app defends against distributed brute-force from day one.
|
|
10
|
-
|
|
11
|
-
```ts
|
|
12
|
-
await createServer({
|
|
13
|
-
auth: {
|
|
14
|
-
passwordPolicy: {
|
|
15
|
-
minLength: 12,
|
|
16
|
-
requireLetter: true,
|
|
17
|
-
requireDigit: true,
|
|
18
|
-
requireSpecial: true, // forces non-alphanumeric character
|
|
19
|
-
},
|
|
20
|
-
mfa: {
|
|
21
|
-
issuer: "FinApp",
|
|
22
|
-
required: true, // 403 MFA_SETUP_REQUIRED until user enrolls
|
|
23
|
-
recoveryCodes: 10,
|
|
24
|
-
challengeTtlSeconds: 180, // 3-minute window to complete MFA
|
|
25
|
-
},
|
|
26
|
-
emailVerification: {
|
|
27
|
-
required: true, // can't log in until email is verified
|
|
28
|
-
onSend: async (email, token) => {
|
|
29
|
-
await mailer.send(email, `Verify your email: https://app.com/verify?t=${token}`);
|
|
30
|
-
},
|
|
31
|
-
tokenExpiry: 3600, // 1-hour window to verify (not 24h)
|
|
32
|
-
},
|
|
33
|
-
passwordReset: {
|
|
34
|
-
tokenExpiry: 1800, // 30-minute reset window (tighter than default 1h)
|
|
35
|
-
onSend: async (email, token) => {
|
|
36
|
-
await mailer.send(email, `Reset: https://app.com/reset?t=${token}`);
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
refreshTokens: {
|
|
40
|
-
accessTokenExpiry: 900, // 15-minute access tokens
|
|
41
|
-
refreshTokenExpiry: 604_800, // 7-day refresh (not 30 — re-auth weekly)
|
|
42
|
-
rotationGraceSeconds: 30,
|
|
43
|
-
},
|
|
44
|
-
sessionPolicy: {
|
|
45
|
-
maxSessions: 3, // limit concurrent devices
|
|
46
|
-
trackLastActive: true,
|
|
47
|
-
persistSessionMetadata: true,
|
|
48
|
-
includeInactiveSessions: true, // full device history visible to user
|
|
49
|
-
},
|
|
50
|
-
rateLimit: {
|
|
51
|
-
login: { windowMs: 15 * 60 * 1000, max: 5 }, // 5 failures / 15 min
|
|
52
|
-
register: { windowMs: 60 * 60 * 1000, max: 3 }, // 3 signups / hour per IP
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
security: {
|
|
56
|
-
cors: ["https://app.com"],
|
|
57
|
-
trustProxy: 1, // one load balancer between internet and app
|
|
58
|
-
csrf: { enabled: true }, // cookie-based auth — CSRF protection required
|
|
59
|
-
rateLimit: { windowMs: 60_000, max: 60 }, // tighter global cap
|
|
60
|
-
botProtection: {
|
|
61
|
-
fingerprintRateLimit: true, // IP-rotators share a rate-limit bucket
|
|
62
|
-
blockList: [
|
|
63
|
-
"198.51.100.0/24", // known datacenter / proxy ranges
|
|
64
|
-
"203.0.113.0/24",
|
|
65
|
-
],
|
|
66
|
-
},
|
|
67
|
-
signing: {
|
|
68
|
-
// Session binding — ties each session to the IP + UA it was created with.
|
|
69
|
-
// A hijacked token presented from a different IP/UA is rejected outright.
|
|
70
|
-
sessionBinding: {
|
|
71
|
-
fields: ["ip", "ua"],
|
|
72
|
-
onMismatch: "reject", // 401 FINGERPRINT_MISMATCH — strict is appropriate here
|
|
73
|
-
},
|
|
74
|
-
// Require server-to-server API clients to HMAC-sign requests.
|
|
75
|
-
// Covers internal microservice calls and any non-browser client.
|
|
76
|
-
requestSigning: {
|
|
77
|
-
tolerance: 60_000, // 1-minute window (tighter than default 5 min)
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
**Key decisions:**
|
|
85
|
-
- `mfa.required: true` — unenrolled users are blocked from service endpoints until they complete setup. OAuth users are also affected.
|
|
86
|
-
- 7-day refresh tokens instead of 30-day — users re-authenticate weekly, which limits the blast radius if a refresh token is stolen.
|
|
87
|
-
- `includeInactiveSessions: true` — lets users see a full sign-in history and spot unauthorized access the way Google and Meta do.
|
|
88
|
-
- `csrf.enabled` — this app uses cookie auth; CSRF is a real threat.
|
|
89
|
-
- Dual-keyed forgot-password rate limiting (IP + email) is automatic — the config above just tightens the window.
|
|
90
|
-
- `sessionBinding` with `onMismatch: "reject"` — a session token presented from a different IP or user-agent is refused, not just silently treated as unauthenticated. Appropriate here; use `"log-only"` first if rolling out to an existing user base with mobile users on dynamic IPs.
|
|
91
|
-
- `requestSigning` — server-to-server calls from internal services must HMAC-sign the canonical request. Prevents replay attacks and body substitution in transit.
|
|
92
|
-
|
|
93
|
-
---
|
|
94
|
-
|
|
95
|
-
#### Consumer SaaS — social login with verification
|
|
96
|
-
|
|
97
|
-
Google and GitHub OAuth alongside credential login. Email must be verified before users can access the app. Opt-in MFA (users choose whether to enable it). Long-lived refresh tokens for a smooth "stay logged in" experience.
|
|
98
|
-
|
|
99
|
-
```ts
|
|
100
|
-
await createServer({
|
|
101
|
-
auth: {
|
|
102
|
-
roles: ["admin", "member"],
|
|
103
|
-
defaultRole: "member",
|
|
104
|
-
emailVerification: {
|
|
105
|
-
required: true,
|
|
106
|
-
onSend: async (email, token) => {
|
|
107
|
-
await resend.emails.send({
|
|
108
|
-
to: email,
|
|
109
|
-
subject: "Confirm your email",
|
|
110
|
-
html: `<a href="https://myapp.com/verify?token=${token}">Verify</a>`,
|
|
111
|
-
});
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
passwordReset: {
|
|
115
|
-
onSend: async (email, token) => {
|
|
116
|
-
await resend.emails.send({
|
|
117
|
-
to: email,
|
|
118
|
-
subject: "Reset your password",
|
|
119
|
-
html: `<a href="https://myapp.com/reset?token=${token}">Reset password</a>`,
|
|
120
|
-
});
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
mfa: {
|
|
124
|
-
issuer: "MySaaS",
|
|
125
|
-
// required not set — users opt in via account settings
|
|
126
|
-
},
|
|
127
|
-
refreshTokens: {
|
|
128
|
-
accessTokenExpiry: 900, // 15 min
|
|
129
|
-
refreshTokenExpiry: 2_592_000, // 30 days — "stay logged in"
|
|
130
|
-
},
|
|
131
|
-
sessionPolicy: {
|
|
132
|
-
trackLastActive: true, // sliding sessions via refresh
|
|
133
|
-
},
|
|
134
|
-
oauth: {
|
|
135
|
-
postRedirect: "/dashboard",
|
|
136
|
-
allowedRedirectUrls: ["https://myapp.com"],
|
|
137
|
-
providers: {
|
|
138
|
-
google: {
|
|
139
|
-
clientId: process.env.GOOGLE_CLIENT_ID!,
|
|
140
|
-
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
|
|
141
|
-
redirectUri: "https://myapp.com/auth/google/callback",
|
|
142
|
-
},
|
|
143
|
-
github: {
|
|
144
|
-
clientId: process.env.GITHUB_CLIENT_ID!,
|
|
145
|
-
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
|
|
146
|
-
redirectUri: "https://myapp.com/auth/github/callback",
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
security: {
|
|
152
|
-
cors: ["https://myapp.com", "https://staging.myapp.com"],
|
|
153
|
-
trustProxy: 1,
|
|
154
|
-
csrf: { enabled: true },
|
|
155
|
-
botProtection: {
|
|
156
|
-
fingerprintRateLimit: true,
|
|
157
|
-
},
|
|
158
|
-
signing: {
|
|
159
|
-
// Signed cursors — prevents clients from forging pagination cursors to
|
|
160
|
-
// access arbitrary pages. Tampered cursors are rejected with invalidCursor.
|
|
161
|
-
cursors: true,
|
|
162
|
-
// Hash idempotency keys before storage so users can't enumerate each
|
|
163
|
-
// other's pending operations by guessing short numeric keys.
|
|
164
|
-
idempotencyKeys: true,
|
|
165
|
-
// Presigned download URLs — lets the browser download private files
|
|
166
|
-
// directly without routing bytes through the API server.
|
|
167
|
-
presignedUrls: { defaultExpiry: 3600 },
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
});
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
**Key decisions:**
|
|
174
|
-
- OAuth users who share an email with a credential account get a `409` on login with a redirect to `?error=...`. They must sign in with their password and explicitly link the OAuth provider — email matching is never done automatically to prevent account takeover.
|
|
175
|
-
- `allowedRedirectUrls` prevents open-redirect abuse if a crafted `postRedirect` value is injected.
|
|
176
|
-
- MFA is opt-in, so the `mfa` block is present to enable the setup routes even though `required` is false. Users can enable it from their account page via `POST /auth/mfa/setup`.
|
|
177
|
-
- 30-day refresh tokens with `trackLastActive` give users a smooth experience without requiring them to log in every week.
|
|
178
|
-
- `cursors: true` — cursor-based pagination is used for activity feeds and search results; signing prevents users from skipping to arbitrary offsets by hand-crafting cursor values.
|
|
179
|
-
- `idempotencyKeys: true` + `idempotent()` middleware on payment/order routes — mount `idempotent()` on routes where duplicate submission is a real risk (checkout, subscription changes). The HMAC option prevents key enumeration if users pick short keys like `"order-1"`.
|
|
180
|
-
- `presignedUrls` — `GET /uploads/presign/:key` returns a time-limited HMAC URL that the browser can use to download directly from S3 (or your storage backend) without a round-trip through the API on every byte.
|
|
181
|
-
|
|
182
|
-
---
|
|
183
|
-
|
|
184
|
-
#### Internal admin panel — re-authentication on expiry
|
|
185
|
-
|
|
186
|
-
Staff tool with two roles, MFA enforced for everyone, and no refresh tokens. When the access token expires, the session ends and the user must authenticate again. Full device history is kept for auditing.
|
|
187
|
-
|
|
188
|
-
```ts
|
|
189
|
-
await createServer({
|
|
190
|
-
auth: {
|
|
191
|
-
roles: ["superadmin", "admin", "viewer"],
|
|
192
|
-
defaultRole: "viewer",
|
|
193
|
-
mfa: {
|
|
194
|
-
issuer: "Admin Panel",
|
|
195
|
-
required: true,
|
|
196
|
-
challengeTtlSeconds: 120, // 2-minute window for MFA code
|
|
197
|
-
},
|
|
198
|
-
passwordPolicy: {
|
|
199
|
-
minLength: 14,
|
|
200
|
-
requireLetter: true,
|
|
201
|
-
requireDigit: true,
|
|
202
|
-
requireSpecial: true,
|
|
203
|
-
},
|
|
204
|
-
sessionPolicy: {
|
|
205
|
-
maxSessions: 2, // work machine + phone; third device evicts oldest
|
|
206
|
-
trackLastActive: true,
|
|
207
|
-
persistSessionMetadata: true,
|
|
208
|
-
includeInactiveSessions: true, // audit trail of all sign-ins
|
|
209
|
-
},
|
|
210
|
-
rateLimit: {
|
|
211
|
-
login: { windowMs: 15 * 60 * 1000, max: 5 },
|
|
212
|
-
},
|
|
213
|
-
// No refreshTokens — 7-day JWTs, then re-authenticate.
|
|
214
|
-
// For a stricter posture: add refreshTokens with a 4h refreshTokenExpiry.
|
|
215
|
-
//
|
|
216
|
-
// No oauth — staff use internal credentials only.
|
|
217
|
-
// No emailVerification — IT provisions accounts directly.
|
|
218
|
-
},
|
|
219
|
-
security: {
|
|
220
|
-
cors: ["https://admin.internal.myapp.com"],
|
|
221
|
-
trustProxy: 1,
|
|
222
|
-
csrf: { enabled: true },
|
|
223
|
-
rateLimit: { windowMs: 60_000, max: 30 }, // low — this is not a public endpoint
|
|
224
|
-
},
|
|
225
|
-
});
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
**Key decisions:**
|
|
229
|
-
- No `refreshTokens` — when the token expires, the user re-enters credentials. This matches the mental model of a work session and limits how long a compromised token stays valid.
|
|
230
|
-
- `maxSessions: 2` — a staff member logging in from a third device quietly evicts the oldest session. Combined with `includeInactiveSessions: true` and email alerts in `onBeforeDelete`, this can surface unusual access.
|
|
231
|
-
- `requireRole.global("admin")` or `requireRole.global("superadmin")` on sensitive routes — tenant-scoped roles never satisfy a global check.
|
|
232
|
-
|
|
233
|
-
---
|
|
234
|
-
|
|
235
|
-
#### Native mobile / server-to-server — no cookies, no CSRF
|
|
236
|
-
|
|
237
|
-
For **native iOS/Android apps and server-to-server API clients** that pass the JWT in the `x-user-token` header and never touch cookies. CSRF is irrelevant here because the attack requires a browser to silently attach credentials — custom headers can't be forged that way. Phone numbers as the primary identifier.
|
|
238
|
-
|
|
239
|
-
> **Not for browser SPAs.** If your client is a browser app (React, Vue, etc.), see the note after this example — even header-based browser clients need specific CORS origins.
|
|
240
|
-
|
|
241
|
-
```ts
|
|
242
|
-
await createServer({
|
|
243
|
-
auth: {
|
|
244
|
-
primaryField: "phone", // body field is "phone" instead of "email"
|
|
245
|
-
passwordPolicy: {
|
|
246
|
-
minLength: 8,
|
|
247
|
-
requireDigit: true,
|
|
248
|
-
},
|
|
249
|
-
mfa: {
|
|
250
|
-
issuer: "MyApp",
|
|
251
|
-
emailOtp: {
|
|
252
|
-
onSend: async (email, code) => {
|
|
253
|
-
// or route to an SMS gateway keyed by the user's phone number
|
|
254
|
-
await mailer.send(email, `Your login code: ${code}`);
|
|
255
|
-
},
|
|
256
|
-
codeLength: 6,
|
|
257
|
-
},
|
|
258
|
-
},
|
|
259
|
-
refreshTokens: {
|
|
260
|
-
accessTokenExpiry: 900, // 15 min
|
|
261
|
-
refreshTokenExpiry: 2_592_000, // 30 days
|
|
262
|
-
rotationGraceSeconds: 60, // more generous — mobile networks are lossy
|
|
263
|
-
},
|
|
264
|
-
sessionPolicy: {
|
|
265
|
-
maxSessions: 5, // phone, tablet, desktop, smart TV, etc.
|
|
266
|
-
},
|
|
267
|
-
// No emailVerification — phone is the primary field; email may not be present.
|
|
268
|
-
// No csrf — header-based auth is immune to CSRF.
|
|
269
|
-
},
|
|
270
|
-
security: {
|
|
271
|
-
cors: "*", // safe: native apps don't run in a browser, CORS has no effect
|
|
272
|
-
trustProxy: 1,
|
|
273
|
-
botProtection: {
|
|
274
|
-
fingerprintRateLimit: true,
|
|
275
|
-
blockList: ["198.51.100.0/24"],
|
|
276
|
-
},
|
|
277
|
-
rateLimit: { windowMs: 60_000, max: 200 }, // higher cap for mobile traffic bursts
|
|
278
|
-
},
|
|
279
|
-
});
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
**Key decisions:**
|
|
283
|
-
- `primaryField: "phone"` — register/login bodies use `{ phone, password }`. Email verification and password reset routes are not mounted (they require `primaryField: "email"`).
|
|
284
|
-
- `cors: "*"` is safe for native apps because CORS is a browser enforcement mechanism — it has no meaning outside of a browser context. A native app making HTTP requests ignores CORS entirely.
|
|
285
|
-
- `rotationGraceSeconds: 60` — mobile connections drop mid-request more often than browser connections. A longer grace window prevents legitimate refresh retries from triggering theft detection.
|
|
286
|
-
- No `csrf` block — CSRF attacks require the browser to automatically attach credentials (cookies). Since this API uses `x-user-token`, there's nothing to forge.
|
|
287
|
-
|
|
288
|
-
**Adding session binding to mobile apps:** Mobile users frequently switch between Wi-Fi and LTE, so IP-based binding causes false rejections. If you want session binding, use UA only and start with `"log-only"` to measure false-positive rates before switching to `"reject"`:
|
|
289
|
-
|
|
290
|
-
```ts
|
|
291
|
-
signing: {
|
|
292
|
-
sessionBinding: {
|
|
293
|
-
fields: ["ua"], // IP excluded — mobile IPs change too often
|
|
294
|
-
onMismatch: "log-only", // measure first, then tighten to "unauthenticate"
|
|
295
|
-
},
|
|
296
|
-
},
|
|
297
|
-
```
|
|
298
|
-
|
|
299
|
-
##### Browser SPA with header-based auth
|
|
300
|
-
|
|
301
|
-
If your client is a browser app that uses `x-user-token` instead of cookies — common with React/Vue SPAs that manage tokens in memory — the auth config is the same but CORS must be locked down:
|
|
302
|
-
|
|
303
|
-
```ts
|
|
304
|
-
security: {
|
|
305
|
-
cors: ["https://myapp.com"], // NOT "*" — browsers enforce CORS even for header auth
|
|
306
|
-
trustProxy: 1,
|
|
307
|
-
// No csrf — custom headers can't be forged cross-origin without a CORS allowlist,
|
|
308
|
-
// so CSRF protection is still not needed even in the browser.
|
|
309
|
-
botProtection: {
|
|
310
|
-
fingerprintRateLimit: true,
|
|
311
|
-
},
|
|
312
|
-
},
|
|
313
|
-
```
|
|
314
|
-
|
|
315
|
-
The reason CSRF is still not needed: a malicious page can try to make a cross-origin `POST` to your API, but the browser blocks requests with custom headers (`x-user-token`) unless the server's CORS policy explicitly allows the origin. Since `cors` is locked to `["https://myapp.com"]`, any request from a different origin is rejected before it reaches your handler. The CSRF double-submit pattern defends against cookie theft specifically; `x-user-token` doesn't have that vulnerability.
|
|
316
|
-
|
|
317
|
-
**What to avoid:** storing the token in `localStorage` is convenient but exposes it to XSS. Storing it in a `httpOnly` cookie eliminates XSS risk but brings CSRF back — at which point the [Consumer SaaS](#consumer-saas--social-login-with-verification) or [Fintech](#fintech--healthcare--maximum-security) example is the right template instead.
|
|
318
|
-
|
|
319
|
-
---
|
|
320
|
-
|
|
321
|
-
#### Local development — no external dependencies
|
|
322
|
-
|
|
323
|
-
Everything in-memory. No Redis, no MongoDB, no Docker required. Spin up with `bun run dev` and iterate immediately. All data is lost on restart, which is fine for local work.
|
|
324
|
-
|
|
325
|
-
```ts
|
|
326
|
-
await createServer({
|
|
327
|
-
routesDir: import.meta.dir + "/routes",
|
|
328
|
-
db: {
|
|
329
|
-
mongo: false,
|
|
330
|
-
redis: false,
|
|
331
|
-
auth: "memory",
|
|
332
|
-
sessions: "memory",
|
|
333
|
-
},
|
|
334
|
-
auth: {
|
|
335
|
-
roles: ["admin", "user"],
|
|
336
|
-
defaultRole: "user",
|
|
337
|
-
passwordPolicy: {
|
|
338
|
-
minLength: 1, // any password works — don't slow down local testing
|
|
339
|
-
requireLetter: false,
|
|
340
|
-
requireDigit: false,
|
|
341
|
-
requireSpecial: false,
|
|
342
|
-
},
|
|
343
|
-
rateLimit: {
|
|
344
|
-
login: { windowMs: 60_000, max: 10_000 }, // effectively unlimited
|
|
345
|
-
register: { windowMs: 60_000, max: 10_000 },
|
|
346
|
-
},
|
|
347
|
-
// To test email flows locally, add emailVerification / passwordReset with
|
|
348
|
-
// an onSend that logs the token to the console instead of sending a real email:
|
|
349
|
-
//
|
|
350
|
-
// emailVerification: {
|
|
351
|
-
// onSend: async (email, token) => console.log("[verify]", email, token),
|
|
352
|
-
// },
|
|
353
|
-
},
|
|
354
|
-
security: {
|
|
355
|
-
cors: "*",
|
|
356
|
-
bearerAuth: false, // no API key required
|
|
357
|
-
},
|
|
358
|
-
});
|
|
359
|
-
```
|
|
360
|
-
|
|
361
|
-
**Key decisions:**
|
|
362
|
-
- `db: { mongo: false, redis: false }` is the key line — it disables all auto-connect calls, so no connection errors on startup.
|
|
363
|
-
- `auth: "memory"` and `sessions: "memory"` use in-memory Maps. Import `clearMemoryStore()` from the package in your tests to reset state between test runs.
|
|
364
|
-
- Rate limits are set to 10 000 per minute rather than disabled entirely so the rate-limit code path is exercised (avoiding "works in dev, breaks in prod" surprises). The limit is just high enough that it never triggers during normal use.
|
|
365
|
-
- If you want to test email flows locally without a real provider, the commented-out block shows how to log the token to the console — paste it into the browser or a `curl` call directly.
|
|
366
|
-
|
|
367
|
-
---
|
|
368
|
-
|
|
369
|
-
## JWT Claims (iss, aud, iat)
|
|
370
|
-
|
|
371
|
-
By default Bunshot tokens include `sub`, `sid`, and `exp`. Enable standard JWT claims for multi-service deployments or compliance requirements:
|
|
372
|
-
|
|
373
|
-
```ts
|
|
374
|
-
createApp({
|
|
375
|
-
auth: {
|
|
376
|
-
jwt: {
|
|
377
|
-
issuer: "https://auth.yourapp.com", // iss claim — who issued the token
|
|
378
|
-
audience: "your-api", // aud claim — who the token is for
|
|
379
|
-
},
|
|
380
|
-
},
|
|
381
|
-
});
|
|
382
|
-
```
|
|
383
|
-
|
|
384
|
-
When configured:
|
|
385
|
-
- **`iss`** and **`aud`** are included in every token and validated on every verification. Tokens from a different issuer or intended for a different audience are rejected.
|
|
386
|
-
- **`iat`** (issued-at) is always included once JWT config is set. Use it to detect token reuse or implement absolute expiry windows.
|
|
387
|
-
|
|
388
|
-
This is recommended for fintech and multi-tenant deployments where tokens from one service should not be accepted by another.
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
## Authentication
|
|
2
|
-
|
|
3
|
-
Bunshot ships a complete auth system: credential login, OAuth social providers (Google, Apple, Microsoft, GitHub), multi-factor authentication (TOTP, email OTP, WebAuthn), session management, roles, groups, and security hardening (CSRF, rate limiting, bot protection). Everything is opt-in — add only what your app needs.
|
|
4
|
-
|
|
5
|
-
### How it works
|
|
6
|
-
|
|
7
|
-
Auth has two independent layers you configure separately:
|
|
8
|
-
|
|
9
|
-
| Layer | What it stores | Configured via | Default |
|
|
10
|
-
|---|---|---|---|
|
|
11
|
-
| **Auth adapter** | Users, passwords, roles | `auth.adapter` or `db.auth` | MongoDB (`mongoAuthAdapter`) |
|
|
12
|
-
| **Session store** | Active sessions (JWT metadata) | `db.sessions` | Redis |
|
|
13
|
-
|
|
14
|
-
When a user logs in, the auth adapter verifies their credentials and the session store creates a record for the new session. The JWT embeds a `sessionId` claim that ties the token to that record — revoking a session immediately invalidates its token even before the JWT expires.
|
|
15
|
-
|
|
16
|
-
### Minimum working setup
|
|
17
|
-
|
|
18
|
-
Enable auth by passing an `auth` block. The routes are mounted automatically.
|
|
19
|
-
|
|
20
|
-
```ts
|
|
21
|
-
await createServer({
|
|
22
|
-
routesDir: import.meta.dir + "/routes",
|
|
23
|
-
auth: {
|
|
24
|
-
roles: ["admin", "user"],
|
|
25
|
-
defaultRole: "user",
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
This mounts `POST /auth/register`, `POST /auth/login`, `POST /auth/logout`, `GET /auth/me`, and the session management endpoints. Users are stored in MongoDB, sessions in Redis.
|
|
31
|
-
|
|
32
|
-
**Environment variables required:**
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
MONGO_URI_DEV=mongodb://localhost:27017/myapp
|
|
36
|
-
REDIS_URL_DEV=redis://localhost:6379
|
|
37
|
-
JWT_SECRET_DEV=at-least-32-characters-long-secret
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
### Choosing a store
|
|
41
|
-
|
|
42
|
-
| Setup | `db.auth` | `db.sessions` | When to use |
|
|
43
|
-
|---|---|---|---|
|
|
44
|
-
| Default (Mongo + Redis) | `"mongo"` | `"redis"` | Production with both services |
|
|
45
|
-
| Mongo only | `"mongo"` | `"mongo"` | When Redis is unavailable |
|
|
46
|
-
| SQLite | `"sqlite"` | `"sqlite"` | Lightweight deploys, embedded DBs |
|
|
47
|
-
| Memory | `"memory"` | `"memory"` | Tests, local dev — lost on restart |
|
|
48
|
-
|
|
49
|
-
```ts
|
|
50
|
-
// MongoDB sessions instead of Redis
|
|
51
|
-
await createServer({
|
|
52
|
-
db: { redis: false, sessions: "mongo" },
|
|
53
|
-
auth: { /* ... */ },
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
// SQLite — single file, no external services
|
|
57
|
-
await createServer({
|
|
58
|
-
db: { mongo: false, redis: false, sqlite: import.meta.dir + "/data.db", auth: "sqlite", sessions: "sqlite" },
|
|
59
|
-
auth: { /* ... */ },
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
// In-memory — great for tests
|
|
63
|
-
await createServer({
|
|
64
|
-
db: { mongo: false, redis: false, auth: "memory", sessions: "memory" },
|
|
65
|
-
auth: { /* ... */ },
|
|
66
|
-
});
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### Protecting routes
|
|
70
|
-
|
|
71
|
-
```ts
|
|
72
|
-
import { userAuth, requireRole, requireVerifiedEmail } from "@lastshotlabs/bunshot";
|
|
73
|
-
|
|
74
|
-
router.use("/me", userAuth); // 401 if not logged in
|
|
75
|
-
router.use("/admin", userAuth, requireRole("admin")); // 403 if wrong role
|
|
76
|
-
router.use("/content", userAuth, requireRole("admin", "editor")); // either role passes
|
|
77
|
-
router.use("/settings", userAuth, requireVerifiedEmail); // 403 if email unverified
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### Feature map
|
|
81
|
-
|
|
82
|
-
Everything beyond basic credential login is opt-in:
|
|
83
|
-
|
|
84
|
-
| Feature | How to enable | Docs |
|
|
85
|
-
|---|---|---|
|
|
86
|
-
| Email verification | `auth.emailVerification` | [Auth Flow](#auth-flow) |
|
|
87
|
-
| Password reset | `auth.passwordReset` | [Auth Flow](#auth-flow) |
|
|
88
|
-
| Refresh tokens | `auth.refreshTokens` | [Auth Flow](#auth-flow) |
|
|
89
|
-
| MFA (TOTP, email OTP, WebAuthn) | `auth.mfa` | [Auth Flow](#auth-flow) |
|
|
90
|
-
| Social login (OAuth) | `auth.oauth.providers` | [Social Login](#social-login-oauth) |
|
|
91
|
-
| Roles & groups | `auth.roles`, `groups` | [Roles](#roles) |
|
|
92
|
-
| CSRF protection | `security.csrf` | [Auth Flow](#auth-flow) |
|
|
93
|
-
| Bot protection | `security.botProtection` | [Auth Flow](#auth-flow) |
|
|
94
|
-
| Account deletion | `auth.accountDeletion` | [Auth Flow](#auth-flow) |
|
|
95
|
-
| Custom user store | `auth.adapter` | [Auth Flow](#auth-flow) |
|
|
96
|
-
|
|
97
|
-
### Custom auth adapter
|
|
98
|
-
|
|
99
|
-
The default adapter stores users in MongoDB. Pass `auth.adapter` to use any other store — Postgres, SQLite, an external identity provider, etc. Only implement the methods your app uses:
|
|
100
|
-
|
|
101
|
-
```ts
|
|
102
|
-
import type { AuthAdapter } from "@lastshotlabs/bunshot";
|
|
103
|
-
|
|
104
|
-
const myAdapter: AuthAdapter = {
|
|
105
|
-
async findByEmail(email) {
|
|
106
|
-
const user = await db.query("SELECT id, passwordHash FROM users WHERE email = $1", [email]);
|
|
107
|
-
return user ?? null;
|
|
108
|
-
},
|
|
109
|
-
async create(email, passwordHash) {
|
|
110
|
-
const [user] = await db.query(
|
|
111
|
-
"INSERT INTO users (email, passwordHash) VALUES ($1, $2) RETURNING id",
|
|
112
|
-
[email, passwordHash]
|
|
113
|
-
);
|
|
114
|
-
return { id: user.id };
|
|
115
|
-
},
|
|
116
|
-
async getRoles(userId) {
|
|
117
|
-
const user = await db.query("SELECT roles FROM users WHERE id = $1", [userId]);
|
|
118
|
-
return user?.roles ?? [];
|
|
119
|
-
},
|
|
120
|
-
async setRoles(userId, roles) {
|
|
121
|
-
await db.query("UPDATE users SET roles = $2 WHERE id = $1", [userId, roles]);
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
await createServer({
|
|
126
|
-
auth: { adapter: myAdapter, roles: ["admin", "user"], defaultRole: "user" },
|
|
127
|
-
});
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
The full adapter interface and all optional methods (OAuth, MFA, tenant roles, groups, etc.) are covered in [Auth Flow](#auth-flow).
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
## Authentication
|
|
2
|
-
|
|
3
|
-
Bunshot ships a complete auth system: credential login, OAuth social providers (Google, Apple, Microsoft, GitHub), MFA (TOTP, email OTP, WebAuthn), session management, roles & groups, and security hardening (CSRF, rate limiting, bot protection). Everything is opt-in and configurable.
|
|
4
|
-
|
|
5
|
-
Auth has two independently configurable layers: the **auth adapter** (where users and passwords are stored — MongoDB by default, or SQLite/memory/custom) and the **session store** (where active sessions live — Redis by default, or MongoDB/SQLite/memory). Sessions are JWT-backed with a `sessionId` claim, so revoking a session invalidates the token immediately even before it expires. Protect routes with `userAuth`, `requireRole`, and `requireVerifiedEmail` middleware.
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
## CLI — Scaffold a New Project
|
|
2
|
-
|
|
3
|
-
```bash
|
|
4
|
-
bunx @lastshotlabs/bunshot "My App"
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
You can also pass a custom directory name:
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
bunx @lastshotlabs/bunshot "My App" my-app-dir
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
This creates a ready-to-run project with:
|
|
14
|
-
|
|
15
|
-
```
|
|
16
|
-
my-app/
|
|
17
|
-
src/
|
|
18
|
-
index.ts # entry point
|
|
19
|
-
config/index.ts # centralized app configuration
|
|
20
|
-
lib/constants.ts # app name, version, roles
|
|
21
|
-
routes/ # add your route files here
|
|
22
|
-
workers/ # BullMQ workers (auto-discovered)
|
|
23
|
-
middleware/ # custom middleware
|
|
24
|
-
models/ # data models
|
|
25
|
-
services/ # business logic
|
|
26
|
-
tsconfig.json # pre-configured with path aliases
|
|
27
|
-
.env # environment variables template
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
Path aliases like `@config/*`, `@lib/*`, `@middleware/*`, `@models/*`, `@routes/*`, `@services/*`, and `@workers/*` are set up automatically in `tsconfig.json`.
|
|
31
|
-
|
|
32
|
-
After the database setup, the CLI prompts for an **auth security posture**. You can either pick a preset (one question) or configure features step by step:
|
|
33
|
-
|
|
34
|
-
**Presets:**
|
|
35
|
-
- **Web app / SaaS** — CSRF protection, refresh tokens, bot-fingerprint rate limiting. Includes commented-out stubs for email verification, password reset, and MFA.
|
|
36
|
-
- **Internal / admin** — MFA required for all users, strict password policy (14+ chars), low login rate limits, tight session cap.
|
|
37
|
-
- **Mobile / API only** — No CSRF, open CORS, long-lived refresh tokens with rotation grace window.
|
|
38
|
-
- **Dev / prototype** — Permissive password policy, very high rate limits, no bearer auth guard.
|
|
39
|
-
|
|
40
|
-
**Step by step** — choose individual features: password policy, email verification, password reset, refresh tokens, MFA (none / optional / required), CSRF, and OAuth providers (Google, GitHub, Apple, Microsoft).
|
|
41
|
-
|
|
42
|
-
The selected posture is printed in the end-of-run summary and reflected directly in the generated `src/config/index.ts`.
|