@webiny/api-scheduler 0.0.0-unstable.3c5210ad37 → 0.0.0-unstable.48a4e5b6c1
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/ScheduledActionLambdaHandler.d.ts +17 -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 +5 -0
- package/constants.js +11 -8
- package/constants.js.map +1 -1
- package/domain/SchedulePrivateModel.js +26 -22
- package/domain/SchedulePrivateModel.js.map +1 -1
- package/domain/ScheduledActionId.js +12 -4
- package/domain/ScheduledActionId.js.map +1 -1
- package/domain/ScheduledActionIdWithVersion.js +5 -6
- package/domain/ScheduledActionIdWithVersion.js.map +1 -1
- package/domain/ScheduledActionMapper.d.ts +17 -0
- package/domain/ScheduledActionMapper.js +43 -0
- package/domain/ScheduledActionMapper.js.map +1 -0
- package/domain/errors.d.ts +22 -4
- package/domain/errors.js +55 -56
- package/domain/errors.js.map +1 -1
- package/domain/isValidDate.d.ts +1 -1
- package/domain/isValidDate.js +5 -9
- package/domain/isValidDate.js.map +1 -1
- package/exports/api/scheduler.d.ts +11 -0
- package/exports/api/scheduler.js +9 -0
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.d.ts +12 -6
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.js +68 -62
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.js.map +1 -1
- package/features/CancelScheduledAction/abstractions.d.ts +11 -3
- package/features/CancelScheduledAction/abstractions.js +2 -10
- package/features/CancelScheduledAction/abstractions.js.map +1 -1
- package/features/CancelScheduledAction/feature.d.ts +5 -2
- package/features/CancelScheduledAction/feature.js +6 -12
- package/features/CancelScheduledAction/feature.js.map +1 -1
- package/features/CancelScheduledAction/index.js +0 -2
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.d.ts +4 -4
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js +75 -90
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js.map +1 -1
- package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.d.ts +2 -2
- package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.js +21 -25
- package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.js.map +1 -1
- package/features/ExecuteScheduledAction/abstractions.d.ts +11 -3
- package/features/ExecuteScheduledAction/abstractions.js +12 -36
- package/features/ExecuteScheduledAction/abstractions.js.map +1 -1
- package/features/ExecuteScheduledAction/feature.d.ts +5 -2
- package/features/ExecuteScheduledAction/feature.js +7 -13
- package/features/ExecuteScheduledAction/feature.js.map +1 -1
- package/features/ExecuteScheduledAction/index.js +0 -2
- package/features/GetScheduledAction/GetScheduledActionUseCase.d.ts +8 -12
- package/features/GetScheduledAction/GetScheduledActionUseCase.js +44 -40
- package/features/GetScheduledAction/GetScheduledActionUseCase.js.map +1 -1
- package/features/GetScheduledAction/abstractions.d.ts +9 -2
- package/features/GetScheduledAction/abstractions.js +2 -11
- package/features/GetScheduledAction/abstractions.js.map +1 -1
- package/features/GetScheduledAction/feature.d.ts +4 -1
- package/features/GetScheduledAction/feature.js +6 -12
- package/features/GetScheduledAction/feature.js.map +1 -1
- package/features/GetScheduledAction/index.js +0 -2
- package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.d.ts +21 -0
- package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.js +69 -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/{RunAction → GetTargetScheduledAction}/index.js +0 -2
- package/features/ListScheduledActions/ListScheduledActionsUseCase.d.ts +7 -12
- package/features/ListScheduledActions/ListScheduledActionsUseCase.js +61 -68
- package/features/ListScheduledActions/ListScheduledActionsUseCase.js.map +1 -1
- package/features/ListScheduledActions/abstractions.d.ts +11 -3
- package/features/ListScheduledActions/abstractions.js +2 -12
- package/features/ListScheduledActions/abstractions.js.map +1 -1
- package/features/ListScheduledActions/feature.d.ts +4 -1
- package/features/ListScheduledActions/feature.js +6 -12
- package/features/ListScheduledActions/feature.js.map +1 -1
- package/features/ListScheduledActions/index.js +0 -2
- 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 +56 -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 +9 -9
- package/features/ScheduleAction/ScheduleActionUseCase.js +158 -144
- package/features/ScheduleAction/ScheduleActionUseCase.js.map +1 -1
- package/features/ScheduleAction/abstractions.d.ts +16 -11
- package/features/ScheduleAction/abstractions.js +2 -10
- package/features/ScheduleAction/abstractions.js.map +1 -1
- package/features/ScheduleAction/feature.d.ts +4 -1
- package/features/ScheduleAction/feature.js +6 -12
- package/features/ScheduleAction/feature.js.map +1 -1
- package/features/ScheduleAction/index.js +0 -2
- 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 +4 -1
- package/features/SchedulerFeature.js +12 -20
- package/features/SchedulerFeature.js.map +1 -1
- package/features/SchedulerService/VoidSchedulerService.d.ts +9 -9
- package/features/SchedulerService/VoidSchedulerService.js +17 -24
- package/features/SchedulerService/VoidSchedulerService.js.map +1 -1
- 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 +32 -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 +225 -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 +3 -8
- package/index.js +3 -12
- package/package.json +22 -34
- package/shared/abstractions.d.ts +49 -13
- package/shared/abstractions.js +4 -29
- package/shared/abstractions.js.map +1 -1
- package/context.d.ts +0 -7
- package/context.js +0 -41
- package/context.js.map +0 -1
- package/createEventHandler.d.ts +0 -13
- package/createEventHandler.js +0 -50
- package/createEventHandler.js.map +0 -1
- package/createScheduler.d.ts +0 -6
- package/createScheduler.js +0 -11
- package/createScheduler.js.map +0 -1
- package/features/CancelScheduledAction/index.js.map +0 -1
- package/features/ExecuteScheduledAction/index.js.map +0 -1
- package/features/GetScheduledAction/index.js.map +0 -1
- package/features/ListScheduledActions/index.js.map +0 -1
- package/features/RunAction/RunActionUseCase.d.ts +0 -23
- package/features/RunAction/RunActionUseCase.js +0 -37
- package/features/RunAction/RunActionUseCase.js.map +0 -1
- package/features/RunAction/abstractions.d.ts +0 -35
- package/features/RunAction/abstractions.js +0 -15
- package/features/RunAction/abstractions.js.map +0 -1
- package/features/RunAction/feature.d.ts +0 -7
- package/features/RunAction/feature.js +0 -17
- package/features/RunAction/feature.js.map +0 -1
- package/features/RunAction/index.js.map +0 -1
- package/features/ScheduleAction/index.js.map +0 -1
- package/features/SchedulerService/EventBridgeSchedulerService.d.ts +0 -26
- package/features/SchedulerService/EventBridgeSchedulerService.js +0 -131
- package/features/SchedulerService/EventBridgeSchedulerService.js.map +0 -1
- package/index.js.map +0 -1
- package/manifest.d.ts +0 -17
- package/manifest.js +0 -39
- package/manifest.js.map +0 -1
- /package/features/{RunAction → GetTargetScheduledAction}/index.d.ts +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ScheduledActionInputHandler } from "@webiny/api-kernel-core";
|
|
2
|
+
import type { IScheduledActionEvent } from "@webiny/api-kernel-core";
|
|
3
|
+
import type { IScheduledActionResult } from "@webiny/api-kernel-core";
|
|
4
|
+
import type { InputContext, NextFunction } from "@webiny/api-kernel-core";
|
|
5
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
6
|
+
import { GetTenantByIdUseCase, TenantScopes } from "@webiny/api-core/exports/api/tenancy.js";
|
|
7
|
+
declare class ScheduledActionLambdaHandlerImpl implements ScheduledActionInputHandler.Interface {
|
|
8
|
+
private tenantContext;
|
|
9
|
+
private getTenantById;
|
|
10
|
+
private tenantScopes;
|
|
11
|
+
constructor(tenantContext: TenantContext.Interface, getTenantById: GetTenantByIdUseCase.Interface, tenantScopes: TenantScopes.Interface);
|
|
12
|
+
execute(inputCtx: InputContext<IScheduledActionEvent>, _next: NextFunction): Promise<IScheduledActionResult>;
|
|
13
|
+
}
|
|
14
|
+
export declare const ScheduledActionLambdaHandler: typeof ScheduledActionLambdaHandlerImpl & {
|
|
15
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-kernel-core/features/scheduledAction/ScheduledActionInputHandler").IScheduledActionInputHandler>;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ScheduledActionInputHandler } from "@webiny/api-kernel-core";
|
|
2
|
+
import { ExecuteScheduledActionUseCase } from "./features/ExecuteScheduledAction/index.js";
|
|
3
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
4
|
+
import { GetTenantByIdUseCase, TenantScopes } from "@webiny/api-core/exports/api/tenancy.js";
|
|
5
|
+
import { SCHEDULED_ACTION_EVENT_IDENTIFIER } from "./constants.js";
|
|
6
|
+
class ScheduledActionLambdaHandlerImpl {
|
|
7
|
+
constructor(tenantContext, getTenantById, tenantScopes){
|
|
8
|
+
this.tenantContext = tenantContext;
|
|
9
|
+
this.getTenantById = getTenantById;
|
|
10
|
+
this.tenantScopes = tenantScopes;
|
|
11
|
+
}
|
|
12
|
+
async execute(inputCtx, _next) {
|
|
13
|
+
const input = inputCtx.input[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.tenantScopes.withTenant(tenant, async (scope)=>{
|
|
19
|
+
const result = await scope.resolve(ExecuteScheduledActionUseCase).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 = ScheduledActionInputHandler.createImplementation({
|
|
32
|
+
implementation: ScheduledActionLambdaHandlerImpl,
|
|
33
|
+
dependencies: [
|
|
34
|
+
TenantContext,
|
|
35
|
+
GetTenantByIdUseCase,
|
|
36
|
+
TenantScopes
|
|
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 { ScheduledActionInputHandler } from \"@webiny/api-kernel-core\";\nimport type { IScheduledActionEvent } from \"@webiny/api-kernel-core\";\nimport type { IScheduledActionResult } from \"@webiny/api-kernel-core\";\nimport type { InputContext, NextFunction } from \"@webiny/api-kernel-core\";\nimport { ExecuteScheduledActionUseCase } from \"~/features/ExecuteScheduledAction/index.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { GetTenantByIdUseCase, TenantScopes } from \"@webiny/api-core/exports/api/tenancy.js\";\nimport { SCHEDULED_ACTION_EVENT_IDENTIFIER } from \"~/constants.js\";\n\nclass ScheduledActionLambdaHandlerImpl implements ScheduledActionInputHandler.Interface {\n constructor(\n private tenantContext: TenantContext.Interface,\n private getTenantById: GetTenantByIdUseCase.Interface,\n private tenantScopes: TenantScopes.Interface\n ) {}\n\n async execute(\n inputCtx: InputContext<IScheduledActionEvent>,\n _next: NextFunction\n ): Promise<IScheduledActionResult> {\n const input = inputCtx.input[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 action runs in\n * its tenant's scope (the one this event already runs in, see `ScheduledActionTenantSource`).\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.tenantScopes.withTenant(tenant, async scope => {\n const result = await scope.resolve(ExecuteScheduledActionUseCase).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 = ScheduledActionInputHandler.createImplementation({\n implementation: ScheduledActionLambdaHandlerImpl,\n dependencies: [TenantContext, GetTenantByIdUseCase, TenantScopes]\n});\n"],"names":["ScheduledActionLambdaHandlerImpl","tenantContext","getTenantById","tenantScopes","inputCtx","_next","input","SCHEDULED_ACTION_EVENT_IDENTIFIER","tenantResult","tenant","scope","result","ExecuteScheduledActionUseCase","error","console","ScheduledActionLambdaHandler","ScheduledActionInputHandler","TenantContext","GetTenantByIdUseCase","TenantScopes"],"mappings":";;;;;AASA,MAAMA;IACF,YACYC,aAAsC,EACtCC,aAA6C,EAC7CC,YAAoC,CAC9C;aAHUF,aAAa,GAAbA;aACAC,aAAa,GAAbA;aACAC,YAAY,GAAZA;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,YAAY,CAAC,UAAU,CAACC,QAAQ,OAAMC;YAC9C,MAAMC,SAAS,MAAMD,MAAM,OAAO,CAACE,+BAA+B,OAAO,CAACN;YAE1E,IAAIK,OAAO,MAAM,IAAI;gBACjB,MAAME,QAAQF,OAAO,KAAK;gBAC1BG,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,gBAAgBhB;IAChB,cAAc;QAACiB;QAAeC;QAAsBC;KAAa;AACrE"}
|
|
@@ -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
CHANGED
|
@@ -6,3 +6,8 @@ export declare const SCHEDULE_ID_PREFIX = "wby-schedule-";
|
|
|
6
6
|
*/
|
|
7
7
|
export declare const SCHEDULE_MIN_FUTURE_SECONDS = 65;
|
|
8
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
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 };
|
|
9
12
|
|
|
10
13
|
//# sourceMappingURL=constants.js.map
|
package/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|
|
@@ -1,29 +1,33 @@
|
|
|
1
1
|
import { ModelFactory } from "@webiny/api-headless-cms/features/modelBuilder/index.js";
|
|
2
2
|
import { SCHEDULE_MODEL_ID } from "../constants.js";
|
|
3
3
|
class SchedulePrivateModelImpl {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
+
}
|
|
23
26
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
const SchedulePrivateModel = ModelFactory.createImplementation({
|
|
28
|
+
implementation: SchedulePrivateModelImpl,
|
|
29
|
+
dependencies: []
|
|
27
30
|
});
|
|
31
|
+
export { SchedulePrivateModel };
|
|
28
32
|
|
|
29
33
|
//# sourceMappingURL=SchedulePrivateModel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { createCacheKey } from "@webiny/utils";
|
|
2
2
|
import { SCHEDULE_ID_PREFIX } from "../constants.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
+
}
|
|
7
14
|
}
|
|
15
|
+
export { ScheduledActionId };
|
|
8
16
|
|
|
9
17
|
//# sourceMappingURL=ScheduledActionId.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
class ScheduledActionIdWithVersion {
|
|
2
|
+
static from(id) {
|
|
3
|
+
if (id.endsWith("#0001")) return id;
|
|
4
|
+
return `${id}#0001`;
|
|
5
5
|
}
|
|
6
|
-
return `${id}#0001`;
|
|
7
|
-
}
|
|
8
6
|
}
|
|
7
|
+
export { ScheduledActionIdWithVersion };
|
|
9
8
|
|
|
10
9
|
//# sourceMappingURL=ScheduledActionIdWithVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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,17 @@
|
|
|
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
|
+
error: string | null;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
error: action.error || null
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export { ScheduledActionMapper };
|
|
42
|
+
|
|
43
|
+
//# 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 error: action.error || null\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;YACnB,OAAOA,OAAO,KAAK,IAAI;QAC3B;IACJ;AACJ"}
|
package/domain/errors.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
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
|
+
}
|
|
2
9
|
/**
|
|
3
10
|
* Scheduled action not found error
|
|
4
11
|
*/
|
|
@@ -18,16 +25,16 @@ export declare class ScheduledActionPersistenceError extends BaseError<{
|
|
|
18
25
|
constructor(error: Error);
|
|
19
26
|
}
|
|
20
27
|
/**
|
|
21
|
-
* Invalid schedule date error (e.g., scheduling in the past)
|
|
28
|
+
* Invalid schedule date error (e.g., scheduling in the past, or no date at all)
|
|
22
29
|
*/
|
|
23
30
|
export declare class InvalidScheduleDateError extends BaseError<{
|
|
24
|
-
scheduleFor: string;
|
|
31
|
+
scheduleFor: string | null;
|
|
25
32
|
}> {
|
|
26
33
|
readonly code: "Scheduler/ScheduledAction/InvalidDate";
|
|
27
|
-
constructor(scheduleFor:
|
|
34
|
+
constructor(scheduleFor: Date | null | undefined);
|
|
28
35
|
}
|
|
29
36
|
/**
|
|
30
|
-
* Scheduler service error (
|
|
37
|
+
* Scheduler service error (scheduler backend / provider errors)
|
|
31
38
|
*/
|
|
32
39
|
export declare class SchedulerServiceError extends BaseError<{
|
|
33
40
|
originalError: Error;
|
|
@@ -35,3 +42,14 @@ export declare class SchedulerServiceError extends BaseError<{
|
|
|
35
42
|
readonly code: "Scheduler/Service/Error";
|
|
36
43
|
constructor(error: Error);
|
|
37
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
CHANGED
|
@@ -1,63 +1,62 @@
|
|
|
1
1
|
import { BaseError } from "@webiny/feature/api";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
constructor(scheduleId) {
|
|
9
|
-
super({
|
|
10
|
-
message: `Scheduled action "${scheduleId}" was not found.`,
|
|
11
|
-
data: {
|
|
12
|
-
scheduleId
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
}
|
|
2
|
+
class NotAuthorizedError extends BaseError {
|
|
3
|
+
constructor(){
|
|
4
|
+
super({
|
|
5
|
+
message: "Not authorized!"
|
|
6
|
+
}), this.code = "Scheduler/NotAuthorized";
|
|
7
|
+
}
|
|
16
8
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
data: {
|
|
27
|
-
originalError: error
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
}
|
|
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
|
+
}
|
|
31
18
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
data: {
|
|
42
|
-
scheduleFor
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
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
|
+
}
|
|
46
28
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
29
|
+
class InvalidScheduleDateError extends BaseError {
|
|
30
|
+
constructor(scheduleFor){
|
|
31
|
+
const isDate = scheduleFor instanceof Date && !isNaN(scheduleFor.getTime());
|
|
32
|
+
super({
|
|
33
|
+
message: isDate ? "Cannot schedule in the past" : "A valid schedule date is required",
|
|
34
|
+
data: {
|
|
35
|
+
scheduleFor: isDate ? scheduleFor.toISOString() : null
|
|
36
|
+
}
|
|
37
|
+
}), this.code = "Scheduler/ScheduledAction/InvalidDate";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
class SchedulerServiceError extends BaseError {
|
|
41
|
+
constructor(error){
|
|
42
|
+
super({
|
|
43
|
+
message: `Scheduler service error: ${error.message}`,
|
|
44
|
+
data: {
|
|
45
|
+
originalError: error
|
|
46
|
+
}
|
|
47
|
+
}), this.code = "Scheduler/Service/Error";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
class NamespaceHandlerNotFoundError extends BaseError {
|
|
51
|
+
constructor(namespace){
|
|
52
|
+
super({
|
|
53
|
+
message: `Namespace handler for "${namespace}" was not found.`,
|
|
54
|
+
data: {
|
|
55
|
+
namespace
|
|
56
|
+
}
|
|
57
|
+
}), this.code = "Scheduler/NamespaceHandler/NotFound";
|
|
58
|
+
}
|
|
61
59
|
}
|
|
60
|
+
export { InvalidScheduleDateError, NamespaceHandlerNotFoundError, NotAuthorizedError, ScheduledActionNotFoundError, ScheduledActionPersistenceError, SchedulerServiceError };
|
|
62
61
|
|
|
63
62
|
//# sourceMappingURL=errors.js.map
|
package/domain/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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, or no date at all)\n */\nexport class InvalidScheduleDateError extends BaseError<{ scheduleFor: string | null }> {\n override readonly code = \"Scheduler/ScheduledAction/InvalidDate\" as const;\n\n constructor(scheduleFor: Date | null | undefined) {\n const isDate = scheduleFor instanceof Date && !isNaN(scheduleFor.getTime());\n super({\n message: isDate ? \"Cannot schedule in the past\" : \"A valid schedule date is required\",\n data: {\n scheduleFor: isDate ? scheduleFor.toISOString() : null\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","isDate","Date","isNaN","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,WAAoC,CAAE;QAC9C,MAAMC,SAASD,uBAAuBE,QAAQ,CAACC,MAAMH,YAAY,OAAO;QACxE,KAAK,CAAC;YACF,SAASC,SAAS,gCAAgC;YAClD,MAAM;gBACF,aAAaA,SAASD,YAAY,WAAW,KAAK;YACtD;QACJ,SATc,IAAI,GAAG;IAUzB;AACJ;AAKO,MAAMI,8BAA8BV;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,MAAMO,sCAAsCX;IAG/C,YAAYY,SAAiB,CAAE;QAC3B,KAAK,CAAC;YACF,SAAS,CAAC,uBAAuB,EAAEA,UAAU,gBAAgB,CAAC;YAC9D,MAAM;gBACFA;YACJ;QACJ,SARc,IAAI,GAAG;IASzB;AACJ"}
|
package/domain/isValidDate.d.ts
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* We need to ensure that the date is at least a SCHEDULE_MIN_FUTURE_MINUTES minutes in the future.
|
|
4
4
|
* Otherwise, we consider it as "immediate" and run the action right away.
|
|
5
5
|
*/
|
|
6
|
-
export declare const isValidDate: (
|
|
6
|
+
export declare const isValidDate: (input: Date | null | undefined) => input is Date;
|
package/domain/isValidDate.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { SCHEDULE_MIN_FUTURE_SECONDS } from "../constants.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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();
|
|
2
|
+
const isValidDate = (input)=>{
|
|
3
|
+
if (!(input instanceof Date)) return false;
|
|
4
|
+
const minDate = new Date(Date.now() + 1000 * SCHEDULE_MIN_FUTURE_SECONDS);
|
|
5
|
+
return input.getTime() >= minDate.getTime();
|
|
11
6
|
};
|
|
7
|
+
export { isValidDate };
|
|
12
8
|
|
|
13
9
|
//# sourceMappingURL=isValidDate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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 | null | undefined): input is Date => {\n if (!(input instanceof Date)) {\n return false;\n }\n const minDate = new Date(Date.now() + SCHEDULE_MIN_FUTURE_SECONDS * 1000);\n\n return input.getTime() >= minDate.getTime();\n};\n"],"names":["isValidDate","input","Date","minDate","SCHEDULE_MIN_FUTURE_SECONDS"],"mappings":";AAOO,MAAMA,cAAc,CAACC;IACxB,IAAI,CAAEA,CAAAA,iBAAiBC,IAAG,GACtB,OAAO;IAEX,MAAMC,UAAU,IAAID,KAAKA,KAAK,GAAG,KAAKE,AAA8B,OAA9BA;IAEtC,OAAOH,MAAM,OAAO,MAAME,QAAQ,OAAO;AAC7C"}
|
|
@@ -0,0 +1,11 @@
|
|
|
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";
|
|
11
|
+
export { NotAuthorizedError as SchedulerNotAuthorizedError } from "../../domain/errors.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
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";
|
|
9
|
+
export { NotAuthorizedError as SchedulerNotAuthorizedError } from "../../domain/errors.js";
|