@awesome-lang-auth/node 1.10.1
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/LICENSE +21 -0
- package/README.detailed.md +4059 -0
- package/README.md +248 -0
- package/dist/abstract/base-auth-strategy.abstract.d.ts +7 -0
- package/dist/abstract/base-auth-strategy.abstract.d.ts.map +1 -0
- package/dist/abstract/base-auth-strategy.abstract.js +7 -0
- package/dist/abstract/base-auth-strategy.abstract.js.map +1 -0
- package/dist/abstract/base-oauth-strategy.abstract.d.ts +27 -0
- package/dist/abstract/base-oauth-strategy.abstract.d.ts.map +1 -0
- package/dist/abstract/base-oauth-strategy.abstract.js +11 -0
- package/dist/abstract/base-oauth-strategy.abstract.js.map +1 -0
- package/dist/adapters/express.d.ts +45 -0
- package/dist/adapters/express.d.ts.map +1 -0
- package/dist/adapters/express.js +49 -0
- package/dist/adapters/express.js.map +1 -0
- package/dist/adapters/fastify.d.ts +72 -0
- package/dist/adapters/fastify.d.ts.map +1 -0
- package/dist/adapters/fastify.js +63 -0
- package/dist/adapters/fastify.js.map +1 -0
- package/dist/auth-configurator.d.ts +65 -0
- package/dist/auth-configurator.d.ts.map +1 -0
- package/dist/auth-configurator.js +127 -0
- package/dist/auth-configurator.js.map +1 -0
- package/dist/events/auth-event-bus.d.ts +68 -0
- package/dist/events/auth-event-bus.d.ts.map +1 -0
- package/dist/events/auth-event-bus.js +60 -0
- package/dist/events/auth-event-bus.js.map +1 -0
- package/dist/events/auth-event-names.d.ts +34 -0
- package/dist/events/auth-event-names.d.ts.map +1 -0
- package/dist/events/auth-event-names.js +41 -0
- package/dist/events/auth-event-names.js.map +1 -0
- package/dist/http-types.d.ts +135 -0
- package/dist/http-types.d.ts.map +1 -0
- package/dist/http-types.js +18 -0
- package/dist/http-types.js.map +1 -0
- package/dist/index.d.ts +80 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +88 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/api-key-store.interface.d.ts +94 -0
- package/dist/interfaces/api-key-store.interface.d.ts.map +1 -0
- package/dist/interfaces/api-key-store.interface.js +3 -0
- package/dist/interfaces/api-key-store.interface.js.map +1 -0
- package/dist/interfaces/auth-strategy.interface.d.ts +6 -0
- package/dist/interfaces/auth-strategy.interface.d.ts.map +1 -0
- package/dist/interfaces/auth-strategy.interface.js +3 -0
- package/dist/interfaces/auth-strategy.interface.js.map +1 -0
- package/dist/interfaces/linked-accounts-store.interface.d.ts +74 -0
- package/dist/interfaces/linked-accounts-store.interface.d.ts.map +1 -0
- package/dist/interfaces/linked-accounts-store.interface.js +3 -0
- package/dist/interfaces/linked-accounts-store.interface.js.map +1 -0
- package/dist/interfaces/pending-link-store.interface.d.ts +77 -0
- package/dist/interfaces/pending-link-store.interface.d.ts.map +1 -0
- package/dist/interfaces/pending-link-store.interface.js +3 -0
- package/dist/interfaces/pending-link-store.interface.js.map +1 -0
- package/dist/interfaces/roles-permissions-store.interface.d.ts +129 -0
- package/dist/interfaces/roles-permissions-store.interface.d.ts.map +1 -0
- package/dist/interfaces/roles-permissions-store.interface.js +3 -0
- package/dist/interfaces/roles-permissions-store.interface.js.map +1 -0
- package/dist/interfaces/session-store.interface.d.ts +92 -0
- package/dist/interfaces/session-store.interface.d.ts.map +1 -0
- package/dist/interfaces/session-store.interface.js +3 -0
- package/dist/interfaces/session-store.interface.js.map +1 -0
- package/dist/interfaces/settings-store.interface.d.ts +91 -0
- package/dist/interfaces/settings-store.interface.d.ts.map +1 -0
- package/dist/interfaces/settings-store.interface.js +3 -0
- package/dist/interfaces/settings-store.interface.js.map +1 -0
- package/dist/interfaces/sse-distributor.interface.d.ts +25 -0
- package/dist/interfaces/sse-distributor.interface.d.ts.map +1 -0
- package/dist/interfaces/sse-distributor.interface.js +3 -0
- package/dist/interfaces/sse-distributor.interface.js.map +1 -0
- package/dist/interfaces/telemetry-store.interface.d.ts +72 -0
- package/dist/interfaces/telemetry-store.interface.d.ts.map +1 -0
- package/dist/interfaces/telemetry-store.interface.js +3 -0
- package/dist/interfaces/telemetry-store.interface.js.map +1 -0
- package/dist/interfaces/template-store.interface.d.ts +37 -0
- package/dist/interfaces/template-store.interface.d.ts.map +1 -0
- package/dist/interfaces/template-store.interface.js +3 -0
- package/dist/interfaces/template-store.interface.js.map +1 -0
- package/dist/interfaces/tenant-store.interface.d.ts +97 -0
- package/dist/interfaces/tenant-store.interface.d.ts.map +1 -0
- package/dist/interfaces/tenant-store.interface.js +3 -0
- package/dist/interfaces/tenant-store.interface.js.map +1 -0
- package/dist/interfaces/token-store.interface.d.ts +10 -0
- package/dist/interfaces/token-store.interface.d.ts.map +1 -0
- package/dist/interfaces/token-store.interface.js +3 -0
- package/dist/interfaces/token-store.interface.js.map +1 -0
- package/dist/interfaces/user-metadata-store.interface.d.ts +50 -0
- package/dist/interfaces/user-metadata-store.interface.d.ts.map +1 -0
- package/dist/interfaces/user-metadata-store.interface.js +3 -0
- package/dist/interfaces/user-metadata-store.interface.js.map +1 -0
- package/dist/interfaces/user-store.interface.d.ts +113 -0
- package/dist/interfaces/user-store.interface.d.ts.map +1 -0
- package/dist/interfaces/user-store.interface.js +3 -0
- package/dist/interfaces/user-store.interface.js.map +1 -0
- package/dist/interfaces/webhook-store.interface.d.ts +139 -0
- package/dist/interfaces/webhook-store.interface.d.ts.map +1 -0
- package/dist/interfaces/webhook-store.interface.js +3 -0
- package/dist/interfaces/webhook-store.interface.js.map +1 -0
- package/dist/middleware/api-key.middleware.d.ts +35 -0
- package/dist/middleware/api-key.middleware.d.ts.map +1 -0
- package/dist/middleware/api-key.middleware.js +45 -0
- package/dist/middleware/api-key.middleware.js.map +1 -0
- package/dist/middleware/auth.middleware.d.ts +13 -0
- package/dist/middleware/auth.middleware.d.ts.map +1 -0
- package/dist/middleware/auth.middleware.js +55 -0
- package/dist/middleware/auth.middleware.js.map +1 -0
- package/dist/middleware/jwks-auth.middleware.d.ts +18 -0
- package/dist/middleware/jwks-auth.middleware.d.ts.map +1 -0
- package/dist/middleware/jwks-auth.middleware.js +77 -0
- package/dist/middleware/jwks-auth.middleware.js.map +1 -0
- package/dist/models/api-key.model.d.ts +66 -0
- package/dist/models/api-key.model.d.ts.map +1 -0
- package/dist/models/api-key.model.js +3 -0
- package/dist/models/api-key.model.js.map +1 -0
- package/dist/models/auth-config.model.d.ts +387 -0
- package/dist/models/auth-config.model.d.ts.map +1 -0
- package/dist/models/auth-config.model.js +3 -0
- package/dist/models/auth-config.model.js.map +1 -0
- package/dist/models/errors.d.ts +7 -0
- package/dist/models/errors.d.ts.map +1 -0
- package/dist/models/errors.js +14 -0
- package/dist/models/errors.js.map +1 -0
- package/dist/models/session.model.d.ts +28 -0
- package/dist/models/session.model.d.ts.map +1 -0
- package/dist/models/session.model.js +3 -0
- package/dist/models/session.model.js.map +1 -0
- package/dist/models/tenant.model.d.ts +20 -0
- package/dist/models/tenant.model.d.ts.map +1 -0
- package/dist/models/tenant.model.js +3 -0
- package/dist/models/tenant.model.js.map +1 -0
- package/dist/models/token.model.d.ts +21 -0
- package/dist/models/token.model.d.ts.map +1 -0
- package/dist/models/token.model.js +3 -0
- package/dist/models/token.model.js.map +1 -0
- package/dist/models/user.model.d.ts +92 -0
- package/dist/models/user.model.d.ts.map +1 -0
- package/dist/models/user.model.js +3 -0
- package/dist/models/user.model.js.map +1 -0
- package/dist/router/admin.router.d.ts +188 -0
- package/dist/router/admin.router.d.ts.map +1 -0
- package/dist/router/admin.router.js +1507 -0
- package/dist/router/admin.router.js.map +1 -0
- package/dist/router/auth.router.d.ts +199 -0
- package/dist/router/auth.router.d.ts.map +1 -0
- package/dist/router/auth.router.js +1636 -0
- package/dist/router/auth.router.js.map +1 -0
- package/dist/router/openapi.d.ts +98 -0
- package/dist/router/openapi.d.ts.map +1 -0
- package/dist/router/openapi.js +1518 -0
- package/dist/router/openapi.js.map +1 -0
- package/dist/router/router-events.d.ts +38 -0
- package/dist/router/router-events.d.ts.map +1 -0
- package/dist/router/router-events.js +74 -0
- package/dist/router/router-events.js.map +1 -0
- package/dist/router/tools.router.d.ts +104 -0
- package/dist/router/tools.router.d.ts.map +1 -0
- package/dist/router/tools.router.js +227 -0
- package/dist/router/tools.router.js.map +1 -0
- package/dist/router/ui.router.d.ts +49 -0
- package/dist/router/ui.router.d.ts.map +1 -0
- package/dist/router/ui.router.js +272 -0
- package/dist/router/ui.router.js.map +1 -0
- package/dist/services/api-key.service.d.ts +53 -0
- package/dist/services/api-key.service.d.ts.map +1 -0
- package/dist/services/api-key.service.js +66 -0
- package/dist/services/api-key.service.js.map +1 -0
- package/dist/services/jwks.service.d.ts +73 -0
- package/dist/services/jwks.service.d.ts.map +1 -0
- package/dist/services/jwks.service.js +174 -0
- package/dist/services/jwks.service.js.map +1 -0
- package/dist/services/mailer.service.d.ts +30 -0
- package/dist/services/mailer.service.d.ts.map +1 -0
- package/dist/services/mailer.service.js +248 -0
- package/dist/services/mailer.service.js.map +1 -0
- package/dist/services/notification.service.d.ts +110 -0
- package/dist/services/notification.service.d.ts.map +1 -0
- package/dist/services/notification.service.js +79 -0
- package/dist/services/notification.service.js.map +1 -0
- package/dist/services/password.service.d.ts +5 -0
- package/dist/services/password.service.d.ts.map +1 -0
- package/dist/services/password.service.js +17 -0
- package/dist/services/password.service.js.map +1 -0
- package/dist/services/sms.service.d.ts +14 -0
- package/dist/services/sms.service.d.ts.map +1 -0
- package/dist/services/sms.service.js +51 -0
- package/dist/services/sms.service.js.map +1 -0
- package/dist/services/token.service.d.ts +62 -0
- package/dist/services/token.service.d.ts.map +1 -0
- package/dist/services/token.service.js +354 -0
- package/dist/services/token.service.js.map +1 -0
- package/dist/stores/memory-template.store.d.ts +12 -0
- package/dist/stores/memory-template.store.d.ts.map +1 -0
- package/dist/stores/memory-template.store.js +35 -0
- package/dist/stores/memory-template.store.js.map +1 -0
- package/dist/strategies/api-key/api-key.strategy.d.ts +72 -0
- package/dist/strategies/api-key/api-key.strategy.d.ts.map +1 -0
- package/dist/strategies/api-key/api-key.strategy.js +182 -0
- package/dist/strategies/api-key/api-key.strategy.js.map +1 -0
- package/dist/strategies/local/local.strategy.d.ts +19 -0
- package/dist/strategies/local/local.strategy.d.ts.map +1 -0
- package/dist/strategies/local/local.strategy.js +45 -0
- package/dist/strategies/local/local.strategy.js.map +1 -0
- package/dist/strategies/magic-link/magic-link.strategy.d.ts +8 -0
- package/dist/strategies/magic-link/magic-link.strategy.d.ts.map +1 -0
- package/dist/strategies/magic-link/magic-link.strategy.js +53 -0
- package/dist/strategies/magic-link/magic-link.strategy.js.map +1 -0
- package/dist/strategies/oauth/generic-oauth.strategy.d.ts +120 -0
- package/dist/strategies/oauth/generic-oauth.strategy.d.ts.map +1 -0
- package/dist/strategies/oauth/generic-oauth.strategy.js +88 -0
- package/dist/strategies/oauth/generic-oauth.strategy.js.map +1 -0
- package/dist/strategies/oauth/github.strategy.d.ts +31 -0
- package/dist/strategies/oauth/github.strategy.d.ts.map +1 -0
- package/dist/strategies/oauth/github.strategy.js +72 -0
- package/dist/strategies/oauth/github.strategy.js.map +1 -0
- package/dist/strategies/oauth/google.strategy.d.ts +31 -0
- package/dist/strategies/oauth/google.strategy.d.ts.map +1 -0
- package/dist/strategies/oauth/google.strategy.js +61 -0
- package/dist/strategies/oauth/google.strategy.js.map +1 -0
- package/dist/strategies/sms/sms.strategy.d.ts +7 -0
- package/dist/strategies/sms/sms.strategy.d.ts.map +1 -0
- package/dist/strategies/sms/sms.strategy.js +39 -0
- package/dist/strategies/sms/sms.strategy.js.map +1 -0
- package/dist/strategies/two-factor/totp.strategy.d.ts +12 -0
- package/dist/strategies/two-factor/totp.strategy.d.ts.map +1 -0
- package/dist/strategies/two-factor/totp.strategy.js +32 -0
- package/dist/strategies/two-factor/totp.strategy.js.map +1 -0
- package/dist/tools/auth-tools.d.ts +200 -0
- package/dist/tools/auth-tools.d.ts.map +1 -0
- package/dist/tools/auth-tools.js +232 -0
- package/dist/tools/auth-tools.js.map +1 -0
- package/dist/tools/sse-manager.d.ts +118 -0
- package/dist/tools/sse-manager.d.ts.map +1 -0
- package/dist/tools/sse-manager.js +163 -0
- package/dist/tools/sse-manager.js.map +1 -0
- package/dist/tools/sse-notify.decorator.d.ts +74 -0
- package/dist/tools/sse-notify.decorator.d.ts.map +1 -0
- package/dist/tools/sse-notify.decorator.js +78 -0
- package/dist/tools/sse-notify.decorator.js.map +1 -0
- package/dist/tools/webhook-action.d.ts +130 -0
- package/dist/tools/webhook-action.d.ts.map +1 -0
- package/dist/tools/webhook-action.js +144 -0
- package/dist/tools/webhook-action.js.map +1 -0
- package/dist/tools/webhook-sender.d.ts +31 -0
- package/dist/tools/webhook-sender.d.ts.map +1 -0
- package/dist/tools/webhook-sender.js +80 -0
- package/dist/tools/webhook-sender.js.map +1 -0
- package/dist/ui-assets/2fa.html +115 -0
- package/dist/ui-assets/account-conflict.html +108 -0
- package/dist/ui-assets/admin.css +263 -0
- package/dist/ui-assets/admin.js +1927 -0
- package/dist/ui-assets/auth.js +725 -0
- package/dist/ui-assets/base.css +219 -0
- package/dist/ui-assets/forgot-password.html +93 -0
- package/dist/ui-assets/link-verify.html +74 -0
- package/dist/ui-assets/login.html +135 -0
- package/dist/ui-assets/magic-link.html +112 -0
- package/dist/ui-assets/register.html +122 -0
- package/dist/ui-assets/reset-password.html +103 -0
- package/dist/ui-assets/ui-i18n-keys.json +78 -0
- package/dist/ui-assets/verify-email.html +66 -0
- package/package.json +89 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildAdminOpenApiSpec = exports.buildAuthOpenApiSpec = exports.buildSwaggerUiHtml = exports.buildOpenApiSpec = exports.createToolsRouter = exports.sseNotify = exports.SseNotifyRegistry = exports.webhookAction = exports.ActionRegistry = exports.AuthTools = exports.WebhookSender = exports.SseManager = exports.AuthEventNames = exports.AuthEventBus = exports.buildUiRouter = exports.createAdminRouter = exports.buildUiLink = exports.createAuthRouter = exports.createJwksAuthMiddleware = exports.createApiKeyMiddleware = exports.createAuthMiddleware = exports.JwksClient = exports.JwksService = exports.ApiKeyService = exports.NotificationService = exports.MailerService = exports.SmsService = exports.PasswordService = exports.TokenService = exports.ApiKeyStrategy = exports.TotpStrategy = exports.SmsStrategy = exports.MagicLinkStrategy = exports.GenericOAuthStrategy = exports.GithubStrategy = exports.GoogleStrategy = exports.LocalStrategy = exports.BaseOAuthStrategy = exports.BaseAuthStrategy = exports.AuthError = exports.MemoryTemplateStore = exports.fastifyAdapter = exports.expressAdapter = exports.AuthConfigurator = void 0;
|
|
4
|
+
var auth_configurator_1 = require("./auth-configurator");
|
|
5
|
+
Object.defineProperty(exports, "AuthConfigurator", { enumerable: true, get: function () { return auth_configurator_1.AuthConfigurator; } });
|
|
6
|
+
// ---- Framework adapters -------------------------------------------------------
|
|
7
|
+
var express_1 = require("./adapters/express");
|
|
8
|
+
Object.defineProperty(exports, "expressAdapter", { enumerable: true, get: function () { return express_1.expressAdapter; } });
|
|
9
|
+
var fastify_1 = require("./adapters/fastify");
|
|
10
|
+
Object.defineProperty(exports, "fastifyAdapter", { enumerable: true, get: function () { return fastify_1.fastifyAdapter; } });
|
|
11
|
+
var memory_template_store_1 = require("./stores/memory-template.store");
|
|
12
|
+
Object.defineProperty(exports, "MemoryTemplateStore", { enumerable: true, get: function () { return memory_template_store_1.MemoryTemplateStore; } });
|
|
13
|
+
var errors_1 = require("./models/errors");
|
|
14
|
+
Object.defineProperty(exports, "AuthError", { enumerable: true, get: function () { return errors_1.AuthError; } });
|
|
15
|
+
var base_auth_strategy_abstract_1 = require("./abstract/base-auth-strategy.abstract");
|
|
16
|
+
Object.defineProperty(exports, "BaseAuthStrategy", { enumerable: true, get: function () { return base_auth_strategy_abstract_1.BaseAuthStrategy; } });
|
|
17
|
+
var base_oauth_strategy_abstract_1 = require("./abstract/base-oauth-strategy.abstract");
|
|
18
|
+
Object.defineProperty(exports, "BaseOAuthStrategy", { enumerable: true, get: function () { return base_oauth_strategy_abstract_1.BaseOAuthStrategy; } });
|
|
19
|
+
var local_strategy_1 = require("./strategies/local/local.strategy");
|
|
20
|
+
Object.defineProperty(exports, "LocalStrategy", { enumerable: true, get: function () { return local_strategy_1.LocalStrategy; } });
|
|
21
|
+
var google_strategy_1 = require("./strategies/oauth/google.strategy");
|
|
22
|
+
Object.defineProperty(exports, "GoogleStrategy", { enumerable: true, get: function () { return google_strategy_1.GoogleStrategy; } });
|
|
23
|
+
var github_strategy_1 = require("./strategies/oauth/github.strategy");
|
|
24
|
+
Object.defineProperty(exports, "GithubStrategy", { enumerable: true, get: function () { return github_strategy_1.GithubStrategy; } });
|
|
25
|
+
var generic_oauth_strategy_1 = require("./strategies/oauth/generic-oauth.strategy");
|
|
26
|
+
Object.defineProperty(exports, "GenericOAuthStrategy", { enumerable: true, get: function () { return generic_oauth_strategy_1.GenericOAuthStrategy; } });
|
|
27
|
+
var magic_link_strategy_1 = require("./strategies/magic-link/magic-link.strategy");
|
|
28
|
+
Object.defineProperty(exports, "MagicLinkStrategy", { enumerable: true, get: function () { return magic_link_strategy_1.MagicLinkStrategy; } });
|
|
29
|
+
var sms_strategy_1 = require("./strategies/sms/sms.strategy");
|
|
30
|
+
Object.defineProperty(exports, "SmsStrategy", { enumerable: true, get: function () { return sms_strategy_1.SmsStrategy; } });
|
|
31
|
+
var totp_strategy_1 = require("./strategies/two-factor/totp.strategy");
|
|
32
|
+
Object.defineProperty(exports, "TotpStrategy", { enumerable: true, get: function () { return totp_strategy_1.TotpStrategy; } });
|
|
33
|
+
var api_key_strategy_1 = require("./strategies/api-key/api-key.strategy");
|
|
34
|
+
Object.defineProperty(exports, "ApiKeyStrategy", { enumerable: true, get: function () { return api_key_strategy_1.ApiKeyStrategy; } });
|
|
35
|
+
var token_service_1 = require("./services/token.service");
|
|
36
|
+
Object.defineProperty(exports, "TokenService", { enumerable: true, get: function () { return token_service_1.TokenService; } });
|
|
37
|
+
var password_service_1 = require("./services/password.service");
|
|
38
|
+
Object.defineProperty(exports, "PasswordService", { enumerable: true, get: function () { return password_service_1.PasswordService; } });
|
|
39
|
+
var sms_service_1 = require("./services/sms.service");
|
|
40
|
+
Object.defineProperty(exports, "SmsService", { enumerable: true, get: function () { return sms_service_1.SmsService; } });
|
|
41
|
+
var mailer_service_1 = require("./services/mailer.service");
|
|
42
|
+
Object.defineProperty(exports, "MailerService", { enumerable: true, get: function () { return mailer_service_1.MailerService; } });
|
|
43
|
+
var notification_service_1 = require("./services/notification.service");
|
|
44
|
+
Object.defineProperty(exports, "NotificationService", { enumerable: true, get: function () { return notification_service_1.NotificationService; } });
|
|
45
|
+
var api_key_service_1 = require("./services/api-key.service");
|
|
46
|
+
Object.defineProperty(exports, "ApiKeyService", { enumerable: true, get: function () { return api_key_service_1.ApiKeyService; } });
|
|
47
|
+
var jwks_service_1 = require("./services/jwks.service");
|
|
48
|
+
Object.defineProperty(exports, "JwksService", { enumerable: true, get: function () { return jwks_service_1.JwksService; } });
|
|
49
|
+
var jwks_service_2 = require("./services/jwks.service");
|
|
50
|
+
Object.defineProperty(exports, "JwksClient", { enumerable: true, get: function () { return jwks_service_2.JwksClient; } });
|
|
51
|
+
var auth_middleware_1 = require("./middleware/auth.middleware");
|
|
52
|
+
Object.defineProperty(exports, "createAuthMiddleware", { enumerable: true, get: function () { return auth_middleware_1.createAuthMiddleware; } });
|
|
53
|
+
var api_key_middleware_1 = require("./middleware/api-key.middleware");
|
|
54
|
+
Object.defineProperty(exports, "createApiKeyMiddleware", { enumerable: true, get: function () { return api_key_middleware_1.createApiKeyMiddleware; } });
|
|
55
|
+
var jwks_auth_middleware_1 = require("./middleware/jwks-auth.middleware");
|
|
56
|
+
Object.defineProperty(exports, "createJwksAuthMiddleware", { enumerable: true, get: function () { return jwks_auth_middleware_1.createJwksAuthMiddleware; } });
|
|
57
|
+
var auth_router_1 = require("./router/auth.router");
|
|
58
|
+
Object.defineProperty(exports, "createAuthRouter", { enumerable: true, get: function () { return auth_router_1.createAuthRouter; } });
|
|
59
|
+
Object.defineProperty(exports, "buildUiLink", { enumerable: true, get: function () { return auth_router_1.buildUiLink; } });
|
|
60
|
+
var admin_router_1 = require("./router/admin.router");
|
|
61
|
+
Object.defineProperty(exports, "createAdminRouter", { enumerable: true, get: function () { return admin_router_1.createAdminRouter; } });
|
|
62
|
+
var ui_router_1 = require("./router/ui.router");
|
|
63
|
+
Object.defineProperty(exports, "buildUiRouter", { enumerable: true, get: function () { return ui_router_1.buildUiRouter; } });
|
|
64
|
+
// ---- Event-driven tools system -------------------------------------------
|
|
65
|
+
var auth_event_bus_1 = require("./events/auth-event-bus");
|
|
66
|
+
Object.defineProperty(exports, "AuthEventBus", { enumerable: true, get: function () { return auth_event_bus_1.AuthEventBus; } });
|
|
67
|
+
var auth_event_names_1 = require("./events/auth-event-names");
|
|
68
|
+
Object.defineProperty(exports, "AuthEventNames", { enumerable: true, get: function () { return auth_event_names_1.AuthEventNames; } });
|
|
69
|
+
var sse_manager_1 = require("./tools/sse-manager");
|
|
70
|
+
Object.defineProperty(exports, "SseManager", { enumerable: true, get: function () { return sse_manager_1.SseManager; } });
|
|
71
|
+
var webhook_sender_1 = require("./tools/webhook-sender");
|
|
72
|
+
Object.defineProperty(exports, "WebhookSender", { enumerable: true, get: function () { return webhook_sender_1.WebhookSender; } });
|
|
73
|
+
var auth_tools_1 = require("./tools/auth-tools");
|
|
74
|
+
Object.defineProperty(exports, "AuthTools", { enumerable: true, get: function () { return auth_tools_1.AuthTools; } });
|
|
75
|
+
var webhook_action_1 = require("./tools/webhook-action");
|
|
76
|
+
Object.defineProperty(exports, "ActionRegistry", { enumerable: true, get: function () { return webhook_action_1.ActionRegistry; } });
|
|
77
|
+
Object.defineProperty(exports, "webhookAction", { enumerable: true, get: function () { return webhook_action_1.webhookAction; } });
|
|
78
|
+
var sse_notify_decorator_1 = require("./tools/sse-notify.decorator");
|
|
79
|
+
Object.defineProperty(exports, "SseNotifyRegistry", { enumerable: true, get: function () { return sse_notify_decorator_1.SseNotifyRegistry; } });
|
|
80
|
+
Object.defineProperty(exports, "sseNotify", { enumerable: true, get: function () { return sse_notify_decorator_1.sseNotify; } });
|
|
81
|
+
var tools_router_1 = require("./router/tools.router");
|
|
82
|
+
Object.defineProperty(exports, "createToolsRouter", { enumerable: true, get: function () { return tools_router_1.createToolsRouter; } });
|
|
83
|
+
var openapi_1 = require("./router/openapi");
|
|
84
|
+
Object.defineProperty(exports, "buildOpenApiSpec", { enumerable: true, get: function () { return openapi_1.buildOpenApiSpec; } });
|
|
85
|
+
Object.defineProperty(exports, "buildSwaggerUiHtml", { enumerable: true, get: function () { return openapi_1.buildSwaggerUiHtml; } });
|
|
86
|
+
Object.defineProperty(exports, "buildAuthOpenApiSpec", { enumerable: true, get: function () { return openapi_1.buildAuthOpenApiSpec; } });
|
|
87
|
+
Object.defineProperty(exports, "buildAdminOpenApiSpec", { enumerable: true, get: function () { return openapi_1.buildAdminOpenApiSpec; } });
|
|
88
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yDAAuD;AAA9C,qHAAA,gBAAgB,OAAA;AAMzB,kFAAkF;AAClF,8CAAoD;AAA3C,yGAAA,cAAc,OAAA;AACvB,8CAAoD;AAA3C,yGAAA,cAAc,OAAA;AAevB,wEAAqE;AAA5D,4HAAA,mBAAmB,OAAA;AAO5B,0CAA4C;AAAnC,mGAAA,SAAS,OAAA;AAGlB,sFAA0E;AAAjE,+HAAA,gBAAgB,OAAA;AACzB,wFAA4E;AAAnE,iIAAA,iBAAiB,OAAA;AAE1B,oEAAkE;AAAzD,+GAAA,aAAa,OAAA;AACtB,sEAAoE;AAA3D,iHAAA,cAAc,OAAA;AACvB,sEAAoE;AAA3D,iHAAA,cAAc,OAAA;AACvB,oFAAiF;AAAxE,8HAAA,oBAAoB,OAAA;AAE7B,mFAAgF;AAAvE,wHAAA,iBAAiB,OAAA;AAC1B,8DAA4D;AAAnD,2GAAA,WAAW,OAAA;AACpB,uEAAqE;AAA5D,6GAAA,YAAY,OAAA;AACrB,0EAAuE;AAA9D,kHAAA,cAAc,OAAA;AAGvB,0DAAwD;AAA/C,6GAAA,YAAY,OAAA;AACrB,gEAA8D;AAArD,mHAAA,eAAe,OAAA;AACxB,sDAAoD;AAA3C,yGAAA,UAAU,OAAA;AACnB,4DAA0D;AAAjD,+GAAA,aAAa,OAAA;AACtB,wEAAsE;AAA7D,2HAAA,mBAAmB,OAAA;AAG5B,8DAA2D;AAAlD,gHAAA,aAAa,OAAA;AAEtB,wDAAsD;AAA7C,2GAAA,WAAW,OAAA;AAEpB,wDAAqD;AAA5C,0GAAA,UAAU,OAAA;AAGnB,gEAAoE;AAA3D,uHAAA,oBAAoB,OAAA;AAC7B,sEAAyE;AAAhE,4HAAA,sBAAsB,OAAA;AAC/B,0EAA6E;AAApE,gIAAA,wBAAwB,OAAA;AACjC,oDAAqE;AAA5D,+GAAA,gBAAgB,OAAA;AAAE,0GAAA,WAAW,OAAA;AAEtC,sDAA0D;AAAjD,iHAAA,iBAAiB,OAAA;AAE1B,gDAAmD;AAA1C,0GAAA,aAAa,OAAA;AAGtB,6EAA6E;AAC7E,0DAAuD;AAA9C,8GAAA,YAAY,OAAA;AAErB,8DAA2D;AAAlD,kHAAA,cAAc,OAAA;AAIvB,mDAAiD;AAAxC,yGAAA,UAAU,OAAA;AAGnB,yDAAuD;AAA9C,+GAAA,aAAa,OAAA;AACtB,iDAA+C;AAAtC,uGAAA,SAAS,OAAA;AAElB,yDAAuE;AAA9D,gHAAA,cAAc,OAAA;AAAE,+GAAA,aAAa,OAAA;AAEtC,qEAA4E;AAAnE,yHAAA,iBAAiB,OAAA;AAAE,iHAAA,SAAS,OAAA;AAErC,sDAA0D;AAAjD,iHAAA,iBAAiB,OAAA;AAE1B,4CAAqH;AAA5G,2GAAA,gBAAgB,OAAA;AAAE,6GAAA,kBAAkB,OAAA;AAAE,+GAAA,oBAAoB,OAAA;AAAE,gHAAA,qBAAqB,OAAA"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { ApiKey } from '../models/api-key.model';
|
|
2
|
+
/**
|
|
3
|
+
* Pluggable persistence interface for API Keys / Service Tokens.
|
|
4
|
+
*
|
|
5
|
+
* Implement this interface and pass the instance to `ApiKeyStrategy` and
|
|
6
|
+
* `ApiKeyService`. All methods are optional except for `findByPrefix` and
|
|
7
|
+
* `findById` — only the features your application actually needs have to be
|
|
8
|
+
* implemented.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { IApiKeyStore } from '@awesome-lang-auth/node';
|
|
13
|
+
*
|
|
14
|
+
* export class MyApiKeyStore implements IApiKeyStore {
|
|
15
|
+
* async save(key: ApiKey) {
|
|
16
|
+
* await db('api_keys').insert(key);
|
|
17
|
+
* }
|
|
18
|
+
* async findByPrefix(prefix: string) {
|
|
19
|
+
* return db('api_keys').where({ keyPrefix: prefix, isActive: true }).first() ?? null;
|
|
20
|
+
* }
|
|
21
|
+
* async findById(id: string) {
|
|
22
|
+
* return db('api_keys').where({ id }).first() ?? null;
|
|
23
|
+
* }
|
|
24
|
+
* async revoke(id: string) {
|
|
25
|
+
* await db('api_keys').where({ id }).update({ isActive: false });
|
|
26
|
+
* }
|
|
27
|
+
* async updateLastUsed(id: string) {
|
|
28
|
+
* await db('api_keys').where({ id }).update({ lastUsedAt: new Date() });
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export interface IApiKeyStore {
|
|
34
|
+
/**
|
|
35
|
+
* Persist a newly created API key record.
|
|
36
|
+
*/
|
|
37
|
+
save(key: ApiKey): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Look up an active key candidate by its prefix.
|
|
40
|
+
*
|
|
41
|
+
* Because bcrypt comparison is expensive, the prefix is used as a fast
|
|
42
|
+
* lookup index. The caller will then verify the raw key against the hash.
|
|
43
|
+
*
|
|
44
|
+
* Only return records where `isActive = true`.
|
|
45
|
+
*/
|
|
46
|
+
findByPrefix(prefix: string): Promise<ApiKey | null>;
|
|
47
|
+
/**
|
|
48
|
+
* Retrieve a key record by its unique ID.
|
|
49
|
+
* Used for revocation, rotation, and admin management.
|
|
50
|
+
*/
|
|
51
|
+
findById(id: string): Promise<ApiKey | null>;
|
|
52
|
+
/**
|
|
53
|
+
* Mark a key as inactive (revoke it).
|
|
54
|
+
* After revocation all subsequent requests using this key must be rejected.
|
|
55
|
+
*/
|
|
56
|
+
revoke(id: string): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Update the `lastUsedAt` timestamp after a successful authentication.
|
|
59
|
+
* Also used for audit purposes.
|
|
60
|
+
*/
|
|
61
|
+
updateLastUsed(id: string, at?: Date): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Return all keys belonging to a given service identity.
|
|
64
|
+
* Optional — only needed if you expose a key-listing UI.
|
|
65
|
+
*/
|
|
66
|
+
listByServiceId?(serviceId: string): Promise<ApiKey[]>;
|
|
67
|
+
/**
|
|
68
|
+
* Return all key records (paginated).
|
|
69
|
+
* Optional — only needed for admin management screens.
|
|
70
|
+
*/
|
|
71
|
+
listAll?(limit: number, offset: number): Promise<ApiKey[]>;
|
|
72
|
+
/**
|
|
73
|
+
* Permanently delete a key record.
|
|
74
|
+
* Optional — prefer `revoke` for audit-trail preservation.
|
|
75
|
+
*/
|
|
76
|
+
delete?(id: string): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Append a usage audit-log entry for the given key.
|
|
79
|
+
* Optional — implement when you need per-key access logs.
|
|
80
|
+
*/
|
|
81
|
+
logUsage?(entry: ApiKeyAuditEntry): Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
/** A single usage audit record for an API key. */
|
|
84
|
+
export interface ApiKeyAuditEntry {
|
|
85
|
+
keyId: string;
|
|
86
|
+
timestamp: Date;
|
|
87
|
+
ip?: string;
|
|
88
|
+
userAgent?: string;
|
|
89
|
+
path?: string;
|
|
90
|
+
method?: string;
|
|
91
|
+
success: boolean;
|
|
92
|
+
failureReason?: string;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=api-key-store.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key-store.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/api-key-store.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjC;;;;;;;OAOG;IACH,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAErD;;;OAGG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAE7C;;;OAGG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAElC;;;OAGG;IACH,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAErD;;;OAGG;IACH,eAAe,CAAC,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAEvD;;;OAGG;IACH,OAAO,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAE3D;;;OAGG;IACH,MAAM,CAAC,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnC;;;OAGG;IACH,QAAQ,CAAC,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnD;AAED,kDAAkD;AAClD,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,IAAI,CAAC;IAChB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key-store.interface.js","sourceRoot":"","sources":["../../src/interfaces/api-key-store.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AuthConfig } from '../models/auth-config.model';
|
|
2
|
+
export interface IAuthStrategy<TInput = unknown, TOutput = unknown> {
|
|
3
|
+
name: string;
|
|
4
|
+
authenticate(input: TInput, config: AuthConfig): Promise<TOutput>;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=auth-strategy.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-strategy.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/auth-strategy.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEzD,MAAM,WAAW,aAAa,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO;IAChE,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACnE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-strategy.interface.js","sourceRoot":"","sources":["../../src/interfaces/auth-strategy.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an OAuth account linked to a user.
|
|
3
|
+
*/
|
|
4
|
+
export interface LinkedAccount {
|
|
5
|
+
/** Provider name, e.g. `'google'`, `'github'`. */
|
|
6
|
+
provider: string;
|
|
7
|
+
/** Unique user identifier returned by the provider. */
|
|
8
|
+
providerAccountId: string;
|
|
9
|
+
/** Email address returned by the provider (optional). */
|
|
10
|
+
email?: string;
|
|
11
|
+
/** Display name returned by the provider (optional). */
|
|
12
|
+
name?: string;
|
|
13
|
+
/** Profile picture URL returned by the provider (optional). */
|
|
14
|
+
picture?: string;
|
|
15
|
+
/** When the account was linked (optional). */
|
|
16
|
+
linkedAt?: Date;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Store for managing multiple OAuth provider accounts linked to a single user.
|
|
20
|
+
*
|
|
21
|
+
* Implement this interface to support flexible account linking, where a single
|
|
22
|
+
* user can have multiple OAuth providers linked to their account and can
|
|
23
|
+
* selectively unlink individual providers.
|
|
24
|
+
*
|
|
25
|
+
* When provided to `createAuthRouter` via `RouterOptions.linkedAccountsStore`,
|
|
26
|
+
* the following endpoints become available:
|
|
27
|
+
* - `GET /auth/linked-accounts` — list linked accounts (authenticated)
|
|
28
|
+
* - `DELETE /auth/linked-accounts/:provider/:providerAccountId` — unlink an account (authenticated)
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import { ILinkedAccountsStore, LinkedAccount } from '@awesome-lang-auth/node';
|
|
33
|
+
*
|
|
34
|
+
* export class MyLinkedAccountsStore implements ILinkedAccountsStore {
|
|
35
|
+
* async getLinkedAccounts(userId: string): Promise<LinkedAccount[]> {
|
|
36
|
+
* return db('linked_accounts').where({ userId });
|
|
37
|
+
* }
|
|
38
|
+
* async linkAccount(userId: string, account: LinkedAccount): Promise<void> {
|
|
39
|
+
* await db('linked_accounts').insert({ userId, ...account });
|
|
40
|
+
* }
|
|
41
|
+
* async unlinkAccount(userId: string, provider: string, providerAccountId: string): Promise<void> {
|
|
42
|
+
* await db('linked_accounts').where({ userId, provider, providerAccountId }).delete();
|
|
43
|
+
* }
|
|
44
|
+
* async findUserByProviderAccount(provider: string, providerAccountId: string): Promise<{ userId: string } | null> {
|
|
45
|
+
* const row = await db('linked_accounts').where({ provider, providerAccountId }).first();
|
|
46
|
+
* return row ? { userId: row.userId } : null;
|
|
47
|
+
* }
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export interface ILinkedAccountsStore {
|
|
52
|
+
/**
|
|
53
|
+
* Return all OAuth accounts linked to the given user.
|
|
54
|
+
*/
|
|
55
|
+
getLinkedAccounts(userId: string): Promise<LinkedAccount[]>;
|
|
56
|
+
/**
|
|
57
|
+
* Persist a new linked account for the given user.
|
|
58
|
+
* Implementations should be idempotent: re-linking the same
|
|
59
|
+
* `(provider, providerAccountId)` pair should not create a duplicate.
|
|
60
|
+
*/
|
|
61
|
+
linkAccount(userId: string, account: LinkedAccount): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Remove the link between the given user and the specified provider account.
|
|
64
|
+
*/
|
|
65
|
+
unlinkAccount(userId: string, provider: string, providerAccountId: string): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Look up the user ID that has the given provider account linked.
|
|
68
|
+
* Returns `null` if no match is found.
|
|
69
|
+
*/
|
|
70
|
+
findUserByProviderAccount(provider: string, providerAccountId: string): Promise<{
|
|
71
|
+
userId: string;
|
|
72
|
+
} | null>;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=linked-accounts-store.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linked-accounts-store.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/linked-accounts-store.interface.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,kDAAkD;IAClD,QAAQ,EAAE,MAAM,CAAC;IACjB,uDAAuD;IACvD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,yDAAyD;IACzD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,+DAA+D;IAC/D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,IAAI,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IAE5D;;;;OAIG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnE;;OAEG;IACH,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1F;;;OAGG;IACH,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;CAC5G"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linked-accounts-store.interface.js","sourceRoot":"","sources":["../../src/interfaces/linked-accounts-store.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base interface for a pending OAuth account-link document stored in a
|
|
3
|
+
* database. Use this as the foundation for Mongoose schemas or other ORM
|
|
4
|
+
* models so that the exact document shape is known at compile time.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* // Mongoose example
|
|
9
|
+
* import { IPendingLink } from '@awesome-lang-auth/node';
|
|
10
|
+
* import { Schema, model, Document } from 'mongoose';
|
|
11
|
+
*
|
|
12
|
+
* interface IPendingLinkDoc extends IPendingLink, Document {}
|
|
13
|
+
*
|
|
14
|
+
* const pendingLinkSchema = new Schema<IPendingLinkDoc>({
|
|
15
|
+
* email: { type: String, required: true, index: true },
|
|
16
|
+
* provider: { type: String, required: true },
|
|
17
|
+
* providerAccountId: { type: String, required: true },
|
|
18
|
+
* createdAt: { type: Date, default: Date.now },
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export interface IPendingLink {
|
|
23
|
+
email: string;
|
|
24
|
+
provider: string;
|
|
25
|
+
providerAccountId: string;
|
|
26
|
+
createdAt: Date;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Store for temporarily persisting OAuth account-link data for unauthenticated
|
|
30
|
+
* users who encountered an `OAUTH_ACCOUNT_CONFLICT`.
|
|
31
|
+
*
|
|
32
|
+
* Implement this interface and pass it as `pendingLinkStore` in `RouterOptions`
|
|
33
|
+
* to enable native unauthenticated account linking. When present, the library
|
|
34
|
+
* will automatically stash the conflicting provider details and include the
|
|
35
|
+
* `email` and `provider` query parameters in the `/auth/account-conflict`
|
|
36
|
+
* redirect so the front-end can drive the verification flow without any
|
|
37
|
+
* custom server-side routes.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* import { IPendingLinkStore } from '@awesome-lang-auth/node';
|
|
42
|
+
*
|
|
43
|
+
* export class InMemoryPendingLinkStore implements IPendingLinkStore {
|
|
44
|
+
* private store = new Map<string, { providerAccountId: string }>();
|
|
45
|
+
*
|
|
46
|
+
* private key(email: string, provider: string) { return `${email}::${provider}`; }
|
|
47
|
+
*
|
|
48
|
+
* async stash(email: string, provider: string, providerAccountId: string) {
|
|
49
|
+
* this.store.set(this.key(email, provider), { providerAccountId });
|
|
50
|
+
* }
|
|
51
|
+
* async retrieve(email: string, provider: string) {
|
|
52
|
+
* return this.store.get(this.key(email, provider)) ?? null;
|
|
53
|
+
* }
|
|
54
|
+
* async remove(email: string, provider: string) {
|
|
55
|
+
* this.store.delete(this.key(email, provider));
|
|
56
|
+
* }
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export interface IPendingLinkStore {
|
|
61
|
+
/**
|
|
62
|
+
* Persist a pending link so it can be retrieved later during `/link-verify`.
|
|
63
|
+
*/
|
|
64
|
+
stash(email: string, provider: string, providerAccountId: string): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Retrieve the stashed `providerAccountId` for the given `email`/`provider`
|
|
67
|
+
* pair, or `null` if no pending link exists.
|
|
68
|
+
*/
|
|
69
|
+
retrieve(email: string, provider: string): Promise<{
|
|
70
|
+
providerAccountId: string;
|
|
71
|
+
} | null>;
|
|
72
|
+
/**
|
|
73
|
+
* Remove a stashed entry after it has been consumed or invalidated.
|
|
74
|
+
*/
|
|
75
|
+
remove(email: string, provider: string): Promise<void>;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=pending-link-store.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pending-link-store.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/pending-link-store.interface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,SAAS,EAAE,IAAI,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjF;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,iBAAiB,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;IAEzF;;OAEG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pending-link-store.interface.js","sourceRoot":"","sources":["../../src/interfaces/pending-link-store.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base interface for a role document stored in a database.
|
|
3
|
+
* Use this as the foundation for Mongoose schemas or other ORM models.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* // Mongoose example
|
|
8
|
+
* import { IRoleDocument } from '@awesome-lang-auth/node';
|
|
9
|
+
* import { Schema, model, Document } from 'mongoose';
|
|
10
|
+
*
|
|
11
|
+
* interface IRoleDoc extends IRoleDocument, Document {}
|
|
12
|
+
*
|
|
13
|
+
* const roleSchema = new Schema<IRoleDoc>({
|
|
14
|
+
* name: { type: String, required: true, unique: true },
|
|
15
|
+
* permissions: [{ type: String }],
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export interface IRoleDocument {
|
|
20
|
+
name: string;
|
|
21
|
+
permissions: string[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Base interface for a user-role assignment document stored in a database.
|
|
25
|
+
* Supports both single-tenant and multi-tenant role assignments via the
|
|
26
|
+
* optional `tenantId` field.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* // Mongoose example
|
|
31
|
+
* import { IRoleUserDocument } from '@awesome-lang-auth/node';
|
|
32
|
+
* import { Schema, model, Document } from 'mongoose';
|
|
33
|
+
*
|
|
34
|
+
* interface IRoleUserDoc extends IRoleUserDocument, Document {}
|
|
35
|
+
*
|
|
36
|
+
* const roleUserSchema = new Schema<IRoleUserDoc>({
|
|
37
|
+
* userId: { type: String, required: true, index: true },
|
|
38
|
+
* role: { type: String, required: true, index: true },
|
|
39
|
+
* tenantId: { type: String, index: true },
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export interface IRoleUserDocument {
|
|
44
|
+
userId: string;
|
|
45
|
+
role: string;
|
|
46
|
+
tenantId?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Optional store for role-based access control (RBAC).
|
|
50
|
+
*
|
|
51
|
+
* Implement this interface to assign roles to users, attach fine-grained
|
|
52
|
+
* permissions to roles, and perform permission checks. All tenant-aware
|
|
53
|
+
* methods accept an optional `tenantId` parameter so the same interface
|
|
54
|
+
* works for both single-tenant and multi-tenant applications.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* import { IRolesPermissionsStore } from '@awesome-lang-auth/node';
|
|
59
|
+
*
|
|
60
|
+
* export class MyRbacStore implements IRolesPermissionsStore {
|
|
61
|
+
* async addRoleToUser(userId, role, tenantId?) { ... }
|
|
62
|
+
* async removeRoleFromUser(userId, role, tenantId?) { ... }
|
|
63
|
+
* async getRolesForUser(userId, tenantId?) { ... }
|
|
64
|
+
* async createRole(role, permissions?) { ... }
|
|
65
|
+
* async deleteRole(role) { ... }
|
|
66
|
+
* async addPermissionToRole(role, permission) { ... }
|
|
67
|
+
* async removePermissionFromRole(role, permission) { ... }
|
|
68
|
+
* async getPermissionsForRole(role) { ... }
|
|
69
|
+
* async getPermissionsForUser(userId, tenantId?) { ... }
|
|
70
|
+
* async userHasPermission(userId, permission, tenantId?) { ... }
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export interface IRolesPermissionsStore {
|
|
75
|
+
/**
|
|
76
|
+
* Assign `role` to the given user.
|
|
77
|
+
* When `tenantId` is provided the assignment is scoped to that tenant.
|
|
78
|
+
*/
|
|
79
|
+
addRoleToUser(userId: string, role: string, tenantId?: string): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Remove `role` from the given user.
|
|
82
|
+
* When `tenantId` is provided only the tenant-scoped assignment is removed.
|
|
83
|
+
*/
|
|
84
|
+
removeRoleFromUser(userId: string, role: string, tenantId?: string): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Return the list of roles assigned to the given user.
|
|
87
|
+
* When `tenantId` is provided only roles scoped to that tenant are returned.
|
|
88
|
+
*/
|
|
89
|
+
getRolesForUser(userId: string, tenantId?: string): Promise<string[]>;
|
|
90
|
+
/**
|
|
91
|
+
* Create a new role, optionally pre-loading it with a set of permissions.
|
|
92
|
+
* Idempotent — calling it on an existing role should not throw.
|
|
93
|
+
*/
|
|
94
|
+
createRole(role: string, permissions?: string[]): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Delete a role and all its permission assignments.
|
|
97
|
+
* User ↔ role assignments for this role should also be removed.
|
|
98
|
+
*/
|
|
99
|
+
deleteRole(role: string): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Add `permission` to `role`.
|
|
102
|
+
* Idempotent — adding an already-assigned permission should not throw.
|
|
103
|
+
*/
|
|
104
|
+
addPermissionToRole(role: string, permission: string): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Remove `permission` from `role`.
|
|
107
|
+
*/
|
|
108
|
+
removePermissionFromRole(role: string, permission: string): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Return all permissions assigned to `role`.
|
|
111
|
+
*/
|
|
112
|
+
getPermissionsForRole(role: string): Promise<string[]>;
|
|
113
|
+
/**
|
|
114
|
+
* Return all permissions the user has, aggregated across all their roles.
|
|
115
|
+
* When `tenantId` is provided only roles scoped to that tenant are considered.
|
|
116
|
+
*/
|
|
117
|
+
getPermissionsForUser(userId: string, tenantId?: string): Promise<string[]>;
|
|
118
|
+
/**
|
|
119
|
+
* Check whether the user has a specific permission (across any of their roles).
|
|
120
|
+
* When `tenantId` is provided only roles scoped to that tenant are checked.
|
|
121
|
+
*/
|
|
122
|
+
userHasPermission(userId: string, permission: string, tenantId?: string): Promise<boolean>;
|
|
123
|
+
/**
|
|
124
|
+
* Return all role names defined in the store.
|
|
125
|
+
* Used by the optional admin router to display the roles & permissions table.
|
|
126
|
+
*/
|
|
127
|
+
getAllRoles?(): Promise<string[]>;
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=roles-permissions-store.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roles-permissions-store.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/roles-permissions-store.interface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,WAAW,sBAAsB;IAKrC;;;OAGG;IACH,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9E;;;OAGG;IACH,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnF;;;OAGG;IACH,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAMtE;;;OAGG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhE;;;OAGG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAMxC;;;OAGG;IACH,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAErE;;OAEG;IACH,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1E;;OAEG;IACH,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAMvD;;;OAGG;IACH,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAE5E;;;OAGG;IACH,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE3F;;;OAGG;IACH,WAAW,CAAC,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CACnC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roles-permissions-store.interface.js","sourceRoot":"","sources":["../../src/interfaces/roles-permissions-store.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { SessionInfo } from '../models/session.model';
|
|
2
|
+
/**
|
|
3
|
+
* Optional store for device-aware session management.
|
|
4
|
+
*
|
|
5
|
+
* Implement this interface when you need to give users visibility into
|
|
6
|
+
* (and control over) their active sessions — similar to "Manage devices"
|
|
7
|
+
* screens in modern applications.
|
|
8
|
+
*
|
|
9
|
+
* Each session is identified by an opaque `sessionHandle` (e.g. a UUID or a
|
|
10
|
+
* hex token) that is independent of the JWT. This lets you list, inspect,
|
|
11
|
+
* and revoke individual sessions without invalidating all tokens at once.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { ISessionStore } from '@awesome-lang-auth/node';
|
|
16
|
+
*
|
|
17
|
+
* export class MySessionStore implements ISessionStore {
|
|
18
|
+
* async createSession(info) {
|
|
19
|
+
* const handle = crypto.randomUUID();
|
|
20
|
+
* await db('sessions').insert({ handle, ...info });
|
|
21
|
+
* return { sessionHandle: handle, ...info };
|
|
22
|
+
* }
|
|
23
|
+
* async getSession(handle) {
|
|
24
|
+
* return db('sessions').where({ handle }).first() ?? null;
|
|
25
|
+
* }
|
|
26
|
+
* async getSessionsForUser(userId) {
|
|
27
|
+
* return db('sessions').where({ userId });
|
|
28
|
+
* }
|
|
29
|
+
* async updateSessionLastActive(handle) {
|
|
30
|
+
* await db('sessions').where({ handle }).update({ lastActiveAt: new Date() });
|
|
31
|
+
* }
|
|
32
|
+
* async revokeSession(handle) {
|
|
33
|
+
* await db('sessions').where({ handle }).delete();
|
|
34
|
+
* }
|
|
35
|
+
* async revokeAllSessionsForUser(userId) {
|
|
36
|
+
* await db('sessions').where({ userId }).delete();
|
|
37
|
+
* }
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export interface ISessionStore {
|
|
42
|
+
/**
|
|
43
|
+
* Persist a new session and return it with the generated `sessionHandle`.
|
|
44
|
+
*/
|
|
45
|
+
createSession(info: Omit<SessionInfo, 'sessionHandle'>): Promise<SessionInfo>;
|
|
46
|
+
/**
|
|
47
|
+
* Retrieve a session by its handle.
|
|
48
|
+
* Returns `null` when the session does not exist or has expired.
|
|
49
|
+
*/
|
|
50
|
+
getSession(sessionHandle: string): Promise<SessionInfo | null>;
|
|
51
|
+
/**
|
|
52
|
+
* Return all active sessions for the given user.
|
|
53
|
+
* When `tenantId` is provided only sessions belonging to that tenant are
|
|
54
|
+
* returned.
|
|
55
|
+
*/
|
|
56
|
+
getSessionsForUser(userId: string, tenantId?: string): Promise<SessionInfo[]>;
|
|
57
|
+
/**
|
|
58
|
+
* Bump the `lastActiveAt` timestamp for the given session.
|
|
59
|
+
* Call this on every authenticated request to keep session activity up to date.
|
|
60
|
+
*/
|
|
61
|
+
updateSessionLastActive(sessionHandle: string): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Invalidate (delete) a single session.
|
|
64
|
+
*
|
|
65
|
+
* If `AuthConfig.session.checkOn` is set to `'allcalls'`, access is revoked
|
|
66
|
+
* immediately. If set to `'refresh'`, access is revoked at the next token
|
|
67
|
+
* rotation.
|
|
68
|
+
*/
|
|
69
|
+
revokeSession(sessionHandle: string): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Invalidate all sessions for the given user (e.g. "log out everywhere").
|
|
72
|
+
* When `tenantId` is provided only sessions for that tenant are revoked.
|
|
73
|
+
*/
|
|
74
|
+
revokeAllSessionsForUser(userId: string, tenantId?: string): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Return all active sessions across all users.
|
|
77
|
+
* Used by the optional admin router to display the sessions table.
|
|
78
|
+
*
|
|
79
|
+
* @param limit Maximum number of records to return.
|
|
80
|
+
* @param offset Zero-based offset for pagination.
|
|
81
|
+
*/
|
|
82
|
+
getAllSessions?(limit: number, offset: number): Promise<SessionInfo[]>;
|
|
83
|
+
/**
|
|
84
|
+
* Delete all sessions whose `expiresAt` timestamp is in the past.
|
|
85
|
+
* Intended to be called periodically (e.g. from a cron job) via the
|
|
86
|
+
* `POST /auth/sessions/cleanup` endpoint.
|
|
87
|
+
*
|
|
88
|
+
* @returns The number of sessions that were deleted.
|
|
89
|
+
*/
|
|
90
|
+
deleteExpiredSessions?(): Promise<number>;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=session-store.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-store.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/session-store.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,aAAa,CACX,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,eAAe,CAAC,GACvC,OAAO,CAAC,WAAW,CAAC,CAAC;IAExB;;;OAGG;IACH,UAAU,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IAE/D;;;;OAIG;IACH,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAE9E;;;OAGG;IACH,uBAAuB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9D;;;;;;OAMG;IACH,aAAa,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpD;;;OAGG;IACH,wBAAwB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3E;;;;;;OAMG;IACH,cAAc,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAEvE;;;;;;OAMG;IACH,qBAAqB,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CAC3C"}
|