@webiny/api-scheduler 6.4.11 → 6.6.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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/domain/errors.d.ts +1 -1
- package/domain/errors.js.map +1 -1
- package/domain/permissionsSchema.d.ts +9 -0
- package/domain/permissionsSchema.js +18 -0
- package/domain/permissionsSchema.js.map +1 -0
- package/exports/api/scheduler.d.ts +1 -1
- package/exports/api/scheduler.js +1 -1
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.d.ts +7 -7
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.js +15 -17
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.js.map +1 -1
- package/features/CancelScheduledAction/abstractions.d.ts +1 -1
- package/features/CancelScheduledAction/abstractions.js.map +1 -1
- package/features/CancelScheduledAction/feature.d.ts +1 -1
- package/features/CancelScheduledAction/feature.js.map +1 -1
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.d.ts +3 -3
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js +8 -15
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js.map +1 -1
- package/features/ExecuteScheduledAction/abstractions.d.ts +1 -1
- package/features/ExecuteScheduledAction/abstractions.js.map +1 -1
- package/features/ExecuteScheduledAction/feature.d.ts +1 -1
- package/features/ExecuteScheduledAction/feature.js.map +1 -1
- package/features/GetScheduledAction/GetScheduledActionUseCase.d.ts +5 -5
- package/features/GetScheduledAction/GetScheduledActionUseCase.js +12 -14
- package/features/GetScheduledAction/GetScheduledActionUseCase.js.map +1 -1
- package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.d.ts +5 -5
- package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.js +13 -15
- package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.js.map +1 -1
- package/features/ListScheduledActions/ListScheduledActionsUseCase.d.ts +5 -5
- package/features/ListScheduledActions/ListScheduledActionsUseCase.js +14 -17
- package/features/ListScheduledActions/ListScheduledActionsUseCase.js.map +1 -1
- 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/ScheduleAction/ScheduleActionUseCase.d.ts +6 -6
- package/features/ScheduleAction/ScheduleActionUseCase.js +10 -8
- package/features/ScheduleAction/ScheduleActionUseCase.js.map +1 -1
- package/features/ScheduledActionModelProvider.d.ts +26 -0
- package/features/ScheduledActionModelProvider.js +22 -0
- package/features/ScheduledActionModelProvider.js.map +1 -0
- package/features/permissions/abstractions.d.ts +12 -14
- package/features/permissions/abstractions.js +4 -4
- package/features/permissions/abstractions.js.map +1 -1
- package/features/permissions/feature.d.ts +4 -0
- package/features/permissions/feature.js +7 -0
- package/features/permissions/feature.js.map +1 -0
- package/graphql/SchedulerGraphQLFactory.d.ts +3 -3
- package/graphql/SchedulerGraphQLFactory.js +2 -2
- package/graphql/SchedulerGraphQLFactory.js.map +1 -1
- package/graphql/feature.d.ts +4 -0
- package/graphql/feature.js +11 -0
- package/graphql/feature.js.map +1 -0
- package/index.d.ts +3 -2
- package/index.js +3 -2
- package/package.json +13 -22
- package/shared/abstractions.d.ts +11 -5
- package/shared/abstractions.js +2 -2
- package/shared/abstractions.js.map +1 -1
- package/context.d.ts +0 -7
- package/context.js +0 -46
- package/context.js.map +0 -1
- package/createEventHandler.d.ts +0 -15
- package/createEventHandler.js +0 -47
- package/createEventHandler.js.map +0 -1
- package/createScheduler.d.ts +0 -6
- package/createScheduler.js +0 -9
- package/createScheduler.js.map +0 -1
- package/features/SchedulerService/EventBridgeSchedulerService.d.ts +0 -29
- package/features/SchedulerService/EventBridgeSchedulerService.js +0 -114
- package/features/SchedulerService/EventBridgeSchedulerService.js.map +0 -1
- package/features/permissions/SchedulerPermissionsResolver.d.ts +0 -10
- package/features/permissions/SchedulerPermissionsResolver.js +0 -23
- package/features/permissions/SchedulerPermissionsResolver.js.map +0 -1
- package/manifest.d.ts +0 -17
- package/manifest.js +0 -35
- package/manifest.js.map +0 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CmsModel } from "@webiny/api-headless-cms/types";
|
|
2
|
+
import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel/index.js";
|
|
3
|
+
import { ScheduledActionModelProvider as Abstraction } from "../shared/abstractions.js";
|
|
4
|
+
/**
|
|
5
|
+
* Resolves the tenant's `wbySchedule` model on demand, replacing the per-request hook that used to
|
|
6
|
+
* push an already-resolved model into the container.
|
|
7
|
+
*
|
|
8
|
+
* No memoization: `ModelsFetcher` already caches the model list per request (`ModelCache` is a
|
|
9
|
+
* per-request `createMemoryCache()`). No `withoutAuthorization` either — `wbySchedule` is a private
|
|
10
|
+
* model, and `PrivateModelBuilder` sets `authorization: false`, which short-circuits
|
|
11
|
+
* `canAccessModel()` to true for every identity, so the wrapper the initializer used changed
|
|
12
|
+
* nothing.
|
|
13
|
+
*
|
|
14
|
+
* `GetModelUseCase` is an ordinary constructor dependency: this provider is only constructed when a
|
|
15
|
+
* consumer first awaits `get()`, during request handling — after the CMS has registered everything
|
|
16
|
+
* the use case needs. That timing is what forced the initializer's lazy `container.resolve()`.
|
|
17
|
+
*/
|
|
18
|
+
declare class ScheduledActionModelProviderImpl implements Abstraction.Interface {
|
|
19
|
+
private getModel;
|
|
20
|
+
constructor(getModel: GetModelUseCase.Interface);
|
|
21
|
+
get(): Promise<CmsModel>;
|
|
22
|
+
}
|
|
23
|
+
export declare const ScheduledActionModelProvider: typeof ScheduledActionModelProviderImpl & {
|
|
24
|
+
__abstraction: import("@webiny/di").Abstraction<import("~/shared/abstractions.js").IScheduledActionModelProvider>;
|
|
25
|
+
};
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel/index.js";
|
|
2
|
+
import { ScheduledActionModelProvider } from "../shared/abstractions.js";
|
|
3
|
+
import { SCHEDULE_MODEL_ID } from "../constants.js";
|
|
4
|
+
class ScheduledActionModelProviderImpl {
|
|
5
|
+
constructor(getModel){
|
|
6
|
+
this.getModel = getModel;
|
|
7
|
+
}
|
|
8
|
+
async get() {
|
|
9
|
+
const result = await this.getModel.execute(SCHEDULE_MODEL_ID);
|
|
10
|
+
if (result.isFail()) throw result.error;
|
|
11
|
+
return result.value;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const ScheduledActionModelProvider_ScheduledActionModelProvider = ScheduledActionModelProvider.createImplementation({
|
|
15
|
+
implementation: ScheduledActionModelProviderImpl,
|
|
16
|
+
dependencies: [
|
|
17
|
+
GetModelUseCase
|
|
18
|
+
]
|
|
19
|
+
});
|
|
20
|
+
export { ScheduledActionModelProvider_ScheduledActionModelProvider as ScheduledActionModelProvider };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=ScheduledActionModelProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/ScheduledActionModelProvider.js","sources":["../../src/features/ScheduledActionModelProvider.ts"],"sourcesContent":["import type { CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { ScheduledActionModelProvider as Abstraction } from \"~/shared/abstractions.js\";\nimport { SCHEDULE_MODEL_ID } from \"~/constants.js\";\n\n/**\n * Resolves the tenant's `wbySchedule` model on demand, replacing the per-request hook that used to\n * push an already-resolved model into the container.\n *\n * No memoization: `ModelsFetcher` already caches the model list per request (`ModelCache` is a\n * per-request `createMemoryCache()`). No `withoutAuthorization` either — `wbySchedule` is a private\n * model, and `PrivateModelBuilder` sets `authorization: false`, which short-circuits\n * `canAccessModel()` to true for every identity, so the wrapper the initializer used changed\n * nothing.\n *\n * `GetModelUseCase` is an ordinary constructor dependency: this provider is only constructed when a\n * consumer first awaits `get()`, during request handling — after the CMS has registered everything\n * the use case needs. That timing is what forced the initializer's lazy `container.resolve()`.\n */\nclass ScheduledActionModelProviderImpl implements Abstraction.Interface {\n constructor(private getModel: GetModelUseCase.Interface) {}\n\n async get(): Promise<CmsModel> {\n const result = await this.getModel.execute(SCHEDULE_MODEL_ID);\n if (result.isFail()) {\n throw result.error;\n }\n return result.value;\n }\n}\n\nexport const ScheduledActionModelProvider = Abstraction.createImplementation({\n implementation: ScheduledActionModelProviderImpl,\n dependencies: [GetModelUseCase]\n});\n"],"names":["ScheduledActionModelProviderImpl","getModel","result","SCHEDULE_MODEL_ID","ScheduledActionModelProvider","Abstraction","GetModelUseCase"],"mappings":";;;AAmBA,MAAMA;IACF,YAAoBC,QAAmC,CAAE;aAArCA,QAAQ,GAARA;IAAsC;IAE1D,MAAM,MAAyB;QAC3B,MAAMC,SAAS,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAACC;QAC3C,IAAID,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;QAEtB,OAAOA,OAAO,KAAK;IACvB;AACJ;AAEO,MAAME,4DAA+BC,6BAAAA,oBAAgC,CAAC;IACzE,gBAAgBL;IAChB,cAAc;QAACM;KAAgB;AACnC"}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type { Permissions } from "@webiny/api-core/exports/api/security.js";
|
|
2
|
+
import { SCHEDULER_PERMISSIONS_SCHEMA } from "../../domain/permissionsSchema.js";
|
|
3
|
+
export declare const SchedulerPermissions: import("@webiny/di").Abstraction<import("@webiny/api-core/features/security/permissions/types").PermissionsTyped<{
|
|
4
|
+
readonly prefix: "scheduler";
|
|
5
|
+
readonly fullAccess: true;
|
|
6
|
+
readonly entities: readonly [{
|
|
7
|
+
readonly id: "action";
|
|
8
|
+
readonly permission: "scheduler.action";
|
|
9
|
+
readonly scopes: readonly ["full", "own"];
|
|
10
|
+
}];
|
|
11
|
+
}>>;
|
|
7
12
|
export declare namespace SchedulerPermissions {
|
|
8
|
-
type Interface =
|
|
9
|
-
}
|
|
10
|
-
export interface ISchedulerPermissionsResolver {
|
|
11
|
-
forNamespace(namespace: string): ISchedulerPermissions | undefined;
|
|
12
|
-
}
|
|
13
|
-
export declare const SchedulerPermissionsResolver: import("@webiny/di").Abstraction<ISchedulerPermissionsResolver>;
|
|
14
|
-
export declare namespace SchedulerPermissionsResolver {
|
|
15
|
-
type Interface = ISchedulerPermissionsResolver;
|
|
13
|
+
type Interface = Permissions<typeof SCHEDULER_PERMISSIONS_SCHEMA>;
|
|
16
14
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
export { SchedulerPermissions
|
|
1
|
+
import { createPermissionsAbstraction } from "@webiny/api-core/exports/api/security.js";
|
|
2
|
+
import { SCHEDULER_PERMISSIONS_SCHEMA } from "../../domain/permissionsSchema.js";
|
|
3
|
+
const SchedulerPermissions = createPermissionsAbstraction(SCHEDULER_PERMISSIONS_SCHEMA);
|
|
4
|
+
export { SchedulerPermissions };
|
|
5
5
|
|
|
6
6
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/permissions/abstractions.js","sources":["../../../src/features/permissions/abstractions.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"features/permissions/abstractions.js","sources":["../../../src/features/permissions/abstractions.ts"],"sourcesContent":["import { createPermissionsAbstraction } from \"@webiny/api-core/exports/api/security.js\";\nimport type { Permissions } from \"@webiny/api-core/exports/api/security.js\";\nimport { SCHEDULER_PERMISSIONS_SCHEMA } from \"~/domain/permissionsSchema.js\";\n\nexport const SchedulerPermissions = createPermissionsAbstraction(SCHEDULER_PERMISSIONS_SCHEMA);\n\nexport namespace SchedulerPermissions {\n export type Interface = Permissions<typeof SCHEDULER_PERMISSIONS_SCHEMA>;\n}\n"],"names":["SchedulerPermissions","createPermissionsAbstraction","SCHEDULER_PERMISSIONS_SCHEMA"],"mappings":";;AAIO,MAAMA,uBAAuBC,6BAA6BC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createPermissionsFeature } from "@webiny/api-core/exports/api/security.js";
|
|
2
|
+
import { SCHEDULER_PERMISSIONS_SCHEMA } from "../../domain/permissionsSchema.js";
|
|
3
|
+
import { SchedulerPermissions } from "./abstractions.js";
|
|
4
|
+
const SchedulerPermissionsFeature = createPermissionsFeature(SCHEDULER_PERMISSIONS_SCHEMA, SchedulerPermissions);
|
|
5
|
+
export { SchedulerPermissionsFeature };
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/permissions/feature.js","sources":["../../../src/features/permissions/feature.ts"],"sourcesContent":["import { createPermissionsFeature } from \"@webiny/api-core/exports/api/security.js\";\nimport { SCHEDULER_PERMISSIONS_SCHEMA } from \"~/domain/permissionsSchema.js\";\nimport { SchedulerPermissions } from \"./abstractions.js\";\n\nexport const SchedulerPermissionsFeature = createPermissionsFeature(\n SCHEDULER_PERMISSIONS_SCHEMA,\n SchedulerPermissions\n);\n"],"names":["SchedulerPermissionsFeature","createPermissionsFeature","SCHEDULER_PERMISSIONS_SCHEMA","SchedulerPermissions"],"mappings":";;;AAIO,MAAMA,8BAA8BC,yBACvCC,8BACAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { GraphQLSchemaBuilder } from "@webiny/
|
|
2
|
-
import { CoreGraphQLSchemaFactory } from "@webiny/
|
|
1
|
+
import { GraphQLSchemaBuilder } from "@webiny/api-graphql/features/GraphQLSchemaBuilder/abstractions";
|
|
2
|
+
import { CoreGraphQLSchemaFactory } from "@webiny/api-graphql/graphql/abstractions.core.js";
|
|
3
3
|
export declare class SchedulerGraphQL implements CoreGraphQLSchemaFactory.Interface {
|
|
4
4
|
execute(builder: GraphQLSchemaBuilder.Interface): Promise<GraphQLSchemaBuilder.Interface>;
|
|
5
5
|
}
|
|
6
6
|
export declare const SchedulerGraphQLFactory: typeof SchedulerGraphQL & {
|
|
7
|
-
__abstraction: import("@webiny/di").Abstraction<import("@webiny/
|
|
7
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-graphql/graphql/abstractions.core.js").ICoreGraphQLSchemaFactory>;
|
|
8
8
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CoreGraphQLSchemaFactory } from "@webiny/
|
|
1
|
+
import { CoreGraphQLSchemaFactory } from "@webiny/api-graphql/graphql/abstractions.core.js";
|
|
2
2
|
import { GetScheduledActionUseCase } from "../features/GetScheduledAction/index.js";
|
|
3
|
-
import { ErrorResponse, ListResponse, Response } from "@webiny/
|
|
3
|
+
import { ErrorResponse, ListResponse, Response } from "@webiny/api-graphql/responses.js";
|
|
4
4
|
import { ListScheduledActionsUseCase } from "../features/ListScheduledActions/index.js";
|
|
5
5
|
import { ScheduleActionUseCase } from "../features/ScheduleAction/index.js";
|
|
6
6
|
import { CancelScheduledActionUseCase } from "../features/CancelScheduledAction/index.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql/SchedulerGraphQLFactory.js","sources":["../../src/graphql/SchedulerGraphQLFactory.ts"],"sourcesContent":["import { GraphQLSchemaBuilder } from \"@webiny/handler-graphql/features/GraphQLSchemaBuilder/abstractions\";\nimport { CoreGraphQLSchemaFactory } from \"@webiny/handler-graphql/graphql/abstractions.core.js\";\nimport { GetScheduledActionUseCase } from \"~/features/GetScheduledAction/index.js\";\nimport { ErrorResponse, ListResponse, Response } from \"@webiny/handler-graphql/responses.js\";\nimport { ListScheduledActionsUseCase } from \"~/features/ListScheduledActions/index.js\";\nimport { ScheduleActionUseCase } from \"~/features/ScheduleAction/index.js\";\nimport { CancelScheduledActionUseCase } from \"~/features/CancelScheduledAction/index.js\";\nimport { ScheduledActionNotFoundError } from \"~/domain/errors.js\";\nimport type { Identity, ScheduledActionType } from \"~/shared/abstractions.js\";\nimport { ScheduledActionMapper } from \"~/domain/ScheduledActionMapper.js\";\nimport { GetTargetScheduledActionUseCase } from \"~/features/GetTargetScheduledAction/index.js\";\n\ninterface IListScheduledActionsArgs extends ListScheduledActionsUseCase.Params {\n namespace: string;\n}\n\ninterface IScheduleRecordOutput {\n id: string;\n targetId: string;\n namespace: string;\n scheduledBy: Identity;\n publishOn: Date | null;\n unpublishOn: Date | null;\n actionType: ScheduledActionType;\n title: string;\n}\n\nexport class SchedulerGraphQL implements CoreGraphQLSchemaFactory.Interface {\n public async execute(\n builder: GraphQLSchemaBuilder.Interface\n ): Promise<GraphQLSchemaBuilder.Interface> {\n builder.addTypeDefs(`\n enum ScheduleRecordType {\n publish\n unpublish\n }\n \n type ScheduleError {\n message: String!\n code: String\n data: JSON\n stack: String\n }\n \n type ScheduleListMeta {\n hasMoreItems: Boolean!\n totalCount: Int!\n cursor: String\n }\n \n type ScheduleIdentity {\n id: String!\n displayName: String\n type: String\n }\n \n type ScheduleRecord {\n id: ID!\n targetId: String!\n namespace: String!\n scheduledBy: ScheduleIdentity!\n publishOn: DateTime\n unpublishOn: DateTime\n actionType: ScheduleRecordType!\n title: String!\n }\n\n type GetScheduledActionResponse {\n data: ScheduleRecord\n error: ScheduleError\n }\n\n type ListScheduledActionsResponse {\n data: [ScheduleRecord!]\n error: ScheduleError\n meta: ScheduleListMeta\n }\n\n type ScheduleActionResponse {\n data: ScheduleRecord\n error: ScheduleError\n }\n\n type CancelScheduledActionResponse {\n data: Boolean\n error: ScheduleError\n }\n\n input ListScheduledActionsWhereInput {\n targetId: String\n targetId_in: [String!]\n title: String\n title_contains: String\n title_not_contains: String\n actionType: ScheduleRecordType\n actionType_in: [ScheduleRecordType!]\n scheduledBy: String\n scheduledBy_in: [String!]\n scheduledFor: DateTime\n scheduledFor_gte: DateTime\n scheduledFor_lte: DateTime\n }\n\n enum ListScheduledActionsSorter {\n title_ASC\n title_DESC\n scheduledFor_ASC\n scheduledFor_DESC\n }\n \n type SchedulerQuery {\n _empty: String\n }\n \n type SchedulerMutation {\n _empty: String\n }\n\n extend type SchedulerQuery {\n # Fetch scheduled action by its own ID\n getScheduledAction(namespace: String!, id: ID!): GetScheduledActionResponse!\n \n # Fetch scheduled action by target ID\n getTargetScheduledAction(namespace: String!, id: ID!): GetScheduledActionResponse!\n \n listScheduledActions(\n namespace: String!\n where: ListScheduledActionsWhereInput\n sort: [ListScheduledActionsSorter!]\n limit: Int\n after: String\n ): ListScheduledActionsResponse!\n }\n\n extend type SchedulerMutation {\n scheduleAction(\n namespace: String!\n targetId: ID!\n immediately: Boolean\n scheduleFor: DateTime\n actionType: ScheduleRecordType!\n ): ScheduleActionResponse!\n \n cancelScheduledAction(namespace: String!, id: ID!): CancelScheduledActionResponse!\n }\n \n extend type Query {\n scheduler: SchedulerQuery\n }\n \n extend type Mutation {\n scheduler: SchedulerMutation\n }\n `);\n\n builder.addResolver({\n path: \"Query.scheduler\",\n resolver: () => {\n return async () => {\n return {};\n };\n }\n });\n builder.addResolver({\n path: \"Mutation.scheduler\",\n resolver: () => {\n return async () => {\n return {};\n };\n }\n });\n\n builder.addResolver<GetScheduledActionUseCase.Params>({\n path: \"SchedulerQuery.getScheduledAction\",\n dependencies: [GetScheduledActionUseCase],\n resolver: (useCase: GetScheduledActionUseCase.Interface) => {\n return async ({ args }) => {\n const result = await useCase.execute(args);\n\n if (result.isFail()) {\n if (result.error instanceof ScheduledActionNotFoundError) {\n return new Response(null);\n }\n return new ErrorResponse(result.error);\n }\n\n return new Response<IScheduleRecordOutput>(\n ScheduledActionMapper.toGraphQL(result.value)\n );\n };\n }\n });\n\n builder.addResolver<GetTargetScheduledActionUseCase.Params>({\n path: \"SchedulerQuery.getTargetScheduledAction\",\n dependencies: [GetTargetScheduledActionUseCase],\n resolver: (useCase: GetTargetScheduledActionUseCase.Interface) => {\n return async ({ args }) => {\n const result = await useCase.execute(args);\n\n if (result.isFail()) {\n if (result.error instanceof ScheduledActionNotFoundError) {\n return new Response(null);\n }\n return new ErrorResponse(result.error);\n }\n\n return new Response<IScheduleRecordOutput>(\n ScheduledActionMapper.toGraphQL(result.value)\n );\n };\n }\n });\n\n builder.addResolver<IListScheduledActionsArgs>({\n path: \"SchedulerQuery.listScheduledActions\",\n dependencies: [ListScheduledActionsUseCase],\n resolver: (useCase: ListScheduledActionsUseCase.Interface) => {\n return async ({ args }) => {\n const result = await useCase.execute({\n ...args,\n where: {\n ...args.where,\n namespace: args.namespace\n }\n });\n\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n\n return new ListResponse<IScheduleRecordOutput>(\n result.value.items.map(item => {\n return ScheduledActionMapper.toGraphQL(item);\n }),\n result.value.meta\n );\n };\n }\n });\n\n builder.addResolver<ScheduleActionUseCase.Params>({\n path: \"SchedulerMutation.scheduleAction\",\n dependencies: [ScheduleActionUseCase],\n resolver: (useCase: ScheduleActionUseCase.Interface) => {\n return async ({ args }) => {\n const result = await useCase.execute(args);\n\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n\n return new Response<IScheduleRecordOutput>(\n ScheduledActionMapper.toGraphQL(result.value)\n );\n };\n }\n });\n\n builder.addResolver<CancelScheduledActionUseCase.Params>({\n path: \"SchedulerMutation.cancelScheduledAction\",\n dependencies: [CancelScheduledActionUseCase],\n resolver: (useCase: CancelScheduledActionUseCase.Interface) => {\n return async ({ args }) => {\n const result = await useCase.execute(args);\n\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n\n return new Response<boolean>(result.value);\n };\n }\n });\n\n return builder;\n }\n}\n\nexport const SchedulerGraphQLFactory = CoreGraphQLSchemaFactory.createImplementation({\n dependencies: [],\n implementation: SchedulerGraphQL\n});\n"],"names":["SchedulerGraphQL","builder","GetScheduledActionUseCase","useCase","args","result","ScheduledActionNotFoundError","Response","ErrorResponse","ScheduledActionMapper","GetTargetScheduledActionUseCase","ListScheduledActionsUseCase","ListResponse","item","ScheduleActionUseCase","CancelScheduledActionUseCase","SchedulerGraphQLFactory","CoreGraphQLSchemaFactory"],"mappings":";;;;;;;;;AA2BO,MAAMA;IACT,MAAa,QACTC,OAAuC,EACA;QACvCA,QAAQ,WAAW,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QA0HrB,CAAC;QAEDA,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,UAAU,IACC,UACI,EAAC;QAGpB;QACAA,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,UAAU,IACC,UACI,EAAC;QAGpB;QAEAA,QAAQ,WAAW,CAAmC;YAClD,MAAM;YACN,cAAc;gBAACC;aAA0B;YACzC,UAAU,CAACC,UACA,OAAO,EAAEC,IAAI,EAAE;oBAClB,MAAMC,SAAS,MAAMF,QAAQ,OAAO,CAACC;oBAErC,IAAIC,OAAO,MAAM,IAAI;wBACjB,IAAIA,OAAO,KAAK,YAAYC,8BACxB,OAAO,IAAIC,SAAS;wBAExB,OAAO,IAAIC,cAAcH,OAAO,KAAK;oBACzC;oBAEA,OAAO,IAAIE,SACPE,sBAAsB,SAAS,CAACJ,OAAO,KAAK;gBAEpD;QAER;QAEAJ,QAAQ,WAAW,CAAyC;YACxD,MAAM;YACN,cAAc;gBAACS;aAAgC;YAC/C,UAAU,CAACP,UACA,OAAO,EAAEC,IAAI,EAAE;oBAClB,MAAMC,SAAS,MAAMF,QAAQ,OAAO,CAACC;oBAErC,IAAIC,OAAO,MAAM,IAAI;wBACjB,IAAIA,OAAO,KAAK,YAAYC,8BACxB,OAAO,IAAIC,SAAS;wBAExB,OAAO,IAAIC,cAAcH,OAAO,KAAK;oBACzC;oBAEA,OAAO,IAAIE,SACPE,sBAAsB,SAAS,CAACJ,OAAO,KAAK;gBAEpD;QAER;QAEAJ,QAAQ,WAAW,CAA4B;YAC3C,MAAM;YACN,cAAc;gBAACU;aAA4B;YAC3C,UAAU,CAACR,UACA,OAAO,EAAEC,IAAI,EAAE;oBAClB,MAAMC,SAAS,MAAMF,QAAQ,OAAO,CAAC;wBACjC,GAAGC,IAAI;wBACP,OAAO;4BACH,GAAGA,KAAK,KAAK;4BACb,WAAWA,KAAK,SAAS;wBAC7B;oBACJ;oBAEA,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIG,cAAcH,OAAO,KAAK;oBAGzC,OAAO,IAAIO,aACPP,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,CAACQ,CAAAA,OACZJ,sBAAsB,SAAS,CAACI,QAE3CR,OAAO,KAAK,CAAC,IAAI;gBAEzB;QAER;QAEAJ,QAAQ,WAAW,CAA+B;YAC9C,MAAM;YACN,cAAc;gBAACa;aAAsB;YACrC,UAAU,CAACX,UACA,OAAO,EAAEC,IAAI,EAAE;oBAClB,MAAMC,SAAS,MAAMF,QAAQ,OAAO,CAACC;oBAErC,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIG,cAAcH,OAAO,KAAK;oBAGzC,OAAO,IAAIE,SACPE,sBAAsB,SAAS,CAACJ,OAAO,KAAK;gBAEpD;QAER;QAEAJ,QAAQ,WAAW,CAAsC;YACrD,MAAM;YACN,cAAc;gBAACc;aAA6B;YAC5C,UAAU,CAACZ,UACA,OAAO,EAAEC,IAAI,EAAE;oBAClB,MAAMC,SAAS,MAAMF,QAAQ,OAAO,CAACC;oBAErC,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIG,cAAcH,OAAO,KAAK;oBAGzC,OAAO,IAAIE,SAAkBF,OAAO,KAAK;gBAC7C;QAER;QAEA,OAAOJ;IACX;AACJ;AAEO,MAAMe,0BAA0BC,yBAAyB,oBAAoB,CAAC;IACjF,cAAc,EAAE;IAChB,gBAAgBjB;AACpB"}
|
|
1
|
+
{"version":3,"file":"graphql/SchedulerGraphQLFactory.js","sources":["../../src/graphql/SchedulerGraphQLFactory.ts"],"sourcesContent":["import { GraphQLSchemaBuilder } from \"@webiny/api-graphql/features/GraphQLSchemaBuilder/abstractions\";\nimport { CoreGraphQLSchemaFactory } from \"@webiny/api-graphql/graphql/abstractions.core.js\";\nimport { GetScheduledActionUseCase } from \"~/features/GetScheduledAction/index.js\";\nimport { ErrorResponse, ListResponse, Response } from \"@webiny/api-graphql/responses.js\";\nimport { ListScheduledActionsUseCase } from \"~/features/ListScheduledActions/index.js\";\nimport { ScheduleActionUseCase } from \"~/features/ScheduleAction/index.js\";\nimport { CancelScheduledActionUseCase } from \"~/features/CancelScheduledAction/index.js\";\nimport { ScheduledActionNotFoundError } from \"~/domain/errors.js\";\nimport type { Identity, ScheduledActionType } from \"~/shared/abstractions.js\";\nimport { ScheduledActionMapper } from \"~/domain/ScheduledActionMapper.js\";\nimport { GetTargetScheduledActionUseCase } from \"~/features/GetTargetScheduledAction/index.js\";\n\ninterface IListScheduledActionsArgs extends ListScheduledActionsUseCase.Params {\n namespace: string;\n}\n\ninterface IScheduleRecordOutput {\n id: string;\n targetId: string;\n namespace: string;\n scheduledBy: Identity;\n publishOn: Date | null;\n unpublishOn: Date | null;\n actionType: ScheduledActionType;\n title: string;\n}\n\nexport class SchedulerGraphQL implements CoreGraphQLSchemaFactory.Interface {\n public async execute(\n builder: GraphQLSchemaBuilder.Interface\n ): Promise<GraphQLSchemaBuilder.Interface> {\n builder.addTypeDefs(`\n enum ScheduleRecordType {\n publish\n unpublish\n }\n \n type ScheduleError {\n message: String!\n code: String\n data: JSON\n stack: String\n }\n \n type ScheduleListMeta {\n hasMoreItems: Boolean!\n totalCount: Int!\n cursor: String\n }\n \n type ScheduleIdentity {\n id: String!\n displayName: String\n type: String\n }\n \n type ScheduleRecord {\n id: ID!\n targetId: String!\n namespace: String!\n scheduledBy: ScheduleIdentity!\n publishOn: DateTime\n unpublishOn: DateTime\n actionType: ScheduleRecordType!\n title: String!\n }\n\n type GetScheduledActionResponse {\n data: ScheduleRecord\n error: ScheduleError\n }\n\n type ListScheduledActionsResponse {\n data: [ScheduleRecord!]\n error: ScheduleError\n meta: ScheduleListMeta\n }\n\n type ScheduleActionResponse {\n data: ScheduleRecord\n error: ScheduleError\n }\n\n type CancelScheduledActionResponse {\n data: Boolean\n error: ScheduleError\n }\n\n input ListScheduledActionsWhereInput {\n targetId: String\n targetId_in: [String!]\n title: String\n title_contains: String\n title_not_contains: String\n actionType: ScheduleRecordType\n actionType_in: [ScheduleRecordType!]\n scheduledBy: String\n scheduledBy_in: [String!]\n scheduledFor: DateTime\n scheduledFor_gte: DateTime\n scheduledFor_lte: DateTime\n }\n\n enum ListScheduledActionsSorter {\n title_ASC\n title_DESC\n scheduledFor_ASC\n scheduledFor_DESC\n }\n \n type SchedulerQuery {\n _empty: String\n }\n \n type SchedulerMutation {\n _empty: String\n }\n\n extend type SchedulerQuery {\n # Fetch scheduled action by its own ID\n getScheduledAction(namespace: String!, id: ID!): GetScheduledActionResponse!\n \n # Fetch scheduled action by target ID\n getTargetScheduledAction(namespace: String!, id: ID!): GetScheduledActionResponse!\n \n listScheduledActions(\n namespace: String!\n where: ListScheduledActionsWhereInput\n sort: [ListScheduledActionsSorter!]\n limit: Int\n after: String\n ): ListScheduledActionsResponse!\n }\n\n extend type SchedulerMutation {\n scheduleAction(\n namespace: String!\n targetId: ID!\n immediately: Boolean\n scheduleFor: DateTime\n actionType: ScheduleRecordType!\n ): ScheduleActionResponse!\n \n cancelScheduledAction(namespace: String!, id: ID!): CancelScheduledActionResponse!\n }\n \n extend type Query {\n scheduler: SchedulerQuery\n }\n \n extend type Mutation {\n scheduler: SchedulerMutation\n }\n `);\n\n builder.addResolver({\n path: \"Query.scheduler\",\n resolver: () => {\n return async () => {\n return {};\n };\n }\n });\n builder.addResolver({\n path: \"Mutation.scheduler\",\n resolver: () => {\n return async () => {\n return {};\n };\n }\n });\n\n builder.addResolver<GetScheduledActionUseCase.Params>({\n path: \"SchedulerQuery.getScheduledAction\",\n dependencies: [GetScheduledActionUseCase],\n resolver: (useCase: GetScheduledActionUseCase.Interface) => {\n return async ({ args }) => {\n const result = await useCase.execute(args);\n\n if (result.isFail()) {\n if (result.error instanceof ScheduledActionNotFoundError) {\n return new Response(null);\n }\n return new ErrorResponse(result.error);\n }\n\n return new Response<IScheduleRecordOutput>(\n ScheduledActionMapper.toGraphQL(result.value)\n );\n };\n }\n });\n\n builder.addResolver<GetTargetScheduledActionUseCase.Params>({\n path: \"SchedulerQuery.getTargetScheduledAction\",\n dependencies: [GetTargetScheduledActionUseCase],\n resolver: (useCase: GetTargetScheduledActionUseCase.Interface) => {\n return async ({ args }) => {\n const result = await useCase.execute(args);\n\n if (result.isFail()) {\n if (result.error instanceof ScheduledActionNotFoundError) {\n return new Response(null);\n }\n return new ErrorResponse(result.error);\n }\n\n return new Response<IScheduleRecordOutput>(\n ScheduledActionMapper.toGraphQL(result.value)\n );\n };\n }\n });\n\n builder.addResolver<IListScheduledActionsArgs>({\n path: \"SchedulerQuery.listScheduledActions\",\n dependencies: [ListScheduledActionsUseCase],\n resolver: (useCase: ListScheduledActionsUseCase.Interface) => {\n return async ({ args }) => {\n const result = await useCase.execute({\n ...args,\n where: {\n ...args.where,\n namespace: args.namespace\n }\n });\n\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n\n return new ListResponse<IScheduleRecordOutput>(\n result.value.items.map(item => {\n return ScheduledActionMapper.toGraphQL(item);\n }),\n result.value.meta\n );\n };\n }\n });\n\n builder.addResolver<ScheduleActionUseCase.Params>({\n path: \"SchedulerMutation.scheduleAction\",\n dependencies: [ScheduleActionUseCase],\n resolver: (useCase: ScheduleActionUseCase.Interface) => {\n return async ({ args }) => {\n const result = await useCase.execute(args);\n\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n\n return new Response<IScheduleRecordOutput>(\n ScheduledActionMapper.toGraphQL(result.value)\n );\n };\n }\n });\n\n builder.addResolver<CancelScheduledActionUseCase.Params>({\n path: \"SchedulerMutation.cancelScheduledAction\",\n dependencies: [CancelScheduledActionUseCase],\n resolver: (useCase: CancelScheduledActionUseCase.Interface) => {\n return async ({ args }) => {\n const result = await useCase.execute(args);\n\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n\n return new Response<boolean>(result.value);\n };\n }\n });\n\n return builder;\n }\n}\n\nexport const SchedulerGraphQLFactory = CoreGraphQLSchemaFactory.createImplementation({\n dependencies: [],\n implementation: SchedulerGraphQL\n});\n"],"names":["SchedulerGraphQL","builder","GetScheduledActionUseCase","useCase","args","result","ScheduledActionNotFoundError","Response","ErrorResponse","ScheduledActionMapper","GetTargetScheduledActionUseCase","ListScheduledActionsUseCase","ListResponse","item","ScheduleActionUseCase","CancelScheduledActionUseCase","SchedulerGraphQLFactory","CoreGraphQLSchemaFactory"],"mappings":";;;;;;;;;AA2BO,MAAMA;IACT,MAAa,QACTC,OAAuC,EACA;QACvCA,QAAQ,WAAW,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QA0HrB,CAAC;QAEDA,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,UAAU,IACC,UACI,EAAC;QAGpB;QACAA,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,UAAU,IACC,UACI,EAAC;QAGpB;QAEAA,QAAQ,WAAW,CAAmC;YAClD,MAAM;YACN,cAAc;gBAACC;aAA0B;YACzC,UAAU,CAACC,UACA,OAAO,EAAEC,IAAI,EAAE;oBAClB,MAAMC,SAAS,MAAMF,QAAQ,OAAO,CAACC;oBAErC,IAAIC,OAAO,MAAM,IAAI;wBACjB,IAAIA,OAAO,KAAK,YAAYC,8BACxB,OAAO,IAAIC,SAAS;wBAExB,OAAO,IAAIC,cAAcH,OAAO,KAAK;oBACzC;oBAEA,OAAO,IAAIE,SACPE,sBAAsB,SAAS,CAACJ,OAAO,KAAK;gBAEpD;QAER;QAEAJ,QAAQ,WAAW,CAAyC;YACxD,MAAM;YACN,cAAc;gBAACS;aAAgC;YAC/C,UAAU,CAACP,UACA,OAAO,EAAEC,IAAI,EAAE;oBAClB,MAAMC,SAAS,MAAMF,QAAQ,OAAO,CAACC;oBAErC,IAAIC,OAAO,MAAM,IAAI;wBACjB,IAAIA,OAAO,KAAK,YAAYC,8BACxB,OAAO,IAAIC,SAAS;wBAExB,OAAO,IAAIC,cAAcH,OAAO,KAAK;oBACzC;oBAEA,OAAO,IAAIE,SACPE,sBAAsB,SAAS,CAACJ,OAAO,KAAK;gBAEpD;QAER;QAEAJ,QAAQ,WAAW,CAA4B;YAC3C,MAAM;YACN,cAAc;gBAACU;aAA4B;YAC3C,UAAU,CAACR,UACA,OAAO,EAAEC,IAAI,EAAE;oBAClB,MAAMC,SAAS,MAAMF,QAAQ,OAAO,CAAC;wBACjC,GAAGC,IAAI;wBACP,OAAO;4BACH,GAAGA,KAAK,KAAK;4BACb,WAAWA,KAAK,SAAS;wBAC7B;oBACJ;oBAEA,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIG,cAAcH,OAAO,KAAK;oBAGzC,OAAO,IAAIO,aACPP,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,CAACQ,CAAAA,OACZJ,sBAAsB,SAAS,CAACI,QAE3CR,OAAO,KAAK,CAAC,IAAI;gBAEzB;QAER;QAEAJ,QAAQ,WAAW,CAA+B;YAC9C,MAAM;YACN,cAAc;gBAACa;aAAsB;YACrC,UAAU,CAACX,UACA,OAAO,EAAEC,IAAI,EAAE;oBAClB,MAAMC,SAAS,MAAMF,QAAQ,OAAO,CAACC;oBAErC,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIG,cAAcH,OAAO,KAAK;oBAGzC,OAAO,IAAIE,SACPE,sBAAsB,SAAS,CAACJ,OAAO,KAAK;gBAEpD;QAER;QAEAJ,QAAQ,WAAW,CAAsC;YACrD,MAAM;YACN,cAAc;gBAACc;aAA6B;YAC5C,UAAU,CAACZ,UACA,OAAO,EAAEC,IAAI,EAAE;oBAClB,MAAMC,SAAS,MAAMF,QAAQ,OAAO,CAACC;oBAErC,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIG,cAAcH,OAAO,KAAK;oBAGzC,OAAO,IAAIE,SAAkBF,OAAO,KAAK;gBAC7C;QAER;QAEA,OAAOJ;IACX;AACJ;AAEO,MAAMe,0BAA0BC,yBAAyB,oBAAoB,CAAC;IACjF,cAAc,EAAE;IAChB,gBAAgBjB;AACpB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { SchedulerGraphQLFactory } from "./SchedulerGraphQLFactory.js";
|
|
3
|
+
const SchedulerGraphQLFactoryFeature = createFeature({
|
|
4
|
+
name: "SchedulerGraphQLFactory",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(SchedulerGraphQLFactory);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { SchedulerGraphQLFactoryFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql/feature.js","sources":["../../src/graphql/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { SchedulerGraphQLFactory } from \"./SchedulerGraphQLFactory.js\";\n\nexport const SchedulerGraphQLFactoryFeature = createFeature({\n name: \"SchedulerGraphQLFactory\",\n register(container) {\n container.register(SchedulerGraphQLFactory);\n }\n});\n"],"names":["SchedulerGraphQLFactoryFeature","createFeature","container","SchedulerGraphQLFactory"],"mappings":";;AAGO,MAAMA,iCAAiCC,cAAc;IACxD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { SchedulerService,
|
|
1
|
+
export { SchedulerService, ScheduledActionHandler } from "./shared/abstractions.js";
|
|
2
2
|
export type { IScheduledAction } from "./shared/abstractions.js";
|
|
3
3
|
export { ScheduledActionId } from "./domain/ScheduledActionId.js";
|
|
4
|
-
export {
|
|
4
|
+
export { SchedulerFeature } from "./SchedulerFeature.js";
|
|
5
|
+
export { ScheduledActionLambdaHandler } from "./ScheduledActionLambdaHandler.js";
|
package/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { ScheduledActionHandler,
|
|
1
|
+
export { ScheduledActionHandler, SchedulerService } from "./shared/abstractions.js";
|
|
2
2
|
export { ScheduledActionId } from "./domain/ScheduledActionId.js";
|
|
3
|
-
export {
|
|
3
|
+
export { SchedulerFeature } from "./SchedulerFeature.js";
|
|
4
|
+
export { ScheduledActionLambdaHandler } from "./ScheduledActionLambdaHandler.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-scheduler",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.6.0-alpha.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -18,30 +18,21 @@
|
|
|
18
18
|
"description": "A generic action scheduler.",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@webiny/api": "6.
|
|
22
|
-
"@webiny/api-core": "6.
|
|
23
|
-
"@webiny/api-
|
|
24
|
-
"@webiny/
|
|
25
|
-
"@webiny/
|
|
26
|
-
"@webiny/
|
|
27
|
-
"@webiny/
|
|
28
|
-
"@webiny/
|
|
29
|
-
"
|
|
30
|
-
"zod": "4.4.3"
|
|
21
|
+
"@webiny/api": "6.6.0-alpha.1",
|
|
22
|
+
"@webiny/api-core": "6.6.0-alpha.1",
|
|
23
|
+
"@webiny/api-graphql": "6.6.0-alpha.1",
|
|
24
|
+
"@webiny/api-headless-cms": "6.6.0-alpha.1",
|
|
25
|
+
"@webiny/event-handler-aws": "6.6.0-alpha.1",
|
|
26
|
+
"@webiny/event-handler-core": "6.6.0-alpha.1",
|
|
27
|
+
"@webiny/feature": "6.6.0-alpha.1",
|
|
28
|
+
"@webiny/utils": "6.6.0-alpha.1",
|
|
29
|
+
"graphql": "16.14.2"
|
|
31
30
|
},
|
|
32
31
|
"devDependencies": {
|
|
33
|
-
"@webiny/build-tools": "6.
|
|
34
|
-
"@webiny/db-dynamodb": "6.4.11",
|
|
35
|
-
"@webiny/handler": "6.4.11",
|
|
36
|
-
"@webiny/handler-aws": "6.4.11",
|
|
37
|
-
"@webiny/project-utils": "6.4.11",
|
|
38
|
-
"@webiny/testing": "6.4.11",
|
|
39
|
-
"@webiny/wcp": "6.4.11",
|
|
40
|
-
"aws-sdk-client-mock": "4.1.0",
|
|
41
|
-
"jest-dynalite": "3.6.1",
|
|
32
|
+
"@webiny/build-tools": "6.6.0-alpha.1",
|
|
42
33
|
"rimraf": "6.1.3",
|
|
43
|
-
"typescript": "
|
|
44
|
-
"vitest": "4.1.
|
|
34
|
+
"typescript": "7.0.2",
|
|
35
|
+
"vitest": "4.1.11"
|
|
45
36
|
},
|
|
46
37
|
"publishConfig": {
|
|
47
38
|
"access": "public"
|
package/shared/abstractions.d.ts
CHANGED
|
@@ -98,10 +98,16 @@ export declare namespace SchedulerService {
|
|
|
98
98
|
type ExistsParams = ISchedulerServiceExistsParams;
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
101
|
-
*
|
|
101
|
+
* Provides the scheduler's CMS model for the current request's tenant.
|
|
102
|
+
*
|
|
103
|
+
* A provider rather than the model itself: fetching a model is asynchronous and tenant-dependent,
|
|
104
|
+
* and DI resolution is synchronous — so an already-resolved `CmsModel` could only be supplied by a
|
|
105
|
+
* per-request hook running before every consumer. Consumers `await get()` at the point of use.
|
|
102
106
|
*/
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
+
export interface IScheduledActionModelProvider {
|
|
108
|
+
get(): Promise<CmsModel>;
|
|
109
|
+
}
|
|
110
|
+
export declare const ScheduledActionModelProvider: import("@webiny/di").Abstraction<IScheduledActionModelProvider>;
|
|
111
|
+
export declare namespace ScheduledActionModelProvider {
|
|
112
|
+
type Interface = IScheduledActionModelProvider;
|
|
107
113
|
}
|
package/shared/abstractions.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
2
|
const ScheduledActionHandler = createAbstraction("ScheduledActionHandler");
|
|
3
3
|
const SchedulerService = createAbstraction("SchedulerService");
|
|
4
|
-
const
|
|
5
|
-
export { ScheduledActionHandler,
|
|
4
|
+
const ScheduledActionModelProvider = createAbstraction("ScheduledActionModelProvider");
|
|
5
|
+
export { ScheduledActionHandler, ScheduledActionModelProvider, SchedulerService };
|
|
6
6
|
|
|
7
7
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared/abstractions.js","sources":["../../src/shared/abstractions.ts"],"sourcesContent":["import type { CmsModel } from \"@webiny/api-headless-cms/types/model.js\";\nimport { createAbstraction } from \"@webiny/feature/api\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { CmsEntry } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { SCHEDULED_ACTION_PUBLISH, SCHEDULED_ACTION_UNPUBLISH } from \"~/constants.js\";\n\n/**\n * Identity type - represents who scheduled an action\n */\nexport interface Identity {\n id: string;\n type: string;\n displayName: string;\n}\n\nexport type ScheduledActionType =\n | typeof SCHEDULED_ACTION_PUBLISH\n | typeof SCHEDULED_ACTION_UNPUBLISH;\n/**\n * Scheduled Action Record - The data stored for a scheduled action\n */\n\nexport interface IScheduledActionEntryValues<T> {\n namespace: string; // Resource scope: \"Cms/Entry/Article\", \"Mailer/Email\"\n actionType: ScheduledActionType;\n targetId: string; // Resource identifier (entry ID, email ID, etc.)\n scheduledBy: Identity;\n scheduledFor: string;\n title: string;\n payload: T; // Action-specific data\n error: string | undefined; // Error if execution failed\n}\n\nexport interface IScheduledActionEntry<T extends GenericRecord = GenericRecord> extends CmsEntry<\n IScheduledActionEntryValues<T>\n> {}\n\nexport interface IScheduledAction<T extends GenericRecord = GenericRecord> extends Omit<\n IScheduledActionEntryValues<T>,\n \"scheduledFor\"\n> {\n id: string;\n tenant: string;\n scheduledFor: Date;\n}\n\n/**\n * ScheduledActionHandler - Similar to EventHandler pattern\n *\n * Each application (CMS, Mailer, etc.) implements handlers for their actions.\n * This is the ONLY action abstraction needed.\n */\nexport interface IScheduledActionHandler {\n /**\n * Determines if this handler can handle the given action\n *\n * @param namespace - Resource scope (e.g., \"Cms/Entry/Article\")\n * @param actionType - Operation type (e.g., \"Publish\")\n */\n canHandle(namespace: string, actionType: ScheduledActionType): boolean;\n\n /**\n * Executes the scheduled action\n */\n handle(action: IScheduledAction<any>): Promise<void>;\n}\n\n/** Handle execution of a scheduled action. */\nexport const ScheduledActionHandler =\n createAbstraction<IScheduledActionHandler>(\"ScheduledActionHandler\");\n\nexport namespace ScheduledActionHandler {\n export type Interface = IScheduledActionHandler;\n}\n\n/**\n * SchedulerService - Cloud-agnostic scheduler service\n *\n * Abstracts the underlying scheduling infrastructure (AWS EventBridge, Azure Logic Apps, etc.)\n */\n\nexport interface ISchedulerServiceCreateParams {\n id: string;\n tenant: string;\n namespace: string;\n scheduleFor: Date;\n}\nexport interface ISchedulerServiceUpdateParams {\n id: string;\n tenant: string;\n namespace: string;\n scheduleFor: Date;\n}\n\nexport interface ISchedulerServiceDeleteParams {\n id: string;\n namespace: string;\n tenant: string;\n}\n\nexport interface ISchedulerServiceExistsParams {\n id: string;\n namespace: string;\n tenant: string;\n}\n\nexport interface ISchedulerService {\n create(params: ISchedulerServiceCreateParams): Promise<void>;\n update(params: ISchedulerServiceUpdateParams): Promise<void>;\n delete(params: ISchedulerServiceDeleteParams): Promise<void>;\n exists(params: ISchedulerServiceExistsParams): Promise<boolean>;\n}\n\n/** Core service for managing scheduled actions. */\nexport const SchedulerService = createAbstraction<ISchedulerService>(\"SchedulerService\");\n\nexport namespace SchedulerService {\n export type Interface = ISchedulerService;\n export type CreateParams = ISchedulerServiceCreateParams;\n export type UpdateParams = ISchedulerServiceUpdateParams;\n export type DeleteParams = ISchedulerServiceDeleteParams;\n export type ExistsParams = ISchedulerServiceExistsParams;\n}\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"shared/abstractions.js","sources":["../../src/shared/abstractions.ts"],"sourcesContent":["import type { CmsModel } from \"@webiny/api-headless-cms/types/model.js\";\nimport { createAbstraction } from \"@webiny/feature/api\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { CmsEntry } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { SCHEDULED_ACTION_PUBLISH, SCHEDULED_ACTION_UNPUBLISH } from \"~/constants.js\";\n\n/**\n * Identity type - represents who scheduled an action\n */\nexport interface Identity {\n id: string;\n type: string;\n displayName: string;\n}\n\nexport type ScheduledActionType =\n | typeof SCHEDULED_ACTION_PUBLISH\n | typeof SCHEDULED_ACTION_UNPUBLISH;\n/**\n * Scheduled Action Record - The data stored for a scheduled action\n */\n\nexport interface IScheduledActionEntryValues<T> {\n namespace: string; // Resource scope: \"Cms/Entry/Article\", \"Mailer/Email\"\n actionType: ScheduledActionType;\n targetId: string; // Resource identifier (entry ID, email ID, etc.)\n scheduledBy: Identity;\n scheduledFor: string;\n title: string;\n payload: T; // Action-specific data\n error: string | undefined; // Error if execution failed\n}\n\nexport interface IScheduledActionEntry<T extends GenericRecord = GenericRecord> extends CmsEntry<\n IScheduledActionEntryValues<T>\n> {}\n\nexport interface IScheduledAction<T extends GenericRecord = GenericRecord> extends Omit<\n IScheduledActionEntryValues<T>,\n \"scheduledFor\"\n> {\n id: string;\n tenant: string;\n scheduledFor: Date;\n}\n\n/**\n * ScheduledActionHandler - Similar to EventHandler pattern\n *\n * Each application (CMS, Mailer, etc.) implements handlers for their actions.\n * This is the ONLY action abstraction needed.\n */\nexport interface IScheduledActionHandler {\n /**\n * Determines if this handler can handle the given action\n *\n * @param namespace - Resource scope (e.g., \"Cms/Entry/Article\")\n * @param actionType - Operation type (e.g., \"Publish\")\n */\n canHandle(namespace: string, actionType: ScheduledActionType): boolean;\n\n /**\n * Executes the scheduled action\n */\n handle(action: IScheduledAction<any>): Promise<void>;\n}\n\n/** Handle execution of a scheduled action. */\nexport const ScheduledActionHandler =\n createAbstraction<IScheduledActionHandler>(\"ScheduledActionHandler\");\n\nexport namespace ScheduledActionHandler {\n export type Interface = IScheduledActionHandler;\n}\n\n/**\n * SchedulerService - Cloud-agnostic scheduler service\n *\n * Abstracts the underlying scheduling infrastructure (AWS EventBridge, Azure Logic Apps, etc.)\n */\n\nexport interface ISchedulerServiceCreateParams {\n id: string;\n tenant: string;\n namespace: string;\n scheduleFor: Date;\n}\nexport interface ISchedulerServiceUpdateParams {\n id: string;\n tenant: string;\n namespace: string;\n scheduleFor: Date;\n}\n\nexport interface ISchedulerServiceDeleteParams {\n id: string;\n namespace: string;\n tenant: string;\n}\n\nexport interface ISchedulerServiceExistsParams {\n id: string;\n namespace: string;\n tenant: string;\n}\n\nexport interface ISchedulerService {\n create(params: ISchedulerServiceCreateParams): Promise<void>;\n update(params: ISchedulerServiceUpdateParams): Promise<void>;\n delete(params: ISchedulerServiceDeleteParams): Promise<void>;\n exists(params: ISchedulerServiceExistsParams): Promise<boolean>;\n}\n\n/** Core service for managing scheduled actions. */\nexport const SchedulerService = createAbstraction<ISchedulerService>(\"SchedulerService\");\n\nexport namespace SchedulerService {\n export type Interface = ISchedulerService;\n export type CreateParams = ISchedulerServiceCreateParams;\n export type UpdateParams = ISchedulerServiceUpdateParams;\n export type DeleteParams = ISchedulerServiceDeleteParams;\n export type ExistsParams = ISchedulerServiceExistsParams;\n}\n\n/**\n * Provides the scheduler's CMS model for the current request's tenant.\n *\n * A provider rather than the model itself: fetching a model is asynchronous and tenant-dependent,\n * and DI resolution is synchronous — so an already-resolved `CmsModel` could only be supplied by a\n * per-request hook running before every consumer. Consumers `await get()` at the point of use.\n */\nexport interface IScheduledActionModelProvider {\n get(): Promise<CmsModel>;\n}\n\nexport const ScheduledActionModelProvider = createAbstraction<IScheduledActionModelProvider>(\n \"ScheduledActionModelProvider\"\n);\n\nexport namespace ScheduledActionModelProvider {\n export type Interface = IScheduledActionModelProvider;\n}\n"],"names":["ScheduledActionHandler","createAbstraction","SchedulerService","ScheduledActionModelProvider"],"mappings":";AAoEO,MAAMA,yBACTC,kBAA2C;AA6CxC,MAAMC,mBAAmBD,kBAAqC;AAqB9D,MAAME,+BAA+BF,kBACxC"}
|
package/context.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ContextPlugin } from "@webiny/api";
|
|
2
|
-
import type { SchedulerClient, SchedulerClientConfig } from "@webiny/aws-sdk/client-scheduler/index.js";
|
|
3
|
-
import type { CmsContext } from "@webiny/api-headless-cms/types/index.js";
|
|
4
|
-
export interface ICreateHeadlessCmsSchedulerContextParams {
|
|
5
|
-
getClient(config?: SchedulerClientConfig): Pick<SchedulerClient, "send">;
|
|
6
|
-
}
|
|
7
|
-
export declare const createSchedulerContext: (params: ICreateHeadlessCmsSchedulerContextParams) => (ContextPlugin<CmsContext> | import("@webiny/handler").RegisterExtensionPlugin<import("@webiny/handler/types.js").Context>)[];
|
package/context.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { ContextPlugin } from "@webiny/api";
|
|
2
|
-
import { getManifest } from "./manifest.js";
|
|
3
|
-
import { SCHEDULE_MODEL_ID } from "./constants.js";
|
|
4
|
-
import { ScheduledActionModel, SchedulerService } from "./shared/abstractions.js";
|
|
5
|
-
import { EventBridgeSchedulerService } from "./features/SchedulerService/EventBridgeSchedulerService.js";
|
|
6
|
-
import { VoidSchedulerService } from "./features/SchedulerService/VoidSchedulerService.js";
|
|
7
|
-
import { SchedulePrivateModel } from "./domain/SchedulePrivateModel.js";
|
|
8
|
-
import { SchedulerFeature } from "./features/SchedulerFeature.js";
|
|
9
|
-
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
10
|
-
import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel/index.js";
|
|
11
|
-
import { SchedulerGraphQLFactory } from "./graphql/index.js";
|
|
12
|
-
import { NamespaceHandlerExecutioner } from "./features/NamespaceHandler/NamespaceHandlerExecutioner.js";
|
|
13
|
-
import { SchedulerPermissionsResolver } from "./features/permissions/SchedulerPermissionsResolver.js";
|
|
14
|
-
import { createRegisterExtensionPlugin } from "@webiny/handler";
|
|
15
|
-
const createSchedulerContext = (params)=>{
|
|
16
|
-
const modelsPlugin = createRegisterExtensionPlugin((context)=>{
|
|
17
|
-
context.container.register(SchedulePrivateModel);
|
|
18
|
-
});
|
|
19
|
-
const schedulerContextPlugin = new ContextPlugin(async (context)=>{
|
|
20
|
-
const tenantContext = context.container.resolve(TenantContext);
|
|
21
|
-
const getModel = context.container.resolve(GetModelUseCase);
|
|
22
|
-
if (!tenantContext.getTenant()) return;
|
|
23
|
-
const manifest = await getManifest({
|
|
24
|
-
client: context.db.driver.getClient()
|
|
25
|
-
});
|
|
26
|
-
if (manifest.error) context.container.registerInstance(SchedulerService, new VoidSchedulerService());
|
|
27
|
-
else context.container.registerInstance(SchedulerService, new EventBridgeSchedulerService(params.getClient, {
|
|
28
|
-
lambdaArn: manifest.data.lambdaArn,
|
|
29
|
-
roleArn: manifest.data.roleArn
|
|
30
|
-
}));
|
|
31
|
-
context.container.register(SchedulerGraphQLFactory);
|
|
32
|
-
context.container.register(NamespaceHandlerExecutioner);
|
|
33
|
-
context.container.register(SchedulerPermissionsResolver);
|
|
34
|
-
const schedulerModelResult = await context.security.withoutAuthorization(async ()=>await getModel.execute(SCHEDULE_MODEL_ID));
|
|
35
|
-
if (schedulerModelResult.isFail()) throw schedulerModelResult.error;
|
|
36
|
-
context.container.registerInstance(ScheduledActionModel, schedulerModelResult.value);
|
|
37
|
-
SchedulerFeature.register(context.container);
|
|
38
|
-
});
|
|
39
|
-
return [
|
|
40
|
-
schedulerContextPlugin,
|
|
41
|
-
modelsPlugin
|
|
42
|
-
];
|
|
43
|
-
};
|
|
44
|
-
export { createSchedulerContext };
|
|
45
|
-
|
|
46
|
-
//# sourceMappingURL=context.js.map
|
package/context.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sources":["../src/context.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport type {\n SchedulerClient,\n SchedulerClientConfig\n} from \"@webiny/aws-sdk/client-scheduler/index.js\";\nimport { getManifest } from \"~/manifest.js\";\nimport type { CmsContext } from \"@webiny/api-headless-cms/types/index.js\";\nimport { SCHEDULE_MODEL_ID } from \"./constants.js\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { ScheduledActionModel, SchedulerService } from \"~/shared/abstractions.js\";\nimport { EventBridgeSchedulerService } from \"~/features/SchedulerService/EventBridgeSchedulerService.js\";\nimport { VoidSchedulerService } from \"~/features/SchedulerService/VoidSchedulerService.js\";\nimport { SchedulePrivateModel } from \"~/domain/SchedulePrivateModel.js\";\nimport { SchedulerFeature } from \"./features/SchedulerFeature.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { SchedulerGraphQLFactory } from \"~/graphql/index.js\";\nimport { NamespaceHandlerExecutioner } from \"~/features/NamespaceHandler/NamespaceHandlerExecutioner.js\";\nimport { SchedulerPermissionsResolver } from \"~/features/permissions/SchedulerPermissionsResolver.js\";\nimport { createRegisterExtensionPlugin } from \"@webiny/handler\";\n\nexport interface ICreateHeadlessCmsSchedulerContextParams {\n getClient(config?: SchedulerClientConfig): Pick<SchedulerClient, \"send\">;\n}\n\nexport const createSchedulerContext = (params: ICreateHeadlessCmsSchedulerContextParams) => {\n const modelsPlugin = createRegisterExtensionPlugin(context => {\n context.container.register(SchedulePrivateModel);\n });\n\n const schedulerContextPlugin = new ContextPlugin<CmsContext>(async context => {\n const tenantContext = context.container.resolve(TenantContext);\n const getModel = context.container.resolve(GetModelUseCase);\n\n if (!tenantContext.getTenant()) {\n return;\n }\n\n const manifest = await getManifest({\n client: context.db.driver.getClient() as DynamoDBDocument\n });\n\n if (manifest.error) {\n context.container.registerInstance(SchedulerService, new VoidSchedulerService());\n } else {\n // TODO: in the future, extract AWS specific implementation into a separate package\n context.container.registerInstance(\n SchedulerService,\n new EventBridgeSchedulerService(params.getClient, {\n lambdaArn: manifest.data.lambdaArn,\n roleArn: manifest.data.roleArn\n })\n );\n }\n\n context.container.register(SchedulerGraphQLFactory);\n context.container.register(NamespaceHandlerExecutioner);\n context.container.register(SchedulerPermissionsResolver);\n\n const schedulerModelResult = await context.security.withoutAuthorization(async () => {\n return await getModel.execute(SCHEDULE_MODEL_ID);\n });\n if (schedulerModelResult.isFail()) {\n throw schedulerModelResult.error;\n }\n context.container.registerInstance(ScheduledActionModel, schedulerModelResult.value);\n\n // Register all features\n SchedulerFeature.register(context.container);\n });\n\n return [schedulerContextPlugin, modelsPlugin];\n};\n"],"names":["createSchedulerContext","params","modelsPlugin","createRegisterExtensionPlugin","context","SchedulePrivateModel","schedulerContextPlugin","ContextPlugin","tenantContext","TenantContext","getModel","GetModelUseCase","manifest","getManifest","SchedulerService","VoidSchedulerService","EventBridgeSchedulerService","SchedulerGraphQLFactory","NamespaceHandlerExecutioner","SchedulerPermissionsResolver","schedulerModelResult","SCHEDULE_MODEL_ID","ScheduledActionModel","SchedulerFeature"],"mappings":";;;;;;;;;;;;;;AAyBO,MAAMA,yBAAyB,CAACC;IACnC,MAAMC,eAAeC,8BAA8BC,CAAAA;QAC/CA,QAAQ,SAAS,CAAC,QAAQ,CAACC;IAC/B;IAEA,MAAMC,yBAAyB,IAAIC,cAA0B,OAAMH;QAC/D,MAAMI,gBAAgBJ,QAAQ,SAAS,CAAC,OAAO,CAACK;QAChD,MAAMC,WAAWN,QAAQ,SAAS,CAAC,OAAO,CAACO;QAE3C,IAAI,CAACH,cAAc,SAAS,IACxB;QAGJ,MAAMI,WAAW,MAAMC,YAAY;YAC/B,QAAQT,QAAQ,EAAE,CAAC,MAAM,CAAC,SAAS;QACvC;QAEA,IAAIQ,SAAS,KAAK,EACdR,QAAQ,SAAS,CAAC,gBAAgB,CAACU,kBAAkB,IAAIC;aAGzDX,QAAQ,SAAS,CAAC,gBAAgB,CAC9BU,kBACA,IAAIE,4BAA4Bf,OAAO,SAAS,EAAE;YAC9C,WAAWW,SAAS,IAAI,CAAC,SAAS;YAClC,SAASA,SAAS,IAAI,CAAC,OAAO;QAClC;QAIRR,QAAQ,SAAS,CAAC,QAAQ,CAACa;QAC3Bb,QAAQ,SAAS,CAAC,QAAQ,CAACc;QAC3Bd,QAAQ,SAAS,CAAC,QAAQ,CAACe;QAE3B,MAAMC,uBAAuB,MAAMhB,QAAQ,QAAQ,CAAC,oBAAoB,CAAC,UAC9D,MAAMM,SAAS,OAAO,CAACW;QAElC,IAAID,qBAAqB,MAAM,IAC3B,MAAMA,qBAAqB,KAAK;QAEpChB,QAAQ,SAAS,CAAC,gBAAgB,CAACkB,sBAAsBF,qBAAqB,KAAK;QAGnFG,iBAAiB,QAAQ,CAACnB,QAAQ,SAAS;IAC/C;IAEA,OAAO;QAACE;QAAwBJ;KAAa;AACjD"}
|
package/createEventHandler.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { HandlerFactoryParams } from "@webiny/handler-aws/types.js";
|
|
2
|
-
import { SCHEDULED_ACTION_EVENT_IDENTIFIER } from "./constants.js";
|
|
3
|
-
export interface IScheduledActionEventPayload {
|
|
4
|
-
namespace: string;
|
|
5
|
-
id: string;
|
|
6
|
-
scheduleFor: string;
|
|
7
|
-
tenant: string;
|
|
8
|
-
}
|
|
9
|
-
export interface IScheduledActionEvent {
|
|
10
|
-
[SCHEDULED_ACTION_EVENT_IDENTIFIER]: IScheduledActionEventPayload;
|
|
11
|
-
}
|
|
12
|
-
export interface HandlerParams extends HandlerFactoryParams {
|
|
13
|
-
debug?: boolean;
|
|
14
|
-
}
|
|
15
|
-
export declare const createScheduledActionEventHandler: () => import("@webiny/handler-aws/raw/index.js").RawEventHandler<IScheduledActionEvent, import("@webiny/handler/types").Context, any>;
|
package/createEventHandler.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { registry } from "@webiny/handler-aws/registry.js";
|
|
2
|
-
import { createSourceHandler } from "@webiny/handler-aws/sourceHandler.js";
|
|
3
|
-
import { createEventHandler, createHandler } from "@webiny/handler-aws/raw/index.js";
|
|
4
|
-
import { SCHEDULED_ACTION_EVENT_IDENTIFIER } from "./constants.js";
|
|
5
|
-
import { ExecuteScheduledActionUseCase } from "./features/ExecuteScheduledAction/index.js";
|
|
6
|
-
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
7
|
-
import { GetTenantByIdUseCase } from "@webiny/api-core/exports/api/tenancy.js";
|
|
8
|
-
const canHandle = (event)=>{
|
|
9
|
-
if ("function" != typeof event?.hasOwnProperty) return false;
|
|
10
|
-
if (!event.hasOwnProperty(SCHEDULED_ACTION_EVENT_IDENTIFIER)) return false;
|
|
11
|
-
const value = event[SCHEDULED_ACTION_EVENT_IDENTIFIER];
|
|
12
|
-
return !!(value?.id && value?.scheduleFor);
|
|
13
|
-
};
|
|
14
|
-
const handler = createSourceHandler({
|
|
15
|
-
name: "handler-aws-event-bridge-scheduled-cms-action-event",
|
|
16
|
-
canUse: canHandle,
|
|
17
|
-
handle: async ({ params, event, context })=>createHandler(params)(event, context)
|
|
18
|
-
});
|
|
19
|
-
registry.register(handler);
|
|
20
|
-
const createScheduledActionEventHandler = ()=>createEventHandler({
|
|
21
|
-
canHandle: canHandle,
|
|
22
|
-
handle: async (params)=>{
|
|
23
|
-
const { payload, context } = params;
|
|
24
|
-
const input = payload[SCHEDULED_ACTION_EVENT_IDENTIFIER];
|
|
25
|
-
const tenantContext = context.container.resolve(TenantContext);
|
|
26
|
-
if (!input.tenant) input.tenant = tenantContext.getTenant().id;
|
|
27
|
-
const getTenantByIdUseCase = context.container.resolve(GetTenantByIdUseCase);
|
|
28
|
-
const tenantResult = await getTenantByIdUseCase.execute(input.tenant);
|
|
29
|
-
if (tenantResult.isFail()) throw tenantResult.error;
|
|
30
|
-
const tenant = tenantResult.value;
|
|
31
|
-
return tenantContext.withTenant(tenant, async ()=>{
|
|
32
|
-
const executeScheduledAction = context.container.resolve(ExecuteScheduledActionUseCase);
|
|
33
|
-
const result = await executeScheduledAction.execute(input);
|
|
34
|
-
if (result.isFail()) {
|
|
35
|
-
const error = result.error;
|
|
36
|
-
console.error(error.code, error.message);
|
|
37
|
-
throw error;
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
success: true
|
|
41
|
-
};
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
export { createScheduledActionEventHandler };
|
|
46
|
-
|
|
47
|
-
//# sourceMappingURL=createEventHandler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createEventHandler.js","sources":["../src/createEventHandler.ts"],"sourcesContent":["import { registry } from \"@webiny/handler-aws/registry.js\";\nimport type { HandlerFactoryParams } from \"@webiny/handler-aws/types.js\";\nimport { createSourceHandler } from \"@webiny/handler-aws/sourceHandler.js\";\nimport { createEventHandler, createHandler } from \"@webiny/handler-aws/raw/index.js\";\nimport { SCHEDULED_ACTION_EVENT_IDENTIFIER } from \"~/constants.js\";\nimport { ExecuteScheduledActionUseCase } from \"~/features/ExecuteScheduledAction/index.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { GetTenantByIdUseCase } from \"@webiny/api-core/exports/api/tenancy.js\";\n\nexport interface IScheduledActionEventPayload {\n namespace: string;\n id: string;\n scheduleFor: string;\n tenant: string;\n}\n\nexport interface IScheduledActionEvent {\n [SCHEDULED_ACTION_EVENT_IDENTIFIER]: IScheduledActionEventPayload;\n}\n\nexport interface HandlerParams extends HandlerFactoryParams {\n debug?: boolean;\n}\n\nconst canHandle = (event: Partial<IScheduledActionEvent>): boolean => {\n if (typeof event?.hasOwnProperty !== \"function\") {\n return false;\n } else if (!event.hasOwnProperty(SCHEDULED_ACTION_EVENT_IDENTIFIER)) {\n return false;\n }\n\n const value = event[SCHEDULED_ACTION_EVENT_IDENTIFIER];\n return !!(value?.id && value?.scheduleFor);\n};\n\nconst handler = createSourceHandler<IScheduledActionEvent, HandlerParams>({\n name: \"handler-aws-event-bridge-scheduled-cms-action-event\",\n canUse: canHandle,\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n\nexport const createScheduledActionEventHandler = () => {\n return createEventHandler<IScheduledActionEvent>({\n canHandle,\n handle: async params => {\n const { payload, context } = params;\n const input = payload[SCHEDULED_ACTION_EVENT_IDENTIFIER];\n\n const tenantContext = context.container.resolve(TenantContext);\n /**\n * Use default tenant if tenant is not provided in the payload.\n * This allows backward compatibility with existing scheduled actions that do not have tenant information in their payload.\n */\n if (!input.tenant) {\n input.tenant = tenantContext.getTenant().id;\n }\n const getTenantByIdUseCase = context.container.resolve(GetTenantByIdUseCase);\n const tenantResult = await getTenantByIdUseCase.execute(input.tenant);\n if (tenantResult.isFail()) {\n throw tenantResult.error;\n }\n const tenant = tenantResult.value;\n\n /**\n * No need to re-load ScheduledActionModel here. CMS repositories use RuntimeTenant\n * to stamp the correct tenant on models/entries before passing them to storage operations.\n */\n return tenantContext.withTenant(tenant, async () => {\n const executeScheduledAction = context.container.resolve(\n ExecuteScheduledActionUseCase\n );\n const result = await 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 return {\n success: true\n };\n });\n }\n });\n};\n"],"names":["canHandle","event","SCHEDULED_ACTION_EVENT_IDENTIFIER","value","handler","createSourceHandler","params","context","createHandler","registry","createScheduledActionEventHandler","createEventHandler","payload","input","tenantContext","TenantContext","getTenantByIdUseCase","GetTenantByIdUseCase","tenantResult","tenant","executeScheduledAction","ExecuteScheduledActionUseCase","result","error","console"],"mappings":";;;;;;;AAwBA,MAAMA,YAAY,CAACC;IACf,IAAI,AAAiC,cAAjC,OAAOA,OAAO,gBACd,OAAO;IACJ,IAAI,CAACA,MAAM,cAAc,CAACC,oCAC7B,OAAO;IAGX,MAAMC,QAAQF,KAAK,CAACC,kCAAkC;IACtD,OAAO,CAAC,CAAEC,CAAAA,OAAO,MAAMA,OAAO,WAAU;AAC5C;AAEA,MAAMC,UAAUC,oBAA0D;IACtE,MAAM;IACN,QAAQL;IACR,QAAQ,OAAO,EAAEM,MAAM,EAAEL,KAAK,EAAEM,OAAO,EAAE,GAC9BC,cAAcF,QAAQL,OAAOM;AAE5C;AAEAE,SAAS,QAAQ,CAACL;AAEX,MAAMM,oCAAoC,IACtCC,mBAA0C;QAC7CX,WAAAA;QACA,QAAQ,OAAMM;YACV,MAAM,EAAEM,OAAO,EAAEL,OAAO,EAAE,GAAGD;YAC7B,MAAMO,QAAQD,OAAO,CAACV,kCAAkC;YAExD,MAAMY,gBAAgBP,QAAQ,SAAS,CAAC,OAAO,CAACQ;YAKhD,IAAI,CAACF,MAAM,MAAM,EACbA,MAAM,MAAM,GAAGC,cAAc,SAAS,GAAG,EAAE;YAE/C,MAAME,uBAAuBT,QAAQ,SAAS,CAAC,OAAO,CAACU;YACvD,MAAMC,eAAe,MAAMF,qBAAqB,OAAO,CAACH,MAAM,MAAM;YACpE,IAAIK,aAAa,MAAM,IACnB,MAAMA,aAAa,KAAK;YAE5B,MAAMC,SAASD,aAAa,KAAK;YAMjC,OAAOJ,cAAc,UAAU,CAACK,QAAQ;gBACpC,MAAMC,yBAAyBb,QAAQ,SAAS,CAAC,OAAO,CACpDc;gBAEJ,MAAMC,SAAS,MAAMF,uBAAuB,OAAO,CAACP;gBAEpD,IAAIS,OAAO,MAAM,IAAI;oBACjB,MAAMC,QAAQD,OAAO,KAAK;oBAC1BE,QAAQ,KAAK,CAACD,MAAM,IAAI,EAAEA,MAAM,OAAO;oBACvC,MAAMA;gBACV;gBACA,OAAO;oBACH,SAAS;gBACb;YACJ;QACJ;IACJ"}
|
package/createScheduler.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from "@webiny/plugins/types.js";
|
|
2
|
-
import { SchedulerClient, SchedulerClientConfig } from "@webiny/aws-sdk/client-scheduler/index.js";
|
|
3
|
-
export interface ICreateSchedulerParams {
|
|
4
|
-
getClient(config?: SchedulerClientConfig): Pick<SchedulerClient, "send">;
|
|
5
|
-
}
|
|
6
|
-
export declare const createScheduler: (params: ICreateSchedulerParams) => Plugin[];
|
package/createScheduler.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { createSchedulerContext } from "./context.js";
|
|
2
|
-
import { createScheduledActionEventHandler } from "./createEventHandler.js";
|
|
3
|
-
const createScheduler = (params)=>[
|
|
4
|
-
createScheduledActionEventHandler(),
|
|
5
|
-
...createSchedulerContext(params)
|
|
6
|
-
];
|
|
7
|
-
export { createScheduler };
|
|
8
|
-
|
|
9
|
-
//# sourceMappingURL=createScheduler.js.map
|
package/createScheduler.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createScheduler.js","sources":["../src/createScheduler.ts"],"sourcesContent":["import type { Plugin } from \"@webiny/plugins/types.js\";\nimport { SchedulerClient, SchedulerClientConfig } from \"@webiny/aws-sdk/client-scheduler/index.js\";\nimport { createSchedulerContext } from \"~/context.js\";\nimport { createScheduledActionEventHandler } from \"~/createEventHandler.js\";\n\nexport interface ICreateSchedulerParams {\n getClient(config?: SchedulerClientConfig): Pick<SchedulerClient, \"send\">;\n}\nexport const createScheduler = (params: ICreateSchedulerParams): Plugin[] => {\n return [\n /**\n * Handler for the Scheduled Action Event.\n */\n createScheduledActionEventHandler(),\n ...createSchedulerContext(params)\n ];\n};\n"],"names":["createScheduler","params","createScheduledActionEventHandler","createSchedulerContext"],"mappings":";;AAQO,MAAMA,kBAAkB,CAACC,SACrB;QAIHC;WACGC,uBAAuBF;KAC7B"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { SchedulerService } from "../../shared/abstractions.js";
|
|
2
|
-
import { type SchedulerClient } from "@webiny/aws-sdk/client-scheduler/index.js";
|
|
3
|
-
export interface ISchedulerConfig {
|
|
4
|
-
lambdaArn: string;
|
|
5
|
-
roleArn: string;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* AWS EventBridge Scheduler implementation
|
|
9
|
-
*
|
|
10
|
-
* This is the AWS-specific implementation of the cloud-agnostic SchedulerService abstraction.
|
|
11
|
-
*
|
|
12
|
-
* Manages schedules in AWS EventBridge Scheduler for triggering Lambda functions
|
|
13
|
-
* at specified future times.
|
|
14
|
-
*/
|
|
15
|
-
export declare class EventBridgeSchedulerService implements SchedulerService.Interface {
|
|
16
|
-
private getClient;
|
|
17
|
-
private config;
|
|
18
|
-
constructor(getClient: (config?: any) => Pick<SchedulerClient, "send">, config: ISchedulerConfig);
|
|
19
|
-
create(params: SchedulerService.CreateParams): Promise<void>;
|
|
20
|
-
update(params: SchedulerService.UpdateParams): Promise<void>;
|
|
21
|
-
delete(params: SchedulerService.DeleteParams): Promise<void>;
|
|
22
|
-
exists(params: SchedulerService.ExistsParams): Promise<boolean>;
|
|
23
|
-
private createInternal;
|
|
24
|
-
private updateInternal;
|
|
25
|
-
private createScheduleExpression;
|
|
26
|
-
private createScheduledActionEventInput;
|
|
27
|
-
private createScheduledActionEventPayload;
|
|
28
|
-
private createScheduleName;
|
|
29
|
-
}
|