@webiny/api-scheduler 6.0.0 → 6.1.0-beta.0

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 (102) hide show
  1. package/constants.d.ts +5 -0
  2. package/constants.js +6 -0
  3. package/constants.js.map +1 -1
  4. package/context.js +6 -0
  5. package/context.js.map +1 -1
  6. package/createEventHandler.d.ts +1 -0
  7. package/createEventHandler.js +1 -1
  8. package/createEventHandler.js.map +1 -1
  9. package/domain/ScheduledActionMapper.d.ts +16 -0
  10. package/domain/ScheduledActionMapper.js +37 -0
  11. package/domain/ScheduledActionMapper.js.map +1 -0
  12. package/domain/errors.d.ts +19 -1
  13. package/domain/errors.js +27 -1
  14. package/domain/errors.js.map +1 -1
  15. package/domain/isValidDate.d.ts +1 -1
  16. package/domain/isValidDate.js +2 -2
  17. package/domain/isValidDate.js.map +1 -1
  18. package/domain/permissions.d.ts +45 -0
  19. package/domain/permissions.js +13 -0
  20. package/domain/permissions.js.map +1 -0
  21. package/exports/api/scheduler.d.ts +10 -0
  22. package/exports/api/scheduler.js +10 -0
  23. package/exports/api/scheduler.js.map +1 -0
  24. package/features/CancelScheduledAction/CancelScheduledActionUseCase.d.ts +4 -2
  25. package/features/CancelScheduledAction/CancelScheduledActionUseCase.js +17 -8
  26. package/features/CancelScheduledAction/CancelScheduledActionUseCase.js.map +1 -1
  27. package/features/CancelScheduledAction/abstractions.d.ts +9 -2
  28. package/features/CancelScheduledAction/abstractions.js +2 -1
  29. package/features/CancelScheduledAction/abstractions.js.map +1 -1
  30. package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.d.ts +1 -1
  31. package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js +9 -6
  32. package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js.map +1 -1
  33. package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.d.ts +2 -2
  34. package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.js.map +1 -1
  35. package/features/ExecuteScheduledAction/abstractions.d.ts +9 -2
  36. package/features/ExecuteScheduledAction/abstractions.js +2 -1
  37. package/features/ExecuteScheduledAction/abstractions.js.map +1 -1
  38. package/features/GetScheduledAction/GetScheduledActionUseCase.d.ts +6 -2
  39. package/features/GetScheduledAction/GetScheduledActionUseCase.js +32 -15
  40. package/features/GetScheduledAction/GetScheduledActionUseCase.js.map +1 -1
  41. package/features/GetScheduledAction/abstractions.d.ts +9 -2
  42. package/features/GetScheduledAction/abstractions.js +2 -1
  43. package/features/GetScheduledAction/abstractions.js.map +1 -1
  44. package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.d.ts +32 -0
  45. package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.js +86 -0
  46. package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.js.map +1 -0
  47. package/features/GetTargetScheduledAction/abstractions.d.ts +24 -0
  48. package/features/GetTargetScheduledAction/abstractions.js +4 -0
  49. package/features/GetTargetScheduledAction/abstractions.js.map +1 -0
  50. package/features/GetTargetScheduledAction/feature.d.ts +7 -0
  51. package/features/GetTargetScheduledAction/feature.js +17 -0
  52. package/features/GetTargetScheduledAction/feature.js.map +1 -0
  53. package/features/ListScheduledActions/ListScheduledActionsUseCase.d.ts +5 -1
  54. package/features/ListScheduledActions/ListScheduledActionsUseCase.js +25 -24
  55. package/features/ListScheduledActions/ListScheduledActionsUseCase.js.map +1 -1
  56. package/features/ListScheduledActions/abstractions.d.ts +11 -3
  57. package/features/ListScheduledActions/abstractions.js +2 -1
  58. package/features/ListScheduledActions/abstractions.js.map +1 -1
  59. package/features/NamespaceHandler/NamespaceHandlerExecutioner.d.ts +11 -0
  60. package/features/NamespaceHandler/NamespaceHandlerExecutioner.js +25 -0
  61. package/features/NamespaceHandler/NamespaceHandlerExecutioner.js.map +1 -0
  62. package/features/NamespaceHandler/abstractions.d.ts +50 -0
  63. package/features/NamespaceHandler/abstractions.js +16 -0
  64. package/features/NamespaceHandler/abstractions.js.map +1 -0
  65. package/features/NamespaceHandler/index.d.ts +1 -0
  66. package/features/NamespaceHandler/index.js +3 -0
  67. package/features/NamespaceHandler/index.js.map +1 -0
  68. package/features/ScheduleAction/ScheduleActionUseCase.d.ts +4 -4
  69. package/features/ScheduleAction/ScheduleActionUseCase.js +75 -16
  70. package/features/ScheduleAction/ScheduleActionUseCase.js.map +1 -1
  71. package/features/ScheduleAction/abstractions.d.ts +10 -10
  72. package/features/ScheduleAction/abstractions.js +2 -1
  73. package/features/ScheduleAction/abstractions.js.map +1 -1
  74. package/features/SchedulerFeature.js +2 -2
  75. package/features/SchedulerFeature.js.map +1 -1
  76. package/features/SchedulerService/EventBridgeSchedulerService.js +3 -1
  77. package/features/SchedulerService/EventBridgeSchedulerService.js.map +1 -1
  78. package/graphql/SchedulerGraphQLFactory.d.ts +8 -0
  79. package/graphql/SchedulerGraphQLFactory.js +248 -0
  80. package/graphql/SchedulerGraphQLFactory.js.map +1 -0
  81. package/graphql/index.d.ts +1 -0
  82. package/graphql/index.js +3 -0
  83. package/graphql/index.js.map +1 -0
  84. package/index.d.ts +0 -6
  85. package/index.js +0 -8
  86. package/index.js.map +1 -1
  87. package/package.json +20 -27
  88. package/shared/abstractions.d.ts +18 -6
  89. package/shared/abstractions.js +3 -0
  90. package/shared/abstractions.js.map +1 -1
  91. package/features/RunAction/RunActionUseCase.d.ts +0 -23
  92. package/features/RunAction/RunActionUseCase.js +0 -37
  93. package/features/RunAction/RunActionUseCase.js.map +0 -1
  94. package/features/RunAction/abstractions.d.ts +0 -35
  95. package/features/RunAction/abstractions.js +0 -15
  96. package/features/RunAction/abstractions.js.map +0 -1
  97. package/features/RunAction/feature.d.ts +0 -7
  98. package/features/RunAction/feature.js +0 -17
  99. package/features/RunAction/feature.js.map +0 -1
  100. /package/features/{RunAction → GetTargetScheduledAction}/index.d.ts +0 -0
  101. /package/features/{RunAction → GetTargetScheduledAction}/index.js +0 -0
  102. /package/features/{RunAction → GetTargetScheduledAction}/index.js.map +0 -0
@@ -24,7 +24,7 @@ declare class ExecuteScheduledActionUseCaseImpl implements UseCaseAbstraction.In
24
24
  private model;
25
25
  private identityContext;
26
26
  constructor(getScheduledActionUseCase: GetScheduledActionUseCase.Interface, actionHandler: ScheduledActionHandler.Interface, deleteEntryUseCase: DeleteEntryUseCase.Interface, updateEntryUseCase: UpdateEntryUseCase.Interface, model: ScheduledActionModel.Interface, identityContext: IdentityContext.Interface);
27
- execute<T extends GenericRecord>(id: string): Promise<Result<void, UseCaseAbstraction.Error>>;
27
+ execute<T extends GenericRecord>(params: UseCaseAbstraction.Params): Promise<Result<void, UseCaseAbstraction.Error>>;
28
28
  private executeAction;
29
29
  }
