@webiny/api-scheduler 0.0.0-unstable.ac6ebf63c6 → 0.0.0-unstable.b6d7105cee

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.
Files changed (155) hide show
  1. package/constants.d.ts +5 -0
  2. package/constants.js +11 -8
  3. package/constants.js.map +1 -1
  4. package/context.d.ts +2 -6
  5. package/context.js +29 -31
  6. package/context.js.map +1 -1
  7. package/domain/SchedulePrivateModel.js +25 -22
  8. package/domain/SchedulePrivateModel.js.map +1 -1
  9. package/domain/ScheduledActionId.js +12 -4
  10. package/domain/ScheduledActionId.js.map +1 -1
  11. package/domain/ScheduledActionIdWithVersion.js +5 -6
  12. package/domain/ScheduledActionIdWithVersion.js.map +1 -1
  13. package/domain/ScheduledActionMapper.d.ts +16 -0
  14. package/domain/ScheduledActionMapper.js +37 -0
  15. package/domain/ScheduledActionMapper.js.map +1 -0
  16. package/domain/errors.d.ts +19 -1
  17. package/domain/errors.js +54 -56
  18. package/domain/errors.js.map +1 -1
  19. package/domain/isValidDate.d.ts +1 -1
  20. package/domain/isValidDate.js +4 -9
  21. package/domain/isValidDate.js.map +1 -1
  22. package/domain/permissionsSchema.d.ts +9 -0
  23. package/domain/permissionsSchema.js +18 -0
  24. package/domain/permissionsSchema.js.map +1 -0
  25. package/exports/api/scheduler.d.ts +10 -0
  26. package/exports/api/scheduler.js +8 -0
  27. package/features/CancelScheduledAction/CancelScheduledActionUseCase.d.ts +4 -2
  28. package/features/CancelScheduledAction/CancelScheduledActionUseCase.js +45 -61
  29. package/features/CancelScheduledAction/CancelScheduledActionUseCase.js.map +1 -1
  30. package/features/CancelScheduledAction/abstractions.d.ts +10 -2
  31. package/features/CancelScheduledAction/abstractions.js +2 -10
  32. package/features/CancelScheduledAction/abstractions.js.map +1 -1
  33. package/features/CancelScheduledAction/feature.d.ts +4 -1
  34. package/features/CancelScheduledAction/feature.js +6 -12
  35. package/features/CancelScheduledAction/feature.js.map +1 -1
  36. package/features/CancelScheduledAction/index.js +0 -2
  37. package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.d.ts +1 -1
  38. package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js +65 -89
  39. package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js.map +1 -1
  40. package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.d.ts +2 -2
  41. package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.js +21 -25
  42. package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.js.map +1 -1
  43. package/features/ExecuteScheduledAction/abstractions.d.ts +10 -2
  44. package/features/ExecuteScheduledAction/abstractions.js +12 -36
  45. package/features/ExecuteScheduledAction/abstractions.js.map +1 -1
  46. package/features/ExecuteScheduledAction/feature.d.ts +4 -1
  47. package/features/ExecuteScheduledAction/feature.js +7 -13
  48. package/features/ExecuteScheduledAction/feature.js.map +1 -1
  49. package/features/ExecuteScheduledAction/index.js +0 -2
  50. package/features/GetScheduledAction/GetScheduledActionUseCase.d.ts +6 -2
  51. package/features/GetScheduledAction/GetScheduledActionUseCase.js +38 -39
  52. package/features/GetScheduledAction/GetScheduledActionUseCase.js.map +1 -1
  53. package/features/GetScheduledAction/abstractions.d.ts +9 -2
  54. package/features/GetScheduledAction/abstractions.js +2 -11
  55. package/features/GetScheduledAction/abstractions.js.map +1 -1
  56. package/features/GetScheduledAction/feature.d.ts +4 -1
  57. package/features/GetScheduledAction/feature.js +6 -12
  58. package/features/GetScheduledAction/feature.js.map +1 -1
  59. package/features/GetScheduledAction/index.js +0 -2
  60. package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.d.ts +32 -0
  61. package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.js +64 -0
  62. package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.js.map +1 -0
  63. package/features/GetTargetScheduledAction/abstractions.d.ts +24 -0
  64. package/features/GetTargetScheduledAction/abstractions.js +5 -0
  65. package/features/GetTargetScheduledAction/abstractions.js.map +1 -0
  66. package/features/GetTargetScheduledAction/feature.d.ts +10 -0
  67. package/features/GetTargetScheduledAction/feature.js +11 -0
  68. package/features/GetTargetScheduledAction/feature.js.map +1 -0
  69. package/features/{RunAction → GetTargetScheduledAction}/index.js +0 -2
  70. package/features/ListScheduledActions/ListScheduledActionsUseCase.d.ts +5 -1
  71. package/features/ListScheduledActions/ListScheduledActionsUseCase.js +53 -67
  72. package/features/ListScheduledActions/ListScheduledActionsUseCase.js.map +1 -1
  73. package/features/ListScheduledActions/abstractions.d.ts +11 -3
  74. package/features/ListScheduledActions/abstractions.js +2 -12
  75. package/features/ListScheduledActions/abstractions.js.map +1 -1
  76. package/features/ListScheduledActions/feature.d.ts +4 -1
  77. package/features/ListScheduledActions/feature.js +6 -12
  78. package/features/ListScheduledActions/feature.js.map +1 -1
  79. package/features/ListScheduledActions/index.js +0 -2
  80. package/features/NamespaceHandler/NamespaceHandlerExecutioner.d.ts +11 -0
  81. package/features/NamespaceHandler/NamespaceHandlerExecutioner.js +26 -0
  82. package/features/NamespaceHandler/NamespaceHandlerExecutioner.js.map +1 -0
  83. package/features/NamespaceHandler/abstractions.d.ts +50 -0
  84. package/features/NamespaceHandler/abstractions.js +6 -0
  85. package/features/NamespaceHandler/abstractions.js.map +1 -0
  86. package/features/NamespaceHandler/feature.d.ts +4 -0
  87. package/features/NamespaceHandler/feature.js +11 -0
  88. package/features/NamespaceHandler/feature.js.map +1 -0
  89. package/features/NamespaceHandler/index.d.ts +1 -0
  90. package/features/NamespaceHandler/index.js +1 -0
  91. package/features/ScheduleAction/ScheduleActionUseCase.d.ts +4 -4
  92. package/features/ScheduleAction/ScheduleActionUseCase.js +150 -143
  93. package/features/ScheduleAction/ScheduleActionUseCase.js.map +1 -1
  94. package/features/ScheduleAction/abstractions.d.ts +12 -11
  95. package/features/ScheduleAction/abstractions.js +2 -10
  96. package/features/ScheduleAction/abstractions.js.map +1 -1
  97. package/features/ScheduleAction/feature.d.ts +4 -1
  98. package/features/ScheduleAction/feature.js +6 -12
  99. package/features/ScheduleAction/feature.js.map +1 -1
  100. package/features/ScheduleAction/index.js +0 -2
  101. package/features/SchedulerFeature.d.ts +4 -1
  102. package/features/SchedulerFeature.js +12 -20
  103. package/features/SchedulerFeature.js.map +1 -1
  104. package/features/SchedulerService/VoidSchedulerService.d.ts +9 -9
  105. package/features/SchedulerService/VoidSchedulerService.js +17 -24
  106. package/features/SchedulerService/VoidSchedulerService.js.map +1 -1
  107. package/features/permissions/abstractions.d.ts +14 -0
  108. package/features/permissions/abstractions.js +6 -0
  109. package/features/permissions/abstractions.js.map +1 -0
  110. package/features/permissions/feature.d.ts +4 -0
  111. package/features/permissions/feature.js +7 -0
  112. package/features/permissions/feature.js.map +1 -0
  113. package/graphql/SchedulerGraphQLFactory.d.ts +8 -0
  114. package/graphql/SchedulerGraphQLFactory.js +219 -0
  115. package/graphql/SchedulerGraphQLFactory.js.map +1 -0
  116. package/graphql/feature.d.ts +4 -0
  117. package/graphql/feature.js +11 -0
  118. package/graphql/feature.js.map +1 -0
  119. package/graphql/index.d.ts +1 -0
  120. package/graphql/index.js +1 -0
  121. package/index.d.ts +1 -7
  122. package/index.js +2 -12
  123. package/package.json +21 -33
  124. package/shared/abstractions.d.ts +38 -8
  125. package/shared/abstractions.js +4 -29
  126. package/shared/abstractions.js.map +1 -1
  127. package/createEventHandler.d.ts +0 -13
  128. package/createEventHandler.js +0 -50
  129. package/createEventHandler.js.map +0 -1
  130. package/createScheduler.d.ts +0 -6
  131. package/createScheduler.js +0 -11
  132. package/createScheduler.js.map +0 -1
  133. package/features/CancelScheduledAction/index.js.map +0 -1
  134. package/features/ExecuteScheduledAction/index.js.map +0 -1
  135. package/features/GetScheduledAction/index.js.map +0 -1
  136. package/features/ListScheduledActions/index.js.map +0 -1
  137. package/features/RunAction/RunActionUseCase.d.ts +0 -23
  138. package/features/RunAction/RunActionUseCase.js +0 -37
  139. package/features/RunAction/RunActionUseCase.js.map +0 -1
  140. package/features/RunAction/abstractions.d.ts +0 -35
  141. package/features/RunAction/abstractions.js +0 -15
  142. package/features/RunAction/abstractions.js.map +0 -1
  143. package/features/RunAction/feature.d.ts +0 -7
  144. package/features/RunAction/feature.js +0 -17
  145. package/features/RunAction/feature.js.map +0 -1
  146. package/features/RunAction/index.js.map +0 -1
  147. package/features/ScheduleAction/index.js.map +0 -1
  148. package/features/SchedulerService/EventBridgeSchedulerService.d.ts +0 -26
  149. package/features/SchedulerService/EventBridgeSchedulerService.js +0 -131
  150. package/features/SchedulerService/EventBridgeSchedulerService.js.map +0 -1
  151. package/index.js.map +0 -1
  152. package/manifest.d.ts +0 -17
  153. package/manifest.js +0 -39
  154. package/manifest.js.map +0 -1
  155. /package/features/{RunAction → GetTargetScheduledAction}/index.d.ts +0 -0
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
- export const SCHEDULE_MODEL_ID = "wbySchedule";
2
- export const SCHEDULE_ID_PREFIX = "wby-schedule-";
3
- /**
4
- * Minimum number of seconds in the future that a schedule can be set.
5
- * Everything else will result in immediately running the action.
6
- */
7
- export const SCHEDULE_MIN_FUTURE_SECONDS = 65;
8
- export const SCHEDULED_ACTION_EVENT_IDENTIFIER = "WebinyScheduledAction";
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,"names":["SCHEDULE_MODEL_ID","SCHEDULE_ID_PREFIX","SCHEDULE_MIN_FUTURE_SECONDS","SCHEDULED_ACTION_EVENT_IDENTIFIER"],"sources":["constants.ts"],"sourcesContent":["export const SCHEDULE_MODEL_ID = \"wbySchedule\";\nexport const SCHEDULE_ID_PREFIX = \"wby-schedule-\";\n/**\n * Minimum number of seconds in the future that a schedule can be set.\n * Everything else will result in immediately running the action.\n */\nexport const SCHEDULE_MIN_FUTURE_SECONDS = 65;\n\nexport const SCHEDULED_ACTION_EVENT_IDENTIFIER = \"WebinyScheduledAction\";\n"],"mappings":"AAAA,OAAO,MAAMA,iBAAiB,GAAG,aAAa;AAC9C,OAAO,MAAMC,kBAAkB,GAAG,eAAe;AACjD;AACA;AACA;AACA;AACA,OAAO,MAAMC,2BAA2B,GAAG,EAAE;AAE7C,OAAO,MAAMC,iCAAiC,GAAG,uBAAuB","ignoreList":[]}
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"}
package/context.d.ts CHANGED
@@ -1,7 +1,3 @@
1
- import { ContextPlugin } from "@webiny/api";
2
- import type { SchedulerClient, SchedulerClientConfig } from "@webiny/aws-sdk/client-scheduler/index.js";
3
1
  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>;
