openloops 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/README.md +1 -1
- package/dist/clients/llm/llm-client.mjs +0 -1
- package/dist/clients/llm/llm-error.mjs +0 -1
- package/dist/clients/llm/llm-types.mjs +0 -1
- package/dist/clients/llm/model-resolution.mjs +0 -1
- package/dist/clients/llm/pi-ai-adapter.mjs +0 -1
- package/dist/clients/llm/sampling-rules.mjs +0 -1
- package/dist/clients/serper/serper-client.mjs +0 -1
- package/dist/clients/slack/slack-client.mjs +0 -1
- package/dist/common/base/base.app.d.ts +3 -3
- package/dist/common/base/base.app.mjs +0 -1
- package/dist/common/base/base.entity.d.ts +4 -16
- package/dist/common/base/base.entity.js +11 -39
- package/dist/common/base/base.entity.mjs +11 -40
- package/dist/common/base/base.use-case.d.ts +1 -7
- package/dist/common/base/base.use-case.mjs +0 -1
- package/dist/common/base/current-session.mjs +0 -1
- package/dist/common/base/current-user.mjs +0 -1
- package/dist/common/base/share.mjs +0 -1
- package/dist/common/base/utils/index.d.ts +1 -2
- package/dist/common/base/utils/index.js +2 -4
- package/dist/common/base/utils/index.mjs +1 -2
- package/dist/common/base/utils/is-plain-object.mjs +0 -1
- package/dist/common/base/utils/to-patch.d.ts +9 -0
- package/dist/common/base/utils/to-patch.js +46 -0
- package/dist/common/base/utils/to-patch.mjs +21 -0
- package/dist/common/constants/harness.mjs +0 -1
- package/dist/common/error/http-error.mjs +0 -1
- package/dist/common/error/reportError.mjs +0 -1
- package/dist/common/error/sentry-client.mjs +0 -1
- package/dist/common/helpers/escape-regex.mjs +0 -1
- package/dist/common/helpers/extract-json-from-text.mjs +0 -1
- package/dist/common/helpers/sanitize-string.mjs +0 -1
- package/dist/common/logger/pino.mjs +0 -1
- package/dist/common/repositories/mongo-db.client.mjs +0 -1
- package/dist/common/repositories/mongo-db.repository.d.ts +15 -4
- package/dist/common/repositories/mongo-db.repository.js +44 -15
- package/dist/common/repositories/mongo-db.repository.mjs +44 -16
- package/dist/common/repositories/scope.mjs +0 -1
- package/dist/common/utils/database-name.mjs +0 -1
- package/dist/common/utils/number-setting.mjs +0 -1
- package/dist/common/utils/secret-manager.mjs +0 -1
- package/dist/db/indexes/agent-actions.mjs +0 -1
- package/dist/db/indexes/agent-tasks.mjs +0 -1
- package/dist/db/indexes/agent-traces.mjs +0 -1
- package/dist/db/indexes/automation-runs.mjs +0 -1
- package/dist/db/indexes/automations.mjs +0 -1
- package/dist/db/indexes/chats.mjs +0 -1
- package/dist/db/indexes/index.js +3 -1
- package/dist/db/indexes/index.mjs +3 -2
- package/dist/db/indexes/llm-calls.mjs +0 -1
- package/dist/db/indexes/mcp-servers.mjs +0 -1
- package/dist/db/indexes/refresh-tokens.d.ts +2 -0
- package/dist/{common/decorators/mask-in-logs/index.js → db/indexes/refresh-tokens.js} +16 -5
- package/dist/db/indexes/refresh-tokens.mjs +9 -0
- package/dist/db/indexes/revoked-tokens.mjs +0 -1
- package/dist/db/indexes/workspace-items.mjs +0 -1
- package/dist/db/migrations/automations.mjs +0 -1
- package/dist/guardrails/guard.mjs +0 -1
- package/dist/guardrails/index.mjs +0 -1
- package/dist/guardrails/input/block-card.mjs +0 -1
- package/dist/guardrails/input/block-code.mjs +0 -1
- package/dist/guardrails/input/block-email.mjs +0 -1
- package/dist/guardrails/input/create-block-input-oversize.mjs +0 -1
- package/dist/guardrails/input/diagnostic-sanity.mjs +0 -1
- package/dist/guardrails/input/input-check.mjs +0 -1
- package/dist/harness/agent-loop.mjs +0 -1
- package/dist/harness/agent-state.mjs +0 -1
- package/dist/harness/agent.d.ts +0 -1
- package/dist/harness/agent.js +14 -14
- package/dist/harness/agent.mjs +14 -15
- package/dist/harness/native-tools.mjs +0 -1
- package/dist/harness/skills/approval-request.mjs +0 -1
- package/dist/harness/skills/autonomous-answer.mjs +0 -1
- package/dist/harness/skills/confirmation-gate.mjs +0 -1
- package/dist/harness/skills/mcp-change-review.mjs +0 -1
- package/dist/harness/tool-catalog.mjs +0 -1
- package/dist/harness/tool-pipeline.mjs +0 -1
- package/dist/harness/utils/activity.mjs +0 -1
- package/dist/harness/utils/describe-shape.mjs +0 -1
- package/dist/harness/utils/grounding.mjs +0 -1
- package/dist/harness/utils/rank-tools-by-keywords.mjs +0 -1
- package/dist/harness/workspace.js +7 -7
- package/dist/harness/workspace.mjs +7 -8
- package/dist/loops/agi/loop.mjs +0 -1
- package/dist/loops/agi/skills/reasoning-engine.mjs +0 -1
- package/dist/loops/shared/skills/fast-responder.mjs +0 -1
- package/dist/services/authentication/entities/index.d.ts +1 -0
- package/dist/services/authentication/entities/index.js +3 -1
- package/dist/services/authentication/entities/index.mjs +1 -0
- package/dist/services/authentication/entities/refresh-token.entity.d.ts +25 -0
- package/dist/services/authentication/entities/refresh-token.entity.js +75 -0
- package/dist/services/authentication/entities/refresh-token.entity.mjs +51 -0
- package/dist/services/authentication/entities/revoked-token.entity.mjs +0 -1
- package/dist/services/authentication/helpers/auth-config.d.ts +9 -0
- package/dist/{common/decorators/index.js → services/authentication/helpers/auth-config.js} +19 -5
- package/dist/services/authentication/helpers/auth-config.mjs +12 -0
- package/dist/services/authentication/helpers/session-tokens.d.ts +16 -0
- package/dist/services/authentication/helpers/session-tokens.js +60 -0
- package/dist/services/authentication/helpers/session-tokens.mjs +35 -0
- package/dist/services/authentication/helpers/tokens.d.ts +43 -0
- package/dist/services/authentication/helpers/tokens.js +113 -0
- package/dist/services/authentication/helpers/tokens.mjs +71 -0
- package/dist/services/authentication/index.d.ts +3 -0
- package/dist/services/authentication/index.js +23 -0
- package/dist/services/authentication/index.mjs +11 -0
- package/dist/services/authentication/module.d.ts +12 -3
- package/dist/services/authentication/module.js +40 -7
- package/dist/services/authentication/module.mjs +34 -7
- package/dist/services/authentication/repositories/index.d.ts +1 -0
- package/dist/services/authentication/repositories/index.js +3 -1
- package/dist/services/authentication/repositories/index.mjs +1 -0
- package/dist/services/authentication/repositories/refresh-token.repository.d.ts +10 -0
- package/dist/services/authentication/repositories/refresh-token.repository.js +60 -0
- package/dist/services/authentication/repositories/refresh-token.repository.mjs +36 -0
- package/dist/services/authentication/repositories/revoked-token.repository.js +3 -15
- package/dist/services/authentication/repositories/revoked-token.repository.mjs +3 -10
- package/dist/services/authentication/use-cases/claim-refresh-token.use-case.d.ts +12 -0
- package/dist/services/authentication/use-cases/claim-refresh-token.use-case.js +40 -0
- package/dist/services/authentication/use-cases/claim-refresh-token.use-case.mjs +16 -0
- package/dist/services/authentication/use-cases/create-refresh-token.use-case.d.ts +11 -0
- package/dist/services/authentication/use-cases/create-refresh-token.use-case.js +43 -0
- package/dist/services/authentication/use-cases/create-refresh-token.use-case.mjs +19 -0
- package/dist/services/authentication/use-cases/find-refresh-token-by-hash.use-case.d.ts +11 -0
- package/dist/services/authentication/use-cases/find-refresh-token-by-hash.use-case.js +40 -0
- package/dist/services/authentication/use-cases/find-refresh-token-by-hash.use-case.mjs +16 -0
- package/dist/services/authentication/use-cases/is-token-revoked.use-case.d.ts +6 -8
- package/dist/services/authentication/use-cases/is-token-revoked.use-case.js +4 -18
- package/dist/services/authentication/use-cases/is-token-revoked.use-case.mjs +4 -13
- package/dist/services/authentication/use-cases/issue-password-reset-token.use-case.d.ts +18 -0
- package/dist/services/authentication/use-cases/issue-password-reset-token.use-case.js +49 -0
- package/dist/services/authentication/use-cases/issue-password-reset-token.use-case.mjs +25 -0
- package/dist/services/authentication/use-cases/issue-session.use-case.d.ts +13 -0
- package/dist/services/authentication/use-cases/issue-session.use-case.js +48 -0
- package/dist/services/authentication/use-cases/issue-session.use-case.mjs +24 -0
- package/dist/services/authentication/use-cases/login.use-case.d.ts +11 -11
- package/dist/services/authentication/use-cases/login.use-case.js +18 -54
- package/dist/services/authentication/use-cases/login.use-case.mjs +17 -38
- package/dist/services/authentication/use-cases/logout.use-case.d.ts +14 -0
- package/dist/services/authentication/use-cases/logout.use-case.js +48 -0
- package/dist/services/authentication/use-cases/logout.use-case.mjs +24 -0
- package/dist/services/authentication/use-cases/refresh.use-case.d.ts +23 -0
- package/dist/services/authentication/use-cases/refresh.use-case.js +84 -0
- package/dist/services/authentication/use-cases/refresh.use-case.mjs +60 -0
- package/dist/services/authentication/use-cases/reset-password.use-case.d.ts +15 -0
- package/dist/services/authentication/use-cases/reset-password.use-case.js +61 -0
- package/dist/services/authentication/use-cases/reset-password.use-case.mjs +37 -0
- package/dist/services/authentication/use-cases/revoke-refresh-token-family.use-case.d.ts +11 -0
- package/dist/services/authentication/use-cases/revoke-refresh-token-family.use-case.js +40 -0
- package/dist/services/authentication/use-cases/revoke-refresh-token-family.use-case.mjs +16 -0
- package/dist/services/authentication/use-cases/revoke-token.use-case.d.ts +4 -6
- package/dist/services/authentication/use-cases/revoke-token.use-case.js +12 -26
- package/dist/services/authentication/use-cases/revoke-token.use-case.mjs +10 -19
- package/dist/services/authentication/use-cases/revoke-user-refresh-tokens.use-case.d.ts +13 -0
- package/dist/services/authentication/use-cases/revoke-user-refresh-tokens.use-case.js +40 -0
- package/dist/services/authentication/use-cases/revoke-user-refresh-tokens.use-case.mjs +16 -0
- package/dist/services/automations/entities/automation-run.entity.mjs +0 -1
- package/dist/services/automations/entities/automation.entity.d.ts +1 -0
- package/dist/services/automations/entities/automation.entity.js +2 -1
- package/dist/services/automations/entities/automation.entity.mjs +2 -2
- package/dist/services/automations/entities/recurrence.mjs +0 -1
- package/dist/services/automations/entities/trigger.mjs +0 -1
- package/dist/services/automations/module.d.ts +0 -1
- package/dist/services/automations/module.js +20 -22
- package/dist/services/automations/module.mjs +20 -23
- package/dist/services/automations/repositories/automation-run.repository.js +7 -22
- package/dist/services/automations/repositories/automation-run.repository.mjs +7 -17
- package/dist/services/automations/repositories/automation.repository.js +25 -39
- package/dist/services/automations/repositories/automation.repository.mjs +25 -34
- package/dist/services/automations/runner/automation-runner.js +8 -9
- package/dist/services/automations/runner/automation-runner.mjs +8 -10
- package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.d.ts +4 -6
- package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.js +5 -19
- package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.mjs +5 -14
- package/dist/services/automations/use-cases/claim-due-automations.use-case.d.ts +9 -11
- package/dist/services/automations/use-cases/claim-due-automations.use-case.js +4 -20
- package/dist/services/automations/use-cases/claim-due-automations.use-case.mjs +4 -15
- package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.d.ts +9 -11
- package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.js +4 -20
- package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.mjs +4 -15
- package/dist/services/automations/use-cases/create-automation.use-case.d.ts +4 -6
- package/dist/services/automations/use-cases/create-automation.use-case.js +5 -19
- package/dist/services/automations/use-cases/create-automation.use-case.mjs +5 -14
- package/dist/services/automations/use-cases/delete-automation.use-case.d.ts +6 -6
- package/dist/services/automations/use-cases/delete-automation.use-case.js +8 -22
- package/dist/services/automations/use-cases/delete-automation.use-case.mjs +8 -17
- package/dist/services/automations/use-cases/finish-automation-run.use-case.d.ts +5 -7
- package/dist/services/automations/use-cases/finish-automation-run.use-case.js +5 -20
- package/dist/services/automations/use-cases/finish-automation-run.use-case.mjs +5 -15
- package/dist/services/automations/use-cases/get-automation-by-id.use-case.d.ts +4 -6
- package/dist/services/automations/use-cases/get-automation-by-id.use-case.js +5 -19
- package/dist/services/automations/use-cases/get-automation-by-id.use-case.mjs +5 -14
- package/dist/services/automations/use-cases/issue-automation-event-token.use-case.d.ts +7 -9
- package/dist/services/automations/use-cases/issue-automation-event-token.use-case.js +6 -20
- package/dist/services/automations/use-cases/issue-automation-event-token.use-case.mjs +6 -15
- package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.d.ts +6 -6
- package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.js +5 -19
- package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.mjs +5 -14
- package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.d.ts +6 -6
- package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.js +5 -19
- package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.mjs +5 -14
- package/dist/services/automations/use-cases/list-automations-by-user.use-case.d.ts +6 -6
- package/dist/services/automations/use-cases/list-automations-by-user.use-case.js +5 -19
- package/dist/services/automations/use-cases/list-automations-by-user.use-case.mjs +5 -14
- package/dist/services/automations/use-cases/preview-automation-runs.use-case.d.ts +4 -6
- package/dist/services/automations/use-cases/preview-automation-runs.use-case.js +3 -15
- package/dist/services/automations/use-cases/preview-automation-runs.use-case.mjs +3 -10
- package/dist/services/automations/use-cases/receive-automation-event.use-case.d.ts +8 -10
- package/dist/services/automations/use-cases/receive-automation-event.use-case.js +8 -23
- package/dist/services/automations/use-cases/receive-automation-event.use-case.mjs +8 -18
- package/dist/services/automations/use-cases/renew-automation-lease.use-case.d.ts +6 -8
- package/dist/services/automations/use-cases/renew-automation-lease.use-case.js +4 -18
- package/dist/services/automations/use-cases/renew-automation-lease.use-case.mjs +4 -13
- package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.d.ts +6 -8
- package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.js +8 -21
- package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.mjs +9 -17
- package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.d.ts +4 -6
- package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.js +8 -22
- package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.mjs +8 -17
- package/dist/services/automations/use-cases/start-automation-run.use-case.d.ts +8 -10
- package/dist/services/automations/use-cases/start-automation-run.use-case.js +5 -20
- package/dist/services/automations/use-cases/start-automation-run.use-case.mjs +5 -15
- package/dist/services/automations/use-cases/sync-automation-run.use-case.d.ts +5 -7
- package/dist/services/automations/use-cases/sync-automation-run.use-case.js +12 -27
- package/dist/services/automations/use-cases/sync-automation-run.use-case.mjs +12 -22
- package/dist/services/automations/use-cases/sync-automation-runs.use-case.d.ts +8 -10
- package/dist/services/automations/use-cases/sync-automation-runs.use-case.js +7 -22
- package/dist/services/automations/use-cases/sync-automation-runs.use-case.mjs +7 -17
- package/dist/services/automations/use-cases/update-automation.use-case.d.ts +4 -6
- package/dist/services/automations/use-cases/update-automation.use-case.js +10 -24
- package/dist/services/automations/use-cases/update-automation.use-case.mjs +10 -19
- package/dist/services/automations/utils/automation-event-error.mjs +0 -1
- package/dist/services/automations/utils/automation-fields.mjs +0 -1
- package/dist/services/automations/utils/event-message.mjs +0 -1
- package/dist/services/automations/utils/event-token.d.ts +1 -2
- package/dist/services/automations/utils/event-token.js +9 -35
- package/dist/services/automations/utils/event-token.mjs +9 -25
- package/dist/services/automations/utils/next-run.mjs +0 -1
- package/dist/services/automations/utils/open-run.mjs +0 -1
- package/dist/services/automations/utils/previous-run.js +1 -1
- package/dist/services/automations/utils/previous-run.mjs +1 -2
- package/dist/services/automations/utils/runner-scope.mjs +0 -1
- package/dist/services/automations/utils/settings.mjs +0 -1
- package/dist/services/chats/entities/chat-message.entity.mjs +0 -1
- package/dist/services/chats/entities/chat-settings.entity.mjs +0 -1
- package/dist/services/chats/entities/chat.entity.d.ts +1 -0
- package/dist/services/chats/entities/chat.entity.js +3 -2
- package/dist/services/chats/entities/chat.entity.mjs +3 -3
- package/dist/services/chats/module.d.ts +0 -1
- package/dist/services/chats/module.js +5 -7
- package/dist/services/chats/module.mjs +5 -8
- package/dist/services/chats/repositories/chat.repository.js +5 -20
- package/dist/services/chats/repositories/chat.repository.mjs +5 -15
- package/dist/services/chats/use-cases/create-chat.use-case.d.ts +4 -6
- package/dist/services/chats/use-cases/create-chat.use-case.js +5 -19
- package/dist/services/chats/use-cases/create-chat.use-case.mjs +5 -14
- package/dist/services/chats/use-cases/delete-chat.use-case.d.ts +6 -6
- package/dist/services/chats/use-cases/delete-chat.use-case.js +8 -22
- package/dist/services/chats/use-cases/delete-chat.use-case.mjs +8 -17
- package/dist/services/chats/use-cases/get-chat-by-id.use-case.d.ts +4 -6
- package/dist/services/chats/use-cases/get-chat-by-id.use-case.js +6 -20
- package/dist/services/chats/use-cases/get-chat-by-id.use-case.mjs +6 -15
- package/dist/services/chats/use-cases/interrupt-execution.use-case.d.ts +4 -6
- package/dist/services/chats/use-cases/interrupt-execution.use-case.js +6 -20
- package/dist/services/chats/use-cases/interrupt-execution.use-case.mjs +6 -15
- package/dist/services/chats/use-cases/list-chats-by-props.use-case.d.ts +6 -6
- package/dist/services/chats/use-cases/list-chats-by-props.use-case.js +5 -19
- package/dist/services/chats/use-cases/list-chats-by-props.use-case.mjs +5 -14
- package/dist/services/chats/use-cases/list-chats-by-user.use-case.d.ts +6 -6
- package/dist/services/chats/use-cases/list-chats-by-user.use-case.js +5 -19
- package/dist/services/chats/use-cases/list-chats-by-user.use-case.mjs +5 -14
- package/dist/services/chats/use-cases/update-chat.use-case.d.ts +5 -6
- package/dist/services/chats/use-cases/update-chat.use-case.js +8 -26
- package/dist/services/chats/use-cases/update-chat.use-case.mjs +8 -21
- package/dist/services/chats/utils/deprecated-activity.mjs +0 -1
- package/dist/services/llmcalls/entities/llmcall.entity.mjs +0 -1
- package/dist/services/llmcalls/module.d.ts +0 -1
- package/dist/services/llmcalls/module.js +4 -6
- package/dist/services/llmcalls/module.mjs +4 -7
- package/dist/services/llmcalls/repositories/llmcall.repository.js +5 -20
- package/dist/services/llmcalls/repositories/llmcall.repository.mjs +5 -15
- package/dist/services/llmcalls/use-cases/create-llmcall.use-case.d.ts +4 -6
- package/dist/services/llmcalls/use-cases/create-llmcall.use-case.js +5 -19
- package/dist/services/llmcalls/use-cases/create-llmcall.use-case.mjs +5 -14
- package/dist/services/llmcalls/use-cases/delete-llmcall.use-case.d.ts +6 -6
- package/dist/services/llmcalls/use-cases/delete-llmcall.use-case.js +8 -22
- package/dist/services/llmcalls/use-cases/delete-llmcall.use-case.mjs +8 -17
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.d.ts +4 -6
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.js +5 -19
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.mjs +5 -14
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.d.ts +4 -6
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.js +5 -19
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.mjs +5 -14
- package/dist/services/llmcalls/use-cases/get-llm-usage-stats.use-case.d.ts +4 -6
- package/dist/services/llmcalls/use-cases/get-llm-usage-stats.use-case.js +5 -19
- package/dist/services/llmcalls/use-cases/get-llm-usage-stats.use-case.mjs +5 -14
- package/dist/services/llmcalls/use-cases/get-llmcall-by-id.use-case.d.ts +4 -6
- package/dist/services/llmcalls/use-cases/get-llmcall-by-id.use-case.js +6 -20
- package/dist/services/llmcalls/use-cases/get-llmcall-by-id.use-case.mjs +6 -15
- package/dist/services/llmcalls/use-cases/list-llmcalls-by-props.use-case.d.ts +6 -6
- package/dist/services/llmcalls/use-cases/list-llmcalls-by-props.use-case.js +5 -19
- package/dist/services/llmcalls/use-cases/list-llmcalls-by-props.use-case.mjs +5 -14
- package/dist/services/llmcalls/use-cases/update-llmcall.use-case.d.ts +4 -6
- package/dist/services/llmcalls/use-cases/update-llmcall.use-case.js +7 -21
- package/dist/services/llmcalls/use-cases/update-llmcall.use-case.mjs +7 -16
- package/dist/services/llmcalls/utils/usage-periods.mjs +0 -1
- package/dist/services/llmcalls/utils/usage-totals.mjs +0 -1
- package/dist/services/mcp-servers/entities/mcp-manifest.mjs +0 -1
- package/dist/services/mcp-servers/entities/mcpserver.entity.mjs +0 -1
- package/dist/services/mcp-servers/module.d.ts +0 -1
- package/dist/services/mcp-servers/module.js +8 -10
- package/dist/services/mcp-servers/module.mjs +8 -11
- package/dist/services/mcp-servers/repositories/mcpserver.repository.js +5 -21
- package/dist/services/mcp-servers/repositories/mcpserver.repository.mjs +5 -16
- package/dist/services/mcp-servers/use-cases/create-mcpserver.use-case.d.ts +5 -7
- package/dist/services/mcp-servers/use-cases/create-mcpserver.use-case.js +5 -21
- package/dist/services/mcp-servers/use-cases/create-mcpserver.use-case.mjs +5 -16
- package/dist/services/mcp-servers/use-cases/decide-mcpserver-trust.use-case.d.ts +4 -6
- package/dist/services/mcp-servers/use-cases/decide-mcpserver-trust.use-case.js +7 -21
- package/dist/services/mcp-servers/use-cases/decide-mcpserver-trust.use-case.mjs +7 -16
- package/dist/services/mcp-servers/use-cases/delete-mcpserver.use-case.d.ts +6 -6
- package/dist/services/mcp-servers/use-cases/delete-mcpserver.use-case.js +8 -22
- package/dist/services/mcp-servers/use-cases/delete-mcpserver.use-case.mjs +8 -17
- package/dist/services/mcp-servers/use-cases/get-mcpserver-by-id.use-case.d.ts +4 -6
- package/dist/services/mcp-servers/use-cases/get-mcpserver-by-id.use-case.js +5 -19
- package/dist/services/mcp-servers/use-cases/get-mcpserver-by-id.use-case.mjs +5 -14
- package/dist/services/mcp-servers/use-cases/list-all-mcpservers-by-user.use-case.d.ts +6 -6
- package/dist/services/mcp-servers/use-cases/list-all-mcpservers-by-user.use-case.js +5 -19
- package/dist/services/mcp-servers/use-cases/list-all-mcpservers-by-user.use-case.mjs +5 -14
- package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.d.ts +6 -6
- package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.js +5 -19
- package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.mjs +5 -14
- package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.d.ts +5 -7
- package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.js +9 -25
- package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.mjs +9 -20
- package/dist/services/mcp-servers/use-cases/verify-mcpserver-connection.use-case.d.ts +4 -6
- package/dist/services/mcp-servers/use-cases/verify-mcpserver-connection.use-case.js +9 -23
- package/dist/services/mcp-servers/use-cases/verify-mcpserver-connection.use-case.mjs +9 -18
- package/dist/services/tasks/entities/agent-action.entity.mjs +0 -1
- package/dist/services/tasks/entities/agent-task.entity.mjs +0 -1
- package/dist/services/tasks/module.d.ts +0 -1
- package/dist/services/tasks/module.js +7 -9
- package/dist/services/tasks/module.mjs +7 -10
- package/dist/services/tasks/repositories/agent-action.repository.js +5 -21
- package/dist/services/tasks/repositories/agent-action.repository.mjs +5 -16
- package/dist/services/tasks/repositories/agent-task.repository.js +5 -21
- package/dist/services/tasks/repositories/agent-task.repository.mjs +5 -16
- package/dist/services/tasks/use-cases/create-agent-action.use-case.d.ts +4 -6
- package/dist/services/tasks/use-cases/create-agent-action.use-case.js +5 -19
- package/dist/services/tasks/use-cases/create-agent-action.use-case.mjs +5 -14
- package/dist/services/tasks/use-cases/create-agent-task.use-case.d.ts +4 -6
- package/dist/services/tasks/use-cases/create-agent-task.use-case.js +5 -19
- package/dist/services/tasks/use-cases/create-agent-task.use-case.mjs +5 -14
- package/dist/services/tasks/use-cases/get-agent-task-by-id.use-case.d.ts +4 -6
- package/dist/services/tasks/use-cases/get-agent-task-by-id.use-case.js +5 -19
- package/dist/services/tasks/use-cases/get-agent-task-by-id.use-case.mjs +5 -14
- package/dist/services/tasks/use-cases/list-agent-actions-by-task.use-case.d.ts +6 -6
- package/dist/services/tasks/use-cases/list-agent-actions-by-task.use-case.js +5 -19
- package/dist/services/tasks/use-cases/list-agent-actions-by-task.use-case.mjs +5 -14
- package/dist/services/tasks/use-cases/list-agent-tasks-by-chat.use-case.d.ts +6 -6
- package/dist/services/tasks/use-cases/list-agent-tasks-by-chat.use-case.js +5 -19
- package/dist/services/tasks/use-cases/list-agent-tasks-by-chat.use-case.mjs +5 -14
- package/dist/services/tasks/use-cases/update-agent-action.use-case.d.ts +4 -6
- package/dist/services/tasks/use-cases/update-agent-action.use-case.js +6 -20
- package/dist/services/tasks/use-cases/update-agent-action.use-case.mjs +6 -15
- package/dist/services/tasks/use-cases/update-agent-task.use-case.d.ts +4 -6
- package/dist/services/tasks/use-cases/update-agent-task.use-case.js +6 -20
- package/dist/services/tasks/use-cases/update-agent-task.use-case.mjs +6 -15
- package/dist/services/traces/entities/agent-trace-entry.entity.mjs +0 -1
- package/dist/services/traces/module.d.ts +0 -1
- package/dist/services/traces/module.js +2 -4
- package/dist/services/traces/module.mjs +2 -5
- package/dist/services/traces/repositories/agent-trace.repository.js +3 -15
- package/dist/services/traces/repositories/agent-trace.repository.mjs +3 -10
- package/dist/services/traces/use-cases/create-agent-traces.use-case.d.ts +6 -8
- package/dist/services/traces/use-cases/create-agent-traces.use-case.js +5 -19
- package/dist/services/traces/use-cases/create-agent-traces.use-case.mjs +5 -14
- package/dist/services/traces/use-cases/list-agent-traces-by-chat.use-case.d.ts +6 -6
- package/dist/services/traces/use-cases/list-agent-traces-by-chat.use-case.js +5 -19
- package/dist/services/traces/use-cases/list-agent-traces-by-chat.use-case.mjs +5 -14
- package/dist/services/users/entities/user-acquisition.js +2 -2
- package/dist/services/users/entities/user-acquisition.mjs +2 -3
- package/dist/services/users/entities/user-country.js +2 -2
- package/dist/services/users/entities/user-country.mjs +2 -3
- package/dist/services/users/entities/user-currency.js +2 -2
- package/dist/services/users/entities/user-currency.mjs +2 -3
- package/dist/services/users/entities/user-default-model.js +2 -2
- package/dist/services/users/entities/user-default-model.mjs +2 -3
- package/dist/services/users/entities/user-email.value-object.mjs +0 -1
- package/dist/services/users/entities/user-language.js +2 -2
- package/dist/services/users/entities/user-language.mjs +2 -3
- package/dist/services/users/entities/user-marketing.js +2 -2
- package/dist/services/users/entities/user-marketing.mjs +2 -3
- package/dist/services/users/entities/user-notification-preferences.mjs +0 -1
- package/dist/services/users/entities/user-password.value-object.mjs +0 -1
- package/dist/services/users/entities/user-permissions.mjs +0 -1
- package/dist/services/users/entities/user-preferences.mjs +0 -1
- package/dist/services/users/entities/user-report-preferences.mjs +0 -1
- package/dist/services/users/entities/user-report-schedule.mjs +0 -1
- package/dist/services/users/entities/user-timezone.js +2 -2
- package/dist/services/users/entities/user-timezone.mjs +2 -3
- package/dist/services/users/entities/user.entity.d.ts +1 -0
- package/dist/services/users/entities/user.entity.js +9 -22
- package/dist/services/users/entities/user.entity.mjs +9 -17
- package/dist/services/users/module.d.ts +2 -1
- package/dist/services/users/module.js +12 -7
- package/dist/services/users/module.mjs +11 -8
- package/dist/services/users/repositories/user.repository.d.ts +2 -0
- package/dist/services/users/repositories/user.repository.js +11 -20
- package/dist/services/users/repositories/user.repository.mjs +11 -15
- package/dist/services/users/use-cases/change-password.use-case.d.ts +15 -0
- package/dist/services/users/use-cases/change-password.use-case.js +52 -0
- package/dist/services/users/use-cases/change-password.use-case.mjs +28 -0
- package/dist/services/users/use-cases/create-user.use-case.d.ts +4 -6
- package/dist/services/users/use-cases/create-user.use-case.js +5 -19
- package/dist/services/users/use-cases/create-user.use-case.mjs +5 -14
- package/dist/services/users/use-cases/delete-user.use-case.d.ts +6 -6
- package/dist/services/users/use-cases/delete-user.use-case.js +8 -22
- package/dist/services/users/use-cases/delete-user.use-case.mjs +8 -17
- package/dist/services/users/use-cases/get-user-by-id.use-case.d.ts +4 -6
- package/dist/services/users/use-cases/get-user-by-id.use-case.js +6 -20
- package/dist/services/users/use-cases/get-user-by-id.use-case.mjs +6 -15
- package/dist/services/users/use-cases/list-users-by-props.use-case.d.ts +6 -6
- package/dist/services/users/use-cases/list-users-by-props.use-case.js +5 -19
- package/dist/services/users/use-cases/list-users-by-props.use-case.mjs +5 -14
- package/dist/services/users/use-cases/update-user.use-case.d.ts +4 -6
- package/dist/services/users/use-cases/update-user.use-case.js +9 -22
- package/dist/services/users/use-cases/update-user.use-case.mjs +9 -17
- package/dist/services/users/utils/default-model.mjs +0 -1
- package/dist/services/workspaces/entities/workspace-item.entity.mjs +0 -1
- package/dist/services/workspaces/module.d.ts +0 -1
- package/dist/services/workspaces/module.js +5 -7
- package/dist/services/workspaces/module.mjs +5 -8
- package/dist/services/workspaces/repositories/workspace-item.repository.js +5 -20
- package/dist/services/workspaces/repositories/workspace-item.repository.mjs +5 -15
- package/dist/services/workspaces/use-cases/delete-workspace-item.use-case.d.ts +6 -8
- package/dist/services/workspaces/use-cases/delete-workspace-item.use-case.js +7 -21
- package/dist/services/workspaces/use-cases/delete-workspace-item.use-case.mjs +7 -16
- package/dist/services/workspaces/use-cases/get-workspace-item.use-case.d.ts +4 -6
- package/dist/services/workspaces/use-cases/get-workspace-item.use-case.js +6 -20
- package/dist/services/workspaces/use-cases/get-workspace-item.use-case.mjs +6 -15
- package/dist/services/workspaces/use-cases/list-workspace-items.use-case.d.ts +6 -6
- package/dist/services/workspaces/use-cases/list-workspace-items.use-case.js +5 -19
- package/dist/services/workspaces/use-cases/list-workspace-items.use-case.mjs +5 -14
- package/dist/services/workspaces/use-cases/save-workspace-item.use-case.d.ts +4 -6
- package/dist/services/workspaces/use-cases/save-workspace-item.use-case.js +10 -24
- package/dist/services/workspaces/use-cases/save-workspace-item.use-case.mjs +10 -19
- package/dist/services/workspaces/use-cases/search-workspace-items.use-case.d.ts +6 -6
- package/dist/services/workspaces/use-cases/search-workspace-items.use-case.js +5 -19
- package/dist/services/workspaces/use-cases/search-workspace-items.use-case.mjs +5 -14
- package/dist/skills/call-modes.mjs +0 -1
- package/dist/skills/runtime-context.mjs +0 -1
- package/dist/skills/shared/shared-rules.mjs +0 -1
- package/dist/skills/skill.js +1 -2
- package/dist/skills/skill.mjs +1 -3
- package/dist/tools/core/call-ai/call-ai.skill.mjs +0 -1
- package/dist/tools/core/call-ai/call-ai.tool.mjs +0 -1
- package/dist/tools/core/slack/send-slack-message.tool.mjs +0 -1
- package/dist/tools/core/web-search/web-search.tool.mjs +0 -1
- package/dist/tools/tool.mjs +0 -1
- package/docs/authentication.md +95 -16
- package/docs/authorization.md +1 -1
- package/docs/automations.md +6 -5
- package/docs/chats.md +1 -1
- package/docs/configuration.md +1 -1
- package/docs/integration-guide.md +2 -2
- package/docs/mcp-servers.md +1 -1
- package/docs/usage.md +5 -5
- package/docs/users.md +1 -1
- package/examples/authentication/login.ts +1 -1
- package/examples/automations/create-automation.ts +1 -1
- package/examples/automations/create-event-automation.ts +2 -2
- package/examples/automations/list-automation-runs.ts +2 -2
- package/examples/automations/list-automations.ts +1 -1
- package/examples/automations/preview-automation-runs.ts +1 -1
- package/examples/automations/receive-automation-event.ts +1 -1
- package/examples/automations/revoke-automation-event-token.ts +2 -2
- package/examples/automations/update-automation.ts +2 -2
- package/examples/chats/get-chat-by-id.ts +2 -2
- package/examples/chats/list-autonomous-chats.ts +1 -1
- package/examples/chats/list-chats.ts +1 -1
- package/examples/mcps/decide-mcp.ts +3 -3
- package/examples/mcps/list-all-mcps.ts +1 -1
- package/examples/mcps/verify-mcp.ts +1 -1
- package/examples/usage/get-chat-usage.ts +2 -2
- package/examples/usage/get-message-usage.ts +2 -2
- package/examples/usage/get-usage-stats-by-range.ts +1 -1
- package/examples/usage/get-usage-stats.ts +3 -3
- package/examples/users/set-default-model.ts +1 -1
- package/package.json +2 -4
- package/dist/chunk-CF3WOMB3.mjs +0 -16
- package/dist/common/base/utils/delete-empty-fields.d.ts +0 -1
- package/dist/common/base/utils/delete-empty-fields.js +0 -66
- package/dist/common/base/utils/delete-empty-fields.mjs +0 -43
- package/dist/common/base/utils/flatten-object.d.ts +0 -1
- package/dist/common/base/utils/flatten-object.js +0 -45
- package/dist/common/base/utils/flatten-object.mjs +0 -22
- package/dist/common/decorators/index.d.ts +0 -1
- package/dist/common/decorators/index.mjs +0 -1
- package/dist/common/decorators/mask-in-logs/index.d.ts +0 -1
- package/dist/common/decorators/mask-in-logs/index.mjs +0 -1
- package/dist/common/decorators/mask-in-logs/mask-in-logs.d.ts +0 -2
- package/dist/common/decorators/mask-in-logs/mask-in-logs.js +0 -53
- package/dist/common/decorators/mask-in-logs/mask-in-logs.mjs +0 -29
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare const TOKEN_ISSUER = "openloops";
|
|
2
|
+
export declare const SESSION_AUDIENCE = "session";
|
|
3
|
+
export declare const PASSWORD_RESET_AUDIENCE = "password-reset";
|
|
4
|
+
export declare const AUTOMATION_EVENT_AUDIENCE = "automation-event";
|
|
5
|
+
export type TokenFailure = 'invalid' | 'expired';
|
|
6
|
+
export declare class TokenError extends Error {
|
|
7
|
+
readonly reason: TokenFailure;
|
|
8
|
+
constructor(reason: TokenFailure);
|
|
9
|
+
}
|
|
10
|
+
export interface TokenClaims {
|
|
11
|
+
sub: string;
|
|
12
|
+
iss: string;
|
|
13
|
+
aud: string;
|
|
14
|
+
iat: number;
|
|
15
|
+
exp?: number;
|
|
16
|
+
expiresAt?: Date;
|
|
17
|
+
jti?: string;
|
|
18
|
+
[claim: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
export interface SignTokenParams {
|
|
21
|
+
audience: string;
|
|
22
|
+
subject: string;
|
|
23
|
+
expiresIn?: string | number;
|
|
24
|
+
jti?: string;
|
|
25
|
+
claims?: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
export declare function signToken(params: SignTokenParams): {
|
|
28
|
+
token: string;
|
|
29
|
+
expiresAt?: Date;
|
|
30
|
+
};
|
|
31
|
+
export declare function verifyToken(token: unknown, audience: string, options?: {
|
|
32
|
+
ignoreExpiration?: boolean;
|
|
33
|
+
}): TokenClaims;
|
|
34
|
+
export interface SessionClaims {
|
|
35
|
+
userId: string;
|
|
36
|
+
sessionId?: string;
|
|
37
|
+
email?: string;
|
|
38
|
+
firstName?: string;
|
|
39
|
+
lastName?: string;
|
|
40
|
+
exp?: number;
|
|
41
|
+
}
|
|
42
|
+
export declare function verifySessionToken(token: unknown): SessionClaims;
|
|
43
|
+
export declare const hashToken: (token: string) => string;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var tokens_exports = {};
|
|
30
|
+
__export(tokens_exports, {
|
|
31
|
+
AUTOMATION_EVENT_AUDIENCE: () => AUTOMATION_EVENT_AUDIENCE,
|
|
32
|
+
PASSWORD_RESET_AUDIENCE: () => PASSWORD_RESET_AUDIENCE,
|
|
33
|
+
SESSION_AUDIENCE: () => SESSION_AUDIENCE,
|
|
34
|
+
TOKEN_ISSUER: () => TOKEN_ISSUER,
|
|
35
|
+
TokenError: () => TokenError,
|
|
36
|
+
hashToken: () => hashToken,
|
|
37
|
+
signToken: () => signToken,
|
|
38
|
+
verifySessionToken: () => verifySessionToken,
|
|
39
|
+
verifyToken: () => verifyToken
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(tokens_exports);
|
|
42
|
+
var import_node_crypto = require("node:crypto");
|
|
43
|
+
var import_jsonwebtoken = __toESM(require("jsonwebtoken"));
|
|
44
|
+
var import_secret_manager = require("../../../common/utils/secret-manager.js");
|
|
45
|
+
const TOKEN_ISSUER = "openloops";
|
|
46
|
+
const SESSION_AUDIENCE = "session";
|
|
47
|
+
const PASSWORD_RESET_AUDIENCE = "password-reset";
|
|
48
|
+
const AUTOMATION_EVENT_AUDIENCE = "automation-event";
|
|
49
|
+
class TokenError extends Error {
|
|
50
|
+
constructor(reason) {
|
|
51
|
+
super(`The token is ${reason}`);
|
|
52
|
+
this.reason = reason;
|
|
53
|
+
this.name = "TokenError";
|
|
54
|
+
}
|
|
55
|
+
reason;
|
|
56
|
+
}
|
|
57
|
+
const DURATION = /^[1-9]\d*[smhdw]$/;
|
|
58
|
+
const secret = () => {
|
|
59
|
+
const value = import_secret_manager.secretManager.get("JWT_SECRET");
|
|
60
|
+
if (!value) throw new Error("{{jwt_secret_not_found}}");
|
|
61
|
+
return value;
|
|
62
|
+
};
|
|
63
|
+
function signToken(params) {
|
|
64
|
+
const { audience, subject, expiresIn, jti, claims } = params;
|
|
65
|
+
if (typeof expiresIn === "string" && !DURATION.test(expiresIn)) throw new Error("The expiration must be a positive duration such as 30m, 12h, 30d or 2w");
|
|
66
|
+
const token = import_jsonwebtoken.default.sign({ ...claims }, secret(), {
|
|
67
|
+
algorithm: "HS256",
|
|
68
|
+
issuer: TOKEN_ISSUER,
|
|
69
|
+
audience,
|
|
70
|
+
subject,
|
|
71
|
+
...jti ? { jwtid: jti } : {},
|
|
72
|
+
...expiresIn !== void 0 ? { expiresIn } : {}
|
|
73
|
+
});
|
|
74
|
+
const { exp } = import_jsonwebtoken.default.decode(token);
|
|
75
|
+
return { token, expiresAt: exp ? new Date(exp * 1e3) : void 0 };
|
|
76
|
+
}
|
|
77
|
+
function verifyToken(token, audience, options = {}) {
|
|
78
|
+
if (typeof token !== "string" || !token) throw new TokenError("invalid");
|
|
79
|
+
try {
|
|
80
|
+
const claims = import_jsonwebtoken.default.verify(token, secret(), { algorithms: ["HS256"], issuer: TOKEN_ISSUER, audience, ignoreExpiration: options.ignoreExpiration });
|
|
81
|
+
if (typeof claims.sub !== "string" || !claims.sub) throw new TokenError("invalid");
|
|
82
|
+
return { ...claims, expiresAt: claims.exp ? new Date(claims.exp * 1e3) : void 0 };
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (error instanceof TokenError) throw error;
|
|
85
|
+
if (error?.name === "TokenExpiredError") throw new TokenError("expired");
|
|
86
|
+
if (error?.name === "JsonWebTokenError" || error?.name === "NotBeforeError") throw new TokenError("invalid");
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function verifySessionToken(token) {
|
|
91
|
+
const claims = verifyToken(token, SESSION_AUDIENCE);
|
|
92
|
+
return {
|
|
93
|
+
userId: claims.sub,
|
|
94
|
+
sessionId: typeof claims.sid === "string" ? claims.sid : void 0,
|
|
95
|
+
email: typeof claims.email === "string" ? claims.email : void 0,
|
|
96
|
+
firstName: typeof claims.firstName === "string" ? claims.firstName : void 0,
|
|
97
|
+
lastName: typeof claims.lastName === "string" ? claims.lastName : void 0,
|
|
98
|
+
exp: claims.exp
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const hashToken = (token) => (0, import_node_crypto.createHash)("sha256").update(token).digest("hex");
|
|
102
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
103
|
+
0 && (module.exports = {
|
|
104
|
+
AUTOMATION_EVENT_AUDIENCE,
|
|
105
|
+
PASSWORD_RESET_AUDIENCE,
|
|
106
|
+
SESSION_AUDIENCE,
|
|
107
|
+
TOKEN_ISSUER,
|
|
108
|
+
TokenError,
|
|
109
|
+
hashToken,
|
|
110
|
+
signToken,
|
|
111
|
+
verifySessionToken,
|
|
112
|
+
verifyToken
|
|
113
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import jwt from "jsonwebtoken";
|
|
3
|
+
import { secretManager } from "../../../common/utils/secret-manager.js";
|
|
4
|
+
const TOKEN_ISSUER = "openloops";
|
|
5
|
+
const SESSION_AUDIENCE = "session";
|
|
6
|
+
const PASSWORD_RESET_AUDIENCE = "password-reset";
|
|
7
|
+
const AUTOMATION_EVENT_AUDIENCE = "automation-event";
|
|
8
|
+
class TokenError extends Error {
|
|
9
|
+
constructor(reason) {
|
|
10
|
+
super(`The token is ${reason}`);
|
|
11
|
+
this.reason = reason;
|
|
12
|
+
this.name = "TokenError";
|
|
13
|
+
}
|
|
14
|
+
reason;
|
|
15
|
+
}
|
|
16
|
+
const DURATION = /^[1-9]\d*[smhdw]$/;
|
|
17
|
+
const secret = () => {
|
|
18
|
+
const value = secretManager.get("JWT_SECRET");
|
|
19
|
+
if (!value) throw new Error("{{jwt_secret_not_found}}");
|
|
20
|
+
return value;
|
|
21
|
+
};
|
|
22
|
+
function signToken(params) {
|
|
23
|
+
const { audience, subject, expiresIn, jti, claims } = params;
|
|
24
|
+
if (typeof expiresIn === "string" && !DURATION.test(expiresIn)) throw new Error("The expiration must be a positive duration such as 30m, 12h, 30d or 2w");
|
|
25
|
+
const token = jwt.sign({ ...claims }, secret(), {
|
|
26
|
+
algorithm: "HS256",
|
|
27
|
+
issuer: TOKEN_ISSUER,
|
|
28
|
+
audience,
|
|
29
|
+
subject,
|
|
30
|
+
...jti ? { jwtid: jti } : {},
|
|
31
|
+
...expiresIn !== void 0 ? { expiresIn } : {}
|
|
32
|
+
});
|
|
33
|
+
const { exp } = jwt.decode(token);
|
|
34
|
+
return { token, expiresAt: exp ? new Date(exp * 1e3) : void 0 };
|
|
35
|
+
}
|
|
36
|
+
function verifyToken(token, audience, options = {}) {
|
|
37
|
+
if (typeof token !== "string" || !token) throw new TokenError("invalid");
|
|
38
|
+
try {
|
|
39
|
+
const claims = jwt.verify(token, secret(), { algorithms: ["HS256"], issuer: TOKEN_ISSUER, audience, ignoreExpiration: options.ignoreExpiration });
|
|
40
|
+
if (typeof claims.sub !== "string" || !claims.sub) throw new TokenError("invalid");
|
|
41
|
+
return { ...claims, expiresAt: claims.exp ? new Date(claims.exp * 1e3) : void 0 };
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (error instanceof TokenError) throw error;
|
|
44
|
+
if (error?.name === "TokenExpiredError") throw new TokenError("expired");
|
|
45
|
+
if (error?.name === "JsonWebTokenError" || error?.name === "NotBeforeError") throw new TokenError("invalid");
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function verifySessionToken(token) {
|
|
50
|
+
const claims = verifyToken(token, SESSION_AUDIENCE);
|
|
51
|
+
return {
|
|
52
|
+
userId: claims.sub,
|
|
53
|
+
sessionId: typeof claims.sid === "string" ? claims.sid : void 0,
|
|
54
|
+
email: typeof claims.email === "string" ? claims.email : void 0,
|
|
55
|
+
firstName: typeof claims.firstName === "string" ? claims.firstName : void 0,
|
|
56
|
+
lastName: typeof claims.lastName === "string" ? claims.lastName : void 0,
|
|
57
|
+
exp: claims.exp
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const hashToken = (token) => createHash("sha256").update(token).digest("hex");
|
|
61
|
+
export {
|
|
62
|
+
AUTOMATION_EVENT_AUDIENCE,
|
|
63
|
+
PASSWORD_RESET_AUDIENCE,
|
|
64
|
+
SESSION_AUDIENCE,
|
|
65
|
+
TOKEN_ISSUER,
|
|
66
|
+
TokenError,
|
|
67
|
+
hashToken,
|
|
68
|
+
signToken,
|
|
69
|
+
verifySessionToken,
|
|
70
|
+
verifyToken
|
|
71
|
+
};
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
export * from './module';
|
|
2
2
|
export * from './entities';
|
|
3
|
+
export { TOKEN_ISSUER, SESSION_AUDIENCE, PASSWORD_RESET_AUDIENCE, AUTOMATION_EVENT_AUDIENCE, TokenError, signToken, verifyToken, verifySessionToken } from './helpers/tokens';
|
|
4
|
+
export type { SessionClaims, TokenClaims, SignTokenParams, TokenFailure } from './helpers/tokens';
|
|
5
|
+
export type { SessionTokens } from './helpers/session-tokens';
|
|
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
6
10
|
var __copyProps = (to, from, except, desc) => {
|
|
7
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
12
|
for (let key of __getOwnPropNames(from))
|
|
@@ -14,11 +18,30 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
18
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
20
|
var authentication_exports = {};
|
|
21
|
+
__export(authentication_exports, {
|
|
22
|
+
AUTOMATION_EVENT_AUDIENCE: () => import_tokens.AUTOMATION_EVENT_AUDIENCE,
|
|
23
|
+
PASSWORD_RESET_AUDIENCE: () => import_tokens.PASSWORD_RESET_AUDIENCE,
|
|
24
|
+
SESSION_AUDIENCE: () => import_tokens.SESSION_AUDIENCE,
|
|
25
|
+
TOKEN_ISSUER: () => import_tokens.TOKEN_ISSUER,
|
|
26
|
+
TokenError: () => import_tokens.TokenError,
|
|
27
|
+
signToken: () => import_tokens.signToken,
|
|
28
|
+
verifySessionToken: () => import_tokens.verifySessionToken,
|
|
29
|
+
verifyToken: () => import_tokens.verifyToken
|
|
30
|
+
});
|
|
17
31
|
module.exports = __toCommonJS(authentication_exports);
|
|
18
32
|
__reExport(authentication_exports, require("./module"), module.exports);
|
|
19
33
|
__reExport(authentication_exports, require("./entities"), module.exports);
|
|
34
|
+
var import_tokens = require("./helpers/tokens");
|
|
20
35
|
// Annotate the CommonJS export names for ESM import in node:
|
|
21
36
|
0 && (module.exports = {
|
|
37
|
+
AUTOMATION_EVENT_AUDIENCE,
|
|
38
|
+
PASSWORD_RESET_AUDIENCE,
|
|
39
|
+
SESSION_AUDIENCE,
|
|
40
|
+
TOKEN_ISSUER,
|
|
41
|
+
TokenError,
|
|
42
|
+
signToken,
|
|
43
|
+
verifySessionToken,
|
|
44
|
+
verifyToken,
|
|
22
45
|
...require("./module"),
|
|
23
46
|
...require("./entities")
|
|
24
47
|
});
|
|
@@ -1,2 +1,13 @@
|
|
|
1
1
|
export * from "./module";
|
|
2
2
|
export * from "./entities";
|
|
3
|
+
import { TOKEN_ISSUER, SESSION_AUDIENCE, PASSWORD_RESET_AUDIENCE, AUTOMATION_EVENT_AUDIENCE, TokenError, signToken, verifyToken, verifySessionToken } from "./helpers/tokens";
|
|
4
|
+
export {
|
|
5
|
+
AUTOMATION_EVENT_AUDIENCE,
|
|
6
|
+
PASSWORD_RESET_AUDIENCE,
|
|
7
|
+
SESSION_AUDIENCE,
|
|
8
|
+
TOKEN_ISSUER,
|
|
9
|
+
TokenError,
|
|
10
|
+
signToken,
|
|
11
|
+
verifySessionToken,
|
|
12
|
+
verifyToken
|
|
13
|
+
};
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
1
|
import { Params as LParams, Output as LOutput } from './use-cases/login.use-case';
|
|
3
|
-
import { Params as RParams, Output as ROutput } from './use-cases/
|
|
2
|
+
import { Params as RParams, Output as ROutput } from './use-cases/refresh.use-case';
|
|
3
|
+
import { Params as OParams, Output as OOutput } from './use-cases/logout.use-case';
|
|
4
|
+
import { Params as PParams, Output as POutput } from './use-cases/issue-password-reset-token.use-case';
|
|
5
|
+
import { Params as SParams, Output as SOutput } from './use-cases/reset-password.use-case';
|
|
6
|
+
import { Params as UParams, Output as UOutput } from './use-cases/revoke-user-refresh-tokens.use-case';
|
|
7
|
+
import { Params as TParams, Output as TOutput } from './use-cases/revoke-token.use-case';
|
|
4
8
|
import { Params as IParams, Output as IOutput } from './use-cases/is-token-revoked.use-case';
|
|
5
9
|
export declare function login(props: LParams): Promise<LOutput>;
|
|
6
|
-
export declare function
|
|
10
|
+
export declare function refreshSession(props: RParams): Promise<ROutput>;
|
|
11
|
+
export declare function logout(props: OParams): Promise<OOutput>;
|
|
12
|
+
export declare function issuePasswordResetToken(props: PParams): Promise<POutput>;
|
|
13
|
+
export declare function resetPassword(props: SParams): Promise<SOutput>;
|
|
14
|
+
export declare function revokeUserSessions(props: UParams): Promise<UOutput>;
|
|
15
|
+
export declare function revokeToken(props: TParams): Promise<TOutput>;
|
|
7
16
|
export declare function isTokenRevoked(props: IParams): Promise<IOutput>;
|
|
@@ -19,30 +19,63 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var module_exports = {};
|
|
20
20
|
__export(module_exports, {
|
|
21
21
|
isTokenRevoked: () => isTokenRevoked,
|
|
22
|
+
issuePasswordResetToken: () => issuePasswordResetToken,
|
|
22
23
|
login: () => login,
|
|
23
|
-
|
|
24
|
+
logout: () => logout,
|
|
25
|
+
refreshSession: () => refreshSession,
|
|
26
|
+
resetPassword: () => resetPassword,
|
|
27
|
+
revokeToken: () => revokeToken,
|
|
28
|
+
revokeUserSessions: () => revokeUserSessions
|
|
24
29
|
});
|
|
25
30
|
module.exports = __toCommonJS(module_exports);
|
|
26
|
-
var import_reflect_metadata = require("reflect-metadata");
|
|
27
|
-
var import_tsyringe = require("tsyringe");
|
|
28
31
|
var import_login = require("./use-cases/login.use-case");
|
|
32
|
+
var import_refresh = require("./use-cases/refresh.use-case");
|
|
33
|
+
var import_logout = require("./use-cases/logout.use-case");
|
|
34
|
+
var import_issue_password_reset_token = require("./use-cases/issue-password-reset-token.use-case");
|
|
35
|
+
var import_reset_password = require("./use-cases/reset-password.use-case");
|
|
36
|
+
var import_revoke_user_refresh_tokens = require("./use-cases/revoke-user-refresh-tokens.use-case");
|
|
29
37
|
var import_revoke_token = require("./use-cases/revoke-token.use-case");
|
|
30
38
|
var import_is_token_revoked = require("./use-cases/is-token-revoked.use-case");
|
|
31
39
|
async function login(props) {
|
|
32
|
-
const loginUseCase =
|
|
40
|
+
const loginUseCase = new import_login.LoginUseCase();
|
|
33
41
|
return loginUseCase.execute(props);
|
|
34
42
|
}
|
|
43
|
+
async function refreshSession(props) {
|
|
44
|
+
const refreshUseCase = new import_refresh.RefreshUseCase();
|
|
45
|
+
return refreshUseCase.execute(props);
|
|
46
|
+
}
|
|
47
|
+
async function logout(props) {
|
|
48
|
+
const logoutUseCase = new import_logout.LogoutUseCase();
|
|
49
|
+
return logoutUseCase.execute(props);
|
|
50
|
+
}
|
|
51
|
+
async function issuePasswordResetToken(props) {
|
|
52
|
+
const issuePasswordResetTokenUseCase = new import_issue_password_reset_token.IssuePasswordResetTokenUseCase();
|
|
53
|
+
return issuePasswordResetTokenUseCase.execute(props);
|
|
54
|
+
}
|
|
55
|
+
async function resetPassword(props) {
|
|
56
|
+
const resetPasswordUseCase = new import_reset_password.ResetPasswordUseCase();
|
|
57
|
+
return resetPasswordUseCase.execute(props);
|
|
58
|
+
}
|
|
59
|
+
async function revokeUserSessions(props) {
|
|
60
|
+
const revokeUserRefreshTokensUseCase = new import_revoke_user_refresh_tokens.RevokeUserRefreshTokensUseCase();
|
|
61
|
+
return revokeUserRefreshTokensUseCase.execute(props);
|
|
62
|
+
}
|
|
35
63
|
async function revokeToken(props) {
|
|
36
|
-
const revokeTokenUseCase =
|
|
64
|
+
const revokeTokenUseCase = new import_revoke_token.RevokeTokenUseCase();
|
|
37
65
|
return revokeTokenUseCase.execute(props);
|
|
38
66
|
}
|
|
39
67
|
async function isTokenRevoked(props) {
|
|
40
|
-
const isTokenRevokedUseCase =
|
|
68
|
+
const isTokenRevokedUseCase = new import_is_token_revoked.IsTokenRevokedUseCase();
|
|
41
69
|
return isTokenRevokedUseCase.execute(props);
|
|
42
70
|
}
|
|
43
71
|
// Annotate the CommonJS export names for ESM import in node:
|
|
44
72
|
0 && (module.exports = {
|
|
45
73
|
isTokenRevoked,
|
|
74
|
+
issuePasswordResetToken,
|
|
46
75
|
login,
|
|
47
|
-
|
|
76
|
+
logout,
|
|
77
|
+
refreshSession,
|
|
78
|
+
resetPassword,
|
|
79
|
+
revokeToken,
|
|
80
|
+
revokeUserSessions
|
|
48
81
|
});
|
|
@@ -1,23 +1,50 @@
|
|
|
1
|
-
import "../../chunk-CF3WOMB3.mjs";
|
|
2
|
-
import "reflect-metadata";
|
|
3
|
-
import { container } from "tsyringe";
|
|
4
1
|
import { LoginUseCase } from "./use-cases/login.use-case";
|
|
2
|
+
import { RefreshUseCase } from "./use-cases/refresh.use-case";
|
|
3
|
+
import { LogoutUseCase } from "./use-cases/logout.use-case";
|
|
4
|
+
import { IssuePasswordResetTokenUseCase } from "./use-cases/issue-password-reset-token.use-case";
|
|
5
|
+
import { ResetPasswordUseCase } from "./use-cases/reset-password.use-case";
|
|
6
|
+
import { RevokeUserRefreshTokensUseCase } from "./use-cases/revoke-user-refresh-tokens.use-case";
|
|
5
7
|
import { RevokeTokenUseCase } from "./use-cases/revoke-token.use-case";
|
|
6
8
|
import { IsTokenRevokedUseCase } from "./use-cases/is-token-revoked.use-case";
|
|
7
9
|
async function login(props) {
|
|
8
|
-
const loginUseCase =
|
|
10
|
+
const loginUseCase = new LoginUseCase();
|
|
9
11
|
return loginUseCase.execute(props);
|
|
10
12
|
}
|
|
13
|
+
async function refreshSession(props) {
|
|
14
|
+
const refreshUseCase = new RefreshUseCase();
|
|
15
|
+
return refreshUseCase.execute(props);
|
|
16
|
+
}
|
|
17
|
+
async function logout(props) {
|
|
18
|
+
const logoutUseCase = new LogoutUseCase();
|
|
19
|
+
return logoutUseCase.execute(props);
|
|
20
|
+
}
|
|
21
|
+
async function issuePasswordResetToken(props) {
|
|
22
|
+
const issuePasswordResetTokenUseCase = new IssuePasswordResetTokenUseCase();
|
|
23
|
+
return issuePasswordResetTokenUseCase.execute(props);
|
|
24
|
+
}
|
|
25
|
+
async function resetPassword(props) {
|
|
26
|
+
const resetPasswordUseCase = new ResetPasswordUseCase();
|
|
27
|
+
return resetPasswordUseCase.execute(props);
|
|
28
|
+
}
|
|
29
|
+
async function revokeUserSessions(props) {
|
|
30
|
+
const revokeUserRefreshTokensUseCase = new RevokeUserRefreshTokensUseCase();
|
|
31
|
+
return revokeUserRefreshTokensUseCase.execute(props);
|
|
32
|
+
}
|
|
11
33
|
async function revokeToken(props) {
|
|
12
|
-
const revokeTokenUseCase =
|
|
34
|
+
const revokeTokenUseCase = new RevokeTokenUseCase();
|
|
13
35
|
return revokeTokenUseCase.execute(props);
|
|
14
36
|
}
|
|
15
37
|
async function isTokenRevoked(props) {
|
|
16
|
-
const isTokenRevokedUseCase =
|
|
38
|
+
const isTokenRevokedUseCase = new IsTokenRevokedUseCase();
|
|
17
39
|
return isTokenRevokedUseCase.execute(props);
|
|
18
40
|
}
|
|
19
41
|
export {
|
|
20
42
|
isTokenRevoked,
|
|
43
|
+
issuePasswordResetToken,
|
|
21
44
|
login,
|
|
22
|
-
|
|
45
|
+
logout,
|
|
46
|
+
refreshSession,
|
|
47
|
+
resetPassword,
|
|
48
|
+
revokeToken,
|
|
49
|
+
revokeUserSessions
|
|
23
50
|
};
|
|
@@ -16,7 +16,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
16
16
|
var repositories_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(repositories_exports);
|
|
18
18
|
__reExport(repositories_exports, require("./revoked-token.repository"), module.exports);
|
|
19
|
+
__reExport(repositories_exports, require("./refresh-token.repository"), module.exports);
|
|
19
20
|
// Annotate the CommonJS export names for ESM import in node:
|
|
20
21
|
0 && (module.exports = {
|
|
21
|
-
...require("./revoked-token.repository")
|
|
22
|
+
...require("./revoked-token.repository"),
|
|
23
|
+
...require("./refresh-token.repository")
|
|
22
24
|
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MongoRepository, Scope } from '../../../common/repositories/index.js';
|
|
2
|
+
import { RefreshToken, RefreshTokenProps } from '../entities';
|
|
3
|
+
export declare class RefreshTokenRepository {
|
|
4
|
+
readonly _: MongoRepository<RefreshTokenProps>;
|
|
5
|
+
create(token: RefreshToken, scope: Scope): Promise<RefreshToken>;
|
|
6
|
+
findByHash(tokenHash: string, scope: Scope): Promise<RefreshTokenProps | null>;
|
|
7
|
+
claim(tokenHash: string, now: Date, scope: Scope): Promise<RefreshTokenProps | null>;
|
|
8
|
+
revokeFamily(familyId: string, now: Date, scope: Scope): Promise<number>;
|
|
9
|
+
revokeUser(userId: string, now: Date, scope: Scope, exceptFamilyId?: string): Promise<number>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var refresh_token_repository_exports = {};
|
|
20
|
+
__export(refresh_token_repository_exports, {
|
|
21
|
+
RefreshTokenRepository: () => RefreshTokenRepository
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(refresh_token_repository_exports);
|
|
24
|
+
var import_repositories = require("../../../common/repositories/index.js");
|
|
25
|
+
var import_database_name = require("../../../common/utils/database-name.js");
|
|
26
|
+
class RefreshTokenRepository {
|
|
27
|
+
_ = new import_repositories.MongoRepository({
|
|
28
|
+
database: (0, import_database_name.getDatabaseName)(),
|
|
29
|
+
collection: "refresh_tokens",
|
|
30
|
+
scoped: true,
|
|
31
|
+
ownerField: "userId"
|
|
32
|
+
});
|
|
33
|
+
async create(token, scope) {
|
|
34
|
+
const { _id, createdAt } = await this._.createOne({ payload: token.toJSON(), scope });
|
|
35
|
+
Object.assign(token, { _id, createdAt });
|
|
36
|
+
return token;
|
|
37
|
+
}
|
|
38
|
+
async findByHash(tokenHash, scope) {
|
|
39
|
+
return await this._.findOne({ scope, where: { tokenHash } });
|
|
40
|
+
}
|
|
41
|
+
async claim(tokenHash, now, scope) {
|
|
42
|
+
return await this._.claimOne({ scope, where: { tokenHash, usedAt: null, revokedAt: null }, set: { usedAt: now } });
|
|
43
|
+
}
|
|
44
|
+
async revokeFamily(familyId, now, scope) {
|
|
45
|
+
return await this._.updateMany({ scope, where: { familyId, revokedAt: null }, payload: { revokedAt: now } });
|
|
46
|
+
}
|
|
47
|
+
async revokeUser(userId, now, scope, exceptFamilyId) {
|
|
48
|
+
const id = this._.parseId(userId);
|
|
49
|
+
if (!id) return 0;
|
|
50
|
+
return await this._.updateMany({
|
|
51
|
+
scope,
|
|
52
|
+
where: { userId: id, revokedAt: null, ...exceptFamilyId ? { familyId: { $ne: exceptFamilyId } } : {} },
|
|
53
|
+
payload: { revokedAt: now }
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
RefreshTokenRepository
|
|
60
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { MongoRepository } from "../../../common/repositories/index.js";
|
|
2
|
+
import { getDatabaseName } from "../../../common/utils/database-name.js";
|
|
3
|
+
class RefreshTokenRepository {
|
|
4
|
+
_ = new MongoRepository({
|
|
5
|
+
database: getDatabaseName(),
|
|
6
|
+
collection: "refresh_tokens",
|
|
7
|
+
scoped: true,
|
|
8
|
+
ownerField: "userId"
|
|
9
|
+
});
|
|
10
|
+
async create(token, scope) {
|
|
11
|
+
const { _id, createdAt } = await this._.createOne({ payload: token.toJSON(), scope });
|
|
12
|
+
Object.assign(token, { _id, createdAt });
|
|
13
|
+
return token;
|
|
14
|
+
}
|
|
15
|
+
async findByHash(tokenHash, scope) {
|
|
16
|
+
return await this._.findOne({ scope, where: { tokenHash } });
|
|
17
|
+
}
|
|
18
|
+
async claim(tokenHash, now, scope) {
|
|
19
|
+
return await this._.claimOne({ scope, where: { tokenHash, usedAt: null, revokedAt: null }, set: { usedAt: now } });
|
|
20
|
+
}
|
|
21
|
+
async revokeFamily(familyId, now, scope) {
|
|
22
|
+
return await this._.updateMany({ scope, where: { familyId, revokedAt: null }, payload: { revokedAt: now } });
|
|
23
|
+
}
|
|
24
|
+
async revokeUser(userId, now, scope, exceptFamilyId) {
|
|
25
|
+
const id = this._.parseId(userId);
|
|
26
|
+
if (!id) return 0;
|
|
27
|
+
return await this._.updateMany({
|
|
28
|
+
scope,
|
|
29
|
+
where: { userId: id, revokedAt: null, ...exceptFamilyId ? { familyId: { $ne: exceptFamilyId } } : {} },
|
|
30
|
+
payload: { revokedAt: now }
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
RefreshTokenRepository
|
|
36
|
+
};
|
|
@@ -16,40 +16,28 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var __decorateClass = (decorators, target, key, kind) => {
|
|
20
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
21
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
22
|
-
if (decorator = decorators[i])
|
|
23
|
-
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
24
|
-
if (kind && result) __defProp(target, key, result);
|
|
25
|
-
return result;
|
|
26
|
-
};
|
|
27
19
|
var revoked_token_repository_exports = {};
|
|
28
20
|
__export(revoked_token_repository_exports, {
|
|
29
21
|
RevokedTokenRepository: () => RevokedTokenRepository
|
|
30
22
|
});
|
|
31
23
|
module.exports = __toCommonJS(revoked_token_repository_exports);
|
|
32
|
-
var import_tsyringe = require("tsyringe");
|
|
33
24
|
var import_repositories = require("../../../common/repositories/index.js");
|
|
34
25
|
var import_database_name = require("../../../common/utils/database-name.js");
|
|
35
|
-
|
|
26
|
+
class RevokedTokenRepository {
|
|
36
27
|
_ = new import_repositories.MongoRepository({
|
|
37
28
|
database: (0, import_database_name.getDatabaseName)(),
|
|
38
29
|
collection: "revoked_tokens",
|
|
39
30
|
scoped: true
|
|
40
31
|
});
|
|
41
32
|
async create(token, scope) {
|
|
42
|
-
const { _id, ownerId, createdAt, createdBy } = await this._.createOne({ payload: token.
|
|
33
|
+
const { _id, ownerId, createdAt, createdBy } = await this._.createOne({ payload: token.toJSON(), scope });
|
|
43
34
|
Object.assign(token, { _id, ownerId, createdAt, createdBy });
|
|
44
35
|
return token;
|
|
45
36
|
}
|
|
46
37
|
async findByJti(jti, scope) {
|
|
47
38
|
return await this._.findOne({ scope, where: { jti } });
|
|
48
39
|
}
|
|
49
|
-
}
|
|
50
|
-
RevokedTokenRepository = __decorateClass([
|
|
51
|
-
(0, import_tsyringe.autoInjectable)()
|
|
52
|
-
], RevokedTokenRepository);
|
|
40
|
+
}
|
|
53
41
|
// Annotate the CommonJS export names for ESM import in node:
|
|
54
42
|
0 && (module.exports = {
|
|
55
43
|
RevokedTokenRepository
|
|
@@ -1,27 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__decorateClass
|
|
3
|
-
} from "../../../chunk-CF3WOMB3.mjs";
|
|
4
|
-
import { autoInjectable } from "tsyringe";
|
|
5
1
|
import { MongoRepository } from "../../../common/repositories/index.js";
|
|
6
2
|
import { getDatabaseName } from "../../../common/utils/database-name.js";
|
|
7
|
-
|
|
3
|
+
class RevokedTokenRepository {
|
|
8
4
|
_ = new MongoRepository({
|
|
9
5
|
database: getDatabaseName(),
|
|
10
6
|
collection: "revoked_tokens",
|
|
11
7
|
scoped: true
|
|
12
8
|
});
|
|
13
9
|
async create(token, scope) {
|
|
14
|
-
const { _id, ownerId, createdAt, createdBy } = await this._.createOne({ payload: token.
|
|
10
|
+
const { _id, ownerId, createdAt, createdBy } = await this._.createOne({ payload: token.toJSON(), scope });
|
|
15
11
|
Object.assign(token, { _id, ownerId, createdAt, createdBy });
|
|
16
12
|
return token;
|
|
17
13
|
}
|
|
18
14
|
async findByJti(jti, scope) {
|
|
19
15
|
return await this._.findOne({ scope, where: { jti } });
|
|
20
16
|
}
|
|
21
|
-
}
|
|
22
|
-
RevokedTokenRepository = __decorateClass([
|
|
23
|
-
autoInjectable()
|
|
24
|
-
], RevokedTokenRepository);
|
|
17
|
+
}
|
|
25
18
|
export {
|
|
26
19
|
RevokedTokenRepository
|
|
27
20
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseUseCase, BaseUseCaseParams } from '../../../common/base/base.use-case.js';
|
|
2
|
+
import { RefreshTokenProps } from '../entities';
|
|
3
|
+
import { RefreshTokenRepository } from '../repositories';
|
|
4
|
+
export interface Params extends BaseUseCaseParams {
|
|
5
|
+
tokenHash: string;
|
|
6
|
+
now: Date;
|
|
7
|
+
}
|
|
8
|
+
export declare class ClaimRefreshTokenUseCase extends BaseUseCase<Params, RefreshTokenProps | null> {
|
|
9
|
+
private readonly refreshTokenRepository;
|
|
10
|
+
constructor(refreshTokenRepository?: RefreshTokenRepository);
|
|
11
|
+
execute(params: Params): Promise<RefreshTokenProps | null>;
|
|
12
|
+
}
|