30
30
  export declare const ExecuteScheduledActionUseCase: typeof ExecuteScheduledActionUseCaseImpl & {
@@ -27,14 +27,17 @@ class ExecuteScheduledActionUseCaseImpl {
27
27
  this.model = model;
28
28
  this.identityContext = identityContext;
29
29
  }
30
- async execute(id) {
31
- // return this.identityContext.withoutAuthorization(async () => {
32
- return this.executeAction(id);
33
- // });
30
+ async execute(params) {
31
+ return this.identityContext.withoutAuthorization(async () => {
32
+ return this.executeAction(params);
33
+ });
34
34
  }
35
- async executeAction(id) {
35
+ async executeAction(params) {
36
+ const {
37
+ id
38
+ } = params;
36
39
  // Load scheduled action
37
- const getResult = await this.getScheduledActionUseCase.execute(id);
40
+ const getResult = await this.getScheduledActionUseCase.execute(params);
38
41
  if (getResult.isFail()) {
39
42
  const error = getResult.error;
40
43
  if (error.code === "Scheduler/ScheduledAction/NotFound") {
@@ -1 +1 @@
1
- {"version":3,"names":["Result","ExecuteScheduledActionUseCase","UseCaseAbstraction","ExecutionFailedError","HandlerNotFoundError","GetScheduledActionUseCase","ScheduledActionHandler","ScheduledActionModel","ScheduledActionNotFoundError","ScheduledActionPersistenceError","DeleteEntryUseCase","UpdateEntryUseCase","ScheduledActionIdWithVersion","AuthenticatedIdentity","IdentityContext","ExecuteScheduledActionUseCaseImpl","constructor","getScheduledActionUseCase","actionHandler","deleteEntryUseCase","updateEntryUseCase","model","identityContext","execute","id","executeAction","getResult","isFail","error","code","fail","scheduledAction","value","scheduledBy","setIdentity","type","displayName","context","canAccessTenant","scheduleId","from","canHandle","namespace","actionType","values","message","handle","deleteResult","force","permanently","Error","ok","executionError","createImplementation","implementation","dependencies"],"sources":["ExecuteScheduledActionUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n ExecuteScheduledActionUseCase as UseCaseAbstraction,\n ExecutionFailedError,\n HandlerNotFoundError\n} from \"./abstractions.js\";\nimport { GetScheduledActionUseCase } from \"~/features/GetScheduledAction/abstractions.js\";\nimport {\n type IScheduledAction,\n ScheduledActionHandler,\n ScheduledActionModel\n} from \"~/shared/abstractions.js\";\nimport { ScheduledActionNotFoundError, ScheduledActionPersistenceError } from \"~/domain/errors.js\";\nimport { DeleteEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js\";\nimport { UpdateEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/UpdateEntry/index.js\";\nimport { ScheduledActionIdWithVersion } from \"~/domain/ScheduledActionIdWithVersion.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport {\n AuthenticatedIdentity,\n IdentityContext\n} from \"@webiny/api-core/features/security/IdentityContext/index.js\";\n\n/**\n * Executes a scheduled action\n *\n * Flow:\n * 1. Load scheduled action from CMS\n * 2. Find registered handler for namespace + actionType\n * 3. Execute handler\n * 4. Delete schedule entry on success\n * 5. Update entry with error on failure (for debugging/audit)\n */\nclass ExecuteScheduledActionUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private getScheduledActionUseCase: GetScheduledActionUseCase.Interface,\n private actionHandler: ScheduledActionHandler.Interface,\n private deleteEntryUseCase: DeleteEntryUseCase.Interface,\n private updateEntryUseCase: UpdateEntryUseCase.Interface,\n private model: ScheduledActionModel.Interface,\n private identityContext: IdentityContext.Interface\n ) {}\n\n public async execute<T extends GenericRecord>(\n id: string\n ): Promise<Result<void, UseCaseAbstraction.Error>> {\n // return this.identityContext.withoutAuthorization(async () => {\n return this.executeAction<T>(id);\n // });\n }\n\n private async executeAction<T extends GenericRecord>(\n id: string\n ): Promise<Result<void, UseCaseAbstraction.Error>> {\n // Load scheduled action\n const getResult = await this.getScheduledActionUseCase.execute<T>(id);\n\n if (getResult.isFail()) {\n const error = getResult.error;\n\n if (error.code === \"Scheduler/ScheduledAction/NotFound\") {\n return Result.fail(new ScheduledActionNotFoundError(id));\n }\n\n return Result.fail(error);\n }\n const scheduledAction = getResult.value;\n\n /**\n * When executing the scheduled action, we need a user which has access to perform the action.\n * We will set a user which created the scheduled action as the execution user.\n */\n const scheduledBy = scheduledAction.scheduledBy;\n this.identityContext.setIdentity(\n new AuthenticatedIdentity({\n id: scheduledBy.id,\n type: scheduledBy.type,\n displayName: scheduledBy.displayName ?? \"\",\n context: {\n canAccessTenant: true\n }\n })\n );\n\n const scheduleId = ScheduledActionIdWithVersion.from(id);\n\n // Check if the handler can handle this action\n if (!this.actionHandler.canHandle(scheduledAction.namespace, scheduledAction.actionType)) {\n const error = new HandlerNotFoundError(\n scheduledAction.namespace,\n scheduledAction.actionType\n );\n\n // Update entry with error for debugging\n await this.updateEntryUseCase.execute<IScheduledAction<T>>(this.model, scheduleId, {\n values: {\n error: error.message\n }\n });\n\n return Result.fail(error);\n }\n\n // Execute handler\n try {\n await this.actionHandler.handle(scheduledAction);\n\n // Delete schedule entry on success\n const deleteResult = await this.deleteEntryUseCase.execute(this.model, scheduleId, {\n force: true,\n permanently: true\n });\n\n if (deleteResult.isFail()) {\n return Result.fail(\n new ScheduledActionPersistenceError(new Error(deleteResult.error.message))\n );\n }\n\n return Result.ok();\n } catch (error) {\n const executionError = new ExecutionFailedError(\n `Failed to execute scheduled action: ${(error as Error).message}`,\n error as Error\n );\n\n // Update entry with error for debugging\n await this.updateEntryUseCase.execute<IScheduledAction<T>>(this.model, scheduleId, {\n values: {\n error: executionError.message\n }\n });\n\n return Result.fail(executionError);\n }\n }\n}\n\nexport const ExecuteScheduledActionUseCase = UseCaseAbstraction.createImplementation({\n implementation: ExecuteScheduledActionUseCaseImpl,\n dependencies: [\n GetScheduledActionUseCase,\n ScheduledActionHandler,\n DeleteEntryUseCase,\n UpdateEntryUseCase,\n ScheduledActionModel,\n IdentityContext\n ]\n});\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;AAC5C,SACIC,6BAA6B,IAAIC,kBAAkB,EACnDC,oBAAoB,EACpBC,oBAAoB;AAExB,SAASC,yBAAyB;AAClC,SAEIC,sBAAsB,EACtBC,oBAAoB;AAExB,SAASC,4BAA4B,EAAEC,+BAA+B;AACtE,SAASC,kBAAkB,QAAQ,qEAAqE;AACxG,SAASC,kBAAkB,QAAQ,qEAAqE;AACxG,SAASC,4BAA4B;AAErC,SACIC,qBAAqB,EACrBC,eAAe,QACZ,6DAA6D;;AAEpE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,iCAAiC,CAAyC;EACrEC,WAAWA,CACNC,yBAA8D,EAC9DC,aAA+C,EAC/CC,kBAAgD,EAChDC,kBAAgD,EAChDC,KAAqC,EACrCC,eAA0C,EACpD;IAAA,KANUL,yBAA8D,GAA9DA,yBAA8D;IAAA,KAC9DC,aAA+C,GAA/CA,aAA+C;IAAA,KAC/CC,kBAAgD,GAAhDA,kBAAgD;IAAA,KAChDC,kBAAgD,GAAhDA,kBAAgD;IAAA,KAChDC,KAAqC,GAArCA,KAAqC;IAAA,KACrCC,eAA0C,GAA1CA,eAA0C;EACnD;EAEH,MAAaC,OAAOA,CAChBC,EAAU,EACqC;IAC/C;IACA,OAAO,IAAI,CAACC,aAAa,CAAID,EAAE,CAAC;IAChC;EACJ;EAEA,MAAcC,aAAaA,CACvBD,EAAU,EACqC;IAC/C;IACA,MAAME,SAAS,GAAG,MAAM,IAAI,CAACT,yBAAyB,CAACM,OAAO,CAAIC,EAAE,CAAC;IAErE,IAAIE,SAAS,C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f,eAAe,CAAC;;MAEhD;MACA,MAAMgB,YAAY,GAAG,MAAM,IAAI,CAAC5B,kBAAkB,CAACI,OAAO,CAAC,IAAI,CAACF,KAAK,EAAEkB,UAAU,EAAE;QAC/ES,KAAK,EAAE,IAAI;QACXC,WAAW,EAAE;MACjB,CAAC,CAAC;MAEF,IAAIF,YAAY,CAACpB,MAAM,CAAC,CAAC,EAAE;QACvB,OAAO3B,MAAM,CAAC8B,IAAI,CACd,IAAIrB,+BAA+B,CAAC,IAAIyC,KAAK,CAACH,YAAY,CAACnB,KAAK,CAACiB,OAAO,CAAC,CAC7E,CAAC;MACL;MAEA,OAAO7C,MAAM,CAACmD,EAAE,CAAC,CAAC;IACtB,CAAC,CAAC,OAAOvB,KAAK,EAAE;MACZ,MAAMwB,cAAc,GAAG,IAAIjD,oBAAoB,CAC3C,uCAAwCyB,KAAK,CAAWiB,OAAO,EAAE,EACjEjB,KACJ,CAAC;;MAED;MACA,MAAM,IAAI,CAACR,kBAAkB,CAACG,OAAO,CAAsB,IAAI,CAACF,KAAK,EAAEkB,UAAU,EAAE;QAC/EK,MAAM,EAAE;UACJhB,KAAK,EAAEwB,cAAc,CAACP;QAC1B;MACJ,CAAC,CAAC;MAEF,OAAO7C,MAAM,CAAC8B,IAAI,CAACsB,cAAc,CAAC;IACtC;EACJ;AACJ;AAEA,OAAO,MAAMnD,6BAA6B,GAAGC,kBAAkB,CAACmD,oBAAoB,CAAC;EACjFC,cAAc,EAAEvC,iCAAiC;EACjDwC,YAAY,EAAE,CACVlD,yBAAyB,EACzBC,sBAAsB,EACtBI,kBAAkB,EAClBC,kBAAkB,EAClBJ,oBAAoB,EACpBO,eAAe;AAEvB,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["Result","ExecuteScheduledActionUseCase","UseCaseAbstraction","ExecutionFailedError","HandlerNotFoundError","GetScheduledActionUseCase","ScheduledActionHandler","ScheduledActionModel","ScheduledActionNotFoundError","ScheduledActionPersistenceError","DeleteEntryUseCase","UpdateEntryUseCase","ScheduledActionIdWithVersion","AuthenticatedIdentity","IdentityContext","ExecuteScheduledActionUseCaseImpl","constructor","getScheduledActionUseCase","actionHandler","deleteEntryUseCase","updateEntryUseCase","model","identityContext","execute","params","withoutAuthorization","executeAction","id","getResult","isFail","error","code","fail","scheduledAction","value","scheduledBy","setIdentity","type","displayName","context","canAccessTenant","scheduleId","from","canHandle","namespace","actionType","values","message","handle","deleteResult","force","permanently","Error","ok","executionError","createImplementation","implementation","dependencies"],"sources":["ExecuteScheduledActionUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n ExecuteScheduledActionUseCase as UseCaseAbstraction,\n ExecutionFailedError,\n HandlerNotFoundError\n} from \"./abstractions.js\";\nimport { GetScheduledActionUseCase } from \"~/features/GetScheduledAction/abstractions.js\";\nimport {\n type IScheduledAction,\n ScheduledActionHandler,\n ScheduledActionModel\n} from \"~/shared/abstractions.js\";\nimport { ScheduledActionNotFoundError, ScheduledActionPersistenceError } from \"~/domain/errors.js\";\nimport { DeleteEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js\";\nimport { UpdateEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/UpdateEntry/index.js\";\nimport { ScheduledActionIdWithVersion } from \"~/domain/ScheduledActionIdWithVersion.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport {\n AuthenticatedIdentity,\n IdentityContext\n} from \"@webiny/api-core/features/security/IdentityContext/index.js\";\n\n/**\n * Executes a scheduled action\n *\n * Flow:\n * 1. Load scheduled action from CMS\n * 2. Find registered handler for namespace + actionType\n * 3. Execute handler\n * 4. Delete schedule entry on success\n * 5. Update entry with error on failure (for debugging/audit)\n */\nclass ExecuteScheduledActionUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private getScheduledActionUseCase: GetScheduledActionUseCase.Interface,\n private actionHandler: ScheduledActionHandler.Interface,\n private deleteEntryUseCase: DeleteEntryUseCase.Interface,\n private updateEntryUseCase: UpdateEntryUseCase.Interface,\n private model: ScheduledActionModel.Interface,\n private identityContext: IdentityContext.Interface\n ) {}\n\n public async execute<T extends GenericRecord>(\n params: UseCaseAbstraction.Params\n ): Promise<Result<void, UseCaseAbstraction.Error>> {\n return this.identityContext.withoutAuthorization(async () => {\n return this.executeAction<T>(params);\n });\n }\n\n private async executeAction<T extends GenericRecord>(\n params: UseCaseAbstraction.Params\n ): Promise<Result<void, UseCaseAbstraction.Error>> {\n const { id } = params;\n // Load scheduled action\n const getResult = await this.getScheduledActionUseCase.execute<T>(params);\n\n if (getResult.isFail()) {\n const error = getResult.error;\n\n if (error.code === \"Scheduler/ScheduledAction/NotFound\") {\n return Result.fail(new ScheduledActionNotFoundError(id));\n }\n\n return Result.fail(error);\n }\n const scheduledAction = getResult.value;\n\n /**\n * When executing the scheduled action, we need a user which has access to perform the action.\n * We will set a user which created the scheduled action as the execution user.\n */\n const scheduledBy = scheduledAction.scheduledBy;\n this.identityContext.setIdentity(\n new AuthenticatedIdentity({\n id: scheduledBy.id,\n type: scheduledBy.type,\n displayName: scheduledBy.displayName ?? \"\",\n context: {\n canAccessTenant: true\n }\n })\n );\n\n const scheduleId = ScheduledActionIdWithVersion.from(id);\n\n // Check if the handler can handle this action\n if (!this.actionHandler.canHandle(scheduledAction.namespace, scheduledAction.actionType)) {\n const error = new HandlerNotFoundError(\n scheduledAction.namespace,\n scheduledAction.actionType\n );\n\n // Update entry with error for debugging\n await this.updateEntryUseCase.execute<IScheduledAction<T>>(this.model, scheduleId, {\n values: {\n error: error.message\n }\n });\n\n return Result.fail(error);\n }\n\n // Execute handler\n try {\n await this.actionHandler.handle(scheduledAction);\n\n // Delete schedule entry on success\n const deleteResult = await this.deleteEntryUseCase.execute(this.model, scheduleId, {\n force: true,\n permanently: true\n });\n\n if (deleteResult.isFail()) {\n return Result.fail(\n new ScheduledActionPersistenceError(new Error(deleteResult.error.message))\n );\n }\n\n return Result.ok();\n } catch (error) {\n const executionError = new ExecutionFailedError(\n `Failed to execute scheduled action: ${(error as Error).message}`,\n error as Error\n );\n\n // Update entry with error for debugging\n await this.updateEntryUseCase.execute<IScheduledAction<T>>(this.model, scheduleId, {\n values: {\n error: executionError.message\n }\n });\n\n return Result.fail(executionError);\n }\n }\n}\n\nexport const ExecuteScheduledActionUseCase = UseCaseAbstraction.createImplementation({\n implementation: ExecuteScheduledActionUseCaseImpl,\n dependencies: [\n GetScheduledActionUseCase,\n ScheduledActionHandler,\n DeleteEntryUseCase,\n UpdateEntryUseCase,\n ScheduledActionModel,\n IdentityContext\n ]\n});\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;AAC5C,SACIC,6BAA6B,IAAIC,kBAAkB,EACnDC,oBAAoB,EACpBC,oBAAoB;AAExB,SAASC,yBAAyB;AAClC,SAEIC,sBAAsB,EACtBC,oBAAoB;AAExB,SAASC,4BAA4B,EAAEC,+BAA+B;AACtE,SAASC,kBAAkB,QAAQ,qEAAqE;AACxG,SAASC,kBAAkB,QAAQ,qEAAqE;AACxG,SAASC,4BAA4B;AAErC,SACIC,qBAAqB,EACrBC,eAAe,QACZ,6DAA6D;;AAEpE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,iCAAiC,CAAyC;EACrEC,WAAWA,CACNC,yBAA8D,EAC9DC,aAA+C,EAC/CC,kBAAgD,EAChDC,kBAAgD,EAChDC,KAAqC,EACrCC,eAA0C,EACpD;IAAA,KANUL,yBAA8D,GAA9DA,yBAA8D;IAAA,KAC9DC,aAA+C,GAA/CA,aAA+C;IAAA,KAC/CC,kBAAgD,GAAhDA,kBAAgD;IAAA,KAChDC,kBAAgD,GAAhDA,kBAAgD;IAAA,KAChDC,KAAqC,GAArCA,KAAqC;IAAA,KACrCC,eAA0C,GAA1CA,eAA0C;EACnD;EAEH,MAAaC,OAAOA,CAChBC,MAAiC,EACc;IAC/C,OAAO,IAAI,CAACF,eAAe,CAACG,oBAAoB,CAAC,YAAY;MAC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,EACtBI,kBAAkB,EAClBC,kBAAkB,EAClBJ,oBAAoB,EACpBO,eAAe;AAEvB,CAAC,CAAC","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import { IScheduledAction, ScheduledActionHandler } from "../../shared/abstractions.js";
1
+ import { IScheduledAction, ScheduledActionHandler, type ScheduledActionType } from "../../shared/abstractions.js";
2
2
  import type { GenericRecord } from "@webiny/api/types.js";
3
3
  /**
4
4
  * Composite handler that iterates through all registered handlers
@@ -10,7 +10,7 @@ import type { GenericRecord } from "@webiny/api/types.js";
10
10
  declare class ScheduledActionHandlerCompositeImpl implements ScheduledActionHandler.Interface {
11
11
  private handlers;
12
12
  constructor(handlers: ScheduledActionHandler.Interface[]);
13
- canHandle(namespace: string, actionType: string): boolean;
13
+ canHandle(namespace: string, actionType: ScheduledActionType): boolean;
14
14
  handle<T extends GenericRecord>(action: IScheduledAction<T>): Promise<void>;
15
15
  }
16
16
  export declare const ScheduledActionHandlerComposite: typeof ScheduledActionHandlerCompositeImpl & {
@@ -1 +1 @@
1
- {"version":3,"names":["ScheduledActionHandler","ScheduledActionHandlerCompositeImpl","constructor","handlers","canHandle","namespace","actionType","some","handler","handle","action","find","h","console","log","ScheduledActionHandlerComposite","createComposite","implementation","dependencies","multiple"],"sources":["ScheduledActionHandlerComposite.ts"],"sourcesContent":["import { IScheduledAction, ScheduledActionHandler } from \"~/shared/abstractions.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\n/**\n * Composite handler that iterates through all registered handlers\n * to find one that can handle the given namespace + actionType combination.\n *\n * This is registered as a composite via container.registerComposite(),\n * and the DI container will automatically inject all registered handlers.\n */\nclass ScheduledActionHandlerCompositeImpl implements ScheduledActionHandler.Interface {\n public constructor(private handlers: ScheduledActionHandler.Interface[]) {}\n\n public canHandle(namespace: string, actionType: string): boolean {\n return this.handlers.some(handler => handler.canHandle(namespace, actionType));\n }\n\n public async handle<T extends GenericRecord>(action: IScheduledAction<T>): Promise<void> {\n const handler = this.handlers.find(h => h.canHandle(action.namespace, action.actionType));\n\n if (!handler) {\n console.log(\n `No handler found for namespace \"${action.namespace}\" and actionType \"${action.actionType}\"`\n );\n return;\n }\n\n await handler.handle(action);\n }\n}\n\nexport const ScheduledActionHandlerComposite = ScheduledActionHandler.createComposite({\n implementation: ScheduledActionHandlerCompositeImpl,\n dependencies: [[ScheduledActionHandler, { multiple: true }]]\n});\n"],"mappings":"AAAA,SAA2BA,sBAAsB;AAGjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,mCAAmC,CAA6C;EAC3EC,WAAWA,CAASC,QAA4C,EAAE;IAAA,KAA9CA,QAA4C,GAA5CA,QAA4C;EAAG;EAEnEC,SAASA,CAACC,SAAiB,EAAEC,UAAkB,EAAW;IAC7D,OAAO,IAAI,CAACH,QAAQ,CAACI,IAAI,CAACC,OAAO,IAAIA,OAAO,CAACJ,SAAS,CAACC,SAAS,EAAEC,UAAU,CAAC,CAAC;EAClF;EAEA,MAAaG,MAAMA,CAA0BC,MAA2B,EAAiB;IACrF,MAAMF,OAAO,GAAG,IAAI,CAACL,QAAQ,CAACQ,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACR,SAAS,CAACM,MAAM,CAACL,SAAS,EAAEK,MAAM,CAACJ,UAAU,CAAC,CAAC;IAEzF,IAAI,CAACE,OAAO,EAAE;MACVK,OAAO,CAACC,GAAG,CACP,mCAAmCJ,MAAM,CAACL,SAAS,qBAAqBK,MAAM,CAACJ,UAAU,GAC7F,CAAC;MACD;IACJ;IAEA,MAAME,OAAO,CAACC,MAAM,CAACC,MAAM,CAAC;EAChC;AACJ;AAEA,OAAO,MAAMK,+BAA+B,GAAGf,sBAAsB,CAACgB,eAAe,CAAC;EAClFC,cAAc,EAAEhB,mCAAmC;EACnDiB,YAAY,EAAE,CAAC,CAAClB,sBAAsB,EAAE;IAAEmB,QAAQ,EAAE;EAAK,CAAC,CAAC;AAC/D,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["ScheduledActionHandler","ScheduledActionHandlerCompositeImpl","constructor","handlers","canHandle","namespace","actionType","some","handler","handle","action","find","h","console","log","ScheduledActionHandlerComposite","createComposite","implementation","dependencies","multiple"],"sources":["ScheduledActionHandlerComposite.ts"],"sourcesContent":["import {\n IScheduledAction,\n ScheduledActionHandler,\n type ScheduledActionType\n} from \"~/shared/abstractions.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\n/**\n * Composite handler that iterates through all registered handlers\n * to find one that can handle the given namespace + actionType combination.\n *\n * This is registered as a composite via container.registerComposite(),\n * and the DI container will automatically inject all registered handlers.\n */\nclass ScheduledActionHandlerCompositeImpl implements ScheduledActionHandler.Interface {\n public constructor(private handlers: ScheduledActionHandler.Interface[]) {}\n\n public canHandle(namespace: string, actionType: ScheduledActionType): boolean {\n return this.handlers.some(handler => handler.canHandle(namespace, actionType));\n }\n\n public async handle<T extends GenericRecord>(action: IScheduledAction<T>): Promise<void> {\n const handler = this.handlers.find(h => h.canHandle(action.namespace, action.actionType));\n\n if (!handler) {\n console.log(\n `No handler found for namespace \"${action.namespace}\" and actionType \"${action.actionType}\"`\n );\n return;\n }\n\n await handler.handle(action);\n }\n}\n\nexport const ScheduledActionHandlerComposite = ScheduledActionHandler.createComposite({\n implementation: ScheduledActionHandlerCompositeImpl,\n dependencies: [[ScheduledActionHandler, { multiple: true }]]\n});\n"],"mappings":"AAAA,SAEIA,sBAAsB;AAK1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,mCAAmC,CAA6C;EAC3EC,WAAWA,CAASC,QAA4C,EAAE;IAAA,KAA9CA,QAA4C,GAA5CA,QAA4C;EAAG;EAEnEC,SAASA,CAACC,SAAiB,EAAEC,UAA+B,EAAW;IAC1E,OAAO,IAAI,CAACH,QAAQ,CAACI,IAAI,CAACC,OAAO,IAAIA,OAAO,CAACJ,SAAS,CAACC,SAAS,EAAEC,UAAU,CAAC,CAAC;EAClF;EAEA,MAAaG,MAAMA,CAA0BC,MAA2B,EAAiB;IACrF,MAAMF,OAAO,GAAG,IAAI,CAACL,QAAQ,CAACQ,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACR,SAAS,CAACM,MAAM,CAACL,SAAS,EAAEK,MAAM,CAACJ,UAAU,CAAC,CAAC;IAEzF,IAAI,CAACE,OAAO,EAAE;MACVK,OAAO,CAACC,GAAG,CACP,mCAAmCJ,MAAM,CAACL,SAAS,qBAAqBK,MAAM,CAACJ,UAAU,GAC7F,CAAC;MACD;IACJ;IAEA,MAAME,OAAO,CAACC,MAAM,CAACC,MAAM,CAAC;EAChC;AACJ;AAEA,OAAO,MAAMK,+BAA+B,GAAGf,sBAAsB,CAACgB,eAAe,CAAC;EAClFC,cAAc,EAAEhB,mCAAmC;EACnDiB,YAAY,EAAE,CAAC,CAAClB,sBAAsB,EAAE;IAAEmB,QAAQ,EAAE;EAAK,CAAC,CAAC;AAC/D,CAAC,CAAC","ignoreList":[]}
@@ -1,5 +1,5 @@
1
1
  import { Result } from "@webiny/feature/api";
2
- import { ScheduledActionNotFoundError, ScheduledActionPersistenceError } from "../../domain/errors.js";
2
+ import { NotAuthorizedError, ScheduledActionNotFoundError, ScheduledActionPersistenceError } from "../../domain/errors.js";
3
3
  /**
4
4
  * ExecuteScheduledActionUseCase - Execute a scheduled action
5
5
  *
@@ -18,15 +18,22 @@ export interface IExecuteScheduledActionErrors {
18
18
  persistence: ScheduledActionPersistenceError;
19
19
  handlerNotFound: HandlerNotFoundError;
20
20
  executionFailed: ExecutionFailedError;
21
+ unauthorized: NotAuthorizedError;
21
22
  }
22
23
  type ExecuteScheduledActionError = IExecuteScheduledActionErrors[keyof IExecuteScheduledActionErrors];
24
+ export interface IExecuteScheduledActionUseCaseParams {
25
+ namespace: string;
26
+ id: string;
27
+ }
23
28
  export interface IExecuteScheduledActionUseCase {
24
- execute(scheduleId: string): Promise<Result<void, ExecuteScheduledActionError>>;
29
+ execute(params: IExecuteScheduledActionUseCaseParams): Promise<Result<void, ExecuteScheduledActionError>>;
25
30
  }
31
+ /** Execute a scheduled action immediately. */
26
32
  export declare const ExecuteScheduledActionUseCase: import("@webiny/di").Abstraction<IExecuteScheduledActionUseCase>;
27
33
  export declare namespace ExecuteScheduledActionUseCase {
28
34
  type Interface = IExecuteScheduledActionUseCase;
29
35
  type Error = ExecuteScheduledActionError;
36
+ type Params = IExecuteScheduledActionUseCaseParams;
30
37
  }
31
38
  /**
32
39
  * Handler not found error
@@ -14,7 +14,8 @@ import { createAbstraction } from "@webiny/feature/api";
14
14
  * 5. Update entry with error on failure
15
15
  */
16
16
 
17
- export const ExecuteScheduledActionUseCase = createAbstraction("ExecuteScheduledActionUseCase");
17
+ /** Execute a scheduled action immediately. */
18
+ export const ExecuteScheduledActionUseCase = createAbstraction("Scheduler/ExecuteScheduledActionUseCase");
18
19
  /**
19
20
  * Handler not found error
20
21
  */
@@ -1 +1 @@
1
- {"version":3,"names":["createAbstraction","ExecuteScheduledActionUseCase","HandlerNotFoundError","Error","code","constructor","namespace","actionType","name","ExecutionFailedError","message","originalError"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { ScheduledActionNotFoundError, ScheduledActionPersistenceError } from \"~/domain/errors.js\";\n\n/**\n * ExecuteScheduledActionUseCase - Execute a scheduled action\n *\n * This is triggered by EventBridge when a schedule fires.\n * Finds the appropriate handler based on namespace + actionType and executes it.\n *\n * Flow:\n * 1. Load scheduled action from CMS\n * 2. Find registered handler for namespace + actionType\n * 3. Execute handler\n * 4. Delete schedule entry on success\n * 5. Update entry with error on failure\n */\n\nexport interface IExecuteScheduledActionErrors {\n notFound: ScheduledActionNotFoundError;\n persistence: ScheduledActionPersistenceError;\n handlerNotFound: HandlerNotFoundError;\n executionFailed: ExecutionFailedError;\n}\n\ntype ExecuteScheduledActionError =\n IExecuteScheduledActionErrors[keyof IExecuteScheduledActionErrors];\n\nexport interface IExecuteScheduledActionUseCase {\n execute(scheduleId: string): Promise<Result<void, ExecuteScheduledActionError>>;\n}\n\nexport const ExecuteScheduledActionUseCase = createAbstraction<IExecuteScheduledActionUseCase>(\n \"ExecuteScheduledActionUseCase\"\n);\n\nexport namespace ExecuteScheduledActionUseCase {\n export type Interface = IExecuteScheduledActionUseCase;\n export type Error = ExecuteScheduledActionError;\n}\n\n/**\n * Handler not found error\n */\nexport class HandlerNotFoundError extends Error {\n readonly code = \"Scheduler/Handler/NotFound\" as const;\n\n constructor(namespace: string, actionType: string) {\n super(`No handler registered for namespace \"${namespace}\" and actionType \"${actionType}\"`);\n this.name = \"HandlerNotFoundError\";\n }\n}\n\n/**\n * Execution failed error\n */\nexport class ExecutionFailedError extends Error {\n readonly code = \"Scheduler/Execution/Failed\" as const;\n\n constructor(\n message: string,\n public readonly originalError?: Error\n ) {\n super(message);\n this.name = \"ExecutionFailedError\";\n }\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;;AAIvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAgBA,OAAO,MAAMC,6BAA6B,GAAGD,iBAAiB,CAC1D,+BACJ,CAAC;AAOD;AACA;AACA;AACA,OAAO,MAAME,oBAAoB,SAASC,KAAK,CAAC;EACnCC,IAAI,GAAG,4BAA4B;EAE5CC,WAAWA,CAACC,SAAiB,EAAEC,UAAkB,EAAE;IAC/C,KAAK,CAAC,wCAAwCD,SAAS,qBAAqBC,UAAU,GAAG,CAAC;IAC1F,IAAI,CAACC,IAAI,GAAG,sBAAsB;EACtC;AACJ;;AAEA;AACA;AACA;AACA,OAAO,MAAMC,oBAAoB,SAASN,KAAK,CAAC;EACnCC,IAAI,GAAG,4BAA4B;EAE5CC,WAAWA,CACPK,OAAe,EACCC,aAAqB,EACvC;IACE,KAAK,CAACD,OAAO,CAAC;IAAC,KAFCC,aAAqB,GAArBA,aAAqB;IAGrC,IAAI,CAACH,IAAI,GAAG,sBAAsB;EACtC;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["createAbstraction","ExecuteScheduledActionUseCase","HandlerNotFoundError","Error","code","constructor","namespace","actionType","name","ExecutionFailedError","message","originalError"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport {\n NotAuthorizedError,\n ScheduledActionNotFoundError,\n ScheduledActionPersistenceError\n} from \"~/domain/errors.js\";\n\n/**\n * ExecuteScheduledActionUseCase - Execute a scheduled action\n *\n * This is triggered by EventBridge when a schedule fires.\n * Finds the appropriate handler based on namespace + actionType and executes it.\n *\n * Flow:\n * 1. Load scheduled action from CMS\n * 2. Find registered handler for namespace + actionType\n * 3. Execute handler\n * 4. Delete schedule entry on success\n * 5. Update entry with error on failure\n */\n\nexport interface IExecuteScheduledActionErrors {\n notFound: ScheduledActionNotFoundError;\n persistence: ScheduledActionPersistenceError;\n handlerNotFound: HandlerNotFoundError;\n executionFailed: ExecutionFailedError;\n unauthorized: NotAuthorizedError;\n}\n\ntype ExecuteScheduledActionError =\n IExecuteScheduledActionErrors[keyof IExecuteScheduledActionErrors];\n\nexport interface IExecuteScheduledActionUseCaseParams {\n namespace: string;\n id: string;\n}\n\nexport interface IExecuteScheduledActionUseCase {\n execute(\n params: IExecuteScheduledActionUseCaseParams\n ): Promise<Result<void, ExecuteScheduledActionError>>;\n}\n\n/** Execute a scheduled action immediately. */\nexport const ExecuteScheduledActionUseCase = createAbstraction<IExecuteScheduledActionUseCase>(\n \"Scheduler/ExecuteScheduledActionUseCase\"\n);\n\nexport namespace ExecuteScheduledActionUseCase {\n export type Interface = IExecuteScheduledActionUseCase;\n export type Error = ExecuteScheduledActionError;\n export type Params = IExecuteScheduledActionUseCaseParams;\n}\n\n/**\n * Handler not found error\n */\nexport class HandlerNotFoundError extends Error {\n readonly code = \"Scheduler/Handler/NotFound\" as const;\n\n constructor(namespace: string, actionType: string) {\n super(`No handler registered for namespace \"${namespace}\" and actionType \"${actionType}\"`);\n this.name = \"HandlerNotFoundError\";\n }\n}\n\n/**\n * Execution failed error\n */\nexport class ExecutionFailedError extends Error {\n readonly code = \"Scheduler/Execution/Failed\" as const;\n\n constructor(\n message: string,\n public readonly originalError?: Error\n ) {\n super(message);\n this.name = \"ExecutionFailedError\";\n }\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;;AAQvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAwBA;AACA,OAAO,MAAMC,6BAA6B,GAAGD,iBAAiB,CAC1D,yCACJ,CAAC;AAQD;AACA;AACA;AACA,OAAO,MAAME,oBAAoB,SAASC,KAAK,CAAC;EACnCC,IAAI,GAAG,4BAA4B;EAE5CC,WAAWA,CAACC,SAAiB,EAAEC,UAAkB,EAAE;IAC/C,KAAK,CAAC,wCAAwCD,SAAS,qBAAqBC,UAAU,GAAG,CAAC;IAC1F,IAAI,CAACC,IAAI,GAAG,sBAAsB;EACtC;AACJ;;AAEA;AACA;AACA;AACA,OAAO,MAAMC,oBAAoB,SAASN,KAAK,CAAC;EACnCC,IAAI,GAAG,4BAA4B;EAE5CC,WAAWA,CACPK,OAAe,EACCC,aAAqB,EACvC;IACE,KAAK,CAACD,OAAO,CAAC;IAAC,KAFCC,aAAqB,GAArBA,aAAqB;IAGrC,IAAI,CAACH,IAAI,GAAG,sBAAsB;EACtC;AACJ","ignoreList":[]}
@@ -4,6 +4,8 @@ import type { IScheduledAction } from "../../shared/abstractions.js";
4
4
  import { ScheduledActionModel } from "../../shared/abstractions.js";
5
5
  import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById/index.js";
6
6
  import type { GenericRecord } from "@webiny/api/types.js";
7
+ import { SchedulerPermissions } from "../../domain/permissions.js";
8
+ import { IdentityContext } from "@webiny/api-core/exports/api/security.js";
7
9
  /**
8
10
  * Retrieves a scheduled action by its ID
9
11
  *
@@ -15,8 +17,10 @@ import type { GenericRecord } from "@webiny/api/types.js";
15
17
  declare class GetScheduledActionUseCaseImpl implements UseCaseAbstraction.Interface {
16
18
  private getEntryByIdUseCase;
17
19
  private model;
18
- constructor(getEntryByIdUseCase: GetEntryByIdUseCase.Interface, model: ScheduledActionModel.Interface);
19
- execute<T extends GenericRecord>(id: string): Promise<Result<IScheduledAction<T>, UseCaseAbstraction.Error>>;
20
+ private permissions;
21
+ private identityContext;
22
+ constructor(getEntryByIdUseCase: GetEntryByIdUseCase.Interface, model: ScheduledActionModel.Interface, permissions: SchedulerPermissions.Interface, identityContext: IdentityContext.Interface);
23
+ execute<T extends GenericRecord>(params: UseCaseAbstraction.Params): Promise<Result<IScheduledAction<T>, UseCaseAbstraction.Error>>;
20
24
  }
21
25
  export declare const GetScheduledActionUseCase: typeof GetScheduledActionUseCaseImpl & {
22
26
  __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetScheduledActionUseCase>;
@@ -1,9 +1,13 @@
1
1
  import { Result } from "@webiny/feature/api";
2
2
  import { GetScheduledActionUseCase as UseCaseAbstraction } from "./abstractions.js";
3
3
  import { ScheduledActionModel } from "../../shared/abstractions.js";
4
- import { ScheduledActionNotFoundError, ScheduledActionPersistenceError } from "../../domain/errors.js";
4
+ import { NotAuthorizedError, ScheduledActionNotFoundError, ScheduledActionPersistenceError } from "../../domain/errors.js";
5
5
  import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById/index.js";
6
6
  import { ScheduledActionIdWithVersion } from "../../domain/ScheduledActionIdWithVersion.js";
7
+ import { SchedulerPermissions } from "../../domain/permissions.js";
8
+ import { IdentityContext } from "@webiny/api-core/exports/api/security.js";
9
+ import { ScheduledActionMapper } from "../../domain/ScheduledActionMapper.js";
10
+
7
11
  /**
8
12
  * Retrieves a scheduled action by its ID
9
13
  *
@@ -13,11 +17,21 @@ import { ScheduledActionIdWithVersion } from "../../domain/ScheduledActionIdWith
13
17
  * 3. Transform CMS entry to IScheduledAction format
14
18
  */
15
19
  class GetScheduledActionUseCaseImpl {
16
- constructor(getEntryByIdUseCase, model) {
20
+ constructor(getEntryByIdUseCase, model, permissions, identityContext) {
17
21
  this.getEntryByIdUseCase = getEntryByIdUseCase;
18
22
  this.model = model;
23
+ this.permissions = permissions;
24
+ this.identityContext = identityContext;
19
25
  }
20
- async execute(id) {
26
+ async execute(params) {
27
+ const hasPermission = await this.permissions.canRead("action");
28
+ if (!hasPermission) {
29
+ return Result.fail(new NotAuthorizedError());
30
+ }
31
+ const {
32
+ id,
33
+ namespace
34
+ } = params;
21
35
  // Get entry from CMS
22
36
  const scheduleId = ScheduledActionIdWithVersion.from(id);
23
37
  const entryResult = await this.getEntryByIdUseCase.execute(this.model, scheduleId);
@@ -27,23 +41,26 @@ class GetScheduledActionUseCaseImpl {
27
41
  }
28
42
  return Result.fail(new ScheduledActionPersistenceError(entryResult.error));
29
43
  }
44
+ const ownRecordsOnly = await this.permissions.onlyOwnRecords("action");
45
+ if (ownRecordsOnly) {
46
+ if (entryResult.value.createdBy.id !== this.identityContext.getIdentity().id) {
47
+ return Result.fail(new NotAuthorizedError());
48
+ }
49
+ }
30
50
  const entry = entryResult.value;
31
- return Result.ok({
32
- id: entry.entryId,
33
- namespace: entry.values.namespace,
34
- actionType: entry.values.actionType,
35
- targetId: entry.values.targetId,
36
- scheduledBy: entry.values.scheduledBy,
37
- scheduledFor: entry.values.scheduledFor,
38
- payload: entry.values.payload,
39
- title: entry.values.title,
40
- error: entry.values.error
41
- });
51
+ /**
52
+ * Always check if the namespace is correct because entry is loaded directly, not via filtering.
53
+ */
54
+ if (entry.values.namespace !== namespace) {
55
+ return Result.fail(new ScheduledActionNotFoundError(scheduleId));
56
+ }
57
+ const action = ScheduledActionMapper.toAction(entry);
58
+ return Result.ok(action);
42
59
  }
43
60
  }
44
61
  export const GetScheduledActionUseCase = UseCaseAbstraction.createImplementation({
45
62
  implementation: GetScheduledActionUseCaseImpl,
46
- dependencies: [GetEntryByIdUseCase, ScheduledActionModel]
63
+ dependencies: [GetEntryByIdUseCase, ScheduledActionModel, SchedulerPermissions.Abstraction, IdentityContext]
47
64
  });
48
65
 
49
66
  //# sourceMappingURL=GetScheduledActionUseCase.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Result","GetScheduledActionUseCase","UseCaseAbstraction","ScheduledActionModel","ScheduledActionNotFoundError","ScheduledActionPersistenceError","GetEntryByIdUseCase","ScheduledActionIdWithVersion","GetScheduledActionUseCaseImpl","constructor","getEntryByIdUseCase","model","execute","id","scheduleId","from","entryResult","isFail","error","code","fail","entry","value","ok","entryId","namespace","values","actionType","targetId","scheduledBy","scheduledFor","payload","title","createImplementation","implementation","dependencies"],"sources":["GetScheduledActionUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { GetScheduledActionUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport type { IScheduledAction } from \"~/shared/abstractions.js\";\nimport { ScheduledActionModel } from \"~/shared/abstractions.js\";\nimport { ScheduledActionNotFoundError, ScheduledActionPersistenceError } from \"~/domain/errors.js\";\nimport { GetEntryByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetEntryById/index.js\";\nimport { ScheduledActionIdWithVersion } from \"~/domain/ScheduledActionIdWithVersion.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\n/**\n * Retrieves a scheduled action by its ID\n *\n * Flow:\n * 1. Fetch schedule entry from CMS storage by ID\n * 2. Return null if not found\n * 3. Transform CMS entry to IScheduledAction format\n */\nclass GetScheduledActionUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private getEntryByIdUseCase: GetEntryByIdUseCase.Interface,\n private model: ScheduledActionModel.Interface\n ) {}\n\n async execute<T extends GenericRecord>(\n id: string\n ): Promise<Result<IScheduledAction<T>, UseCaseAbstraction.Error>> {\n // Get entry from CMS\n const scheduleId = ScheduledActionIdWithVersion.from(id);\n const entryResult = await this.getEntryByIdUseCase.execute<IScheduledAction<T>>(\n this.model,\n scheduleId\n );\n\n if (entryResult.isFail()) {\n if (entryResult.error.code === \"Cms/Entry/NotFound\") {\n return Result.fail(new ScheduledActionNotFoundError(scheduleId));\n }\n\n return Result.fail(new ScheduledActionPersistenceError(entryResult.error));\n }\n\n const entry = entryResult.value;\n\n return Result.ok({\n id: entry.entryId,\n namespace: entry.values.namespace,\n actionType: entry.values.actionType,\n targetId: entry.values.targetId,\n scheduledBy: entry.values.scheduledBy,\n scheduledFor: entry.values.scheduledFor,\n payload: entry.values.payload,\n title: entry.values.title,\n error: entry.values.error\n });\n }\n}\n\nexport const GetScheduledActionUseCase = UseCaseAbstraction.createImplementation({\n implementation: GetScheduledActionUseCaseImpl,\n dependencies: [GetEntryByIdUseCase, ScheduledActionModel]\n});\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;AAC5C,SAASC,yBAAyB,IAAIC,kBAAkB;AAExD,SAASC,oBAAoB;AAC7B,SAASC,4BAA4B,EAAEC,+BAA+B;AACtE,SAASC,mBAAmB,QAAQ,sEAAsE;AAC1G,SAASC,4BAA4B;AAGrC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,6BAA6B,CAAyC;EACxEC,WAAWA,CACCC,mBAAkD,EAClDC,KAAqC,EAC/C;IAAA,KAFUD,mBAAkD,GAAlDA,mBAAkD;IAAA,KAClDC,KAAqC,GAArCA,KAAqC;EAC9C;EAEH,MAAMC,OAAOA,CACTC,EAAU,EACoD;IAC9D;IACA,MAAMC,UAAU,GAAGP,4BAA4B,CAACQ,IAAI,CAACF,EAAE,CAAC;IACxD,MAAMG,WAAW,GAAG,MAAM,IAAI,CAACN,mBAAmB,CAACE,OAAO,CACtD,IAAI,CAACD,KAAK,EACVG,UACJ,CAAC;IAED,IAAIE,WAAW,CAACC,MAAM,CAAC,CAAC,EAAE;MACtB,IAAID,WAAW,CAACE,KAAK,CAACC,IAAI,KAAK,oBAAoB,EAAE;QACjD,OAAOnB,MAAM,CAACoB,IAAI,CAAC,IAAIhB,4BAA4B,CAACU,UAAU,CAAC,CAAC;MACpE;MAEA,OAAOd,MAAM,CAACoB,IAAI,CAAC,IAAIf,+BAA+B,CAACW,WAAW,CAACE,KAAK,CAAC,CAAC;IAC9E;IAEA,MAAMG,KAAK,GAAGL,WAAW,CAACM,KAAK;IAE/B,OAAOtB,MAAM,CAACuB,EAAE,CAAC;MACbV,EAAE,EAAEQ,KAAK,CAACG,OAAO;MACjBC,SAAS,EAAEJ,KAAK,CAACK,MAAM,CAACD,SAAS;MACjCE,UAAU,EAAEN,KAAK,CAACK,MAAM,CAACC,UAAU;MACnCC,QAAQ,EAAEP,KAAK,CAACK,MAAM,CAACE,QAAQ;MAC/BC,WAAW,EAAER,KAAK,CAACK,MAAM,CAACG,WAAW;MACrCC,YAAY,EAAET,KAAK,CAACK,MAAM,CAACI,YAAY;MACvCC,OAAO,EAAEV,KAAK,CAACK,MAAM,CAACK,OAAO;MAC7BC,KAAK,EAAEX,KAAK,CAACK,MAAM,CAACM,KAAK;MACzBd,KAAK,EAAEG,KAAK,CAACK,MAAM,CAACR;IACxB,CAAC,CAAC;EACN;AACJ;AAEA,OAAO,MAAMjB,yBAAyB,GAAGC,kBAAkB,CAAC+B,oBAAoB,CAAC;EAC7EC,cAAc,EAAE1B,6BAA6B;EAC7C2B,YAAY,EAAE,CAAC7B,mBAAmB,EAAEH,oBAAoB;AAC5D,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["Result","GetScheduledActionUseCase","UseCaseAbstraction","ScheduledActionModel","NotAuthorizedError","ScheduledActionNotFoundError","ScheduledActionPersistenceError","GetEntryByIdUseCase","ScheduledActionIdWithVersion","SchedulerPermissions","IdentityContext","ScheduledActionMapper","GetScheduledActionUseCaseImpl","constructor","getEntryByIdUseCase","model","permissions","identityContext","execute","params","hasPermission","canRead","fail","id","namespace","scheduleId","from","entryResult","isFail","error","code","ownRecordsOnly","onlyOwnRecords","value","createdBy","getIdentity","entry","values","action","toAction","ok","createImplementation","implementation","dependencies","Abstraction"],"sources":["GetScheduledActionUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { GetScheduledActionUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport type { IScheduledAction, IScheduledActionEntryValues } from \"~/shared/abstractions.js\";\nimport { ScheduledActionModel } from \"~/shared/abstractions.js\";\nimport {\n NotAuthorizedError,\n ScheduledActionNotFoundError,\n ScheduledActionPersistenceError\n} from \"~/domain/errors.js\";\nimport { GetEntryByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetEntryById/index.js\";\nimport { ScheduledActionIdWithVersion } from \"~/domain/ScheduledActionIdWithVersion.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { SchedulerPermissions } from \"~/domain/permissions.js\";\nimport { IdentityContext } from \"@webiny/api-core/exports/api/security.js\";\nimport { ScheduledActionMapper } from \"~/domain/ScheduledActionMapper.js\";\n\n/**\n * Retrieves a scheduled action by its ID\n *\n * Flow:\n * 1. Fetch schedule entry from CMS storage by ID\n * 2. Return null if not found\n * 3. Transform CMS entry to IScheduledAction format\n */\nclass GetScheduledActionUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private getEntryByIdUseCase: GetEntryByIdUseCase.Interface,\n private model: ScheduledActionModel.Interface,\n private permissions: SchedulerPermissions.Interface,\n private identityContext: IdentityContext.Interface\n ) {}\n\n async execute<T extends GenericRecord>(\n params: UseCaseAbstraction.Params\n ): Promise<Result<IScheduledAction<T>, UseCaseAbstraction.Error>> {\n const hasPermission = await this.permissions.canRead(\"action\");\n if (!hasPermission) {\n return Result.fail(new NotAuthorizedError());\n }\n const { id, namespace } = params;\n // Get entry from CMS\n const scheduleId = ScheduledActionIdWithVersion.from(id);\n const entryResult = await this.getEntryByIdUseCase.execute<IScheduledActionEntryValues<T>>(\n this.model,\n scheduleId\n );\n\n if (entryResult.isFail()) {\n if (entryResult.error.code === \"Cms/Entry/NotFound\") {\n return Result.fail(new ScheduledActionNotFoundError(scheduleId));\n }\n\n return Result.fail(new ScheduledActionPersistenceError(entryResult.error));\n }\n\n const ownRecordsOnly = await this.permissions.onlyOwnRecords(\"action\");\n if (ownRecordsOnly) {\n if (entryResult.value.createdBy.id !== this.identityContext.getIdentity().id) {\n return Result.fail(new NotAuthorizedError());\n }\n }\n\n const entry = entryResult.value;\n /**\n * Always check if the namespace is correct because entry is loaded directly, not via filtering.\n */\n if (entry.values.namespace !== namespace) {\n return Result.fail(new ScheduledActionNotFoundError(scheduleId));\n }\n const action = ScheduledActionMapper.toAction<T>(entry);\n\n return Result.ok(action);\n }\n}\n\nexport const GetScheduledActionUseCase = UseCaseAbstraction.createImplementation({\n implementation: GetScheduledActionUseCaseImpl,\n dependencies: [\n GetEntryByIdUseCase,\n ScheduledActionModel,\n SchedulerPermissions.Abstraction,\n IdentityContext\n ]\n});\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;AAC5C,SAASC,yBAAyB,IAAIC,kBAAkB;AAExD,SAASC,oBAAoB;AAC7B,SACIC,kBAAkB,EAClBC,4BAA4B,EAC5BC,+BAA+B;AAEnC,SAASC,mBAAmB,QAAQ,sEAAsE;AAC1G,SAASC,4BAA4B;AAErC,SAASC,oBAAoB;AAC7B,SAASC,eAAe,QAAQ,0CAA0C;AAC1E,SAASC,qBAAqB;;AAE9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,6BAA6B,CAAyC;EACxEC,WAAWA,CACCC,mBAAkD,EAClDC,KAAqC,EACrCC,WAA2C,EAC3CC,eAA0C,EACpD;IAAA,KAJUH,mBAAkD,GAAlDA,mBAAkD;IAAA,KAClDC,KAAqC,GAArCA,KAAqC;IAAA,KACrCC,WAA2C,GAA3CA,WAA2C;IAAA,KAC3CC,eAA0C,GAA1CA,eAA0C;EACnD;EAEH,MAAMC,OAAOA,CACTC,MAAiC,EAC6B;IAC9D,MAAMC,aAAa,GAAG,MAAM,IAAI,CAACJ,WAAW,CAACK,OAAO,CAAC,QAAQ,CAAC;IAC9D,IAAI,CAACD,aAAa,E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OpC,MAAM,CAACwC,EAAE,CAACF,MAAM,CAAC;EAC5B;AACJ;AAEA,OAAO,MAAMrC,yBAAyB,GAAGC,kBAAkB,CAACuC,oBAAoB,CAAC;EAC7EC,cAAc,EAAE9B,6BAA6B;EAC7C+B,YAAY,EAAE,CACVpC,mBAAmB,EACnBJ,oBAAoB,EACpBM,oBAAoB,CAACmC,WAAW,EAChClC,eAAe;AAEvB,CAAC,CAAC","ignoreList":[]}
@@ -1,6 +1,6 @@
1
1
  import { Result } from "@webiny/feature/api";
2
2
  import type { IScheduledAction } from "../../shared/abstractions.js";
3
- import { ScheduledActionNotFoundError, ScheduledActionPersistenceError } from "../../domain/errors.js";
3
+ import { ScheduledActionNotFoundError, ScheduledActionPersistenceError, NotAuthorizedError } from "../../domain/errors.js";
4
4
  import type { GenericRecord } from "@webiny/api/types.js";
5
5
  /**
6
6
  * GetScheduledActionUseCase - Retrieve a scheduled action by ID
@@ -13,14 +13,21 @@ import type { GenericRecord } from "@webiny/api/types.js";
13
13
  export interface IGetScheduledActionErrors {
14
14
  persistence: ScheduledActionPersistenceError;
15
15
  notFound: ScheduledActionNotFoundError;
16
+ unauthorized: NotAuthorizedError;
16
17
  }
17
18
  type GetScheduledActionError = IGetScheduledActionErrors[keyof IGetScheduledActionErrors];
19
+ export interface IGetScheduledActionUseCaseParams {
20
+ namespace: string;
21
+ id: string;
22
+ }
18
23
  export interface IGetScheduledActionUseCase {
19
- execute<T extends GenericRecord>(scheduleId: string): Promise<Result<IScheduledAction<T>, GetScheduledActionError>>;
24
+ execute<T extends GenericRecord>(params: IGetScheduledActionUseCaseParams): Promise<Result<IScheduledAction<T>, GetScheduledActionError>>;
20
25
  }
26
+ /** Retrieve a scheduled action. */
21
27
  export declare const GetScheduledActionUseCase: import("@webiny/di").Abstraction<IGetScheduledActionUseCase>;
22
28
  export declare namespace GetScheduledActionUseCase {
23
29
  type Interface = IGetScheduledActionUseCase;
24
30
  type Error = GetScheduledActionError;
31
+ type Params = IGetScheduledActionUseCaseParams;
25
32
  }
26
33
  export {};
@@ -9,6 +9,7 @@ import { createAbstraction } from "@webiny/feature/api";
9
9
  * Returns null value (Result.ok(null)) if schedule not found.
10
10
  */
11
11
 
12
- export const GetScheduledActionUseCase = createAbstraction("GetScheduledActionUseCase");
12
+ /** Retrieve a scheduled action. */
13
+ export const GetScheduledActionUseCase = createAbstraction("Scheduler/GetScheduledActionUseCase");
13
14
 
14
15
  //# sourceMappingURL=abstractions.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createAbstraction","GetScheduledActionUseCase"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { IScheduledAction } from \"~/shared/abstractions.js\";\nimport { ScheduledActionNotFoundError, ScheduledActionPersistenceError } from \"~/domain/errors.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\n/**\n * GetScheduledActionUseCase - Retrieve a scheduled action by ID\n *\n * Used to check if a schedule exists (for reschedule logic) and to retrieve\n * schedule details for display/management purposes.\n *\n * Returns null value (Result.ok(null)) if schedule not found.\n */\n\nexport interface IGetScheduledActionErrors {\n persistence: ScheduledActionPersistenceError;\n notFound: ScheduledActionNotFoundError;\n}\n\ntype GetScheduledActionError = IGetScheduledActionErrors[keyof IGetScheduledActionErrors];\n\nexport interface IGetScheduledActionUseCase {\n execute<T extends GenericRecord>(\n scheduleId: string\n ): Promise<Result<IScheduledAction<T>, GetScheduledActionError>>;\n}\n\nexport const GetScheduledActionUseCase = createAbstraction<IGetScheduledActionUseCase>(\n \"GetScheduledActionUseCase\"\n);\n\nexport namespace GetScheduledActionUseCase {\n export type Interface = IGetScheduledActionUseCase;\n export type Error = GetScheduledActionError;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;;AAMvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAeA,OAAO,MAAMC,yBAAyB,GAAGD,iBAAiB,CACtD,2BACJ,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["createAbstraction","GetScheduledActionUseCase"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type { IScheduledAction } from \"~/shared/abstractions.js\";\nimport {\n ScheduledActionNotFoundError,\n ScheduledActionPersistenceError,\n NotAuthorizedError\n} from \"~/domain/errors.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\n/**\n * GetScheduledActionUseCase - Retrieve a scheduled action by ID\n *\n * Used to check if a schedule exists (for reschedule logic) and to retrieve\n * schedule details for display/management purposes.\n *\n * Returns null value (Result.ok(null)) if schedule not found.\n */\n\nexport interface IGetScheduledActionErrors {\n persistence: ScheduledActionPersistenceError;\n notFound: ScheduledActionNotFoundError;\n unauthorized: NotAuthorizedError;\n}\n\ntype GetScheduledActionError = IGetScheduledActionErrors[keyof IGetScheduledActionErrors];\n\nexport interface IGetScheduledActionUseCaseParams {\n namespace: string;\n id: string;\n}\n\nexport interface IGetScheduledActionUseCase {\n execute<T extends GenericRecord>(\n params: IGetScheduledActionUseCaseParams\n ): Promise<Result<IScheduledAction<T>, GetScheduledActionError>>;\n}\n\n/** Retrieve a scheduled action. */\nexport const GetScheduledActionUseCase = createAbstraction<IGetScheduledActionUseCase>(\n \"Scheduler/GetScheduledActionUseCase\"\n);\n\nexport namespace GetScheduledActionUseCase {\n export type Interface = IGetScheduledActionUseCase;\n export type Error = GetScheduledActionError;\n export type Params = IGetScheduledActionUseCaseParams;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAgB,qBAAqB;;AAS/D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAqBA;AACA,OAAO,MAAMC,yBAAyB,GAAGD,iBAAiB,CACtD,qCACJ,CAAC","ignoreList":[]}
@@ -0,0 +1,32 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import { GetTargetScheduledActionUseCase as UseCaseAbstraction } from "./abstractions.js";
3
+ import type { IScheduledAction } from "../../shared/abstractions.js";
4
+ import { ScheduledActionModel } from "../../shared/abstractions.js";
5
+ import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById/index.js";
6
+ import type { GenericRecord } from "@webiny/api/types.js";
7
+ import { SchedulerPermissions } from "../../domain/permissions.js";
8
+ import { IdentityContext } from "@webiny/api-core/exports/api/security.js";
9
+ /**
10
+ * Retrieves a scheduled action by its ID
11
+ *
12
+ * Flow:
13
+ * 1. Fetch schedule entry from CMS storage by ID
14
+ * 2. Return null if not found
15
+ * 3. Transform CMS entry to IScheduledAction format
16
+ */
17
+ declare class GetTargetScheduledActionUseCaseImpl implements UseCaseAbstraction.Interface {
18
+ private getEntryByIdUseCase;
19
+ private model;
20
+ private permissions;
21
+ private identityContext;
22
+ constructor(getEntryByIdUseCase: GetEntryByIdUseCase.Interface, model: ScheduledActionModel.Interface, permissions: SchedulerPermissions.Interface, identityContext: IdentityContext.Interface);
23
+ execute<T extends GenericRecord>(params: UseCaseAbstraction.Params): Promise<Result<IScheduledAction<T>, UseCaseAbstraction.Error>>;
24
+ /**
25
+ * We always need to fetch both publish and unpublish actions because we don't know the type of the action that is being searched for.
26
+ */
27
+ private getRecord;
28
+ }
29
+ export declare const GetTargetScheduledActionUseCase: typeof GetTargetScheduledActionUseCaseImpl & {
30
+ __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetTargetScheduledActionUseCase>;
31
+ };
32
+ export {};
@@ -0,0 +1,86 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import { GetTargetScheduledActionUseCase as UseCaseAbstraction } from "./abstractions.js";
3
+ import { ScheduledActionModel } from "../../shared/abstractions.js";
4
+ import { NotAuthorizedError, ScheduledActionNotFoundError, ScheduledActionPersistenceError } from "../../domain/errors.js";
5
+ import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById/index.js";
6
+ import { SchedulerPermissions } from "../../domain/permissions.js";
7
+ import { IdentityContext } from "@webiny/api-core/exports/api/security.js";
8
+ import { ScheduledActionMapper } from "../../domain/ScheduledActionMapper.js";
9
+ import { ScheduledActionId } from "../../domain/ScheduledActionId.js";
10
+ import { ScheduledActionIdWithVersion } from "../../domain/ScheduledActionIdWithVersion.js";
11
+ import { SCHEDULED_ACTION_PUBLISH, SCHEDULED_ACTION_UNPUBLISH } from "../../constants.js";
12
+
13
+ /**
14
+ * Retrieves a scheduled action by its ID
15
+ *
16
+ * Flow:
17
+ * 1. Fetch schedule entry from CMS storage by ID
18
+ * 2. Return null if not found
19
+ * 3. Transform CMS entry to IScheduledAction format
20
+ */
21
+ class GetTargetScheduledActionUseCaseImpl {
22
+ constructor(getEntryByIdUseCase, model, permissions, identityContext) {
23
+ this.getEntryByIdUseCase = getEntryByIdUseCase;
24
+ this.model = model;
25
+ this.permissions = permissions;
26
+ this.identityContext = identityContext;
27
+ }
28
+ async execute(params) {
29
+ const hasPermission = await this.permissions.canRead("action");
30
+ if (!hasPermission) {
31
+ return Result.fail(new NotAuthorizedError());
32
+ }
33
+ const {
34
+ id,
35
+ namespace
36
+ } = params;
37
+ const entryResult = await this.getRecord(params);
38
+ if (entryResult.isFail()) {
39
+ if (entryResult.error.code === "Cms/Entry/NotFound") {
40
+ return Result.fail(new ScheduledActionNotFoundError(id));
41
+ }
42
+ return Result.fail(new ScheduledActionPersistenceError(entryResult.error));
43
+ }
44
+ const ownRecordsOnly = await this.permissions.onlyOwnRecords("action");
45
+ if (ownRecordsOnly) {
46
+ if (entryResult.value.createdBy.id !== this.identityContext.getIdentity().id) {
47
+ return Result.fail(new NotAuthorizedError());
48
+ }
49
+ }
50
+ const entry = entryResult.value;
51
+ /**
52
+ * Always check if the namespace is correct because entry is loaded directly, not via filtering.
53
+ */
54
+ if (entry.values.namespace !== namespace) {
55
+ return Result.fail(new ScheduledActionNotFoundError(id));
56
+ }
57
+ const action = ScheduledActionMapper.toAction(entry);
58
+ return Result.ok(action);
59
+ }
60
+ /**
61
+ * We always need to fetch both publish and unpublish actions because we don't know the type of the action that is being searched for.
62
+ */
63
+ async getRecord(params) {
64
+ const schedulePublishId = ScheduledActionId.from({
65
+ namespace: params.namespace,
66
+ targetId: params.id,
67
+ actionType: SCHEDULED_ACTION_PUBLISH
68
+ });
69
+ const publishResult = await this.getEntryByIdUseCase.execute(this.model, ScheduledActionIdWithVersion.from(schedulePublishId));
70
+ if (publishResult.isOk()) {
71
+ return publishResult;
72
+ }
73
+ const scheduleUnpublishId = ScheduledActionId.from({
74
+ namespace: params.namespace,
75
+ targetId: params.id,
76
+ actionType: SCHEDULED_ACTION_UNPUBLISH
77
+ });
78
+ return this.getEntryByIdUseCase.execute(this.model, ScheduledActionIdWithVersion.from(scheduleUnpublishId));
79
+ }
80
+ }
81
+ export const GetTargetScheduledActionUseCase = UseCaseAbstraction.createImplementation({
82
+ implementation: GetTargetScheduledActionUseCaseImpl,
83
+ dependencies: [GetEntryByIdUseCase, ScheduledActionModel, SchedulerPermissions.Abstraction, IdentityContext]
84
+ });
85
+
86
+ //# sourceMappingURL=GetTargetScheduledActionUseCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Result","GetTargetScheduledActionUseCase","UseCaseAbstraction","ScheduledActionModel","NotAuthorizedError","ScheduledActionNotFoundError","ScheduledActionPersistenceError","GetEntryByIdUseCase","SchedulerPermissions","IdentityContext","ScheduledActionMapper","ScheduledActionId","ScheduledActionIdWithVersion","SCHEDULED_ACTION_PUBLISH","SCHEDULED_ACTION_UNPUBLISH","GetTargetScheduledActionUseCaseImpl","constructor","getEntryByIdUseCase","model","permissions","identityContext","execute","params","hasPermission","canRead","fail","id","namespace","entryResult","getRecord","isFail","error","code","ownRecordsOnly","onlyOwnRecords","value","createdBy","getIdentity","entry","values","action","toAction","ok","schedulePublishId","from","targetId","actionType","publishResult","isOk","scheduleUnpublishId","createImplementation","implementation","dependencies","Abstraction"],"sources":["GetTargetScheduledActionUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { GetTargetScheduledActionUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport type { IScheduledAction, IScheduledActionEntryValues } from \"~/shared/abstractions.js\";\nimport { ScheduledActionModel } from \"~/shared/abstractions.js\";\nimport {\n NotAuthorizedError,\n ScheduledActionNotFoundError,\n ScheduledActionPersistenceError\n} from \"~/domain/errors.js\";\nimport { GetEntryByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetEntryById/index.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { SchedulerPermissions } from \"~/domain/permissions.js\";\nimport { IdentityContext } from \"@webiny/api-core/exports/api/security.js\";\nimport { ScheduledActionMapper } from \"~/domain/ScheduledActionMapper.js\";\nimport { ScheduledActionId } from \"~/domain/ScheduledActionId.js\";\nimport { ScheduledActionIdWithVersion } from \"~/domain/ScheduledActionIdWithVersion.js\";\nimport { SCHEDULED_ACTION_PUBLISH, SCHEDULED_ACTION_UNPUBLISH } from \"~/constants.js\";\n\n/**\n * Retrieves a scheduled action by its ID\n *\n * Flow:\n * 1. Fetch schedule entry from CMS storage by ID\n * 2. Return null if not found\n * 3. Transform CMS entry to IScheduledAction format\n */\nclass GetTargetScheduledActionUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private getEntryByIdUseCase: GetEntryByIdUseCase.Interface,\n private model: ScheduledActionModel.Interface,\n private permissions: SchedulerPermissions.Interface,\n private identityContext: IdentityContext.Interface\n ) {}\n\n async execute<T extends GenericRecord>(\n params: UseCaseAbstraction.Params\n ): Promise<Result<IScheduledAction<T>, UseCaseAbstraction.Error>> {\n const hasPermission = await this.permissions.canRead(\"action\");\n if (!hasPermission) {\n return Result.fail(new NotAuthorizedError());\n }\n const { id, namespace } = params;\n\n const entryResult = await this.getRecord<T>(params);\n\n if (entryResult.isFail()) {\n if (entryResult.error.code === \"Cms/Entry/NotFound\") {\n return Result.fail(new ScheduledActionNotFoundError(id));\n }\n\n return Result.fail(new ScheduledActionPersistenceError(entryResult.error));\n }\n\n const ownRecordsOnly = await this.permissions.onlyOwnRecords(\"action\");\n if (ownRecordsOnly) {\n if (entryResult.value.createdBy.id !== this.identityContext.getIdentity().id) {\n return Result.fail(new NotAuthorizedError());\n }\n }\n\n const entry = entryResult.value;\n /**\n * Always check if the namespace is correct because entry is loaded directly, not via filtering.\n */\n if (entry.values.namespace !== namespace) {\n return Result.fail(new ScheduledActionNotFoundError(id));\n }\n const action = ScheduledActionMapper.toAction<T>(entry);\n return Result.ok(action);\n }\n /**\n * We always need to fetch both publish and unpublish actions because we don't know the type of the action that is being searched for.\n */\n private async getRecord<T extends GenericRecord>(params: UseCaseAbstraction.Params) {\n const schedulePublishId = ScheduledActionId.from({\n namespace: params.namespace,\n targetId: params.id,\n actionType: SCHEDULED_ACTION_PUBLISH\n });\n const publishResult = await this.getEntryByIdUseCase.execute<\n IScheduledActionEntryValues<T>\n >(this.model, ScheduledActionIdWithVersion.from(schedulePublishId));\n if (publishResult.isOk()) {\n return publishResult;\n }\n const scheduleUnpublishId = ScheduledActionId.from({\n namespace: params.namespace,\n targetId: params.id,\n actionType: SCHEDULED_ACTION_UNPUBLISH\n });\n return this.getEntryByIdUseCase.execute<IScheduledActionEntryValues<T>>(\n this.model,\n ScheduledActionIdWithVersion.from(scheduleUnpublishId)\n );\n }\n}\n\nexport const GetTargetScheduledActionUseCase = UseCaseAbstraction.createImplementation({\n implementation: GetTargetScheduledActionUseCaseImpl,\n dependencies: [\n GetEntryByIdUseCase,\n ScheduledActionModel,\n SchedulerPermissions.Abstraction,\n IdentityContext\n ]\n});\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;AAC5C,SAASC,+BAA+B,IAAIC,kBAAkB;AAE9D,SAASC,oBAAoB;AAC7B,SACIC,kBAAkB,EAClBC,4BAA4B,EAC5BC,+BAA+B;AAEnC,SAASC,mBAAmB,QAAQ,sEAAsE;AAE1G,SAASC,oBAAoB;AAC7B,SAASC,eAAe,QAAQ,0CAA0C;AAC1E,SAASC,qBAAqB;AAC9B,SAASC,iBAAiB;AAC1B,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MAAMhD,+BAA+B,GAAGC,kBAAkB,CAACgD,oBAAoB,CAAC;EACnFC,cAAc,EAAEpC,mCAAmC;EACnDqC,YAAY,EAAE,CACV7C,mBAAmB,EACnBJ,oBAAoB,EACpBK,oBAAoB,CAAC6C,WAAW,EAChC5C,eAAe;AAEvB,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,24 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import type { IScheduledAction } from "../../shared/abstractions.js";
3
+ import { ScheduledActionNotFoundError, ScheduledActionPersistenceError, NotAuthorizedError } from "../../domain/errors.js";
4
+ import type { GenericRecord } from "@webiny/api/types.js";
5
+ export interface IGetTargetScheduledActionErrors {
6
+ persistence: ScheduledActionPersistenceError;
7
+ notFound: ScheduledActionNotFoundError;
8
+ unauthorized: NotAuthorizedError;
9
+ }
10
+ type GetTargetScheduledActionError = IGetTargetScheduledActionErrors[keyof IGetTargetScheduledActionErrors];
11
+ export interface IGetTargetScheduledActionUseCaseParams {
12
+ namespace: string;
13
+ id: string;
14
+ }
15
+ export interface IGetTargetScheduledActionUseCase {
16
+ execute<T extends GenericRecord>(params: IGetTargetScheduledActionUseCaseParams): Promise<Result<IScheduledAction<T>, GetTargetScheduledActionError>>;
17
+ }
18
+ export declare const GetTargetScheduledActionUseCase: import("@webiny/di").Abstraction<IGetTargetScheduledActionUseCase>;
19
+ export declare namespace GetTargetScheduledActionUseCase {
20
+ type Interface = IGetTargetScheduledActionUseCase;
21
+ type Error = GetTargetScheduledActionError;
22
+ type Params = IGetTargetScheduledActionUseCaseParams;
23
+ }
24
+ export {};
@@ -0,0 +1,4 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ export const GetTargetScheduledActionUseCase = createAbstraction("Scheduler/GetTargetScheduledActionUseCase");
3
+
4
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createAbstraction","GetTargetScheduledActionUseCase"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type { IScheduledAction } from \"~/shared/abstractions.js\";\nimport {\n ScheduledActionNotFoundError,\n ScheduledActionPersistenceError,\n NotAuthorizedError\n} from \"~/domain/errors.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport interface IGetTargetScheduledActionErrors {\n persistence: ScheduledActionPersistenceError;\n notFound: ScheduledActionNotFoundError;\n unauthorized: NotAuthorizedError;\n}\n\ntype GetTargetScheduledActionError =\n IGetTargetScheduledActionErrors[keyof IGetTargetScheduledActionErrors];\n\nexport interface IGetTargetScheduledActionUseCaseParams {\n namespace: string;\n id: string;\n}\n\nexport interface IGetTargetScheduledActionUseCase {\n execute<T extends GenericRecord>(\n params: IGetTargetScheduledActionUseCaseParams\n ): Promise<Result<IScheduledAction<T>, GetTargetScheduledActionError>>;\n}\n\nexport const GetTargetScheduledActionUseCase = createAbstraction<IGetTargetScheduledActionUseCase>(\n \"Scheduler/GetTargetScheduledActionUseCase\"\n);\n\nexport namespace GetTargetScheduledActionUseCase {\n export type Interface = IGetTargetScheduledActionUseCase;\n export type Error = GetTargetScheduledActionError;\n export type Params = IGetTargetScheduledActionUseCaseParams;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAgB,qBAAqB;AA6B/D,OAAO,MAAMC,+BAA+B,GAAGD,iBAAiB,CAC5D,2CACJ,CAAC","ignoreList":[]}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * GetTargetScheduledAction Feature
3
+ *
4
+ * Provides the ability to retrieve a target scheduled action by ID.
5
+ * Used for checking if schedules exist and displaying schedule details.
6
+ */
7
+ export declare const GetTargetScheduledActionFeature: import("@webiny/feature/api/createFeature.js").FeatureDefinition<unknown>;
@@ -0,0 +1,17 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { GetTargetScheduledActionUseCase } from "./GetTargetScheduledActionUseCase.js";
3
+
4
+ /**
5
+ * GetTargetScheduledAction Feature
6
+ *
7
+ * Provides the ability to retrieve a target scheduled action by ID.
8
+ * Used for checking if schedules exist and displaying schedule details.
9
+ */
10
+ export const GetTargetScheduledActionFeature = createFeature({
11
+ name: "GetTargetScheduledAction",
12
+ register(container) {
13
+ container.register(GetTargetScheduledActionUseCase);
14
+ }
15
+ });
16
+
17
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createFeature","GetTargetScheduledActionUseCase","GetTargetScheduledActionFeature","name","register","container"],"sources":["feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { GetTargetScheduledActionUseCase } from \"./GetTargetScheduledActionUseCase.js\";\n\n/**\n * GetTargetScheduledAction Feature\n *\n * Provides the ability to retrieve a target scheduled action by ID.\n * Used for checking if schedules exist and displaying schedule details.\n */\nexport const GetTargetScheduledActionFeature = createFeature({\n name: \"GetTargetScheduledAction\",\n register(container) {\n container.register(GetTargetScheduledActionUseCase);\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,+BAA+B;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,+BAA+B,GAAGF,aAAa,CAAC;EACzDG,IAAI,EAAE,0BAA0B;EAChCC,QAAQA,CAACC,SAAS,EAAE;IAChBA,SAAS,CAACD,QAAQ,CAACH,+BAA+B,CAAC;EACvD;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -4,6 +4,8 @@ import { IListScheduledActionsParams, IListScheduledActionsResponse, ListSchedul
4
4
  import { ScheduledActionModel } from "../../shared/abstractions.js";
5
5
  import { CmsSortMapper, CmsWhereMapper } from "@webiny/api-headless-cms";
6
6
  import type { GenericRecord } from "@webiny/api/types.js";
7
+ import { SchedulerPermissions } from "../../domain/permissions.js";
8
+ import { IdentityContext } from "@webiny/api-core/exports/api/security.js";
7
9
  /**
8
10
  * Lists scheduled actions with optional filtering
9
11
  *
@@ -18,7 +20,9 @@ declare class ListScheduledActionsUseCaseImpl implements UseCaseAbstraction.Inte
18
20
  private model;
19
21
  private cmsWhereMapper;
20
22
  private cmsSortMapper;
21
- constructor(listEntriesUseCase: ListLatestEntriesUseCase.Interface, model: ScheduledActionModel.Interface, cmsWhereMapper: CmsWhereMapper.Interface, cmsSortMapper: CmsSortMapper.Interface);
23
+ private permissions;
24
+ private identityContext;
25
+ constructor(listEntriesUseCase: ListLatestEntriesUseCase.Interface, model: ScheduledActionModel.Interface, cmsWhereMapper: CmsWhereMapper.Interface, cmsSortMapper: CmsSortMapper.Interface, permissions: SchedulerPermissions.Interface, identityContext: IdentityContext.Interface);
22
26
  execute<T extends GenericRecord>(params: IListScheduledActionsParams): Promise<Result<IListScheduledActionsResponse<T>, UseCaseAbstraction.Error>>;
23
27
  }
24
28
  export declare const ListScheduledActionsUseCase: typeof ListScheduledActionsUseCaseImpl & {