openloops 0.3.4 → 0.4.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/README.md +9 -8
- package/dist/clients/llm/llm-client.js +6 -5
- package/dist/clients/llm/llm-client.mjs +6 -5
- package/dist/clients/llm/llm-types.d.ts +3 -0
- package/dist/clients/llm/llm-types.js +15 -0
- package/dist/clients/llm/llm-types.mjs +7 -0
- 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/harness/agent-loop.d.ts +2 -0
- package/dist/harness/agent.d.ts +1 -0
- package/dist/harness/agent.js +8 -0
- package/dist/harness/agent.mjs +8 -0
- package/dist/loops/agi/loop.js +2 -1
- package/dist/loops/agi/loop.mjs +2 -1
- package/dist/loops/agi/skills/reasoning-engine.js +3 -2
- package/dist/loops/agi/skills/reasoning-engine.mjs +3 -2
- package/dist/loops/shared/skills/fast-responder.js +2 -2
- package/dist/loops/shared/skills/fast-responder.mjs +2 -2
- 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/authentication/use-cases/is-token-revoked.use-case.js +55 -0
- 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/{agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.d.ts → automations/use-cases/list-automation-runs-by-automation.use-case.d.ts} +7 -7
- package/dist/services/{agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.js → automations/use-cases/list-automation-runs-by-automation.use-case.js} +15 -15
- package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.mjs +28 -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} +7 -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} +14 -14
- package/dist/services/{agentic-jobs/use-cases/list-agentic-job-runs-by-user.use-case.mjs → automations/use-cases/list-automation-runs-by-user.use-case.mjs} +11 -11
- 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} +6 -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} +14 -14
- package/dist/services/{agentic-jobs/use-cases/list-agentic-jobs-by-user.use-case.mjs → automations/use-cases/list-automations-by-user.use-case.mjs} +11 -11
- 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/entities/chat-settings.entity.d.ts +5 -1
- package/dist/services/chats/entities/chat-settings.entity.js +10 -3
- package/dist/services/chats/entities/chat-settings.entity.mjs +10 -3
- package/dist/skills/skill.d.ts +2 -1
- package/dist/skills/skill.js +4 -3
- package/dist/skills/skill.mjs +4 -3
- package/docs/README.md +1 -1
- package/docs/agent.md +3 -2
- package/docs/authentication.md +18 -1
- package/docs/automations.md +341 -0
- package/docs/chats.md +1 -1
- package/docs/configuration.md +8 -7
- 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/docs/skills.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 +14 -13
- 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.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
|
@@ -25,33 +25,33 @@ 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 list_automations_by_user_use_case_exports = {};
|
|
29
|
+
__export(list_automations_by_user_use_case_exports, {
|
|
30
|
+
ListAutomationsByUserUseCase: () => ListAutomationsByUserUseCase
|
|
31
31
|
});
|
|
32
|
-
module.exports = __toCommonJS(
|
|
32
|
+
module.exports = __toCommonJS(list_automations_by_user_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_repositories2 = require("../repositories");
|
|
36
|
-
let
|
|
37
|
-
constructor(
|
|
36
|
+
let ListAutomationsByUserUseCase = class extends import_base.BaseUseCase {
|
|
37
|
+
constructor(automationRepository) {
|
|
38
38
|
super();
|
|
39
|
-
this.
|
|
39
|
+
this.automationRepository = automationRepository;
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
automationRepository;
|
|
42
42
|
async execute(params) {
|
|
43
43
|
const { options, currentUser } = params;
|
|
44
|
-
if (!currentUser?.userId) throw new Error("CurrentUser is required to list the
|
|
44
|
+
if (!currentUser?.userId) throw new Error("CurrentUser is required to list the automations");
|
|
45
45
|
const { page = 1, limit = 10, sortBy = { createdAt: -1 } } = options || {};
|
|
46
|
-
const results = await this.
|
|
46
|
+
const results = await this.automationRepository?.findByOwner(currentUser.userId, { page, limit, sortBy });
|
|
47
47
|
return { data: results ?? [] };
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
|
-
|
|
50
|
+
ListAutomationsByUserUseCase = __decorateClass([
|
|
51
51
|
(0, import_tsyringe.autoInjectable)(),
|
|
52
|
-
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories2.
|
|
53
|
-
],
|
|
52
|
+
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories2.AutomationRepository))
|
|
53
|
+
], ListAutomationsByUserUseCase);
|
|
54
54
|
// Annotate the CommonJS export names for ESM import in node:
|
|
55
55
|
0 && (module.exports = {
|
|
56
|
-
|
|
56
|
+
ListAutomationsByUserUseCase
|
|
57
57
|
});
|
|
@@ -4,25 +4,25 @@ 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
|
-
let
|
|
9
|
-
constructor(
|
|
7
|
+
import { AutomationRepository } from "../repositories";
|
|
8
|
+
let ListAutomationsByUserUseCase = class extends BaseUseCase {
|
|
9
|
+
constructor(automationRepository) {
|
|
10
10
|
super();
|
|
11
|
-
this.
|
|
11
|
+
this.automationRepository = automationRepository;
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
automationRepository;
|
|
14
14
|
async execute(params) {
|
|
15
15
|
const { options, currentUser } = params;
|
|
16
|
-
if (!currentUser?.userId) throw new Error("CurrentUser is required to list the
|
|
16
|
+
if (!currentUser?.userId) throw new Error("CurrentUser is required to list the automations");
|
|
17
17
|
const { page = 1, limit = 10, sortBy = { createdAt: -1 } } = options || {};
|
|
18
|
-
const results = await this.
|
|
18
|
+
const results = await this.automationRepository?.findByOwner(currentUser.userId, { page, limit, sortBy });
|
|
19
19
|
return { data: results ?? [] };
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
|
-
|
|
22
|
+
ListAutomationsByUserUseCase = __decorateClass([
|
|
23
23
|
autoInjectable(),
|
|
24
|
-
__decorateParam(0, inject(
|
|
25
|
-
],
|
|
24
|
+
__decorateParam(0, inject(AutomationRepository))
|
|
25
|
+
], ListAutomationsByUserUseCase);
|
|
26
26
|
export {
|
|
27
|
-
|
|
27
|
+
ListAutomationsByUserUseCase
|
|
28
28
|
};
|
|
@@ -10,6 +10,6 @@ export interface Output extends BaseUseCaseOutput {
|
|
|
10
10
|
runs: Date[];
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
export declare class
|
|
13
|
+
export declare class PreviewAutomationRunsUseCase extends BaseUseCase<Params, Output> {
|
|
14
14
|
execute(params: Params): Promise<Output>;
|
|
15
15
|
}
|
|
@@ -24,17 +24,17 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
24
24
|
if (kind && result) __defProp(target, key, result);
|
|
25
25
|
return result;
|
|
26
26
|
};
|
|
27
|
-
var
|
|
28
|
-
__export(
|
|
29
|
-
|
|
27
|
+
var preview_automation_runs_use_case_exports = {};
|
|
28
|
+
__export(preview_automation_runs_use_case_exports, {
|
|
29
|
+
PreviewAutomationRunsUseCase: () => PreviewAutomationRunsUseCase
|
|
30
30
|
});
|
|
31
|
-
module.exports = __toCommonJS(
|
|
31
|
+
module.exports = __toCommonJS(preview_automation_runs_use_case_exports);
|
|
32
32
|
var import_tsyringe = require("tsyringe");
|
|
33
33
|
var import_base = require("../../../common/base/base.use-case.js");
|
|
34
34
|
var import_entities = require("../entities");
|
|
35
35
|
var import_next_run = require("../utils/next-run");
|
|
36
36
|
const DEFAULT_COUNT = 5;
|
|
37
|
-
let
|
|
37
|
+
let PreviewAutomationRunsUseCase = class extends import_base.BaseUseCase {
|
|
38
38
|
async execute(params) {
|
|
39
39
|
const recurrence = (0, import_entities.validateRecurrence)(params.recurrence);
|
|
40
40
|
const timezone = (0, import_next_run.assertTimezone)(params.timezone);
|
|
@@ -43,10 +43,10 @@ let PreviewAgenticJobRunsUseCase = class extends import_base.BaseUseCase {
|
|
|
43
43
|
return { data: { runs: (0, import_next_run.previewNextRuns)(recurrence, timezone, params.count ?? DEFAULT_COUNT, from) } };
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
|
-
|
|
46
|
+
PreviewAutomationRunsUseCase = __decorateClass([
|
|
47
47
|
(0, import_tsyringe.autoInjectable)()
|
|
48
|
-
],
|
|
48
|
+
], PreviewAutomationRunsUseCase);
|
|
49
49
|
// Annotate the CommonJS export names for ESM import in node:
|
|
50
50
|
0 && (module.exports = {
|
|
51
|
-
|
|
51
|
+
PreviewAutomationRunsUseCase
|
|
52
52
|
});
|
|
@@ -6,7 +6,7 @@ import { BaseUseCase } from "../../../common/base/base.use-case.js";
|
|
|
6
6
|
import { validateRecurrence } from "../entities";
|
|
7
7
|
import { assertTimezone, previewNextRuns } from "../utils/next-run";
|
|
8
8
|
const DEFAULT_COUNT = 5;
|
|
9
|
-
let
|
|
9
|
+
let PreviewAutomationRunsUseCase = class extends BaseUseCase {
|
|
10
10
|
async execute(params) {
|
|
11
11
|
const recurrence = validateRecurrence(params.recurrence);
|
|
12
12
|
const timezone = assertTimezone(params.timezone);
|
|
@@ -15,9 +15,9 @@ let PreviewAgenticJobRunsUseCase = class extends BaseUseCase {
|
|
|
15
15
|
return { data: { runs: previewNextRuns(recurrence, timezone, params.count ?? DEFAULT_COUNT, from) } };
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
PreviewAutomationRunsUseCase = __decorateClass([
|
|
19
19
|
autoInjectable()
|
|
20
|
-
],
|
|
20
|
+
], PreviewAutomationRunsUseCase);
|
|
21
21
|
export {
|
|
22
|
-
|
|
22
|
+
PreviewAutomationRunsUseCase
|
|
23
23
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
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 type AutomationEventStatus = 'queued' | 'duplicate' | 'skipped';
|
|
5
|
+
export interface Params extends BaseUseCaseParams {
|
|
6
|
+
automationId: string;
|
|
7
|
+
token: string;
|
|
8
|
+
payload?: unknown;
|
|
9
|
+
idempotencyKey?: string;
|
|
10
|
+
now?: Date;
|
|
11
|
+
}
|
|
12
|
+
export interface Output extends BaseUseCaseOutput {
|
|
13
|
+
data: {
|
|
14
|
+
status: AutomationEventStatus;
|
|
15
|
+
run: AutomationRunProps;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export declare class ReceiveAutomationEventUseCase extends BaseUseCase<Params, Output> {
|
|
19
|
+
private readonly automationRepository?;
|
|
20
|
+
private readonly automationRunRepository?;
|
|
21
|
+
constructor(automationRepository?: AutomationRepository | undefined, automationRunRepository?: AutomationRunRepository | undefined);
|
|
22
|
+
execute(params: Params): Promise<Output>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
20
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
21
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
22
|
+
if (decorator = decorators[i])
|
|
23
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
24
|
+
if (kind && result) __defProp(target, key, result);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
28
|
+
var receive_automation_event_use_case_exports = {};
|
|
29
|
+
__export(receive_automation_event_use_case_exports, {
|
|
30
|
+
ReceiveAutomationEventUseCase: () => ReceiveAutomationEventUseCase
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(receive_automation_event_use_case_exports);
|
|
33
|
+
var import_tsyringe = require("tsyringe");
|
|
34
|
+
var import_base = require("../../../common/base/base.use-case.js");
|
|
35
|
+
var import_authentication = require("../../authentication/index.js");
|
|
36
|
+
var import_repositories = require("../repositories");
|
|
37
|
+
var import_automation_event_error = require("../utils/automation-event-error");
|
|
38
|
+
var import_event_token = require("../utils/event-token");
|
|
39
|
+
var import_open_run = require("../utils/open-run");
|
|
40
|
+
var import_settings = require("../utils/settings");
|
|
41
|
+
const MAX_PAYLOAD_CHARS = 5e4;
|
|
42
|
+
const MAX_KEY_CHARS = 200;
|
|
43
|
+
const serialize = (payload) => {
|
|
44
|
+
const text = typeof payload === "string" ? payload : JSON.stringify(payload);
|
|
45
|
+
return text || void 0;
|
|
46
|
+
};
|
|
47
|
+
let ReceiveAutomationEventUseCase = class extends import_base.BaseUseCase {
|
|
48
|
+
constructor(automationRepository, automationRunRepository) {
|
|
49
|
+
super();
|
|
50
|
+
this.automationRepository = automationRepository;
|
|
51
|
+
this.automationRunRepository = automationRunRepository;
|
|
52
|
+
}
|
|
53
|
+
automationRepository;
|
|
54
|
+
automationRunRepository;
|
|
55
|
+
async execute(params) {
|
|
56
|
+
const { automationId, token } = params;
|
|
57
|
+
const now = params.now ?? /* @__PURE__ */ new Date();
|
|
58
|
+
const claims = (0, import_event_token.readEventToken)(token);
|
|
59
|
+
if (claims.sub !== automationId) throw new import_automation_event_error.AutomationEventError("invalid");
|
|
60
|
+
const automation = await this.automationRepository.findById(automationId);
|
|
61
|
+
if (!automation) throw new import_automation_event_error.AutomationEventError("not_found");
|
|
62
|
+
if (automation.trigger?.type !== "event" || automation.trigger.tokenVersion !== claims.v) throw new import_automation_event_error.AutomationEventError("invalid");
|
|
63
|
+
if (!automation.enabled) throw new import_automation_event_error.AutomationEventError("disabled");
|
|
64
|
+
const { data: { revoked } } = await (0, import_authentication.isTokenRevoked)({ jti: claims.jti });
|
|
65
|
+
if (revoked) throw new import_automation_event_error.AutomationEventError("revoked");
|
|
66
|
+
const payload = serialize(params.payload);
|
|
67
|
+
if (payload && payload.length > MAX_PAYLOAD_CHARS) throw new import_automation_event_error.AutomationEventError("payload_too_large");
|
|
68
|
+
const idempotencyKey = params.idempotencyKey?.trim() || void 0;
|
|
69
|
+
if (idempotencyKey && idempotencyKey.length > MAX_KEY_CHARS) throw new Error(`The idempotency key cannot be longer than ${MAX_KEY_CHARS} characters`);
|
|
70
|
+
if (idempotencyKey) {
|
|
71
|
+
const duplicate = await this.automationRunRepository.findByIdempotencyKey(automationId, idempotencyKey);
|
|
72
|
+
if (duplicate) return { data: { status: "duplicate", run: duplicate } };
|
|
73
|
+
}
|
|
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
|
+
return { data: { status: "skipped", run: skipped.toJSON() } };
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
const run = await (0, import_open_run.openRun)(this.automationRunRepository, { automation, trigger: "event", status: "queued", now, payload, idempotencyKey });
|
|
80
|
+
return { data: { status: "queued", run: run.toJSON() } };
|
|
81
|
+
} catch (error) {
|
|
82
|
+
if (!idempotencyKey || error?.code !== 11e3) throw error;
|
|
83
|
+
const duplicate = await this.automationRunRepository.findByIdempotencyKey(automationId, idempotencyKey);
|
|
84
|
+
if (!duplicate) throw error;
|
|
85
|
+
return { data: { status: "duplicate", run: duplicate } };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
ReceiveAutomationEventUseCase = __decorateClass([
|
|
90
|
+
(0, import_tsyringe.autoInjectable)(),
|
|
91
|
+
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories.AutomationRepository)),
|
|
92
|
+
__decorateParam(1, (0, import_tsyringe.inject)(import_repositories.AutomationRunRepository))
|
|
93
|
+
], ReceiveAutomationEventUseCase);
|
|
94
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
95
|
+
0 && (module.exports = {
|
|
96
|
+
ReceiveAutomationEventUseCase
|
|
97
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
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 { isTokenRevoked } from "../../authentication/index.js";
|
|
8
|
+
import { AutomationRepository, AutomationRunRepository } from "../repositories";
|
|
9
|
+
import { AutomationEventError } from "../utils/automation-event-error";
|
|
10
|
+
import { readEventToken } from "../utils/event-token";
|
|
11
|
+
import { openRun } from "../utils/open-run";
|
|
12
|
+
import { maxQueuedRuns } from "../utils/settings";
|
|
13
|
+
const MAX_PAYLOAD_CHARS = 5e4;
|
|
14
|
+
const MAX_KEY_CHARS = 200;
|
|
15
|
+
const serialize = (payload) => {
|
|
16
|
+
const text = typeof payload === "string" ? payload : JSON.stringify(payload);
|
|
17
|
+
return text || void 0;
|
|
18
|
+
};
|
|
19
|
+
let ReceiveAutomationEventUseCase = class extends BaseUseCase {
|
|
20
|
+
constructor(automationRepository, automationRunRepository) {
|
|
21
|
+
super();
|
|
22
|
+
this.automationRepository = automationRepository;
|
|
23
|
+
this.automationRunRepository = automationRunRepository;
|
|
24
|
+
}
|
|
25
|
+
automationRepository;
|
|
26
|
+
automationRunRepository;
|
|
27
|
+
async execute(params) {
|
|
28
|
+
const { automationId, token } = params;
|
|
29
|
+
const now = params.now ?? /* @__PURE__ */ new Date();
|
|
30
|
+
const claims = readEventToken(token);
|
|
31
|
+
if (claims.sub !== automationId) throw new AutomationEventError("invalid");
|
|
32
|
+
const automation = await this.automationRepository.findById(automationId);
|
|
33
|
+
if (!automation) throw new AutomationEventError("not_found");
|
|
34
|
+
if (automation.trigger?.type !== "event" || automation.trigger.tokenVersion !== claims.v) throw new AutomationEventError("invalid");
|
|
35
|
+
if (!automation.enabled) throw new AutomationEventError("disabled");
|
|
36
|
+
const { data: { revoked } } = await isTokenRevoked({ jti: claims.jti });
|
|
37
|
+
if (revoked) throw new AutomationEventError("revoked");
|
|
38
|
+
const payload = serialize(params.payload);
|
|
39
|
+
if (payload && payload.length > MAX_PAYLOAD_CHARS) throw new AutomationEventError("payload_too_large");
|
|
40
|
+
const idempotencyKey = params.idempotencyKey?.trim() || void 0;
|
|
41
|
+
if (idempotencyKey && idempotencyKey.length > MAX_KEY_CHARS) throw new Error(`The idempotency key cannot be longer than ${MAX_KEY_CHARS} characters`);
|
|
42
|
+
if (idempotencyKey) {
|
|
43
|
+
const duplicate = await this.automationRunRepository.findByIdempotencyKey(automationId, idempotencyKey);
|
|
44
|
+
if (duplicate) return { data: { status: "duplicate", run: duplicate } };
|
|
45
|
+
}
|
|
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
|
+
return { data: { status: "skipped", run: skipped.toJSON() } };
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const run = await openRun(this.automationRunRepository, { automation, trigger: "event", status: "queued", now, payload, idempotencyKey });
|
|
52
|
+
return { data: { status: "queued", run: run.toJSON() } };
|
|
53
|
+
} catch (error) {
|
|
54
|
+
if (!idempotencyKey || error?.code !== 11e3) throw error;
|
|
55
|
+
const duplicate = await this.automationRunRepository.findByIdempotencyKey(automationId, idempotencyKey);
|
|
56
|
+
if (!duplicate) throw error;
|
|
57
|
+
return { data: { status: "duplicate", run: duplicate } };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
ReceiveAutomationEventUseCase = __decorateClass([
|
|
62
|
+
autoInjectable(),
|
|
63
|
+
__decorateParam(0, inject(AutomationRepository)),
|
|
64
|
+
__decorateParam(1, inject(AutomationRunRepository))
|
|
65
|
+
], ReceiveAutomationEventUseCase);
|
|
66
|
+
export {
|
|
67
|
+
ReceiveAutomationEventUseCase
|
|
68
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseUseCase, BaseUseCaseParams, BaseUseCaseOutput } from '../../../common/base/base.use-case.js';
|
|
2
|
-
import {
|
|
2
|
+
import { AutomationRepository } from '../repositories';
|
|
3
3
|
export interface Params extends BaseUseCaseParams {
|
|
4
|
-
|
|
4
|
+
automationId: string;
|
|
5
5
|
workerId: string;
|
|
6
6
|
leaseMs?: number;
|
|
7
7
|
now?: Date;
|
|
@@ -11,8 +11,8 @@ export interface Output extends BaseUseCaseOutput {
|
|
|
11
11
|
renewed: boolean;
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
-
export declare class
|
|
15
|
-
private readonly
|
|
16
|
-
constructor(
|
|
14
|
+
export declare class RenewAutomationLeaseUseCase extends BaseUseCase<Params, Output> {
|
|
15
|
+
private readonly automationRepository?;
|
|
16
|
+
constructor(automationRepository?: AutomationRepository | undefined);
|
|
17
17
|
execute(params: Params): Promise<Output>;
|
|
18
18
|
}
|
|
@@ -25,34 +25,34 @@ 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 renew_automation_lease_use_case_exports = {};
|
|
29
|
+
__export(renew_automation_lease_use_case_exports, {
|
|
30
|
+
RenewAutomationLeaseUseCase: () => RenewAutomationLeaseUseCase
|
|
31
31
|
});
|
|
32
|
-
module.exports = __toCommonJS(
|
|
32
|
+
module.exports = __toCommonJS(renew_automation_lease_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_settings = require("../utils/settings");
|
|
37
|
-
let
|
|
38
|
-
constructor(
|
|
37
|
+
let RenewAutomationLeaseUseCase = class extends import_base.BaseUseCase {
|
|
38
|
+
constructor(automationRepository) {
|
|
39
39
|
super();
|
|
40
|
-
this.
|
|
40
|
+
this.automationRepository = automationRepository;
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
automationRepository;
|
|
43
43
|
async execute(params) {
|
|
44
|
-
const {
|
|
44
|
+
const { automationId, workerId } = params;
|
|
45
45
|
const now = params.now ?? /* @__PURE__ */ new Date();
|
|
46
46
|
const until = new Date(now.getTime() + (params.leaseMs ?? (0, import_settings.leaseMs)()));
|
|
47
|
-
const
|
|
48
|
-
return { data: { renewed: Boolean(
|
|
47
|
+
const automation = await this.automationRepository.renewLease(automationId, workerId, until);
|
|
48
|
+
return { data: { renewed: Boolean(automation) } };
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
|
|
51
|
+
RenewAutomationLeaseUseCase = __decorateClass([
|
|
52
52
|
(0, import_tsyringe.autoInjectable)(),
|
|
53
|
-
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories.
|
|
54
|
-
],
|
|
53
|
+
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories.AutomationRepository))
|
|
54
|
+
], RenewAutomationLeaseUseCase);
|
|
55
55
|
// Annotate the CommonJS export names for ESM import in node:
|
|
56
56
|
0 && (module.exports = {
|
|
57
|
-
|
|
57
|
+
RenewAutomationLeaseUseCase
|
|
58
58
|
});
|
|
@@ -0,0 +1,29 @@
|
|
|
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 } from "../repositories";
|
|
8
|
+
import { leaseMs as defaultLeaseMs } from "../utils/settings";
|
|
9
|
+
let RenewAutomationLeaseUseCase = class extends BaseUseCase {
|
|
10
|
+
constructor(automationRepository) {
|
|
11
|
+
super();
|
|
12
|
+
this.automationRepository = automationRepository;
|
|
13
|
+
}
|
|
14
|
+
automationRepository;
|
|
15
|
+
async execute(params) {
|
|
16
|
+
const { automationId, workerId } = params;
|
|
17
|
+
const now = params.now ?? /* @__PURE__ */ new Date();
|
|
18
|
+
const until = new Date(now.getTime() + (params.leaseMs ?? defaultLeaseMs()));
|
|
19
|
+
const automation = await this.automationRepository.renewLease(automationId, workerId, until);
|
|
20
|
+
return { data: { renewed: Boolean(automation) } };
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
RenewAutomationLeaseUseCase = __decorateClass([
|
|
24
|
+
autoInjectable(),
|
|
25
|
+
__decorateParam(0, inject(AutomationRepository))
|
|
26
|
+
], RenewAutomationLeaseUseCase);
|
|
27
|
+
export {
|
|
28
|
+
RenewAutomationLeaseUseCase
|
|
29
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseUseCase, BaseUseCaseParams, BaseUseCaseOutput } from '../../../common/base/base.use-case.js';
|
|
2
|
+
import { AutomationRepository } from '../repositories';
|
|
3
|
+
export interface Params extends BaseUseCaseParams {
|
|
4
|
+
id: string;
|
|
5
|
+
token: string;
|
|
6
|
+
}
|
|
7
|
+
export interface Output extends BaseUseCaseOutput {
|
|
8
|
+
data: {
|
|
9
|
+
jti: string;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export declare class RevokeAutomationEventTokenUseCase extends BaseUseCase<Params, Output> {
|
|
13
|
+
private readonly automationRepository?;
|
|
14
|
+
constructor(automationRepository?: AutomationRepository | undefined);
|
|
15
|
+
execute(params: Params): Promise<Output>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
20
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
21
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
22
|
+
if (decorator = decorators[i])
|
|
23
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
24
|
+
if (kind && result) __defProp(target, key, result);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
28
|
+
var revoke_automation_event_token_use_case_exports = {};
|
|
29
|
+
__export(revoke_automation_event_token_use_case_exports, {
|
|
30
|
+
RevokeAutomationEventTokenUseCase: () => RevokeAutomationEventTokenUseCase
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(revoke_automation_event_token_use_case_exports);
|
|
33
|
+
var import_tsyringe = require("tsyringe");
|
|
34
|
+
var import_base = require("../../../common/base/base.use-case.js");
|
|
35
|
+
var import_authentication = require("../../authentication/index.js");
|
|
36
|
+
var import_repositories = require("../repositories");
|
|
37
|
+
var import_event_token = require("../utils/event-token");
|
|
38
|
+
let RevokeAutomationEventTokenUseCase = class extends import_base.BaseUseCase {
|
|
39
|
+
constructor(automationRepository) {
|
|
40
|
+
super();
|
|
41
|
+
this.automationRepository = automationRepository;
|
|
42
|
+
}
|
|
43
|
+
automationRepository;
|
|
44
|
+
async execute(params) {
|
|
45
|
+
const { id, token, currentUser } = params;
|
|
46
|
+
const automation = await this.automationRepository?.findById(id);
|
|
47
|
+
if (!automation) throw new Error("Automation not found");
|
|
48
|
+
if (!currentUser?.isAdmin() && String(automation.ownerId) !== currentUser?.userId) this.throwError403();
|
|
49
|
+
const claims = (0, import_event_token.readEventToken)(token, { ignoreExpiration: true });
|
|
50
|
+
if (claims.sub !== id) throw new Error("The token does not belong to this automation");
|
|
51
|
+
await (0, import_authentication.revokeToken)({
|
|
52
|
+
payload: { jti: claims.jti, audience: import_event_token.EVENT_TOKEN_AUDIENCE, subject: id, expiresAt: claims.exp ? new Date(claims.exp * 1e3) : void 0 },
|
|
53
|
+
currentUser
|
|
54
|
+
});
|
|
55
|
+
return { data: { jti: claims.jti } };
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
RevokeAutomationEventTokenUseCase = __decorateClass([
|
|
59
|
+
(0, import_tsyringe.autoInjectable)(),
|
|
60
|
+
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories.AutomationRepository))
|
|
61
|
+
], RevokeAutomationEventTokenUseCase);
|
|
62
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
+
0 && (module.exports = {
|
|
64
|
+
RevokeAutomationEventTokenUseCase
|
|
65
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
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 { revokeToken } from "../../authentication/index.js";
|
|
8
|
+
import { AutomationRepository } from "../repositories";
|
|
9
|
+
import { EVENT_TOKEN_AUDIENCE, readEventToken } from "../utils/event-token";
|
|
10
|
+
let RevokeAutomationEventTokenUseCase = class extends BaseUseCase {
|
|
11
|
+
constructor(automationRepository) {
|
|
12
|
+
super();
|
|
13
|
+
this.automationRepository = automationRepository;
|
|
14
|
+
}
|
|
15
|
+
automationRepository;
|
|
16
|
+
async execute(params) {
|
|
17
|
+
const { id, token, currentUser } = params;
|
|
18
|
+
const automation = await this.automationRepository?.findById(id);
|
|
19
|
+
if (!automation) throw new Error("Automation not found");
|
|
20
|
+
if (!currentUser?.isAdmin() && String(automation.ownerId) !== currentUser?.userId) this.throwError403();
|
|
21
|
+
const claims = readEventToken(token, { ignoreExpiration: true });
|
|
22
|
+
if (claims.sub !== id) throw new Error("The token does not belong to this automation");
|
|
23
|
+
await revokeToken({
|
|
24
|
+
payload: { jti: claims.jti, audience: EVENT_TOKEN_AUDIENCE, subject: id, expiresAt: claims.exp ? new Date(claims.exp * 1e3) : void 0 },
|
|
25
|
+
currentUser
|
|
26
|
+
});
|
|
27
|
+
return { data: { jti: claims.jti } };
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
RevokeAutomationEventTokenUseCase = __decorateClass([
|
|
31
|
+
autoInjectable(),
|
|
32
|
+
__decorateParam(0, inject(AutomationRepository))
|
|
33
|
+
], RevokeAutomationEventTokenUseCase);
|
|
34
|
+
export {
|
|
35
|
+
RevokeAutomationEventTokenUseCase
|
|
36
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
}
|
|
7
|
+
export interface Output extends BaseUseCaseOutput {
|
|
8
|
+
data: AutomationProps;
|
|
9
|
+
}
|
|
10
|
+
export declare class RotateAutomationEventTokensUseCase extends BaseUseCase<Params, Output> {
|
|
11
|
+
private readonly automationRepository?;
|
|
12
|
+
constructor(automationRepository?: AutomationRepository | undefined);
|
|
13
|
+
execute(params: Params): Promise<Output>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
20
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
21
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
22
|
+
if (decorator = decorators[i])
|
|
23
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
24
|
+
if (kind && result) __defProp(target, key, result);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
28
|
+
var rotate_automation_event_tokens_use_case_exports = {};
|
|
29
|
+
__export(rotate_automation_event_tokens_use_case_exports, {
|
|
30
|
+
RotateAutomationEventTokensUseCase: () => RotateAutomationEventTokensUseCase
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(rotate_automation_event_tokens_use_case_exports);
|
|
33
|
+
var import_tsyringe = require("tsyringe");
|
|
34
|
+
var import_base = require("../../../common/base/base.use-case.js");
|
|
35
|
+
var import_entities = require("../entities");
|
|
36
|
+
var import_repositories = require("../repositories");
|
|
37
|
+
let RotateAutomationEventTokensUseCase = class extends import_base.BaseUseCase {
|
|
38
|
+
constructor(automationRepository) {
|
|
39
|
+
super();
|
|
40
|
+
this.automationRepository = automationRepository;
|
|
41
|
+
}
|
|
42
|
+
automationRepository;
|
|
43
|
+
async execute(params) {
|
|
44
|
+
const { id, currentUser } = params;
|
|
45
|
+
const existing = await this.automationRepository?.findById(id);
|
|
46
|
+
if (!existing) throw new Error("Automation not found");
|
|
47
|
+
if (!currentUser?.isAdmin() && String(existing.ownerId) !== currentUser?.userId) this.throwError403();
|
|
48
|
+
if (existing.trigger?.type !== "event") throw new Error("Only an automation with an event trigger has tokens");
|
|
49
|
+
const automation = import_entities.Automation.fromJSON({ ...existing, trigger: { ...existing.trigger, tokenVersion: existing.trigger.tokenVersion + 1 } });
|
|
50
|
+
automation.setUpdatedBy(currentUser);
|
|
51
|
+
const result = await this.automationRepository?.update(automation, { expectedVersion: existing.__v });
|
|
52
|
+
if (!result) throw new Error("Automation not found or update failed");
|
|
53
|
+
return { data: result };
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
RotateAutomationEventTokensUseCase = __decorateClass([
|
|
57
|
+
(0, import_tsyringe.autoInjectable)(),
|
|
58
|
+
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories.AutomationRepository))
|
|
59
|
+
], RotateAutomationEventTokensUseCase);
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
RotateAutomationEventTokensUseCase
|
|
63
|
+
});
|