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
|
@@ -9,6 +9,7 @@ import { AutomationRepository, AutomationRunRepository } from "../repositories";
|
|
|
9
9
|
import { findPausedRun } from "../utils/previous-run";
|
|
10
10
|
import { leaseMs as defaultLeaseMs } from "../utils/settings";
|
|
11
11
|
import { SyncAutomationRunUseCase } from "./sync-automation-run.use-case";
|
|
12
|
+
import { runnerScope } from "../utils/runner-scope";
|
|
12
13
|
const SCAN_LIMIT = 200;
|
|
13
14
|
let ClaimQueuedAutomationRunsUseCase = class extends BaseUseCase {
|
|
14
15
|
constructor(automationRepository, automationRunRepository, syncRun) {
|
|
@@ -26,7 +27,7 @@ let ClaimQueuedAutomationRunsUseCase = class extends BaseUseCase {
|
|
|
26
27
|
const now = params.now ?? /* @__PURE__ */ new Date();
|
|
27
28
|
const leaseMs = params.leaseMs ?? defaultLeaseMs();
|
|
28
29
|
const limit = params.limit ?? SCAN_LIMIT;
|
|
29
|
-
const queued = await this.automationRunRepository.findByStatus("queued", SCAN_LIMIT);
|
|
30
|
+
const queued = await this.automationRunRepository.findByStatus("queued", SCAN_LIMIT, runnerScope);
|
|
30
31
|
const claimed = [];
|
|
31
32
|
const skipped = [];
|
|
32
33
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -35,18 +36,18 @@ let ClaimQueuedAutomationRunsUseCase = class extends BaseUseCase {
|
|
|
35
36
|
const automationId = String(run.automationId);
|
|
36
37
|
if (seen.has(automationId)) continue;
|
|
37
38
|
seen.add(automationId);
|
|
38
|
-
const existing = await this.automationRepository.findById(automationId);
|
|
39
|
-
const reason = !existing ? "The automation no longer exists" : !existing.enabled ? "The automation is turned off" : void 0;
|
|
39
|
+
const existing = await this.automationRepository.findById(automationId, runnerScope);
|
|
40
|
+
const reason = !existing ? "The automation no longer exists" : !existing.triggers?.event?.enabled ? "The event trigger of the automation is turned off" : void 0;
|
|
40
41
|
if (reason) {
|
|
41
|
-
const settled = await this.automationRunRepository.update(AutomationRun.fromJSON({ ...run, status: "skipped", finishedAt: now, skipReason: reason }));
|
|
42
|
+
const settled = await this.automationRunRepository.update(AutomationRun.fromJSON({ ...run, status: "skipped", finishedAt: now, skipReason: reason }), runnerScope);
|
|
42
43
|
if (existing && settled) skipped.push({ automation: existing, run: settled });
|
|
43
44
|
continue;
|
|
44
45
|
}
|
|
45
|
-
const automation = await this.automationRepository.claimManual({ id: automationId, workerId, now, leaseMs });
|
|
46
|
+
const automation = await this.automationRepository.claimManual({ id: automationId, workerId, now, leaseMs }, runnerScope);
|
|
46
47
|
if (!automation) continue;
|
|
47
48
|
const paused = await findPausedRun(this.automationRunRepository, this.syncRun, automation, now);
|
|
48
49
|
if (paused) {
|
|
49
|
-
await this.automationRepository.release(automationId, workerId, { activeRunId: paused._id });
|
|
50
|
+
await this.automationRepository.release(automationId, workerId, { activeRunId: paused._id }, runnerScope);
|
|
50
51
|
continue;
|
|
51
52
|
}
|
|
52
53
|
const started = await this.automationRunRepository.claimQueued(String(run._id), {
|
|
@@ -55,12 +56,12 @@ let ClaimQueuedAutomationRunsUseCase = class extends BaseUseCase {
|
|
|
55
56
|
instructions: automation.instructions,
|
|
56
57
|
modelProvider: automation.modelProvider,
|
|
57
58
|
modelName: automation.modelName
|
|
58
|
-
});
|
|
59
|
+
}, runnerScope);
|
|
59
60
|
if (!started) {
|
|
60
|
-
await this.automationRepository.release(automationId, workerId, {});
|
|
61
|
+
await this.automationRepository.release(automationId, workerId, {}, runnerScope);
|
|
61
62
|
continue;
|
|
62
63
|
}
|
|
63
|
-
await this.automationRepository.setActiveRun(automationId, workerId, String(started._id));
|
|
64
|
+
await this.automationRepository.setActiveRun(automationId, workerId, String(started._id), runnerScope);
|
|
64
65
|
claimed.push({ automation, run: started });
|
|
65
66
|
}
|
|
66
67
|
return { data: { claimed, skipped } };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BaseUseCase, BaseUseCaseParams, BaseUseCaseOutput } from '../../../common/base/base.use-case.js';
|
|
2
|
-
import { AutomationProps } from '../entities';
|
|
2
|
+
import { AutomationPayload, AutomationProps } from '../entities';
|
|
3
3
|
import { AutomationRepository } from '../repositories';
|
|
4
4
|
export interface Params extends BaseUseCaseParams {
|
|
5
|
-
payload?:
|
|
5
|
+
payload?: AutomationPayload;
|
|
6
6
|
}
|
|
7
7
|
export interface Output extends BaseUseCaseOutput {
|
|
8
8
|
data: AutomationProps;
|
|
@@ -32,8 +32,9 @@ __export(create_automation_use_case_exports, {
|
|
|
32
32
|
module.exports = __toCommonJS(create_automation_use_case_exports);
|
|
33
33
|
var import_tsyringe = require("tsyringe");
|
|
34
34
|
var import_base = require("../../../common/base/base.use-case.js");
|
|
35
|
+
var import_repositories = require("../../../common/repositories/index.js");
|
|
35
36
|
var import_entities = require("../entities");
|
|
36
|
-
var
|
|
37
|
+
var import_repositories2 = require("../repositories");
|
|
37
38
|
var import_automation_fields = require("../utils/automation-fields");
|
|
38
39
|
let CreateAutomationUseCase = class extends import_base.BaseUseCase {
|
|
39
40
|
constructor(automationRepository) {
|
|
@@ -49,22 +50,21 @@ let CreateAutomationUseCase = class extends import_base.BaseUseCase {
|
|
|
49
50
|
const automation = import_entities.Automation.fromJSON({
|
|
50
51
|
name: fields.name,
|
|
51
52
|
instructions: fields.instructions,
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
triggers: fields.triggers,
|
|
54
|
+
eventTokenVersion: 1,
|
|
54
55
|
modelProvider: fields.modelProvider ?? void 0,
|
|
55
56
|
modelName: fields.modelName ?? void 0
|
|
56
57
|
});
|
|
57
|
-
automation.setCreatedBy(currentUser);
|
|
58
|
-
automation.setOwner(currentUser);
|
|
59
58
|
automation.scheduleNextRun();
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
const schedule = automation.triggers?.schedule;
|
|
60
|
+
if (schedule?.enabled && !schedule.nextRunAt) throw new Error("The date of the recurrence has already passed");
|
|
61
|
+
await this.automationRepository?.create(automation, params.scope ?? import_repositories.Scope.canEdit(currentUser));
|
|
62
62
|
return { data: automation.toJSON() };
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
CreateAutomationUseCase = __decorateClass([
|
|
66
66
|
(0, import_tsyringe.autoInjectable)(),
|
|
67
|
-
__decorateParam(0, (0, import_tsyringe.inject)(
|
|
67
|
+
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories2.AutomationRepository))
|
|
68
68
|
], CreateAutomationUseCase);
|
|
69
69
|
// Annotate the CommonJS export names for ESM import in node:
|
|
70
70
|
0 && (module.exports = {
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
} from "../../../chunk-CF3WOMB3.mjs";
|
|
5
5
|
import { autoInjectable, inject } from "tsyringe";
|
|
6
6
|
import { BaseUseCase } from "../../../common/base/base.use-case.js";
|
|
7
|
+
import { Scope } from "../../../common/repositories/index.js";
|
|
7
8
|
import { Automation } from "../entities";
|
|
8
9
|
import { AutomationRepository } from "../repositories";
|
|
9
10
|
import { readAutomationFields, assertModel } from "../utils/automation-fields";
|
|
@@ -21,16 +22,15 @@ let CreateAutomationUseCase = class extends BaseUseCase {
|
|
|
21
22
|
const automation = Automation.fromJSON({
|
|
22
23
|
name: fields.name,
|
|
23
24
|
instructions: fields.instructions,
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
triggers: fields.triggers,
|
|
26
|
+
eventTokenVersion: 1,
|
|
26
27
|
modelProvider: fields.modelProvider ?? void 0,
|
|
27
28
|
modelName: fields.modelName ?? void 0
|
|
28
29
|
});
|
|
29
|
-
automation.setCreatedBy(currentUser);
|
|
30
|
-
automation.setOwner(currentUser);
|
|
31
30
|
automation.scheduleNextRun();
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
const schedule = automation.triggers?.schedule;
|
|
32
|
+
if (schedule?.enabled && !schedule.nextRunAt) throw new Error("The date of the recurrence has already passed");
|
|
33
|
+
await this.automationRepository?.create(automation, params.scope ?? Scope.canEdit(currentUser));
|
|
34
34
|
return { data: automation.toJSON() };
|
|
35
35
|
}
|
|
36
36
|
};
|
|
@@ -32,8 +32,8 @@ __export(delete_automation_use_case_exports, {
|
|
|
32
32
|
module.exports = __toCommonJS(delete_automation_use_case_exports);
|
|
33
33
|
var import_tsyringe = require("tsyringe");
|
|
34
34
|
var import_base = require("../../../common/base/base.use-case.js");
|
|
35
|
-
var
|
|
36
|
-
var
|
|
35
|
+
var import_repositories = require("../../../common/repositories/index.js");
|
|
36
|
+
var import_repositories2 = require("../repositories");
|
|
37
37
|
let DeleteAutomationUseCase = class extends import_base.BaseUseCase {
|
|
38
38
|
constructor(automationRepository) {
|
|
39
39
|
super();
|
|
@@ -44,20 +44,17 @@ let DeleteAutomationUseCase = class extends import_base.BaseUseCase {
|
|
|
44
44
|
const { id, hardDelete, currentUser } = params;
|
|
45
45
|
if (!id) throw new Error("Missing id");
|
|
46
46
|
if (hardDelete) {
|
|
47
|
-
|
|
48
|
-
const result2 = await this.automationRepository?.deleteById(id);
|
|
47
|
+
const result2 = await this.automationRepository?.deleteById(id, params.scope ?? import_repositories.Scope.asAdmin(currentUser));
|
|
49
48
|
return { data: { deletedCount: result2 } };
|
|
50
49
|
}
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
automation.unset(["nextRunAt"]);
|
|
54
|
-
const result = await this.automationRepository?.update(automation);
|
|
50
|
+
const result = await this.automationRepository?.softDeleteById(id, params.scope ?? import_repositories.Scope.canManage(currentUser));
|
|
51
|
+
if (!result) return this.throwHttpError({ statusCode: 404, errorMessage: "{{resource_not_found}}" });
|
|
55
52
|
return { data: result };
|
|
56
53
|
}
|
|
57
54
|
};
|
|
58
55
|
DeleteAutomationUseCase = __decorateClass([
|
|
59
56
|
(0, import_tsyringe.autoInjectable)(),
|
|
60
|
-
__decorateParam(0, (0, import_tsyringe.inject)(
|
|
57
|
+
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories2.AutomationRepository))
|
|
61
58
|
], DeleteAutomationUseCase);
|
|
62
59
|
// Annotate the CommonJS export names for ESM import in node:
|
|
63
60
|
0 && (module.exports = {
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "../../../chunk-CF3WOMB3.mjs";
|
|
5
5
|
import { autoInjectable, inject } from "tsyringe";
|
|
6
6
|
import { BaseUseCase } from "../../../common/base/base.use-case.js";
|
|
7
|
-
import {
|
|
7
|
+
import { Scope } from "../../../common/repositories/index.js";
|
|
8
8
|
import { AutomationRepository } from "../repositories";
|
|
9
9
|
let DeleteAutomationUseCase = class extends BaseUseCase {
|
|
10
10
|
constructor(automationRepository) {
|
|
@@ -16,14 +16,11 @@ let DeleteAutomationUseCase = class extends BaseUseCase {
|
|
|
16
16
|
const { id, hardDelete, currentUser } = params;
|
|
17
17
|
if (!id) throw new Error("Missing id");
|
|
18
18
|
if (hardDelete) {
|
|
19
|
-
|
|
20
|
-
const result2 = await this.automationRepository?.deleteById(id);
|
|
19
|
+
const result2 = await this.automationRepository?.deleteById(id, params.scope ?? Scope.asAdmin(currentUser));
|
|
21
20
|
return { data: { deletedCount: result2 } };
|
|
22
21
|
}
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
automation.unset(["nextRunAt"]);
|
|
26
|
-
const result = await this.automationRepository?.update(automation);
|
|
22
|
+
const result = await this.automationRepository?.softDeleteById(id, params.scope ?? Scope.canManage(currentUser));
|
|
23
|
+
if (!result) return this.throwHttpError({ statusCode: 404, errorMessage: "{{resource_not_found}}" });
|
|
27
24
|
return { data: result };
|
|
28
25
|
}
|
|
29
26
|
};
|
|
@@ -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_runner_scope = require("../utils/runner-scope");
|
|
37
38
|
let FinishAutomationRunUseCase = class extends import_base.BaseUseCase {
|
|
38
39
|
constructor(automationRepository, automationRunRepository) {
|
|
39
40
|
super();
|
|
@@ -45,7 +46,7 @@ let FinishAutomationRunUseCase = class extends import_base.BaseUseCase {
|
|
|
45
46
|
async execute(params) {
|
|
46
47
|
const { runId, workerId, status, error } = params;
|
|
47
48
|
const now = params.now ?? /* @__PURE__ */ new Date();
|
|
48
|
-
const run = await this.automationRunRepository.findById(runId);
|
|
49
|
+
const run = await this.automationRunRepository.findById(runId, import_runner_scope.runnerScope);
|
|
49
50
|
if (!run) return { data: null };
|
|
50
51
|
const finished = import_entities.AutomationRun.fromJSON({
|
|
51
52
|
...run,
|
|
@@ -53,13 +54,13 @@ let FinishAutomationRunUseCase = class extends import_base.BaseUseCase {
|
|
|
53
54
|
...status === "paused" ? {} : { finishedAt: now },
|
|
54
55
|
...error ? { error } : {}
|
|
55
56
|
});
|
|
56
|
-
const saved = await this.automationRunRepository.update(finished);
|
|
57
|
+
const saved = await this.automationRunRepository.update(finished, import_runner_scope.runnerScope);
|
|
57
58
|
if (run.automationId) {
|
|
58
59
|
await this.automationRepository.release(String(run.automationId), workerId, {
|
|
59
60
|
lastRunAt: now,
|
|
60
61
|
lastRunStatus: status,
|
|
61
62
|
...status === "paused" ? { activeRunId: run._id } : {}
|
|
62
|
-
});
|
|
63
|
+
}, import_runner_scope.runnerScope);
|
|
63
64
|
}
|
|
64
65
|
return { data: saved ?? finished.toJSON() };
|
|
65
66
|
}
|
|
@@ -6,6 +6,7 @@ import { autoInjectable, inject } from "tsyringe";
|
|
|
6
6
|
import { BaseUseCase } from "../../../common/base/base.use-case.js";
|
|
7
7
|
import { AutomationRun } from "../entities";
|
|
8
8
|
import { AutomationRepository, AutomationRunRepository } from "../repositories";
|
|
9
|
+
import { runnerScope } from "../utils/runner-scope";
|
|
9
10
|
let FinishAutomationRunUseCase = class extends BaseUseCase {
|
|
10
11
|
constructor(automationRepository, automationRunRepository) {
|
|
11
12
|
super();
|
|
@@ -17,7 +18,7 @@ let FinishAutomationRunUseCase = class extends BaseUseCase {
|
|
|
17
18
|
async execute(params) {
|
|
18
19
|
const { runId, workerId, status, error } = params;
|
|
19
20
|
const now = params.now ?? /* @__PURE__ */ new Date();
|
|
20
|
-
const run = await this.automationRunRepository.findById(runId);
|
|
21
|
+
const run = await this.automationRunRepository.findById(runId, runnerScope);
|
|
21
22
|
if (!run) return { data: null };
|
|
22
23
|
const finished = AutomationRun.fromJSON({
|
|
23
24
|
...run,
|
|
@@ -25,13 +26,13 @@ let FinishAutomationRunUseCase = class extends BaseUseCase {
|
|
|
25
26
|
...status === "paused" ? {} : { finishedAt: now },
|
|
26
27
|
...error ? { error } : {}
|
|
27
28
|
});
|
|
28
|
-
const saved = await this.automationRunRepository.update(finished);
|
|
29
|
+
const saved = await this.automationRunRepository.update(finished, runnerScope);
|
|
29
30
|
if (run.automationId) {
|
|
30
31
|
await this.automationRepository.release(String(run.automationId), workerId, {
|
|
31
32
|
lastRunAt: now,
|
|
32
33
|
lastRunStatus: status,
|
|
33
34
|
...status === "paused" ? { activeRunId: run._id } : {}
|
|
34
|
-
});
|
|
35
|
+
}, runnerScope);
|
|
35
36
|
}
|
|
36
37
|
return { data: saved ?? finished.toJSON() };
|
|
37
38
|
}
|
|
@@ -32,7 +32,8 @@ __export(get_automation_by_id_use_case_exports, {
|
|
|
32
32
|
module.exports = __toCommonJS(get_automation_by_id_use_case_exports);
|
|
33
33
|
var import_tsyringe = require("tsyringe");
|
|
34
34
|
var import_base = require("../../../common/base/base.use-case.js");
|
|
35
|
-
var import_repositories = require("
|
|
35
|
+
var import_repositories = require("../../../common/repositories/index.js");
|
|
36
|
+
var import_repositories2 = require("../repositories");
|
|
36
37
|
let GetAutomationByIdUseCase = class extends import_base.BaseUseCase {
|
|
37
38
|
constructor(automationRepository) {
|
|
38
39
|
super();
|
|
@@ -40,14 +41,14 @@ let GetAutomationByIdUseCase = class extends import_base.BaseUseCase {
|
|
|
40
41
|
}
|
|
41
42
|
automationRepository;
|
|
42
43
|
async execute(params) {
|
|
43
|
-
const { id } = params;
|
|
44
|
-
const result = await this.automationRepository?.findById(id);
|
|
44
|
+
const { id, currentUser } = params;
|
|
45
|
+
const result = await this.automationRepository?.findById(id, params.scope ?? import_repositories.Scope.canView(currentUser));
|
|
45
46
|
return { data: result ?? null };
|
|
46
47
|
}
|
|
47
48
|
};
|
|
48
49
|
GetAutomationByIdUseCase = __decorateClass([
|
|
49
50
|
(0, import_tsyringe.autoInjectable)(),
|
|
50
|
-
__decorateParam(0, (0, import_tsyringe.inject)(
|
|
51
|
+
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories2.AutomationRepository))
|
|
51
52
|
], GetAutomationByIdUseCase);
|
|
52
53
|
// Annotate the CommonJS export names for ESM import in node:
|
|
53
54
|
0 && (module.exports = {
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
} from "../../../chunk-CF3WOMB3.mjs";
|
|
5
5
|
import { autoInjectable, inject } from "tsyringe";
|
|
6
6
|
import { BaseUseCase } from "../../../common/base/base.use-case.js";
|
|
7
|
+
import { Scope } from "../../../common/repositories/index.js";
|
|
7
8
|
import { AutomationRepository } from "../repositories";
|
|
8
9
|
let GetAutomationByIdUseCase = class extends BaseUseCase {
|
|
9
10
|
constructor(automationRepository) {
|
|
@@ -12,8 +13,8 @@ let GetAutomationByIdUseCase = class extends BaseUseCase {
|
|
|
12
13
|
}
|
|
13
14
|
automationRepository;
|
|
14
15
|
async execute(params) {
|
|
15
|
-
const { id } = params;
|
|
16
|
-
const result = await this.automationRepository?.findById(id);
|
|
16
|
+
const { id, currentUser } = params;
|
|
17
|
+
const result = await this.automationRepository?.findById(id, params.scope ?? Scope.canView(currentUser));
|
|
17
18
|
return { data: result ?? null };
|
|
18
19
|
}
|
|
19
20
|
};
|
|
@@ -32,7 +32,8 @@ __export(issue_automation_event_token_use_case_exports, {
|
|
|
32
32
|
module.exports = __toCommonJS(issue_automation_event_token_use_case_exports);
|
|
33
33
|
var import_tsyringe = require("tsyringe");
|
|
34
34
|
var import_base = require("../../../common/base/base.use-case.js");
|
|
35
|
-
var import_repositories = require("
|
|
35
|
+
var import_repositories = require("../../../common/repositories/index.js");
|
|
36
|
+
var import_repositories2 = require("../repositories");
|
|
36
37
|
var import_event_token = require("../utils/event-token");
|
|
37
38
|
let IssueAutomationEventTokenUseCase = class extends import_base.BaseUseCase {
|
|
38
39
|
constructor(automationRepository) {
|
|
@@ -42,16 +43,15 @@ let IssueAutomationEventTokenUseCase = class extends import_base.BaseUseCase {
|
|
|
42
43
|
automationRepository;
|
|
43
44
|
async execute(params) {
|
|
44
45
|
const { id, expiresIn, currentUser } = params;
|
|
45
|
-
const automation = await this.automationRepository?.findById(id);
|
|
46
|
-
if (!automation)
|
|
47
|
-
if (!
|
|
48
|
-
|
|
49
|
-
return { data: (0, import_event_token.signEventToken)({ automationId: id, tokenVersion: automation.trigger.tokenVersion, expiresIn }) };
|
|
46
|
+
const automation = await this.automationRepository?.findById(id, params.scope ?? import_repositories.Scope.canManage(currentUser));
|
|
47
|
+
if (!automation) return this.throwHttpError({ statusCode: 404, errorMessage: "{{resource_not_found}}" });
|
|
48
|
+
if (!automation.triggers?.event) throw new Error("Only an automation with an event trigger has a token");
|
|
49
|
+
return { data: (0, import_event_token.signEventToken)({ automationId: id, tokenVersion: automation.eventTokenVersion, expiresIn }) };
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
52
|
IssueAutomationEventTokenUseCase = __decorateClass([
|
|
53
53
|
(0, import_tsyringe.autoInjectable)(),
|
|
54
|
-
__decorateParam(0, (0, import_tsyringe.inject)(
|
|
54
|
+
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories2.AutomationRepository))
|
|
55
55
|
], IssueAutomationEventTokenUseCase);
|
|
56
56
|
// Annotate the CommonJS export names for ESM import in node:
|
|
57
57
|
0 && (module.exports = {
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
} from "../../../chunk-CF3WOMB3.mjs";
|
|
5
5
|
import { autoInjectable, inject } from "tsyringe";
|
|
6
6
|
import { BaseUseCase } from "../../../common/base/base.use-case.js";
|
|
7
|
+
import { Scope } from "../../../common/repositories/index.js";
|
|
7
8
|
import { AutomationRepository } from "../repositories";
|
|
8
9
|
import { signEventToken } from "../utils/event-token";
|
|
9
10
|
let IssueAutomationEventTokenUseCase = class extends BaseUseCase {
|
|
@@ -14,11 +15,10 @@ let IssueAutomationEventTokenUseCase = class extends BaseUseCase {
|
|
|
14
15
|
automationRepository;
|
|
15
16
|
async execute(params) {
|
|
16
17
|
const { id, expiresIn, currentUser } = params;
|
|
17
|
-
const automation = await this.automationRepository?.findById(id);
|
|
18
|
-
if (!automation)
|
|
19
|
-
if (!
|
|
20
|
-
|
|
21
|
-
return { data: signEventToken({ automationId: id, tokenVersion: automation.trigger.tokenVersion, expiresIn }) };
|
|
18
|
+
const automation = await this.automationRepository?.findById(id, params.scope ?? Scope.canManage(currentUser));
|
|
19
|
+
if (!automation) return this.throwHttpError({ statusCode: 404, errorMessage: "{{resource_not_found}}" });
|
|
20
|
+
if (!automation.triggers?.event) throw new Error("Only an automation with an event trigger has a token");
|
|
21
|
+
return { data: signEventToken({ automationId: id, tokenVersion: automation.eventTokenVersion, expiresIn }) };
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
IssueAutomationEventTokenUseCase = __decorateClass([
|
|
@@ -32,6 +32,7 @@ __export(list_automation_runs_by_automation_use_case_exports, {
|
|
|
32
32
|
module.exports = __toCommonJS(list_automation_runs_by_automation_use_case_exports);
|
|
33
33
|
var import_tsyringe = require("tsyringe");
|
|
34
34
|
var import_mongodb = require("mongodb");
|
|
35
|
+
var import_repositories = require("../../../common/repositories/index.js");
|
|
35
36
|
var import_base = require("../../../common/base/base.use-case.js");
|
|
36
37
|
var import_repositories2 = require("../repositories");
|
|
37
38
|
let ListAutomationRunsByAutomationUseCase = class extends import_base.BaseUseCase {
|
|
@@ -41,10 +42,11 @@ let ListAutomationRunsByAutomationUseCase = class extends import_base.BaseUseCas
|
|
|
41
42
|
}
|
|
42
43
|
automationRunRepository;
|
|
43
44
|
async execute(params) {
|
|
44
|
-
const { automationId, options } = params;
|
|
45
|
+
const { automationId, options, currentUser } = params;
|
|
45
46
|
if (!automationId) throw new Error("Missing automationId");
|
|
46
47
|
const { page = 1, limit = 10, sortBy = { createdAt: -1 } } = options || {};
|
|
47
48
|
const result = await this.automationRunRepository?._.findManyPaginated({
|
|
49
|
+
scope: params.scope ?? import_repositories.Scope.canView(currentUser),
|
|
48
50
|
where: { automationId: new import_mongodb.ObjectId(automationId) },
|
|
49
51
|
options: { page, limit, sortBy }
|
|
50
52
|
});
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
} from "../../../chunk-CF3WOMB3.mjs";
|
|
5
5
|
import { autoInjectable, inject } from "tsyringe";
|
|
6
6
|
import { ObjectId } from "mongodb";
|
|
7
|
+
import { Scope } from "../../../common/repositories/index.js";
|
|
7
8
|
import { BaseUseCase } from "../../../common/base/base.use-case.js";
|
|
8
9
|
import { AutomationRunRepository } from "../repositories";
|
|
9
10
|
let ListAutomationRunsByAutomationUseCase = class extends BaseUseCase {
|
|
@@ -13,10 +14,11 @@ let ListAutomationRunsByAutomationUseCase = class extends BaseUseCase {
|
|
|
13
14
|
}
|
|
14
15
|
automationRunRepository;
|
|
15
16
|
async execute(params) {
|
|
16
|
-
const { automationId, options } = params;
|
|
17
|
+
const { automationId, options, currentUser } = params;
|
|
17
18
|
if (!automationId) throw new Error("Missing automationId");
|
|
18
19
|
const { page = 1, limit = 10, sortBy = { createdAt: -1 } } = options || {};
|
|
19
20
|
const result = await this.automationRunRepository?._.findManyPaginated({
|
|
21
|
+
scope: params.scope ?? Scope.canView(currentUser),
|
|
20
22
|
where: { automationId: new ObjectId(automationId) },
|
|
21
23
|
options: { page, limit, sortBy }
|
|
22
24
|
});
|
|
@@ -32,6 +32,7 @@ __export(list_automation_runs_by_user_use_case_exports, {
|
|
|
32
32
|
module.exports = __toCommonJS(list_automation_runs_by_user_use_case_exports);
|
|
33
33
|
var import_tsyringe = require("tsyringe");
|
|
34
34
|
var import_mongodb = require("mongodb");
|
|
35
|
+
var import_repositories = require("../../../common/repositories/index.js");
|
|
35
36
|
var import_base = require("../../../common/base/base.use-case.js");
|
|
36
37
|
var import_repositories2 = require("../repositories");
|
|
37
38
|
let ListAutomationRunsByUserUseCase = class extends import_base.BaseUseCase {
|
|
@@ -45,6 +46,7 @@ let ListAutomationRunsByUserUseCase = class extends import_base.BaseUseCase {
|
|
|
45
46
|
if (!currentUser?.userId) throw new Error("CurrentUser is required to list the runs of the automations");
|
|
46
47
|
const { page = 1, limit = 10, sortBy = { createdAt: -1 } } = options || {};
|
|
47
48
|
const result = await this.automationRunRepository?._.findManyPaginated({
|
|
49
|
+
scope: params.scope ?? import_repositories.Scope.canView(currentUser),
|
|
48
50
|
where: { ownerId: new import_mongodb.ObjectId(currentUser.userId), ...status ? { status } : {} },
|
|
49
51
|
options: { page, limit, sortBy }
|
|
50
52
|
});
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
} from "../../../chunk-CF3WOMB3.mjs";
|
|
5
5
|
import { autoInjectable, inject } from "tsyringe";
|
|
6
6
|
import { ObjectId } from "mongodb";
|
|
7
|
+
import { Scope } from "../../../common/repositories/index.js";
|
|
7
8
|
import { BaseUseCase } from "../../../common/base/base.use-case.js";
|
|
8
9
|
import { AutomationRunRepository } from "../repositories";
|
|
9
10
|
let ListAutomationRunsByUserUseCase = class extends BaseUseCase {
|
|
@@ -17,6 +18,7 @@ let ListAutomationRunsByUserUseCase = class extends BaseUseCase {
|
|
|
17
18
|
if (!currentUser?.userId) throw new Error("CurrentUser is required to list the runs of the automations");
|
|
18
19
|
const { page = 1, limit = 10, sortBy = { createdAt: -1 } } = options || {};
|
|
19
20
|
const result = await this.automationRunRepository?._.findManyPaginated({
|
|
21
|
+
scope: params.scope ?? Scope.canView(currentUser),
|
|
20
22
|
where: { ownerId: new ObjectId(currentUser.userId), ...status ? { status } : {} },
|
|
21
23
|
options: { page, limit, sortBy }
|
|
22
24
|
});
|
|
@@ -32,6 +32,7 @@ __export(list_automations_by_user_use_case_exports, {
|
|
|
32
32
|
module.exports = __toCommonJS(list_automations_by_user_use_case_exports);
|
|
33
33
|
var import_tsyringe = require("tsyringe");
|
|
34
34
|
var import_mongodb = require("mongodb");
|
|
35
|
+
var import_repositories = require("../../../common/repositories/index.js");
|
|
35
36
|
var import_base = require("../../../common/base/base.use-case.js");
|
|
36
37
|
var import_repositories2 = require("../repositories");
|
|
37
38
|
let ListAutomationsByUserUseCase = class extends import_base.BaseUseCase {
|
|
@@ -45,6 +46,7 @@ let ListAutomationsByUserUseCase = class extends import_base.BaseUseCase {
|
|
|
45
46
|
if (!currentUser?.userId) throw new Error("CurrentUser is required to list the automations");
|
|
46
47
|
const { page = 1, limit = 10, sortBy = { createdAt: -1 } } = options || {};
|
|
47
48
|
const result = await this.automationRepository?._.findManyPaginated({
|
|
49
|
+
scope: params.scope ?? import_repositories.Scope.canView(currentUser),
|
|
48
50
|
where: { ownerId: new import_mongodb.ObjectId(currentUser.userId) },
|
|
49
51
|
options: { page, limit, sortBy }
|
|
50
52
|
});
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
} from "../../../chunk-CF3WOMB3.mjs";
|
|
5
5
|
import { autoInjectable, inject } from "tsyringe";
|
|
6
6
|
import { ObjectId } from "mongodb";
|
|
7
|
+
import { Scope } from "../../../common/repositories/index.js";
|
|
7
8
|
import { BaseUseCase } from "../../../common/base/base.use-case.js";
|
|
8
9
|
import { AutomationRepository } from "../repositories";
|
|
9
10
|
let ListAutomationsByUserUseCase = class extends BaseUseCase {
|
|
@@ -17,6 +18,7 @@ let ListAutomationsByUserUseCase = class extends BaseUseCase {
|
|
|
17
18
|
if (!currentUser?.userId) throw new Error("CurrentUser is required to list the automations");
|
|
18
19
|
const { page = 1, limit = 10, sortBy = { createdAt: -1 } } = options || {};
|
|
19
20
|
const result = await this.automationRepository?._.findManyPaginated({
|
|
21
|
+
scope: params.scope ?? Scope.canView(currentUser),
|
|
20
22
|
where: { ownerId: new ObjectId(currentUser.userId) },
|
|
21
23
|
options: { page, limit, sortBy }
|
|
22
24
|
});
|
|
@@ -38,6 +38,7 @@ var import_automation_event_error = require("../utils/automation-event-error");
|
|
|
38
38
|
var import_event_token = require("../utils/event-token");
|
|
39
39
|
var import_open_run = require("../utils/open-run");
|
|
40
40
|
var import_settings = require("../utils/settings");
|
|
41
|
+
var import_runner_scope = require("../utils/runner-scope");
|
|
41
42
|
const MAX_PAYLOAD_CHARS = 5e4;
|
|
42
43
|
const MAX_KEY_CHARS = 200;
|
|
43
44
|
const serialize = (payload) => {
|
|
@@ -57,10 +58,11 @@ let ReceiveAutomationEventUseCase = class extends import_base.BaseUseCase {
|
|
|
57
58
|
const now = params.now ?? /* @__PURE__ */ new Date();
|
|
58
59
|
const claims = (0, import_event_token.readEventToken)(token);
|
|
59
60
|
if (claims.sub !== automationId) throw new import_automation_event_error.AutomationEventError("invalid");
|
|
60
|
-
const automation = await this.automationRepository.findById(automationId);
|
|
61
|
+
const automation = await this.automationRepository.findById(automationId, import_runner_scope.eventScope);
|
|
61
62
|
if (!automation) throw new import_automation_event_error.AutomationEventError("not_found");
|
|
62
|
-
|
|
63
|
-
if (!automation.
|
|
63
|
+
const event = automation.triggers?.event;
|
|
64
|
+
if (!event || automation.eventTokenVersion !== claims.v) throw new import_automation_event_error.AutomationEventError("invalid");
|
|
65
|
+
if (!event.enabled) throw new import_automation_event_error.AutomationEventError("disabled");
|
|
64
66
|
const { data: { revoked } } = await (0, import_authentication.isTokenRevoked)({ jti: claims.jti });
|
|
65
67
|
if (revoked) throw new import_automation_event_error.AutomationEventError("revoked");
|
|
66
68
|
const payload = serialize(params.payload);
|
|
@@ -68,19 +70,19 @@ let ReceiveAutomationEventUseCase = class extends import_base.BaseUseCase {
|
|
|
68
70
|
const idempotencyKey = params.idempotencyKey?.trim() || void 0;
|
|
69
71
|
if (idempotencyKey && idempotencyKey.length > MAX_KEY_CHARS) throw new Error(`The idempotency key cannot be longer than ${MAX_KEY_CHARS} characters`);
|
|
70
72
|
if (idempotencyKey) {
|
|
71
|
-
const duplicate = await this.automationRunRepository.findByIdempotencyKey(automationId, idempotencyKey);
|
|
73
|
+
const duplicate = await this.automationRunRepository.findByIdempotencyKey(automationId, idempotencyKey, import_runner_scope.eventScope);
|
|
72
74
|
if (duplicate) return { data: { status: "duplicate", run: duplicate } };
|
|
73
75
|
}
|
|
74
|
-
if (await this.automationRunRepository.countQueued(automationId) >= (0, import_settings.maxQueuedRuns)()) {
|
|
75
|
-
const skipped = await (0, import_open_run.openRun)(this.automationRunRepository, { automation, trigger: "event", status: "skipped", now, payload, skipReason: "The queue of this automation is full" });
|
|
76
|
+
if (await this.automationRunRepository.countQueued(automationId, import_runner_scope.eventScope) >= (0, import_settings.maxQueuedRuns)()) {
|
|
77
|
+
const skipped = await (0, import_open_run.openRun)(this.automationRunRepository, { scope: import_runner_scope.eventScope, automation, trigger: "event", status: "skipped", now, payload, skipReason: "The queue of this automation is full" });
|
|
76
78
|
return { data: { status: "skipped", run: skipped.toJSON() } };
|
|
77
79
|
}
|
|
78
80
|
try {
|
|
79
|
-
const run = await (0, import_open_run.openRun)(this.automationRunRepository, { automation, trigger: "event", status: "queued", now, payload, idempotencyKey });
|
|
81
|
+
const run = await (0, import_open_run.openRun)(this.automationRunRepository, { scope: import_runner_scope.eventScope, automation, trigger: "event", status: "queued", now, payload, idempotencyKey });
|
|
80
82
|
return { data: { status: "queued", run: run.toJSON() } };
|
|
81
83
|
} catch (error) {
|
|
82
84
|
if (!idempotencyKey || error?.code !== 11e3) throw error;
|
|
83
|
-
const duplicate = await this.automationRunRepository.findByIdempotencyKey(automationId, idempotencyKey);
|
|
85
|
+
const duplicate = await this.automationRunRepository.findByIdempotencyKey(automationId, idempotencyKey, import_runner_scope.eventScope);
|
|
84
86
|
if (!duplicate) throw error;
|
|
85
87
|
return { data: { status: "duplicate", run: duplicate } };
|
|
86
88
|
}
|
|
@@ -10,6 +10,7 @@ import { AutomationEventError } from "../utils/automation-event-error";
|
|
|
10
10
|
import { readEventToken } from "../utils/event-token";
|
|
11
11
|
import { openRun } from "../utils/open-run";
|
|
12
12
|
import { maxQueuedRuns } from "../utils/settings";
|
|
13
|
+
import { eventScope } from "../utils/runner-scope";
|
|
13
14
|
const MAX_PAYLOAD_CHARS = 5e4;
|
|
14
15
|
const MAX_KEY_CHARS = 200;
|
|
15
16
|
const serialize = (payload) => {
|
|
@@ -29,10 +30,11 @@ let ReceiveAutomationEventUseCase = class extends BaseUseCase {
|
|
|
29
30
|
const now = params.now ?? /* @__PURE__ */ new Date();
|
|
30
31
|
const claims = readEventToken(token);
|
|
31
32
|
if (claims.sub !== automationId) throw new AutomationEventError("invalid");
|
|
32
|
-
const automation = await this.automationRepository.findById(automationId);
|
|
33
|
+
const automation = await this.automationRepository.findById(automationId, eventScope);
|
|
33
34
|
if (!automation) throw new AutomationEventError("not_found");
|
|
34
|
-
|
|
35
|
-
if (!automation.
|
|
35
|
+
const event = automation.triggers?.event;
|
|
36
|
+
if (!event || automation.eventTokenVersion !== claims.v) throw new AutomationEventError("invalid");
|
|
37
|
+
if (!event.enabled) throw new AutomationEventError("disabled");
|
|
36
38
|
const { data: { revoked } } = await isTokenRevoked({ jti: claims.jti });
|
|
37
39
|
if (revoked) throw new AutomationEventError("revoked");
|
|
38
40
|
const payload = serialize(params.payload);
|
|
@@ -40,19 +42,19 @@ let ReceiveAutomationEventUseCase = class extends BaseUseCase {
|
|
|
40
42
|
const idempotencyKey = params.idempotencyKey?.trim() || void 0;
|
|
41
43
|
if (idempotencyKey && idempotencyKey.length > MAX_KEY_CHARS) throw new Error(`The idempotency key cannot be longer than ${MAX_KEY_CHARS} characters`);
|
|
42
44
|
if (idempotencyKey) {
|
|
43
|
-
const duplicate = await this.automationRunRepository.findByIdempotencyKey(automationId, idempotencyKey);
|
|
45
|
+
const duplicate = await this.automationRunRepository.findByIdempotencyKey(automationId, idempotencyKey, eventScope);
|
|
44
46
|
if (duplicate) return { data: { status: "duplicate", run: duplicate } };
|
|
45
47
|
}
|
|
46
|
-
if (await this.automationRunRepository.countQueued(automationId) >= maxQueuedRuns()) {
|
|
47
|
-
const skipped = await openRun(this.automationRunRepository, { automation, trigger: "event", status: "skipped", now, payload, skipReason: "The queue of this automation is full" });
|
|
48
|
+
if (await this.automationRunRepository.countQueued(automationId, eventScope) >= maxQueuedRuns()) {
|
|
49
|
+
const skipped = await openRun(this.automationRunRepository, { scope: eventScope, automation, trigger: "event", status: "skipped", now, payload, skipReason: "The queue of this automation is full" });
|
|
48
50
|
return { data: { status: "skipped", run: skipped.toJSON() } };
|
|
49
51
|
}
|
|
50
52
|
try {
|
|
51
|
-
const run = await openRun(this.automationRunRepository, { automation, trigger: "event", status: "queued", now, payload, idempotencyKey });
|
|
53
|
+
const run = await openRun(this.automationRunRepository, { scope: eventScope, automation, trigger: "event", status: "queued", now, payload, idempotencyKey });
|
|
52
54
|
return { data: { status: "queued", run: run.toJSON() } };
|
|
53
55
|
} catch (error) {
|
|
54
56
|
if (!idempotencyKey || error?.code !== 11e3) throw error;
|
|
55
|
-
const duplicate = await this.automationRunRepository.findByIdempotencyKey(automationId, idempotencyKey);
|
|
57
|
+
const duplicate = await this.automationRunRepository.findByIdempotencyKey(automationId, idempotencyKey, eventScope);
|
|
56
58
|
if (!duplicate) throw error;
|
|
57
59
|
return { data: { status: "duplicate", run: duplicate } };
|
|
58
60
|
}
|
|
@@ -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_repositories = require("../repositories");
|
|
36
36
|
var import_settings = require("../utils/settings");
|
|
37
|
+
var import_runner_scope = require("../utils/runner-scope");
|
|
37
38
|
let RenewAutomationLeaseUseCase = class extends import_base.BaseUseCase {
|
|
38
39
|
constructor(automationRepository) {
|
|
39
40
|
super();
|
|
@@ -44,7 +45,7 @@ let RenewAutomationLeaseUseCase = class extends import_base.BaseUseCase {
|
|
|
44
45
|
const { automationId, workerId } = params;
|
|
45
46
|
const now = params.now ?? /* @__PURE__ */ new Date();
|
|
46
47
|
const until = new Date(now.getTime() + (params.leaseMs ?? (0, import_settings.leaseMs)()));
|
|
47
|
-
const automation = await this.automationRepository.renewLease(automationId, workerId, until);
|
|
48
|
+
const automation = await this.automationRepository.renewLease(automationId, workerId, until, import_runner_scope.runnerScope);
|
|
48
49
|
return { data: { renewed: Boolean(automation) } };
|
|
49
50
|
}
|
|
50
51
|
};
|
|
@@ -6,6 +6,7 @@ import { autoInjectable, inject } from "tsyringe";
|
|
|
6
6
|
import { BaseUseCase } from "../../../common/base/base.use-case.js";
|
|
7
7
|
import { AutomationRepository } from "../repositories";
|
|
8
8
|
import { leaseMs as defaultLeaseMs } from "../utils/settings";
|
|
9
|
+
import { runnerScope } from "../utils/runner-scope";
|
|
9
10
|
let RenewAutomationLeaseUseCase = class extends BaseUseCase {
|
|
10
11
|
constructor(automationRepository) {
|
|
11
12
|
super();
|
|
@@ -16,7 +17,7 @@ let RenewAutomationLeaseUseCase = class extends BaseUseCase {
|
|
|
16
17
|
const { automationId, workerId } = params;
|
|
17
18
|
const now = params.now ?? /* @__PURE__ */ new Date();
|
|
18
19
|
const until = new Date(now.getTime() + (params.leaseMs ?? defaultLeaseMs()));
|
|
19
|
-
const automation = await this.automationRepository.renewLease(automationId, workerId, until);
|
|
20
|
+
const automation = await this.automationRepository.renewLease(automationId, workerId, until, runnerScope);
|
|
20
21
|
return { data: { renewed: Boolean(automation) } };
|
|
21
22
|
}
|
|
22
23
|
};
|