openloops 0.4.5 → 0.6.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 +52 -0
- package/README.md +2 -1
- package/dist/common/base/base.entity.d.ts +3 -9
- package/dist/common/base/base.entity.js +17 -96
- package/dist/common/base/base.entity.mjs +19 -92
- package/dist/common/base/base.use-case.d.ts +2 -0
- package/dist/common/base/index.d.ts +1 -0
- package/dist/common/base/index.js +3 -1
- package/dist/common/base/index.mjs +1 -0
- package/dist/common/base/share.d.ts +12 -0
- package/dist/common/base/share.js +45 -0
- package/dist/common/base/share.mjs +21 -0
- package/dist/common/decorators/index.d.ts +0 -2
- package/dist/common/decorators/index.js +1 -5
- package/dist/common/decorators/index.mjs +0 -2
- package/dist/common/repositories/index.d.ts +1 -0
- package/dist/common/repositories/index.js +3 -1
- package/dist/common/repositories/index.mjs +1 -0
- package/dist/common/repositories/mongo-db.repository.d.ts +31 -11
- package/dist/common/repositories/mongo-db.repository.js +121 -40
- package/dist/common/repositories/mongo-db.repository.mjs +121 -40
- package/dist/common/repositories/scope.d.ts +19 -0
- package/dist/common/repositories/scope.js +63 -0
- package/dist/common/repositories/scope.mjs +40 -0
- package/dist/db/indexes/automations.js +1 -1
- package/dist/db/indexes/automations.mjs +1 -1
- package/dist/db/migrations/automations.d.ts +1 -0
- package/dist/db/migrations/automations.js +32 -5
- package/dist/db/migrations/automations.mjs +32 -5
- package/dist/services/authentication/repositories/revoked-token.repository.d.ts +3 -3
- package/dist/services/authentication/repositories/revoked-token.repository.js +7 -6
- package/dist/services/authentication/repositories/revoked-token.repository.mjs +7 -6
- package/dist/services/authentication/use-cases/is-token-revoked.use-case.js +2 -1
- package/dist/services/authentication/use-cases/is-token-revoked.use-case.mjs +2 -1
- package/dist/services/authentication/use-cases/login.use-case.js +2 -1
- package/dist/services/authentication/use-cases/login.use-case.mjs +2 -1
- package/dist/services/authentication/use-cases/revoke-token.use-case.js +5 -4
- package/dist/services/authentication/use-cases/revoke-token.use-case.mjs +5 -4
- package/dist/services/automations/entities/automation.entity.d.ts +9 -9
- package/dist/services/automations/entities/automation.entity.js +21 -20
- package/dist/services/automations/entities/automation.entity.mjs +21 -20
- package/dist/services/automations/entities/trigger.d.ts +16 -8
- package/dist/services/automations/entities/trigger.js +28 -17
- package/dist/services/automations/entities/trigger.mjs +27 -16
- package/dist/services/automations/repositories/automation-run.repository.d.ts +10 -10
- package/dist/services/automations/repositories/automation-run.repository.js +21 -18
- package/dist/services/automations/repositories/automation-run.repository.mjs +21 -18
- package/dist/services/automations/repositories/automation.repository.d.ts +14 -13
- package/dist/services/automations/repositories/automation.repository.js +34 -22
- package/dist/services/automations/repositories/automation.repository.mjs +34 -22
- package/dist/services/automations/runner/automation-runner.d.ts +3 -0
- package/dist/services/automations/runner/automation-runner.js +2 -2
- package/dist/services/automations/runner/automation-runner.mjs +2 -2
- package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.js +3 -2
- package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.mjs +3 -2
- package/dist/services/automations/use-cases/claim-due-automations.use-case.js +11 -10
- package/dist/services/automations/use-cases/claim-due-automations.use-case.mjs +11 -10
- package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.js +10 -9
- package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.mjs +10 -9
- package/dist/services/automations/use-cases/create-automation.use-case.d.ts +2 -2
- package/dist/services/automations/use-cases/create-automation.use-case.js +8 -8
- package/dist/services/automations/use-cases/create-automation.use-case.mjs +6 -6
- package/dist/services/automations/use-cases/delete-automation.use-case.js +6 -9
- package/dist/services/automations/use-cases/delete-automation.use-case.mjs +4 -7
- package/dist/services/automations/use-cases/finish-automation-run.use-case.js +4 -3
- package/dist/services/automations/use-cases/finish-automation-run.use-case.mjs +4 -3
- package/dist/services/automations/use-cases/get-automation-by-id.use-case.js +5 -4
- package/dist/services/automations/use-cases/get-automation-by-id.use-case.mjs +3 -2
- package/dist/services/automations/use-cases/issue-automation-event-token.use-case.js +7 -7
- package/dist/services/automations/use-cases/issue-automation-event-token.use-case.mjs +5 -5
- package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.js +3 -1
- package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.mjs +3 -1
- package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.js +2 -0
- package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.mjs +2 -0
- package/dist/services/automations/use-cases/list-automations-by-user.use-case.js +2 -0
- package/dist/services/automations/use-cases/list-automations-by-user.use-case.mjs +2 -0
- package/dist/services/automations/use-cases/receive-automation-event.use-case.js +10 -8
- package/dist/services/automations/use-cases/receive-automation-event.use-case.mjs +10 -8
- package/dist/services/automations/use-cases/renew-automation-lease.use-case.js +2 -1
- package/dist/services/automations/use-cases/renew-automation-lease.use-case.mjs +2 -1
- package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.js +5 -5
- package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.mjs +3 -3
- package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.js +10 -10
- package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.mjs +8 -8
- package/dist/services/automations/use-cases/start-automation-run.use-case.js +8 -6
- package/dist/services/automations/use-cases/start-automation-run.use-case.mjs +8 -6
- package/dist/services/automations/use-cases/sync-automation-run.use-case.js +6 -5
- package/dist/services/automations/use-cases/sync-automation-run.use-case.mjs +6 -5
- package/dist/services/automations/use-cases/sync-automation-runs.use-case.js +3 -2
- package/dist/services/automations/use-cases/sync-automation-runs.use-case.mjs +3 -2
- package/dist/services/automations/use-cases/update-automation.use-case.d.ts +2 -2
- package/dist/services/automations/use-cases/update-automation.use-case.js +16 -12
- package/dist/services/automations/use-cases/update-automation.use-case.mjs +14 -10
- package/dist/services/automations/utils/automation-fields.d.ts +3 -4
- package/dist/services/automations/utils/automation-fields.js +3 -5
- package/dist/services/automations/utils/automation-fields.mjs +4 -6
- package/dist/services/automations/utils/open-run.d.ts +2 -0
- package/dist/services/automations/utils/open-run.js +2 -2
- package/dist/services/automations/utils/open-run.mjs +2 -2
- package/dist/services/automations/utils/previous-run.js +3 -2
- package/dist/services/automations/utils/previous-run.mjs +3 -2
- package/dist/services/automations/utils/runner-scope.d.ts +3 -0
- package/dist/{common/decorators/admin-only/index.js → services/automations/utils/runner-scope.js} +15 -5
- package/dist/services/automations/utils/runner-scope.mjs +8 -0
- package/dist/services/chats/repositories/chat.repository.d.ts +7 -6
- package/dist/services/chats/repositories/chat.repository.js +16 -11
- package/dist/services/chats/repositories/chat.repository.mjs +16 -11
- package/dist/services/chats/use-cases/create-chat.use-case.js +4 -5
- package/dist/services/chats/use-cases/create-chat.use-case.mjs +2 -3
- package/dist/services/chats/use-cases/delete-chat.use-case.js +7 -9
- package/dist/services/chats/use-cases/delete-chat.use-case.mjs +5 -7
- package/dist/services/chats/use-cases/get-chat-by-id.use-case.js +3 -2
- package/dist/services/chats/use-cases/get-chat-by-id.use-case.mjs +3 -2
- package/dist/services/chats/use-cases/interrupt-execution.use-case.js +5 -7
- package/dist/services/chats/use-cases/interrupt-execution.use-case.mjs +3 -5
- package/dist/services/chats/use-cases/list-chats-by-props.use-case.js +3 -2
- package/dist/services/chats/use-cases/list-chats-by-props.use-case.mjs +3 -2
- package/dist/services/chats/use-cases/list-chats-by-user.use-case.js +2 -0
- package/dist/services/chats/use-cases/list-chats-by-user.use-case.mjs +2 -0
- package/dist/services/chats/use-cases/update-chat.use-case.js +5 -7
- package/dist/services/chats/use-cases/update-chat.use-case.mjs +3 -5
- package/dist/services/llmcalls/repositories/llmcall.repository.d.ts +7 -6
- package/dist/services/llmcalls/repositories/llmcall.repository.js +16 -11
- package/dist/services/llmcalls/repositories/llmcall.repository.mjs +16 -11
- package/dist/services/llmcalls/use-cases/create-llmcall.use-case.js +4 -5
- package/dist/services/llmcalls/use-cases/create-llmcall.use-case.mjs +2 -3
- package/dist/services/llmcalls/use-cases/delete-llmcall.use-case.js +6 -8
- package/dist/services/llmcalls/use-cases/delete-llmcall.use-case.mjs +4 -6
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.js +4 -3
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.mjs +2 -1
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.js +4 -3
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.mjs +2 -1
- package/dist/services/llmcalls/use-cases/get-llm-usage-stats.use-case.js +2 -1
- package/dist/services/llmcalls/use-cases/get-llm-usage-stats.use-case.mjs +2 -1
- package/dist/services/llmcalls/use-cases/get-llmcall-by-id.use-case.js +6 -4
- package/dist/services/llmcalls/use-cases/get-llmcall-by-id.use-case.mjs +4 -2
- package/dist/services/llmcalls/use-cases/list-llmcalls-by-props.use-case.js +3 -2
- package/dist/services/llmcalls/use-cases/list-llmcalls-by-props.use-case.mjs +3 -2
- package/dist/services/llmcalls/use-cases/update-llmcall.use-case.js +5 -7
- package/dist/services/llmcalls/use-cases/update-llmcall.use-case.mjs +3 -5
- package/dist/services/mcp-servers/repositories/mcpserver.repository.d.ts +8 -7
- package/dist/services/mcp-servers/repositories/mcpserver.repository.js +18 -12
- package/dist/services/mcp-servers/repositories/mcpserver.repository.mjs +18 -12
- package/dist/services/mcp-servers/use-cases/create-mcpserver.use-case.js +4 -5
- package/dist/services/mcp-servers/use-cases/create-mcpserver.use-case.mjs +2 -3
- package/dist/services/mcp-servers/use-cases/decide-mcpserver-trust.use-case.js +8 -9
- package/dist/services/mcp-servers/use-cases/decide-mcpserver-trust.use-case.mjs +6 -7
- package/dist/services/mcp-servers/use-cases/delete-mcpserver.use-case.js +6 -8
- package/dist/services/mcp-servers/use-cases/delete-mcpserver.use-case.mjs +4 -6
- package/dist/services/mcp-servers/use-cases/get-mcpserver-by-id.use-case.js +5 -4
- package/dist/services/mcp-servers/use-cases/get-mcpserver-by-id.use-case.mjs +3 -2
- package/dist/services/mcp-servers/use-cases/list-all-mcpservers-by-user.use-case.js +4 -3
- package/dist/services/mcp-servers/use-cases/list-all-mcpservers-by-user.use-case.mjs +2 -1
- package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.js +8 -11
- package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.mjs +6 -9
- package/dist/services/mcp-servers/use-cases/verify-mcpserver-connection.use-case.js +9 -9
- package/dist/services/mcp-servers/use-cases/verify-mcpserver-connection.use-case.mjs +7 -7
- package/dist/services/tasks/repositories/agent-action.repository.d.ts +4 -4
- package/dist/services/tasks/repositories/agent-action.repository.js +9 -7
- package/dist/services/tasks/repositories/agent-action.repository.mjs +9 -7
- package/dist/services/tasks/repositories/agent-task.repository.d.ts +5 -5
- package/dist/services/tasks/repositories/agent-task.repository.js +11 -9
- package/dist/services/tasks/repositories/agent-task.repository.mjs +11 -9
- package/dist/services/tasks/use-cases/create-agent-action.use-case.js +4 -5
- package/dist/services/tasks/use-cases/create-agent-action.use-case.mjs +2 -3
- package/dist/services/tasks/use-cases/create-agent-task.use-case.js +4 -5
- package/dist/services/tasks/use-cases/create-agent-task.use-case.mjs +2 -3
- package/dist/services/tasks/use-cases/get-agent-task-by-id.use-case.js +5 -4
- package/dist/services/tasks/use-cases/get-agent-task-by-id.use-case.mjs +3 -2
- package/dist/services/tasks/use-cases/list-agent-actions-by-task.use-case.js +3 -1
- package/dist/services/tasks/use-cases/list-agent-actions-by-task.use-case.mjs +3 -1
- package/dist/services/tasks/use-cases/list-agent-tasks-by-chat.use-case.js +3 -1
- package/dist/services/tasks/use-cases/list-agent-tasks-by-chat.use-case.mjs +3 -1
- package/dist/services/tasks/use-cases/update-agent-action.use-case.js +5 -7
- package/dist/services/tasks/use-cases/update-agent-action.use-case.mjs +3 -5
- package/dist/services/tasks/use-cases/update-agent-task.use-case.js +5 -7
- package/dist/services/tasks/use-cases/update-agent-task.use-case.mjs +3 -5
- package/dist/services/traces/repositories/agent-trace.repository.d.ts +3 -3
- package/dist/services/traces/repositories/agent-trace.repository.js +6 -5
- package/dist/services/traces/repositories/agent-trace.repository.mjs +6 -5
- package/dist/services/traces/use-cases/create-agent-traces.use-case.js +5 -9
- package/dist/services/traces/use-cases/create-agent-traces.use-case.mjs +3 -7
- package/dist/services/traces/use-cases/list-agent-traces-by-chat.use-case.js +3 -1
- package/dist/services/traces/use-cases/list-agent-traces-by-chat.use-case.mjs +3 -1
- package/dist/services/users/entities/user-acquisition.js +3 -16
- package/dist/services/users/entities/user-acquisition.mjs +4 -11
- package/dist/services/users/entities/user-marketing.js +3 -16
- package/dist/services/users/entities/user-marketing.mjs +4 -11
- package/dist/services/users/entities/user.entity.js +0 -3
- package/dist/services/users/entities/user.entity.mjs +1 -4
- package/dist/services/users/repositories/user.repository.d.ts +8 -7
- package/dist/services/users/repositories/user.repository.js +26 -12
- package/dist/services/users/repositories/user.repository.mjs +26 -12
- package/dist/services/users/use-cases/create-user.use-case.d.ts +0 -1
- package/dist/services/users/use-cases/create-user.use-case.js +5 -5
- package/dist/services/users/use-cases/create-user.use-case.mjs +3 -3
- package/dist/services/users/use-cases/delete-user.use-case.js +7 -9
- package/dist/services/users/use-cases/delete-user.use-case.mjs +5 -7
- package/dist/services/users/use-cases/get-user-by-id.use-case.js +6 -4
- package/dist/services/users/use-cases/get-user-by-id.use-case.mjs +4 -2
- package/dist/services/users/use-cases/list-users-by-props.use-case.js +3 -2
- package/dist/services/users/use-cases/list-users-by-props.use-case.mjs +3 -2
- package/dist/services/users/use-cases/update-user.use-case.js +5 -7
- package/dist/services/users/use-cases/update-user.use-case.mjs +3 -5
- package/dist/services/workspaces/repositories/workspace-item.repository.d.ts +8 -8
- package/dist/services/workspaces/repositories/workspace-item.repository.js +17 -14
- package/dist/services/workspaces/repositories/workspace-item.repository.mjs +17 -14
- package/dist/services/workspaces/use-cases/delete-workspace-item.use-case.js +6 -3
- package/dist/services/workspaces/use-cases/delete-workspace-item.use-case.mjs +4 -1
- package/dist/services/workspaces/use-cases/get-workspace-item.use-case.js +4 -3
- package/dist/services/workspaces/use-cases/get-workspace-item.use-case.mjs +2 -1
- package/dist/services/workspaces/use-cases/list-workspace-items.use-case.js +2 -0
- package/dist/services/workspaces/use-cases/list-workspace-items.use-case.mjs +2 -0
- package/dist/services/workspaces/use-cases/save-workspace-item.use-case.js +8 -8
- package/dist/services/workspaces/use-cases/save-workspace-item.use-case.mjs +6 -6
- package/dist/services/workspaces/use-cases/search-workspace-items.use-case.js +2 -0
- package/dist/services/workspaces/use-cases/search-workspace-items.use-case.mjs +2 -0
- package/docs/README.md +3 -2
- package/docs/agent.md +2 -2
- package/docs/authorization.md +77 -0
- package/docs/automations.md +143 -41
- package/docs/integration-guide.md +8 -10
- package/docs/llms.txt +1 -0
- package/docs/mcp-servers.md +4 -4
- package/docs/users.md +6 -4
- package/examples/automations/create-automation.ts +6 -5
- package/examples/automations/create-event-automation.ts +1 -1
- package/examples/automations/list-automation-runs.ts +2 -0
- package/examples/automations/list-automations.ts +3 -2
- package/examples/automations/preview-automation-runs.ts +1 -1
- package/examples/automations/revoke-automation-event-token.ts +1 -1
- package/examples/automations/run-automation-now.ts +3 -1
- package/examples/automations/update-automation.ts +4 -5
- package/examples/chats/delete-chat.ts +1 -1
- package/examples/mcps/internal-mcp.ts +3 -3
- package/examples/run-agent/run-agent-with-identity.ts +1 -1
- package/examples/users/create-user.ts +2 -1
- package/examples/users/list-users.ts +1 -0
- package/package.json +1 -1
- package/dist/common/decorators/admin-only/admin-only.d.ts +0 -2
- package/dist/common/decorators/admin-only/admin-only.js +0 -52
- package/dist/common/decorators/admin-only/admin-only.mjs +0 -28
- package/dist/common/decorators/admin-only/index.d.ts +0 -1
- package/dist/common/decorators/admin-only/index.mjs +0 -1
- package/dist/common/decorators/owner-only/index.d.ts +0 -1
- package/dist/common/decorators/owner-only/index.js +0 -22
- package/dist/common/decorators/owner-only/index.mjs +0 -1
- package/dist/common/decorators/owner-only/owner-only.d.ts +0 -2
- package/dist/common/decorators/owner-only/owner-only.js +0 -52
- package/dist/common/decorators/owner-only/owner-only.mjs +0 -28
|
@@ -33,6 +33,7 @@ module.exports = __toCommonJS(is_token_revoked_use_case_exports);
|
|
|
33
33
|
var import_tsyringe = require("tsyringe");
|
|
34
34
|
var import_base = require("../../../common/base/base.use-case.js");
|
|
35
35
|
var import_repositories = require("../repositories");
|
|
36
|
+
var import_repositories2 = require("../../../common/repositories/index.js");
|
|
36
37
|
let IsTokenRevokedUseCase = class extends import_base.BaseUseCase {
|
|
37
38
|
constructor(revokedTokenRepository) {
|
|
38
39
|
super();
|
|
@@ -41,7 +42,7 @@ let IsTokenRevokedUseCase = class extends import_base.BaseUseCase {
|
|
|
41
42
|
revokedTokenRepository;
|
|
42
43
|
async execute(params) {
|
|
43
44
|
if (!params.jti) throw new Error("The jti is required");
|
|
44
|
-
const found = await this.revokedTokenRepository.findByJti(params.jti);
|
|
45
|
+
const found = await this.revokedTokenRepository.findByJti(params.jti, params.scope ?? import_repositories2.Scope.system("revoked tokens are checked by jti, not by owner"));
|
|
45
46
|
return { data: { revoked: Boolean(found) } };
|
|
46
47
|
}
|
|
47
48
|
};
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
import { autoInjectable, inject } from "tsyringe";
|
|
6
6
|
import { BaseUseCase } from "../../../common/base/base.use-case.js";
|
|
7
7
|
import { RevokedTokenRepository } from "../repositories";
|
|
8
|
+
import { Scope } from "../../../common/repositories/index.js";
|
|
8
9
|
let IsTokenRevokedUseCase = class extends BaseUseCase {
|
|
9
10
|
constructor(revokedTokenRepository) {
|
|
10
11
|
super();
|
|
@@ -13,7 +14,7 @@ let IsTokenRevokedUseCase = class extends BaseUseCase {
|
|
|
13
14
|
revokedTokenRepository;
|
|
14
15
|
async execute(params) {
|
|
15
16
|
if (!params.jti) throw new Error("The jti is required");
|
|
16
|
-
const found = await this.revokedTokenRepository.findByJti(params.jti);
|
|
17
|
+
const found = await this.revokedTokenRepository.findByJti(params.jti, params.scope ?? Scope.system("revoked tokens are checked by jti, not by owner"));
|
|
17
18
|
return { data: { revoked: Boolean(found) } };
|
|
18
19
|
}
|
|
19
20
|
};
|
|
@@ -43,6 +43,7 @@ var import_jsonwebtoken = __toESM(require("jsonwebtoken"));
|
|
|
43
43
|
var import_tsyringe = require("tsyringe");
|
|
44
44
|
var import_base = require("../../../common/base/base.use-case.js");
|
|
45
45
|
var import_entities = require("../../users/entities/index.js");
|
|
46
|
+
var import_repositories2 = require("../../../common/repositories/index.js");
|
|
46
47
|
let LoginUseCase = class extends import_base.BaseUseCase {
|
|
47
48
|
constructor(userRepository) {
|
|
48
49
|
super();
|
|
@@ -54,7 +55,7 @@ let LoginUseCase = class extends import_base.BaseUseCase {
|
|
|
54
55
|
if (!SECRET_KEY) throw new Error("{{jwt_secret_not_found}}");
|
|
55
56
|
const { payload } = params;
|
|
56
57
|
const { emailOrUsername, password } = payload;
|
|
57
|
-
const user = await this.userRepository.findByEmailOrUsernameWithPassword(emailOrUsername);
|
|
58
|
+
const user = await this.userRepository.findByEmailOrUsernameWithPassword(emailOrUsername, params.scope ?? import_repositories2.Scope.system("login: the user is not known before the credentials are checked"));
|
|
58
59
|
if (!user) {
|
|
59
60
|
return this.throwHttpError({
|
|
60
61
|
statusCode: 404,
|
|
@@ -5,6 +5,7 @@ import jwt from "jsonwebtoken";
|
|
|
5
5
|
import { autoInjectable } from "tsyringe";
|
|
6
6
|
import { BaseUseCase } from "../../../common/base/base.use-case.js";
|
|
7
7
|
import { UserRole } from "../../users/entities/index.js";
|
|
8
|
+
import { Scope } from "../../../common/repositories/index.js";
|
|
8
9
|
let LoginUseCase = class extends BaseUseCase {
|
|
9
10
|
constructor(userRepository) {
|
|
10
11
|
super();
|
|
@@ -16,7 +17,7 @@ let LoginUseCase = class extends BaseUseCase {
|
|
|
16
17
|
if (!SECRET_KEY) throw new Error("{{jwt_secret_not_found}}");
|
|
17
18
|
const { payload } = params;
|
|
18
19
|
const { emailOrUsername, password } = payload;
|
|
19
|
-
const user = await this.userRepository.findByEmailOrUsernameWithPassword(emailOrUsername);
|
|
20
|
+
const user = await this.userRepository.findByEmailOrUsernameWithPassword(emailOrUsername, params.scope ?? Scope.system("login: the user is not known before the credentials are checked"));
|
|
20
21
|
if (!user) {
|
|
21
22
|
return this.throwHttpError({
|
|
22
23
|
statusCode: 404,
|
|
@@ -34,6 +34,7 @@ var import_tsyringe = require("tsyringe");
|
|
|
34
34
|
var import_base = require("../../../common/base/base.use-case.js");
|
|
35
35
|
var import_entities = require("../entities");
|
|
36
36
|
var import_repositories = require("../repositories");
|
|
37
|
+
var import_repositories2 = require("../../../common/repositories/index.js");
|
|
37
38
|
let RevokeTokenUseCase = class extends import_base.BaseUseCase {
|
|
38
39
|
constructor(revokedTokenRepository) {
|
|
39
40
|
super();
|
|
@@ -43,12 +44,12 @@ let RevokeTokenUseCase = class extends import_base.BaseUseCase {
|
|
|
43
44
|
async execute(params) {
|
|
44
45
|
const { payload, currentUser } = params;
|
|
45
46
|
if (!payload?.jti || !payload.audience || !payload.subject) throw new Error("The jti, the audience and the subject are required to revoke a token");
|
|
46
|
-
const
|
|
47
|
+
const scope = params.scope ?? import_repositories2.Scope.system("revoked tokens are checked by jti, not by owner");
|
|
48
|
+
const existing = await this.revokedTokenRepository.findByJti(payload.jti, scope);
|
|
47
49
|
if (existing) return { data: existing };
|
|
48
|
-
const revoked = import_entities.RevokedToken.fromJSON({ jti: payload.jti, audience: payload.audience, subject: payload.subject, expiresAt: payload.expiresAt });
|
|
49
|
-
revoked.setCreatedBy(currentUser);
|
|
50
|
+
const revoked = import_entities.RevokedToken.fromJSON({ jti: payload.jti, audience: payload.audience, subject: payload.subject, expiresAt: payload.expiresAt, createdBy: currentUser?.userId });
|
|
50
51
|
try {
|
|
51
|
-
await this.revokedTokenRepository.create(revoked);
|
|
52
|
+
await this.revokedTokenRepository.create(revoked, scope);
|
|
52
53
|
} catch (error) {
|
|
53
54
|
if (error?.code !== 11e3) throw error;
|
|
54
55
|
}
|
|
@@ -6,6 +6,7 @@ import { autoInjectable, inject } from "tsyringe";
|
|
|
6
6
|
import { BaseUseCase } from "../../../common/base/base.use-case.js";
|
|
7
7
|
import { RevokedToken } from "../entities";
|
|
8
8
|
import { RevokedTokenRepository } from "../repositories";
|
|
9
|
+
import { Scope } from "../../../common/repositories/index.js";
|
|
9
10
|
let RevokeTokenUseCase = class extends BaseUseCase {
|
|
10
11
|
constructor(revokedTokenRepository) {
|
|
11
12
|
super();
|
|
@@ -15,12 +16,12 @@ let RevokeTokenUseCase = class extends BaseUseCase {
|
|
|
15
16
|
async execute(params) {
|
|
16
17
|
const { payload, currentUser } = params;
|
|
17
18
|
if (!payload?.jti || !payload.audience || !payload.subject) throw new Error("The jti, the audience and the subject are required to revoke a token");
|
|
18
|
-
const
|
|
19
|
+
const scope = params.scope ?? Scope.system("revoked tokens are checked by jti, not by owner");
|
|
20
|
+
const existing = await this.revokedTokenRepository.findByJti(payload.jti, scope);
|
|
19
21
|
if (existing) return { data: existing };
|
|
20
|
-
const revoked = RevokedToken.fromJSON({ jti: payload.jti, audience: payload.audience, subject: payload.subject, expiresAt: payload.expiresAt });
|
|
21
|
-
revoked.setCreatedBy(currentUser);
|
|
22
|
+
const revoked = RevokedToken.fromJSON({ jti: payload.jti, audience: payload.audience, subject: payload.subject, expiresAt: payload.expiresAt, createdBy: currentUser?.userId });
|
|
22
23
|
try {
|
|
23
|
-
await this.revokedTokenRepository.create(revoked);
|
|
24
|
+
await this.revokedTokenRepository.create(revoked, scope);
|
|
24
25
|
} catch (error) {
|
|
25
26
|
if (error?.code !== 11e3) throw error;
|
|
26
27
|
}
|
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
import { ObjectId } from 'mongodb';
|
|
2
2
|
import { BaseEntity, BaseEntityProps } from '../../../common/base/base.entity.js';
|
|
3
|
-
import {
|
|
3
|
+
import { AutomationTriggers, AutomationTriggersInput } from './trigger';
|
|
4
4
|
import type { AutomationRunStatus } from './automation-run.entity';
|
|
5
5
|
export interface AutomationProps extends BaseEntityProps {
|
|
6
6
|
name?: string;
|
|
7
7
|
instructions?: string;
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
triggers?: AutomationTriggers;
|
|
9
|
+
eventTokenVersion?: number;
|
|
10
10
|
modelProvider?: string;
|
|
11
11
|
modelName?: string;
|
|
12
|
-
nextRunAt?: string | Date | null;
|
|
13
12
|
lastRunAt?: string | Date | null;
|
|
14
13
|
lastRunStatus?: AutomationRunStatus;
|
|
15
14
|
lockedBy?: string | null;
|
|
16
15
|
lockedUntil?: string | Date | null;
|
|
17
16
|
activeRunId?: string | ObjectId | null;
|
|
18
17
|
}
|
|
18
|
+
export type AutomationPayload = Omit<AutomationProps, 'triggers'> & {
|
|
19
|
+
triggers?: AutomationTriggersInput;
|
|
20
|
+
};
|
|
19
21
|
export declare class Automation extends BaseEntity {
|
|
20
22
|
private readonly props;
|
|
21
23
|
name?: string | undefined;
|
|
22
24
|
instructions?: string | undefined;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
triggers?: AutomationTriggers | undefined;
|
|
26
|
+
eventTokenVersion?: number | undefined;
|
|
25
27
|
modelProvider?: string | undefined;
|
|
26
28
|
modelName?: string | undefined;
|
|
27
|
-
nextRunAt?: Date | undefined;
|
|
28
29
|
lastRunAt?: Date | undefined;
|
|
29
30
|
lastRunStatus?: AutomationRunStatus | undefined;
|
|
30
31
|
lockedBy?: string | undefined;
|
|
31
32
|
lockedUntil?: Date | undefined;
|
|
32
33
|
activeRunId?: ObjectId | undefined;
|
|
33
34
|
static fromJSON(props: AutomationProps): Automation;
|
|
34
|
-
constructor(props: AutomationProps, name?: string | undefined, instructions?: string | undefined,
|
|
35
|
+
constructor(props: AutomationProps, name?: string | undefined, instructions?: string | undefined, triggers?: AutomationTriggers | undefined, eventTokenVersion?: number | undefined, modelProvider?: string | undefined, modelName?: string | undefined, lastRunAt?: Date | undefined, lastRunStatus?: AutomationRunStatus | undefined, lockedBy?: string | undefined, lockedUntil?: Date | undefined, activeRunId?: ObjectId | undefined);
|
|
35
36
|
toJSON(): AutomationProps;
|
|
36
|
-
isScheduled(): boolean;
|
|
37
37
|
scheduleNextRun(from?: Date): this;
|
|
38
38
|
}
|
|
@@ -29,17 +29,22 @@ const toDate = (value) => {
|
|
|
29
29
|
if (Number.isNaN(date.getTime())) throw new Error("{{value_must_be_a_date}}");
|
|
30
30
|
return date;
|
|
31
31
|
};
|
|
32
|
+
const readTriggerDates = (triggers) => {
|
|
33
|
+
if (!triggers?.schedule) return triggers;
|
|
34
|
+
const { nextRunAt, ...schedule } = triggers.schedule;
|
|
35
|
+
const date = toDate(nextRunAt);
|
|
36
|
+
return { ...triggers, schedule: { ...schedule, ...date ? { nextRunAt: date } : {} } };
|
|
37
|
+
};
|
|
32
38
|
class Automation extends import_base.BaseEntity {
|
|
33
|
-
constructor(props, name, instructions,
|
|
39
|
+
constructor(props, name, instructions, triggers, eventTokenVersion, modelProvider, modelName, lastRunAt, lastRunStatus, lockedBy, lockedUntil, activeRunId) {
|
|
34
40
|
super(props);
|
|
35
41
|
this.props = props;
|
|
36
42
|
this.name = name;
|
|
37
43
|
this.instructions = instructions;
|
|
38
|
-
this.
|
|
39
|
-
this.
|
|
44
|
+
this.triggers = triggers;
|
|
45
|
+
this.eventTokenVersion = eventTokenVersion;
|
|
40
46
|
this.modelProvider = modelProvider;
|
|
41
47
|
this.modelName = modelName;
|
|
42
|
-
this.nextRunAt = nextRunAt;
|
|
43
48
|
this.lastRunAt = lastRunAt;
|
|
44
49
|
this.lastRunStatus = lastRunStatus;
|
|
45
50
|
this.lockedBy = lockedBy;
|
|
@@ -49,11 +54,10 @@ class Automation extends import_base.BaseEntity {
|
|
|
49
54
|
props;
|
|
50
55
|
name;
|
|
51
56
|
instructions;
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
triggers;
|
|
58
|
+
eventTokenVersion;
|
|
54
59
|
modelProvider;
|
|
55
60
|
modelName;
|
|
56
|
-
nextRunAt;
|
|
57
61
|
lastRunAt;
|
|
58
62
|
lastRunStatus;
|
|
59
63
|
lockedBy;
|
|
@@ -64,11 +68,10 @@ class Automation extends import_base.BaseEntity {
|
|
|
64
68
|
props,
|
|
65
69
|
props.name || void 0,
|
|
66
70
|
props.instructions || void 0,
|
|
67
|
-
props.
|
|
68
|
-
props.
|
|
71
|
+
readTriggerDates(props.triggers),
|
|
72
|
+
props.eventTokenVersion,
|
|
69
73
|
props.modelProvider || void 0,
|
|
70
74
|
props.modelName || void 0,
|
|
71
|
-
toDate(props.nextRunAt),
|
|
72
75
|
toDate(props.lastRunAt),
|
|
73
76
|
props.lastRunStatus,
|
|
74
77
|
props.lockedBy || void 0,
|
|
@@ -81,11 +84,10 @@ class Automation extends import_base.BaseEntity {
|
|
|
81
84
|
...super.toJSON(),
|
|
82
85
|
name: this.name,
|
|
83
86
|
instructions: this.instructions,
|
|
84
|
-
|
|
85
|
-
|
|
87
|
+
triggers: this.triggers,
|
|
88
|
+
eventTokenVersion: this.eventTokenVersion,
|
|
86
89
|
modelProvider: this.modelProvider,
|
|
87
90
|
modelName: this.modelName,
|
|
88
|
-
nextRunAt: this.nextRunAt,
|
|
89
91
|
lastRunAt: this.lastRunAt,
|
|
90
92
|
lastRunStatus: this.lastRunStatus,
|
|
91
93
|
lockedBy: this.lockedBy,
|
|
@@ -93,16 +95,15 @@ class Automation extends import_base.BaseEntity {
|
|
|
93
95
|
activeRunId: this.activeRunId
|
|
94
96
|
};
|
|
95
97
|
}
|
|
96
|
-
isScheduled() {
|
|
97
|
-
return this.trigger?.type === "schedule";
|
|
98
|
-
}
|
|
99
98
|
scheduleNextRun(from = /* @__PURE__ */ new Date()) {
|
|
100
|
-
const
|
|
101
|
-
|
|
99
|
+
const schedule = this.triggers?.schedule;
|
|
100
|
+
if (!schedule) return this;
|
|
101
|
+
const next = schedule.enabled ? (0, import_next_run.computeNextRun)(schedule.recurrence, schedule.timezone, from) : null;
|
|
102
102
|
if (next) {
|
|
103
|
-
|
|
103
|
+
schedule.nextRunAt = next;
|
|
104
104
|
} else {
|
|
105
|
-
|
|
105
|
+
delete schedule.nextRunAt;
|
|
106
|
+
this.toUnset = { ...this.toUnset, "triggers.schedule.nextRunAt": "" };
|
|
106
107
|
}
|
|
107
108
|
return this;
|
|
108
109
|
}
|
|
@@ -7,17 +7,22 @@ const toDate = (value) => {
|
|
|
7
7
|
if (Number.isNaN(date.getTime())) throw new Error("{{value_must_be_a_date}}");
|
|
8
8
|
return date;
|
|
9
9
|
};
|
|
10
|
+
const readTriggerDates = (triggers) => {
|
|
11
|
+
if (!triggers?.schedule) return triggers;
|
|
12
|
+
const { nextRunAt, ...schedule } = triggers.schedule;
|
|
13
|
+
const date = toDate(nextRunAt);
|
|
14
|
+
return { ...triggers, schedule: { ...schedule, ...date ? { nextRunAt: date } : {} } };
|
|
15
|
+
};
|
|
10
16
|
class Automation extends BaseEntity {
|
|
11
|
-
constructor(props, name, instructions,
|
|
17
|
+
constructor(props, name, instructions, triggers, eventTokenVersion, modelProvider, modelName, lastRunAt, lastRunStatus, lockedBy, lockedUntil, activeRunId) {
|
|
12
18
|
super(props);
|
|
13
19
|
this.props = props;
|
|
14
20
|
this.name = name;
|
|
15
21
|
this.instructions = instructions;
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
22
|
+
this.triggers = triggers;
|
|
23
|
+
this.eventTokenVersion = eventTokenVersion;
|
|
18
24
|
this.modelProvider = modelProvider;
|
|
19
25
|
this.modelName = modelName;
|
|
20
|
-
this.nextRunAt = nextRunAt;
|
|
21
26
|
this.lastRunAt = lastRunAt;
|
|
22
27
|
this.lastRunStatus = lastRunStatus;
|
|
23
28
|
this.lockedBy = lockedBy;
|
|
@@ -27,11 +32,10 @@ class Automation extends BaseEntity {
|
|
|
27
32
|
props;
|
|
28
33
|
name;
|
|
29
34
|
instructions;
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
triggers;
|
|
36
|
+
eventTokenVersion;
|
|
32
37
|
modelProvider;
|
|
33
38
|
modelName;
|
|
34
|
-
nextRunAt;
|
|
35
39
|
lastRunAt;
|
|
36
40
|
lastRunStatus;
|
|
37
41
|
lockedBy;
|
|
@@ -42,11 +46,10 @@ class Automation extends BaseEntity {
|
|
|
42
46
|
props,
|
|
43
47
|
props.name || void 0,
|
|
44
48
|
props.instructions || void 0,
|
|
45
|
-
props.
|
|
46
|
-
props.
|
|
49
|
+
readTriggerDates(props.triggers),
|
|
50
|
+
props.eventTokenVersion,
|
|
47
51
|
props.modelProvider || void 0,
|
|
48
52
|
props.modelName || void 0,
|
|
49
|
-
toDate(props.nextRunAt),
|
|
50
53
|
toDate(props.lastRunAt),
|
|
51
54
|
props.lastRunStatus,
|
|
52
55
|
props.lockedBy || void 0,
|
|
@@ -59,11 +62,10 @@ class Automation extends BaseEntity {
|
|
|
59
62
|
...super.toJSON(),
|
|
60
63
|
name: this.name,
|
|
61
64
|
instructions: this.instructions,
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
triggers: this.triggers,
|
|
66
|
+
eventTokenVersion: this.eventTokenVersion,
|
|
64
67
|
modelProvider: this.modelProvider,
|
|
65
68
|
modelName: this.modelName,
|
|
66
|
-
nextRunAt: this.nextRunAt,
|
|
67
69
|
lastRunAt: this.lastRunAt,
|
|
68
70
|
lastRunStatus: this.lastRunStatus,
|
|
69
71
|
lockedBy: this.lockedBy,
|
|
@@ -71,16 +73,15 @@ class Automation extends BaseEntity {
|
|
|
71
73
|
activeRunId: this.activeRunId
|
|
72
74
|
};
|
|
73
75
|
}
|
|
74
|
-
isScheduled() {
|
|
75
|
-
return this.trigger?.type === "schedule";
|
|
76
|
-
}
|
|
77
76
|
scheduleNextRun(from = /* @__PURE__ */ new Date()) {
|
|
78
|
-
const
|
|
79
|
-
|
|
77
|
+
const schedule = this.triggers?.schedule;
|
|
78
|
+
if (!schedule) return this;
|
|
79
|
+
const next = schedule.enabled ? computeNextRun(schedule.recurrence, schedule.timezone, from) : null;
|
|
80
80
|
if (next) {
|
|
81
|
-
|
|
81
|
+
schedule.nextRunAt = next;
|
|
82
82
|
} else {
|
|
83
|
-
|
|
83
|
+
delete schedule.nextRunAt;
|
|
84
|
+
this.toUnset = { ...this.toUnset, "triggers.schedule.nextRunAt": "" };
|
|
84
85
|
}
|
|
85
86
|
return this;
|
|
86
87
|
}
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { Recurrence } from './recurrence';
|
|
2
|
-
export
|
|
3
|
-
|
|
2
|
+
export interface ScheduleTrigger {
|
|
3
|
+
enabled: boolean;
|
|
4
4
|
recurrence: Recurrence;
|
|
5
5
|
timezone: string;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
export
|
|
6
|
+
nextRunAt?: string | Date | null;
|
|
7
|
+
}
|
|
8
|
+
export interface EventTrigger {
|
|
9
|
+
enabled: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface AutomationTriggers {
|
|
12
|
+
schedule?: ScheduleTrigger;
|
|
13
|
+
event?: EventTrigger;
|
|
14
|
+
}
|
|
15
|
+
export interface AutomationTriggersInput {
|
|
16
|
+
schedule?: Partial<Pick<ScheduleTrigger, 'enabled' | 'recurrence' | 'timezone'>> | null;
|
|
17
|
+
event?: Partial<EventTrigger> | null;
|
|
18
|
+
}
|
|
19
|
+
export declare function readTriggers(input: unknown, existing?: AutomationTriggers): AutomationTriggers;
|
|
@@ -18,32 +18,43 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var trigger_exports = {};
|
|
20
20
|
__export(trigger_exports, {
|
|
21
|
-
|
|
21
|
+
readTriggers: () => readTriggers
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(trigger_exports);
|
|
24
24
|
var import_recurrence = require("./recurrence");
|
|
25
25
|
var import_next_run = require("../utils/next-run");
|
|
26
26
|
const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
const readEnabled = (value, fallback) => {
|
|
28
|
+
if (value === void 0) return fallback;
|
|
29
|
+
if (typeof value !== "boolean") throw new Error("The field enabled must be true or false");
|
|
30
|
+
return value;
|
|
31
|
+
};
|
|
32
|
+
function readSchedule(input, existing) {
|
|
33
|
+
if (!isRecord(input)) throw new Error("The schedule trigger must be an object");
|
|
33
34
|
const has = (key) => input[key] !== void 0;
|
|
34
|
-
if (type === "event") {
|
|
35
|
-
const event = previous;
|
|
36
|
-
const timezone = has("timezone") ? (0, import_next_run.assertTimezone)(input.timezone) : event?.timezone;
|
|
37
|
-
return { type, tokenVersion: event?.tokenVersion ?? 1, ...timezone ? { timezone } : {} };
|
|
38
|
-
}
|
|
39
|
-
const schedule = previous;
|
|
40
35
|
return {
|
|
41
|
-
|
|
42
|
-
recurrence: has("recurrence") || !
|
|
43
|
-
timezone: has("timezone") || !
|
|
36
|
+
enabled: readEnabled(input.enabled, existing?.enabled ?? true),
|
|
37
|
+
recurrence: has("recurrence") || !existing ? (0, import_recurrence.validateRecurrence)(input.recurrence) : existing.recurrence,
|
|
38
|
+
timezone: has("timezone") || !existing ? (0, import_next_run.assertTimezone)(input.timezone) : existing.timezone,
|
|
39
|
+
...existing?.nextRunAt ? { nextRunAt: existing.nextRunAt } : {}
|
|
44
40
|
};
|
|
45
41
|
}
|
|
42
|
+
function readEvent(input, existing) {
|
|
43
|
+
if (!isRecord(input)) throw new Error("The event trigger must be an object");
|
|
44
|
+
return { enabled: readEnabled(input.enabled, existing?.enabled ?? true) };
|
|
45
|
+
}
|
|
46
|
+
function readTriggers(input, existing = {}) {
|
|
47
|
+
if (!isRecord(input)) throw new Error("The triggers are required");
|
|
48
|
+
if (Object.keys(input).some((key) => key !== "schedule" && key !== "event")) throw new Error("The triggers can only be schedule or event");
|
|
49
|
+
const triggers = { ...existing };
|
|
50
|
+
if (input.schedule === null) delete triggers.schedule;
|
|
51
|
+
else if (input.schedule !== void 0) triggers.schedule = readSchedule(input.schedule, existing.schedule);
|
|
52
|
+
if (input.event === null) delete triggers.event;
|
|
53
|
+
else if (input.event !== void 0) triggers.event = readEvent(input.event, existing.event);
|
|
54
|
+
if (!triggers.schedule && !triggers.event) throw new Error("The automation needs at least one trigger");
|
|
55
|
+
return triggers;
|
|
56
|
+
}
|
|
46
57
|
// Annotate the CommonJS export names for ESM import in node:
|
|
47
58
|
0 && (module.exports = {
|
|
48
|
-
|
|
59
|
+
readTriggers
|
|
49
60
|
});
|
|
@@ -2,25 +2,36 @@ import "../../../chunk-CF3WOMB3.mjs";
|
|
|
2
2
|
import { validateRecurrence } from "./recurrence";
|
|
3
3
|
import { assertTimezone } from "../utils/next-run";
|
|
4
4
|
const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
5
|
-
|
|
6
|
-
if (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
const readEnabled = (value, fallback) => {
|
|
6
|
+
if (value === void 0) return fallback;
|
|
7
|
+
if (typeof value !== "boolean") throw new Error("The field enabled must be true or false");
|
|
8
|
+
return value;
|
|
9
|
+
};
|
|
10
|
+
function readSchedule(input, existing) {
|
|
11
|
+
if (!isRecord(input)) throw new Error("The schedule trigger must be an object");
|
|
11
12
|
const has = (key) => input[key] !== void 0;
|
|
12
|
-
if (type === "event") {
|
|
13
|
-
const event = previous;
|
|
14
|
-
const timezone = has("timezone") ? assertTimezone(input.timezone) : event?.timezone;
|
|
15
|
-
return { type, tokenVersion: event?.tokenVersion ?? 1, ...timezone ? { timezone } : {} };
|
|
16
|
-
}
|
|
17
|
-
const schedule = previous;
|
|
18
13
|
return {
|
|
19
|
-
|
|
20
|
-
recurrence: has("recurrence") || !
|
|
21
|
-
timezone: has("timezone") || !
|
|
14
|
+
enabled: readEnabled(input.enabled, existing?.enabled ?? true),
|
|
15
|
+
recurrence: has("recurrence") || !existing ? validateRecurrence(input.recurrence) : existing.recurrence,
|
|
16
|
+
timezone: has("timezone") || !existing ? assertTimezone(input.timezone) : existing.timezone,
|
|
17
|
+
...existing?.nextRunAt ? { nextRunAt: existing.nextRunAt } : {}
|
|
22
18
|
};
|
|
23
19
|
}
|
|
20
|
+
function readEvent(input, existing) {
|
|
21
|
+
if (!isRecord(input)) throw new Error("The event trigger must be an object");
|
|
22
|
+
return { enabled: readEnabled(input.enabled, existing?.enabled ?? true) };
|
|
23
|
+
}
|
|
24
|
+
function readTriggers(input, existing = {}) {
|
|
25
|
+
if (!isRecord(input)) throw new Error("The triggers are required");
|
|
26
|
+
if (Object.keys(input).some((key) => key !== "schedule" && key !== "event")) throw new Error("The triggers can only be schedule or event");
|
|
27
|
+
const triggers = { ...existing };
|
|
28
|
+
if (input.schedule === null) delete triggers.schedule;
|
|
29
|
+
else if (input.schedule !== void 0) triggers.schedule = readSchedule(input.schedule, existing.schedule);
|
|
30
|
+
if (input.event === null) delete triggers.event;
|
|
31
|
+
else if (input.event !== void 0) triggers.event = readEvent(input.event, existing.event);
|
|
32
|
+
if (!triggers.schedule && !triggers.event) throw new Error("The automation needs at least one trigger");
|
|
33
|
+
return triggers;
|
|
34
|
+
}
|
|
24
35
|
export {
|
|
25
|
-
|
|
36
|
+
readTriggers
|
|
26
37
|
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { MongoRepository, QueryOptions } from '../../../common/repositories/index.js';
|
|
1
|
+
import { MongoRepository, QueryOptions, Scope } from '../../../common/repositories/index.js';
|
|
2
2
|
import { AutomationRun, AutomationRunProps, AutomationRunStatus } from '../entities';
|
|
3
3
|
export declare class AutomationRunRepository {
|
|
4
4
|
readonly _: MongoRepository<AutomationRunProps>;
|
|
5
|
-
create(run: AutomationRun): Promise<AutomationRun>;
|
|
6
|
-
update(run: AutomationRun): Promise<AutomationRunProps | null>;
|
|
7
|
-
findById(id: string): Promise<AutomationRunProps | null>;
|
|
8
|
-
findByAutomation(automationId: string, options?: QueryOptions): Promise<AutomationRunProps[]>;
|
|
9
|
-
findByOwner(ownerId: string, options?: QueryOptions, status?: AutomationRunStatus): Promise<AutomationRunProps[]>;
|
|
10
|
-
findByStatus(status: AutomationRunStatus, limit: number): Promise<AutomationRunProps[]>;
|
|
11
|
-
findByIdempotencyKey(automationId: string, idempotencyKey: string): Promise<AutomationRunProps | null>;
|
|
12
|
-
countQueued(automationId: string): Promise<number>;
|
|
13
|
-
claimQueued(id: string, fields: Pick<AutomationRunProps, 'workerId' | 'startedAt' | 'instructions' | 'modelProvider' | 'modelName'
|
|
5
|
+
create(run: AutomationRun, scope: Scope): Promise<AutomationRun>;
|
|
6
|
+
update(run: AutomationRun, scope: Scope): Promise<AutomationRunProps | null>;
|
|
7
|
+
findById(id: string, scope: Scope): Promise<AutomationRunProps | null>;
|
|
8
|
+
findByAutomation(automationId: string, scope: Scope, options?: QueryOptions): Promise<AutomationRunProps[]>;
|
|
9
|
+
findByOwner(ownerId: string, scope: Scope, options?: QueryOptions, status?: AutomationRunStatus): Promise<AutomationRunProps[]>;
|
|
10
|
+
findByStatus(status: AutomationRunStatus, limit: number, scope: Scope): Promise<AutomationRunProps[]>;
|
|
11
|
+
findByIdempotencyKey(automationId: string, idempotencyKey: string, scope: Scope): Promise<AutomationRunProps | null>;
|
|
12
|
+
countQueued(automationId: string, scope: Scope): Promise<number>;
|
|
13
|
+
claimQueued(id: string, fields: Pick<AutomationRunProps, 'workerId' | 'startedAt' | 'instructions' | 'modelProvider' | 'modelName'>, scope: Scope): Promise<AutomationRunProps | null>;
|
|
14
14
|
}
|
|
@@ -36,39 +36,42 @@ var import_database_name = require("../../../common/utils/database-name.js");
|
|
|
36
36
|
let AutomationRunRepository = class {
|
|
37
37
|
_ = new import_repositories.MongoRepository({
|
|
38
38
|
database: (0, import_database_name.getDatabaseName)(),
|
|
39
|
-
collection: "automation_runs"
|
|
39
|
+
collection: "automation_runs",
|
|
40
|
+
scoped: true
|
|
40
41
|
});
|
|
41
|
-
async create(run) {
|
|
42
|
-
const
|
|
43
|
-
|
|
42
|
+
async create(run, scope) {
|
|
43
|
+
const { _id, ownerId, createdAt, createdBy } = await this._.createOne({ payload: run.toDocument(), scope });
|
|
44
|
+
Object.assign(run, { _id, ownerId, createdAt, createdBy });
|
|
44
45
|
return run;
|
|
45
46
|
}
|
|
46
|
-
async update(run) {
|
|
47
|
+
async update(run, scope) {
|
|
47
48
|
return await this._.updateOne({
|
|
49
|
+
scope,
|
|
48
50
|
where: { _id: run._id },
|
|
49
51
|
payload: run.toFlatDocument()
|
|
50
52
|
});
|
|
51
53
|
}
|
|
52
|
-
async findById(id) {
|
|
53
|
-
return await this._.findOne({ where: { _id: this._.parseId(id) } });
|
|
54
|
+
async findById(id, scope) {
|
|
55
|
+
return await this._.findOne({ scope, where: { _id: this._.parseId(id) } });
|
|
54
56
|
}
|
|
55
|
-
async findByAutomation(automationId, options) {
|
|
56
|
-
return await this._.findMany({ where: { automationId: new import_mongodb.ObjectId(automationId) }, options });
|
|
57
|
+
async findByAutomation(automationId, scope, options) {
|
|
58
|
+
return await this._.findMany({ scope, where: { automationId: new import_mongodb.ObjectId(automationId) }, options });
|
|
57
59
|
}
|
|
58
|
-
async findByOwner(ownerId, options, status) {
|
|
59
|
-
return await this._.findMany({ where: { ownerId: new import_mongodb.ObjectId(ownerId), ...status ? { status } : {} }, options });
|
|
60
|
+
async findByOwner(ownerId, scope, options, status) {
|
|
61
|
+
return await this._.findMany({ scope, where: { ownerId: new import_mongodb.ObjectId(ownerId), ...status ? { status } : {} }, options });
|
|
60
62
|
}
|
|
61
|
-
async findByStatus(status, limit) {
|
|
62
|
-
return await this._.findMany({ where: { status }, options: { page: 1, limit, sortBy: { createdAt: 1 } } });
|
|
63
|
+
async findByStatus(status, limit, scope) {
|
|
64
|
+
return await this._.findMany({ scope, where: { status }, options: { page: 1, limit, sortBy: { createdAt: 1 } } });
|
|
63
65
|
}
|
|
64
|
-
async findByIdempotencyKey(automationId, idempotencyKey) {
|
|
65
|
-
return await this._.findOne({ where: { automationId: new import_mongodb.ObjectId(automationId), idempotencyKey } });
|
|
66
|
+
async findByIdempotencyKey(automationId, idempotencyKey, scope) {
|
|
67
|
+
return await this._.findOne({ scope, where: { automationId: new import_mongodb.ObjectId(automationId), idempotencyKey } });
|
|
66
68
|
}
|
|
67
|
-
async countQueued(automationId) {
|
|
68
|
-
return await this._.count({ where: { automationId: new import_mongodb.ObjectId(automationId), status: "queued" } });
|
|
69
|
+
async countQueued(automationId, scope) {
|
|
70
|
+
return await this._.count({ scope, where: { automationId: new import_mongodb.ObjectId(automationId), status: "queued" } });
|
|
69
71
|
}
|
|
70
|
-
async claimQueued(id, fields) {
|
|
72
|
+
async claimQueued(id, fields, scope) {
|
|
71
73
|
return await this._.updateOne({
|
|
74
|
+
scope,
|
|
72
75
|
where: { _id: this._.parseId(id), status: "queued" },
|
|
73
76
|
payload: { ...fields, status: "running" }
|
|
74
77
|
});
|