2
+ import { ContextPlugin } from "@webiny/api";
3
+ export declare const registerSchedulerExtension: () => (ContextPlugin<CmsContext> | import("@webiny/handler").RegisterExtensionPlugin<import("@webiny/handler/types").Context>)[];
package/context.js CHANGED
@@ -1,41 +1,39 @@
1
- import { ContextPlugin } from "@webiny/api";
2
- import { getManifest } from "./manifest.js";
3
1
  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";
2
+ import { ScheduledActionModel } from "./shared/abstractions.js";
7
3
  import { SchedulePrivateModel } from "./domain/SchedulePrivateModel.js";
8
4
  import { SchedulerFeature } from "./features/SchedulerFeature.js";
9
5
  import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
10
6
  import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel/index.js";
11
- export const createSchedulerContext = params => {
12
- return new ContextPlugin(async context => {
13
- const tenantContext = context.container.resolve(TenantContext);
14
- const getModel = context.container.resolve(GetModelUseCase);
15
- if (!tenantContext.getTenant()) {
16
- return;
17
- }
18
- const manifest = await getManifest({
19
- client: context.db.driver.getClient()
7
+ import { SchedulerPermissionsFeature } from "./features/permissions/feature.js";
8
+ import { ContextPlugin } from "@webiny/api";
9
+ import { createRegisterExtensionPlugin } from "@webiny/handler";
10
+ import { NamespaceHandlerExecutionerFeature } from "./features/NamespaceHandler/feature.js";
11
+ import { SchedulerGraphQLFactoryFeature } from "./graphql/feature.js";
12
+ const registerSchedulerExtension = ()=>{
13
+ const extensionPlugin = createRegisterExtensionPlugin(async (context)=>{
14
+ context.container.register(SchedulePrivateModel);
15
+ SchedulerPermissionsFeature.register(context.container);
16
+ SchedulerGraphQLFactoryFeature.register(context.container);
17
+ NamespaceHandlerExecutionerFeature.register(context.container);
18
+ SchedulerFeature.register(context.container);
20
19
  });
21
- if (manifest.error) {
22
- context.container.registerInstance(SchedulerService, new VoidSchedulerService());
23
- } else {
24
- // TODO: in the future, extract AWS specific implementation into a separate package
25
- context.container.registerInstance(SchedulerService, new EventBridgeSchedulerService(params.getClient, {
26
- lambdaArn: manifest.data.lambdaArn,
27
- roleArn: manifest.data.roleArn
28
- }));
29
- }
30
- context.container.register(SchedulePrivateModel);
31
- await context.security.withoutAuthorization(async () => {
32
- const schedulerModel = await getModel.execute(SCHEDULE_MODEL_ID);
33
- context.container.registerInstance(ScheduledActionModel, schedulerModel.value);
20
+ extensionPlugin.name = "scheduler.base.extension";
21
+ const contextPlugin = new ContextPlugin(async (context)=>{
22
+ const tenantContext = context.container.resolve(TenantContext);
23
+ const getModel = context.container.resolve(GetModelUseCase);
24
+ if (!tenantContext.getTenant()) return;
25
+ await context.security.withoutAuthorization(async ()=>{
26
+ const schedulerModel = await getModel.execute(SCHEDULE_MODEL_ID);
27
+ if (schedulerModel.isFail()) throw schedulerModel.error;
28
+ context.container.registerInstance(ScheduledActionModel, schedulerModel.value);
29
+ });
34
30
  });
35
-
36
- // Register all features
37
- SchedulerFeature.register(context.container);
38
- });
31
+ contextPlugin.name = "scheduler.base.context";
32
+ return [
33
+ extensionPlugin,
34
+ contextPlugin
35
+ ];
39
36
  };
37
+ export { registerSchedulerExtension };
40
38
 
41
39
  //# sourceMappingURL=context.js.map
package/context.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["ContextPlugin","getManifest","SCHEDULE_MODEL_ID","ScheduledActionModel","SchedulerService","EventBridgeSchedulerService","VoidSchedulerService","SchedulePrivateModel","SchedulerFeature","TenantContext","GetModelUseCase","createSchedulerContext","params","context","tenantContext","container","resolve","getModel","getTenant","manifest","client","db","driver","getClient","error","registerInstance","lambdaArn","data","roleArn","register","security","withoutAuthorization","schedulerModel","execute","value"],"sources":["context.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport type {\n SchedulerClient,\n SchedulerClientConfig\n} from \"@webiny/aws-sdk/client-scheduler/index.js\";\nimport { getManifest } from \"~/manifest.js\";\nimport type { CmsContext } from \"@webiny/api-headless-cms/types/index.js\";\nimport { SCHEDULE_MODEL_ID } from \"./constants.js\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { ScheduledActionModel, SchedulerService } from \"~/shared/abstractions.js\";\nimport { EventBridgeSchedulerService } from \"~/features/SchedulerService/EventBridgeSchedulerService.js\";\nimport { VoidSchedulerService } from \"~/features/SchedulerService/VoidSchedulerService.js\";\nimport { SchedulePrivateModel } from \"~/domain/SchedulePrivateModel.js\";\nimport { SchedulerFeature } from \"./features/SchedulerFeature.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\n\nexport interface ICreateHeadlessCmsSchedulerContextParams {\n getClient(config?: SchedulerClientConfig): Pick<SchedulerClient, \"send\">;\n}\n\nexport const createSchedulerContext = (params: ICreateHeadlessCmsSchedulerContextParams) => {\n return new ContextPlugin<CmsContext>(async context => {\n const tenantContext = context.container.resolve(TenantContext);\n const getModel = context.container.resolve(GetModelUseCase);\n\n if (!tenantContext.getTenant()) {\n return;\n }\n\n const manifest = await getManifest({\n client: context.db.driver.getClient() as DynamoDBDocument\n });\n\n if (manifest.error) {\n context.container.registerInstance(SchedulerService, new VoidSchedulerService());\n } else {\n // TODO: in the future, extract AWS specific implementation into a separate package\n context.container.registerInstance(\n SchedulerService,\n new EventBridgeSchedulerService(params.getClient, {\n lambdaArn: manifest.data.lambdaArn,\n roleArn: manifest.data.roleArn\n })\n );\n }\n\n context.container.register(SchedulePrivateModel);\n\n await context.security.withoutAuthorization(async () => {\n const schedulerModel = await getModel.execute(SCHEDULE_MODEL_ID);\n context.container.registerInstance(ScheduledActionModel, schedulerModel.value);\n });\n\n // Register all features\n SchedulerFeature.register(context.container);\n });\n};\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,aAAa;AAK3C,SAASC,WAAW;AAEpB,SAASC,iBAAiB;AAE1B,SAASC,oBAAoB,EAAEC,gBAAgB;AAC/C,SAASC,2BAA2B;AACpC,SAASC,oBAAoB;AAC7B,SAASC,oBAAoB;AAC7B,SAASC,gBAAgB;AACzB,SAASC,aAAa,QAAQ,0DAA0D;AACxF,SAASC,eAAe,QAAQ,kEAAkE;AAMlG,OAAO,MAAMC,sBAAsB,GAAIC,MAAgD,IAAK;EACxF,OAAO,IAAIZ,aAAa,CAAa,MAAMa,OAAO,IAAI;IAClD,MAAMC,aAAa,GAAGD,OAAO,CAACE,SAAS,CAACC,OAAO,CAACP,aAAa,CAAC;IAC9D,MAAMQ,QAAQ,GAAGJ,OAAO,CAACE,SAAS,CAACC,OAAO,CAACN,eAAe,CAAC;IAE3D,IAAI,CAACI,aAAa,CAACI,SAAS,CAAC,CAAC,EAAE;MAC5B;IACJ;IAEA,MAAMC,QAAQ,GAAG,MAAMlB,WAAW,CAAC;MAC/BmB,MAAM,EAAEP,OAAO,CAACQ,EAAE,CAACC,MAAM,CAACC,SAAS,CAAC;IACxC,CAAC,CAAC;IAEF,IAAIJ,QAAQ,CAACK,KAAK,EAAE;MAChBX,OAAO,CAACE,SAAS,CAACU,gBAAgB,CAACrB,gBAAgB,EAAE,IAAIE,oBAAoB,CAAC,CAAC,CAAC;IACpF,CAAC,MAAM;MACH;MACAO,OAAO,CAACE,SAAS,CAACU,gBAAgB,CAC9BrB,gBAAgB,EAChB,IAAIC,2BAA2B,CAACO,MAAM,CAACW,SAAS,EAAE;QAC9CG,SAAS,EAAEP,QAAQ,CAACQ,IAAI,CAACD,SAAS;QAClCE,OAAO,EAAET,QAAQ,CAACQ,IAAI,CAACC;MAC3B,CAAC,CACL,CAAC;IACL;IAEAf,OAAO,CAACE,SAAS,CAACc,QAAQ,CAACtB,oBAAoB,CAAC;IAEhD,MAAMM,OAAO,CAACiB,QAAQ,CAACC,oBAAoB,CAAC,YAAY;MACpD,MAAMC,cAAc,GAAG,MAAMf,QAAQ,CAACgB,OAAO,CAAC/B,iBAAiB,CAAC;MAChEW,OAAO,CAACE,SAAS,CAACU,gBAAgB,CAACtB,oBAAoB,EAAE6B,cAAc,CAACE,KAAK,CAAC;IAClF,CAAC,CAAC;;IAEF;IACA1B,gBAAgB,CAACqB,QAAQ,CAAChB,OAAO,CAACE,SAAS,CAAC;EAChD,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"context.js","sources":["../src/context.ts"],"sourcesContent":["import type { CmsContext } from \"@webiny/api-headless-cms/types/index.js\";\nimport { SCHEDULE_MODEL_ID } from \"~/constants.js\";\nimport { ScheduledActionModel } from \"~/shared/abstractions.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 { SchedulerPermissionsFeature } from \"~/features/permissions/feature.js\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { createRegisterExtensionPlugin } from \"@webiny/handler\";\nimport { NamespaceHandlerExecutionerFeature } from \"~/features/NamespaceHandler/feature.js\";\nimport { SchedulerGraphQLFactoryFeature } from \"~/graphql/feature.js\";\n\nexport const registerSchedulerExtension = () => {\n const extensionPlugin = createRegisterExtensionPlugin(async context => {\n context.container.register(SchedulePrivateModel);\n SchedulerPermissionsFeature.register(context.container);\n SchedulerGraphQLFactoryFeature.register(context.container);\n NamespaceHandlerExecutionerFeature.register(context.container);\n SchedulerFeature.register(context.container);\n });\n extensionPlugin.name = \"scheduler.base.extension\";\n\n const contextPlugin = 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 await context.security.withoutAuthorization(async () => {\n const schedulerModel = await getModel.execute(SCHEDULE_MODEL_ID);\n if (schedulerModel.isFail()) {\n throw schedulerModel.error;\n }\n context.container.registerInstance(ScheduledActionModel, schedulerModel.value);\n });\n });\n\n contextPlugin.name = \"scheduler.base.context\";\n\n return [extensionPlugin, contextPlugin];\n};\n"],"names":["registerSchedulerExtension","extensionPlugin","createRegisterExtensionPlugin","context","SchedulePrivateModel","SchedulerPermissionsFeature","SchedulerGraphQLFactoryFeature","NamespaceHandlerExecutionerFeature","SchedulerFeature","contextPlugin","ContextPlugin","tenantContext","TenantContext","getModel","GetModelUseCase","schedulerModel","SCHEDULE_MODEL_ID","ScheduledActionModel"],"mappings":";;;;;;;;;;;AAaO,MAAMA,6BAA6B;IACtC,MAAMC,kBAAkBC,8BAA8B,OAAMC;QACxDA,QAAQ,SAAS,CAAC,QAAQ,CAACC;QAC3BC,4BAA4B,QAAQ,CAACF,QAAQ,SAAS;QACtDG,+BAA+B,QAAQ,CAACH,QAAQ,SAAS;QACzDI,mCAAmC,QAAQ,CAACJ,QAAQ,SAAS;QAC7DK,iBAAiB,QAAQ,CAACL,QAAQ,SAAS;IAC/C;IACAF,gBAAgB,IAAI,GAAG;IAEvB,MAAMQ,gBAAgB,IAAIC,cAA0B,OAAMP;QACtD,MAAMQ,gBAAgBR,QAAQ,SAAS,CAAC,OAAO,CAACS;QAChD,MAAMC,WAAWV,QAAQ,SAAS,CAAC,OAAO,CAACW;QAE3C,IAAI,CAACH,cAAc,SAAS,IACxB;QAGJ,MAAMR,QAAQ,QAAQ,CAAC,oBAAoB,CAAC;YACxC,MAAMY,iBAAiB,MAAMF,SAAS,OAAO,CAACG;YAC9C,IAAID,eAAe,MAAM,IACrB,MAAMA,eAAe,KAAK;YAE9BZ,QAAQ,SAAS,CAAC,gBAAgB,CAACc,sBAAsBF,eAAe,KAAK;QACjF;IACJ;IAEAN,cAAc,IAAI,GAAG;IAErB,OAAO;QAACR;QAAiBQ;KAAc;AAC3C"}
@@ -1,29 +1,32 @@
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
- async execute(builder) {
5
- return [builder.private({
6
- modelId: SCHEDULE_MODEL_ID,
7
- name: "Webiny CMS Schedule"
8
- }).fields(fields => ({
9
- namespace: fields.text().label("Namespace"),
10
- actionType: fields.text().label("Action Type"),
11
- targetId: fields.text().label("Target ID"),
12
- scheduledBy: fields.object().label("Scheduled By").fields(fields => ({
13
- id: fields.text().label("Identity ID"),
14
- displayName: fields.text().label("Display Name"),
15
- type: fields.text().label("Type")
16
- })),
17
- scheduledFor: fields.datetime().label("Scheduled For"),
18
- title: fields.text().label("Title"),
19
- error: fields.text().label("Error"),
20
- payload: fields.json().label("Payload")
21
- }))];
22
- }
4
+ async execute(builder) {
5
+ return [
6
+ builder.private({
7
+ modelId: SCHEDULE_MODEL_ID,
8
+ name: "Webiny CMS Schedule"
9
+ }).fields((fields)=>({
10
+ namespace: fields.text().label("Namespace"),
11
+ actionType: fields.text().label("Action Type"),
12
+ targetId: fields.text().label("Target ID"),
13
+ scheduledBy: fields.object().label("Scheduled By").fields((fields)=>({
14
+ id: fields.text().label("Identity ID"),
15
+ displayName: fields.text().label("Display Name"),
16
+ type: fields.text().label("Type")
17
+ })),
18
+ scheduledFor: fields.datetime().label("Scheduled For"),
19
+ title: fields.text().label("Title"),
20
+ error: fields.text().label("Error"),
21
+ payload: fields.json().label("Payload")
22
+ }))
23
+ ];
24
+ }
23
25
  }
24
- export const SchedulePrivateModel = ModelFactory.createImplementation({
25
- implementation: SchedulePrivateModelImpl,
26
- dependencies: []
26
+ const SchedulePrivateModel = ModelFactory.createImplementation({
27
+ implementation: SchedulePrivateModelImpl,
28
+ dependencies: []
27
29
  });
30
+ export { SchedulePrivateModel };
28
31
 
29
32
  //# sourceMappingURL=SchedulePrivateModel.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["ModelFactory","SCHEDULE_MODEL_ID","SchedulePrivateModelImpl","execute","builder","private","modelId","name","fields","namespace","text","label","actionType","targetId","scheduledBy","object","id","displayName","type","scheduledFor","datetime","title","error","payload","json","SchedulePrivateModel","createImplementation","implementation","dependencies"],"sources":["SchedulePrivateModel.ts"],"sourcesContent":["import { ModelFactory } from \"@webiny/api-headless-cms/features/modelBuilder/index.js\";\nimport { SCHEDULE_MODEL_ID } from \"~/constants.js\";\n\nclass SchedulePrivateModelImpl implements ModelFactory.Interface {\n public async execute(builder: ModelFactory.Builder) {\n return [\n builder\n .private({\n modelId: SCHEDULE_MODEL_ID,\n name: \"Webiny CMS Schedule\"\n })\n .fields(fields => ({\n namespace: fields.text().label(\"Namespace\"),\n actionType: fields.text().label(\"Action Type\"),\n targetId: fields.text().label(\"Target ID\"),\n scheduledBy: fields\n .object()\n .label(\"Scheduled By\")\n .fields(fields => ({\n id: fields.text().label(\"Identity ID\"),\n displayName: fields.text().label(\"Display Name\"),\n type: fields.text().label(\"Type\")\n })),\n scheduledFor: fields.datetime().label(\"Scheduled For\"),\n title: fields.text().label(\"Title\"),\n error: fields.text().label(\"Error\"),\n payload: fields.json().label(\"Payload\")\n }))\n ];\n }\n}\n\nexport const SchedulePrivateModel = ModelFactory.createImplementation({\n implementation: SchedulePrivateModelImpl,\n dependencies: []\n});\n"],"mappings":"AAAA,SAASA,YAAY,QAAQ,yDAAyD;AACtF,SAASC,iBAAiB;AAE1B,MAAMC,wBAAwB,CAAmC;EAC7D,MAAaC,OAAOA,CAACC,OAA6B,EAAE;IAChD,OAAO,CACHA,OAAO,CACFC,OAAO,CAAC;MACLC,OAAO,EAAEL,iBAAiB;MAC1BM,IAAI,EAAE;IACV,CAAC,CAAC,CACDC,MAAM,CAACA,MAAM,KAAK;MACfC,SAAS,EAAED,MAAM,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,WAAW,CAAC;MAC3CC,UAAU,EAAEJ,MAAM,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,aAAa,CAAC;MAC9CE,QAAQ,EAAEL,MAAM,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,WAAW,CAAC;MAC1CG,WAAW,EAAEN,MAAM,CACdO,MAAM,CAAC,CAAC,CACRJ,KAAK,CAAC,cAAc,CAAC,CACrBH,MAAM,CAACA,MAAM,KAAK;QACfQ,EAAE,EAAER,MAAM,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,aAAa,CAAC;QACtCM,WAAW,EAAET,MAAM,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,cAAc,CAAC;QAChDO,IAAI,EAAEV,MAAM,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,MAAM;MACpC,CAAC,CAAC,CAAC;MACPQ,YAAY,EAAEX,MAAM,CAACY,QAAQ,CAAC,CAAC,CAACT,KAAK,CAAC,eAAe,CAAC;MACtDU,KAAK,EAAEb,MAAM,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,OAAO,CAAC;MACnCW,KAAK,EAAEd,MAAM,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,OAAO,CAAC;MACnCY,OAAO,EAAEf,MAAM,CAACgB,IAAI,CAAC,CAAC,CAACb,KAAK,CAAC,SAAS;IAC1C,CAAC,CAAC,CAAC,CACV;EACL;AACJ;AAEA,OAAO,MAAMc,oBAAoB,GAAGzB,YAAY,CAAC0B,oBAAoB,CAAC;EAClEC,cAAc,EAAEzB,wBAAwB;EACxC0B,YAAY,EAAE;AAClB,CAAC,CAAC","ignoreList":[]}
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 })\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;YACV,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
- export class ScheduledActionId {
4
- static from(params) {
5
- return [SCHEDULE_ID_PREFIX, createCacheKey([params.namespace, params.actionType, params.targetId]).slice(-24)].join("");
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,"names":["createCacheKey","SCHEDULE_ID_PREFIX","ScheduledActionId","from","params","namespace","actionType","targetId","slice","join"],"sources":["ScheduledActionId.ts"],"sourcesContent":["import { createCacheKey } from \"@webiny/utils\";\nimport { SCHEDULE_ID_PREFIX } from \"~/constants.js\";\n\nexport interface IScheduledActionIdParams {\n namespace: string;\n actionType: string;\n targetId: string;\n}\n\nexport class ScheduledActionId {\n static from(params: IScheduledActionIdParams) {\n return [\n SCHEDULE_ID_PREFIX,\n createCacheKey([params.namespace, params.actionType, params.targetId]).slice(-24)\n ].join(\"\");\n }\n}\n"],"mappings":"AAAA,SAASA,cAAc,QAAQ,eAAe;AAC9C,SAASC,kBAAkB;AAQ3B,OAAO,MAAMC,iBAAiB,CAAC;EAC3B,OAAOC,IAAIA,CAACC,MAAgC,EAAE;IAC1C,OAAO,CACHH,kBAAkB,EAClBD,cAAc,CAAC,CAACI,MAAM,CAACC,SAAS,EAAED,MAAM,CAACE,UAAU,EAAEF,MAAM,CAACG,QAAQ,CAAC,CAAC,CAACC,KAAK,CAAC,CAAC,EAAE,CAAC,CACpF,CAACC,IAAI,CAAC,EAAE,CAAC;EACd;AACJ","ignoreList":[]}
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
- export class ScheduledActionIdWithVersion {
2
- static from(id) {
3
- if (id.endsWith("#0001")) {
4
- return id;
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,"names":["ScheduledActionIdWithVersion","from","id","endsWith"],"sources":["ScheduledActionIdWithVersion.ts"],"sourcesContent":["export class ScheduledActionIdWithVersion {\n static from(id: string) {\n if (id.endsWith(\"#0001\")) {\n return id;\n }\n\n return `${id}#0001`;\n }\n}\n"],"mappings":"AAAA,OAAO,MAAMA,4BAA4B,CAAC;EACtC,OAAOC,IAAIA,CAACC,EAAU,EAAE;IACpB,IAAIA,EAAE,CAACC,QAAQ,CAAC,OAAO,CAAC,EAAE;MACtB,OAAOD,EAAE;IACb;IAEA,OAAO,GAAGA,EAAE,OAAO;EACvB;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"domain/ScheduledActionIdWithVersion.js","sources":["../../src/domain/ScheduledActionIdWithVersion.ts"],"sourcesContent":["export class ScheduledActionIdWithVersion {\n static from(id: string) {\n if (id.endsWith(\"#0001\")) {\n return id;\n }\n\n return `${id}#0001`;\n }\n}\n"],"names":["ScheduledActionIdWithVersion","id"],"mappings":"AAAO,MAAMA;IACT,OAAO,KAAKC,EAAU,EAAE;QACpB,IAAIA,GAAG,QAAQ,CAAC,UACZ,OAAOA;QAGX,OAAO,GAAGA,GAAG,KAAK,CAAC;IACvB;AACJ"}
@@ -0,0 +1,16 @@
1
+ import type { IScheduledAction, IScheduledActionEntry } from "../shared/abstractions.js";
2
+ import type { GenericRecord } from "@webiny/api/types.js";
3
+ export declare class ScheduledActionMapper {
4
+ static toAction<T extends GenericRecord = GenericRecord>(action: IScheduledActionEntry<T>): IScheduledAction<T>;
5
+ static toActions<T extends GenericRecord = GenericRecord>(actions: IScheduledActionEntry<T>[]): IScheduledAction<T>[];
6
+ static toGraphQL<T extends GenericRecord = GenericRecord>(action: IScheduledAction<T>): {
7
+ id: string;
8
+ targetId: string;
9
+ namespace: string;
10
+ scheduledBy: import("~/shared/abstractions.js").Identity;
11
+ publishOn: Date | null;
12
+ unpublishOn: Date | null;
13
+ actionType: import("~/shared/abstractions.js").ScheduledActionType;
14
+ title: string;
15
+ };
16
+ }
@@ -0,0 +1,37 @@
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
+ return {
7
+ id: scheduleId,
8
+ targetId: action.values.targetId,
9
+ namespace: action.values.namespace,
10
+ scheduledBy: action.values.scheduledBy,
11
+ scheduledFor: new Date(action.values.scheduledFor),
12
+ actionType: action.values.actionType,
13
+ title: action.values.title,
14
+ payload: action.values.payload,
15
+ error: action.values.error,
16
+ tenant: action.tenant
17
+ };
18
+ }
19
+ static toActions(actions) {
20
+ return actions.map(ScheduledActionMapper.toAction);
21
+ }
22
+ static toGraphQL(action) {
23
+ return {
24
+ id: action.id,
25
+ targetId: action.targetId,
26
+ namespace: action.namespace,
27
+ scheduledBy: action.scheduledBy,
28
+ publishOn: action.actionType === SCHEDULED_ACTION_PUBLISH ? action.scheduledFor : null,
29
+ unpublishOn: action.actionType === SCHEDULED_ACTION_UNPUBLISH ? action.scheduledFor : null,
30
+ actionType: action.actionType,
31
+ title: action.title
32
+ };
33
+ }
34
+ }
35
+ export { ScheduledActionMapper };
36
+
37
+ //# 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 return {\n id: scheduleId,\n targetId: action.values.targetId,\n namespace: action.values.namespace,\n scheduledBy: action.values.scheduledBy,\n scheduledFor: new Date(action.values.scheduledFor),\n actionType: action.values.actionType,\n title: action.values.title,\n payload: action.values.payload,\n error: action.values.error,\n tenant: action.tenant\n };\n }\n\n static toActions<T extends GenericRecord = GenericRecord>(\n actions: IScheduledActionEntry<T>[]\n ): IScheduledAction<T>[] {\n return actions.map(ScheduledActionMapper.toAction);\n }\n\n static toGraphQL<T extends GenericRecord = GenericRecord>(action: IScheduledAction<T>) {\n return {\n id: action.id,\n targetId: action.targetId,\n namespace: action.namespace,\n scheduledBy: action.scheduledBy,\n publishOn: action.actionType === SCHEDULED_ACTION_PUBLISH ? action.scheduledFor : null,\n unpublishOn:\n action.actionType === SCHEDULED_ACTION_UNPUBLISH ? action.scheduledFor : null,\n actionType: action.actionType,\n title: action.title\n };\n }\n}\n"],"names":["ScheduledActionMapper","action","scheduleId","parseIdentifier","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,OAAO;YACH,IAAIC;YACJ,UAAUD,OAAO,MAAM,CAAC,QAAQ;YAChC,WAAWA,OAAO,MAAM,CAAC,SAAS;YAClC,aAAaA,OAAO,MAAM,CAAC,WAAW;YACtC,cAAc,IAAIG,KAAKH,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,UACHI,OAAmC,EACd;QACrB,OAAOA,QAAQ,GAAG,CAACL,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,KAAKK,2BAA2BL,OAAO,YAAY,GAAG;YAClF,aACIA,OAAO,UAAU,KAAKM,6BAA6BN,OAAO,YAAY,GAAG;YAC7E,YAAYA,OAAO,UAAU;YAC7B,OAAOA,OAAO,KAAK;QACvB;IACJ;AACJ"}
@@ -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
  */
@@ -24,7 +31,7 @@ export declare class InvalidScheduleDateError extends BaseError<{
24
31
  scheduleFor: string;
25
32
  }> {
26
33
  readonly code: "Scheduler/ScheduledAction/InvalidDate";
27
- constructor(scheduleFor: string);
34
+ constructor(scheduleFor: Date);
28
35
  }
29
36
  /**
30
37
  * Scheduler service error (EventBridge/cloud provider errors)
@@ -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,61 @@
1
1
  import { BaseError } from "@webiny/feature/api";
2
-
3
- /**
4
- * Scheduled action not found error
5
- */
6
- export class ScheduledActionNotFoundError extends BaseError {
7
- code = "Scheduler/ScheduledAction/NotFound";
8
- constructor(scheduleId) {
9
- super({
10
- message: `Scheduled action "${scheduleId}" was not found.`,
11
- data: {
12
- scheduleId
13
- }
14
- });
15
- }
2
+ class NotAuthorizedError extends BaseError {
3
+ constructor(){
4
+ super({
5
+ message: "Not authorized!"
6
+ }), this.code = "Scheduler/NotAuthorized";
7
+ }
16
8
  }
17
-
18
- /**
19
- * Storage/persistence error when working with scheduled actions
20
- */
21
- export class ScheduledActionPersistenceError extends BaseError {
22
- code = "Scheduler/ScheduledAction/PersistenceError";
23
- constructor(error) {
24
- super({
25
- message: error.message,
26
- data: {
27
- originalError: error
28
- }
29
- });
30
- }
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
- * Invalid schedule date error (e.g., scheduling in the past)
35
- */
36
- export class InvalidScheduleDateError extends BaseError {
37
- code = "Scheduler/ScheduledAction/InvalidDate";
38
- constructor(scheduleFor) {
39
- super({
40
- message: "Cannot schedule in the past",
41
- data: {
42
- scheduleFor
43
- }
44
- });
45
- }
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
- * Scheduler service error (EventBridge/cloud provider errors)
50
- */
51
- export class SchedulerServiceError extends BaseError {
52
- code = "Scheduler/Service/Error";
53
- constructor(error) {
54
- super({
55
- message: `Scheduler service error: ${error.message}`,
56
- data: {
57
- originalError: error
58
- }
59
- });
60
- }
29
+ class InvalidScheduleDateError extends BaseError {
30
+ constructor(scheduleFor){
31
+ super({
32
+ message: "Cannot schedule in the past",
33
+ data: {
34
+ scheduleFor: scheduleFor.toISOString()
35
+ }
36
+ }), this.code = "Scheduler/ScheduledAction/InvalidDate";
37
+ }
38
+ }
39
+ class SchedulerServiceError extends BaseError {
40
+ constructor(error){
41
+ super({
42
+ message: `Scheduler service error: ${error.message}`,
43
+ data: {
44
+ originalError: error
45
+ }
46
+ }), this.code = "Scheduler/Service/Error";
47
+ }
48
+ }
49
+ class NamespaceHandlerNotFoundError extends BaseError {
50
+ constructor(namespace){
51
+ super({
52
+ message: `Namespace handler for "${namespace}" was not found.`,
53
+ data: {
54
+ namespace
55
+ }
56
+ }), this.code = "Scheduler/NamespaceHandler/NotFound";
57
+ }
61
58
  }
59
+ export { InvalidScheduleDateError, NamespaceHandlerNotFoundError, NotAuthorizedError, ScheduledActionNotFoundError, ScheduledActionPersistenceError, SchedulerServiceError };
62
60
 
63
61
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["BaseError","ScheduledActionNotFoundError","code","constructor","scheduleId","message","data","ScheduledActionPersistenceError","error","originalError","InvalidScheduleDateError","scheduleFor","SchedulerServiceError"],"sources":["errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\n\n/**\n * Scheduled action not found error\n */\nexport class ScheduledActionNotFoundError extends BaseError<{ scheduleId: string }> {\n override readonly code = \"Scheduler/ScheduledAction/NotFound\" as const;\n\n constructor(scheduleId: string) {\n super({\n message: `Scheduled action \"${scheduleId}\" was not found.`,\n data: {\n scheduleId\n }\n });\n }\n}\n\n/**\n * Storage/persistence error when working with scheduled actions\n */\nexport class ScheduledActionPersistenceError extends BaseError<{ originalError: Error }> {\n override readonly code = \"Scheduler/ScheduledAction/PersistenceError\" as const;\n\n constructor(error: Error) {\n super({\n message: error.message,\n data: { originalError: error }\n });\n }\n}\n\n/**\n * Invalid schedule date error (e.g., scheduling in the past)\n */\nexport class InvalidScheduleDateError extends BaseError<{ scheduleFor: string }> {\n override readonly code = \"Scheduler/ScheduledAction/InvalidDate\" as const;\n\n constructor(scheduleFor: string) {\n super({\n message: \"Cannot schedule in the past\",\n data: { scheduleFor }\n });\n }\n}\n\n/**\n * Scheduler service error (EventBridge/cloud provider errors)\n */\nexport class SchedulerServiceError extends BaseError<{ originalError: Error }> {\n override readonly code = \"Scheduler/Service/Error\" as const;\n\n constructor(error: Error) {\n super({\n message: `Scheduler service error: ${error.message}`,\n data: { originalError: error }\n });\n }\n}\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,qBAAqB;;AAE/C;AACA;AACA;AACA,OAAO,MAAMC,4BAA4B,SAASD,SAAS,CAAyB;EAC9DE,IAAI,GAAG,oCAAoC;EAE7DC,WAAWA,CAACC,UAAkB,EAAE;IAC5B,KAAK,CAAC;MACFC,OAAO,EAAE,qBAAqBD,UAAU,kBAAkB;MAC1DE,IAAI,EAAE;QACFF;MACJ;IACJ,CAAC,CAAC;EACN;AACJ;;AAEA;AACA;AACA;AACA,OAAO,MAAMG,+BAA+B,SAASP,SAAS,CAA2B;EACnEE,IAAI,GAAG,4CAA4C;EAErEC,WAAWA,CAACK,KAAY,EAAE;IACtB,KAAK,CAAC;MACFH,OAAO,EAAEG,KAAK,CAACH,OAAO;MACtBC,IAAI,EAAE;QAAEG,aAAa,EAAED;MAAM;IACjC,CAAC,CAAC;EACN;AACJ;;AAEA;AACA;AACA;AACA,OAAO,MAAME,wBAAwB,SAASV,SAAS,CAA0B;EAC3DE,IAAI,GAAG,uCAAuC;EAEhEC,WAAWA,CAACQ,WAAmB,EAAE;IAC7B,KAAK,CAAC;MACFN,OAAO,EAAE,6BAA6B;MACtCC,IAAI,EAAE;QAAEK;MAAY;IACxB,CAAC,CAAC;EACN;AACJ;;AAEA;AACA;AACA;AACA,OAAO,MAAMC,qBAAqB,SAASZ,SAAS,CAA2B;EACzDE,IAAI,GAAG,yBAAyB;EAElDC,WAAWA,CAACK,KAAY,EAAE;IACtB,KAAK,CAAC;MACFH,OAAO,EAAE,4BAA4BG,KAAK,CAACH,OAAO,EAAE;MACpDC,IAAI,EAAE;QAAEG,aAAa,EAAED;MAAM;IACjC,CAAC,CAAC;EACN;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"domain/errors.js","sources":["../../src/domain/errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\n\n/**\n * Not authorized error when user lacks permissions to manage scheduled actions.\n */\nexport class NotAuthorizedError extends BaseError {\n override readonly code = \"Scheduler/NotAuthorized\" as const;\n\n constructor() {\n super({ message: \"Not authorized!\" });\n }\n}\n\n/**\n * Scheduled action not found error\n */\nexport class ScheduledActionNotFoundError extends BaseError<{ scheduleId: string }> {\n override readonly code = \"Scheduler/ScheduledAction/NotFound\" as const;\n\n constructor(scheduleId: string) {\n super({\n message: `Scheduled action \"${scheduleId}\" was not found.`,\n data: {\n scheduleId\n }\n });\n }\n}\n\n/**\n * Storage/persistence error when working with scheduled actions\n */\nexport class ScheduledActionPersistenceError extends BaseError<{ originalError: Error }> {\n override readonly code = \"Scheduler/ScheduledAction/PersistenceError\" as const;\n\n constructor(error: Error) {\n super({\n message: error.message,\n data: { originalError: error }\n });\n }\n}\n\n/**\n * Invalid schedule date error (e.g., scheduling in the past)\n */\nexport class InvalidScheduleDateError extends BaseError<{ scheduleFor: string }> {\n override readonly code = \"Scheduler/ScheduledAction/InvalidDate\" as const;\n\n constructor(scheduleFor: Date) {\n super({\n message: \"Cannot schedule in the past\",\n data: {\n scheduleFor: scheduleFor.toISOString()\n }\n });\n }\n}\n\n/**\n * Scheduler service error (EventBridge/cloud provider errors)\n */\nexport class SchedulerServiceError extends BaseError<{ originalError: Error }> {\n override readonly code = \"Scheduler/Service/Error\" as const;\n\n constructor(error: Error) {\n super({\n message: `Scheduler service error: ${error.message}`,\n data: { originalError: error }\n });\n }\n}\n\ninterface INamespaceHandlerNotFoundErrorData {\n namespace: string;\n}\n/**\n * Namespace handler not found error.\n */\nexport class NamespaceHandlerNotFoundError extends BaseError<INamespaceHandlerNotFoundErrorData> {\n override readonly code = \"Scheduler/NamespaceHandler/NotFound\" as const;\n\n constructor(namespace: string) {\n super({\n message: `Namespace handler for \"${namespace}\" was not found.`,\n data: {\n namespace\n }\n });\n }\n}\n"],"names":["NotAuthorizedError","BaseError","ScheduledActionNotFoundError","scheduleId","ScheduledActionPersistenceError","error","InvalidScheduleDateError","scheduleFor","SchedulerServiceError","NamespaceHandlerNotFoundError","namespace"],"mappings":";AAKO,MAAMA,2BAA2BC;IAGpC,aAAc;QACV,KAAK,CAAC;YAAE,SAAS;QAAkB,SAHrB,IAAI,GAAG;IAIzB;AACJ;AAKO,MAAMC,qCAAqCD;IAG9C,YAAYE,UAAkB,CAAE;QAC5B,KAAK,CAAC;YACF,SAAS,CAAC,kBAAkB,EAAEA,WAAW,gBAAgB,CAAC;YAC1D,MAAM;gBACFA;YACJ;QACJ,SARc,IAAI,GAAG;IASzB;AACJ;AAKO,MAAMC,wCAAwCH;IAGjD,YAAYI,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAASA,MAAM,OAAO;YACtB,MAAM;gBAAE,eAAeA;YAAM;QACjC,SANc,IAAI,GAAG;IAOzB;AACJ;AAKO,MAAMC,iCAAiCL;IAG1C,YAAYM,WAAiB,CAAE;QAC3B,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBACF,aAAaA,YAAY,WAAW;YACxC;QACJ,SARc,IAAI,GAAG;IASzB;AACJ;AAKO,MAAMC,8BAA8BP;IAGvC,YAAYI,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS,CAAC,yBAAyB,EAAEA,MAAM,OAAO,EAAE;YACpD,MAAM;gBAAE,eAAeA;YAAM;QACjC,SANc,IAAI,GAAG;IAOzB;AACJ;AAQO,MAAMI,sCAAsCR;IAG/C,YAAYS,SAAiB,CAAE;QAC3B,KAAK,CAAC;YACF,SAAS,CAAC,uBAAuB,EAAEA,UAAU,gBAAgB,CAAC;YAC9D,MAAM;gBACFA;YACJ;QACJ,SARc,IAAI,GAAG;IASzB;AACJ"}
@@ -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: (date: string) => boolean;
6
+ export declare const isValidDate: (input: Date) => boolean;
@@ -1,13 +1,8 @@
1
1
  import { SCHEDULE_MIN_FUTURE_SECONDS } from "../constants.js";
2
-
3
- /**
4
- * Check if the provided date is in the future.
5
- * We need to ensure that the date is at least a SCHEDULE_MIN_FUTURE_MINUTES minutes in the future.
6
- * Otherwise, we consider it as "immediate" and run the action right away.
7
- */
8
- export const isValidDate = date => {
9
- const minDate = new Date(Date.now() + SCHEDULE_MIN_FUTURE_SECONDS * 1000);
10
- return new Date(date).getTime() >= minDate.getTime();
2
+ const isValidDate = (input)=>{
3
+ const minDate = new Date(Date.now() + 1000 * SCHEDULE_MIN_FUTURE_SECONDS);
4
+ return input.getTime() >= minDate.getTime();
11
5
  };
6
+ export { isValidDate };
12
7
 
13
8
  //# sourceMappingURL=isValidDate.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["SCHEDULE_MIN_FUTURE_SECONDS","isValidDate","date","minDate","Date","now","getTime"],"sources":["isValidDate.ts"],"sourcesContent":["import { SCHEDULE_MIN_FUTURE_SECONDS } from \"~/constants.js\";\n\n/**\n * Check if the provided date is in the future.\n * We need to ensure that the date is at least a SCHEDULE_MIN_FUTURE_MINUTES minutes in the future.\n * Otherwise, we consider it as \"immediate\" and run the action right away.\n */\nexport const isValidDate = (date: string): boolean => {\n const minDate = new Date(Date.now() + SCHEDULE_MIN_FUTURE_SECONDS * 1000);\n\n return new Date(date).getTime() >= minDate.getTime();\n};\n"],"mappings":"AAAA,SAASA,2BAA2B;;AAEpC;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,WAAW,GAAIC,IAAY,IAAc;EAClD,MAAMC,OAAO,GAAG,IAAIC,IAAI,CAACA,IAAI,CAACC,GAAG,CAAC,CAAC,GAAGL,2BAA2B,GAAG,IAAI,CAAC;EAEzE,OAAO,IAAII,IAAI,CAACF,IAAI,CAAC,CAACI,OAAO,CAAC,CAAC,IAAIH,OAAO,CAACG,OAAO,CAAC,CAAC;AACxD,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"domain/isValidDate.js","sources":["../../src/domain/isValidDate.ts"],"sourcesContent":["import { SCHEDULE_MIN_FUTURE_SECONDS } from \"~/constants.js\";\n\n/**\n * Check if the provided date is in the future.\n * We need to ensure that the date is at least a SCHEDULE_MIN_FUTURE_MINUTES minutes in the future.\n * Otherwise, we consider it as \"immediate\" and run the action right away.\n */\nexport const isValidDate = (input: Date): boolean => {\n const minDate = new Date(Date.now() + SCHEDULE_MIN_FUTURE_SECONDS * 1000);\n\n return input.getTime() >= minDate.getTime();\n};\n"],"names":["isValidDate","input","minDate","Date","SCHEDULE_MIN_FUTURE_SECONDS"],"mappings":";AAOO,MAAMA,cAAc,CAACC;IACxB,MAAMC,UAAU,IAAIC,KAAKA,KAAK,GAAG,KAAKC,AAA8B,OAA9BA;IAEtC,OAAOH,MAAM,OAAO,MAAMC,QAAQ,OAAO;AAC7C"}
@@ -0,0 +1,9 @@
1
+ export declare const SCHEDULER_PERMISSIONS_SCHEMA: {
2
+ readonly prefix: "scheduler";
3
+ readonly fullAccess: true;
4
+ readonly entities: readonly [{
5
+ readonly id: "action";
6
+ readonly permission: "scheduler.action";
7
+ readonly scopes: readonly ["full", "own"];
8
+ }];
9
+ };
@@ -0,0 +1,18 @@
1
+ import { createPermissionSchema } from "@webiny/api-core/exports/api/security.js";
2
+ const SCHEDULER_PERMISSIONS_SCHEMA = createPermissionSchema({
3
+ prefix: "scheduler",
4
+ fullAccess: true,
5
+ entities: [
6
+ {
7
+ id: "action",
8
+ permission: "scheduler.action",
9
+ scopes: [
10
+ "full",
11
+ "own"
12
+ ]
13
+ }
14
+ ]
15
+ });
16
+ export { SCHEDULER_PERMISSIONS_SCHEMA };
17
+
18
+ //# sourceMappingURL=permissionsSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain/permissionsSchema.js","sources":["../../src/domain/permissionsSchema.ts"],"sourcesContent":["import { createPermissionSchema } from \"@webiny/api-core/exports/api/security.js\";\n\nexport const SCHEDULER_PERMISSIONS_SCHEMA = createPermissionSchema({\n prefix: \"scheduler\",\n fullAccess: true,\n entities: [\n {\n id: \"action\",\n permission: \"scheduler.action\",\n scopes: [\"full\", \"own\"]\n }\n ]\n});\n"],"names":["SCHEDULER_PERMISSIONS_SCHEMA","createPermissionSchema"],"mappings":";AAEO,MAAMA,+BAA+BC,uBAAuB;IAC/D,QAAQ;IACR,YAAY;IACZ,UAAU;QACN;YACI,IAAI;YACJ,YAAY;YACZ,QAAQ;gBAAC;gBAAQ;aAAM;QAC3B;KACH;AACL"}