@webiny/api-scheduler 0.0.0-unstable.0156a4c312
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/ScheduledActionLambdaHandler.d.ts +18 -0
- package/ScheduledActionLambdaHandler.js +41 -0
- package/ScheduledActionLambdaHandler.js.map +1 -0
- package/SchedulerFeature.d.ts +5 -0
- package/SchedulerFeature.js +21 -0
- package/SchedulerFeature.js.map +1 -0
- package/constants.d.ts +13 -0
- package/constants.js +13 -0
- package/constants.js.map +1 -0
- package/domain/SchedulePrivateModel.d.ts +8 -0
- package/domain/SchedulePrivateModel.js +33 -0
- package/domain/SchedulePrivateModel.js.map +1 -0
- package/domain/ScheduledActionId.d.ts +8 -0
- package/domain/ScheduledActionId.js +17 -0
- package/domain/ScheduledActionId.js.map +1 -0
- package/domain/ScheduledActionIdWithVersion.d.ts +3 -0
- package/domain/ScheduledActionIdWithVersion.js +9 -0
- package/domain/ScheduledActionIdWithVersion.js.map +1 -0
- package/domain/ScheduledActionMapper.d.ts +16 -0
- package/domain/ScheduledActionMapper.js +42 -0
- package/domain/ScheduledActionMapper.js.map +1 -0
- package/domain/errors.d.ts +55 -0
- package/domain/errors.js +61 -0
- package/domain/errors.js.map +1 -0
- package/domain/isValidDate.d.ts +6 -0
- package/domain/isValidDate.js +8 -0
- package/domain/isValidDate.js.map +1 -0
- package/exports/api/scheduler.d.ts +10 -0
- package/exports/api/scheduler.js +8 -0
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.d.ts +28 -0
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.js +59 -0
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.js.map +1 -0
- package/features/CancelScheduledAction/abstractions.d.ts +32 -0
- package/features/CancelScheduledAction/abstractions.js +5 -0
- package/features/CancelScheduledAction/abstractions.js.map +1 -0
- package/features/CancelScheduledAction/feature.d.ts +10 -0
- package/features/CancelScheduledAction/feature.js +11 -0
- package/features/CancelScheduledAction/feature.js.map +1 -0
- package/features/CancelScheduledAction/index.d.ts +1 -0
- package/features/CancelScheduledAction/index.js +1 -0
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.d.ts +33 -0
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js +91 -0
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js.map +1 -0
- package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.d.ts +19 -0
- package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.js +28 -0
- package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.js.map +1 -0
- package/features/ExecuteScheduledAction/abstractions.d.ts +54 -0
- package/features/ExecuteScheduledAction/abstractions.js +17 -0
- package/features/ExecuteScheduledAction/abstractions.js.map +1 -0
- package/features/ExecuteScheduledAction/feature.d.ts +10 -0
- package/features/ExecuteScheduledAction/feature.js +13 -0
- package/features/ExecuteScheduledAction/feature.js.map +1 -0
- package/features/ExecuteScheduledAction/index.d.ts +1 -0
- package/features/ExecuteScheduledAction/index.js +1 -0
- package/features/GetScheduledAction/GetScheduledActionUseCase.d.ts +28 -0
- package/features/GetScheduledAction/GetScheduledActionUseCase.js +49 -0
- package/features/GetScheduledAction/GetScheduledActionUseCase.js.map +1 -0
- package/features/GetScheduledAction/abstractions.d.ts +33 -0
- package/features/GetScheduledAction/abstractions.js +5 -0
- package/features/GetScheduledAction/abstractions.js.map +1 -0
- package/features/GetScheduledAction/feature.d.ts +10 -0
- package/features/GetScheduledAction/feature.js +11 -0
- package/features/GetScheduledAction/feature.js.map +1 -0
- package/features/GetScheduledAction/index.d.ts +1 -0
- package/features/GetScheduledAction/index.js +1 -0
- package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.d.ts +32 -0
- package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.js +65 -0
- package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.js.map +1 -0
- package/features/GetTargetScheduledAction/abstractions.d.ts +24 -0
- package/features/GetTargetScheduledAction/abstractions.js +5 -0
- package/features/GetTargetScheduledAction/abstractions.js.map +1 -0
- package/features/GetTargetScheduledAction/feature.d.ts +10 -0
- package/features/GetTargetScheduledAction/feature.js +11 -0
- package/features/GetTargetScheduledAction/feature.js.map +1 -0
- package/features/GetTargetScheduledAction/index.d.ts +1 -0
- package/features/GetTargetScheduledAction/index.js +1 -0
- package/features/ListScheduledActions/ListScheduledActionsUseCase.d.ts +31 -0
- package/features/ListScheduledActions/ListScheduledActionsUseCase.js +65 -0
- package/features/ListScheduledActions/ListScheduledActionsUseCase.js.map +1 -0
- package/features/ListScheduledActions/abstractions.d.ts +57 -0
- package/features/ListScheduledActions/abstractions.js +5 -0
- package/features/ListScheduledActions/abstractions.js.map +1 -0
- package/features/ListScheduledActions/feature.d.ts +10 -0
- package/features/ListScheduledActions/feature.js +11 -0
- package/features/ListScheduledActions/feature.js.map +1 -0
- package/features/ListScheduledActions/index.d.ts +1 -0
- package/features/ListScheduledActions/index.js +1 -0
- package/features/NamespaceHandler/NamespaceHandlerExecutioner.d.ts +11 -0
- package/features/NamespaceHandler/NamespaceHandlerExecutioner.js +26 -0
- package/features/NamespaceHandler/NamespaceHandlerExecutioner.js.map +1 -0
- package/features/NamespaceHandler/abstractions.d.ts +50 -0
- package/features/NamespaceHandler/abstractions.js +6 -0
- package/features/NamespaceHandler/abstractions.js.map +1 -0
- package/features/NamespaceHandler/feature.d.ts +4 -0
- package/features/NamespaceHandler/feature.js +11 -0
- package/features/NamespaceHandler/feature.js.map +1 -0
- package/features/NamespaceHandler/index.d.ts +1 -0
- package/features/NamespaceHandler/index.js +1 -0
- package/features/ScheduleAction/ScheduleActionUseCase.d.ts +45 -0
- package/features/ScheduleAction/ScheduleActionUseCase.js +175 -0
- package/features/ScheduleAction/ScheduleActionUseCase.js.map +1 -0
- package/features/ScheduleAction/abstractions.d.ts +36 -0
- package/features/ScheduleAction/abstractions.js +5 -0
- package/features/ScheduleAction/abstractions.js.map +1 -0
- package/features/ScheduleAction/feature.d.ts +10 -0
- package/features/ScheduleAction/feature.js +11 -0
- package/features/ScheduleAction/feature.js.map +1 -0
- package/features/ScheduleAction/index.d.ts +1 -0
- package/features/ScheduleAction/index.js +1 -0
- package/features/ScheduledActionModelProvider.d.ts +26 -0
- package/features/ScheduledActionModelProvider.js +22 -0
- package/features/ScheduledActionModelProvider.js.map +1 -0
- package/features/SchedulerFeature.d.ts +11 -0
- package/features/SchedulerFeature.js +21 -0
- package/features/SchedulerFeature.js.map +1 -0
- package/features/SchedulerService/VoidSchedulerService.d.ts +15 -0
- package/features/SchedulerService/VoidSchedulerService.js +24 -0
- package/features/SchedulerService/VoidSchedulerService.js.map +1 -0
- package/features/permissions/SchedulerPermissionsResolver.d.ts +12 -0
- package/features/permissions/SchedulerPermissionsResolver.js +42 -0
- package/features/permissions/SchedulerPermissionsResolver.js.map +1 -0
- package/features/permissions/abstractions.d.ts +20 -0
- package/features/permissions/abstractions.js +6 -0
- package/features/permissions/abstractions.js.map +1 -0
- package/graphql/SchedulerGraphQLFactory.d.ts +9 -0
- package/graphql/SchedulerGraphQLFactory.js +223 -0
- package/graphql/SchedulerGraphQLFactory.js.map +1 -0
- package/graphql/feature.d.ts +4 -0
- package/graphql/feature.js +11 -0
- package/graphql/feature.js.map +1 -0
- package/graphql/index.d.ts +1 -0
- package/graphql/index.js +1 -0
- package/index.d.ts +5 -0
- package/index.js +4 -0
- package/package.json +43 -0
- package/shared/abstractions.d.ts +113 -0
- package/shared/abstractions.js +7 -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._
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ScheduledActionEventHandler } from "@webiny/event-handler-core";
|
|
2
|
+
import type { IScheduledActionEvent } from "@webiny/event-handler-core";
|
|
3
|
+
import type { IScheduledActionResult } from "@webiny/event-handler-core";
|
|
4
|
+
import type { EventContext, NextFunction } from "@webiny/event-handler-core";
|
|
5
|
+
import type { IExecuteScheduledActionUseCase } from "./features/ExecuteScheduledAction/abstractions.js";
|
|
6
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
7
|
+
import { GetTenantByIdUseCase } from "@webiny/api-core/exports/api/tenancy.js";
|
|
8
|
+
declare class ScheduledActionLambdaHandlerImpl implements ScheduledActionEventHandler.Interface {
|
|
9
|
+
private executeScheduledAction;
|
|
10
|
+
private tenantContext;
|
|
11
|
+
private getTenantById;
|
|
12
|
+
constructor(executeScheduledAction: IExecuteScheduledActionUseCase, tenantContext: TenantContext.Interface, getTenantById: GetTenantByIdUseCase.Interface);
|
|
13
|
+
execute(eventCtx: EventContext<IScheduledActionEvent>, _next: NextFunction): Promise<IScheduledActionResult>;
|
|
14
|
+
}
|
|
15
|
+
export declare const ScheduledActionLambdaHandler: typeof ScheduledActionLambdaHandlerImpl & {
|
|
16
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/event-handler-core/features/scheduledAction/ScheduledActionEventHandler").IScheduledActionEventHandler>;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ScheduledActionEventHandler } from "@webiny/event-handler-core";
|
|
2
|
+
import { ExecuteScheduledActionUseCase } from "./features/ExecuteScheduledAction/index.js";
|
|
3
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
4
|
+
import { GetTenantByIdUseCase } from "@webiny/api-core/exports/api/tenancy.js";
|
|
5
|
+
import { SCHEDULED_ACTION_EVENT_IDENTIFIER } from "./constants.js";
|
|
6
|
+
class ScheduledActionLambdaHandlerImpl {
|
|
7
|
+
constructor(executeScheduledAction, tenantContext, getTenantById){
|
|
8
|
+
this.executeScheduledAction = executeScheduledAction;
|
|
9
|
+
this.tenantContext = tenantContext;
|
|
10
|
+
this.getTenantById = getTenantById;
|
|
11
|
+
}
|
|
12
|
+
async execute(eventCtx, _next) {
|
|
13
|
+
const input = eventCtx.event[SCHEDULED_ACTION_EVENT_IDENTIFIER];
|
|
14
|
+
if (!input.tenant) input.tenant = this.tenantContext.getTenant().id;
|
|
15
|
+
const tenantResult = await this.getTenantById.execute(input.tenant);
|
|
16
|
+
if (tenantResult.isFail()) throw tenantResult.error;
|
|
17
|
+
const tenant = tenantResult.value;
|
|
18
|
+
return this.tenantContext.withTenant(tenant, async ()=>{
|
|
19
|
+
const result = await this.executeScheduledAction.execute(input);
|
|
20
|
+
if (result.isFail()) {
|
|
21
|
+
const error = result.error;
|
|
22
|
+
console.error(error.code, error.message);
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
success: true
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const ScheduledActionLambdaHandler = ScheduledActionEventHandler.createImplementation({
|
|
32
|
+
implementation: ScheduledActionLambdaHandlerImpl,
|
|
33
|
+
dependencies: [
|
|
34
|
+
ExecuteScheduledActionUseCase,
|
|
35
|
+
TenantContext,
|
|
36
|
+
GetTenantByIdUseCase
|
|
37
|
+
]
|
|
38
|
+
});
|
|
39
|
+
export { ScheduledActionLambdaHandler };
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=ScheduledActionLambdaHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScheduledActionLambdaHandler.js","sources":["../src/ScheduledActionLambdaHandler.ts"],"sourcesContent":["import { ScheduledActionEventHandler } from \"@webiny/event-handler-core\";\nimport type { IScheduledActionEvent } from \"@webiny/event-handler-core\";\nimport type { IScheduledActionResult } from \"@webiny/event-handler-core\";\nimport type { EventContext, NextFunction } from \"@webiny/event-handler-core\";\nimport { ExecuteScheduledActionUseCase } from \"~/features/ExecuteScheduledAction/index.js\";\nimport type { IExecuteScheduledActionUseCase } from \"~/features/ExecuteScheduledAction/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { GetTenantByIdUseCase } from \"@webiny/api-core/exports/api/tenancy.js\";\nimport { SCHEDULED_ACTION_EVENT_IDENTIFIER } from \"~/constants.js\";\n\nclass ScheduledActionLambdaHandlerImpl implements ScheduledActionEventHandler.Interface {\n constructor(\n private executeScheduledAction: IExecuteScheduledActionUseCase,\n private tenantContext: TenantContext.Interface,\n private getTenantById: GetTenantByIdUseCase.Interface\n ) {}\n\n async execute(\n eventCtx: EventContext<IScheduledActionEvent>,\n _next: NextFunction\n ): Promise<IScheduledActionResult> {\n const input = eventCtx.event[SCHEDULED_ACTION_EVENT_IDENTIFIER];\n\n /**\n * Use the current tenant if the payload doesn't carry one — keeps backward compatibility\n * with scheduled actions created before `tenant` was added to the payload. The actual\n * per-request DynamoDB queries run inside withTenant() below.\n */\n if (!input.tenant) {\n input.tenant = this.tenantContext.getTenant().id;\n }\n\n const tenantResult = await this.getTenantById.execute(input.tenant);\n if (tenantResult.isFail()) {\n throw tenantResult.error;\n }\n const tenant = tenantResult.value;\n\n return this.tenantContext.withTenant(tenant, async () => {\n const result = await this.executeScheduledAction.execute(input);\n\n if (result.isFail()) {\n const error = result.error;\n console.error(error.code, error.message);\n throw error;\n }\n\n return { success: true };\n });\n }\n}\n\nexport const ScheduledActionLambdaHandler = ScheduledActionEventHandler.createImplementation({\n implementation: ScheduledActionLambdaHandlerImpl,\n dependencies: [ExecuteScheduledActionUseCase, TenantContext, GetTenantByIdUseCase]\n});\n"],"names":["ScheduledActionLambdaHandlerImpl","executeScheduledAction","tenantContext","getTenantById","eventCtx","_next","input","SCHEDULED_ACTION_EVENT_IDENTIFIER","tenantResult","tenant","result","error","console","ScheduledActionLambdaHandler","ScheduledActionEventHandler","ExecuteScheduledActionUseCase","TenantContext","GetTenantByIdUseCase"],"mappings":";;;;;AAUA,MAAMA;IACF,YACYC,sBAAsD,EACtDC,aAAsC,EACtCC,aAA6C,CACvD;aAHUF,sBAAsB,GAAtBA;aACAC,aAAa,GAAbA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QACFC,QAA6C,EAC7CC,KAAmB,EACY;QAC/B,MAAMC,QAAQF,SAAS,KAAK,CAACG,kCAAkC;QAO/D,IAAI,CAACD,MAAM,MAAM,EACbA,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,SAAS,GAAG,EAAE;QAGpD,MAAME,eAAe,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAACF,MAAM,MAAM;QAClE,IAAIE,aAAa,MAAM,IACnB,MAAMA,aAAa,KAAK;QAE5B,MAAMC,SAASD,aAAa,KAAK;QAEjC,OAAO,IAAI,CAAC,aAAa,CAAC,UAAU,CAACC,QAAQ;YACzC,MAAMC,SAAS,MAAM,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAACJ;YAEzD,IAAII,OAAO,MAAM,IAAI;gBACjB,MAAMC,QAAQD,OAAO,KAAK;gBAC1BE,QAAQ,KAAK,CAACD,MAAM,IAAI,EAAEA,MAAM,OAAO;gBACvC,MAAMA;YACV;YAEA,OAAO;gBAAE,SAAS;YAAK;QAC3B;IACJ;AACJ;AAEO,MAAME,+BAA+BC,4BAA4B,oBAAoB,CAAC;IACzF,gBAAgBd;IAChB,cAAc;QAACe;QAA+BC;QAAeC;KAAqB;AACtF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { SchedulePrivateModel } from "./domain/SchedulePrivateModel.js";
|
|
3
|
+
import { SchedulerPermissionsResolver } from "./features/permissions/SchedulerPermissionsResolver.js";
|
|
4
|
+
import { SchedulerGraphQLFactoryFeature } from "./graphql/feature.js";
|
|
5
|
+
import { NamespaceHandlerExecutionerFeature } from "./features/NamespaceHandler/feature.js";
|
|
6
|
+
import { ScheduledActionModelProvider } from "./features/ScheduledActionModelProvider.js";
|
|
7
|
+
import { SchedulerFeature } from "./features/SchedulerFeature.js";
|
|
8
|
+
const SchedulerFeature_SchedulerFeature = createFeature({
|
|
9
|
+
name: "Scheduler",
|
|
10
|
+
register (container) {
|
|
11
|
+
container.register(SchedulePrivateModel);
|
|
12
|
+
container.register(SchedulerPermissionsResolver);
|
|
13
|
+
SchedulerGraphQLFactoryFeature.register(container);
|
|
14
|
+
NamespaceHandlerExecutionerFeature.register(container);
|
|
15
|
+
SchedulerFeature.register(container);
|
|
16
|
+
container.register(ScheduledActionModelProvider);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
export { SchedulerFeature_SchedulerFeature as SchedulerFeature };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=SchedulerFeature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchedulerFeature.js","sources":["../src/SchedulerFeature.ts"],"sourcesContent":["import { type Container, createFeature } from \"@webiny/feature/api\";\nimport { SchedulePrivateModel } from \"./domain/SchedulePrivateModel.js\";\nimport { SchedulerPermissionsResolver } from \"~/features/permissions/SchedulerPermissionsResolver.js\";\nimport { SchedulerGraphQLFactoryFeature } from \"~/graphql/feature.js\";\nimport { NamespaceHandlerExecutionerFeature } from \"~/features/NamespaceHandler/feature.js\";\nimport { ScheduledActionModelProvider } from \"~/features/ScheduledActionModelProvider.js\";\nimport { SchedulerFeature as SchedulerCoreFeature } from \"~/features/SchedulerFeature.js\";\n\nexport const SchedulerFeature = createFeature({\n name: \"Scheduler\",\n register(container: Container) {\n container.register(SchedulePrivateModel);\n container.register(SchedulerPermissionsResolver);\n SchedulerGraphQLFactoryFeature.register(container);\n NamespaceHandlerExecutionerFeature.register(container);\n SchedulerCoreFeature.register(container);\n container.register(ScheduledActionModelProvider);\n }\n});\n"],"names":["SchedulerFeature","createFeature","container","SchedulePrivateModel","SchedulerPermissionsResolver","SchedulerGraphQLFactoryFeature","NamespaceHandlerExecutionerFeature","SchedulerCoreFeature","ScheduledActionModelProvider"],"mappings":";;;;;;;AAQO,MAAMA,oCAAmBC,cAAc;IAC1C,MAAM;IACN,UAASC,SAAoB;QACzBA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBC,+BAA+B,QAAQ,CAACH;QACxCI,mCAAmC,QAAQ,CAACJ;QAC5CK,iBAAAA,QAA6B,CAACL;QAC9BA,UAAU,QAAQ,CAACM;IACvB;AACJ"}
|
package/constants.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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";
|
|
9
|
+
/** Constant identifier for the publish scheduled action type. */
|
|
10
|
+
export declare const SCHEDULED_ACTION_PUBLISH: "publish";
|
|
11
|
+
/** Constant identifier for the unpublish scheduled action type. */
|
|
12
|
+
export declare const SCHEDULED_ACTION_UNPUBLISH: "unpublish";
|
|
13
|
+
export declare const SCHEDULED_ACTIONS: readonly ["publish", "unpublish"];
|
package/constants.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const SCHEDULE_MODEL_ID = "wbySchedule";
|
|
2
|
+
const SCHEDULE_ID_PREFIX = "wby-schedule-";
|
|
3
|
+
const SCHEDULE_MIN_FUTURE_SECONDS = 65;
|
|
4
|
+
const SCHEDULED_ACTION_EVENT_IDENTIFIER = "WebinyScheduledAction";
|
|
5
|
+
const SCHEDULED_ACTION_PUBLISH = "publish";
|
|
6
|
+
const SCHEDULED_ACTION_UNPUBLISH = "unpublish";
|
|
7
|
+
const SCHEDULED_ACTIONS = [
|
|
8
|
+
SCHEDULED_ACTION_PUBLISH,
|
|
9
|
+
SCHEDULED_ACTION_UNPUBLISH
|
|
10
|
+
];
|
|
11
|
+
export { SCHEDULED_ACTIONS, SCHEDULED_ACTION_EVENT_IDENTIFIER, SCHEDULED_ACTION_PUBLISH, SCHEDULED_ACTION_UNPUBLISH, SCHEDULE_ID_PREFIX, SCHEDULE_MIN_FUTURE_SECONDS, SCHEDULE_MODEL_ID };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=constants.js.map
|
package/constants.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../src/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\n/** Constant identifier for the publish scheduled action type. */\nexport const SCHEDULED_ACTION_PUBLISH = \"publish\" as const;\n/** Constant identifier for the unpublish scheduled action type. */\nexport const SCHEDULED_ACTION_UNPUBLISH = \"unpublish\" as const;\n\nexport const SCHEDULED_ACTIONS = [SCHEDULED_ACTION_PUBLISH, SCHEDULED_ACTION_UNPUBLISH] as const;\n"],"names":["SCHEDULE_MODEL_ID","SCHEDULE_ID_PREFIX","SCHEDULE_MIN_FUTURE_SECONDS","SCHEDULED_ACTION_EVENT_IDENTIFIER","SCHEDULED_ACTION_PUBLISH","SCHEDULED_ACTION_UNPUBLISH","SCHEDULED_ACTIONS"],"mappings":"AAAO,MAAMA,oBAAoB;AAC1B,MAAMC,qBAAqB;AAK3B,MAAMC,8BAA8B;AAEpC,MAAMC,oCAAoC;AAG1C,MAAMC,2BAA2B;AAEjC,MAAMC,6BAA6B;AAEnC,MAAMC,oBAAoB;IAACF;IAA0BC;CAA2B"}
|
|
@@ -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,33 @@
|
|
|
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 [
|
|
6
|
+
builder.private({
|
|
7
|
+
modelId: SCHEDULE_MODEL_ID,
|
|
8
|
+
name: "Webiny CMS Schedule",
|
|
9
|
+
lifecycleEvents: false
|
|
10
|
+
}).fields((fields)=>({
|
|
11
|
+
namespace: fields.text().label("Namespace"),
|
|
12
|
+
actionType: fields.text().label("Action Type"),
|
|
13
|
+
targetId: fields.text().label("Target ID"),
|
|
14
|
+
scheduledBy: fields.object().label("Scheduled By").fields((fields)=>({
|
|
15
|
+
id: fields.text().label("Identity ID"),
|
|
16
|
+
displayName: fields.text().label("Display Name"),
|
|
17
|
+
type: fields.text().label("Type")
|
|
18
|
+
})),
|
|
19
|
+
scheduledFor: fields.datetime().label("Scheduled For"),
|
|
20
|
+
title: fields.text().label("Title"),
|
|
21
|
+
error: fields.text().label("Error"),
|
|
22
|
+
payload: fields.json().label("Payload")
|
|
23
|
+
}))
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const SchedulePrivateModel = ModelFactory.createImplementation({
|
|
28
|
+
implementation: SchedulePrivateModelImpl,
|
|
29
|
+
dependencies: []
|
|
30
|
+
});
|
|
31
|
+
export { SchedulePrivateModel };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=SchedulePrivateModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain/SchedulePrivateModel.js","sources":["../../src/domain/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 lifecycleEvents: false\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"],"names":["SchedulePrivateModelImpl","builder","SCHEDULE_MODEL_ID","fields","SchedulePrivateModel","ModelFactory"],"mappings":";;AAGA,MAAMA;IACF,MAAa,QAAQC,OAA6B,EAAE;QAChD,OAAO;YACHA,QACK,OAAO,CAAC;gBACL,SAASC;gBACT,MAAM;gBACN,iBAAiB;YACrB,GACC,MAAM,CAACC,CAAAA,SAAW;oBACf,WAAWA,OAAO,IAAI,GAAG,KAAK,CAAC;oBAC/B,YAAYA,OAAO,IAAI,GAAG,KAAK,CAAC;oBAChC,UAAUA,OAAO,IAAI,GAAG,KAAK,CAAC;oBAC9B,aAAaA,OACR,MAAM,GACN,KAAK,CAAC,gBACN,MAAM,CAACA,CAAAA,SAAW;4BACf,IAAIA,OAAO,IAAI,GAAG,KAAK,CAAC;4BACxB,aAAaA,OAAO,IAAI,GAAG,KAAK,CAAC;4BACjC,MAAMA,OAAO,IAAI,GAAG,KAAK,CAAC;wBAC9B;oBACJ,cAAcA,OAAO,QAAQ,GAAG,KAAK,CAAC;oBACtC,OAAOA,OAAO,IAAI,GAAG,KAAK,CAAC;oBAC3B,OAAOA,OAAO,IAAI,GAAG,KAAK,CAAC;oBAC3B,SAASA,OAAO,IAAI,GAAG,KAAK,CAAC;gBACjC;SACP;IACL;AACJ;AAEO,MAAMC,uBAAuBC,aAAa,oBAAoB,CAAC;IAClE,gBAAgBL;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createCacheKey } from "@webiny/utils";
|
|
2
|
+
import { SCHEDULE_ID_PREFIX } from "../constants.js";
|
|
3
|
+
class ScheduledActionId {
|
|
4
|
+
static from(params) {
|
|
5
|
+
return [
|
|
6
|
+
SCHEDULE_ID_PREFIX,
|
|
7
|
+
createCacheKey([
|
|
8
|
+
params.namespace,
|
|
9
|
+
params.actionType,
|
|
10
|
+
params.targetId
|
|
11
|
+
]).slice(-24)
|
|
12
|
+
].join("");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export { ScheduledActionId };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=ScheduledActionId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain/ScheduledActionId.js","sources":["../../src/domain/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"],"names":["ScheduledActionId","params","SCHEDULE_ID_PREFIX","createCacheKey"],"mappings":";;AASO,MAAMA;IACT,OAAO,KAAKC,MAAgC,EAAE;QAC1C,OAAO;YACHC;YACAC,eAAe;gBAACF,OAAO,SAAS;gBAAEA,OAAO,UAAU;gBAAEA,OAAO,QAAQ;aAAC,EAAE,KAAK,CAAC;SAChF,CAAC,IAAI,CAAC;IACX;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain/ScheduledActionIdWithVersion.js","sources":["../../src/domain/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"],"names":["ScheduledActionIdWithVersion","id"],"mappings":"AAAO,MAAMA;IACT,OAAO,KAAKC,EAAU,EAAE;QACpB,IAAIA,GAAG,QAAQ,CAAC,UACZ,OAAOA;QAGX,OAAO,GAAGA,GAAG,KAAK,CAAC;IACvB;AACJ"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { IScheduledAction, IScheduledActionEntry } from "../shared/abstractions.js";
|
|
2
|
+
import type { GenericRecord } from "@webiny/api/types.js";
|
|
3
|
+
export declare class ScheduledActionMapper {
|
|
4
|
+
static toAction<T extends GenericRecord = GenericRecord>(action: IScheduledActionEntry<T>): IScheduledAction<T>;
|
|
5
|
+
static toActions<T extends GenericRecord = GenericRecord>(actions: IScheduledActionEntry<T>[]): IScheduledAction<T>[];
|
|
6
|
+
static toGraphQL<T extends GenericRecord = GenericRecord>(action: IScheduledAction<T>): {
|
|
7
|
+
id: string;
|
|
8
|
+
targetId: string;
|
|
9
|
+
namespace: string;
|
|
10
|
+
scheduledBy: import("~/shared/abstractions.js").Identity;
|
|
11
|
+
publishOn: Date | null;
|
|
12
|
+
unpublishOn: Date | null;
|
|
13
|
+
actionType: import("~/shared/abstractions.js").ScheduledActionType;
|
|
14
|
+
title: string;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { parseIdentifier } from "@webiny/utils";
|
|
2
|
+
import { SCHEDULED_ACTION_PUBLISH, SCHEDULED_ACTION_UNPUBLISH } from "../constants.js";
|
|
3
|
+
class ScheduledActionMapper {
|
|
4
|
+
static toAction(action) {
|
|
5
|
+
const { id: scheduleId } = parseIdentifier(action.id);
|
|
6
|
+
const scheduledBy = action.values.scheduledBy;
|
|
7
|
+
return {
|
|
8
|
+
id: scheduleId,
|
|
9
|
+
targetId: action.values.targetId,
|
|
10
|
+
namespace: action.values.namespace,
|
|
11
|
+
scheduledBy: {
|
|
12
|
+
id: scheduledBy.id,
|
|
13
|
+
displayName: scheduledBy.displayName,
|
|
14
|
+
type: scheduledBy.type
|
|
15
|
+
},
|
|
16
|
+
scheduledFor: new Date(action.values.scheduledFor),
|
|
17
|
+
actionType: action.values.actionType,
|
|
18
|
+
title: action.values.title,
|
|
19
|
+
payload: action.values.payload,
|
|
20
|
+
error: action.values.error,
|
|
21
|
+
tenant: action.tenant
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
static toActions(actions) {
|
|
25
|
+
return actions.map(ScheduledActionMapper.toAction);
|
|
26
|
+
}
|
|
27
|
+
static toGraphQL(action) {
|
|
28
|
+
return {
|
|
29
|
+
id: action.id,
|
|
30
|
+
targetId: action.targetId,
|
|
31
|
+
namespace: action.namespace,
|
|
32
|
+
scheduledBy: action.scheduledBy,
|
|
33
|
+
publishOn: action.actionType === SCHEDULED_ACTION_PUBLISH ? action.scheduledFor : null,
|
|
34
|
+
unpublishOn: action.actionType === SCHEDULED_ACTION_UNPUBLISH ? action.scheduledFor : null,
|
|
35
|
+
actionType: action.actionType,
|
|
36
|
+
title: action.title
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export { ScheduledActionMapper };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=ScheduledActionMapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain/ScheduledActionMapper.js","sources":["../../src/domain/ScheduledActionMapper.ts"],"sourcesContent":["import type { IScheduledAction, IScheduledActionEntry } from \"~/shared/abstractions.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { SCHEDULED_ACTION_PUBLISH, SCHEDULED_ACTION_UNPUBLISH } from \"~/constants.js\";\n\nexport class ScheduledActionMapper {\n static toAction<T extends GenericRecord = GenericRecord>(\n action: IScheduledActionEntry<T>\n ): IScheduledAction<T> {\n const { id: scheduleId } = parseIdentifier(action.id);\n const scheduledBy = action.values.scheduledBy;\n return {\n id: scheduleId,\n targetId: action.values.targetId,\n namespace: action.values.namespace,\n /**\n * Mapped field by field on purpose: Headless CMS stores this as an object\n * field, and object values carry a generated `_id` we don't want to leak\n * into the identity.\n */\n scheduledBy: {\n id: scheduledBy.id,\n displayName: scheduledBy.displayName,\n type: scheduledBy.type\n },\n scheduledFor: new Date(action.values.scheduledFor),\n actionType: action.values.actionType,\n title: action.values.title,\n payload: action.values.payload,\n error: action.values.error,\n tenant: action.tenant\n };\n }\n\n static toActions<T extends GenericRecord = GenericRecord>(\n actions: IScheduledActionEntry<T>[]\n ): IScheduledAction<T>[] {\n return actions.map(ScheduledActionMapper.toAction);\n }\n\n static toGraphQL<T extends GenericRecord = GenericRecord>(action: IScheduledAction<T>) {\n return {\n id: action.id,\n targetId: action.targetId,\n namespace: action.namespace,\n scheduledBy: action.scheduledBy,\n publishOn: action.actionType === SCHEDULED_ACTION_PUBLISH ? action.scheduledFor : null,\n unpublishOn:\n action.actionType === SCHEDULED_ACTION_UNPUBLISH ? action.scheduledFor : null,\n actionType: action.actionType,\n title: action.title\n };\n }\n}\n"],"names":["ScheduledActionMapper","action","scheduleId","parseIdentifier","scheduledBy","Date","actions","SCHEDULED_ACTION_PUBLISH","SCHEDULED_ACTION_UNPUBLISH"],"mappings":";;AAKO,MAAMA;IACT,OAAO,SACHC,MAAgC,EACb;QACnB,MAAM,EAAE,IAAIC,UAAU,EAAE,GAAGC,gBAAgBF,OAAO,EAAE;QACpD,MAAMG,cAAcH,OAAO,MAAM,CAAC,WAAW;QAC7C,OAAO;YACH,IAAIC;YACJ,UAAUD,OAAO,MAAM,CAAC,QAAQ;YAChC,WAAWA,OAAO,MAAM,CAAC,SAAS;YAMlC,aAAa;gBACT,IAAIG,YAAY,EAAE;gBAClB,aAAaA,YAAY,WAAW;gBACpC,MAAMA,YAAY,IAAI;YAC1B;YACA,cAAc,IAAIC,KAAKJ,OAAO,MAAM,CAAC,YAAY;YACjD,YAAYA,OAAO,MAAM,CAAC,UAAU;YACpC,OAAOA,OAAO,MAAM,CAAC,KAAK;YAC1B,SAASA,OAAO,MAAM,CAAC,OAAO;YAC9B,OAAOA,OAAO,MAAM,CAAC,KAAK;YAC1B,QAAQA,OAAO,MAAM;QACzB;IACJ;IAEA,OAAO,UACHK,OAAmC,EACd;QACrB,OAAOA,QAAQ,GAAG,CAACN,sBAAsB,QAAQ;IACrD;IAEA,OAAO,UAAmDC,MAA2B,EAAE;QACnF,OAAO;YACH,IAAIA,OAAO,EAAE;YACb,UAAUA,OAAO,QAAQ;YACzB,WAAWA,OAAO,SAAS;YAC3B,aAAaA,OAAO,WAAW;YAC/B,WAAWA,OAAO,UAAU,KAAKM,2BAA2BN,OAAO,YAAY,GAAG;YAClF,aACIA,OAAO,UAAU,KAAKO,6BAA6BP,OAAO,YAAY,GAAG;YAC7E,YAAYA,OAAO,UAAU;YAC7B,OAAOA,OAAO,KAAK;QACvB;IACJ;AACJ"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { BaseError } from "@webiny/feature/api";
|
|
2
|
+
/**
|
|
3
|
+
* Not authorized error when user lacks permissions to manage scheduled actions.
|
|
4
|
+
*/
|
|
5
|
+
export declare class NotAuthorizedError extends BaseError {
|
|
6
|
+
readonly code: "Scheduler/NotAuthorized";
|
|
7
|
+
constructor();
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Scheduled action not found error
|
|
11
|
+
*/
|
|
12
|
+
export declare class ScheduledActionNotFoundError extends BaseError<{
|
|
13
|
+
scheduleId: string;
|
|
14
|
+
}> {
|
|
15
|
+
readonly code: "Scheduler/ScheduledAction/NotFound";
|
|
16
|
+
constructor(scheduleId: string);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Storage/persistence error when working with scheduled actions
|
|
20
|
+
*/
|
|
21
|
+
export declare class ScheduledActionPersistenceError extends BaseError<{
|
|
22
|
+
originalError: Error;
|
|
23
|
+
}> {
|
|
24
|
+
readonly code: "Scheduler/ScheduledAction/PersistenceError";
|
|
25
|
+
constructor(error: Error);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Invalid schedule date error (e.g., scheduling in the past)
|
|
29
|
+
*/
|
|
30
|
+
export declare class InvalidScheduleDateError extends BaseError<{
|
|
31
|
+
scheduleFor: string;
|
|
32
|
+
}> {
|
|
33
|
+
readonly code: "Scheduler/ScheduledAction/InvalidDate";
|
|
34
|
+
constructor(scheduleFor: Date);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Scheduler service error (scheduler backend / provider errors)
|
|
38
|
+
*/
|
|
39
|
+
export declare class SchedulerServiceError extends BaseError<{
|
|
40
|
+
originalError: Error;
|
|
41
|
+
}> {
|
|
42
|
+
readonly code: "Scheduler/Service/Error";
|
|
43
|
+
constructor(error: Error);
|
|
44
|
+
}
|
|
45
|
+
interface INamespaceHandlerNotFoundErrorData {
|
|
46
|
+
namespace: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Namespace handler not found error.
|
|
50
|
+
*/
|
|
51
|
+
export declare class NamespaceHandlerNotFoundError extends BaseError<INamespaceHandlerNotFoundErrorData> {
|
|
52
|
+
readonly code: "Scheduler/NamespaceHandler/NotFound";
|
|
53
|
+
constructor(namespace: string);
|
|
54
|
+
}
|
|
55
|
+
export {};
|
package/domain/errors.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { BaseError } from "@webiny/feature/api";
|
|
2
|
+
class NotAuthorizedError extends BaseError {
|
|
3
|
+
constructor(){
|
|
4
|
+
super({
|
|
5
|
+
message: "Not authorized!"
|
|
6
|
+
}), this.code = "Scheduler/NotAuthorized";
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
class ScheduledActionNotFoundError extends BaseError {
|
|
10
|
+
constructor(scheduleId){
|
|
11
|
+
super({
|
|
12
|
+
message: `Scheduled action "${scheduleId}" was not found.`,
|
|
13
|
+
data: {
|
|
14
|
+
scheduleId
|
|
15
|
+
}
|
|
16
|
+
}), this.code = "Scheduler/ScheduledAction/NotFound";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
class ScheduledActionPersistenceError extends BaseError {
|
|
20
|
+
constructor(error){
|
|
21
|
+
super({
|
|
22
|
+
message: error.message,
|
|
23
|
+
data: {
|
|
24
|
+
originalError: error
|
|
25
|
+
}
|
|
26
|
+
}), this.code = "Scheduler/ScheduledAction/PersistenceError";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
class InvalidScheduleDateError extends BaseError {
|
|
30
|
+
constructor(scheduleFor){
|
|
31
|
+
super({
|
|
32
|
+
message: "Cannot schedule in the past",
|
|
33
|
+
data: {
|
|
34
|
+
scheduleFor: scheduleFor.toISOString()
|
|
35
|
+
}
|
|
36
|
+
}), this.code = "Scheduler/ScheduledAction/InvalidDate";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
class SchedulerServiceError extends BaseError {
|
|
40
|
+
constructor(error){
|
|
41
|
+
super({
|
|
42
|
+
message: `Scheduler service error: ${error.message}`,
|
|
43
|
+
data: {
|
|
44
|
+
originalError: error
|
|
45
|
+
}
|
|
46
|
+
}), this.code = "Scheduler/Service/Error";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
class NamespaceHandlerNotFoundError extends BaseError {
|
|
50
|
+
constructor(namespace){
|
|
51
|
+
super({
|
|
52
|
+
message: `Namespace handler for "${namespace}" was not found.`,
|
|
53
|
+
data: {
|
|
54
|
+
namespace
|
|
55
|
+
}
|
|
56
|
+
}), this.code = "Scheduler/NamespaceHandler/NotFound";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export { InvalidScheduleDateError, NamespaceHandlerNotFoundError, NotAuthorizedError, ScheduledActionNotFoundError, ScheduledActionPersistenceError, SchedulerServiceError };
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain/errors.js","sources":["../../src/domain/errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\n\n/**\n * Not authorized error when user lacks permissions to manage scheduled actions.\n */\nexport class NotAuthorizedError extends BaseError {\n override readonly code = \"Scheduler/NotAuthorized\" as const;\n\n constructor() {\n super({ message: \"Not authorized!\" });\n }\n}\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: Date) {\n super({\n message: \"Cannot schedule in the past\",\n data: {\n scheduleFor: scheduleFor.toISOString()\n }\n });\n }\n}\n\n/**\n * Scheduler service error (scheduler backend / 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\ninterface INamespaceHandlerNotFoundErrorData {\n namespace: string;\n}\n/**\n * Namespace handler not found error.\n */\nexport class NamespaceHandlerNotFoundError extends BaseError<INamespaceHandlerNotFoundErrorData> {\n override readonly code = \"Scheduler/NamespaceHandler/NotFound\" as const;\n\n constructor(namespace: string) {\n super({\n message: `Namespace handler for \"${namespace}\" was not found.`,\n data: {\n namespace\n }\n });\n }\n}\n"],"names":["NotAuthorizedError","BaseError","ScheduledActionNotFoundError","scheduleId","ScheduledActionPersistenceError","error","InvalidScheduleDateError","scheduleFor","SchedulerServiceError","NamespaceHandlerNotFoundError","namespace"],"mappings":";AAKO,MAAMA,2BAA2BC;IAGpC,aAAc;QACV,KAAK,CAAC;YAAE,SAAS;QAAkB,SAHrB,IAAI,GAAG;IAIzB;AACJ;AAKO,MAAMC,qCAAqCD;IAG9C,YAAYE,UAAkB,CAAE;QAC5B,KAAK,CAAC;YACF,SAAS,CAAC,kBAAkB,EAAEA,WAAW,gBAAgB,CAAC;YAC1D,MAAM;gBACFA;YACJ;QACJ,SARc,IAAI,GAAG;IASzB;AACJ;AAKO,MAAMC,wCAAwCH;IAGjD,YAAYI,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAASA,MAAM,OAAO;YACtB,MAAM;gBAAE,eAAeA;YAAM;QACjC,SANc,IAAI,GAAG;IAOzB;AACJ;AAKO,MAAMC,iCAAiCL;IAG1C,YAAYM,WAAiB,CAAE;QAC3B,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBACF,aAAaA,YAAY,WAAW;YACxC;QACJ,SARc,IAAI,GAAG;IASzB;AACJ;AAKO,MAAMC,8BAA8BP;IAGvC,YAAYI,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS,CAAC,yBAAyB,EAAEA,MAAM,OAAO,EAAE;YACpD,MAAM;gBAAE,eAAeA;YAAM;QACjC,SANc,IAAI,GAAG;IAOzB;AACJ;AAQO,MAAMI,sCAAsCR;IAG/C,YAAYS,SAAiB,CAAE;QAC3B,KAAK,CAAC;YACF,SAAS,CAAC,uBAAuB,EAAEA,UAAU,gBAAgB,CAAC;YAC9D,MAAM;gBACFA;YACJ;QACJ,SARc,IAAI,GAAG;IASzB;AACJ"}
|
|
@@ -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: (input: Date) => boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SCHEDULE_MIN_FUTURE_SECONDS } from "../constants.js";
|
|
2
|
+
const isValidDate = (input)=>{
|
|
3
|
+
const minDate = new Date(Date.now() + 1000 * SCHEDULE_MIN_FUTURE_SECONDS);
|
|
4
|
+
return input.getTime() >= minDate.getTime();
|
|
5
|
+
};
|
|
6
|
+
export { isValidDate };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=isValidDate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain/isValidDate.js","sources":["../../src/domain/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 = (input: Date): boolean => {\n const minDate = new Date(Date.now() + SCHEDULE_MIN_FUTURE_SECONDS * 1000);\n\n return input.getTime() >= minDate.getTime();\n};\n"],"names":["isValidDate","input","minDate","Date","SCHEDULE_MIN_FUTURE_SECONDS"],"mappings":";AAOO,MAAMA,cAAc,CAACC;IACxB,MAAMC,UAAU,IAAIC,KAAKA,KAAK,GAAG,KAAKC,AAA8B,OAA9BA;IAEtC,OAAOH,MAAM,OAAO,MAAMC,QAAQ,OAAO;AAC7C"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { ScheduleActionUseCase } from "../../features/ScheduleAction/index.js";
|
|
2
|
+
export type { ScheduleActionError } from "../../features/ScheduleAction/index.js";
|
|
3
|
+
export { GetScheduledActionUseCase } from "../../features/GetScheduledAction/index.js";
|
|
4
|
+
export { ListScheduledActionsUseCase } from "../../features/ListScheduledActions/index.js";
|
|
5
|
+
export { CancelScheduledActionUseCase } from "../../features/CancelScheduledAction/index.js";
|
|
6
|
+
export { ExecuteScheduledActionUseCase } from "../../features/ExecuteScheduledAction/index.js";
|
|
7
|
+
export { NamespaceHandler } from "../../features/NamespaceHandler/index.js";
|
|
8
|
+
export type { IScheduledAction, IScheduledActionEntry, ScheduledActionType } from "../../shared/abstractions.js";
|
|
9
|
+
export { SchedulerService, ScheduledActionHandler } from "../../shared/abstractions.js";
|
|
10
|
+
export { SCHEDULED_ACTION_PUBLISH as ScheduledActionTypePublish, SCHEDULED_ACTION_UNPUBLISH as ScheduledActionTypeUnpublish } from "../../constants.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { ScheduleActionUseCase } from "../../features/ScheduleAction/index.js";
|
|
2
|
+
export { GetScheduledActionUseCase } from "../../features/GetScheduledAction/index.js";
|
|
3
|
+
export { ListScheduledActionsUseCase } from "../../features/ListScheduledActions/index.js";
|
|
4
|
+
export { CancelScheduledActionUseCase } from "../../features/CancelScheduledAction/index.js";
|
|
5
|
+
export { ExecuteScheduledActionUseCase } from "../../features/ExecuteScheduledAction/index.js";
|
|
6
|
+
export { NamespaceHandler } from "../../features/NamespaceHandler/index.js";
|
|
7
|
+
export { ScheduledActionHandler, SchedulerService } from "../../shared/abstractions.js";
|
|
8
|
+
export { SCHEDULED_ACTION_PUBLISH as ScheduledActionTypePublish, SCHEDULED_ACTION_UNPUBLISH as ScheduledActionTypeUnpublish } from "../../constants.js";
|
|
@@ -0,0 +1,28 @@
|
|
|
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 { ScheduledActionModelProvider, SchedulerService } from "../../shared/abstractions.js";
|
|
5
|
+
import { DeleteEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js";
|
|
6
|
+
import { SchedulerPermissionsResolver } from "../../features/permissions/abstractions.js";
|
|
7
|
+
/**
|
|
8
|
+
* Cancels a scheduled action
|
|
9
|
+
*
|
|
10
|
+
* Flow:
|
|
11
|
+
* 1. Check if schedule exists
|
|
12
|
+
* 2. Delete scheduler timer
|
|
13
|
+
* 3. Delete CMS entry
|
|
14
|
+
* 4. If the scheduler delete fails, continue anyway (schedule might already be executed/deleted)
|
|
15
|
+
*/
|
|
16
|
+
declare class CancelScheduledActionUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
17
|
+
private getScheduledActionUseCase;
|
|
18
|
+
private schedulerService;
|
|
19
|
+
private deleteEntryUseCase;
|
|
20
|
+
private modelProvider;
|
|
21
|
+
private permissionsResolver;
|
|
22
|
+
constructor(getScheduledActionUseCase: GetScheduledActionUseCase.Interface, schedulerService: SchedulerService.Interface, deleteEntryUseCase: DeleteEntryUseCase.Interface, modelProvider: ScheduledActionModelProvider.Interface, permissionsResolver: SchedulerPermissionsResolver.Interface);
|
|
23
|
+
execute(params: UseCaseAbstraction.Params): Promise<Result<boolean, UseCaseAbstraction.Error>>;
|
|
24
|
+
}
|
|
25
|
+
export declare const CancelScheduledActionUseCase: typeof CancelScheduledActionUseCaseImpl & {
|
|
26
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ICancelScheduledActionUseCase>;
|
|
27
|
+
};
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { CancelScheduledActionUseCase } from "./abstractions.js";
|
|
3
|
+
import { GetScheduledActionUseCase } from "../GetScheduledAction/abstractions.js";
|
|
4
|
+
import { ScheduledActionModelProvider, SchedulerService } from "../../shared/abstractions.js";
|
|
5
|
+
import { NotAuthorizedError, 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
|
+
import { SchedulerPermissionsResolver } from "../permissions/abstractions.js";
|
|
10
|
+
class CancelScheduledActionUseCaseImpl {
|
|
11
|
+
constructor(getScheduledActionUseCase, schedulerService, deleteEntryUseCase, modelProvider, permissionsResolver){
|
|
12
|
+
this.getScheduledActionUseCase = getScheduledActionUseCase;
|
|
13
|
+
this.schedulerService = schedulerService;
|
|
14
|
+
this.deleteEntryUseCase = deleteEntryUseCase;
|
|
15
|
+
this.modelProvider = modelProvider;
|
|
16
|
+
this.permissionsResolver = permissionsResolver;
|
|
17
|
+
}
|
|
18
|
+
async execute(params) {
|
|
19
|
+
const { id, namespace } = params;
|
|
20
|
+
const permissions = this.permissionsResolver.forNamespace(namespace);
|
|
21
|
+
if (!await permissions.canRead()) return Result.fail(new NotAuthorizedError());
|
|
22
|
+
const getResult = await this.getScheduledActionUseCase.execute(params);
|
|
23
|
+
if (getResult.isFail()) {
|
|
24
|
+
const error = getResult.error;
|
|
25
|
+
if ("Scheduler/ScheduledAction/NotFound" === error.code) return Result.fail(new ScheduledActionNotFoundError(id));
|
|
26
|
+
return Result.fail(error);
|
|
27
|
+
}
|
|
28
|
+
const scheduleId = ScheduledActionIdWithVersion.from(id);
|
|
29
|
+
try {
|
|
30
|
+
const scheduleExists = await this.schedulerService.exists(params);
|
|
31
|
+
if (scheduleExists) await this.schedulerService.delete(params);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.warn(`Failed to delete the schedule: ${scheduleId}, tenant "${params.tenant}". Continuing with CMS entry deletion.`, error);
|
|
34
|
+
}
|
|
35
|
+
const model = await this.modelProvider.get();
|
|
36
|
+
const deleteResult = await this.deleteEntryUseCase.execute(model, getResult.value.id, {
|
|
37
|
+
force: true,
|
|
38
|
+
permanently: true
|
|
39
|
+
});
|
|
40
|
+
if (deleteResult.isFail()) {
|
|
41
|
+
if (deleteResult.error instanceof EntryNotFoundError) return Result.ok(true);
|
|
42
|
+
return Result.fail(new ScheduledActionPersistenceError(new Error(deleteResult.error.message)));
|
|
43
|
+
}
|
|
44
|
+
return Result.ok(true);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const CancelScheduledActionUseCase_CancelScheduledActionUseCase = CancelScheduledActionUseCase.createImplementation({
|
|
48
|
+
implementation: CancelScheduledActionUseCaseImpl,
|
|
49
|
+
dependencies: [
|
|
50
|
+
GetScheduledActionUseCase,
|
|
51
|
+
SchedulerService,
|
|
52
|
+
DeleteEntryUseCase,
|
|
53
|
+
ScheduledActionModelProvider,
|
|
54
|
+
SchedulerPermissionsResolver
|
|
55
|
+
]
|
|
56
|
+
});
|
|
57
|
+
export { CancelScheduledActionUseCase_CancelScheduledActionUseCase as CancelScheduledActionUseCase };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=CancelScheduledActionUseCase.js.map
|