@webiny/api-scheduler 0.0.0-unstable.61c048f412
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/LICENSE +21 -0
- package/README.md +11 -0
- package/constants.d.ts +8 -0
- package/constants.js +10 -0
- package/constants.js.map +1 -0
- package/context.d.ts +7 -0
- package/context.js +41 -0
- package/context.js.map +1 -0
- package/createEventHandler.d.ts +13 -0
- package/createEventHandler.js +50 -0
- package/createEventHandler.js.map +1 -0
- package/createScheduler.d.ts +6 -0
- package/createScheduler.js +11 -0
- package/createScheduler.js.map +1 -0
- package/domain/SchedulePrivateModel.d.ts +8 -0
- package/domain/SchedulePrivateModel.js +29 -0
- package/domain/SchedulePrivateModel.js.map +1 -0
- package/domain/ScheduledActionId.d.ts +8 -0
- package/domain/ScheduledActionId.js +9 -0
- package/domain/ScheduledActionId.js.map +1 -0
- package/domain/ScheduledActionIdWithVersion.d.ts +3 -0
- package/domain/ScheduledActionIdWithVersion.js +10 -0
- package/domain/ScheduledActionIdWithVersion.js.map +1 -0
- package/domain/errors.d.ts +37 -0
- package/domain/errors.js +63 -0
- package/domain/errors.js.map +1 -0
- package/domain/isValidDate.d.ts +6 -0
- package/domain/isValidDate.js +13 -0
- package/domain/isValidDate.js.map +1 -0
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.d.ts +26 -0
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.js +74 -0
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.js.map +1 -0
- package/features/CancelScheduledAction/abstractions.d.ts +24 -0
- package/features/CancelScheduledAction/abstractions.js +13 -0
- package/features/CancelScheduledAction/abstractions.js.map +1 -0
- package/features/CancelScheduledAction/feature.d.ts +7 -0
- package/features/CancelScheduledAction/feature.js +17 -0
- package/features/CancelScheduledAction/feature.js.map +1 -0
- package/features/CancelScheduledAction/index.d.ts +1 -0
- package/features/CancelScheduledAction/index.js +3 -0
- package/features/CancelScheduledAction/index.js.map +1 -0
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.d.ts +33 -0
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js +106 -0
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js.map +1 -0
- package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.d.ts +19 -0
- package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.js +32 -0
- package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.js.map +1 -0
- package/features/ExecuteScheduledAction/abstractions.d.ts +46 -0
- package/features/ExecuteScheduledAction/abstractions.js +41 -0
- package/features/ExecuteScheduledAction/abstractions.js.map +1 -0
- package/features/ExecuteScheduledAction/feature.d.ts +7 -0
- package/features/ExecuteScheduledAction/feature.js +19 -0
- package/features/ExecuteScheduledAction/feature.js.map +1 -0
- package/features/ExecuteScheduledAction/index.d.ts +1 -0
- package/features/ExecuteScheduledAction/index.js +3 -0
- package/features/ExecuteScheduledAction/index.js.map +1 -0
- package/features/GetScheduledAction/GetScheduledActionUseCase.d.ts +24 -0
- package/features/GetScheduledAction/GetScheduledActionUseCase.js +49 -0
- package/features/GetScheduledAction/GetScheduledActionUseCase.js.map +1 -0
- package/features/GetScheduledAction/abstractions.d.ts +26 -0
- package/features/GetScheduledAction/abstractions.js +14 -0
- package/features/GetScheduledAction/abstractions.js.map +1 -0
- package/features/GetScheduledAction/feature.d.ts +7 -0
- package/features/GetScheduledAction/feature.js +17 -0
- package/features/GetScheduledAction/feature.js.map +1 -0
- package/features/GetScheduledAction/index.d.ts +1 -0
- package/features/GetScheduledAction/index.js +3 -0
- package/features/GetScheduledAction/index.js.map +1 -0
- package/features/ListScheduledActions/ListScheduledActionsUseCase.d.ts +27 -0
- package/features/ListScheduledActions/ListScheduledActionsUseCase.js +77 -0
- package/features/ListScheduledActions/ListScheduledActionsUseCase.js.map +1 -0
- package/features/ListScheduledActions/abstractions.d.ts +49 -0
- package/features/ListScheduledActions/abstractions.js +15 -0
- package/features/ListScheduledActions/abstractions.js.map +1 -0
- package/features/ListScheduledActions/feature.d.ts +7 -0
- package/features/ListScheduledActions/feature.js +17 -0
- package/features/ListScheduledActions/feature.js.map +1 -0
- package/features/ListScheduledActions/index.d.ts +1 -0
- package/features/ListScheduledActions/index.js +3 -0
- package/features/ListScheduledActions/index.js.map +1 -0
- package/features/RunAction/RunActionUseCase.d.ts +23 -0
- package/features/RunAction/RunActionUseCase.js +37 -0
- package/features/RunAction/RunActionUseCase.js.map +1 -0
- package/features/RunAction/abstractions.d.ts +35 -0
- package/features/RunAction/abstractions.js +15 -0
- package/features/RunAction/abstractions.js.map +1 -0
- package/features/RunAction/feature.d.ts +7 -0
- package/features/RunAction/feature.js +17 -0
- package/features/RunAction/feature.js.map +1 -0
- package/features/RunAction/index.d.ts +1 -0
- package/features/RunAction/index.js +3 -0
- package/features/RunAction/index.js.map +1 -0
- package/features/ScheduleAction/ScheduleActionUseCase.d.ts +45 -0
- package/features/ScheduleAction/ScheduleActionUseCase.js +164 -0
- package/features/ScheduleAction/ScheduleActionUseCase.js.map +1 -0
- package/features/ScheduleAction/abstractions.d.ts +35 -0
- package/features/ScheduleAction/abstractions.js +13 -0
- package/features/ScheduleAction/abstractions.js.map +1 -0
- package/features/ScheduleAction/feature.d.ts +7 -0
- package/features/ScheduleAction/feature.js +17 -0
- package/features/ScheduleAction/feature.js.map +1 -0
- package/features/ScheduleAction/index.d.ts +1 -0
- package/features/ScheduleAction/index.js +3 -0
- package/features/ScheduleAction/index.js.map +1 -0
- package/features/SchedulerFeature.d.ts +8 -0
- package/features/SchedulerFeature.js +29 -0
- package/features/SchedulerFeature.js.map +1 -0
- package/features/SchedulerService/EventBridgeSchedulerService.d.ts +26 -0
- package/features/SchedulerService/EventBridgeSchedulerService.js +131 -0
- package/features/SchedulerService/EventBridgeSchedulerService.js.map +1 -0
- package/features/SchedulerService/VoidSchedulerService.d.ts +15 -0
- package/features/SchedulerService/VoidSchedulerService.js +31 -0
- package/features/SchedulerService/VoidSchedulerService.js.map +1 -0
- package/index.d.ts +10 -0
- package/index.js +13 -0
- package/index.js.map +1 -0
- package/manifest.d.ts +17 -0
- package/manifest.js +39 -0
- package/manifest.js.map +1 -0
- package/package.json +55 -0
- package/shared/abstractions.d.ts +77 -0
- package/shared/abstractions.js +32 -0
- package/shared/abstractions.js.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @webiny/api-scheduler
|
|
2
|
+
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This package is part of the [Webiny](https://www.webiny.com) monorepo.
|
|
5
|
+
> It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
|
|
6
|
+
|
|
7
|
+
📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
_This README file is automatically generated during the publish process._
|
package/constants.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const SCHEDULE_MODEL_ID = "wbySchedule";
|
|
2
|
+
export declare const SCHEDULE_ID_PREFIX = "wby-schedule-";
|
|
3
|
+
/**
|
|
4
|
+
* Minimum number of seconds in the future that a schedule can be set.
|
|
5
|
+
* Everything else will result in immediately running the action.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SCHEDULE_MIN_FUTURE_SECONDS = 65;
|
|
8
|
+
export declare const SCHEDULED_ACTION_EVENT_IDENTIFIER = "WebinyScheduledAction";
|
package/constants.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const SCHEDULE_MODEL_ID = "wbySchedule";
|
|
2
|
+
export const SCHEDULE_ID_PREFIX = "wby-schedule-";
|
|
3
|
+
/**
|
|
4
|
+
* Minimum number of seconds in the future that a schedule can be set.
|
|
5
|
+
* Everything else will result in immediately running the action.
|
|
6
|
+
*/
|
|
7
|
+
export const SCHEDULE_MIN_FUTURE_SECONDS = 65;
|
|
8
|
+
export const SCHEDULED_ACTION_EVENT_IDENTIFIER = "WebinyScheduledAction";
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=constants.js.map
|
package/constants.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["SCHEDULE_MODEL_ID","SCHEDULE_ID_PREFIX","SCHEDULE_MIN_FUTURE_SECONDS","SCHEDULED_ACTION_EVENT_IDENTIFIER"],"sources":["constants.ts"],"sourcesContent":["export const SCHEDULE_MODEL_ID = \"wbySchedule\";\nexport const SCHEDULE_ID_PREFIX = \"wby-schedule-\";\n/**\n * Minimum number of seconds in the future that a schedule can be set.\n * Everything else will result in immediately running the action.\n */\nexport const SCHEDULE_MIN_FUTURE_SECONDS = 65;\n\nexport const SCHEDULED_ACTION_EVENT_IDENTIFIER = \"WebinyScheduledAction\";\n"],"mappings":"AAAA,OAAO,MAAMA,iBAAiB,GAAG,aAAa;AAC9C,OAAO,MAAMC,kBAAkB,GAAG,eAAe;AACjD;AACA;AACA;AACA;AACA,OAAO,MAAMC,2BAA2B,GAAG,EAAE;AAE7C,OAAO,MAAMC,iCAAiC,GAAG,uBAAuB","ignoreList":[]}
|
package/context.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ContextPlugin } from "@webiny/api";
|
|
2
|
+
import type { SchedulerClient, SchedulerClientConfig } from "@webiny/aws-sdk/client-scheduler/index.js";
|
|
3
|
+
import type { CmsContext } from "@webiny/api-headless-cms/types/index.js";
|
|
4
|
+
export interface ICreateHeadlessCmsSchedulerContextParams {
|
|
5
|
+
getClient(config?: SchedulerClientConfig): Pick<SchedulerClient, "send">;
|
|
6
|
+
}
|
|
7
|
+
export declare const createSchedulerContext: (params: ICreateHeadlessCmsSchedulerContextParams) => ContextPlugin<CmsContext>;
|
package/context.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ContextPlugin } from "@webiny/api";
|
|
2
|
+
import { getManifest } from "./manifest.js";
|
|
3
|
+
import { SCHEDULE_MODEL_ID } from "./constants.js";
|
|
4
|
+
import { ScheduledActionModel, SchedulerService } from "./shared/abstractions.js";
|
|
5
|
+
import { EventBridgeSchedulerService } from "./features/SchedulerService/EventBridgeSchedulerService.js";
|
|
6
|
+
import { VoidSchedulerService } from "./features/SchedulerService/VoidSchedulerService.js";
|
|
7
|
+
import { SchedulePrivateModel } from "./domain/SchedulePrivateModel.js";
|
|
8
|
+
import { SchedulerFeature } from "./features/SchedulerFeature.js";
|
|
9
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
10
|
+
import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel/index.js";
|
|
11
|
+
export const createSchedulerContext = params => {
|
|
12
|
+
return new ContextPlugin(async context => {
|
|
13
|
+
const tenantContext = context.container.resolve(TenantContext);
|
|
14
|
+
const getModel = context.container.resolve(GetModelUseCase);
|
|
15
|
+
if (!tenantContext.getTenant()) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const manifest = await getManifest({
|
|
19
|
+
client: context.db.driver.getClient()
|
|
20
|
+
});
|
|
21
|
+
if (manifest.error) {
|
|
22
|
+
context.container.registerInstance(SchedulerService, new VoidSchedulerService());
|
|
23
|
+
} else {
|
|
24
|
+
// TODO: in the future, extract AWS specific implementation into a separate package
|
|
25
|
+
context.container.registerInstance(SchedulerService, new EventBridgeSchedulerService(params.getClient, {
|
|
26
|
+
lambdaArn: manifest.data.lambdaArn,
|
|
27
|
+
roleArn: manifest.data.roleArn
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
context.container.register(SchedulePrivateModel);
|
|
31
|
+
await context.security.withoutAuthorization(async () => {
|
|
32
|
+
const schedulerModel = await getModel.execute(SCHEDULE_MODEL_ID);
|
|
33
|
+
context.container.registerInstance(ScheduledActionModel, schedulerModel.value);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Register all features
|
|
37
|
+
SchedulerFeature.register(context.container);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=context.js.map
|
package/context.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ContextPlugin","getManifest","SCHEDULE_MODEL_ID","ScheduledActionModel","SchedulerService","EventBridgeSchedulerService","VoidSchedulerService","SchedulePrivateModel","SchedulerFeature","TenantContext","GetModelUseCase","createSchedulerContext","params","context","tenantContext","container","resolve","getModel","getTenant","manifest","client","db","driver","getClient","error","registerInstance","lambdaArn","data","roleArn","register","security","withoutAuthorization","schedulerModel","execute","value"],"sources":["context.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport type {\n SchedulerClient,\n SchedulerClientConfig\n} from \"@webiny/aws-sdk/client-scheduler/index.js\";\nimport { getManifest } from \"~/manifest.js\";\nimport type { CmsContext } from \"@webiny/api-headless-cms/types/index.js\";\nimport { SCHEDULE_MODEL_ID } from \"./constants.js\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { ScheduledActionModel, SchedulerService } from \"~/shared/abstractions.js\";\nimport { EventBridgeSchedulerService } from \"~/features/SchedulerService/EventBridgeSchedulerService.js\";\nimport { VoidSchedulerService } from \"~/features/SchedulerService/VoidSchedulerService.js\";\nimport { SchedulePrivateModel } from \"~/domain/SchedulePrivateModel.js\";\nimport { SchedulerFeature } from \"./features/SchedulerFeature.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\n\nexport interface ICreateHeadlessCmsSchedulerContextParams {\n getClient(config?: SchedulerClientConfig): Pick<SchedulerClient, \"send\">;\n}\n\nexport const createSchedulerContext = (params: ICreateHeadlessCmsSchedulerContextParams) => {\n return new ContextPlugin<CmsContext>(async context => {\n const tenantContext = context.container.resolve(TenantContext);\n const getModel = context.container.resolve(GetModelUseCase);\n\n if (!tenantContext.getTenant()) {\n return;\n }\n\n const manifest = await getManifest({\n client: context.db.driver.getClient() as DynamoDBDocument\n });\n\n if (manifest.error) {\n context.container.registerInstance(SchedulerService, new VoidSchedulerService());\n } else {\n // TODO: in the future, extract AWS specific implementation into a separate package\n context.container.registerInstance(\n SchedulerService,\n new EventBridgeSchedulerService(params.getClient, {\n lambdaArn: manifest.data.lambdaArn,\n roleArn: manifest.data.roleArn\n })\n );\n }\n\n context.container.register(SchedulePrivateModel);\n\n await context.security.withoutAuthorization(async () => {\n const schedulerModel = await getModel.execute(SCHEDULE_MODEL_ID);\n context.container.registerInstance(ScheduledActionModel, schedulerModel.value);\n });\n\n // Register all features\n SchedulerFeature.register(context.container);\n });\n};\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,aAAa;AAK3C,SAASC,WAAW;AAEpB,SAASC,iBAAiB;AAE1B,SAASC,oBAAoB,EAAEC,gBAAgB;AAC/C,SAASC,2BAA2B;AACpC,SAASC,oBAAoB;AAC7B,SAASC,oBAAoB;AAC7B,SAASC,gBAAgB;AACzB,SAASC,aAAa,QAAQ,0DAA0D;AACxF,SAASC,eAAe,QAAQ,kEAAkE;AAMlG,OAAO,MAAMC,sBAAsB,GAAIC,MAAgD,IAAK;EACxF,OAAO,IAAIZ,aAAa,CAAa,MAAMa,OAAO,IAAI;IAClD,MAAMC,aAAa,GAAGD,OAAO,CAACE,SAAS,CAACC,OAAO,CAACP,aAAa,CAAC;IAC9D,MAAMQ,QAAQ,GAAGJ,OAAO,CAACE,SAAS,CAACC,OAAO,CAACN,eAAe,CAAC;IAE3D,IAAI,CAACI,aAAa,CAACI,SAAS,CAAC,CAAC,EAAE;MAC5B;IACJ;IAEA,MAAMC,QAAQ,GAAG,MAAMlB,WAAW,CAAC;MAC/BmB,MAAM,EAAEP,OAAO,CAACQ,EAAE,CAACC,MAAM,CAACC,SAAS,CAAC;IACxC,CAAC,CAAC;IAEF,IAAIJ,QAAQ,CAACK,KAAK,EAAE;MAChBX,OAAO,CAACE,SAAS,CAACU,gBAAgB,CAACrB,gBAAgB,EAAE,IAAIE,oBAAoB,CAAC,CAAC,CAAC;IACpF,CAAC,MAAM;MACH;MACAO,OAAO,CAACE,SAAS,CAACU,gBAAgB,CAC9BrB,gBAAgB,EAChB,IAAIC,2BAA2B,CAACO,MAAM,CAACW,SAAS,EAAE;QAC9CG,SAAS,EAAEP,QAAQ,CAACQ,IAAI,CAACD,SAAS;QAClCE,OAAO,EAAET,QAAQ,CAACQ,IAAI,CAACC;MAC3B,CAAC,CACL,CAAC;IACL;IAEAf,OAAO,CAACE,SAAS,CAACc,QAAQ,CAACtB,oBAAoB,CAAC;IAEhD,MAAMM,OAAO,CAACiB,QAAQ,CAACC,oBAAoB,CAAC,YAAY;MACpD,MAAMC,cAAc,GAAG,MAAMf,QAAQ,CAACgB,OAAO,CAAC/B,iBAAiB,CAAC;MAChEW,OAAO,CAACE,SAAS,CAACU,gBAAgB,CAACtB,oBAAoB,EAAE6B,cAAc,CAACE,KAAK,CAAC;IAClF,CAAC,CAAC;;IAEF;IACA1B,gBAAgB,CAACqB,QAAQ,CAAChB,OAAO,CAACE,SAAS,CAAC;EAChD,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HandlerFactoryParams } from "@webiny/handler-aws/types.js";
|
|
2
|
+
import { SCHEDULED_ACTION_EVENT_IDENTIFIER } from "./constants.js";
|
|
3
|
+
export interface IScheduledActionEventPayload {
|
|
4
|
+
id: string;
|
|
5
|
+
scheduleFor: string;
|
|
6
|
+
}
|
|
7
|
+
export interface IScheduledActionEvent {
|
|
8
|
+
[SCHEDULED_ACTION_EVENT_IDENTIFIER]: IScheduledActionEventPayload;
|
|
9
|
+
}
|
|
10
|
+
export interface HandlerParams extends HandlerFactoryParams {
|
|
11
|
+
debug?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare const createScheduledActionEventHandler: () => import("@webiny/handler-aws/raw/index.js").RawEventHandler<IScheduledActionEvent, import("@webiny/handler/types").Context, any>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { registry } from "@webiny/handler-aws/registry.js";
|
|
2
|
+
import { createSourceHandler } from "@webiny/handler-aws/sourceHandler.js";
|
|
3
|
+
import { createEventHandler, createHandler } from "@webiny/handler-aws/raw/index.js";
|
|
4
|
+
import { SCHEDULED_ACTION_EVENT_IDENTIFIER } from "./constants.js";
|
|
5
|
+
import { ExecuteScheduledActionUseCase } from "./features/ExecuteScheduledAction/index.js";
|
|
6
|
+
const canHandle = event => {
|
|
7
|
+
if (typeof event?.hasOwnProperty !== "function") {
|
|
8
|
+
return false;
|
|
9
|
+
} else if (!event.hasOwnProperty(SCHEDULED_ACTION_EVENT_IDENTIFIER)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const value = event[SCHEDULED_ACTION_EVENT_IDENTIFIER];
|
|
13
|
+
return !!(value?.id && value?.scheduleFor);
|
|
14
|
+
};
|
|
15
|
+
const handler = createSourceHandler({
|
|
16
|
+
name: "handler-aws-event-bridge-scheduled-cms-action-event",
|
|
17
|
+
canUse: canHandle,
|
|
18
|
+
handle: async ({
|
|
19
|
+
params,
|
|
20
|
+
event,
|
|
21
|
+
context
|
|
22
|
+
}) => {
|
|
23
|
+
return createHandler(params)(event, context);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
registry.register(handler);
|
|
27
|
+
export const createScheduledActionEventHandler = () => {
|
|
28
|
+
return createEventHandler({
|
|
29
|
+
canHandle,
|
|
30
|
+
handle: async params => {
|
|
31
|
+
const {
|
|
32
|
+
payload,
|
|
33
|
+
context
|
|
34
|
+
} = params;
|
|
35
|
+
const input = payload[SCHEDULED_ACTION_EVENT_IDENTIFIER];
|
|
36
|
+
const executeScheduledAction = context.container.resolve(ExecuteScheduledActionUseCase);
|
|
37
|
+
const result = await executeScheduledAction.execute(input.id);
|
|
38
|
+
if (result.isFail()) {
|
|
39
|
+
const error = result.error;
|
|
40
|
+
console.error(error.code, error.message);
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
success: true
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=createEventHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["registry","createSourceHandler","createEventHandler","createHandler","SCHEDULED_ACTION_EVENT_IDENTIFIER","ExecuteScheduledActionUseCase","canHandle","event","hasOwnProperty","value","id","scheduleFor","handler","name","canUse","handle","params","context","register","createScheduledActionEventHandler","payload","input","executeScheduledAction","container","resolve","result","execute","isFail","error","console","code","message","success"],"sources":["createEventHandler.ts"],"sourcesContent":["import { registry } from \"@webiny/handler-aws/registry.js\";\nimport type { HandlerFactoryParams } from \"@webiny/handler-aws/types.js\";\nimport { createSourceHandler } from \"@webiny/handler-aws/sourceHandler.js\";\nimport { createEventHandler, createHandler } from \"@webiny/handler-aws/raw/index.js\";\nimport { SCHEDULED_ACTION_EVENT_IDENTIFIER } from \"~/constants.js\";\nimport { ExecuteScheduledActionUseCase } from \"~/features/ExecuteScheduledAction/index.js\";\n\nexport interface IScheduledActionEventPayload {\n id: string;\n scheduleFor: string;\n}\n\nexport interface IScheduledActionEvent {\n [SCHEDULED_ACTION_EVENT_IDENTIFIER]: IScheduledActionEventPayload;\n}\n\nexport interface HandlerParams extends HandlerFactoryParams {\n debug?: boolean;\n}\n\nconst canHandle = (event: Partial<IScheduledActionEvent>): boolean => {\n if (typeof event?.hasOwnProperty !== \"function\") {\n return false;\n } else if (!event.hasOwnProperty(SCHEDULED_ACTION_EVENT_IDENTIFIER)) {\n return false;\n }\n\n const value = event[SCHEDULED_ACTION_EVENT_IDENTIFIER];\n return !!(value?.id && value?.scheduleFor);\n};\n\nconst handler = createSourceHandler<IScheduledActionEvent, HandlerParams>({\n name: \"handler-aws-event-bridge-scheduled-cms-action-event\",\n canUse: canHandle,\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n\nexport const createScheduledActionEventHandler = () => {\n return createEventHandler<IScheduledActionEvent>({\n canHandle,\n handle: async params => {\n const { payload, context } = params;\n const input = payload[SCHEDULED_ACTION_EVENT_IDENTIFIER];\n\n const executeScheduledAction = context.container.resolve(ExecuteScheduledActionUseCase);\n const result = await executeScheduledAction.execute(input.id);\n\n if (result.isFail()) {\n const error = result.error;\n console.error(error.code, error.message);\n throw error;\n }\n return {\n success: true\n };\n }\n });\n};\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,iCAAiC;AAE1D,SAASC,mBAAmB,QAAQ,sCAAsC;AAC1E,SAASC,kBAAkB,EAAEC,aAAa,QAAQ,kCAAkC;AACpF,SAASC,iCAAiC;AAC1C,SAASC,6BAA6B;AAetC,MAAMC,SAAS,GAAIC,KAAqC,IAAc;EAClE,IAAI,OAAOA,KAAK,EAAEC,cAAc,KAAK,UAAU,EAAE;IAC7C,OAAO,KAAK;EAChB,CAAC,MAAM,IAAI,CAACD,KAAK,CAACC,cAAc,CAACJ,iCAAiC,CAAC,EAAE;IACjE,OAAO,KAAK;EAChB;EAEA,MAAMK,KAAK,GAAGF,KAAK,CAACH,iCAAiC,CAAC;EACtD,OAAO,CAAC,EAAEK,KAAK,EAAEC,EAAE,IAAID,KAAK,EAAEE,WAAW,CAAC;AAC9C,CAAC;AAED,MAAMC,OAAO,GAAGX,mBAAmB,CAAuC;EACtEY,IAAI,EAAE,qDAAqD;EAC3DC,MAAM,EAAER,SAAS;EACjBS,MAAM,EAAE,MAAAA,CAAO;IAAEC,MAAM;IAAET,KAAK;IAAEU;EAAQ,CAAC,KAAK;IAC1C,OAAOd,aAAa,CAACa,MAAM,CAAC,CAACT,KAAK,EAAEU,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFjB,QAAQ,CAACkB,QAAQ,CAACN,OAAO,CAAC;AAE1B,OAAO,MAAMO,iCAAiC,GAAGA,CAAA,KAAM;EACnD,OAAOjB,kBAAkB,CAAwB;IAC7CI,SAAS;IACTS,MAAM,EAAE,MAAMC,MAAM,IAAI;MACpB,MAAM;QAAEI,OAAO;QAAEH;MAAQ,CAAC,GAAGD,MAAM;MACnC,MAAMK,KAAK,GAAGD,OAAO,CAAChB,iCAAiC,CAAC;MAExD,MAAMkB,sBAAsB,GAAGL,OAAO,CAACM,SAAS,CAACC,OAAO,CAACnB,6BAA6B,CAAC;MACvF,MAAMoB,MAAM,GAAG,MAAMH,sBAAsB,CAACI,OAAO,CAACL,KAAK,CAACX,EAAE,CAAC;MAE7D,IAAIe,MAAM,CAACE,MAAM,CAAC,CAAC,EAAE;QACjB,MAAMC,KAAK,GAAGH,MAAM,CAACG,KAAK;QAC1BC,OAAO,CAACD,KAAK,CAACA,KAAK,CAACE,IAAI,EAAEF,KAAK,CAACG,OAAO,CAAC;QACxC,MAAMH,KAAK;MACf;MACA,OAAO;QACHI,OAAO,EAAE;MACb,CAAC;IACL;EACJ,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Plugin } from "@webiny/plugins/types.js";
|
|
2
|
+
import { SchedulerClient, SchedulerClientConfig } from "@webiny/aws-sdk/client-scheduler";
|
|
3
|
+
export interface ICreateSchedulerParams {
|
|
4
|
+
getClient(config?: SchedulerClientConfig): Pick<SchedulerClient, "send">;
|
|
5
|
+
}
|
|
6
|
+
export declare const createScheduler: (params: ICreateSchedulerParams) => Plugin[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createSchedulerContext } from "./context.js";
|
|
2
|
+
import { createScheduledActionEventHandler } from "./createEventHandler.js";
|
|
3
|
+
export const createScheduler = params => {
|
|
4
|
+
return [
|
|
5
|
+
/**
|
|
6
|
+
* Handler for the Scheduled Action Event.
|
|
7
|
+
*/
|
|
8
|
+
createScheduledActionEventHandler(), createSchedulerContext(params)];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=createScheduler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createSchedulerContext","createScheduledActionEventHandler","createScheduler","params"],"sources":["createScheduler.ts"],"sourcesContent":["import type { Plugin } from \"@webiny/plugins/types.js\";\nimport { SchedulerClient, SchedulerClientConfig } from \"@webiny/aws-sdk/client-scheduler\";\nimport { createSchedulerContext } from \"~/context.js\";\nimport { createScheduledActionEventHandler } from \"~/createEventHandler.js\";\n\nexport interface ICreateSchedulerParams {\n getClient(config?: SchedulerClientConfig): Pick<SchedulerClient, \"send\">;\n}\nexport const createScheduler = (params: ICreateSchedulerParams): Plugin[] => {\n return [\n /**\n * Handler for the Scheduled Action Event.\n */\n createScheduledActionEventHandler(),\n createSchedulerContext(params)\n ];\n};\n"],"mappings":"AAEA,SAASA,sBAAsB;AAC/B,SAASC,iCAAiC;AAK1C,OAAO,MAAMC,eAAe,GAAIC,MAA8B,IAAe;EACzE,OAAO;EACH;AACR;AACA;EACQF,iCAAiC,CAAC,CAAC,EACnCD,sBAAsB,CAACG,MAAM,CAAC,CACjC;AACL,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ModelFactory } from "@webiny/api-headless-cms/features/modelBuilder/index.js";
|
|
2
|
+
declare class SchedulePrivateModelImpl implements ModelFactory.Interface {
|
|
3
|
+
execute(builder: ModelFactory.Builder): Promise<import("@webiny/api-headless-cms/features/modelBuilder/index.js").PrivateModelBuilder[]>;
|
|
4
|
+
}
|
|
5
|
+
export declare const SchedulePrivateModel: typeof SchedulePrivateModelImpl & {
|
|
6
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-headless-cms/features/modelBuilder/abstractions").IModelFactory>;
|
|
7
|
+
};
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ModelFactory } from "@webiny/api-headless-cms/features/modelBuilder/index.js";
|
|
2
|
+
import { SCHEDULE_MODEL_ID } from "../constants.js";
|
|
3
|
+
class SchedulePrivateModelImpl {
|
|
4
|
+
async execute(builder) {
|
|
5
|
+
return [builder.private({
|
|
6
|
+
modelId: SCHEDULE_MODEL_ID,
|
|
7
|
+
name: "Webiny CMS Schedule"
|
|
8
|
+
}).fields(fields => ({
|
|
9
|
+
namespace: fields.text().label("Namespace"),
|
|
10
|
+
actionType: fields.text().label("Action Type"),
|
|
11
|
+
targetId: fields.text().label("Target ID"),
|
|
12
|
+
scheduledBy: fields.object().label("Scheduled By").fields(fields => ({
|
|
13
|
+
id: fields.text().label("Identity ID"),
|
|
14
|
+
displayName: fields.text().label("Display Name"),
|
|
15
|
+
type: fields.text().label("Type")
|
|
16
|
+
})),
|
|
17
|
+
scheduledFor: fields.datetime().label("Scheduled For"),
|
|
18
|
+
title: fields.text().label("Title"),
|
|
19
|
+
error: fields.text().label("Error"),
|
|
20
|
+
payload: fields.json().label("Payload")
|
|
21
|
+
}))];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export const SchedulePrivateModel = ModelFactory.createImplementation({
|
|
25
|
+
implementation: SchedulePrivateModelImpl,
|
|
26
|
+
dependencies: []
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=SchedulePrivateModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ModelFactory","SCHEDULE_MODEL_ID","SchedulePrivateModelImpl","execute","builder","private","modelId","name","fields","namespace","text","label","actionType","targetId","scheduledBy","object","id","displayName","type","scheduledFor","datetime","title","error","payload","json","SchedulePrivateModel","createImplementation","implementation","dependencies"],"sources":["SchedulePrivateModel.ts"],"sourcesContent":["import { ModelFactory } from \"@webiny/api-headless-cms/features/modelBuilder/index.js\";\nimport { SCHEDULE_MODEL_ID } from \"~/constants.js\";\n\nclass SchedulePrivateModelImpl implements ModelFactory.Interface {\n public async execute(builder: ModelFactory.Builder) {\n return [\n builder\n .private({\n modelId: SCHEDULE_MODEL_ID,\n name: \"Webiny CMS Schedule\"\n })\n .fields(fields => ({\n namespace: fields.text().label(\"Namespace\"),\n actionType: fields.text().label(\"Action Type\"),\n targetId: fields.text().label(\"Target ID\"),\n scheduledBy: fields\n .object()\n .label(\"Scheduled By\")\n .fields(fields => ({\n id: fields.text().label(\"Identity ID\"),\n displayName: fields.text().label(\"Display Name\"),\n type: fields.text().label(\"Type\")\n })),\n scheduledFor: fields.datetime().label(\"Scheduled For\"),\n title: fields.text().label(\"Title\"),\n error: fields.text().label(\"Error\"),\n payload: fields.json().label(\"Payload\")\n }))\n ];\n }\n}\n\nexport const SchedulePrivateModel = ModelFactory.createImplementation({\n implementation: SchedulePrivateModelImpl,\n dependencies: []\n});\n"],"mappings":"AAAA,SAASA,YAAY,QAAQ,yDAAyD;AACtF,SAASC,iBAAiB;AAE1B,MAAMC,wBAAwB,CAAmC;EAC7D,MAAaC,OAAOA,CAACC,OAA6B,EAAE;IAChD,OAAO,CACHA,OAAO,CACFC,OAAO,CAAC;MACLC,OAAO,EAAEL,iBAAiB;MAC1BM,IAAI,EAAE;IACV,CAAC,CAAC,CACDC,MAAM,CAACA,MAAM,KAAK;MACfC,SAAS,EAAED,MAAM,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,WAAW,CAAC;MAC3CC,UAAU,EAAEJ,MAAM,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,aAAa,CAAC;MAC9CE,QAAQ,EAAEL,MAAM,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,WAAW,CAAC;MAC1CG,WAAW,EAAEN,MAAM,CACdO,MAAM,CAAC,CAAC,CACRJ,KAAK,CAAC,cAAc,CAAC,CACrBH,MAAM,CAACA,MAAM,KAAK;QACfQ,EAAE,EAAER,MAAM,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,aAAa,CAAC;QACtCM,WAAW,EAAET,MAAM,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,cAAc,CAAC;QAChDO,IAAI,EAAEV,MAAM,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,MAAM;MACpC,CAAC,CAAC,CAAC;MACPQ,YAAY,EAAEX,MAAM,CAACY,QAAQ,CAAC,CAAC,CAACT,KAAK,CAAC,eAAe,CAAC;MACtDU,KAAK,EAAEb,MAAM,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,OAAO,CAAC;MACnCW,KAAK,EAAEd,MAAM,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,OAAO,CAAC;MACnCY,OAAO,EAAEf,MAAM,CAACgB,IAAI,CAAC,CAAC,CAACb,KAAK,CAAC,SAAS;IAC1C,CAAC,CAAC,CAAC,CACV;EACL;AACJ;AAEA,OAAO,MAAMc,oBAAoB,GAAGzB,YAAY,CAAC0B,oBAAoB,CAAC;EAClEC,cAAc,EAAEzB,wBAAwB;EACxC0B,YAAY,EAAE;AAClB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createCacheKey } from "@webiny/utils";
|
|
2
|
+
import { SCHEDULE_ID_PREFIX } from "../constants.js";
|
|
3
|
+
export class ScheduledActionId {
|
|
4
|
+
static from(params) {
|
|
5
|
+
return [SCHEDULE_ID_PREFIX, createCacheKey([params.namespace, params.actionType, params.targetId]).slice(-24)].join("");
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=ScheduledActionId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createCacheKey","SCHEDULE_ID_PREFIX","ScheduledActionId","from","params","namespace","actionType","targetId","slice","join"],"sources":["ScheduledActionId.ts"],"sourcesContent":["import { createCacheKey } from \"@webiny/utils\";\nimport { SCHEDULE_ID_PREFIX } from \"~/constants.js\";\n\nexport interface IScheduledActionIdParams {\n namespace: string;\n actionType: string;\n targetId: string;\n}\n\nexport class ScheduledActionId {\n static from(params: IScheduledActionIdParams) {\n return [\n SCHEDULE_ID_PREFIX,\n createCacheKey([params.namespace, params.actionType, params.targetId]).slice(-24)\n ].join(\"\");\n }\n}\n"],"mappings":"AAAA,SAASA,cAAc,QAAQ,eAAe;AAC9C,SAASC,kBAAkB;AAQ3B,OAAO,MAAMC,iBAAiB,CAAC;EAC3B,OAAOC,IAAIA,CAACC,MAAgC,EAAE;IAC1C,OAAO,CACHH,kBAAkB,EAClBD,cAAc,CAAC,CAACI,MAAM,CAACC,SAAS,EAAED,MAAM,CAACE,UAAU,EAAEF,MAAM,CAACG,QAAQ,CAAC,CAAC,CAACC,KAAK,CAAC,CAAC,EAAE,CAAC,CACpF,CAACC,IAAI,CAAC,EAAE,CAAC;EACd;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ScheduledActionIdWithVersion","from","id","endsWith"],"sources":["ScheduledActionIdWithVersion.ts"],"sourcesContent":["export class ScheduledActionIdWithVersion {\n static from(id: string) {\n if (id.endsWith(\"#0001\")) {\n return id;\n }\n\n return `${id}#0001`;\n }\n}\n"],"mappings":"AAAA,OAAO,MAAMA,4BAA4B,CAAC;EACtC,OAAOC,IAAIA,CAACC,EAAU,EAAE;IACpB,IAAIA,EAAE,CAACC,QAAQ,CAAC,OAAO,CAAC,EAAE;MACtB,OAAOD,EAAE;IACb;IAEA,OAAO,GAAGA,EAAE,OAAO;EACvB;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { BaseError } from "@webiny/feature/api";
|
|
2
|
+
/**
|
|
3
|
+
* Scheduled action not found error
|
|
4
|
+
*/
|
|
5
|
+
export declare class ScheduledActionNotFoundError extends BaseError<{
|
|
6
|
+
scheduleId: string;
|
|
7
|
+
}> {
|
|
8
|
+
readonly code: "Scheduler/ScheduledAction/NotFound";
|
|
9
|
+
constructor(scheduleId: string);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Storage/persistence error when working with scheduled actions
|
|
13
|
+
*/
|
|
14
|
+
export declare class ScheduledActionPersistenceError extends BaseError<{
|
|
15
|
+
originalError: Error;
|
|
16
|
+
}> {
|
|
17
|
+
readonly code: "Scheduler/ScheduledAction/PersistenceError";
|
|
18
|
+
constructor(error: Error);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Invalid schedule date error (e.g., scheduling in the past)
|
|
22
|
+
*/
|
|
23
|
+
export declare class InvalidScheduleDateError extends BaseError<{
|
|
24
|
+
scheduleFor: string;
|
|
25
|
+
}> {
|
|
26
|
+
readonly code: "Scheduler/ScheduledAction/InvalidDate";
|
|
27
|
+
constructor(scheduleFor: string);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Scheduler service error (EventBridge/cloud provider errors)
|
|
31
|
+
*/
|
|
32
|
+
export declare class SchedulerServiceError extends BaseError<{
|
|
33
|
+
originalError: Error;
|
|
34
|
+
}> {
|
|
35
|
+
readonly code: "Scheduler/Service/Error";
|
|
36
|
+
constructor(error: Error);
|
|
37
|
+
}
|
package/domain/errors.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { BaseError } from "@webiny/feature/api";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Scheduled action not found error
|
|
5
|
+
*/
|
|
6
|
+
export class ScheduledActionNotFoundError extends BaseError {
|
|
7
|
+
code = "Scheduler/ScheduledAction/NotFound";
|
|
8
|
+
constructor(scheduleId) {
|
|
9
|
+
super({
|
|
10
|
+
message: `Scheduled action "${scheduleId}" was not found.`,
|
|
11
|
+
data: {
|
|
12
|
+
scheduleId
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Storage/persistence error when working with scheduled actions
|
|
20
|
+
*/
|
|
21
|
+
export class ScheduledActionPersistenceError extends BaseError {
|
|
22
|
+
code = "Scheduler/ScheduledAction/PersistenceError";
|
|
23
|
+
constructor(error) {
|
|
24
|
+
super({
|
|
25
|
+
message: error.message,
|
|
26
|
+
data: {
|
|
27
|
+
originalError: error
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Invalid schedule date error (e.g., scheduling in the past)
|
|
35
|
+
*/
|
|
36
|
+
export class InvalidScheduleDateError extends BaseError {
|
|
37
|
+
code = "Scheduler/ScheduledAction/InvalidDate";
|
|
38
|
+
constructor(scheduleFor) {
|
|
39
|
+
super({
|
|
40
|
+
message: "Cannot schedule in the past",
|
|
41
|
+
data: {
|
|
42
|
+
scheduleFor
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Scheduler service error (EventBridge/cloud provider errors)
|
|
50
|
+
*/
|
|
51
|
+
export class SchedulerServiceError extends BaseError {
|
|
52
|
+
code = "Scheduler/Service/Error";
|
|
53
|
+
constructor(error) {
|
|
54
|
+
super({
|
|
55
|
+
message: `Scheduler service error: ${error.message}`,
|
|
56
|
+
data: {
|
|
57
|
+
originalError: error
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["BaseError","ScheduledActionNotFoundError","code","constructor","scheduleId","message","data","ScheduledActionPersistenceError","error","originalError","InvalidScheduleDateError","scheduleFor","SchedulerServiceError"],"sources":["errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\n\n/**\n * Scheduled action not found error\n */\nexport class ScheduledActionNotFoundError extends BaseError<{ scheduleId: string }> {\n override readonly code = \"Scheduler/ScheduledAction/NotFound\" as const;\n\n constructor(scheduleId: string) {\n super({\n message: `Scheduled action \"${scheduleId}\" was not found.`,\n data: {\n scheduleId\n }\n });\n }\n}\n\n/**\n * Storage/persistence error when working with scheduled actions\n */\nexport class ScheduledActionPersistenceError extends BaseError<{ originalError: Error }> {\n override readonly code = \"Scheduler/ScheduledAction/PersistenceError\" as const;\n\n constructor(error: Error) {\n super({\n message: error.message,\n data: { originalError: error }\n });\n }\n}\n\n/**\n * Invalid schedule date error (e.g., scheduling in the past)\n */\nexport class InvalidScheduleDateError extends BaseError<{ scheduleFor: string }> {\n override readonly code = \"Scheduler/ScheduledAction/InvalidDate\" as const;\n\n constructor(scheduleFor: string) {\n super({\n message: \"Cannot schedule in the past\",\n data: { scheduleFor }\n });\n }\n}\n\n/**\n * Scheduler service error (EventBridge/cloud provider errors)\n */\nexport class SchedulerServiceError extends BaseError<{ originalError: Error }> {\n override readonly code = \"Scheduler/Service/Error\" as const;\n\n constructor(error: Error) {\n super({\n message: `Scheduler service error: ${error.message}`,\n data: { originalError: error }\n });\n }\n}\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,qBAAqB;;AAE/C;AACA;AACA;AACA,OAAO,MAAMC,4BAA4B,SAASD,SAAS,CAAyB;EAC9DE,IAAI,GAAG,oCAAoC;EAE7DC,WAAWA,CAACC,UAAkB,EAAE;IAC5B,KAAK,CAAC;MACFC,OAAO,EAAE,qBAAqBD,UAAU,kBAAkB;MAC1DE,IAAI,EAAE;QACFF;MACJ;IACJ,CAAC,CAAC;EACN;AACJ;;AAEA;AACA;AACA;AACA,OAAO,MAAMG,+BAA+B,SAASP,SAAS,CAA2B;EACnEE,IAAI,GAAG,4CAA4C;EAErEC,WAAWA,CAACK,KAAY,EAAE;IACtB,KAAK,CAAC;MACFH,OAAO,EAAEG,KAAK,CAACH,OAAO;MACtBC,IAAI,EAAE;QAAEG,aAAa,EAAED;MAAM;IACjC,CAAC,CAAC;EACN;AACJ;;AAEA;AACA;AACA;AACA,OAAO,MAAME,wBAAwB,SAASV,SAAS,CAA0B;EAC3DE,IAAI,GAAG,uCAAuC;EAEhEC,WAAWA,CAACQ,WAAmB,EAAE;IAC7B,KAAK,CAAC;MACFN,OAAO,EAAE,6BAA6B;MACtCC,IAAI,EAAE;QAAEK;MAAY;IACxB,CAAC,CAAC;EACN;AACJ;;AAEA;AACA;AACA;AACA,OAAO,MAAMC,qBAAqB,SAASZ,SAAS,CAA2B;EACzDE,IAAI,GAAG,yBAAyB;EAElDC,WAAWA,CAACK,KAAY,EAAE;IACtB,KAAK,CAAC;MACFH,OAAO,EAAE,4BAA4BG,KAAK,CAACH,OAAO,EAAE;MACpDC,IAAI,EAAE;QAAEG,aAAa,EAAED;MAAM;IACjC,CAAC,CAAC;EACN;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if the provided date is in the future.
|
|
3
|
+
* We need to ensure that the date is at least a SCHEDULE_MIN_FUTURE_MINUTES minutes in the future.
|
|
4
|
+
* Otherwise, we consider it as "immediate" and run the action right away.
|
|
5
|
+
*/
|
|
6
|
+
export declare const isValidDate: (date: string) => boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SCHEDULE_MIN_FUTURE_SECONDS } from "../constants.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Check if the provided date is in the future.
|
|
5
|
+
* We need to ensure that the date is at least a SCHEDULE_MIN_FUTURE_MINUTES minutes in the future.
|
|
6
|
+
* Otherwise, we consider it as "immediate" and run the action right away.
|
|
7
|
+
*/
|
|
8
|
+
export const isValidDate = date => {
|
|
9
|
+
const minDate = new Date(Date.now() + SCHEDULE_MIN_FUTURE_SECONDS * 1000);
|
|
10
|
+
return new Date(date).getTime() >= minDate.getTime();
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=isValidDate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["SCHEDULE_MIN_FUTURE_SECONDS","isValidDate","date","minDate","Date","now","getTime"],"sources":["isValidDate.ts"],"sourcesContent":["import { SCHEDULE_MIN_FUTURE_SECONDS } from \"~/constants.js\";\n\n/**\n * Check if the provided date is in the future.\n * We need to ensure that the date is at least a SCHEDULE_MIN_FUTURE_MINUTES minutes in the future.\n * Otherwise, we consider it as \"immediate\" and run the action right away.\n */\nexport const isValidDate = (date: string): boolean => {\n const minDate = new Date(Date.now() + SCHEDULE_MIN_FUTURE_SECONDS * 1000);\n\n return new Date(date).getTime() >= minDate.getTime();\n};\n"],"mappings":"AAAA,SAASA,2BAA2B;;AAEpC;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,WAAW,GAAIC,IAAY,IAAc;EAClD,MAAMC,OAAO,GAAG,IAAIC,IAAI,CAACA,IAAI,CAACC,GAAG,CAAC,CAAC,GAAGL,2BAA2B,GAAG,IAAI,CAAC;EAEzE,OAAO,IAAII,IAAI,CAACF,IAAI,CAAC,CAACI,OAAO,CAAC,CAAC,IAAIH,OAAO,CAACG,OAAO,CAAC,CAAC;AACxD,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { CancelScheduledActionUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
3
|
+
import { GetScheduledActionUseCase } from "../../features/GetScheduledAction/abstractions.js";
|
|
4
|
+
import { ScheduledActionModel, SchedulerService } from "../../shared/abstractions.js";
|
|
5
|
+
import { DeleteEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Cancels a scheduled action
|
|
8
|
+
*
|
|
9
|
+
* Flow:
|
|
10
|
+
* 1. Check if schedule exists
|
|
11
|
+
* 2. Delete EventBridge schedule
|
|
12
|
+
* 3. Delete CMS entry
|
|
13
|
+
* 4. If EventBridge delete fails, continue anyway (schedule might already be executed/deleted)
|
|
14
|
+
*/
|
|
15
|
+
declare class CancelScheduledActionUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
16
|
+
private getScheduledActionUseCase;
|
|
17
|
+
private schedulerService;
|
|
18
|
+
private deleteEntryUseCase;
|
|
19
|
+
private model;
|
|
20
|
+
constructor(getScheduledActionUseCase: GetScheduledActionUseCase.Interface, schedulerService: SchedulerService.Interface, deleteEntryUseCase: DeleteEntryUseCase.Interface, model: ScheduledActionModel.Interface);
|
|
21
|
+
execute(id: string): Promise<Result<void, UseCaseAbstraction.Error>>;
|
|
22
|
+
}
|
|
23
|
+
export declare const CancelScheduledActionUseCase: typeof CancelScheduledActionUseCaseImpl & {
|
|
24
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ICancelScheduledActionUseCase>;
|
|
25
|
+
};
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { CancelScheduledActionUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
3
|
+
import { GetScheduledActionUseCase } from "../GetScheduledAction/abstractions.js";
|
|
4
|
+
import { ScheduledActionModel, SchedulerService } from "../../shared/abstractions.js";
|
|
5
|
+
import { ScheduledActionNotFoundError, ScheduledActionPersistenceError } from "../../domain/errors.js";
|
|
6
|
+
import { DeleteEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js";
|
|
7
|
+
import { ScheduledActionIdWithVersion } from "../../domain/ScheduledActionIdWithVersion.js";
|
|
8
|
+
import { EntryNotFoundError } from "@webiny/api-headless-cms/domain/contentEntry/errors.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Cancels a scheduled action
|
|
12
|
+
*
|
|
13
|
+
* Flow:
|
|
14
|
+
* 1. Check if schedule exists
|
|
15
|
+
* 2. Delete EventBridge schedule
|
|
16
|
+
* 3. Delete CMS entry
|
|
17
|
+
* 4. If EventBridge delete fails, continue anyway (schedule might already be executed/deleted)
|
|
18
|
+
*/
|
|
19
|
+
class CancelScheduledActionUseCaseImpl {
|
|
20
|
+
constructor(getScheduledActionUseCase, schedulerService, deleteEntryUseCase, model) {
|
|
21
|
+
this.getScheduledActionUseCase = getScheduledActionUseCase;
|
|
22
|
+
this.schedulerService = schedulerService;
|
|
23
|
+
this.deleteEntryUseCase = deleteEntryUseCase;
|
|
24
|
+
this.model = model;
|
|
25
|
+
}
|
|
26
|
+
async execute(id) {
|
|
27
|
+
// Check if scheduled action exists
|
|
28
|
+
const getResult = await this.getScheduledActionUseCase.execute(id);
|
|
29
|
+
if (getResult.isFail()) {
|
|
30
|
+
const error = getResult.error;
|
|
31
|
+
if (error.code === "Scheduler/ScheduledAction/NotFound") {
|
|
32
|
+
return Result.fail(new ScheduledActionNotFoundError(id));
|
|
33
|
+
}
|
|
34
|
+
return Result.fail(error);
|
|
35
|
+
}
|
|
36
|
+
const scheduleId = ScheduledActionIdWithVersion.from(id);
|
|
37
|
+
|
|
38
|
+
// Delete EventBridge schedule
|
|
39
|
+
// Note: We continue even if this fails, as the schedule might already be executed/deleted
|
|
40
|
+
try {
|
|
41
|
+
const eventBridgeSchedule = await this.schedulerService.exists(id);
|
|
42
|
+
/**
|
|
43
|
+
* No point to even try deleting if it doesn't exist.
|
|
44
|
+
*/
|
|
45
|
+
if (eventBridgeSchedule) {
|
|
46
|
+
await this.schedulerService.delete(id);
|
|
47
|
+
}
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.warn(`Failed to delete EventBridge schedule: ${scheduleId}. Continuing with CMS entry deletion.`, error);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Delete CMS entry
|
|
53
|
+
const deleteResult = await this.deleteEntryUseCase.execute(this.model, scheduleId, {
|
|
54
|
+
force: true,
|
|
55
|
+
permanently: true
|
|
56
|
+
});
|
|
57
|
+
if (deleteResult.isFail()) {
|
|
58
|
+
/**
|
|
59
|
+
* Some process could have already deleted the entry, in which case we can safely ignore this error.
|
|
60
|
+
*/
|
|
61
|
+
if (deleteResult.error instanceof EntryNotFoundError) {
|
|
62
|
+
return Result.ok();
|
|
63
|
+
}
|
|
64
|
+
return Result.fail(new ScheduledActionPersistenceError(new Error(deleteResult.error.message)));
|
|
65
|
+
}
|
|
66
|
+
return Result.ok();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export const CancelScheduledActionUseCase = UseCaseAbstraction.createImplementation({
|
|
70
|
+
implementation: CancelScheduledActionUseCaseImpl,
|
|
71
|
+
dependencies: [GetScheduledActionUseCase, SchedulerService, DeleteEntryUseCase, ScheduledActionModel]
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=CancelScheduledActionUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Result","CancelScheduledActionUseCase","UseCaseAbstraction","GetScheduledActionUseCase","ScheduledActionModel","SchedulerService","ScheduledActionNotFoundError","ScheduledActionPersistenceError","DeleteEntryUseCase","ScheduledActionIdWithVersion","EntryNotFoundError","CancelScheduledActionUseCaseImpl","constructor","getScheduledActionUseCase","schedulerService","deleteEntryUseCase","model","execute","id","getResult","isFail","error","code","fail","scheduleId","from","eventBridgeSchedule","exists","delete","console","warn","deleteResult","force","permanently","ok","Error","message","createImplementation","implementation","dependencies"],"sources":["CancelScheduledActionUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { CancelScheduledActionUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { GetScheduledActionUseCase } from \"~/features/GetScheduledAction/abstractions.js\";\nimport { ScheduledActionModel, SchedulerService } from \"~/shared/abstractions.js\";\nimport { ScheduledActionNotFoundError, ScheduledActionPersistenceError } from \"~/domain/errors.js\";\nimport { DeleteEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js\";\nimport { ScheduledActionIdWithVersion } from \"~/domain/ScheduledActionIdWithVersion.js\";\nimport { EntryNotFoundError } from \"@webiny/api-headless-cms/domain/contentEntry/errors.js\";\n\n/**\n * Cancels a scheduled action\n *\n * Flow:\n * 1. Check if schedule exists\n * 2. Delete EventBridge schedule\n * 3. Delete CMS entry\n * 4. If EventBridge delete fails, continue anyway (schedule might already be executed/deleted)\n */\nclass CancelScheduledActionUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private getScheduledActionUseCase: GetScheduledActionUseCase.Interface,\n private schedulerService: SchedulerService.Interface,\n private deleteEntryUseCase: DeleteEntryUseCase.Interface,\n private model: ScheduledActionModel.Interface\n ) {}\n\n async execute(id: string): Promise<Result<void, UseCaseAbstraction.Error>> {\n // Check if scheduled action exists\n const getResult = await this.getScheduledActionUseCase.execute(id);\n\n if (getResult.isFail()) {\n const error = getResult.error;\n\n if (error.code === \"Scheduler/ScheduledAction/NotFound\") {\n return Result.fail(new ScheduledActionNotFoundError(id));\n }\n\n return Result.fail(error);\n }\n\n const scheduleId = ScheduledActionIdWithVersion.from(id);\n\n // Delete EventBridge schedule\n // Note: We continue even if this fails, as the schedule might already be executed/deleted\n try {\n const eventBridgeSchedule = await this.schedulerService.exists(id);\n /**\n * No point to even try deleting if it doesn't exist.\n */\n if (eventBridgeSchedule) {\n await this.schedulerService.delete(id);\n }\n } catch (error) {\n console.warn(\n `Failed to delete EventBridge schedule: ${scheduleId}. Continuing with CMS entry deletion.`,\n error\n );\n }\n\n // Delete CMS entry\n const deleteResult = await this.deleteEntryUseCase.execute(this.model, scheduleId, {\n force: true,\n permanently: true\n });\n\n if (deleteResult.isFail()) {\n /**\n * Some process could have already deleted the entry, in which case we can safely ignore this error.\n */\n if (deleteResult.error instanceof EntryNotFoundError) {\n return Result.ok();\n }\n return Result.fail(\n new ScheduledActionPersistenceError(new Error(deleteResult.error.message))\n );\n }\n\n return Result.ok();\n }\n}\n\nexport const CancelScheduledActionUseCase = UseCaseAbstraction.createImplementation({\n implementation: CancelScheduledActionUseCaseImpl,\n dependencies: [\n GetScheduledActionUseCase,\n SchedulerService,\n DeleteEntryUseCase,\n ScheduledActionModel\n ]\n});\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;AAC5C,SAASC,4BAA4B,IAAIC,kBAAkB;AAC3D,SAASC,yBAAyB;AAClC,SAASC,oBAAoB,EAAEC,gBAAgB;AAC/C,SAASC,4BAA4B,EAAEC,+BAA+B;AACtE,SAASC,kBAAkB,QAAQ,qEAAqE;AACxG,SAASC,4BAA4B;AACrC,SAASC,kBAAkB,QAAQ,wDAAwD;;AAE3F;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,gCAAgC,CAAyC;EAC3EC,WAAWA,CACCC,yBAA8D,EAC9DC,gBAA4C,EAC5CC,kBAAgD,EAChDC,KAAqC,EAC/C;IAAA,KAJUH,yBAA8D,GAA9DA,yBAA8D;IAAA,KAC9DC,gBAA4C,GAA5CA,gBAA4C;IAAA,KAC5CC,kBAAgD,GAAhDA,kBAAgD;IAAA,KAChDC,KAAqC,GAArCA,KAAqC;EAC9C;EAEH,MAAMC,OAAOA,CAACC,EAAU,EAAmD;IACvE;IACA,MAAMC,SAAS,GAAG,MAAM,IAAI,CAACN,yBAAyB,CAACI,OAAO,CAACC,EAAE,CAAC;IAElE,IAAIC,SAAS,CAACC,MAAM,CAAC,CAAC,EAAE;MACpB,MAAMC,KAAK,GAAGF,SAAS,CAACE,KAAK;MAE7B,IAAIA,KAAK,CAACC,IAAI,KAAK,oCAAoC,EAAE;QACrD,OAAOtB,MAAM,CAACuB,IAAI,CAAC,IAAIjB,4BAA4B,CAACY,EAAE,CAAC,CAAC;MAC5D;MAEA,OAAOlB,MAAM,CAACuB,IAAI,CAACF,KAAK,CAAC;IAC7B;IAEA,MAAMG,UAAU,GAAGf,4BAA4B,CAACgB,IAAI,CAACP,EAAE,CAAC;;IAExD;IACA;IACA,IAAI;MACA,MAAMQ,mBAAmB,GAAG,MAAM,IAAI,CAACZ,gBAAgB,CAACa,MAAM,CAACT,EAAE,CAAC;MAClE;AACZ;AACA;MACY,IAAIQ,mBAAmB,EAAE;QACrB,MAAM,IAAI,CAACZ,gBAAgB,CAACc,MAAM,CAACV,EAAE,CAAC;MAC1C;IACJ,CAAC,CAAC,OAAOG,KAAK,EAAE;MACZQ,OAAO,CAACC,IAAI,CACR,0CAA0CN,UAAU,uCAAuC,EAC3FH,KACJ,CAAC;IACL;;IAEA;IACA,MAAMU,YAAY,GAAG,MAAM,IAAI,CAAChB,kBAAkB,CAACE,OAAO,CAAC,IAAI,CAACD,KAAK,EAAEQ,UAAU,EAAE;MAC/EQ,KAAK,EAAE,IAAI;MACXC,WAAW,EAAE;IACjB,CAAC,CAAC;IAEF,IAAIF,YAAY,CAACX,MAAM,CAAC,CAAC,EAAE;MACvB;AACZ;AACA;MACY,IAAIW,YAAY,CAACV,KAAK,YAAYX,kBAAkB,EAAE;QAClD,OAAOV,MAAM,CAACkC,EAAE,CAAC,CAAC;MACtB;MACA,OAAOlC,MAAM,CAACuB,IAAI,CACd,IAAIhB,+BAA+B,CAAC,IAAI4B,KAAK,CAACJ,YAAY,CAACV,KAAK,CAACe,OAAO,CAAC,CAC7E,CAAC;IACL;IAEA,OAAOpC,MAAM,CAACkC,EAAE,CAAC,CAAC;EACtB;AACJ;AAEA,OAAO,MAAMjC,4BAA4B,GAAGC,kBAAkB,CAACmC,oBAAoB,CAAC;EAChFC,cAAc,EAAE3B,gCAAgC;EAChD4B,YAAY,EAAE,CACVpC,yBAAyB,EACzBE,gBAAgB,EAChBG,kBAAkB,EAClBJ,oBAAoB;AAE5B,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { ScheduledActionNotFoundError, ScheduledActionPersistenceError, SchedulerServiceError } from "../../domain/errors.js";
|
|
3
|
+
/**
|
|
4
|
+
* CancelScheduledActionUseCase - Cancel a scheduled action
|
|
5
|
+
*
|
|
6
|
+
* Cancels both the CMS entry and the EventBridge schedule.
|
|
7
|
+
* Used when a user manually cancels a scheduled action or when business logic
|
|
8
|
+
* determines the action should no longer execute.
|
|
9
|
+
*/
|
|
10
|
+
export interface ICancelScheduledActionErrors {
|
|
11
|
+
notFound: ScheduledActionNotFoundError;
|
|
12
|
+
persistence: ScheduledActionPersistenceError;
|
|
13
|
+
schedulerService: SchedulerServiceError;
|
|
14
|
+
}
|
|
15
|
+
type CancelScheduledActionError = ICancelScheduledActionErrors[keyof ICancelScheduledActionErrors];
|
|
16
|
+
export interface ICancelScheduledActionUseCase {
|
|
17
|
+
execute(scheduleId: string): Promise<Result<void, CancelScheduledActionError>>;
|
|
18
|
+
}
|
|
19
|
+
export declare const CancelScheduledActionUseCase: import("@webiny/di").Abstraction<ICancelScheduledActionUseCase>;
|
|
20
|
+
export declare namespace CancelScheduledActionUseCase {
|
|
21
|
+
type Interface = ICancelScheduledActionUseCase;
|
|
22
|
+
type Error = CancelScheduledActionError;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* CancelScheduledActionUseCase - Cancel a scheduled action
|
|
5
|
+
*
|
|
6
|
+
* Cancels both the CMS entry and the EventBridge schedule.
|
|
7
|
+
* Used when a user manually cancels a scheduled action or when business logic
|
|
8
|
+
* determines the action should no longer execute.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export const CancelScheduledActionUseCase = createAbstraction("CancelScheduledActionUseCase");
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=abstractions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createAbstraction","CancelScheduledActionUseCase"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport {\n ScheduledActionNotFoundError,\n ScheduledActionPersistenceError,\n SchedulerServiceError\n} from \"~/domain/errors.js\";\n\n/**\n * CancelScheduledActionUseCase - Cancel a scheduled action\n *\n * Cancels both the CMS entry and the EventBridge schedule.\n * Used when a user manually cancels a scheduled action or when business logic\n * determines the action should no longer execute.\n */\n\nexport interface ICancelScheduledActionErrors {\n notFound: ScheduledActionNotFoundError;\n persistence: ScheduledActionPersistenceError;\n schedulerService: SchedulerServiceError;\n}\n\ntype CancelScheduledActionError = ICancelScheduledActionErrors[keyof ICancelScheduledActionErrors];\n\nexport interface ICancelScheduledActionUseCase {\n execute(scheduleId: string): Promise<Result<void, CancelScheduledActionError>>;\n}\n\nexport const CancelScheduledActionUseCase = createAbstraction<ICancelScheduledActionUseCase>(\n \"CancelScheduledActionUseCase\"\n);\n\nexport namespace CancelScheduledActionUseCase {\n export type Interface = ICancelScheduledActionUseCase;\n export type Error = CancelScheduledActionError;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;;AAQvD;AACA;AACA;AACA;AACA;AACA;AACA;;AAcA,OAAO,MAAMC,4BAA4B,GAAGD,iBAAiB,CACzD,8BACJ,CAAC","ignoreList":[]}
|