openloops 0.3.5 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/README.md +10 -8
- package/dist/common/repositories/mongo-db.repository.d.ts +6 -1
- package/dist/common/repositories/mongo-db.repository.js +13 -5
- package/dist/common/repositories/mongo-db.repository.mjs +13 -5
- package/dist/db/index.d.ts +1 -0
- package/dist/db/index.js +3 -1
- package/dist/db/index.mjs +1 -0
- package/dist/db/indexes/automation-runs.d.ts +2 -0
- package/dist/db/indexes/automation-runs.js +33 -0
- package/dist/db/indexes/automation-runs.mjs +10 -0
- package/dist/db/indexes/automations.d.ts +2 -0
- package/dist/db/indexes/{agentic-jobs.js → automations.js} +6 -6
- package/dist/db/indexes/{agentic-jobs.mjs → automations.mjs} +2 -2
- package/dist/db/indexes/index.js +6 -4
- package/dist/db/indexes/index.mjs +6 -4
- package/dist/db/indexes/revoked-tokens.d.ts +2 -0
- package/dist/db/indexes/{agentic-job-runs.js → revoked-tokens.js} +8 -9
- package/dist/db/indexes/revoked-tokens.mjs +8 -0
- package/dist/db/migrations/automations.d.ts +12 -0
- package/dist/db/migrations/automations.js +70 -0
- package/dist/db/migrations/automations.mjs +47 -0
- package/dist/services/authentication/entities/index.d.ts +1 -0
- package/dist/services/authentication/entities/index.js +22 -0
- package/dist/services/authentication/entities/index.mjs +1 -0
- package/dist/services/authentication/entities/revoked-token.entity.d.ts +17 -0
- package/dist/services/authentication/entities/revoked-token.entity.js +67 -0
- package/dist/services/authentication/entities/revoked-token.entity.mjs +44 -0
- package/dist/services/authentication/index.d.ts +1 -0
- package/dist/services/authentication/index.js +3 -1
- package/dist/services/authentication/index.mjs +1 -0
- package/dist/services/authentication/module.d.ts +4 -0
- package/dist/services/authentication/module.js +16 -2
- package/dist/services/authentication/module.mjs +13 -1
- package/dist/services/authentication/repositories/index.d.ts +1 -0
- package/dist/services/{agentic-jobs → authentication}/repositories/index.js +2 -4
- package/dist/services/authentication/repositories/index.mjs +1 -0
- package/dist/services/authentication/repositories/revoked-token.repository.d.ts +7 -0
- package/dist/services/authentication/repositories/revoked-token.repository.js +55 -0
- package/dist/services/authentication/repositories/revoked-token.repository.mjs +26 -0
- package/dist/services/authentication/use-cases/is-token-revoked.use-case.d.ts +15 -0
- package/dist/services/{agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.js → authentication/use-cases/is-token-revoked.use-case.js} +16 -18
- package/dist/services/authentication/use-cases/is-token-revoked.use-case.mjs +26 -0
- package/dist/services/authentication/use-cases/revoke-token.use-case.d.ts +14 -0
- package/dist/services/authentication/use-cases/revoke-token.use-case.js +65 -0
- package/dist/services/authentication/use-cases/revoke-token.use-case.mjs +36 -0
- package/dist/services/automations/entities/automation-run.entity.d.ts +46 -0
- package/dist/services/{agentic-jobs/entities/agentic-job-run.entity.js → automations/entities/automation-run.entity.js} +22 -14
- package/dist/services/{agentic-jobs/entities/agentic-job-run.entity.mjs → automations/entities/automation-run.entity.mjs} +18 -10
- package/dist/services/automations/entities/automation.entity.d.ts +38 -0
- package/dist/services/{agentic-jobs/entities/agentic-job.entity.js → automations/entities/automation.entity.js} +17 -17
- package/dist/services/{agentic-jobs/entities/agentic-job.entity.mjs → automations/entities/automation.entity.mjs} +13 -13
- package/dist/services/automations/entities/index.d.ts +4 -0
- package/dist/services/{agentic-jobs → automations}/entities/index.js +6 -4
- package/dist/services/automations/entities/index.mjs +4 -0
- package/dist/services/automations/entities/trigger.d.ts +11 -0
- package/dist/services/automations/entities/trigger.js +49 -0
- package/dist/services/automations/entities/trigger.mjs +26 -0
- package/dist/services/automations/index.d.ts +5 -0
- package/dist/services/{agentic-jobs → automations}/index.js +9 -7
- package/dist/services/automations/index.mjs +5 -0
- package/dist/services/automations/module.d.ts +41 -0
- package/dist/services/automations/module.js +167 -0
- package/dist/services/automations/module.mjs +125 -0
- package/dist/services/automations/repositories/automation-run.repository.d.ts +14 -0
- package/dist/services/{agentic-jobs/repositories/agentic-job-run.repository.js → automations/repositories/automation-run.repository.js} +23 -11
- package/dist/services/{agentic-jobs/repositories/agentic-job-run.repository.mjs → automations/repositories/automation-run.repository.mjs} +19 -7
- package/dist/services/automations/repositories/automation.repository.d.ts +27 -0
- package/dist/services/{agentic-jobs/repositories/agentic-job.repository.js → automations/repositories/automation.repository.js} +17 -17
- package/dist/services/{agentic-jobs/repositories/agentic-job.repository.mjs → automations/repositories/automation.repository.mjs} +13 -13
- package/dist/services/automations/repositories/index.d.ts +2 -0
- package/dist/services/automations/repositories/index.js +24 -0
- package/dist/services/automations/repositories/index.mjs +2 -0
- package/dist/services/automations/runner/automation-runner.d.ts +49 -0
- package/dist/services/{agentic-jobs/runner/agentic-job-runner.js → automations/runner/automation-runner.js} +55 -45
- package/dist/services/{agentic-jobs/runner/agentic-job-runner.mjs → automations/runner/automation-runner.mjs} +50 -40
- package/dist/services/{agentic-jobs/use-cases/attach-agentic-job-run-chat.use-case.d.ts → automations/use-cases/attach-automation-run-chat.use-case.d.ts} +6 -6
- package/dist/services/{agentic-jobs/use-cases/attach-agentic-job-run-chat.use-case.js → automations/use-cases/attach-automation-run-chat.use-case.js} +14 -14
- package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.mjs +29 -0
- package/dist/services/automations/use-cases/claim-due-automations.use-case.d.ts +28 -0
- package/dist/services/{agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.js → automations/use-cases/claim-due-automations.use-case.js} +32 -43
- package/dist/services/automations/use-cases/claim-due-automations.use-case.mjs +70 -0
- package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.d.ts +27 -0
- package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.js +106 -0
- package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.mjs +77 -0
- package/dist/services/automations/use-cases/create-automation.use-case.d.ts +14 -0
- package/dist/services/{agentic-jobs/use-cases/create-agentic-job.use-case.js → automations/use-cases/create-automation.use-case.js} +24 -25
- package/dist/services/automations/use-cases/create-automation.use-case.mjs +43 -0
- package/dist/services/{agentic-jobs/use-cases/delete-agentic-job.use-case.d.ts → automations/use-cases/delete-automation.use-case.d.ts} +6 -6
- package/dist/services/{agentic-jobs/use-cases/delete-agentic-job.use-case.js → automations/use-cases/delete-automation.use-case.js} +17 -17
- package/dist/services/automations/use-cases/delete-automation.use-case.mjs +36 -0
- package/dist/services/{agentic-jobs/use-cases/finish-agentic-job-run.use-case.d.ts → automations/use-cases/finish-automation-run.use-case.d.ts} +8 -8
- package/dist/services/{agentic-jobs/use-cases/finish-agentic-job-run.use-case.js → automations/use-cases/finish-automation-run.use-case.js} +20 -20
- package/dist/services/automations/use-cases/finish-automation-run.use-case.mjs +46 -0
- package/dist/services/{agentic-jobs/use-cases/get-agentic-job-by-id.use-case.d.ts → automations/use-cases/get-automation-by-id.use-case.d.ts} +6 -6
- package/dist/services/{agentic-jobs/use-cases/get-agentic-job-by-id.use-case.js → automations/use-cases/get-automation-by-id.use-case.js} +13 -13
- package/dist/services/automations/use-cases/get-automation-by-id.use-case.mjs +26 -0
- package/dist/services/automations/use-cases/issue-automation-event-token.use-case.d.ts +17 -0
- package/dist/services/automations/use-cases/issue-automation-event-token.use-case.js +59 -0
- package/dist/services/automations/use-cases/issue-automation-event-token.use-case.mjs +30 -0
- package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.d.ts +17 -0
- package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.js +61 -0
- package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.mjs +32 -0
- package/dist/services/{agentic-jobs/use-cases/list-agentic-job-runs-by-user.use-case.d.ts → automations/use-cases/list-automation-runs-by-user.use-case.d.ts} +8 -7
- package/dist/services/{agentic-jobs/use-cases/list-agentic-job-runs-by-user.use-case.js → automations/use-cases/list-automation-runs-by-user.use-case.js} +19 -15
- package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.mjs +32 -0
- package/dist/services/{agentic-jobs/use-cases/list-agentic-jobs-by-user.use-case.d.ts → automations/use-cases/list-automations-by-user.use-case.d.ts} +7 -6
- package/dist/services/{agentic-jobs/use-cases/list-agentic-jobs-by-user.use-case.js → automations/use-cases/list-automations-by-user.use-case.js} +19 -15
- package/dist/services/automations/use-cases/list-automations-by-user.use-case.mjs +32 -0
- package/dist/services/{agentic-jobs/use-cases/preview-agentic-job-runs.use-case.d.ts → automations/use-cases/preview-automation-runs.use-case.d.ts} +1 -1
- package/dist/services/{agentic-jobs/use-cases/preview-agentic-job-runs.use-case.js → automations/use-cases/preview-automation-runs.use-case.js} +8 -8
- package/dist/services/{agentic-jobs/use-cases/preview-agentic-job-runs.use-case.mjs → automations/use-cases/preview-automation-runs.use-case.mjs} +4 -4
- package/dist/services/automations/use-cases/receive-automation-event.use-case.d.ts +23 -0
- package/dist/services/automations/use-cases/receive-automation-event.use-case.js +97 -0
- package/dist/services/automations/use-cases/receive-automation-event.use-case.mjs +68 -0
- package/dist/services/{agentic-jobs/use-cases/renew-agentic-job-lease.use-case.d.ts → automations/use-cases/renew-automation-lease.use-case.d.ts} +5 -5
- package/dist/services/{agentic-jobs/use-cases/renew-agentic-job-lease.use-case.js → automations/use-cases/renew-automation-lease.use-case.js} +15 -15
- package/dist/services/automations/use-cases/renew-automation-lease.use-case.mjs +29 -0
- package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.d.ts +16 -0
- package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.js +65 -0
- package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.mjs +36 -0
- package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.d.ts +14 -0
- package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.js +63 -0
- package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.mjs +34 -0
- package/dist/services/automations/use-cases/start-automation-run.use-case.d.ts +21 -0
- package/dist/services/{agentic-jobs/use-cases/start-agentic-job-run.use-case.js → automations/use-cases/start-automation-run.use-case.js} +24 -24
- package/dist/services/automations/use-cases/start-automation-run.use-case.mjs +38 -0
- package/dist/services/automations/use-cases/sync-automation-run.use-case.d.ts +20 -0
- package/dist/services/{agentic-jobs/use-cases/sync-agentic-job-run.use-case.js → automations/use-cases/sync-automation-run.use-case.js} +23 -23
- package/dist/services/{agentic-jobs/use-cases/sync-agentic-job-run.use-case.mjs → automations/use-cases/sync-automation-run.use-case.mjs} +21 -21
- package/dist/services/{agentic-jobs/use-cases/sync-agentic-job-runs.use-case.d.ts → automations/use-cases/sync-automation-runs.use-case.d.ts} +5 -5
- package/dist/services/{agentic-jobs/use-cases/sync-agentic-job-runs.use-case.js → automations/use-cases/sync-automation-runs.use-case.js} +16 -16
- package/dist/services/{agentic-jobs/use-cases/sync-agentic-job-runs.use-case.mjs → automations/use-cases/sync-automation-runs.use-case.mjs} +13 -13
- package/dist/services/automations/use-cases/update-automation.use-case.d.ts +15 -0
- package/dist/services/{agentic-jobs/use-cases/update-agentic-job.use-case.js → automations/use-cases/update-automation.use-case.js} +27 -27
- package/dist/services/automations/use-cases/update-automation.use-case.mjs +54 -0
- package/dist/services/automations/utils/automation-event-error.d.ts +6 -0
- package/dist/services/automations/utils/automation-event-error.js +37 -0
- package/dist/services/automations/utils/automation-event-error.mjs +14 -0
- package/dist/services/automations/utils/automation-fields.d.ts +14 -0
- package/dist/services/{agentic-jobs/utils/job-fields.js → automations/utils/automation-fields.js} +8 -10
- package/dist/services/{agentic-jobs/utils/job-fields.mjs → automations/utils/automation-fields.mjs} +4 -6
- package/dist/services/automations/utils/event-message.d.ts +1 -0
- package/dist/services/automations/utils/event-message.js +37 -0
- package/dist/services/automations/utils/event-message.mjs +14 -0
- package/dist/services/automations/utils/event-token.d.ts +18 -0
- package/dist/services/automations/utils/event-token.js +78 -0
- package/dist/services/automations/utils/event-token.mjs +43 -0
- package/dist/services/automations/utils/open-run.d.ts +14 -0
- package/dist/services/{agentic-jobs → automations}/utils/open-run.js +10 -8
- package/dist/services/automations/utils/open-run.mjs +26 -0
- package/dist/services/automations/utils/previous-run.d.ts +4 -0
- package/dist/services/automations/utils/previous-run.js +42 -0
- package/dist/services/automations/utils/previous-run.mjs +19 -0
- package/dist/services/{agentic-jobs → automations}/utils/settings.d.ts +1 -0
- package/dist/services/{agentic-jobs → automations}/utils/settings.js +6 -2
- package/dist/services/automations/utils/settings.mjs +13 -0
- package/dist/services/chats/use-cases/list-chats-by-user.use-case.d.ts +1 -0
- package/dist/services/chats/use-cases/list-chats-by-user.use-case.js +2 -2
- package/dist/services/chats/use-cases/list-chats-by-user.use-case.mjs +2 -2
- package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.d.ts +1 -0
- package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.js +2 -2
- package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.mjs +2 -2
- package/docs/README.md +1 -1
- package/docs/agent.md +2 -2
- package/docs/authentication.md +18 -1
- package/docs/automations.md +388 -0
- package/docs/chats.md +1 -1
- package/docs/configuration.md +6 -5
- package/docs/harness.md +1 -1
- package/docs/integration-guide.md +22 -18
- package/docs/llms.txt +1 -1
- package/docs/mcp-servers.md +1 -1
- package/examples/{agentic-jobs/create-agentic-job.ts → automations/create-automation.ts} +10 -7
- package/examples/automations/create-event-automation.ts +24 -0
- package/examples/{agentic-jobs/list-agentic-job-runs.ts → automations/list-automation-runs.ts} +8 -8
- package/examples/automations/list-automations.ts +25 -0
- package/examples/{agentic-jobs/preview-agentic-job-runs.ts → automations/preview-automation-runs.ts} +2 -2
- package/examples/automations/receive-automation-event.ts +26 -0
- package/examples/automations/revoke-automation-event-token.ts +25 -0
- package/examples/{agentic-jobs/run-agentic-job-now.ts → automations/run-automation-now.ts} +3 -3
- package/examples/{agentic-jobs/run-agentic-job-worker.ts → automations/run-automation-worker.ts} +6 -6
- package/examples/{agentic-jobs/update-agentic-job.ts → automations/update-automation.ts} +10 -10
- package/package.json +16 -14
- package/dist/db/indexes/agentic-job-runs.d.ts +0 -2
- package/dist/db/indexes/agentic-job-runs.mjs +0 -9
- package/dist/db/indexes/agentic-jobs.d.ts +0 -2
- package/dist/services/agentic-jobs/entities/agentic-job-run.entity.d.ts +0 -42
- package/dist/services/agentic-jobs/entities/agentic-job.entity.d.ts +0 -39
- package/dist/services/agentic-jobs/entities/index.d.ts +0 -3
- package/dist/services/agentic-jobs/entities/index.mjs +0 -3
- package/dist/services/agentic-jobs/index.d.ts +0 -4
- package/dist/services/agentic-jobs/index.mjs +0 -4
- package/dist/services/agentic-jobs/module.d.ts +0 -31
- package/dist/services/agentic-jobs/module.js +0 -132
- package/dist/services/agentic-jobs/module.mjs +0 -95
- package/dist/services/agentic-jobs/repositories/agentic-job-run.repository.d.ts +0 -11
- package/dist/services/agentic-jobs/repositories/agentic-job.repository.d.ts +0 -27
- package/dist/services/agentic-jobs/repositories/index.d.ts +0 -2
- package/dist/services/agentic-jobs/repositories/index.mjs +0 -2
- package/dist/services/agentic-jobs/runner/agentic-job-runner.d.ts +0 -48
- package/dist/services/agentic-jobs/use-cases/attach-agentic-job-run-chat.use-case.mjs +0 -29
- package/dist/services/agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.d.ts +0 -29
- package/dist/services/agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.mjs +0 -81
- package/dist/services/agentic-jobs/use-cases/create-agentic-job.use-case.d.ts +0 -14
- package/dist/services/agentic-jobs/use-cases/create-agentic-job.use-case.mjs +0 -44
- package/dist/services/agentic-jobs/use-cases/delete-agentic-job.use-case.mjs +0 -36
- package/dist/services/agentic-jobs/use-cases/finish-agentic-job-run.use-case.mjs +0 -46
- package/dist/services/agentic-jobs/use-cases/get-agentic-job-by-id.use-case.mjs +0 -26
- package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.d.ts +0 -16
- package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.mjs +0 -28
- package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-user.use-case.mjs +0 -28
- package/dist/services/agentic-jobs/use-cases/list-agentic-jobs-by-user.use-case.mjs +0 -28
- package/dist/services/agentic-jobs/use-cases/renew-agentic-job-lease.use-case.mjs +0 -29
- package/dist/services/agentic-jobs/use-cases/start-agentic-job-run.use-case.d.ts +0 -21
- package/dist/services/agentic-jobs/use-cases/start-agentic-job-run.use-case.mjs +0 -38
- package/dist/services/agentic-jobs/use-cases/sync-agentic-job-run.use-case.d.ts +0 -20
- package/dist/services/agentic-jobs/use-cases/update-agentic-job.use-case.d.ts +0 -15
- package/dist/services/agentic-jobs/use-cases/update-agentic-job.use-case.mjs +0 -54
- package/dist/services/agentic-jobs/utils/job-fields.d.ts +0 -14
- package/dist/services/agentic-jobs/utils/open-run.d.ts +0 -12
- package/dist/services/agentic-jobs/utils/open-run.mjs +0 -24
- package/dist/services/agentic-jobs/utils/settings.mjs +0 -10
- package/docs/agentic-jobs.md +0 -217
- package/examples/agentic-jobs/list-agentic-jobs.ts +0 -25
- /package/dist/services/{agentic-jobs → automations}/entities/recurrence.d.ts +0 -0
- /package/dist/services/{agentic-jobs → automations}/entities/recurrence.js +0 -0
- /package/dist/services/{agentic-jobs → automations}/entities/recurrence.mjs +0 -0
- /package/dist/services/{agentic-jobs → automations}/utils/next-run.d.ts +0 -0
- /package/dist/services/{agentic-jobs → automations}/utils/next-run.js +0 -0
- /package/dist/services/{agentic-jobs → automations}/utils/next-run.mjs +0 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__decorateClass,
|
|
3
|
+
__decorateParam
|
|
4
|
+
} from "../../../chunk-CF3WOMB3.mjs";
|
|
5
|
+
import { autoInjectable, inject } from "tsyringe";
|
|
6
|
+
import { BaseUseCase } from "../../../common/base/base.use-case.js";
|
|
7
|
+
import { Automation } from "../entities";
|
|
8
|
+
import { AutomationRepository } from "../repositories";
|
|
9
|
+
let RotateAutomationEventTokensUseCase = class extends BaseUseCase {
|
|
10
|
+
constructor(automationRepository) {
|
|
11
|
+
super();
|
|
12
|
+
this.automationRepository = automationRepository;
|
|
13
|
+
}
|
|
14
|
+
automationRepository;
|
|
15
|
+
async execute(params) {
|
|
16
|
+
const { id, currentUser } = params;
|
|
17
|
+
const existing = await this.automationRepository?.findById(id);
|
|
18
|
+
if (!existing) throw new Error("Automation not found");
|
|
19
|
+
if (!currentUser?.isAdmin() && String(existing.ownerId) !== currentUser?.userId) this.throwError403();
|
|
20
|
+
if (existing.trigger?.type !== "event") throw new Error("Only an automation with an event trigger has tokens");
|
|
21
|
+
const automation = Automation.fromJSON({ ...existing, trigger: { ...existing.trigger, tokenVersion: existing.trigger.tokenVersion + 1 } });
|
|
22
|
+
automation.setUpdatedBy(currentUser);
|
|
23
|
+
const result = await this.automationRepository?.update(automation, { expectedVersion: existing.__v });
|
|
24
|
+
if (!result) throw new Error("Automation not found or update failed");
|
|
25
|
+
return { data: result };
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
RotateAutomationEventTokensUseCase = __decorateClass([
|
|
29
|
+
autoInjectable(),
|
|
30
|
+
__decorateParam(0, inject(AutomationRepository))
|
|
31
|
+
], RotateAutomationEventTokensUseCase);
|
|
32
|
+
export {
|
|
33
|
+
RotateAutomationEventTokensUseCase
|
|
34
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BaseUseCase, BaseUseCaseParams, BaseUseCaseOutput } from '../../../common/base/base.use-case.js';
|
|
2
|
+
import { AutomationProps, AutomationRunProps } from '../entities';
|
|
3
|
+
import { AutomationRepository, AutomationRunRepository } from '../repositories';
|
|
4
|
+
export interface Params extends BaseUseCaseParams {
|
|
5
|
+
automationId: string;
|
|
6
|
+
workerId: string;
|
|
7
|
+
leaseMs?: number;
|
|
8
|
+
now?: Date;
|
|
9
|
+
}
|
|
10
|
+
export interface Output extends BaseUseCaseOutput {
|
|
11
|
+
data: {
|
|
12
|
+
automation: AutomationProps;
|
|
13
|
+
run: AutomationRunProps;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare class StartAutomationRunUseCase extends BaseUseCase<Params, Output> {
|
|
17
|
+
private readonly automationRepository?;
|
|
18
|
+
private readonly automationRunRepository?;
|
|
19
|
+
constructor(automationRepository?: AutomationRepository | undefined, automationRunRepository?: AutomationRunRepository | undefined);
|
|
20
|
+
execute(params: Params): Promise<Output>;
|
|
21
|
+
}
|
|
@@ -25,43 +25,43 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
25
25
|
return result;
|
|
26
26
|
};
|
|
27
27
|
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
28
|
-
var
|
|
29
|
-
__export(
|
|
30
|
-
|
|
28
|
+
var start_automation_run_use_case_exports = {};
|
|
29
|
+
__export(start_automation_run_use_case_exports, {
|
|
30
|
+
StartAutomationRunUseCase: () => StartAutomationRunUseCase
|
|
31
31
|
});
|
|
32
|
-
module.exports = __toCommonJS(
|
|
32
|
+
module.exports = __toCommonJS(start_automation_run_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
36
|
var import_open_run = require("../utils/open-run");
|
|
37
37
|
var import_settings = require("../utils/settings");
|
|
38
|
-
let
|
|
39
|
-
constructor(
|
|
38
|
+
let StartAutomationRunUseCase = class extends import_base.BaseUseCase {
|
|
39
|
+
constructor(automationRepository, automationRunRepository) {
|
|
40
40
|
super();
|
|
41
|
-
this.
|
|
42
|
-
this.
|
|
41
|
+
this.automationRepository = automationRepository;
|
|
42
|
+
this.automationRunRepository = automationRunRepository;
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
automationRepository;
|
|
45
|
+
automationRunRepository;
|
|
46
46
|
async execute(params) {
|
|
47
|
-
const {
|
|
48
|
-
if (!
|
|
47
|
+
const { automationId, workerId } = params;
|
|
48
|
+
if (!automationId || !workerId) throw new Error("The automation and the worker are required");
|
|
49
49
|
const now = params.now ?? /* @__PURE__ */ new Date();
|
|
50
|
-
const existing = await this.
|
|
51
|
-
if (!existing) throw new Error("
|
|
52
|
-
const
|
|
53
|
-
if (!
|
|
54
|
-
const run = await (0, import_open_run.openRun)(this.
|
|
55
|
-
await this.
|
|
56
|
-
return { data: {
|
|
50
|
+
const existing = await this.automationRepository.findById(automationId);
|
|
51
|
+
if (!existing) throw new Error("Automation not found");
|
|
52
|
+
const automation = await this.automationRepository.claimManual({ id: automationId, workerId, now, leaseMs: params.leaseMs ?? (0, import_settings.leaseMs)() });
|
|
53
|
+
if (!automation) throw new Error("The automation is already running");
|
|
54
|
+
const run = await (0, import_open_run.openRun)(this.automationRunRepository, { automation, trigger: "manual", status: "running", workerId, now });
|
|
55
|
+
await this.automationRepository.setActiveRun(automationId, workerId, String(run._id));
|
|
56
|
+
return { data: { automation, run: run.toJSON() } };
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
|
-
|
|
59
|
+
StartAutomationRunUseCase = __decorateClass([
|
|
60
60
|
(0, import_tsyringe.autoInjectable)(),
|
|
61
|
-
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories.
|
|
62
|
-
__decorateParam(1, (0, import_tsyringe.inject)(import_repositories.
|
|
63
|
-
],
|
|
61
|
+
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories.AutomationRepository)),
|
|
62
|
+
__decorateParam(1, (0, import_tsyringe.inject)(import_repositories.AutomationRunRepository))
|
|
63
|
+
], StartAutomationRunUseCase);
|
|
64
64
|
// Annotate the CommonJS export names for ESM import in node:
|
|
65
65
|
0 && (module.exports = {
|
|
66
|
-
|
|
66
|
+
StartAutomationRunUseCase
|
|
67
67
|
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__decorateClass,
|
|
3
|
+
__decorateParam
|
|
4
|
+
} from "../../../chunk-CF3WOMB3.mjs";
|
|
5
|
+
import { autoInjectable, inject } from "tsyringe";
|
|
6
|
+
import { BaseUseCase } from "../../../common/base/base.use-case.js";
|
|
7
|
+
import { AutomationRepository, AutomationRunRepository } from "../repositories";
|
|
8
|
+
import { openRun } from "../utils/open-run";
|
|
9
|
+
import { leaseMs as defaultLeaseMs } from "../utils/settings";
|
|
10
|
+
let StartAutomationRunUseCase = class extends BaseUseCase {
|
|
11
|
+
constructor(automationRepository, automationRunRepository) {
|
|
12
|
+
super();
|
|
13
|
+
this.automationRepository = automationRepository;
|
|
14
|
+
this.automationRunRepository = automationRunRepository;
|
|
15
|
+
}
|
|
16
|
+
automationRepository;
|
|
17
|
+
automationRunRepository;
|
|
18
|
+
async execute(params) {
|
|
19
|
+
const { automationId, workerId } = params;
|
|
20
|
+
if (!automationId || !workerId) throw new Error("The automation and the worker are required");
|
|
21
|
+
const now = params.now ?? /* @__PURE__ */ new Date();
|
|
22
|
+
const existing = await this.automationRepository.findById(automationId);
|
|
23
|
+
if (!existing) throw new Error("Automation not found");
|
|
24
|
+
const automation = await this.automationRepository.claimManual({ id: automationId, workerId, now, leaseMs: params.leaseMs ?? defaultLeaseMs() });
|
|
25
|
+
if (!automation) throw new Error("The automation is already running");
|
|
26
|
+
const run = await openRun(this.automationRunRepository, { automation, trigger: "manual", status: "running", workerId, now });
|
|
27
|
+
await this.automationRepository.setActiveRun(automationId, workerId, String(run._id));
|
|
28
|
+
return { data: { automation, run: run.toJSON() } };
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
StartAutomationRunUseCase = __decorateClass([
|
|
32
|
+
autoInjectable(),
|
|
33
|
+
__decorateParam(0, inject(AutomationRepository)),
|
|
34
|
+
__decorateParam(1, inject(AutomationRunRepository))
|
|
35
|
+
], StartAutomationRunUseCase);
|
|
36
|
+
export {
|
|
37
|
+
StartAutomationRunUseCase
|
|
38
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseUseCase, BaseUseCaseParams, BaseUseCaseOutput } from '../../../common/base/base.use-case.js';
|
|
2
|
+
import { AutomationRunProps } from '../entities';
|
|
3
|
+
import { AutomationRepository, AutomationRunRepository } from '../repositories';
|
|
4
|
+
export interface Params extends BaseUseCaseParams {
|
|
5
|
+
runId: string;
|
|
6
|
+
now?: Date;
|
|
7
|
+
}
|
|
8
|
+
export interface Output extends BaseUseCaseOutput {
|
|
9
|
+
data: AutomationRunProps | null;
|
|
10
|
+
}
|
|
11
|
+
export declare const LOST_WORKER_MESSAGE = "The worker that was running this automation was lost before it finished";
|
|
12
|
+
export declare class SyncAutomationRunUseCase extends BaseUseCase<Params, Output> {
|
|
13
|
+
private readonly automationRepository?;
|
|
14
|
+
private readonly automationRunRepository?;
|
|
15
|
+
constructor(automationRepository?: AutomationRepository | undefined, automationRunRepository?: AutomationRunRepository | undefined);
|
|
16
|
+
execute(params: Params): Promise<Output>;
|
|
17
|
+
private syncPaused;
|
|
18
|
+
private syncRunning;
|
|
19
|
+
private settle;
|
|
20
|
+
}
|
|
@@ -25,29 +25,29 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
25
25
|
return result;
|
|
26
26
|
};
|
|
27
27
|
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
28
|
-
var
|
|
29
|
-
__export(
|
|
28
|
+
var sync_automation_run_use_case_exports = {};
|
|
29
|
+
__export(sync_automation_run_use_case_exports, {
|
|
30
30
|
LOST_WORKER_MESSAGE: () => LOST_WORKER_MESSAGE,
|
|
31
|
-
|
|
31
|
+
SyncAutomationRunUseCase: () => SyncAutomationRunUseCase
|
|
32
32
|
});
|
|
33
|
-
module.exports = __toCommonJS(
|
|
33
|
+
module.exports = __toCommonJS(sync_automation_run_use_case_exports);
|
|
34
34
|
var import_tsyringe = require("tsyringe");
|
|
35
35
|
var import_base = require("../../../common/base/base.use-case.js");
|
|
36
36
|
var import_chats = require("../../chats/index.js");
|
|
37
37
|
var import_entities = require("../entities");
|
|
38
38
|
var import_repositories = require("../repositories");
|
|
39
|
-
const LOST_WORKER_MESSAGE = "The worker that was running this
|
|
40
|
-
let
|
|
41
|
-
constructor(
|
|
39
|
+
const LOST_WORKER_MESSAGE = "The worker that was running this automation was lost before it finished";
|
|
40
|
+
let SyncAutomationRunUseCase = class extends import_base.BaseUseCase {
|
|
41
|
+
constructor(automationRepository, automationRunRepository) {
|
|
42
42
|
super();
|
|
43
|
-
this.
|
|
44
|
-
this.
|
|
43
|
+
this.automationRepository = automationRepository;
|
|
44
|
+
this.automationRunRepository = automationRunRepository;
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
automationRepository;
|
|
47
|
+
automationRunRepository;
|
|
48
48
|
async execute(params) {
|
|
49
49
|
const now = params.now ?? /* @__PURE__ */ new Date();
|
|
50
|
-
const run = await this.
|
|
50
|
+
const run = await this.automationRunRepository?.findById(params.runId);
|
|
51
51
|
if (!run) return { data: null };
|
|
52
52
|
if (run.status === "paused") return { data: await this.syncPaused(run, now) };
|
|
53
53
|
if (run.status === "running") return { data: await this.syncRunning(run, now) };
|
|
@@ -62,25 +62,25 @@ let SyncAgenticJobRunUseCase = class extends import_base.BaseUseCase {
|
|
|
62
62
|
return run;
|
|
63
63
|
}
|
|
64
64
|
async syncRunning(run, now) {
|
|
65
|
-
const
|
|
66
|
-
const lockedUntil =
|
|
67
|
-
if (
|
|
65
|
+
const automation = run.automationId ? await this.automationRepository?.findById(String(run.automationId)) : null;
|
|
66
|
+
const lockedUntil = automation?.lockedUntil ? new Date(automation.lockedUntil).getTime() : 0;
|
|
67
|
+
if (automation && lockedUntil > now.getTime()) return run;
|
|
68
68
|
return await this.settle(run, "failed", now, { code: "WORKER_LOST", message: LOST_WORKER_MESSAGE });
|
|
69
69
|
}
|
|
70
70
|
async settle(run, status, now, error) {
|
|
71
|
-
const updated = import_entities.
|
|
72
|
-
const saved = await this.
|
|
73
|
-
if (run.
|
|
71
|
+
const updated = import_entities.AutomationRun.fromJSON({ ...run, status, finishedAt: now, ...error ? { error } : {} });
|
|
72
|
+
const saved = await this.automationRunRepository?.update(updated);
|
|
73
|
+
if (run.automationId && run._id) await this.automationRepository?.settleRun(String(run.automationId), String(run._id), status, now);
|
|
74
74
|
return saved ?? updated.toJSON();
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
|
-
|
|
77
|
+
SyncAutomationRunUseCase = __decorateClass([
|
|
78
78
|
(0, import_tsyringe.autoInjectable)(),
|
|
79
|
-
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories.
|
|
80
|
-
__decorateParam(1, (0, import_tsyringe.inject)(import_repositories.
|
|
81
|
-
],
|
|
79
|
+
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories.AutomationRepository)),
|
|
80
|
+
__decorateParam(1, (0, import_tsyringe.inject)(import_repositories.AutomationRunRepository))
|
|
81
|
+
], SyncAutomationRunUseCase);
|
|
82
82
|
// Annotate the CommonJS export names for ESM import in node:
|
|
83
83
|
0 && (module.exports = {
|
|
84
84
|
LOST_WORKER_MESSAGE,
|
|
85
|
-
|
|
85
|
+
SyncAutomationRunUseCase
|
|
86
86
|
});
|
|
@@ -5,20 +5,20 @@ import {
|
|
|
5
5
|
import { autoInjectable, inject } from "tsyringe";
|
|
6
6
|
import { BaseUseCase } from "../../../common/base/base.use-case.js";
|
|
7
7
|
import { getChatById } from "../../chats/index.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
const LOST_WORKER_MESSAGE = "The worker that was running this
|
|
11
|
-
let
|
|
12
|
-
constructor(
|
|
8
|
+
import { AutomationRun } from "../entities";
|
|
9
|
+
import { AutomationRepository, AutomationRunRepository } from "../repositories";
|
|
10
|
+
const LOST_WORKER_MESSAGE = "The worker that was running this automation was lost before it finished";
|
|
11
|
+
let SyncAutomationRunUseCase = class extends BaseUseCase {
|
|
12
|
+
constructor(automationRepository, automationRunRepository) {
|
|
13
13
|
super();
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
14
|
+
this.automationRepository = automationRepository;
|
|
15
|
+
this.automationRunRepository = automationRunRepository;
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
automationRepository;
|
|
18
|
+
automationRunRepository;
|
|
19
19
|
async execute(params) {
|
|
20
20
|
const now = params.now ?? /* @__PURE__ */ new Date();
|
|
21
|
-
const run = await this.
|
|
21
|
+
const run = await this.automationRunRepository?.findById(params.runId);
|
|
22
22
|
if (!run) return { data: null };
|
|
23
23
|
if (run.status === "paused") return { data: await this.syncPaused(run, now) };
|
|
24
24
|
if (run.status === "running") return { data: await this.syncRunning(run, now) };
|
|
@@ -33,24 +33,24 @@ let SyncAgenticJobRunUseCase = class extends BaseUseCase {
|
|
|
33
33
|
return run;
|
|
34
34
|
}
|
|
35
35
|
async syncRunning(run, now) {
|
|
36
|
-
const
|
|
37
|
-
const lockedUntil =
|
|
38
|
-
if (
|
|
36
|
+
const automation = run.automationId ? await this.automationRepository?.findById(String(run.automationId)) : null;
|
|
37
|
+
const lockedUntil = automation?.lockedUntil ? new Date(automation.lockedUntil).getTime() : 0;
|
|
38
|
+
if (automation && lockedUntil > now.getTime()) return run;
|
|
39
39
|
return await this.settle(run, "failed", now, { code: "WORKER_LOST", message: LOST_WORKER_MESSAGE });
|
|
40
40
|
}
|
|
41
41
|
async settle(run, status, now, error) {
|
|
42
|
-
const updated =
|
|
43
|
-
const saved = await this.
|
|
44
|
-
if (run.
|
|
42
|
+
const updated = AutomationRun.fromJSON({ ...run, status, finishedAt: now, ...error ? { error } : {} });
|
|
43
|
+
const saved = await this.automationRunRepository?.update(updated);
|
|
44
|
+
if (run.automationId && run._id) await this.automationRepository?.settleRun(String(run.automationId), String(run._id), status, now);
|
|
45
45
|
return saved ?? updated.toJSON();
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
|
-
|
|
48
|
+
SyncAutomationRunUseCase = __decorateClass([
|
|
49
49
|
autoInjectable(),
|
|
50
|
-
__decorateParam(0, inject(
|
|
51
|
-
__decorateParam(1, inject(
|
|
52
|
-
],
|
|
50
|
+
__decorateParam(0, inject(AutomationRepository)),
|
|
51
|
+
__decorateParam(1, inject(AutomationRunRepository))
|
|
52
|
+
], SyncAutomationRunUseCase);
|
|
53
53
|
export {
|
|
54
54
|
LOST_WORKER_MESSAGE,
|
|
55
|
-
|
|
55
|
+
SyncAutomationRunUseCase
|
|
56
56
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseUseCase, BaseUseCaseParams, BaseUseCaseOutput } from '../../../common/base/base.use-case.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { AutomationRunRepository } from '../repositories';
|
|
3
|
+
import { SyncAutomationRunUseCase } from './sync-automation-run.use-case';
|
|
4
4
|
export interface Params extends BaseUseCaseParams {
|
|
5
5
|
limit?: number;
|
|
6
6
|
now?: Date;
|
|
@@ -11,9 +11,9 @@ export interface Output extends BaseUseCaseOutput {
|
|
|
11
11
|
settled: number;
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
-
export declare class
|
|
15
|
-
private readonly
|
|
14
|
+
export declare class SyncAutomationRunsUseCase extends BaseUseCase<Params, Output> {
|
|
15
|
+
private readonly automationRunRepository?;
|
|
16
16
|
private readonly syncRun?;
|
|
17
|
-
constructor(
|
|
17
|
+
constructor(automationRunRepository?: AutomationRunRepository | undefined, syncRun?: SyncAutomationRunUseCase | undefined);
|
|
18
18
|
execute(params: Params): Promise<Output>;
|
|
19
19
|
}
|
|
@@ -25,29 +25,29 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
25
25
|
return result;
|
|
26
26
|
};
|
|
27
27
|
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
28
|
-
var
|
|
29
|
-
__export(
|
|
30
|
-
|
|
28
|
+
var sync_automation_runs_use_case_exports = {};
|
|
29
|
+
__export(sync_automation_runs_use_case_exports, {
|
|
30
|
+
SyncAutomationRunsUseCase: () => SyncAutomationRunsUseCase
|
|
31
31
|
});
|
|
32
|
-
module.exports = __toCommonJS(
|
|
32
|
+
module.exports = __toCommonJS(sync_automation_runs_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
|
|
36
|
+
var import_sync_automation_run = require("./sync-automation-run.use-case");
|
|
37
37
|
const DEFAULT_LIMIT = 100;
|
|
38
|
-
let
|
|
39
|
-
constructor(
|
|
38
|
+
let SyncAutomationRunsUseCase = class extends import_base.BaseUseCase {
|
|
39
|
+
constructor(automationRunRepository, syncRun) {
|
|
40
40
|
super();
|
|
41
|
-
this.
|
|
41
|
+
this.automationRunRepository = automationRunRepository;
|
|
42
42
|
this.syncRun = syncRun;
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
automationRunRepository;
|
|
45
45
|
syncRun;
|
|
46
46
|
async execute(params) {
|
|
47
47
|
const limit = params.limit ?? DEFAULT_LIMIT;
|
|
48
48
|
const open = [
|
|
49
|
-
...await this.
|
|
50
|
-
...await this.
|
|
49
|
+
...await this.automationRunRepository?.findByStatus("paused", limit) ?? [],
|
|
50
|
+
...await this.automationRunRepository?.findByStatus("running", limit) ?? []
|
|
51
51
|
];
|
|
52
52
|
let settled = 0;
|
|
53
53
|
for (const run of open) {
|
|
@@ -57,12 +57,12 @@ let SyncAgenticJobRunsUseCase = class extends import_base.BaseUseCase {
|
|
|
57
57
|
return { data: { checked: open.length, settled } };
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
|
-
|
|
60
|
+
SyncAutomationRunsUseCase = __decorateClass([
|
|
61
61
|
(0, import_tsyringe.autoInjectable)(),
|
|
62
|
-
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories.
|
|
63
|
-
__decorateParam(1, (0, import_tsyringe.inject)(
|
|
64
|
-
],
|
|
62
|
+
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories.AutomationRunRepository)),
|
|
63
|
+
__decorateParam(1, (0, import_tsyringe.inject)(import_sync_automation_run.SyncAutomationRunUseCase))
|
|
64
|
+
], SyncAutomationRunsUseCase);
|
|
65
65
|
// Annotate the CommonJS export names for ESM import in node:
|
|
66
66
|
0 && (module.exports = {
|
|
67
|
-
|
|
67
|
+
SyncAutomationRunsUseCase
|
|
68
68
|
});
|
|
@@ -4,22 +4,22 @@ 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 {
|
|
8
|
-
import {
|
|
7
|
+
import { AutomationRunRepository } from "../repositories";
|
|
8
|
+
import { SyncAutomationRunUseCase } from "./sync-automation-run.use-case";
|
|
9
9
|
const DEFAULT_LIMIT = 100;
|
|
10
|
-
let
|
|
11
|
-
constructor(
|
|
10
|
+
let SyncAutomationRunsUseCase = class extends BaseUseCase {
|
|
11
|
+
constructor(automationRunRepository, syncRun) {
|
|
12
12
|
super();
|
|
13
|
-
this.
|
|
13
|
+
this.automationRunRepository = automationRunRepository;
|
|
14
14
|
this.syncRun = syncRun;
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
automationRunRepository;
|
|
17
17
|
syncRun;
|
|
18
18
|
async execute(params) {
|
|
19
19
|
const limit = params.limit ?? DEFAULT_LIMIT;
|
|
20
20
|
const open = [
|
|
21
|
-
...await this.
|
|
22
|
-
...await this.
|
|
21
|
+
...await this.automationRunRepository?.findByStatus("paused", limit) ?? [],
|
|
22
|
+
...await this.automationRunRepository?.findByStatus("running", limit) ?? []
|
|
23
23
|
];
|
|
24
24
|
let settled = 0;
|
|
25
25
|
for (const run of open) {
|
|
@@ -29,11 +29,11 @@ let SyncAgenticJobRunsUseCase = class extends BaseUseCase {
|
|
|
29
29
|
return { data: { checked: open.length, settled } };
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
|
-
|
|
32
|
+
SyncAutomationRunsUseCase = __decorateClass([
|
|
33
33
|
autoInjectable(),
|
|
34
|
-
__decorateParam(0, inject(
|
|
35
|
-
__decorateParam(1, inject(
|
|
36
|
-
],
|
|
34
|
+
__decorateParam(0, inject(AutomationRunRepository)),
|
|
35
|
+
__decorateParam(1, inject(SyncAutomationRunUseCase))
|
|
36
|
+
], SyncAutomationRunsUseCase);
|
|
37
37
|
export {
|
|
38
|
-
|
|
38
|
+
SyncAutomationRunsUseCase
|
|
39
39
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseUseCase, BaseUseCaseParams, BaseUseCaseOutput } from '../../../common/base/base.use-case.js';
|
|
2
|
+
import { AutomationProps } from '../entities';
|
|
3
|
+
import { AutomationRepository } from '../repositories';
|
|
4
|
+
export interface Params extends BaseUseCaseParams {
|
|
5
|
+
id: string;
|
|
6
|
+
payload?: AutomationProps;
|
|
7
|
+
}
|
|
8
|
+
export interface Output extends BaseUseCaseOutput {
|
|
9
|
+
data: AutomationProps;
|
|
10
|
+
}
|
|
11
|
+
export declare class UpdateAutomationUseCase extends BaseUseCase<Params, Output> {
|
|
12
|
+
private readonly automationRepository?;
|
|
13
|
+
constructor(automationRepository?: AutomationRepository | undefined);
|
|
14
|
+
execute(params: Params): Promise<Output>;
|
|
15
|
+
}
|
|
@@ -25,59 +25,59 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
25
25
|
return result;
|
|
26
26
|
};
|
|
27
27
|
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
28
|
-
var
|
|
29
|
-
__export(
|
|
30
|
-
|
|
28
|
+
var update_automation_use_case_exports = {};
|
|
29
|
+
__export(update_automation_use_case_exports, {
|
|
30
|
+
UpdateAutomationUseCase: () => UpdateAutomationUseCase
|
|
31
31
|
});
|
|
32
|
-
module.exports = __toCommonJS(
|
|
32
|
+
module.exports = __toCommonJS(update_automation_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_mongo_db = require("../../../common/repositories/mongo-db.repository.js");
|
|
36
36
|
var import_entities = require("../entities");
|
|
37
37
|
var import_repositories = require("../repositories");
|
|
38
|
-
var
|
|
39
|
-
let
|
|
40
|
-
constructor(
|
|
38
|
+
var import_automation_fields = require("../utils/automation-fields");
|
|
39
|
+
let UpdateAutomationUseCase = class extends import_base.BaseUseCase {
|
|
40
|
+
constructor(automationRepository) {
|
|
41
41
|
super();
|
|
42
|
-
this.
|
|
42
|
+
this.automationRepository = automationRepository;
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
automationRepository;
|
|
45
45
|
async execute(params) {
|
|
46
46
|
const { id, payload, currentUser } = params;
|
|
47
|
-
if (!payload || Object.keys(payload).length === 0) throw new Error("Payload is required for updating an
|
|
48
|
-
const existing = await this.
|
|
49
|
-
if (!existing) throw new Error("
|
|
47
|
+
if (!payload || Object.keys(payload).length === 0) throw new Error("Payload is required for updating an automation");
|
|
48
|
+
const existing = await this.automationRepository?.findById(id);
|
|
49
|
+
if (!existing) throw new Error("Automation not found or update failed");
|
|
50
50
|
if (payload.__v !== void 0 && payload.__v !== existing.__v) throw new import_mongo_db.VersionConflictError();
|
|
51
|
-
const changes = (0,
|
|
51
|
+
const changes = (0, import_automation_fields.readAutomationFields)(payload, { complete: false, trigger: existing.trigger });
|
|
52
52
|
const { modelProvider, modelName, ...rest } = changes;
|
|
53
53
|
const provider = modelProvider === void 0 ? existing.modelProvider : modelProvider;
|
|
54
54
|
const name = modelName === void 0 ? existing.modelName : modelName;
|
|
55
|
-
(0,
|
|
56
|
-
const
|
|
55
|
+
(0, import_automation_fields.assertModel)(provider, name);
|
|
56
|
+
const automation = import_entities.Automation.fromJSON({
|
|
57
57
|
...existing,
|
|
58
58
|
...rest,
|
|
59
59
|
modelProvider: provider ?? void 0,
|
|
60
60
|
modelName: name ?? void 0,
|
|
61
61
|
_id: id
|
|
62
62
|
});
|
|
63
|
-
|
|
64
|
-
if (!provider)
|
|
65
|
-
const schedulingChanged = rest.
|
|
66
|
-
const missingNextRun =
|
|
63
|
+
automation.setUpdatedBy(currentUser);
|
|
64
|
+
if (!provider) automation.unset(["modelProvider", "modelName"]);
|
|
65
|
+
const schedulingChanged = rest.trigger !== void 0 || rest.enabled !== void 0;
|
|
66
|
+
const missingNextRun = automation.enabled && automation.isScheduled() && !automation.nextRunAt;
|
|
67
67
|
if (schedulingChanged || missingNextRun) {
|
|
68
|
-
|
|
69
|
-
if (
|
|
68
|
+
automation.scheduleNextRun();
|
|
69
|
+
if (automation.enabled && automation.isScheduled() && !automation.nextRunAt) throw new Error("The date of the recurrence has already passed");
|
|
70
70
|
}
|
|
71
|
-
const result = await this.
|
|
72
|
-
if (!result) throw new Error("
|
|
71
|
+
const result = await this.automationRepository?.update(automation, { expectedVersion: existing.__v });
|
|
72
|
+
if (!result) throw new Error("Automation not found or update failed");
|
|
73
73
|
return { data: result };
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
|
-
|
|
76
|
+
UpdateAutomationUseCase = __decorateClass([
|
|
77
77
|
(0, import_tsyringe.autoInjectable)(),
|
|
78
|
-
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories.
|
|
79
|
-
],
|
|
78
|
+
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories.AutomationRepository))
|
|
79
|
+
], UpdateAutomationUseCase);
|
|
80
80
|
// Annotate the CommonJS export names for ESM import in node:
|
|
81
81
|
0 && (module.exports = {
|
|
82
|
-
|
|
82
|
+
UpdateAutomationUseCase
|
|
83
83
|
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__decorateClass,
|
|
3
|
+
__decorateParam
|
|
4
|
+
} from "../../../chunk-CF3WOMB3.mjs";
|
|
5
|
+
import { autoInjectable, inject } from "tsyringe";
|
|
6
|
+
import { BaseUseCase } from "../../../common/base/base.use-case.js";
|
|
7
|
+
import { VersionConflictError } from "../../../common/repositories/mongo-db.repository.js";
|
|
8
|
+
import { Automation } from "../entities";
|
|
9
|
+
import { AutomationRepository } from "../repositories";
|
|
10
|
+
import { readAutomationFields, assertModel } from "../utils/automation-fields";
|
|
11
|
+
let UpdateAutomationUseCase = class extends BaseUseCase {
|
|
12
|
+
constructor(automationRepository) {
|
|
13
|
+
super();
|
|
14
|
+
this.automationRepository = automationRepository;
|
|
15
|
+
}
|
|
16
|
+
automationRepository;
|
|
17
|
+
async execute(params) {
|
|
18
|
+
const { id, payload, currentUser } = params;
|
|
19
|
+
if (!payload || Object.keys(payload).length === 0) throw new Error("Payload is required for updating an automation");
|
|
20
|
+
const existing = await this.automationRepository?.findById(id);
|
|
21
|
+
if (!existing) throw new Error("Automation not found or update failed");
|
|
22
|
+
if (payload.__v !== void 0 && payload.__v !== existing.__v) throw new VersionConflictError();
|
|
23
|
+
const changes = readAutomationFields(payload, { complete: false, trigger: existing.trigger });
|
|
24
|
+
const { modelProvider, modelName, ...rest } = changes;
|
|
25
|
+
const provider = modelProvider === void 0 ? existing.modelProvider : modelProvider;
|
|
26
|
+
const name = modelName === void 0 ? existing.modelName : modelName;
|
|
27
|
+
assertModel(provider, name);
|
|
28
|
+
const automation = Automation.fromJSON({
|
|
29
|
+
...existing,
|
|
30
|
+
...rest,
|
|
31
|
+
modelProvider: provider ?? void 0,
|
|
32
|
+
modelName: name ?? void 0,
|
|
33
|
+
_id: id
|
|
34
|
+
});
|
|
35
|
+
automation.setUpdatedBy(currentUser);
|
|
36
|
+
if (!provider) automation.unset(["modelProvider", "modelName"]);
|
|
37
|
+
const schedulingChanged = rest.trigger !== void 0 || rest.enabled !== void 0;
|
|
38
|
+
const missingNextRun = automation.enabled && automation.isScheduled() && !automation.nextRunAt;
|
|
39
|
+
if (schedulingChanged || missingNextRun) {
|
|
40
|
+
automation.scheduleNextRun();
|
|
41
|
+
if (automation.enabled && automation.isScheduled() && !automation.nextRunAt) throw new Error("The date of the recurrence has already passed");
|
|
42
|
+
}
|
|
43
|
+
const result = await this.automationRepository?.update(automation, { expectedVersion: existing.__v });
|
|
44
|
+
if (!result) throw new Error("Automation not found or update failed");
|
|
45
|
+
return { data: result };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
UpdateAutomationUseCase = __decorateClass([
|
|
49
|
+
autoInjectable(),
|
|
50
|
+
__decorateParam(0, inject(AutomationRepository))
|
|
51
|
+
], UpdateAutomationUseCase);
|
|
52
|
+
export {
|
|
53
|
+
UpdateAutomationUseCase
|
|
54
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type AutomationEventRejection = 'invalid' | 'expired' | 'revoked' | 'not_found' | 'disabled' | 'payload_too_large';
|
|
2
|
+
export declare class AutomationEventError extends Error {
|
|
3
|
+
readonly reason: AutomationEventRejection;
|
|
4
|
+
readonly statusCode: number;
|
|
5
|
+
constructor(reason: AutomationEventRejection);
|
|
6
|
+
}
|