@webiny/api-headless-cms-bulk-actions 0.0.0-unstable.5387e5f7c8 → 0.0.0-unstable.676006d08e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/features/DeleteEntriesBulkAction/DeleteEntriesBulkAction.js +1 -0
- package/features/DeleteEntriesBulkAction/DeleteEntriesBulkAction.js.map +1 -1
- package/features/EntriesBulkAction/createBulkActionTasks.js +1 -1
- package/features/EntriesBulkAction/createBulkActionTasks.js.map +1 -1
- package/features/EntriesBulkAction/internals/CreateTasksByModel.js +1 -1
- package/features/EntriesBulkAction/internals/CreateTasksByModel.js.map +1 -1
- package/features/EntriesBulkAction/internals/ProcessTask.js +1 -1
- package/features/EntriesBulkAction/internals/ProcessTask.js.map +1 -1
- package/features/EntriesBulkAction/internals/ProcessTasksByModel.js +1 -1
- package/features/EntriesBulkAction/internals/ProcessTasksByModel.js.map +1 -1
- package/features/MoveToFolderBulkAction/MoveToFolderBulkAction.js +1 -0
- package/features/MoveToFolderBulkAction/MoveToFolderBulkAction.js.map +1 -1
- package/features/MoveToTrashBulkAction/MoveToTrashBulkAction.js +1 -0
- package/features/MoveToTrashBulkAction/MoveToTrashBulkAction.js.map +1 -1
- package/features/PublishEntriesBulkAction/PublishEntriesBulkAction.js +1 -0
- package/features/PublishEntriesBulkAction/PublishEntriesBulkAction.js.map +1 -1
- package/features/RestoreEntriesBulkAction/RestoreEntriesBulkAction.js +1 -0
- package/features/RestoreEntriesBulkAction/RestoreEntriesBulkAction.js.map +1 -1
- package/features/UnpublishEntriesBulkAction/UnpublishEntriesBulkAction.js +1 -0
- package/features/UnpublishEntriesBulkAction/UnpublishEntriesBulkAction.js.map +1 -1
- package/graphql/BulkActionsGraphQLSchema.js +22 -4
- package/graphql/BulkActionsGraphQLSchema.js.map +1 -1
- package/graphql/bulkActionAccess.d.ts +22 -0
- package/graphql/bulkActionAccess.js +94 -0
- package/graphql/bulkActionAccess.js.map +1 -0
- package/graphql/createBulkActionGraphQL.js +2 -1
- package/graphql/createBulkActionGraphQL.js.map +1 -1
- package/graphql/createDefaultGraphQL.js +2 -1
- package/graphql/createDefaultGraphQL.js.map +1 -1
- package/package.json +18 -17
- package/tasks/EmptyTrashBinTask.d.ts +3 -9
- package/tasks/EmptyTrashBinTask.js +51 -43
- package/tasks/EmptyTrashBinTask.js.map +1 -1
- package/types.js.map +1 -1
|
@@ -10,6 +10,7 @@ class DeleteEntriesBulkActionImpl {
|
|
|
10
10
|
}
|
|
11
11
|
async loadData(model, params) {
|
|
12
12
|
const entriesResult = await this.listDeletedEntries.execute(model, params);
|
|
13
|
+
if (entriesResult.isFail()) throw entriesResult.error;
|
|
13
14
|
return entriesResult.value;
|
|
14
15
|
}
|
|
15
16
|
async processData(model, params) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/DeleteEntriesBulkAction/DeleteEntriesBulkAction.js","sources":["../../../src/features/DeleteEntriesBulkAction/DeleteEntriesBulkAction.ts"],"sourcesContent":["import { ListDeletedEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js\";\nimport { DeleteEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\n\nclass DeleteEntriesBulkActionImpl implements EntriesBulkAction.Interface {\n readonly name = \"delete\";\n\n constructor(\n private listDeletedEntries: ListDeletedEntriesUseCase.Interface,\n private deleteEntry: DeleteEntryUseCase.Interface\n ) {}\n\n async loadData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.LoadDataParams\n ): Promise<EntriesBulkAction.LoadDataResult> {\n const entriesResult = await this.listDeletedEntries.execute(model, params);\n\n return entriesResult.value;\n }\n\n async processData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.ProcessParams\n ): Promise<void> {\n const { id: entryId } = parseIdentifier(params.id);\n\n await this.deleteEntry.execute(model, entryId, {\n permanently: true\n });\n }\n}\n\nexport const DeleteEntriesBulkAction = EntriesBulkAction.createImplementation({\n implementation: DeleteEntriesBulkActionImpl,\n dependencies: [ListDeletedEntriesUseCase, DeleteEntryUseCase]\n});\n"],"names":["DeleteEntriesBulkActionImpl","listDeletedEntries","deleteEntry","model","params","entriesResult","entryId","parseIdentifier","DeleteEntriesBulkAction","EntriesBulkAction","ListDeletedEntriesUseCase","DeleteEntryUseCase"],"mappings":";;;;AAKA,MAAMA;IAGF,YACYC,kBAAuD,EACvDC,WAAyC,CACnD;aAFUD,kBAAkB,GAAlBA;aACAC,WAAW,GAAXA;aAJH,IAAI,GAAG;IAKb;IAEH,MAAM,SACFC,KAA8B,EAC9BC,MAAwC,EACC;QACzC,MAAMC,gBAAgB,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAACF,OAAOC;
|
|
1
|
+
{"version":3,"file":"features/DeleteEntriesBulkAction/DeleteEntriesBulkAction.js","sources":["../../../src/features/DeleteEntriesBulkAction/DeleteEntriesBulkAction.ts"],"sourcesContent":["import { ListDeletedEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js\";\nimport { DeleteEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\n\nclass DeleteEntriesBulkActionImpl implements EntriesBulkAction.Interface {\n readonly name = \"delete\";\n\n constructor(\n private listDeletedEntries: ListDeletedEntriesUseCase.Interface,\n private deleteEntry: DeleteEntryUseCase.Interface\n ) {}\n\n async loadData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.LoadDataParams\n ): Promise<EntriesBulkAction.LoadDataResult> {\n const entriesResult = await this.listDeletedEntries.execute(model, params);\n if (entriesResult.isFail()) {\n throw entriesResult.error;\n }\n\n return entriesResult.value;\n }\n\n async processData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.ProcessParams\n ): Promise<void> {\n const { id: entryId } = parseIdentifier(params.id);\n\n await this.deleteEntry.execute(model, entryId, {\n permanently: true\n });\n }\n}\n\nexport const DeleteEntriesBulkAction = EntriesBulkAction.createImplementation({\n implementation: DeleteEntriesBulkActionImpl,\n dependencies: [ListDeletedEntriesUseCase, DeleteEntryUseCase]\n});\n"],"names":["DeleteEntriesBulkActionImpl","listDeletedEntries","deleteEntry","model","params","entriesResult","entryId","parseIdentifier","DeleteEntriesBulkAction","EntriesBulkAction","ListDeletedEntriesUseCase","DeleteEntryUseCase"],"mappings":";;;;AAKA,MAAMA;IAGF,YACYC,kBAAuD,EACvDC,WAAyC,CACnD;aAFUD,kBAAkB,GAAlBA;aACAC,WAAW,GAAXA;aAJH,IAAI,GAAG;IAKb;IAEH,MAAM,SACFC,KAA8B,EAC9BC,MAAwC,EACC;QACzC,MAAMC,gBAAgB,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAACF,OAAOC;QACnE,IAAIC,cAAc,MAAM,IACpB,MAAMA,cAAc,KAAK;QAG7B,OAAOA,cAAc,KAAK;IAC9B;IAEA,MAAM,YACFF,KAA8B,EAC9BC,MAAuC,EAC1B;QACb,MAAM,EAAE,IAAIE,OAAO,EAAE,GAAGC,gBAAgBH,OAAO,EAAE;QAEjD,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAACD,OAAOG,SAAS;YAC3C,aAAa;QACjB;IACJ;AACJ;AAEO,MAAME,0BAA0BC,kBAAkB,oBAAoB,CAAC;IAC1E,gBAAgBT;IAChB,cAAc;QAACU;QAA2BC;KAAmB;AACjE"}
|
|
@@ -8,7 +8,7 @@ import { ChildTasksCleanup } from "./internals/ChildTasksCleanup.js";
|
|
|
8
8
|
import { ProcessTask } from "./internals/ProcessTask.js";
|
|
9
9
|
import { CreateTasksByModel } from "./internals/CreateTasksByModel.js";
|
|
10
10
|
import { ProcessTasksByModel } from "./internals/ProcessTasksByModel.js";
|
|
11
|
-
import { RequestContainer } from "@webiny/
|
|
11
|
+
import { RequestContainer } from "@webiny/api-kernel-core";
|
|
12
12
|
import { Logger } from "@webiny/api-core/features/logger/index.js";
|
|
13
13
|
const BULK_ACTION_LIST_TASK_ID = "hcmsBulkListEntries";
|
|
14
14
|
const BULK_ACTION_PROCESS_TASK_ID = "hcmsBulkProcessEntries";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/EntriesBulkAction/createBulkActionTasks.js","sources":["../../../src/features/EntriesBulkAction/createBulkActionTasks.ts"],"sourcesContent":["import {\n TaskDefinition,\n TaskHandler\n} from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { DeleteTaskLogUseCase } from \"@webiny/background-tasks/api\";\nimport { DeleteTaskUseCase } from \"@webiny/background-tasks/api\";\nimport { ListTaskLogsUseCase } from \"@webiny/background-tasks/api\";\nimport { ListTasksUseCase } from \"@webiny/background-tasks/api\";\nimport { TriggerTaskUseCase } from \"@webiny/background-tasks/api\";\nimport type {\n IBulkActionOperationByModelInput,\n IBulkActionOperationByModelOutput,\n IBulkActionOperationInput,\n IBulkActionOperationOutput\n} from \"~/types.js\";\nimport { BulkActionOperationByModelAction } from \"~/types.js\";\nimport { EntriesBulkAction, EntriesBulkActionConfig } from \"./abstractions.js\";\nimport { BulkActionName } from \"~/domain/BulkActionName.js\";\nimport { ChildTasksCleanup } from \"./internals/ChildTasksCleanup.js\";\nimport { ProcessTask } from \"./internals/ProcessTask.js\";\nimport { CreateTasksByModel } from \"./internals/CreateTasksByModel.js\";\nimport { ProcessTasksByModel } from \"./internals/ProcessTasksByModel.js\";\nimport type { Container } from \"@webiny/di\";\nimport { RequestContainer } from \"@webiny/event-handler-core\";\nimport { Logger } from \"@webiny/api-core/features/logger/index.js\";\n\nexport const BULK_ACTION_LIST_TASK_ID = \"hcmsBulkListEntries\";\nexport const BULK_ACTION_PROCESS_TASK_ID = \"hcmsBulkProcessEntries\";\n\nconst resolveBulkAction = (container: Container, actionName: string) => {\n const bulkActions = container.resolveAll(EntriesBulkAction);\n const action = bulkActions.find(a => BulkActionName.from(a.name) === actionName);\n if (!action) {\n throw new Error(`Unknown bulk action: \"${actionName}\"`);\n }\n return action;\n};\n\nclass BulkActionListTaskHandlerImpl implements TaskHandler.Interface<\n IBulkActionOperationByModelInput,\n IBulkActionOperationByModelOutput\n> {\n constructor(\n private readonly container: Container,\n private readonly getModel: GetModelUseCase.Interface,\n private readonly listTasks: ListTasksUseCase.Interface,\n private readonly triggerTask: TriggerTaskUseCase.Interface,\n private readonly listTaskLogs: ListTaskLogsUseCase.Interface,\n private readonly deleteTaskLog: DeleteTaskLogUseCase.Interface,\n private readonly deleteTask: DeleteTaskUseCase.Interface,\n private readonly bulkActionsConfig: EntriesBulkActionConfig.Interface,\n private readonly logger: Logger.Interface\n ) {}\n\n async run({\n input,\n controller,\n definition\n }: TaskHandler.RunParams<IBulkActionOperationByModelInput, IBulkActionOperationByModelOutput>) {\n try {\n if (!input.modelId) {\n return controller.response.error(`Missing \"modelId\" in the input.`);\n }\n if (!input.actionName) {\n return controller.response.error(`Missing \"actionName\" in the input.`);\n }\n\n const bulkAction = resolveBulkAction(this.container, input.actionName);\n const batchSize = bulkAction.batchSize ?? this.bulkActionsConfig.batchSize ?? 100;\n const action = input.action ?? BulkActionOperationByModelAction.CREATE_SUBTASKS;\n\n switch (action) {\n case BulkActionOperationByModelAction.PROCESS_SUBTASKS: {\n const processTasks = new ProcessTasksByModel(\n this.listTasks,\n BULK_ACTION_PROCESS_TASK_ID\n );\n return await processTasks.execute({ input, controller, definition });\n }\n case BulkActionOperationByModelAction.CREATE_SUBTASKS:\n case BulkActionOperationByModelAction.CHECK_MORE_SUBTASKS: {\n const createTasks = new CreateTasksByModel(\n this.getModel,\n this.triggerTask,\n bulkAction,\n BULK_ACTION_PROCESS_TASK_ID,\n batchSize,\n this.logger\n );\n return await createTasks.execute({ input, controller, definition });\n }\n case BulkActionOperationByModelAction.END_TASK: {\n return controller.response.done(\n `Task done: bulk action \"${input.actionName}\" has been successfully processed for entries from \"${input.modelId}\" model.`\n );\n }\n default:\n return controller.response.error(`Unknown action: ${action}`);\n }\n } catch (ex) {\n return controller.response.error(\n ex.message ?? \"Error while executing bulk action list task\"\n );\n }\n }\n\n async onDone({ task }: TaskHandler.LifecycleHookParams): Promise<void> {\n await this.cleanup(task);\n }\n\n async onError({ task }: TaskHandler.LifecycleHookParams) {\n await this.cleanup(task);\n }\n\n async onAbort({ task }: TaskHandler.LifecycleHookParams) {\n await this.cleanup(task);\n }\n\n async onMaxIterations({ task }: TaskHandler.LifecycleHookParams) {\n await this.cleanup(task);\n }\n\n async cleanup(task: TaskDefinition.Task) {\n const childTasksCleanup = new ChildTasksCleanup();\n try {\n await childTasksCleanup.execute({\n listTasks: this.listTasks,\n listTaskLogs: this.listTaskLogs,\n deleteTaskLog: this.deleteTaskLog,\n deleteTask: this.deleteTask,\n task\n });\n } catch (ex) {\n this.logger.error({ error: ex }, \"Error while cleaning bulk action list child tasks.\");\n }\n }\n}\n\nconst BulkActionListTaskHandler = TaskHandler.createImplementation({\n implementation: BulkActionListTaskHandlerImpl,\n dependencies: [\n RequestContainer,\n GetModelUseCase,\n ListTasksUseCase,\n TriggerTaskUseCase,\n ListTaskLogsUseCase,\n DeleteTaskLogUseCase,\n DeleteTaskUseCase,\n EntriesBulkActionConfig,\n Logger\n ]\n});\n\nclass BulkActionListTask implements TaskDefinition.Interface {\n public readonly id = BULK_ACTION_LIST_TASK_ID;\n public readonly title = \"Headless CMS: list entries for bulk action\";\n public readonly maxIterations = 500;\n public readonly databaseLogs = false;\n public readonly isPrivate = true;\n public readonly selfCleanup = [\"onSuccess\" as const, \"onAbort\" as const];\n\n handler = BulkActionListTaskHandler;\n}\n\nclass BulkActionProcessTaskHandlerImpl implements TaskHandler.Interface<\n IBulkActionOperationInput,\n IBulkActionOperationOutput\n> {\n constructor(\n private readonly container: Container,\n private readonly getModel: GetModelUseCase.Interface,\n private readonly logger: Logger.Interface\n ) {}\n\n async run({\n input,\n controller,\n definition\n }: TaskHandler.RunParams<IBulkActionOperationInput, IBulkActionOperationOutput>) {\n try {\n if (!input.actionName) {\n return controller.response.error(`Missing \"actionName\" in the input.`);\n }\n\n const bulkAction = resolveBulkAction(this.container, input.actionName);\n const processTask = new ProcessTask(bulkAction, this.getModel, this.logger);\n return await processTask.execute({ input, controller, definition });\n } catch (ex) {\n return controller.response.error(\n ex.message ?? \"Error while executing bulk action process task\"\n );\n }\n }\n}\n\nconst BulkActionProcessTaskHandler = TaskHandler.createImplementation({\n implementation: BulkActionProcessTaskHandlerImpl,\n dependencies: [RequestContainer, GetModelUseCase, Logger]\n});\n\nclass BulkActionProcessTask implements TaskDefinition.Interface {\n public readonly id = BULK_ACTION_PROCESS_TASK_ID;\n public readonly title = \"Headless CMS: process entries for bulk action\";\n public readonly maxIterations = 2;\n public readonly databaseLogs = false;\n public readonly isPrivate = true;\n public readonly selfCleanup = [\"onSuccess\" as const, \"onAbort\" as const];\n\n handler = BulkActionProcessTaskHandler;\n}\n\nexport const BulkActionListTaskDefinition = TaskDefinition.createImplementation({\n implementation: BulkActionListTask,\n dependencies: []\n});\n\nexport const BulkActionProcessTaskDefinition = TaskDefinition.createImplementation({\n implementation: BulkActionProcessTask,\n dependencies: []\n});\n"],"names":["BULK_ACTION_LIST_TASK_ID","BULK_ACTION_PROCESS_TASK_ID","resolveBulkAction","container","actionName","bulkActions","EntriesBulkAction","action","a","BulkActionName","Error","BulkActionListTaskHandlerImpl","getModel","listTasks","triggerTask","listTaskLogs","deleteTaskLog","deleteTask","bulkActionsConfig","logger","input","controller","definition","bulkAction","batchSize","BulkActionOperationByModelAction","processTasks","ProcessTasksByModel","createTasks","CreateTasksByModel","ex","task","childTasksCleanup","ChildTasksCleanup","BulkActionListTaskHandler","TaskHandler","RequestContainer","GetModelUseCase","ListTasksUseCase","TriggerTaskUseCase","ListTaskLogsUseCase","DeleteTaskLogUseCase","DeleteTaskUseCase","EntriesBulkActionConfig","Logger","BulkActionListTask","BulkActionProcessTaskHandlerImpl","processTask","ProcessTask","BulkActionProcessTaskHandler","BulkActionProcessTask","BulkActionListTaskDefinition","TaskDefinition","BulkActionProcessTaskDefinition"],"mappings":";;;;;;;;;;;;AA2BO,MAAMA,2BAA2B;AACjC,MAAMC,8BAA8B;AAE3C,MAAMC,oBAAoB,CAACC,WAAsBC;IAC7C,MAAMC,cAAcF,UAAU,UAAU,CAACG;IACzC,MAAMC,SAASF,YAAY,IAAI,CAACG,CAAAA,IAAKC,eAAe,IAAI,CAACD,EAAE,IAAI,MAAMJ;IACrE,IAAI,CAACG,QACD,MAAM,IAAIG,MAAM,CAAC,sBAAsB,EAAEN,WAAW,CAAC,CAAC;IAE1D,OAAOG;AACX;AAEA,MAAMI;IAIF,YACqBR,SAAoB,EACpBS,QAAmC,EACnCC,SAAqC,EACrCC,WAAyC,EACzCC,YAA2C,EAC3CC,aAA6C,EAC7CC,UAAuC,EACvCC,iBAAoD,EACpDC,MAAwB,CAC3C;aATmBhB,SAAS,GAATA;aACAS,QAAQ,GAARA;aACAC,SAAS,GAATA;aACAC,WAAW,GAAXA;aACAC,YAAY,GAAZA;aACAC,aAAa,GAAbA;aACAC,UAAU,GAAVA;aACAC,iBAAiB,GAAjBA;aACAC,MAAM,GAANA;IAClB;IAEH,MAAM,IAAI,EACNC,KAAK,EACLC,UAAU,EACVC,UAAU,EAC+E,EAAE;QAC3F,IAAI;YACA,IAAI,CAACF,MAAM,OAAO,EACd,OAAOC,WAAW,QAAQ,CAAC,KAAK,CAAC;YAErC,IAAI,CAACD,MAAM,UAAU,EACjB,OAAOC,WAAW,QAAQ,CAAC,KAAK,CAAC;YAGrC,MAAME,aAAarB,kBAAkB,IAAI,CAAC,SAAS,EAAEkB,MAAM,UAAU;YACrE,MAAMI,YAAYD,WAAW,SAAS,IAAI,IAAI,CAAC,iBAAiB,CAAC,SAAS,I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AAC,KAAK,CAC5BS,GAAG,OAAO,IAAI;QAEtB;IACJ;AACJ;AAEA,MAAMmB,+BAA+Bd,YAAY,oBAAoB,CAAC;IAClE,gBAAgBW;IAChB,cAAc;QAACV;QAAkBC;QAAiBO;KAAO;AAC7D;AAEA,MAAMM;;aACc,EAAE,GAAGjD;aACL,KAAK,GAAG;aACR,aAAa,GAAG;aAChB,YAAY,GAAG;aACf,SAAS,GAAG;aACZ,WAAW,GAAG;YAAC;YAAsB;SAAmB;aAExE,OAAO,GAAGgD;;AACd;AAEO,MAAME,+BAA+BC,eAAe,oBAAoB,CAAC;IAC5E,gBAAgBP;IAChB,cAAc,EAAE;AACpB;AAEO,MAAMQ,kCAAkCD,eAAe,oBAAoB,CAAC;IAC/E,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
|
|
1
|
+
{"version":3,"file":"features/EntriesBulkAction/createBulkActionTasks.js","sources":["../../../src/features/EntriesBulkAction/createBulkActionTasks.ts"],"sourcesContent":["import {\n TaskDefinition,\n TaskHandler\n} from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { DeleteTaskLogUseCase } from \"@webiny/background-tasks/api\";\nimport { DeleteTaskUseCase } from \"@webiny/background-tasks/api\";\nimport { ListTaskLogsUseCase } from \"@webiny/background-tasks/api\";\nimport { ListTasksUseCase } from \"@webiny/background-tasks/api\";\nimport { TriggerTaskUseCase } from \"@webiny/background-tasks/api\";\nimport type {\n IBulkActionOperationByModelInput,\n IBulkActionOperationByModelOutput,\n IBulkActionOperationInput,\n IBulkActionOperationOutput\n} from \"~/types.js\";\nimport { BulkActionOperationByModelAction } from \"~/types.js\";\nimport { EntriesBulkAction, EntriesBulkActionConfig } from \"./abstractions.js\";\nimport { BulkActionName } from \"~/domain/BulkActionName.js\";\nimport { ChildTasksCleanup } from \"./internals/ChildTasksCleanup.js\";\nimport { ProcessTask } from \"./internals/ProcessTask.js\";\nimport { CreateTasksByModel } from \"./internals/CreateTasksByModel.js\";\nimport { ProcessTasksByModel } from \"./internals/ProcessTasksByModel.js\";\nimport type { Container } from \"@webiny/di\";\nimport { RequestContainer } from \"@webiny/api-kernel-core\";\nimport { Logger } from \"@webiny/api-core/features/logger/index.js\";\n\nexport const BULK_ACTION_LIST_TASK_ID = \"hcmsBulkListEntries\";\nexport const BULK_ACTION_PROCESS_TASK_ID = \"hcmsBulkProcessEntries\";\n\nconst resolveBulkAction = (container: Container, actionName: string) => {\n const bulkActions = container.resolveAll(EntriesBulkAction);\n const action = bulkActions.find(a => BulkActionName.from(a.name) === actionName);\n if (!action) {\n throw new Error(`Unknown bulk action: \"${actionName}\"`);\n }\n return action;\n};\n\nclass BulkActionListTaskHandlerImpl implements TaskHandler.Interface<\n IBulkActionOperationByModelInput,\n IBulkActionOperationByModelOutput\n> {\n constructor(\n private readonly container: Container,\n private readonly getModel: GetModelUseCase.Interface,\n private readonly listTasks: ListTasksUseCase.Interface,\n private readonly triggerTask: TriggerTaskUseCase.Interface,\n private readonly listTaskLogs: ListTaskLogsUseCase.Interface,\n private readonly deleteTaskLog: DeleteTaskLogUseCase.Interface,\n private readonly deleteTask: DeleteTaskUseCase.Interface,\n private readonly bulkActionsConfig: EntriesBulkActionConfig.Interface,\n private readonly logger: Logger.Interface\n ) {}\n\n async run({\n input,\n controller,\n definition\n }: TaskHandler.RunParams<IBulkActionOperationByModelInput, IBulkActionOperationByModelOutput>) {\n try {\n if (!input.modelId) {\n return controller.response.error(`Missing \"modelId\" in the input.`);\n }\n if (!input.actionName) {\n return controller.response.error(`Missing \"actionName\" in the input.`);\n }\n\n const bulkAction = resolveBulkAction(this.container, input.actionName);\n const batchSize = bulkAction.batchSize ?? this.bulkActionsConfig.batchSize ?? 100;\n const action = input.action ?? BulkActionOperationByModelAction.CREATE_SUBTASKS;\n\n switch (action) {\n case BulkActionOperationByModelAction.PROCESS_SUBTASKS: {\n const processTasks = new ProcessTasksByModel(\n this.listTasks,\n BULK_ACTION_PROCESS_TASK_ID\n );\n return await processTasks.execute({ input, controller, definition });\n }\n case BulkActionOperationByModelAction.CREATE_SUBTASKS:\n case BulkActionOperationByModelAction.CHECK_MORE_SUBTASKS: {\n const createTasks = new CreateTasksByModel(\n this.getModel,\n this.triggerTask,\n bulkAction,\n BULK_ACTION_PROCESS_TASK_ID,\n batchSize,\n this.logger\n );\n return await createTasks.execute({ input, controller, definition });\n }\n case BulkActionOperationByModelAction.END_TASK: {\n return controller.response.done(\n `Task done: bulk action \"${input.actionName}\" has been successfully processed for entries from \"${input.modelId}\" model.`\n );\n }\n default:\n return controller.response.error(`Unknown action: ${action}`);\n }\n } catch (ex) {\n return controller.response.error(\n ex.message ?? \"Error while executing bulk action list task\"\n );\n }\n }\n\n async onDone({ task }: TaskHandler.LifecycleHookParams): Promise<void> {\n await this.cleanup(task);\n }\n\n async onError({ task }: TaskHandler.LifecycleHookParams) {\n await this.cleanup(task);\n }\n\n async onAbort({ task }: TaskHandler.LifecycleHookParams) {\n await this.cleanup(task);\n }\n\n async onMaxIterations({ task }: TaskHandler.LifecycleHookParams) {\n await this.cleanup(task);\n }\n\n async cleanup(task: TaskDefinition.Task) {\n const childTasksCleanup = new ChildTasksCleanup();\n try {\n await childTasksCleanup.execute({\n listTasks: this.listTasks,\n listTaskLogs: this.listTaskLogs,\n deleteTaskLog: this.deleteTaskLog,\n deleteTask: this.deleteTask,\n task\n });\n } catch (ex) {\n this.logger.error({ error: ex }, \"Error while cleaning bulk action list child tasks.\");\n }\n }\n}\n\nconst BulkActionListTaskHandler = TaskHandler.createImplementation({\n implementation: BulkActionListTaskHandlerImpl,\n dependencies: [\n RequestContainer,\n GetModelUseCase,\n ListTasksUseCase,\n TriggerTaskUseCase,\n ListTaskLogsUseCase,\n DeleteTaskLogUseCase,\n DeleteTaskUseCase,\n EntriesBulkActionConfig,\n Logger\n ]\n});\n\nclass BulkActionListTask implements TaskDefinition.Interface {\n public readonly id = BULK_ACTION_LIST_TASK_ID;\n public readonly title = \"Headless CMS: list entries for bulk action\";\n public readonly maxIterations = 500;\n public readonly databaseLogs = false;\n public readonly isPrivate = true;\n public readonly selfCleanup = [\"onSuccess\" as const, \"onAbort\" as const];\n\n handler = BulkActionListTaskHandler;\n}\n\nclass BulkActionProcessTaskHandlerImpl implements TaskHandler.Interface<\n IBulkActionOperationInput,\n IBulkActionOperationOutput\n> {\n constructor(\n private readonly container: Container,\n private readonly getModel: GetModelUseCase.Interface,\n private readonly logger: Logger.Interface\n ) {}\n\n async run({\n input,\n controller,\n definition\n }: TaskHandler.RunParams<IBulkActionOperationInput, IBulkActionOperationOutput>) {\n try {\n if (!input.actionName) {\n return controller.response.error(`Missing \"actionName\" in the input.`);\n }\n\n const bulkAction = resolveBulkAction(this.container, input.actionName);\n const processTask = new ProcessTask(bulkAction, this.getModel, this.logger);\n return await processTask.execute({ input, controller, definition });\n } catch (ex) {\n return controller.response.error(\n ex.message ?? \"Error while executing bulk action process task\"\n );\n }\n }\n}\n\nconst BulkActionProcessTaskHandler = TaskHandler.createImplementation({\n implementation: BulkActionProcessTaskHandlerImpl,\n dependencies: [RequestContainer, GetModelUseCase, Logger]\n});\n\nclass BulkActionProcessTask implements TaskDefinition.Interface {\n public readonly id = BULK_ACTION_PROCESS_TASK_ID;\n public readonly title = \"Headless CMS: process entries for bulk action\";\n public readonly maxIterations = 2;\n public readonly databaseLogs = false;\n public readonly isPrivate = true;\n public readonly selfCleanup = [\"onSuccess\" as const, \"onAbort\" as const];\n\n handler = BulkActionProcessTaskHandler;\n}\n\nexport const BulkActionListTaskDefinition = TaskDefinition.createImplementation({\n implementation: BulkActionListTask,\n dependencies: []\n});\n\nexport const BulkActionProcessTaskDefinition = TaskDefinition.createImplementation({\n implementation: BulkActionProcessTask,\n dependencies: []\n});\n"],"names":["BULK_ACTION_LIST_TASK_ID","BULK_ACTION_PROCESS_TASK_ID","resolveBulkAction","container","actionName","bulkActions","EntriesBulkAction","action","a","BulkActionName","Error","BulkActionListTaskHandlerImpl","getModel","listTasks","triggerTask","listTaskLogs","deleteTaskLog","deleteTask","bulkActionsConfig","logger","input","controller","definition","bulkAction","batchSize","BulkActionOperationByModelAction","processTasks","ProcessTasksByModel","createTasks","CreateTasksByModel","ex","task","childTasksCleanup","ChildTasksCleanup","BulkActionListTaskHandler","TaskHandler","RequestContainer","GetModelUseCase","ListTasksUseCase","TriggerTaskUseCase","ListTaskLogsUseCase","DeleteTaskLogUseCase","DeleteTaskUseCase","EntriesBulkActionConfig","Logger","BulkActionListTask","BulkActionProcessTaskHandlerImpl","processTask","ProcessTask","BulkActionProcessTaskHandler","BulkActionProcessTask","BulkActionListTaskDefinition","TaskDefinition","BulkActionProcessTaskDefinition"],"mappings":";;;;;;;;;;;;AA2BO,MAAMA,2BAA2B;AACjC,MAAMC,8BAA8B;AAE3C,MAAMC,oBAAoB,CAACC,WAAsBC;IAC7C,MAAMC,cAAcF,UAAU,UAAU,CAACG;IACzC,MAAMC,SAASF,YAAY,IAAI,CAACG,CAAAA,IAAKC,eAAe,IAAI,CAACD,EAAE,IAAI,MAAMJ;IACrE,IAAI,CAACG,QACD,MAAM,IAAIG,MAAM,CAAC,sBAAsB,EAAEN,WAAW,CAAC,CAAC;IAE1D,OAAOG;AACX;AAEA,MAAMI;IAIF,YACqBR,SAAoB,EACpBS,QAAmC,EACnCC,SAAqC,EACrCC,WAAyC,EACzCC,YAA2C,EAC3CC,aAA6C,EAC7CC,UAAuC,EACvCC,iBAAoD,EACpDC,MAAwB,CAC3C;aATmBhB,SAAS,GAATA;aACAS,QAAQ,GAARA;aACAC,SAAS,GAATA;aACAC,WAAW,GAAXA;aACAC,YAAY,GAAZA;aACAC,aAAa,GAAbA;aACAC,UAAU,GAAVA;aACAC,iBAAiB,GAAjBA;aACAC,MAAM,GAANA;IAClB;IAEH,MAAM,IAAI,EACNC,KAAK,EACLC,UAAU,EACVC,UAAU,EAC+E,EAAE;QAC3F,IAAI;YACA,IAAI,CAACF,MAAM,OAAO,EACd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AkB,IAAI,CAAC,SAAS,EAAEkB,MAAM,UAAU;YACrE,MAAM2B,cAAc,IAAIC,YAAYzB,YAAY,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM;YAC1E,OAAO,MAAMwB,YAAY,OAAO,CAAC;gBAAE3B;gBAAOC;gBAAYC;YAAW;QACrE,EAAE,OAAOQ,IAAI;YACT,OAAOT,WAAW,QAAQ,CAAC,KAAK,CAC5BS,GAAG,OAAO,IAAI;QAEtB;IACJ;AACJ;AAEA,MAAMmB,+BAA+Bd,YAAY,oBAAoB,CAAC;IAClE,gBAAgBW;IAChB,cAAc;QAACV;QAAkBC;QAAiBO;KAAO;AAC7D;AAEA,MAAMM;;aACc,EAAE,GAAGjD;aACL,KAAK,GAAG;aACR,aAAa,GAAG;aAChB,YAAY,GAAG;aACf,SAAS,GAAG;aACZ,WAAW,GAAG;YAAC;YAAsB;SAAmB;aAExE,OAAO,GAAGgD;;AACd;AAEO,MAAME,+BAA+BC,eAAe,oBAAoB,CAAC;IAC5E,gBAAgBP;IAChB,cAAc,EAAE;AACpB;AAEO,MAAMQ,kCAAkCD,eAAe,oBAAoB,CAAC;IAC/E,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -23,7 +23,7 @@ class CreateTasksByModel {
|
|
|
23
23
|
};
|
|
24
24
|
while(true){
|
|
25
25
|
if (controller.runtime.isAborted()) return controller.response.aborted();
|
|
26
|
-
if (controller.runtime.isCloseToTimeout()) {
|
|
26
|
+
else if (controller.runtime.isCloseToTimeout()) {
|
|
27
27
|
await this.taskCache.triggerTask(this.triggerTask, controller.state.getTask());
|
|
28
28
|
return controller.response.continue({
|
|
29
29
|
...input,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/EntriesBulkAction/internals/CreateTasksByModel.js","sources":["../../../../src/features/EntriesBulkAction/internals/CreateTasksByModel.ts"],"sourcesContent":["import type { CmsEntryListParams } from \"@webiny/api-headless-cms/types/index.js\";\nimport { TaskCache } from \"./TaskCache.js\";\nimport type { IBulkActionOperationByModelTaskParams } from \"~/types.js\";\nimport { BulkActionOperationByModelAction } from \"~/types.js\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\nimport type { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport type { TriggerTaskUseCase } from \"@webiny/background-tasks/api\";\nimport type { Logger } from \"@webiny/api-core/features/logger/index.js\";\n\nconst MAX_TASK_LIST_LENGTH = 10;\n\n/**\n * The `CreateTasksByModel` class handles the execution of a task to process entries in batches.\n */\nexport class CreateTasksByModel {\n private readonly taskCache: TaskCache;\n private readonly batchSize: number;\n private readonly bulkAction: EntriesBulkAction.Interface;\n private readonly triggerTask: TriggerTaskUseCase.Interface;\n private readonly getModel: GetModelUseCase.Interface;\n\n constructor(\n getModel: GetModelUseCase.Interface,\n triggerTask: TriggerTaskUseCase.Interface,\n bulkAction: EntriesBulkAction.Interface,\n taskDefinition: string,\n batchSize: number,\n logger: Logger.Interface\n ) {\n this.getModel = getModel;\n this.taskCache = new TaskCache(taskDefinition, logger);\n this.batchSize = batchSize;\n this.bulkAction = bulkAction;\n this.triggerTask = triggerTask;\n }\n\n async execute(params: IBulkActionOperationByModelTaskParams) {\n const { input, controller } = params;\n\n try {\n const modelResult = await this.getModel.execute(input.modelId);\n\n if (modelResult.isFail()) {\n return controller.response.error(`Model with ${input.modelId} not found!`);\n }\n\n const model = modelResult.value;\n\n const listEntriesParams: CmsEntryListParams = {\n where: input.where,\n search: input.search,\n after: input.after,\n limit: this.batchSize\n };\n\n while (true) {\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n } else if (controller.runtime.isCloseToTimeout()) {\n await this.taskCache.triggerTask(this.triggerTask, controller.state.getTask());\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.PROCESS_SUBTASKS\n });\n }\n\n // List entries from the HCMS based on the provided query\n const { entries, meta } = await this.bulkAction.loadData(model, listEntriesParams);\n\n // End the task if no entries match the query\n if (meta.totalCount === 0) {\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.END_TASK\n });\n }\n\n // Continue processing if we are reached the task list length limit\n if (this.taskCache.getTasksLength() === MAX_TASK_LIST_LENGTH) {\n await this.taskCache.triggerTask(this.triggerTask, controller.state.getTask());\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.PROCESS_SUBTASKS\n });\n }\n\n // Continue processing if no entries are returned in the current batch\n if (entries.length === 0) {\n await this.taskCache.triggerTask(this.triggerTask, controller.state.getTask());\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.PROCESS_SUBTASKS\n });\n }\n\n // Extract entry IDs\n const ids: string[] = [];\n for (let i = 0; i < entries.length; i++) {\n ids.push(entries[i].id);\n }\n\n if (ids.length > 0) {\n this.taskCache.cacheTask({\n actionName: input.actionName,\n modelId: input.modelId,\n identity: input.identity,\n data: input.data,\n ids\n });\n }\n\n // Continue processing if there are no more entries or pagination is complete\n if (!meta.hasMoreItems || !meta.cursor) {\n await this.taskCache.triggerTask(this.triggerTask, controller.state.getTask());\n\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.PROCESS_SUBTASKS\n });\n }\n\n listEntriesParams.after = meta.cursor;\n }\n } catch (ex) {\n return controller.response.error(ex.message ?? `Error while creating task.`);\n }\n }\n}\n"],"names":["MAX_TASK_LIST_LENGTH","CreateTasksByModel","getModel","triggerTask","bulkAction","taskDefinition","batchSize","logger","TaskCache","params","input","controller","modelResult","model","listEntriesParams","BulkActionOperationByModelAction","entries","meta","ids","i","ex"],"mappings":";;AASA,MAAMA,uBAAuB;AAKtB,MAAMC;IAOT,YACIC,QAAmC,EACnCC,WAAyC,EACzCC,UAAuC,EACvCC,cAAsB,EACtBC,SAAiB,EACjBC,MAAwB,CAC1B;QACE,IAAI,CAAC,QAAQ,GAAGL;QAChB,IAAI,CAAC,SAAS,GAAG,IAAIM,UAAUH,gBAAgBE;QAC/C,IAAI,CAAC,SAAS,GAAGD;QACjB,IAAI,CAAC,UAAU,GAAGF;QAClB,IAAI,CAAC,WAAW,GAAGD;IACvB;IAEA,MAAM,QAAQM,MAA6C,EAAE;QACzD,MAAM,EAAEC,KAAK,EAAEC,UAAU,EAAE,GAAGF;QAE9B,IAAI;YACA,MAAMG,cAAc,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAACF,MAAM,OAAO;YAE7D,IAAIE,YAAY,MAAM,IAClB,OAAOD,WAAW,QAAQ,CAAC,KAAK,CAAC,CAAC,WAAW,EAAED,MAAM,OAAO,CAAC,WAAW,CAAC;YAG7E,MAAMG,QAAQD,YAAY,KAAK;YAE/B,MAAME,oBAAwC;gBAC1C,OAAOJ,MAAM,KAAK;gBAClB,QAAQA,MAAM,MAAM;gBACpB,OAAOA,MAAM,KAAK;gBAClB,OAAO,IAAI,CAAC,SAAS;YACzB;YAEA,MAAO,KAAM;gBACT,IAAIC,WAAW,OAAO,CAAC,SAAS,IAC5B,OAAOA,WAAW,QAAQ,CAAC,OAAO;
|
|
1
|
+
{"version":3,"file":"features/EntriesBulkAction/internals/CreateTasksByModel.js","sources":["../../../../src/features/EntriesBulkAction/internals/CreateTasksByModel.ts"],"sourcesContent":["import type { CmsEntryListParams } from \"@webiny/api-headless-cms/types/index.js\";\nimport { TaskCache } from \"./TaskCache.js\";\nimport type { IBulkActionOperationByModelTaskParams } from \"~/types.js\";\nimport { BulkActionOperationByModelAction } from \"~/types.js\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\nimport type { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport type { TriggerTaskUseCase } from \"@webiny/background-tasks/api\";\nimport type { Logger } from \"@webiny/api-core/features/logger/index.js\";\n\nconst MAX_TASK_LIST_LENGTH = 10;\n\n/**\n * The `CreateTasksByModel` class handles the execution of a task to process entries in batches.\n */\nexport class CreateTasksByModel {\n private readonly taskCache: TaskCache;\n private readonly batchSize: number;\n private readonly bulkAction: EntriesBulkAction.Interface;\n private readonly triggerTask: TriggerTaskUseCase.Interface;\n private readonly getModel: GetModelUseCase.Interface;\n\n constructor(\n getModel: GetModelUseCase.Interface,\n triggerTask: TriggerTaskUseCase.Interface,\n bulkAction: EntriesBulkAction.Interface,\n taskDefinition: string,\n batchSize: number,\n logger: Logger.Interface\n ) {\n this.getModel = getModel;\n this.taskCache = new TaskCache(taskDefinition, logger);\n this.batchSize = batchSize;\n this.bulkAction = bulkAction;\n this.triggerTask = triggerTask;\n }\n\n async execute(params: IBulkActionOperationByModelTaskParams) {\n const { input, controller } = params;\n\n try {\n const modelResult = await this.getModel.execute(input.modelId);\n\n if (modelResult.isFail()) {\n return controller.response.error(`Model with ${input.modelId} not found!`);\n }\n\n const model = modelResult.value;\n\n const listEntriesParams: CmsEntryListParams = {\n where: input.where,\n search: input.search,\n after: input.after,\n limit: this.batchSize\n };\n\n while (true) {\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n } else if (controller.runtime.isCloseToTimeout()) {\n await this.taskCache.triggerTask(this.triggerTask, controller.state.getTask());\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.PROCESS_SUBTASKS\n });\n }\n\n // List entries from the HCMS based on the provided query\n const { entries, meta } = await this.bulkAction.loadData(model, listEntriesParams);\n\n // End the task if no entries match the query\n if (meta.totalCount === 0) {\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.END_TASK\n });\n }\n\n // Continue processing if we are reached the task list length limit\n if (this.taskCache.getTasksLength() === MAX_TASK_LIST_LENGTH) {\n await this.taskCache.triggerTask(this.triggerTask, controller.state.getTask());\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.PROCESS_SUBTASKS\n });\n }\n\n // Continue processing if no entries are returned in the current batch\n if (entries.length === 0) {\n await this.taskCache.triggerTask(this.triggerTask, controller.state.getTask());\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.PROCESS_SUBTASKS\n });\n }\n\n // Extract entry IDs\n const ids: string[] = [];\n for (let i = 0; i < entries.length; i++) {\n ids.push(entries[i].id);\n }\n\n if (ids.length > 0) {\n this.taskCache.cacheTask({\n actionName: input.actionName,\n modelId: input.modelId,\n identity: input.identity,\n data: input.data,\n ids\n });\n }\n\n // Continue processing if there are no more entries or pagination is complete\n if (!meta.hasMoreItems || !meta.cursor) {\n await this.taskCache.triggerTask(this.triggerTask, controller.state.getTask());\n\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.PROCESS_SUBTASKS\n });\n }\n\n listEntriesParams.after = meta.cursor;\n }\n } catch (ex) {\n return controller.response.error(ex.message ?? `Error while creating task.`);\n }\n }\n}\n"],"names":["MAX_TASK_LIST_LENGTH","CreateTasksByModel","getModel","triggerTask","bulkAction","taskDefinition","batchSize","logger","TaskCache","params","input","controller","modelResult","model","listEntriesParams","BulkActionOperationByModelAction","entries","meta","ids","i","ex"],"mappings":";;AASA,MAAMA,uBAAuB;AAKtB,MAAMC;IAOT,YACIC,QAAmC,EACnCC,WAAyC,EACzCC,UAAuC,EACvCC,cAAsB,EACtBC,SAAiB,EACjBC,MAAwB,CAC1B;QACE,IAAI,CAAC,QAAQ,GAAGL;QAChB,IAAI,CAAC,SAAS,GAAG,IAAIM,UAAUH,gBAAgBE;QAC/C,IAAI,CAAC,SAAS,GAAGD;QACjB,IAAI,CAAC,UAAU,GAAGF;QAClB,IAAI,CAAC,WAAW,GAAGD;IACvB;IAEA,MAAM,QAAQM,MAA6C,EAAE;QACzD,MAAM,EAAEC,KAAK,EAAEC,UAAU,EAAE,GAAGF;QAE9B,IAAI;YACA,MAAMG,cAAc,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAACF,MAAM,OAAO;YAE7D,IAAIE,YAAY,MAAM,IAClB,OAAOD,WAAW,QAAQ,CAAC,KAAK,CAAC,CAAC,WAAW,EAAED,MAAM,OAAO,CAAC,WAAW,CAAC;YAG7E,MAAMG,QAAQD,YAAY,KAAK;YAE/B,MAAME,oBAA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CAAiC,gBAAgB;oBAC7D;gBACJ;gBAGA,MAAMG,MAAgB,EAAE;gBACxB,IAAK,IAAIC,IAAI,GAAGA,IAAIH,QAAQ,MAAM,EAAEG,IAChCD,IAAI,IAAI,CAACF,OAAO,CAACG,EAAE,CAAC,EAAE;gBAG1B,IAAID,IAAI,MAAM,GAAG,GACb,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC;oBACrB,YAAYR,MAAM,UAAU;oBAC5B,SAASA,MAAM,OAAO;oBACtB,UAAUA,MAAM,QAAQ;oBACxB,MAAMA,MAAM,IAAI;oBAChBQ;gBACJ;gBAIJ,IAAI,CAACD,KAAK,YAAY,IAAI,CAACA,KAAK,MAAM,EAAE;oBACpC,MAAM,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,EAAEN,WAAW,KAAK,CAAC,OAAO;oBAE3E,OAAOA,WAAW,QAAQ,CAAC,QAAQ,CAAC;wBAChC,GAAGD,KAAK;wBACR,QAAQK,iCAAiC,gBAAgB;oBAC7D;gBACJ;gBAEAD,kBAAkB,KAAK,GAAGG,KAAK,MAAM;YACzC;QACJ,EAAE,OAAOG,IAAI;YACT,OAAOT,WAAW,QAAQ,CAAC,KAAK,CAACS,GAAG,OAAO,IAAI;QACnD;IACJ;AACJ"}
|
|
@@ -9,7 +9,7 @@ class ProcessTask {
|
|
|
9
9
|
async execute({ input, controller }) {
|
|
10
10
|
try {
|
|
11
11
|
if (controller.runtime.isAborted()) return controller.response.aborted();
|
|
12
|
-
if (controller.runtime.isCloseToTimeout()) return controller.response.continue({
|
|
12
|
+
else if (controller.runtime.isCloseToTimeout()) return controller.response.continue({
|
|
13
13
|
...input
|
|
14
14
|
});
|
|
15
15
|
if (!input.modelId) return controller.response.error('Missing "modelId" in the input.');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/EntriesBulkAction/internals/ProcessTask.js","sources":["../../../../src/features/EntriesBulkAction/internals/ProcessTask.ts"],"sourcesContent":["import { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\nimport { ProcessTaskResult } from \"./ProcessTaskResult.js\";\nimport type { IBulkActionOperationTaskParams } from \"~/types.js\";\nimport type { Logger } from \"@webiny/api-core/features/logger/index.js\";\n\n/**\n * The `ProcessTask` class is responsible for processing a batch of entries\n * based on the provided parameters. It uses a gateway to perform the actual\n * processing and maintains the results of the operations, including successfully\n * processed and failed entries.\n */\nexport class ProcessTask {\n private readonly result: ProcessTaskResult;\n\n constructor(\n private bulkAction: EntriesBulkAction.Interface,\n private getModel: GetModelUseCase.Interface,\n private logger: Logger.Interface\n ) {\n this.result = new ProcessTaskResult();\n }\n\n async execute({ input, controller }: IBulkActionOperationTaskParams) {\n try {\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n } else if (controller.runtime.isCloseToTimeout()) {\n return controller.response.continue({\n ...input\n });\n }\n\n // Check if the input contains a model ID.\n if (!input.modelId) {\n return controller.response.error(`Missing \"modelId\" in the input.`);\n }\n\n // Check if the model exists.\n const modelResult = await this.getModel.execute(input.modelId);\n\n if (modelResult.isFail()) {\n return controller.response.error(`Model with ${input.modelId} not found!`);\n }\n\n const model = modelResult.value;\n\n // Check if there are any IDs to process.\n if (!input.ids || input.ids.length === 0) {\n return controller.response.done(\n `Task done: no entries to process for \"${input.modelId}\" model.`,\n {\n done: [],\n failed: []\n }\n );\n }\n\n // Process each ID in the input.\n for (const id of input.ids) {\n try {\n // Execute the gateway operation for the current ID.\n await this.bulkAction.processData(model, {\n id,\n data: input.data\n });\n\n // Add the ID to the list of successfully processed entries.\n this.result.addDone(id);\n } catch (ex) {\n this.logger.error(\n { error: ex, id },\n `Failed to process entry with id \"${id}\".`\n );\n // Add the ID to the list of failed entries.\n this.result.addFailed(id);\n }\n }\n\n // Return a done response with the results of the processing.\n return controller.response.done(\n `Task done: all entries processed for \"${model.name}\" model.`,\n {\n done: this.result.getDone(),\n failed: this.result.getFailed()\n }\n );\n } catch (ex) {\n return controller.response.error(ex.message ?? `Error while processing task.`);\n }\n }\n}\n"],"names":["ProcessTask","bulkAction","getModel","logger","ProcessTaskResult","input","controller","modelResult","model","id","ex"],"mappings":";AAYO,MAAMA;IAGT,YACYC,UAAuC,EACvCC,QAAmC,EACnCC,MAAwB,CAClC;aAHUF,UAAU,GAAVA;aACAC,QAAQ,GAARA;aACAC,MAAM,GAANA;QAER,IAAI,CAAC,MAAM,GAAG,IAAIC;IACtB;IAEA,MAAM,QAAQ,EAAEC,KAAK,EAAEC,UAAU,EAAkC,EAAE;QACjE,IAAI;YACA,IAAIA,WAAW,OAAO,CAAC,SAAS,IAC5B,OAAOA,WAAW,QAAQ,CAAC,OAAO;
|
|
1
|
+
{"version":3,"file":"features/EntriesBulkAction/internals/ProcessTask.js","sources":["../../../../src/features/EntriesBulkAction/internals/ProcessTask.ts"],"sourcesContent":["import { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\nimport { ProcessTaskResult } from \"./ProcessTaskResult.js\";\nimport type { IBulkActionOperationTaskParams } from \"~/types.js\";\nimport type { Logger } from \"@webiny/api-core/features/logger/index.js\";\n\n/**\n * The `ProcessTask` class is responsible for processing a batch of entries\n * based on the provided parameters. It uses a gateway to perform the actual\n * processing and maintains the results of the operations, including successfully\n * processed and failed entries.\n */\nexport class ProcessTask {\n private readonly result: ProcessTaskResult;\n\n constructor(\n private bulkAction: EntriesBulkAction.Interface,\n private getModel: GetModelUseCase.Interface,\n private logger: Logger.Interface\n ) {\n this.result = new ProcessTaskResult();\n }\n\n async execute({ input, controller }: IBulkActionOperationTaskParams) {\n try {\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n } else if (controller.runtime.isCloseToTimeout()) {\n return controller.response.continue({\n ...input\n });\n }\n\n // Check if the input contains a model ID.\n if (!input.modelId) {\n return controller.response.error(`Missing \"modelId\" in the input.`);\n }\n\n // Check if the model exists.\n const modelResult = await this.getModel.execute(input.modelId);\n\n if (modelResult.isFail()) {\n return controller.response.error(`Model with ${input.modelId} not found!`);\n }\n\n const model = modelResult.value;\n\n // Check if there are any IDs to process.\n if (!input.ids || input.ids.length === 0) {\n return controller.response.done(\n `Task done: no entries to process for \"${input.modelId}\" model.`,\n {\n done: [],\n failed: []\n }\n );\n }\n\n // Process each ID in the input.\n for (const id of input.ids) {\n try {\n // Execute the gateway operation for the current ID.\n await this.bulkAction.processData(model, {\n id,\n data: input.data\n });\n\n // Add the ID to the list of successfully processed entries.\n this.result.addDone(id);\n } catch (ex) {\n this.logger.error(\n { error: ex, id },\n `Failed to process entry with id \"${id}\".`\n );\n // Add the ID to the list of failed entries.\n this.result.addFailed(id);\n }\n }\n\n // Return a done response with the results of the processing.\n return controller.response.done(\n `Task done: all entries processed for \"${model.name}\" model.`,\n {\n done: this.result.getDone(),\n failed: this.result.getFailed()\n }\n );\n } catch (ex) {\n return controller.response.error(ex.message ?? `Error while processing task.`);\n }\n }\n}\n"],"names":["ProcessTask","bulkAction","getModel","logger","ProcessTaskResult","input","controller","modelResult","model","id","ex"],"mappings":";AAYO,MAAMA;IAGT,YACYC,UAAuC,EACvCC,QAAmC,EACnCC,MAAwB,CAClC;aAHUF,UAAU,GAAVA;aACAC,QAAQ,GAARA;aACAC,MAAM,GAANA;QAER,IAAI,CAAC,MAAM,GAAG,IAAIC;IACtB;IAEA,MAAM,QAAQ,EAAEC,KAAK,EAAEC,UAAU,EAAkC,EAAE;QACjE,IAAI;YACA,IAAIA,WAAW,OAAO,CAAC,SAAS,IAC5B,OAAOA,WAAW,QAAQ,CAAC,OAAO;iBAC/B,IAAIA,WAAW,OAAO,CAAC,gBAAgB,IAC1C,OAAOA,WAAW,QAAQ,CAAC,QAAQ,CAAC;gBAChC,GAAGD,KAAK;YACZ;YAIJ,IAAI,CAACA,MAAM,OAAO,EACd,OAAOC,WAAW,QAAQ,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|
|
9
9
|
try {
|
|
10
10
|
if (controller.runtime.isAborted()) return controller.response.aborted();
|
|
11
|
-
if (controller.runtime.isCloseToTimeout()) return controller.response.continue({
|
|
11
|
+
else if (controller.runtime.isCloseToTimeout()) return controller.response.continue({
|
|
12
12
|
...input,
|
|
13
13
|
action: BulkActionOperationByModelAction.PROCESS_SUBTASKS
|
|
14
14
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/EntriesBulkAction/internals/ProcessTasksByModel.js","sources":["../../../../src/features/EntriesBulkAction/internals/ProcessTasksByModel.ts"],"sourcesContent":["import { TaskDataStatus } from \"@webiny/background-tasks/api\";\nimport type { ListTasksUseCase } from \"@webiny/background-tasks/api\";\nimport type { IBulkActionOperationByModelTaskParams } from \"~/types.js\";\nimport { BulkActionOperationByModelAction } from \"~/types.js\";\n\n/**\n * The `ProcessTasksByModel` class is responsible for processing tasks for a specific model.\n * It checks for any running or pending tasks from the parent task and continues or completes\n * the task based on the status.\n */\nexport class ProcessTasksByModel {\n private readonly listTasks: ListTasksUseCase.Interface;\n private readonly taskDefinition: string;\n\n constructor(listTasks: ListTasksUseCase.Interface, taskDefinition: string) {\n this.listTasks = listTasks;\n this.taskDefinition = taskDefinition;\n }\n\n async execute({ input, controller }: IBulkActionOperationByModelTaskParams) {\n try {\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n } else if (controller.runtime.isCloseToTimeout()) {\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.PROCESS_SUBTASKS\n });\n }\n\n const result = await this.listTasks.execute({\n where: {\n parentId: controller.state.getTask().id,\n definitionId: this.taskDefinition,\n taskStatus_in: [TaskDataStatus.RUNNING, TaskDataStatus.PENDING]\n },\n limit: 1\n });\n if (result.isFail()) {\n throw result.error;\n }\n const { items } = result.value;\n\n // If there are running or pending tasks, continue with a wait.\n if (items.length > 0) {\n return controller.response.continue(\n {\n ...input,\n action: BulkActionOperationByModelAction.PROCESS_SUBTASKS\n },\n {\n seconds: 120\n }\n );\n }\n\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.CHECK_MORE_SUBTASKS\n });\n } catch (ex) {\n return controller.response.error(\n ex.message ?? `Error while processing task \"${this.taskDefinition}\"`\n );\n }\n }\n}\n"],"names":["ProcessTasksByModel","listTasks","taskDefinition","input","controller","BulkActionOperationByModelAction","result","TaskDataStatus","items","ex"],"mappings":";;AAUO,MAAMA;IAIT,YAAYC,SAAqC,EAAEC,cAAsB,CAAE;QACvE,IAAI,CAAC,SAAS,GAAGD;QACjB,IAAI,CAAC,cAAc,GAAGC;IAC1B;IAEA,MAAM,QAAQ,EAAEC,KAAK,EAAEC,UAAU,EAAyC,EAAE;QACxE,IAAI;YACA,IAAIA,WAAW,OAAO,CAAC,SAAS,IAC5B,OAAOA,WAAW,QAAQ,CAAC,OAAO;
|
|
1
|
+
{"version":3,"file":"features/EntriesBulkAction/internals/ProcessTasksByModel.js","sources":["../../../../src/features/EntriesBulkAction/internals/ProcessTasksByModel.ts"],"sourcesContent":["import { TaskDataStatus } from \"@webiny/background-tasks/api\";\nimport type { ListTasksUseCase } from \"@webiny/background-tasks/api\";\nimport type { IBulkActionOperationByModelTaskParams } from \"~/types.js\";\nimport { BulkActionOperationByModelAction } from \"~/types.js\";\n\n/**\n * The `ProcessTasksByModel` class is responsible for processing tasks for a specific model.\n * It checks for any running or pending tasks from the parent task and continues or completes\n * the task based on the status.\n */\nexport class ProcessTasksByModel {\n private readonly listTasks: ListTasksUseCase.Interface;\n private readonly taskDefinition: string;\n\n constructor(listTasks: ListTasksUseCase.Interface, taskDefinition: string) {\n this.listTasks = listTasks;\n this.taskDefinition = taskDefinition;\n }\n\n async execute({ input, controller }: IBulkActionOperationByModelTaskParams) {\n try {\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n } else if (controller.runtime.isCloseToTimeout()) {\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.PROCESS_SUBTASKS\n });\n }\n\n const result = await this.listTasks.execute({\n where: {\n parentId: controller.state.getTask().id,\n definitionId: this.taskDefinition,\n taskStatus_in: [TaskDataStatus.RUNNING, TaskDataStatus.PENDING]\n },\n limit: 1\n });\n if (result.isFail()) {\n throw result.error;\n }\n const { items } = result.value;\n\n // If there are running or pending tasks, continue with a wait.\n if (items.length > 0) {\n return controller.response.continue(\n {\n ...input,\n action: BulkActionOperationByModelAction.PROCESS_SUBTASKS\n },\n {\n seconds: 120\n }\n );\n }\n\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.CHECK_MORE_SUBTASKS\n });\n } catch (ex) {\n return controller.response.error(\n ex.message ?? `Error while processing task \"${this.taskDefinition}\"`\n );\n }\n }\n}\n"],"names":["ProcessTasksByModel","listTasks","taskDefinition","input","controller","BulkActionOperationByModelAction","result","TaskDataStatus","items","ex"],"mappings":";;AAUO,MAAMA;IAIT,YAAYC,SAAqC,EAAEC,cAAsB,CAAE;QACvE,IAAI,CAAC,SAAS,GAAGD;QACjB,IAAI,CAAC,cAAc,GAAGC;IAC1B;IAEA,MAAM,QAAQ,EAAEC,KAAK,EAAEC,UAAU,EAAyC,EAAE;QACxE,IAAI;YACA,IAAIA,WAAW,OAAO,CAAC,SAAS,IAC5B,OAAOA,WAAW,QAAQ,CAAC,OAAO;iBAC/B,IAAIA,WAAW,OAAO,CAAC,gBAAgB,IAC1C,OAAOA,WAAW,QAAQ,CAAC,QAAQ,CAAC;gBAChC,GAAGD,KAAK;gBACR,QAAQE,iCAAiC,gBAAgB;YAC7D;YAGJ,MAAMC,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;gBACxC,OAAO;oBACH,UAAUF,WAAW,KAAK,CAAC,OAAO,GAAG,EAAE;oBACvC,cAAc,IAAI,CAAC,cAAc;oBACjC,eAAe;wBAACG,eAAe,OAAO;wBAAEA,eAAe,OAAO;qBAAC;gBACnE;gBACA,OAAO;YACX;YACA,IAAID,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;YAEtB,MAAM,EAAEE,KAAK,EAAE,GAAGF,OAAO,KAAK;YAG9B,IAAIE,MAAM,MAAM,GAAG,GACf,OAAOJ,WAAW,QAAQ,CAAC,QAAQ,CAC/B;gBACI,GAAGD,KAAK;gBACR,QAAQE,iCAAiC,gBAAgB;YAC7D,GACA;gBACI,SAAS;YACb;YAIR,OAAOD,WAAW,QAAQ,CAAC,QAAQ,CAAC;gBAChC,GAAGD,KAAK;gBACR,QAAQE,iCAAiC,mBAAmB;YAChE;QACJ,EAAE,OAAOI,IAAI;YACT,OAAOL,WAAW,QAAQ,CAAC,KAAK,CAC5BK,GAAG,OAAO,IAAI,CAAC,6BAA6B,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC;QAE5E;IACJ;AACJ"}
|
|
@@ -9,6 +9,7 @@ class MoveToFolderBulkActionImpl {
|
|
|
9
9
|
}
|
|
10
10
|
async loadData(model, params) {
|
|
11
11
|
const entriesResult = await this.listLatestEntries.execute(model, params);
|
|
12
|
+
if (entriesResult.isFail()) throw entriesResult.error;
|
|
12
13
|
return entriesResult.value;
|
|
13
14
|
}
|
|
14
15
|
async processData(model, params) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/MoveToFolderBulkAction/MoveToFolderBulkAction.js","sources":["../../../src/features/MoveToFolderBulkAction/MoveToFolderBulkAction.ts"],"sourcesContent":["import { ListLatestEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js\";\nimport { MoveEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/MoveEntry/index.js\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\n\nclass MoveToFolderBulkActionImpl implements EntriesBulkAction.Interface {\n readonly name = \"moveToFolder\";\n\n constructor(\n private listLatestEntries: ListLatestEntriesUseCase.Interface,\n private moveEntry: MoveEntryUseCase.Interface\n ) {}\n\n async loadData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.LoadDataParams\n ): Promise<EntriesBulkAction.LoadDataResult> {\n const entriesResult = await this.listLatestEntries.execute(model, params);\n\n return entriesResult.value;\n }\n\n async processData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.ProcessParams\n ): Promise<void> {\n if (!params.data?.folderId) {\n throw new Error(`Missing \"data.folderId\" in the input.`);\n }\n\n await this.moveEntry.execute(model, params.id, params.data.folderId);\n }\n}\n\nexport const MoveToFolderBulkAction = EntriesBulkAction.createImplementation({\n implementation: MoveToFolderBulkActionImpl,\n dependencies: [ListLatestEntriesUseCase, MoveEntryUseCase]\n});\n"],"names":["MoveToFolderBulkActionImpl","listLatestEntries","moveEntry","model","params","entriesResult","Error","MoveToFolderBulkAction","EntriesBulkAction","ListLatestEntriesUseCase","MoveEntryUseCase"],"mappings":";;;AAIA,MAAMA;IAGF,YACYC,iBAAqD,EACrDC,SAAqC,CAC/C;aAFUD,iBAAiB,GAAjBA;aACAC,SAAS,GAATA;aAJH,IAAI,GAAG;IAKb;IAEH,MAAM,SACFC,KAA8B,EAC9BC,MAAwC,EACC;QACzC,MAAMC,gBAAgB,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAACF,OAAOC;
|
|
1
|
+
{"version":3,"file":"features/MoveToFolderBulkAction/MoveToFolderBulkAction.js","sources":["../../../src/features/MoveToFolderBulkAction/MoveToFolderBulkAction.ts"],"sourcesContent":["import { ListLatestEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js\";\nimport { MoveEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/MoveEntry/index.js\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\n\nclass MoveToFolderBulkActionImpl implements EntriesBulkAction.Interface {\n readonly name = \"moveToFolder\";\n\n constructor(\n private listLatestEntries: ListLatestEntriesUseCase.Interface,\n private moveEntry: MoveEntryUseCase.Interface\n ) {}\n\n async loadData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.LoadDataParams\n ): Promise<EntriesBulkAction.LoadDataResult> {\n const entriesResult = await this.listLatestEntries.execute(model, params);\n if (entriesResult.isFail()) {\n throw entriesResult.error;\n }\n\n return entriesResult.value;\n }\n\n async processData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.ProcessParams\n ): Promise<void> {\n if (!params.data?.folderId) {\n throw new Error(`Missing \"data.folderId\" in the input.`);\n }\n\n await this.moveEntry.execute(model, params.id, params.data.folderId);\n }\n}\n\nexport const MoveToFolderBulkAction = EntriesBulkAction.createImplementation({\n implementation: MoveToFolderBulkActionImpl,\n dependencies: [ListLatestEntriesUseCase, MoveEntryUseCase]\n});\n"],"names":["MoveToFolderBulkActionImpl","listLatestEntries","moveEntry","model","params","entriesResult","Error","MoveToFolderBulkAction","EntriesBulkAction","ListLatestEntriesUseCase","MoveEntryUseCase"],"mappings":";;;AAIA,MAAMA;IAGF,YACYC,iBAAqD,EACrDC,SAAqC,CAC/C;aAFUD,iBAAiB,GAAjBA;aACAC,SAAS,GAATA;aAJH,IAAI,GAAG;IAKb;IAEH,MAAM,SACFC,KAA8B,EAC9BC,MAAwC,EACC;QACzC,MAAMC,gBAAgB,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAACF,OAAOC;QAClE,IAAIC,cAAc,MAAM,IACpB,MAAMA,cAAc,KAAK;QAG7B,OAAOA,cAAc,KAAK;IAC9B;IAEA,MAAM,YACFF,KAA8B,EAC9BC,MAAuC,EAC1B;QACb,IAAI,CAACA,OAAO,IAAI,EAAE,UACd,MAAM,IAAIE,MAAM;QAGpB,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACH,OAAOC,OAAO,EAAE,EAAEA,OAAO,IAAI,CAAC,QAAQ;IACvE;AACJ;AAEO,MAAMG,yBAAyBC,kBAAkB,oBAAoB,CAAC;IACzE,gBAAgBR;IAChB,cAAc;QAACS;QAA0BC;KAAiB;AAC9D"}
|
|
@@ -10,6 +10,7 @@ class MoveToTrashBulkActionImpl {
|
|
|
10
10
|
}
|
|
11
11
|
async loadData(model, params) {
|
|
12
12
|
const entriesResult = await this.listLatestEntries.execute(model, params);
|
|
13
|
+
if (entriesResult.isFail()) throw entriesResult.error;
|
|
13
14
|
return entriesResult.value;
|
|
14
15
|
}
|
|
15
16
|
async processData(model, params) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/MoveToTrashBulkAction/MoveToTrashBulkAction.js","sources":["../../../src/features/MoveToTrashBulkAction/MoveToTrashBulkAction.ts"],"sourcesContent":["import { ListLatestEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js\";\nimport { DeleteEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\n\nclass MoveToTrashBulkActionImpl implements EntriesBulkAction.Interface {\n readonly name = \"moveToTrash\";\n\n constructor(\n private listLatestEntries: ListLatestEntriesUseCase.Interface,\n private deleteEntry: DeleteEntryUseCase.Interface\n ) {}\n\n async loadData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.LoadDataParams\n ): Promise<EntriesBulkAction.LoadDataResult> {\n const entriesResult = await this.listLatestEntries.execute(model, params);\n\n return entriesResult.value;\n }\n\n async processData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.ProcessParams\n ): Promise<void> {\n const { id: entryId } = parseIdentifier(params.id);\n\n await this.deleteEntry.execute(model, entryId, {\n permanently: false\n });\n }\n}\n\nexport const MoveToTrashBulkAction = EntriesBulkAction.createImplementation({\n implementation: MoveToTrashBulkActionImpl,\n dependencies: [ListLatestEntriesUseCase, DeleteEntryUseCase]\n});\n"],"names":["MoveToTrashBulkActionImpl","listLatestEntries","deleteEntry","model","params","entriesResult","entryId","parseIdentifier","MoveToTrashBulkAction","EntriesBulkAction","ListLatestEntriesUseCase","DeleteEntryUseCase"],"mappings":";;;;AAKA,MAAMA;IAGF,YACYC,iBAAqD,EACrDC,WAAyC,CACnD;aAFUD,iBAAiB,GAAjBA;aACAC,WAAW,GAAXA;aAJH,IAAI,GAAG;IAKb;IAEH,MAAM,SACFC,KAA8B,EAC9BC,MAAwC,EACC;QACzC,MAAMC,gBAAgB,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAACF,OAAOC;
|
|
1
|
+
{"version":3,"file":"features/MoveToTrashBulkAction/MoveToTrashBulkAction.js","sources":["../../../src/features/MoveToTrashBulkAction/MoveToTrashBulkAction.ts"],"sourcesContent":["import { ListLatestEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js\";\nimport { DeleteEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\n\nclass MoveToTrashBulkActionImpl implements EntriesBulkAction.Interface {\n readonly name = \"moveToTrash\";\n\n constructor(\n private listLatestEntries: ListLatestEntriesUseCase.Interface,\n private deleteEntry: DeleteEntryUseCase.Interface\n ) {}\n\n async loadData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.LoadDataParams\n ): Promise<EntriesBulkAction.LoadDataResult> {\n const entriesResult = await this.listLatestEntries.execute(model, params);\n if (entriesResult.isFail()) {\n throw entriesResult.error;\n }\n\n return entriesResult.value;\n }\n\n async processData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.ProcessParams\n ): Promise<void> {\n const { id: entryId } = parseIdentifier(params.id);\n\n await this.deleteEntry.execute(model, entryId, {\n permanently: false\n });\n }\n}\n\nexport const MoveToTrashBulkAction = EntriesBulkAction.createImplementation({\n implementation: MoveToTrashBulkActionImpl,\n dependencies: [ListLatestEntriesUseCase, DeleteEntryUseCase]\n});\n"],"names":["MoveToTrashBulkActionImpl","listLatestEntries","deleteEntry","model","params","entriesResult","entryId","parseIdentifier","MoveToTrashBulkAction","EntriesBulkAction","ListLatestEntriesUseCase","DeleteEntryUseCase"],"mappings":";;;;AAKA,MAAMA;IAGF,YACYC,iBAAqD,EACrDC,WAAyC,CACnD;aAFUD,iBAAiB,GAAjBA;aACAC,WAAW,GAAXA;aAJH,IAAI,GAAG;IAKb;IAEH,MAAM,SACFC,KAA8B,EAC9BC,MAAwC,EACC;QACzC,MAAMC,gBAAgB,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAACF,OAAOC;QAClE,IAAIC,cAAc,MAAM,IACpB,MAAMA,cAAc,KAAK;QAG7B,OAAOA,cAAc,KAAK;IAC9B;IAEA,MAAM,YACFF,KAA8B,EAC9BC,MAAuC,EAC1B;QACb,MAAM,EAAE,IAAIE,OAAO,EAAE,GAAGC,gBAAgBH,OAAO,EAAE;QAEjD,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAACD,OAAOG,SAAS;YAC3C,aAAa;QACjB;IACJ;AACJ;AAEO,MAAME,wBAAwBC,kBAAkB,oBAAoB,CAAC;IACxE,gBAAgBT;IAChB,cAAc;QAACU;QAA0BC;KAAmB;AAChE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/PublishEntriesBulkAction/PublishEntriesBulkAction.js","sources":["../../../src/features/PublishEntriesBulkAction/PublishEntriesBulkAction.ts"],"sourcesContent":["import { ListLatestEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js\";\nimport { PublishEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/PublishEntry/index.js\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\n\nclass PublishEntriesBulkActionImpl implements EntriesBulkAction.Interface {\n readonly name = \"publish\";\n\n constructor(\n private listLatestEntries: ListLatestEntriesUseCase.Interface,\n private publishEntry: PublishEntryUseCase.Interface\n ) {}\n\n async loadData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.LoadDataParams\n ): Promise<EntriesBulkAction.LoadDataResult> {\n const { where, ...rest } = params;\n\n const entriesResult = await this.listLatestEntries.execute(model, {\n ...rest,\n where: {\n ...where,\n status_not: \"published\"\n }\n });\n\n return entriesResult.value;\n }\n\n async processData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.ProcessParams\n ): Promise<void> {\n await this.publishEntry.execute(model, params.id);\n }\n}\n\nexport const PublishEntriesBulkAction = EntriesBulkAction.createImplementation({\n implementation: PublishEntriesBulkActionImpl,\n dependencies: [ListLatestEntriesUseCase, PublishEntryUseCase]\n});\n"],"names":["PublishEntriesBulkActionImpl","listLatestEntries","publishEntry","model","params","where","rest","entriesResult","PublishEntriesBulkAction","EntriesBulkAction","ListLatestEntriesUseCase","PublishEntryUseCase"],"mappings":";;;AAIA,MAAMA;IAGF,YACYC,iBAAqD,EACrDC,YAA2C,CACrD;aAFUD,iBAAiB,GAAjBA;aACAC,YAAY,GAAZA;aAJH,IAAI,GAAG;IAKb;IAEH,MAAM,SACFC,KAA8B,EAC9BC,MAAwC,EACC;QACzC,MAAM,EAAEC,KAAK,EAAE,GAAGC,MAAM,GAAGF;QAE3B,MAAMG,gBAAgB,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAACJ,OAAO;YAC9D,GAAGG,IAAI;YACP,OAAO;gBACH,GAAGD,KAAK;gBACR,YAAY;YAChB;QACJ;QAEA,
|
|
1
|
+
{"version":3,"file":"features/PublishEntriesBulkAction/PublishEntriesBulkAction.js","sources":["../../../src/features/PublishEntriesBulkAction/PublishEntriesBulkAction.ts"],"sourcesContent":["import { ListLatestEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js\";\nimport { PublishEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/PublishEntry/index.js\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\n\nclass PublishEntriesBulkActionImpl implements EntriesBulkAction.Interface {\n readonly name = \"publish\";\n\n constructor(\n private listLatestEntries: ListLatestEntriesUseCase.Interface,\n private publishEntry: PublishEntryUseCase.Interface\n ) {}\n\n async loadData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.LoadDataParams\n ): Promise<EntriesBulkAction.LoadDataResult> {\n const { where, ...rest } = params;\n\n const entriesResult = await this.listLatestEntries.execute(model, {\n ...rest,\n where: {\n ...where,\n status_not: \"published\"\n }\n });\n\n if (entriesResult.isFail()) {\n throw entriesResult.error;\n }\n\n return entriesResult.value;\n }\n\n async processData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.ProcessParams\n ): Promise<void> {\n await this.publishEntry.execute(model, params.id);\n }\n}\n\nexport const PublishEntriesBulkAction = EntriesBulkAction.createImplementation({\n implementation: PublishEntriesBulkActionImpl,\n dependencies: [ListLatestEntriesUseCase, PublishEntryUseCase]\n});\n"],"names":["PublishEntriesBulkActionImpl","listLatestEntries","publishEntry","model","params","where","rest","entriesResult","PublishEntriesBulkAction","EntriesBulkAction","ListLatestEntriesUseCase","PublishEntryUseCase"],"mappings":";;;AAIA,MAAMA;IAGF,YACYC,iBAAqD,EACrDC,YAA2C,CACrD;aAFUD,iBAAiB,GAAjBA;aACAC,YAAY,GAAZA;aAJH,IAAI,GAAG;IAKb;IAEH,MAAM,SACFC,KAA8B,EAC9BC,MAAwC,EACC;QACzC,MAAM,EAAEC,KAAK,EAAE,GAAGC,MAAM,GAAGF;QAE3B,MAAMG,gBAAgB,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAACJ,OAAO;YAC9D,GAAGG,IAAI;YACP,OAAO;gBACH,GAAGD,KAAK;gBACR,YAAY;YAChB;QACJ;QAEA,IAAIE,cAAc,MAAM,IACpB,MAAMA,cAAc,KAAK;QAG7B,OAAOA,cAAc,KAAK;IAC9B;IAEA,MAAM,YACFJ,KAA8B,EAC9BC,MAAuC,EAC1B;QACb,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAACD,OAAOC,OAAO,EAAE;IACpD;AACJ;AAEO,MAAMI,2BAA2BC,kBAAkB,oBAAoB,CAAC;IAC3E,gBAAgBT;IAChB,cAAc;QAACU;QAA0BC;KAAoB;AACjE"}
|
|
@@ -10,6 +10,7 @@ class RestoreEntriesBulkActionImpl {
|
|
|
10
10
|
}
|
|
11
11
|
async loadData(model, params) {
|
|
12
12
|
const entriesResult = await this.listDeletedEntries.execute(model, params);
|
|
13
|
+
if (entriesResult.isFail()) throw entriesResult.error;
|
|
13
14
|
return entriesResult.value;
|
|
14
15
|
}
|
|
15
16
|
async processData(model, params) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/RestoreEntriesBulkAction/RestoreEntriesBulkAction.js","sources":["../../../src/features/RestoreEntriesBulkAction/RestoreEntriesBulkAction.ts"],"sourcesContent":["import { ListDeletedEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js\";\nimport { RestoreEntryFromBinUseCase } from \"@webiny/api-headless-cms/features/contentEntry/RestoreEntryFromBin/index.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\n\nclass RestoreEntriesBulkActionImpl implements EntriesBulkAction.Interface {\n readonly name = \"restore\";\n\n constructor(\n private listDeletedEntries: ListDeletedEntriesUseCase.Interface,\n private restoreEntry: RestoreEntryFromBinUseCase.Interface\n ) {}\n\n async loadData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.LoadDataParams\n ): Promise<EntriesBulkAction.LoadDataResult> {\n const entriesResult = await this.listDeletedEntries.execute(model, params);\n\n return entriesResult.value;\n }\n\n async processData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.ProcessParams\n ): Promise<void> {\n const { id: entryId } = parseIdentifier(params.id);\n\n await this.restoreEntry.execute(model, entryId);\n }\n}\n\nexport const RestoreEntriesBulkAction = EntriesBulkAction.createImplementation({\n implementation: RestoreEntriesBulkActionImpl,\n dependencies: [ListDeletedEntriesUseCase, RestoreEntryFromBinUseCase]\n});\n"],"names":["RestoreEntriesBulkActionImpl","listDeletedEntries","restoreEntry","model","params","entriesResult","entryId","parseIdentifier","RestoreEntriesBulkAction","EntriesBulkAction","ListDeletedEntriesUseCase","RestoreEntryFromBinUseCase"],"mappings":";;;;AAKA,MAAMA;IAGF,YACYC,kBAAuD,EACvDC,YAAkD,CAC5D;aAFUD,kBAAkB,GAAlBA;aACAC,YAAY,GAAZA;aAJH,IAAI,GAAG;IAKb;IAEH,MAAM,SACFC,KAA8B,EAC9BC,MAAwC,EACC;QACzC,MAAMC,gBAAgB,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAACF,OAAOC;
|
|
1
|
+
{"version":3,"file":"features/RestoreEntriesBulkAction/RestoreEntriesBulkAction.js","sources":["../../../src/features/RestoreEntriesBulkAction/RestoreEntriesBulkAction.ts"],"sourcesContent":["import { ListDeletedEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js\";\nimport { RestoreEntryFromBinUseCase } from \"@webiny/api-headless-cms/features/contentEntry/RestoreEntryFromBin/index.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\n\nclass RestoreEntriesBulkActionImpl implements EntriesBulkAction.Interface {\n readonly name = \"restore\";\n\n constructor(\n private listDeletedEntries: ListDeletedEntriesUseCase.Interface,\n private restoreEntry: RestoreEntryFromBinUseCase.Interface\n ) {}\n\n async loadData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.LoadDataParams\n ): Promise<EntriesBulkAction.LoadDataResult> {\n const entriesResult = await this.listDeletedEntries.execute(model, params);\n if (entriesResult.isFail()) {\n throw entriesResult.error;\n }\n\n return entriesResult.value;\n }\n\n async processData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.ProcessParams\n ): Promise<void> {\n const { id: entryId } = parseIdentifier(params.id);\n\n await this.restoreEntry.execute(model, entryId);\n }\n}\n\nexport const RestoreEntriesBulkAction = EntriesBulkAction.createImplementation({\n implementation: RestoreEntriesBulkActionImpl,\n dependencies: [ListDeletedEntriesUseCase, RestoreEntryFromBinUseCase]\n});\n"],"names":["RestoreEntriesBulkActionImpl","listDeletedEntries","restoreEntry","model","params","entriesResult","entryId","parseIdentifier","RestoreEntriesBulkAction","EntriesBulkAction","ListDeletedEntriesUseCase","RestoreEntryFromBinUseCase"],"mappings":";;;;AAKA,MAAMA;IAGF,YACYC,kBAAuD,EACvDC,YAAkD,CAC5D;aAFUD,kBAAkB,GAAlBA;aACAC,YAAY,GAAZA;aAJH,IAAI,GAAG;IAKb;IAEH,MAAM,SACFC,KAA8B,EAC9BC,MAAwC,EACC;QACzC,MAAMC,gBAAgB,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAACF,OAAOC;QACnE,IAAIC,cAAc,MAAM,IACpB,MAAMA,cAAc,KAAK;QAG7B,OAAOA,cAAc,KAAK;IAC9B;IAEA,MAAM,YACFF,KAA8B,EAC9BC,MAAuC,EAC1B;QACb,MAAM,EAAE,IAAIE,OAAO,EAAE,GAAGC,gBAAgBH,OAAO,EAAE;QAEjD,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAACD,OAAOG;IAC3C;AACJ;AAEO,MAAME,2BAA2BC,kBAAkB,oBAAoB,CAAC;IAC3E,gBAAgBT;IAChB,cAAc;QAACU;QAA2BC;KAA2B;AACzE"}
|
|
@@ -9,6 +9,7 @@ class UnpublishEntriesBulkActionImpl {
|
|
|
9
9
|
}
|
|
10
10
|
async loadData(model, params) {
|
|
11
11
|
const entriesResult = await this.listPublishedEntries.execute(model, params);
|
|
12
|
+
if (entriesResult.isFail()) throw entriesResult.error;
|
|
12
13
|
return entriesResult.value;
|
|
13
14
|
}
|
|
14
15
|
async processData(model, params) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/UnpublishEntriesBulkAction/UnpublishEntriesBulkAction.js","sources":["../../../src/features/UnpublishEntriesBulkAction/UnpublishEntriesBulkAction.ts"],"sourcesContent":["import { ListPublishedEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js\";\nimport { UnpublishEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/UnpublishEntry/index.js\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\n\nclass UnpublishEntriesBulkActionImpl implements EntriesBulkAction.Interface {\n readonly name = \"unpublish\";\n\n constructor(\n private listPublishedEntries: ListPublishedEntriesUseCase.Interface,\n private unpublishEntry: UnpublishEntryUseCase.Interface\n ) {}\n\n async loadData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.LoadDataParams\n ): Promise<EntriesBulkAction.LoadDataResult> {\n const entriesResult = await this.listPublishedEntries.execute(model, params);\n\n return entriesResult.value;\n }\n\n async processData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.ProcessParams\n ): Promise<void> {\n await this.unpublishEntry.execute(model, params.id);\n }\n}\n\nexport const UnpublishEntriesBulkAction = EntriesBulkAction.createImplementation({\n implementation: UnpublishEntriesBulkActionImpl,\n dependencies: [ListPublishedEntriesUseCase, UnpublishEntryUseCase]\n});\n"],"names":["UnpublishEntriesBulkActionImpl","listPublishedEntries","unpublishEntry","model","params","entriesResult","UnpublishEntriesBulkAction","EntriesBulkAction","ListPublishedEntriesUseCase","UnpublishEntryUseCase"],"mappings":";;;AAIA,MAAMA;IAGF,YACYC,oBAA2D,EAC3DC,cAA+C,CACzD;aAFUD,oBAAoB,GAApBA;aACAC,cAAc,GAAdA;aAJH,IAAI,GAAG;IAKb;IAEH,MAAM,SACFC,KAA8B,EAC9BC,MAAwC,EACC;QACzC,MAAMC,gBAAgB,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAACF,OAAOC;
|
|
1
|
+
{"version":3,"file":"features/UnpublishEntriesBulkAction/UnpublishEntriesBulkAction.js","sources":["../../../src/features/UnpublishEntriesBulkAction/UnpublishEntriesBulkAction.ts"],"sourcesContent":["import { ListPublishedEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js\";\nimport { UnpublishEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/UnpublishEntry/index.js\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\n\nclass UnpublishEntriesBulkActionImpl implements EntriesBulkAction.Interface {\n readonly name = \"unpublish\";\n\n constructor(\n private listPublishedEntries: ListPublishedEntriesUseCase.Interface,\n private unpublishEntry: UnpublishEntryUseCase.Interface\n ) {}\n\n async loadData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.LoadDataParams\n ): Promise<EntriesBulkAction.LoadDataResult> {\n const entriesResult = await this.listPublishedEntries.execute(model, params);\n if (entriesResult.isFail()) {\n throw entriesResult.error;\n }\n\n return entriesResult.value;\n }\n\n async processData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.ProcessParams\n ): Promise<void> {\n await this.unpublishEntry.execute(model, params.id);\n }\n}\n\nexport const UnpublishEntriesBulkAction = EntriesBulkAction.createImplementation({\n implementation: UnpublishEntriesBulkActionImpl,\n dependencies: [ListPublishedEntriesUseCase, UnpublishEntryUseCase]\n});\n"],"names":["UnpublishEntriesBulkActionImpl","listPublishedEntries","unpublishEntry","model","params","entriesResult","UnpublishEntriesBulkAction","EntriesBulkAction","ListPublishedEntriesUseCase","UnpublishEntryUseCase"],"mappings":";;;AAIA,MAAMA;IAGF,YACYC,oBAA2D,EAC3DC,cAA+C,CACzD;aAFUD,oBAAoB,GAApBA;aACAC,cAAc,GAAdA;aAJH,IAAI,GAAG;IAKb;IAEH,MAAM,SACFC,KAA8B,EAC9BC,MAAwC,EACC;QACzC,MAAMC,gBAAgB,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAACF,OAAOC;QACrE,IAAIC,cAAc,MAAM,IACpB,MAAMA,cAAc,KAAK;QAG7B,OAAOA,cAAc,KAAK;IAC9B;IAEA,MAAM,YACFF,KAA8B,EAC9BC,MAAuC,EAC1B;QACb,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAACD,OAAOC,OAAO,EAAE;IACtD;AACJ;AAEO,MAAME,6BAA6BC,kBAAkB,oBAAoB,CAAC;IAC7E,gBAAgBP;IAChB,cAAc;QAACQ;QAA6BC;KAAsB;AACtE"}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { CmsGraphQLSchemaFactory, CmsGraphQLSchemaPlugin, isHeadlessCmsReady } from "@webiny/api-headless-cms";
|
|
2
2
|
import { ListModelsUseCase } from "@webiny/api-headless-cms/features/contentModel/ListModels/index.js";
|
|
3
3
|
import { CMS_MODEL_SINGLETON_TAG } from "@webiny/api-headless-cms/constants.js";
|
|
4
|
-
import { Response } from "@webiny/api-graphql";
|
|
4
|
+
import { ErrorResponse, Response } from "@webiny/api-graphql";
|
|
5
|
+
import { EntryNotAuthorizedError } from "@webiny/api-headless-cms/domain/contentEntry/errors.js";
|
|
6
|
+
import { AccessControl } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
5
7
|
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
8
|
+
import { HeadlessCmsEndpointConfig } from "@webiny/api-headless-cms/HeadlessCmsEndpointConfig.js";
|
|
6
9
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/abstractions.js";
|
|
7
10
|
import { TriggerTaskUseCase } from "@webiny/background-tasks/api";
|
|
8
11
|
import { EntriesBulkAction } from "../features/EntriesBulkAction/abstractions.js";
|
|
9
12
|
import { BulkActionName } from "../domain/BulkActionName.js";
|
|
10
13
|
import { BULK_ACTION_LIST_TASK_ID } from "../features/EntriesBulkAction/createBulkActionTasks.js";
|
|
11
|
-
import { RequestContainer } from "@webiny/
|
|
14
|
+
import { RequestContainer } from "@webiny/api-kernel-core";
|
|
15
|
+
import { canMoveToFolder, getRequiredAccess, restrictWhere } from "./bulkActionAccess.js";
|
|
12
16
|
class BulkActionsGraphQLSchemaImpl {
|
|
13
17
|
constructor(container){
|
|
14
18
|
this.container = container;
|
|
@@ -69,13 +73,27 @@ class BulkActionsGraphQLSchemaImpl {
|
|
|
69
73
|
resolvers: {
|
|
70
74
|
Mutation: {
|
|
71
75
|
[`bulkAction${model.singularApiName}`]: async (_, args, context)=>{
|
|
76
|
+
const canAccess = await context.container.resolve(AccessControl).canAccessEntry({
|
|
77
|
+
model,
|
|
78
|
+
...getRequiredAccess(args.action)
|
|
79
|
+
});
|
|
80
|
+
if (!canAccess) return new ErrorResponse(EntryNotAuthorizedError.fromModel(model));
|
|
81
|
+
if (args.action === BulkActionName.from("moveToFolder")) {
|
|
82
|
+
const folderId = args.data?.folderId;
|
|
83
|
+
if (!folderId) return new ErrorResponse({
|
|
84
|
+
code: "VALIDATION_FAILED",
|
|
85
|
+
message: 'Missing "data.folderId" in the input.'
|
|
86
|
+
});
|
|
87
|
+
if (!await canMoveToFolder(context, folderId)) return new ErrorResponse(EntryNotAuthorizedError.fromModel(model));
|
|
88
|
+
}
|
|
72
89
|
const identity = context.container.resolve(IdentityContext).getIdentity();
|
|
90
|
+
const where = await restrictWhere(context, model, args.action, args.where);
|
|
73
91
|
const response = await context.container.resolve(TriggerTaskUseCase).execute({
|
|
74
92
|
definition: BULK_ACTION_LIST_TASK_ID,
|
|
75
93
|
input: {
|
|
76
94
|
actionName: args.action,
|
|
77
95
|
modelId: model.modelId,
|
|
78
|
-
where
|
|
96
|
+
where,
|
|
79
97
|
search: args.search,
|
|
80
98
|
data: args.data,
|
|
81
99
|
identity
|
|
@@ -87,7 +105,7 @@ class BulkActionsGraphQLSchemaImpl {
|
|
|
87
105
|
}
|
|
88
106
|
}
|
|
89
107
|
},
|
|
90
|
-
isApplicable: (context)=>context.container.resolve(TenantContext).getTenant().id === tenant.id
|
|
108
|
+
isApplicable: (context)=>context.container.resolve(TenantContext).getTenant().id === tenant.id && "manage" === context.container.resolve(HeadlessCmsEndpointConfig).type
|
|
91
109
|
});
|
|
92
110
|
modelPlugin.name = `headless-cms.graphql.schema.bulkAction.${model.modelId}`;
|
|
93
111
|
plugins.push(modelPlugin);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql/BulkActionsGraphQLSchema.js","sources":["../../src/graphql/BulkActionsGraphQLSchema.ts"],"sourcesContent":["import type { Container } from \"@webiny/di\";\nimport {\n CmsGraphQLSchemaPlugin,\n CmsGraphQLSchemaFactory,\n isHeadlessCmsReady\n} from \"@webiny/api-headless-cms\";\nimport { ListModelsUseCase } from \"@webiny/api-headless-cms/features/contentModel/ListModels/index.js\";\nimport { CMS_MODEL_SINGLETON_TAG } from \"@webiny/api-headless-cms/constants.js\";\nimport { Response } from \"@webiny/api-graphql\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\nimport { TriggerTaskUseCase } from \"@webiny/background-tasks/api\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\nimport { BulkActionName } from \"~/domain/BulkActionName.js\";\nimport { BULK_ACTION_LIST_TASK_ID } from \"~/features/EntriesBulkAction/createBulkActionTasks.js\";\nimport { RequestContainer } from \"@webiny/event-handler-core\";\nimport type { HcmsBulkActionsContext } from \"~/types.js\";\n\nclass BulkActionsGraphQLSchemaImpl implements CmsGraphQLSchemaFactory.Interface {\n constructor(private readonly container: Container) {}\n\n async execute() {\n const context = { container: this.container } as HcmsBulkActionsContext;\n const tenantCtx = this.container.resolve(TenantContext);\n const tenant = tenantCtx.getTenant();\n\n if (!(await isHeadlessCmsReady(context))) {\n return [];\n }\n\n const identityCtx = this.container.resolve(IdentityContext);\n const modelsResult = await identityCtx.withoutAuthorization(async () => {\n return this.container.resolve(ListModelsUseCase).execute();\n });\n\n if (modelsResult.isFail()) {\n return [];\n }\n\n const allModels = modelsResult.value.filter(model => {\n if (model.isPrivate) {\n return false;\n }\n const tags = Array.isArray(model.tags) ? model.tags : [];\n return !tags.includes(CMS_MODEL_SINGLETON_TAG);\n });\n\n const bulkActions = this.container.resolveAll(EntriesBulkAction);\n const plugins: CmsGraphQLSchemaPlugin<HcmsBulkActionsContext>[] = [];\n\n const defaultPlugin = new CmsGraphQLSchemaPlugin({\n typeDefs: /* GraphQL */ `\n type BulkActionResponseData {\n id: String\n }\n\n type BulkActionResponse {\n data: BulkActionResponseData\n error: CmsError\n }\n `\n });\n defaultPlugin.name = \"headless-cms.graphql.schema.bulkAction.default\";\n plugins.push(defaultPlugin);\n\n for (const model of allModels) {\n const applicableActions = bulkActions.filter(action => {\n if (action.modelIds?.length) {\n return action.modelIds.includes(model.modelId);\n }\n return true;\n });\n\n const enumValues = applicableActions\n .map(action => BulkActionName.from(action.name))\n .join(\"\\n \");\n\n const modelPlugin = new CmsGraphQLSchemaPlugin<HcmsBulkActionsContext>({\n typeDefs: /* GraphQL */ `\n enum BulkAction${model.singularApiName}Name {\n _empty\n ${enumValues}\n }\n\n extend type Mutation {\n bulkAction${model.singularApiName}(\n action: BulkAction${model.singularApiName}Name!\n where: ${model.singularApiName}ListWhereInput\n search: String\n data: JSON\n ): BulkActionResponse\n }\n `,\n resolvers: {\n Mutation: {\n [`bulkAction${model.singularApiName}`]: async (_, args, context) => {\n const identity = context.container\n .resolve(IdentityContext)\n .getIdentity();\n\n const response = await context.container\n .resolve(TriggerTaskUseCase)\n .execute({\n definition: BULK_ACTION_LIST_TASK_ID,\n input: {\n actionName: args.action,\n modelId: model.modelId,\n where: args.where,\n search: args.search,\n data: args.data,\n identity\n }\n });\n\n return new Response({\n id: response.value.id\n });\n }\n }\n },\n isApplicable: context =>\n context.container.resolve(TenantContext).getTenant().id === tenant.id\n });\n\n modelPlugin.name = `headless-cms.graphql.schema.bulkAction.${model.modelId}`;\n plugins.push(modelPlugin);\n }\n\n return plugins;\n }\n}\n\nexport const BulkActionsGraphQLSchema = CmsGraphQLSchemaFactory.createImplementation({\n implementation: BulkActionsGraphQLSchemaImpl,\n dependencies: [RequestContainer]\n});\n"],"names":["BulkActionsGraphQLSchemaImpl","container","context","tenantCtx","TenantContext","tenant","isHeadlessCmsReady","identityCtx","IdentityContext","modelsResult","ListModelsUseCase","allModels","model","tags","Array","CMS_MODEL_SINGLETON_TAG","bulkActions","EntriesBulkAction","plugins","defaultPlugin","CmsGraphQLSchemaPlugin","applicableActions","action","enumValues","BulkActionName","modelPlugin","_","args","identity","response","TriggerTaskUseCase","BULK_ACTION_LIST_TASK_ID","Response","BulkActionsGraphQLSchema","CmsGraphQLSchemaFactory","RequestContainer"],"mappings":";;;;;;;;;;;AAkBA,MAAMA;IACF,YAA6BC,SAAoB,CAAE;aAAtBA,SAAS,GAATA;IAAuB;IAEpD,MAAM,UAAU;QACZ,MAAMC,UAAU;YAAE,WAAW,IAAI,CAAC,SAAS;QAAC;QAC5C,MAAMC,YAAY,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;QACzC,MAAMC,SAASF,UAAU,SAAS;QAElC,IAAI,CAAE,MAAMG,mBAAmBJ,UAC3B,OAAO,EAAE;QAGb,MAAMK,cAAc,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;QAC3C,MAAMC,eAAe,MAAMF,YAAY,oBAAoB,CAAC,UACjD,IAAI,CAAC,SAAS,CAAC,OAAO,CAACG,mBAAmB,OAAO;QAG5D,IAAID,aAAa,MAAM,IACnB,OAAO,EAAE;QAGb,MAAME,YAAYF,aAAa,KAAK,CAAC,MAAM,CAACG,CAAAA;YACxC,IAAIA,MAAM,SAAS,EACf,OAAO;YAEX,MAAMC,OAAOC,MAAM,OAAO,CAACF,MAAM,IAAI,IAAIA,MAAM,IAAI,GAAG,EAAE;YACxD,OAAO,CAACC,KAAK,QAAQ,CAACE;QAC1B;QAEA,MAAMC,cAAc,IAAI,CAAC,SAAS,CAAC,UAAU,CAACC;QAC9C,MAAMC,UAA4D,EAAE;QAEpE,MAAMC,gBAAgB,IAAIC,uBAAuB;YAC7C,UAAwB,CAAC;;;;;;;;;YASzB,CAAC;QACL;QACAD,cAAc,IAAI,GAAG;QACrBD,QAAQ,IAAI,CAACC;QAEb,KAAK,MAAMP,SA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AACO;QACjB;QAEA,OAAOP;IACX;AACJ;AAEO,MAAMe,2BAA2BC,wBAAwB,oBAAoB,CAAC;IACjF,gBAAgBlC;IAChB,cAAc;QAACmC;KAAiB;AACpC"}
|
|
1
|
+
{"version":3,"file":"graphql/BulkActionsGraphQLSchema.js","sources":["../../src/graphql/BulkActionsGraphQLSchema.ts"],"sourcesContent":["import type { Container } from \"@webiny/di\";\nimport {\n CmsGraphQLSchemaPlugin,\n CmsGraphQLSchemaFactory,\n isHeadlessCmsReady\n} from \"@webiny/api-headless-cms\";\nimport { ListModelsUseCase } from \"@webiny/api-headless-cms/features/contentModel/ListModels/index.js\";\nimport { CMS_MODEL_SINGLETON_TAG } from \"@webiny/api-headless-cms/constants.js\";\nimport { Response } from \"@webiny/api-graphql\";\nimport { ErrorResponse } from \"@webiny/api-graphql\";\nimport { EntryNotAuthorizedError } from \"@webiny/api-headless-cms/domain/contentEntry/errors.js\";\nimport { AccessControl } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { HeadlessCmsEndpointConfig } from \"@webiny/api-headless-cms/HeadlessCmsEndpointConfig.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\nimport { TriggerTaskUseCase } from \"@webiny/background-tasks/api\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\nimport { BulkActionName } from \"~/domain/BulkActionName.js\";\nimport { BULK_ACTION_LIST_TASK_ID } from \"~/features/EntriesBulkAction/createBulkActionTasks.js\";\nimport { RequestContainer } from \"@webiny/api-kernel-core\";\nimport type { HcmsBulkActionsContext } from \"~/types.js\";\nimport { canMoveToFolder, getRequiredAccess, restrictWhere } from \"./bulkActionAccess.js\";\n\nclass BulkActionsGraphQLSchemaImpl implements CmsGraphQLSchemaFactory.Interface {\n constructor(private readonly container: Container) {}\n\n async execute() {\n const context = { container: this.container } as HcmsBulkActionsContext;\n const tenantCtx = this.container.resolve(TenantContext);\n const tenant = tenantCtx.getTenant();\n\n if (!(await isHeadlessCmsReady(context))) {\n return [];\n }\n\n const identityCtx = this.container.resolve(IdentityContext);\n const modelsResult = await identityCtx.withoutAuthorization(async () => {\n return this.container.resolve(ListModelsUseCase).execute();\n });\n\n if (modelsResult.isFail()) {\n return [];\n }\n\n const allModels = modelsResult.value.filter(model => {\n if (model.isPrivate) {\n return false;\n }\n const tags = Array.isArray(model.tags) ? model.tags : [];\n return !tags.includes(CMS_MODEL_SINGLETON_TAG);\n });\n\n const bulkActions = this.container.resolveAll(EntriesBulkAction);\n const plugins: CmsGraphQLSchemaPlugin<HcmsBulkActionsContext>[] = [];\n\n const defaultPlugin = new CmsGraphQLSchemaPlugin({\n typeDefs: /* GraphQL */ `\n type BulkActionResponseData {\n id: String\n }\n\n type BulkActionResponse {\n data: BulkActionResponseData\n error: CmsError\n }\n `\n });\n defaultPlugin.name = \"headless-cms.graphql.schema.bulkAction.default\";\n plugins.push(defaultPlugin);\n\n for (const model of allModels) {\n const applicableActions = bulkActions.filter(action => {\n if (action.modelIds?.length) {\n return action.modelIds.includes(model.modelId);\n }\n return true;\n });\n\n const enumValues = applicableActions\n .map(action => BulkActionName.from(action.name))\n .join(\"\\n \");\n\n const modelPlugin = new CmsGraphQLSchemaPlugin<HcmsBulkActionsContext>({\n typeDefs: /* GraphQL */ `\n enum BulkAction${model.singularApiName}Name {\n _empty\n ${enumValues}\n }\n\n extend type Mutation {\n bulkAction${model.singularApiName}(\n action: BulkAction${model.singularApiName}Name!\n where: ${model.singularApiName}ListWhereInput\n search: String\n data: JSON\n ): BulkActionResponse\n }\n `,\n resolvers: {\n Mutation: {\n [`bulkAction${model.singularApiName}`]: async (_, args, context) => {\n const canAccess = await context.container\n .resolve(AccessControl)\n .canAccessEntry({ model, ...getRequiredAccess(args.action) });\n if (!canAccess) {\n return new ErrorResponse(EntryNotAuthorizedError.fromModel(model));\n }\n\n if (args.action === BulkActionName.from(\"moveToFolder\")) {\n const folderId = args.data?.folderId;\n if (!folderId) {\n return new ErrorResponse({\n code: \"VALIDATION_FAILED\",\n message: `Missing \"data.folderId\" in the input.`\n });\n }\n if (!(await canMoveToFolder(context, folderId))) {\n return new ErrorResponse(\n EntryNotAuthorizedError.fromModel(model)\n );\n }\n }\n\n const identity = context.container\n .resolve(IdentityContext)\n .getIdentity();\n\n /* The task lists and changes entries without authorization, so its\n query is limited here to the entries the caller may act on. */\n const where = await restrictWhere(\n context,\n model,\n args.action,\n args.where\n );\n\n const response = await context.container\n .resolve(TriggerTaskUseCase)\n .execute({\n definition: BULK_ACTION_LIST_TASK_ID,\n input: {\n actionName: args.action,\n modelId: model.modelId,\n where,\n search: args.search,\n data: args.data,\n identity\n }\n });\n\n return new Response({\n id: response.value.id\n });\n }\n }\n },\n isApplicable: context =>\n context.container.resolve(TenantContext).getTenant().id === tenant.id &&\n // Bulk actions change entries: manage endpoint only.\n context.container.resolve(HeadlessCmsEndpointConfig).type === \"manage\"\n });\n\n modelPlugin.name = `headless-cms.graphql.schema.bulkAction.${model.modelId}`;\n plugins.push(modelPlugin);\n }\n\n return plugins;\n }\n}\n\nexport const BulkActionsGraphQLSchema = CmsGraphQLSchemaFactory.createImplementation({\n implementation: BulkActionsGraphQLSchemaImpl,\n dependencies: [RequestContainer]\n});\n"],"names":["BulkActionsGraphQLSchemaImpl","container","context","tenantCtx","TenantContext","tenant","isHeadlessCmsReady","identityCtx","IdentityContext","modelsResult","ListModelsUseCase","allModels","model","tags","Array","CMS_MODEL_SINGLETON_TAG","bulkActions","EntriesBulkAction","plugins","defaultPlugin","CmsGraphQLSchemaPlugin","applicableActions","action","enumValues","BulkActionName","modelPlugin","_","args","canAccess","AccessControl","getRequiredAccess","ErrorResponse","EntryNotAuthorizedError","folderId","canMoveToFolder","identity","where","restrictWhere","response","TriggerTaskUseCase","BULK_ACTION_LIST_TASK_ID","Response","HeadlessCmsEndpointConfig","BulkActionsGraphQLSchema","CmsGraphQLSchemaFactory","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BACJ;4BAEJ,OAAO,IAAIM,SAAS;gCAChB,IAAIH,SAAS,KAAK,CAAC,EAAE;4BACzB;wBACJ;oBACJ;gBACJ;gBACA,cAAcpC,CAAAA,UACVA,QAAQ,SAAS,CAAC,OAAO,CAACE,eAAe,SAAS,GAAG,EAAE,KAAKC,OAAO,EAAE,IAErEH,AAA8D,aAA9DA,QAAQ,SAAS,CAAC,OAAO,CAACwC,2BAA2B,IAAI;YACjE;YAEAjB,YAAY,IAAI,GAAG,CAAC,uCAAuC,EAAEb,MAAM,OAAO,EAAE;YAC5EM,QAAQ,IAAI,CAACO;QACjB;QAEA,OAAOP;IACX;AACJ;AAEO,MAAMyB,2BAA2BC,wBAAwB,oBAAoB,CAAC;IACjF,gBAAgB5C;IAChB,cAAc;QAAC6C;KAAiB;AACpC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { HcmsBulkActionsContext } from "../types.js";
|
|
2
|
+
import type { CmsEntryListWhere, CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* The permission each bulk action requires on the model, matching the single-entry use case it runs.
|
|
5
|
+
* Custom bulk actions require write access.
|
|
6
|
+
*/
|
|
7
|
+
export declare const getRequiredAccess: (action: string) => {
|
|
8
|
+
rwd?: string;
|
|
9
|
+
pw?: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Bulk action tasks run without authorization, so the target folder of a move is checked here,
|
|
13
|
+
* with the same folder-level permission check the single-entry move uses.
|
|
14
|
+
*/
|
|
15
|
+
export declare const canMoveToFolder: (context: HcmsBulkActionsContext, folderId: string) => Promise<boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* Bulk action tasks list and change entries without authorization, so the task query is
|
|
18
|
+
* restricted here to the entries the caller may act on: own entries only, when that is all the
|
|
19
|
+
* caller may change, and no entries from folders the caller can't change.
|
|
20
|
+
* The restrictions are set on the top level of `where`, so the client `where` can only narrow them.
|
|
21
|
+
*/
|
|
22
|
+
export declare const restrictWhere: (context: HcmsBulkActionsContext, model: CmsModel, action: string, initialWhere: CmsEntryListWhere | undefined) => Promise<CmsEntryListWhere>;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/abstractions.js";
|
|
2
|
+
import { AccessControl } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
3
|
+
import { FolderLevelPermissions } from "@webiny/api-aco/features/flp/FolderLevelPermissions/index.js";
|
|
4
|
+
import { ROOT_FOLDER } from "@webiny/api-aco/constants.js";
|
|
5
|
+
const getRequiredAccess = (action)=>{
|
|
6
|
+
switch(action){
|
|
7
|
+
case "Delete":
|
|
8
|
+
case "MoveToTrash":
|
|
9
|
+
return {
|
|
10
|
+
rwd: "d"
|
|
11
|
+
};
|
|
12
|
+
case "Publish":
|
|
13
|
+
return {
|
|
14
|
+
pw: "p"
|
|
15
|
+
};
|
|
16
|
+
case "Unpublish":
|
|
17
|
+
return {
|
|
18
|
+
pw: "u"
|
|
19
|
+
};
|
|
20
|
+
default:
|
|
21
|
+
return {
|
|
22
|
+
rwd: "w"
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const canMoveToFolder = async (context, folderId)=>{
|
|
27
|
+
if (folderId === ROOT_FOLDER) return true;
|
|
28
|
+
const [flp] = context.container.resolveAll(FolderLevelPermissions);
|
|
29
|
+
if (!flp || !flp.canUseFolderLevelPermissions()) return true;
|
|
30
|
+
const permissions = await flp.getFolderLevelPermissions(folderId);
|
|
31
|
+
return flp.canAccessFolderContent({
|
|
32
|
+
permissions,
|
|
33
|
+
rwd: "w"
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
const canActOnlyOnOwnedEntries = async (context, model, action)=>{
|
|
37
|
+
const accessControl = context.container.resolve(AccessControl);
|
|
38
|
+
if (await accessControl.canAccessOnlyOwnedEntries({
|
|
39
|
+
model
|
|
40
|
+
})) return true;
|
|
41
|
+
const identity = context.container.resolve(IdentityContext).getIdentity();
|
|
42
|
+
const canActOnOthers = await accessControl.canAccessEntry({
|
|
43
|
+
model,
|
|
44
|
+
entry: {
|
|
45
|
+
entryId: "",
|
|
46
|
+
createdBy: {
|
|
47
|
+
id: `${identity.id}#not-owner`,
|
|
48
|
+
displayName: "",
|
|
49
|
+
type: ""
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
...getRequiredAccess(action)
|
|
53
|
+
});
|
|
54
|
+
return !canActOnOthers;
|
|
55
|
+
};
|
|
56
|
+
const listDeniedFolderIds = async (context, model, action)=>{
|
|
57
|
+
const [flp] = context.container.resolveAll(FolderLevelPermissions);
|
|
58
|
+
if (!flp || !flp.canUseFolderLevelPermissions()) return [];
|
|
59
|
+
const rwd = "d" === getRequiredAccess(action).rwd ? "d" : "w";
|
|
60
|
+
const flps = await flp.listFolderLevelPermissions({
|
|
61
|
+
where: {
|
|
62
|
+
type: `cms:${model.modelId}`,
|
|
63
|
+
path_startsWith: `${ROOT_FOLDER}/`
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
const denied = [];
|
|
67
|
+
for (const item of flps)if (!await flp.canAccessFolderContent({
|
|
68
|
+
permissions: item.permissions,
|
|
69
|
+
rwd
|
|
70
|
+
})) denied.push(item.id);
|
|
71
|
+
return denied;
|
|
72
|
+
};
|
|
73
|
+
const restrictWhere = async (context, model, action, initialWhere)=>{
|
|
74
|
+
const where = {
|
|
75
|
+
...initialWhere
|
|
76
|
+
};
|
|
77
|
+
if (await canActOnlyOnOwnedEntries(context, model, action)) where.createdBy = context.container.resolve(IdentityContext).getIdentity().id;
|
|
78
|
+
const deniedFolderIds = await listDeniedFolderIds(context, model, action);
|
|
79
|
+
if (deniedFolderIds.length > 0) {
|
|
80
|
+
const location = where.location ?? where.wbyAco_location ?? {};
|
|
81
|
+
delete where.location;
|
|
82
|
+
where.wbyAco_location = {
|
|
83
|
+
...location,
|
|
84
|
+
folderId_not_in: [
|
|
85
|
+
...location.folderId_not_in ?? [],
|
|
86
|
+
...deniedFolderIds
|
|
87
|
+
]
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return where;
|
|
91
|
+
};
|
|
92
|
+
export { canMoveToFolder, getRequiredAccess, restrictWhere };
|
|
93
|
+
|
|
94
|
+
//# sourceMappingURL=bulkActionAccess.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql/bulkActionAccess.js","sources":["../../src/graphql/bulkActionAccess.ts"],"sourcesContent":["import type { HcmsBulkActionsContext } from \"~/types.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\nimport { AccessControl } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport { FolderLevelPermissions } from \"@webiny/api-aco/features/flp/FolderLevelPermissions/index.js\";\nimport { ROOT_FOLDER } from \"@webiny/api-aco/constants.js\";\nimport type { CmsEntryListWhere, CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\n\n/**\n * The permission each bulk action requires on the model, matching the single-entry use case it runs.\n * Custom bulk actions require write access.\n */\nexport const getRequiredAccess = (action: string): { rwd?: string; pw?: string } => {\n switch (action) {\n case \"Delete\":\n case \"MoveToTrash\":\n return { rwd: \"d\" };\n case \"Publish\":\n return { pw: \"p\" };\n case \"Unpublish\":\n return { pw: \"u\" };\n default:\n return { rwd: \"w\" };\n }\n};\n\n/**\n * Bulk action tasks run without authorization, so the target folder of a move is checked here,\n * with the same folder-level permission check the single-entry move uses.\n */\nexport const canMoveToFolder = async (\n context: HcmsBulkActionsContext,\n folderId: string\n): Promise<boolean> => {\n if (folderId === ROOT_FOLDER) {\n return true;\n }\n\n const [flp] = context.container.resolveAll(FolderLevelPermissions);\n if (!flp || !flp.canUseFolderLevelPermissions()) {\n return true;\n }\n\n const permissions = await flp.getFolderLevelPermissions(folderId);\n return flp.canAccessFolderContent({ permissions, rwd: \"w\" });\n};\n\n/**\n * Whether the caller may run the action only on entries they created. Besides own-only access,\n * this covers several permission sets (e.g. read all entries, delete own), where the action\n * itself is allowed only on own entries: it is checked against an entry the caller doesn't own.\n */\nconst canActOnlyOnOwnedEntries = async (\n context: HcmsBulkActionsContext,\n model: CmsModel,\n action: string\n): Promise<boolean> => {\n const accessControl = context.container.resolve(AccessControl);\n if (await accessControl.canAccessOnlyOwnedEntries({ model })) {\n return true;\n }\n\n const identity = context.container.resolve(IdentityContext).getIdentity();\n const canActOnOthers = await accessControl.canAccessEntry({\n model,\n entry: {\n entryId: \"\",\n createdBy: {\n id: `${identity.id}#not-owner`,\n displayName: \"\",\n type: \"\"\n }\n },\n ...getRequiredAccess(action)\n });\n return !canActOnOthers;\n};\n\n/**\n * Ids of the model's folders whose content the caller can't change with this action.\n */\nconst listDeniedFolderIds = async (\n context: HcmsBulkActionsContext,\n model: CmsModel,\n action: string\n): Promise<string[]> => {\n const [flp] = context.container.resolveAll(FolderLevelPermissions);\n if (!flp || !flp.canUseFolderLevelPermissions()) {\n return [];\n }\n\n const rwd = getRequiredAccess(action).rwd === \"d\" ? \"d\" : \"w\";\n\n // Every folder path starts with the root folder.\n const flps = await flp.listFolderLevelPermissions({\n where: { type: `cms:${model.modelId}`, path_startsWith: `${ROOT_FOLDER}/` }\n });\n\n const denied: string[] = [];\n for (const item of flps) {\n if (!(await flp.canAccessFolderContent({ permissions: item.permissions, rwd }))) {\n denied.push(item.id);\n }\n }\n return denied;\n};\n\n/**\n * Bulk action tasks list and change entries without authorization, so the task query is\n * restricted here to the entries the caller may act on: own entries only, when that is all the\n * caller may change, and no entries from folders the caller can't change.\n * The restrictions are set on the top level of `where`, so the client `where` can only narrow them.\n */\nexport const restrictWhere = async (\n context: HcmsBulkActionsContext,\n model: CmsModel,\n action: string,\n initialWhere: CmsEntryListWhere | undefined\n): Promise<CmsEntryListWhere> => {\n const where: CmsEntryListWhere = { ...initialWhere };\n\n if (await canActOnlyOnOwnedEntries(context, model, action)) {\n where.createdBy = context.container.resolve(IdentityContext).getIdentity().id;\n }\n\n const deniedFolderIds = await listDeniedFolderIds(context, model, action);\n if (deniedFolderIds.length > 0) {\n // Listing replaces `wbyAco_location` with `location` when both are set, so use the same one.\n const location = where.location ?? where.wbyAco_location ?? {};\n delete where.location;\n where.wbyAco_location = {\n ...location,\n folderId_not_in: [...(location.folderId_not_in ?? []), ...deniedFolderIds]\n };\n }\n\n return where;\n};\n"],"names":["getRequiredAccess","action","canMoveToFolder","context","folderId","ROOT_FOLDER","flp","FolderLevelPermissions","permissions","canActOnlyOnOwnedEntries","model","accessControl","AccessControl","identity","IdentityContext","canActOnOthers","listDeniedFolderIds","rwd","flps","denied","item","restrictWhere","initialWhere","where","deniedFolderIds","location"],"mappings":";;;;AAWO,MAAMA,oBAAoB,CAACC;IAC9B,OAAQA;QACJ,KAAK;QACL,KAAK;YACD,OAAO;gBAAE,KAAK;YAAI;QACtB,KAAK;YACD,OAAO;gBAAE,IAAI;YAAI;QACrB,KAAK;YACD,OAAO;gBAAE,IAAI;YAAI;QACrB;YACI,OAAO;gBAAE,KAAK;YAAI;IAC1B;AACJ;AAMO,MAAMC,kBAAkB,OAC3BC,SACAC;IAEA,IAAIA,aAAaC,aACb,OAAO;IAGX,MAAM,CAACC,IAAI,GAAGH,QAAQ,SAAS,CAAC,UAAU,CAACI;IAC3C,IAAI,CAACD,OAAO,CAACA,IAAI,4BAA4B,IACzC,OAAO;IAGX,MAAME,cAAc,MAAMF,IAAI,yBAAyB,CAACF;IACxD,OAAOE,IAAI,sBAAsB,CAAC;QAAEE;QAAa,KAAK;IAAI;AAC9D;AAOA,MAAMC,2BAA2B,OAC7BN,SACAO,OACAT;IAEA,MAAMU,gBAAgBR,QAAQ,SAAS,CAAC,OAAO,CAACS;IAChD,IAAI,MAAMD,cAAc,yBAAyB,CAAC;QAAED;IAAM,IACtD,OAAO;IAGX,MAAMG,WAAWV,QAAQ,SAAS,CAAC,OAAO,CAACW,iBAAiB,WAAW;IACvE,MAAMC,iBAAiB,MAAMJ,cAAc,cAAc,CAAC;QACtDD;QAC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ACX,iBAAiB;mBAAKA,SAAS,eAAe,IAAI,EAAE;mBAAMD;aAAgB;QAC9E;IACJ;IAEA,OAAOD;AACX"}
|
|
@@ -4,6 +4,7 @@ import { Response } from "@webiny/api-graphql";
|
|
|
4
4
|
import { CMS_MODEL_SINGLETON_TAG } from "@webiny/api-headless-cms/constants.js";
|
|
5
5
|
import { BulkActionName } from "../domain/BulkActionName.js";
|
|
6
6
|
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
7
|
+
import { HeadlessCmsEndpointConfig } from "@webiny/api-headless-cms/HeadlessCmsEndpointConfig.js";
|
|
7
8
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/abstractions.js";
|
|
8
9
|
import { TriggerTaskUseCase } from "@webiny/background-tasks/api";
|
|
9
10
|
const createBulkActionGraphQL = async (context, bulkAction)=>{
|
|
@@ -46,7 +47,7 @@ const createBulkActionGraphQL = async (context, bulkAction)=>{
|
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
},
|
|
49
|
-
isApplicable: (context)=>context.container.resolve(TenantContext).getTenant().id === tenant.id
|
|
50
|
+
isApplicable: (context)=>context.container.resolve(TenantContext).getTenant().id === tenant.id && "manage" === context.container.resolve(HeadlessCmsEndpointConfig).type
|
|
50
51
|
});
|
|
51
52
|
plugin.name = `headless-cms.graphql.schema.bulkAction.${model.modelId}.${bulkAction.name}`;
|
|
52
53
|
plugins.push(plugin);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql/createBulkActionGraphQL.js","sources":["../../src/graphql/createBulkActionGraphQL.ts"],"sourcesContent":["import type { HcmsBulkActionsContext } from \"~/types.js\";\nimport {\n CmsGraphQLSchemaPlugin,\n CmsGraphQLSchemaFactory,\n isHeadlessCmsReady\n} from \"@webiny/api-headless-cms\";\nimport { ListModelsUseCase } from \"@webiny/api-headless-cms/features/contentModel/ListModels/index.js\";\nimport { Response } from \"@webiny/api-graphql\";\nimport { CMS_MODEL_SINGLETON_TAG } from \"@webiny/api-headless-cms/constants.js\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\nimport { BulkActionName } from \"~/domain/BulkActionName.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\nimport { TriggerTaskUseCase } from \"@webiny/background-tasks/api\";\n\nexport const createBulkActionGraphQL = async (\n context: HcmsBulkActionsContext,\n bulkAction: EntriesBulkAction.Interface\n) => {\n const tenant = context.container.resolve(TenantContext).getTenant();\n\n if (!(await isHeadlessCmsReady(context))) {\n return;\n }\n\n const modelsResult = await context.container\n .resolve(IdentityContext)\n .withoutAuthorization(async () => {\n return context.container.resolve(ListModelsUseCase).execute();\n });\n if (modelsResult.isFail()) {\n return;\n }\n const models = modelsResult.value.filter(model => {\n if (model.isPrivate) {\n return false;\n }\n const tags = Array.isArray(model.tags) ? model.tags : [];\n if (tags.includes(CMS_MODEL_SINGLETON_TAG)) {\n return false;\n }\n if (bulkAction.modelIds?.length) {\n return bulkAction.modelIds.includes(model.modelId);\n }\n return true;\n });\n\n const plugins: CmsGraphQLSchemaPlugin<HcmsBulkActionsContext>[] = [];\n\n models.forEach(model => {\n const plugin = new CmsGraphQLSchemaPlugin<HcmsBulkActionsContext>({\n typeDefs: /* GraphQL */ `\n extend enum BulkAction${model.singularApiName}Name {\n ${BulkActionName.from(bulkAction.name)}\n }\n `,\n resolvers: {\n Mutation: {\n [`bulkAction${model.singularApiName}`]: async (_, args, context) => {\n const identity = context.container.resolve(IdentityContext).getIdentity();\n\n const response = await context.container\n .resolve(TriggerTaskUseCase)\n .execute({\n definition: `hcmsBulkList${args.action}Entries`,\n input: {\n modelId: model.modelId,\n where: args.where,\n search: args.search,\n data: args.data,\n identity\n }\n });\n\n return new Response({\n id: response.value.id\n });\n }\n }\n },\n isApplicable: context =>\n context.container.resolve(TenantContext).getTenant().id === tenant.id\n });\n\n plugin.name = `headless-cms.graphql.schema.bulkAction.${model.modelId}.${bulkAction.name}`;\n plugins.push(plugin);\n });\n\n context.container.registerInstance(CmsGraphQLSchemaFactory, {\n execute: () => plugins\n });\n};\n"],"names":["createBulkActionGraphQL","context","bulkAction","tenant","TenantContext","isHeadlessCmsReady","modelsResult","IdentityContext","ListModelsUseCase","models","model","tags","Array","CMS_MODEL_SINGLETON_TAG","plugins","plugin","CmsGraphQLSchemaPlugin","BulkActionName","_","args","identity","response","TriggerTaskUseCase","Response","CmsGraphQLSchemaFactory"],"mappings":"
|
|
1
|
+
{"version":3,"file":"graphql/createBulkActionGraphQL.js","sources":["../../src/graphql/createBulkActionGraphQL.ts"],"sourcesContent":["import type { HcmsBulkActionsContext } from \"~/types.js\";\nimport {\n CmsGraphQLSchemaPlugin,\n CmsGraphQLSchemaFactory,\n isHeadlessCmsReady\n} from \"@webiny/api-headless-cms\";\nimport { ListModelsUseCase } from \"@webiny/api-headless-cms/features/contentModel/ListModels/index.js\";\nimport { Response } from \"@webiny/api-graphql\";\nimport { CMS_MODEL_SINGLETON_TAG } from \"@webiny/api-headless-cms/constants.js\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\nimport { BulkActionName } from \"~/domain/BulkActionName.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { HeadlessCmsEndpointConfig } from \"@webiny/api-headless-cms/HeadlessCmsEndpointConfig.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\nimport { TriggerTaskUseCase } from \"@webiny/background-tasks/api\";\n\nexport const createBulkActionGraphQL = async (\n context: HcmsBulkActionsContext,\n bulkAction: EntriesBulkAction.Interface\n) => {\n const tenant = context.container.resolve(TenantContext).getTenant();\n\n if (!(await isHeadlessCmsReady(context))) {\n return;\n }\n\n const modelsResult = await context.container\n .resolve(IdentityContext)\n .withoutAuthorization(async () => {\n return context.container.resolve(ListModelsUseCase).execute();\n });\n if (modelsResult.isFail()) {\n return;\n }\n const models = modelsResult.value.filter(model => {\n if (model.isPrivate) {\n return false;\n }\n const tags = Array.isArray(model.tags) ? model.tags : [];\n if (tags.includes(CMS_MODEL_SINGLETON_TAG)) {\n return false;\n }\n if (bulkAction.modelIds?.length) {\n return bulkAction.modelIds.includes(model.modelId);\n }\n return true;\n });\n\n const plugins: CmsGraphQLSchemaPlugin<HcmsBulkActionsContext>[] = [];\n\n models.forEach(model => {\n const plugin = new CmsGraphQLSchemaPlugin<HcmsBulkActionsContext>({\n typeDefs: /* GraphQL */ `\n extend enum BulkAction${model.singularApiName}Name {\n ${BulkActionName.from(bulkAction.name)}\n }\n `,\n resolvers: {\n Mutation: {\n [`bulkAction${model.singularApiName}`]: async (_, args, context) => {\n const identity = context.container.resolve(IdentityContext).getIdentity();\n\n const response = await context.container\n .resolve(TriggerTaskUseCase)\n .execute({\n definition: `hcmsBulkList${args.action}Entries`,\n input: {\n modelId: model.modelId,\n where: args.where,\n search: args.search,\n data: args.data,\n identity\n }\n });\n\n return new Response({\n id: response.value.id\n });\n }\n }\n },\n isApplicable: context =>\n context.container.resolve(TenantContext).getTenant().id === tenant.id &&\n // Bulk actions change entries: manage endpoint only.\n context.container.resolve(HeadlessCmsEndpointConfig).type === \"manage\"\n });\n\n plugin.name = `headless-cms.graphql.schema.bulkAction.${model.modelId}.${bulkAction.name}`;\n plugins.push(plugin);\n });\n\n context.container.registerInstance(CmsGraphQLSchemaFactory, {\n execute: () => plugins\n });\n};\n"],"names":["createBulkActionGraphQL","context","bulkAction","tenant","TenantContext","isHeadlessCmsReady","modelsResult","IdentityContext","ListModelsUseCase","models","model","tags","Array","CMS_MODEL_SINGLETON_TAG","plugins","plugin","CmsGraphQLSchemaPlugin","BulkActionName","_","args","identity","response","TriggerTaskUseCase","Response","HeadlessCmsEndpointConfig","CmsGraphQLSchemaFactory"],"mappings":";;;;;;;;;AAgBO,MAAMA,0BAA0B,OACnCC,SACAC;IAEA,MAAMC,SAASF,Q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ACfC;4BACJ;wBACJ;wBAEJ,OAAO,IAAIG,SAAS;4BAChB,IAAIF,SAAS,KAAK,CAAC,EAAE;wBACzB;oBACJ;gBACJ;YACJ;YACA,cAAcpB,CAAAA,UACVA,QAAQ,SAAS,CAAC,OAAO,CAACG,eAAe,SAAS,GAAG,EAAE,KAAKD,OAAO,EAAE,IAErEF,AAA8D,aAA9DA,QAAQ,SAAS,CAAC,OAAO,CAACuB,2BAA2B,IAAI;QACjE;QAEAT,OAAO,IAAI,GAAG,CAAC,uCAAuC,EAAEL,MAAM,OAAO,CAAC,CAAC,EAAER,WAAW,IAAI,EAAE;QAC1FY,QAAQ,IAAI,CAACC;IACjB;IAEAd,QAAQ,SAAS,CAAC,gBAAgB,CAACwB,yBAAyB;QACxD,SAAS,IAAMX;IACnB;AACJ"}
|
|
@@ -2,6 +2,7 @@ import { CmsGraphQLSchemaFactory, CmsGraphQLSchemaPlugin, isHeadlessCmsReady } f
|
|
|
2
2
|
import { ListModelsUseCase } from "@webiny/api-headless-cms/features/contentModel/ListModels/index.js";
|
|
3
3
|
import { CMS_MODEL_SINGLETON_TAG } from "@webiny/api-headless-cms/constants.js";
|
|
4
4
|
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
5
|
+
import { HeadlessCmsEndpointConfig } from "@webiny/api-headless-cms/HeadlessCmsEndpointConfig.js";
|
|
5
6
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/abstractions.js";
|
|
6
7
|
const registerDefaultBulkActionGraphQL = async (context)=>{
|
|
7
8
|
const tenant = context.container.resolve(TenantContext).getTenant();
|
|
@@ -43,7 +44,7 @@ const registerDefaultBulkActionGraphQL = async (context)=>{
|
|
|
43
44
|
): BulkActionResponse
|
|
44
45
|
}
|
|
45
46
|
`,
|
|
46
|
-
isApplicable: (context)=>context.container.resolve(TenantContext).getTenant().id === tenant.id
|
|
47
|
+
isApplicable: (context)=>context.container.resolve(TenantContext).getTenant().id === tenant.id && "manage" === context.container.resolve(HeadlessCmsEndpointConfig).type
|
|
47
48
|
});
|
|
48
49
|
plugin.name = `headless-cms.graphql.schema.bulkAction.default.${model.modelId}`;
|
|
49
50
|
modelPlugins.push(plugin);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql/createDefaultGraphQL.js","sources":["../../src/graphql/createDefaultGraphQL.ts"],"sourcesContent":["import type { HcmsBulkActionsContext } from \"~/types.js\";\nimport {\n CmsGraphQLSchemaPlugin,\n CmsGraphQLSchemaFactory,\n isHeadlessCmsReady\n} from \"@webiny/api-headless-cms\";\nimport { ListModelsUseCase } from \"@webiny/api-headless-cms/features/contentModel/ListModels/index.js\";\nimport { CMS_MODEL_SINGLETON_TAG } from \"@webiny/api-headless-cms/constants.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\n\n/**\n * Registers the \"default\" bulk-action GraphQL for every public model: the shared response types plus,\n * per model, an empty `BulkAction<Model>Name` enum + `bulkAction<Model>` mutation skeleton (each\n * action extends the enum via createBulkActionGraphQL). Run per request, since models are only\n * known at request time.\n */\nexport const registerDefaultBulkActionGraphQL = async (context: HcmsBulkActionsContext) => {\n const tenant = context.container.resolve(TenantContext).getTenant();\n\n if (!(await isHeadlessCmsReady(context))) {\n return;\n }\n\n const defaultPlugin = new CmsGraphQLSchemaPlugin({\n typeDefs: /* GraphQL */ `\n type BulkActionResponseData {\n id: String\n }\n\n type BulkActionResponse {\n data: BulkActionResponseData\n error: CmsError\n }\n `\n });\n defaultPlugin.name = `headless-cms.graphql.schema.bulkAction.default`;\n\n const modelsResult = await context.container\n .resolve(IdentityContext)\n .withoutAuthorization(async () => {\n return context.container.resolve(ListModelsUseCase).execute();\n });\n if (modelsResult.isFail()) {\n return;\n }\n const models = modelsResult.value.filter(model => {\n if (model.isPrivate) {\n return false;\n }\n const tags = Array.isArray(model.tags) ? model.tags : [];\n return !tags.includes(CMS_MODEL_SINGLETON_TAG);\n });\n\n const modelPlugins: CmsGraphQLSchemaPlugin<HcmsBulkActionsContext>[] = [];\n\n models.forEach(model => {\n const plugin = new CmsGraphQLSchemaPlugin({\n typeDefs: /* GraphQL */ `\n enum BulkAction${model.singularApiName}Name {\n _empty\n }\n \n extend type Mutation {\n bulkAction${model.singularApiName}(\n action: BulkAction${model.singularApiName}Name!\n where: ${model.singularApiName}ListWhereInput\n search: String\n data: JSON\n ): BulkActionResponse\n }\n `,\n isApplicable: context =>\n context.container.resolve(TenantContext).getTenant().id === tenant.id\n });\n\n plugin.name = `headless-cms.graphql.schema.bulkAction.default.${model.modelId}`;\n modelPlugins.push(plugin);\n });\n\n context.container.registerInstance(CmsGraphQLSchemaFactory, {\n execute: () => [defaultPlugin, ...modelPlugins]\n });\n};\n"],"names":["registerDefaultBulkActionGraphQL","context","tenant","TenantContext","isHeadlessCmsReady","defaultPlugin","CmsGraphQLSchemaPlugin","modelsResult","IdentityContext","ListModelsUseCase","models","model","tags","Array","CMS_MODEL_SINGLETON_TAG","modelPlugins","plugin","CmsGraphQLSchemaFactory"],"mappings":"
|
|
1
|
+
{"version":3,"file":"graphql/createDefaultGraphQL.js","sources":["../../src/graphql/createDefaultGraphQL.ts"],"sourcesContent":["import type { HcmsBulkActionsContext } from \"~/types.js\";\nimport {\n CmsGraphQLSchemaPlugin,\n CmsGraphQLSchemaFactory,\n isHeadlessCmsReady\n} from \"@webiny/api-headless-cms\";\nimport { ListModelsUseCase } from \"@webiny/api-headless-cms/features/contentModel/ListModels/index.js\";\nimport { CMS_MODEL_SINGLETON_TAG } from \"@webiny/api-headless-cms/constants.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { HeadlessCmsEndpointConfig } from \"@webiny/api-headless-cms/HeadlessCmsEndpointConfig.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\n\n/**\n * Registers the \"default\" bulk-action GraphQL for every public model: the shared response types plus,\n * per model, an empty `BulkAction<Model>Name` enum + `bulkAction<Model>` mutation skeleton (each\n * action extends the enum via createBulkActionGraphQL). Run per request, since models are only\n * known at request time.\n */\nexport const registerDefaultBulkActionGraphQL = async (context: HcmsBulkActionsContext) => {\n const tenant = context.container.resolve(TenantContext).getTenant();\n\n if (!(await isHeadlessCmsReady(context))) {\n return;\n }\n\n const defaultPlugin = new CmsGraphQLSchemaPlugin({\n typeDefs: /* GraphQL */ `\n type BulkActionResponseData {\n id: String\n }\n\n type BulkActionResponse {\n data: BulkActionResponseData\n error: CmsError\n }\n `\n });\n defaultPlugin.name = `headless-cms.graphql.schema.bulkAction.default`;\n\n const modelsResult = await context.container\n .resolve(IdentityContext)\n .withoutAuthorization(async () => {\n return context.container.resolve(ListModelsUseCase).execute();\n });\n if (modelsResult.isFail()) {\n return;\n }\n const models = modelsResult.value.filter(model => {\n if (model.isPrivate) {\n return false;\n }\n const tags = Array.isArray(model.tags) ? model.tags : [];\n return !tags.includes(CMS_MODEL_SINGLETON_TAG);\n });\n\n const modelPlugins: CmsGraphQLSchemaPlugin<HcmsBulkActionsContext>[] = [];\n\n models.forEach(model => {\n const plugin = new CmsGraphQLSchemaPlugin({\n typeDefs: /* GraphQL */ `\n enum BulkAction${model.singularApiName}Name {\n _empty\n }\n \n extend type Mutation {\n bulkAction${model.singularApiName}(\n action: BulkAction${model.singularApiName}Name!\n where: ${model.singularApiName}ListWhereInput\n search: String\n data: JSON\n ): BulkActionResponse\n }\n `,\n isApplicable: context =>\n context.container.resolve(TenantContext).getTenant().id === tenant.id &&\n // Bulk actions change entries: manage endpoint only.\n context.container.resolve(HeadlessCmsEndpointConfig).type === \"manage\"\n });\n\n plugin.name = `headless-cms.graphql.schema.bulkAction.default.${model.modelId}`;\n modelPlugins.push(plugin);\n });\n\n context.container.registerInstance(CmsGraphQLSchemaFactory, {\n execute: () => [defaultPlugin, ...modelPlugins]\n });\n};\n"],"names":["registerDefaultBulkActionGraphQL","context","tenant","TenantContext","isHeadlessCmsReady","defaultPlugin","CmsGraphQLSchemaPlugin","modelsResult","IdentityContext","ListModelsUseCase","models","model","tags","Array","CMS_MODEL_SINGLETON_TAG","modelPlugins","plugin","HeadlessCmsEndpointConfig","CmsGraphQLSchemaFactory"],"mappings":";;;;;;AAkBO,MAAMA,mCAAmC,OAAOC;IACnD,MAAMC,SAASD,QAAQ,SAAS,CAAC,OAAO,CAACE,eAAe,SAAS;IAEjE,IAAI,CAAE,MAAMC,mBAAmBH,UAC3B;IAGJ,MAAMI,gBAAgB,IAAIC,uBAAuB;QAC7C,UAAwB,CAAC;;;;;;;;;QASzB,CAAC;IACL;IACAD,cAAc,IAAI,GAAG;IAErB,MAAME,eAAe,MAAMN,QAAQ,SAAS,CACvC,OAAO,CAACO,iBACR,oBAAoB,CAAC,UACXP,QAAQ,SAAS,CAAC,OAAO,CAACQ,mBAAmB,OAAO;IAEnE,IAAIF,aAAa,MAAM,IACnB;IAEJ,MAAMG,SAASH,aAAa,KAAK,CAAC,MAAM,CAACI,CAAAA;QACrC,IAAIA,MAAM,SAAS,EACf,OAAO;QAEX,MAAMC,OAAOC,MAAM,OAAO,CAACF,MAAM,IAAI,IAAIA,MAAM,IAAI,GAAG,EAAE;QACxD,OAAO,CAACC,KAAK,QAAQ,CAACE;IAC1B;IAEA,MAAMC,eAAiE,EAAE;IAEzEL,OAAO,OAAO,CAACC,CAAAA;QACX,MAAMK,SAAS,IAAIV,uBAAuB;YACtC,UAAwB,CAAC;mCACF,EAAEK,MAAM,eAAe,CAAC;;;;;kCAKzB,EAAEA,MAAM,eAAe,CAAC;8CACZ,EAAEA,MAAM,eAAe,CAAC;mCACnC,EAAEA,MAAM,eAAe,CAAC;;;;;gBAK3C,CAAC;YACL,cAAcV,CAAAA,UACVA,QAAQ,SAAS,CAAC,OAAO,CAACE,eAAe,SAAS,GAAG,EAAE,KAAKD,OAAO,EAAE,IAErED,AAA8D,aAA9DA,QAAQ,SAAS,CAAC,OAAO,CAACgB,2BAA2B,IAAI;QACjE;QAEAD,OAAO,IAAI,GAAG,CAAC,+CAA+C,EAAEL,MAAM,OAAO,EAAE;QAC/EI,aAAa,IAAI,CAACC;IACtB;IAEAf,QAAQ,SAAS,CAAC,gBAAgB,CAACiB,yBAAyB;QACxD,SAAS,IAAM;gBAACb;mBAAkBU;aAAa;IACnD;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-headless-cms-bulk-actions",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.676006d08e",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -17,26 +17,27 @@
|
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@webiny/api-
|
|
21
|
-
"@webiny/api-
|
|
22
|
-
"@webiny/
|
|
23
|
-
"@webiny/
|
|
24
|
-
"@webiny/
|
|
25
|
-
"@webiny/
|
|
26
|
-
"@webiny/
|
|
20
|
+
"@webiny/api-aco": "0.0.0-unstable.676006d08e",
|
|
21
|
+
"@webiny/api-graphql": "0.0.0-unstable.676006d08e",
|
|
22
|
+
"@webiny/api-headless-cms": "0.0.0-unstable.676006d08e",
|
|
23
|
+
"@webiny/api-kernel-core": "0.0.0-unstable.676006d08e",
|
|
24
|
+
"@webiny/background-tasks": "0.0.0-unstable.676006d08e",
|
|
25
|
+
"@webiny/feature": "0.0.0-unstable.676006d08e",
|
|
26
|
+
"@webiny/handler": "0.0.0-unstable.676006d08e",
|
|
27
|
+
"@webiny/utils": "0.0.0-unstable.676006d08e"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
|
-
"@webiny/api": "0.0.0-unstable.
|
|
30
|
-
"@webiny/api-core": "0.0.0-unstable.
|
|
31
|
-
"@webiny/api-graphql": "0.0.0-unstable.
|
|
32
|
-
"@webiny/api-headless-cms-testing": "0.0.0-unstable.
|
|
33
|
-
"@webiny/build-tools": "0.0.0-unstable.
|
|
30
|
+
"@webiny/api": "0.0.0-unstable.676006d08e",
|
|
31
|
+
"@webiny/api-core": "0.0.0-unstable.676006d08e",
|
|
32
|
+
"@webiny/api-graphql": "0.0.0-unstable.676006d08e",
|
|
33
|
+
"@webiny/api-headless-cms-testing": "0.0.0-unstable.676006d08e",
|
|
34
|
+
"@webiny/build-tools": "0.0.0-unstable.676006d08e",
|
|
34
35
|
"@webiny/di": "2.0.0",
|
|
35
|
-
"@webiny/plugins": "0.0.0-unstable.
|
|
36
|
-
"@webiny/wcp": "0.0.0-unstable.
|
|
37
|
-
"graphql": "16.
|
|
36
|
+
"@webiny/plugins": "0.0.0-unstable.676006d08e",
|
|
37
|
+
"@webiny/wcp": "0.0.0-unstable.676006d08e",
|
|
38
|
+
"graphql": "16.15.0",
|
|
38
39
|
"typescript": "7.0.2",
|
|
39
|
-
"vitest": "
|
|
40
|
+
"vitest": "5.1.1"
|
|
40
41
|
},
|
|
41
42
|
"publishConfig": {
|
|
42
43
|
"access": "public"
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
import type { IEmptyTrashBinsInput, IEmptyTrashBinsOutput } from "../types.js";
|
|
2
2
|
import { TaskDefinition, TaskHandler } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
3
3
|
import { ListTenantsUseCase } from "@webiny/api-core/features/tenancy/ListTenants/index.js";
|
|
4
|
-
import {
|
|
5
|
-
import { ListModelsUseCase } from "@webiny/api-headless-cms/features/contentModel/ListModels/index.js";
|
|
6
|
-
import { DeleteEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js";
|
|
7
|
-
import { ListDeletedEntriesUseCase } from "@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js";
|
|
4
|
+
import { TenantScopes } from "@webiny/api-core/features/tenancy/TenantScopes/index.js";
|
|
8
5
|
declare class EmptyTrashBinTaskHandlerImpl implements TaskHandler.Interface<IEmptyTrashBinsInput, IEmptyTrashBinsOutput> {
|
|
9
|
-
private
|
|
6
|
+
private tenantScopes;
|
|
10
7
|
private listTenants;
|
|
11
|
-
|
|
12
|
-
private listDeletedEntries;
|
|
13
|
-
private deleteEntry;
|
|
14
|
-
constructor(tenantContext: TenantContext.Interface, listTenants: ListTenantsUseCase.Interface, listModels: ListModelsUseCase.Interface, listDeletedEntries: ListDeletedEntriesUseCase.Interface, deleteEntry: DeleteEntryUseCase.Interface);
|
|
8
|
+
constructor(tenantScopes: TenantScopes.Interface, listTenants: ListTenantsUseCase.Interface);
|
|
15
9
|
run(params: TaskHandler.RunParams<IEmptyTrashBinsInput, IEmptyTrashBinsOutput>): Promise<TaskDefinition.Result<IEmptyTrashBinsInput, IEmptyTrashBinsOutput>>;
|
|
16
10
|
}
|
|
17
11
|
declare class EmptyTrashBinTask implements TaskDefinition.Interface {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TaskDefinition, TaskHandler } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
2
2
|
import { ListTenantsUseCase } from "@webiny/api-core/features/tenancy/ListTenants/index.js";
|
|
3
|
-
import {
|
|
3
|
+
import { TenantScopes } from "@webiny/api-core/features/tenancy/TenantScopes/index.js";
|
|
4
4
|
import { ListModelsUseCase } from "@webiny/api-headless-cms/features/contentModel/ListModels/index.js";
|
|
5
5
|
import { DeleteEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js";
|
|
6
6
|
import { ListDeletedEntriesUseCase } from "@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js";
|
|
@@ -12,62 +12,73 @@ const calculateDateTimeString = ()=>{
|
|
|
12
12
|
return currentDate.toISOString();
|
|
13
13
|
};
|
|
14
14
|
class EmptyTrashBinTaskHandlerImpl {
|
|
15
|
-
constructor(
|
|
16
|
-
this.
|
|
15
|
+
constructor(tenantScopes, listTenants){
|
|
16
|
+
this.tenantScopes = tenantScopes;
|
|
17
17
|
this.listTenants = listTenants;
|
|
18
|
-
this.listModels = listModels;
|
|
19
|
-
this.listDeletedEntries = listDeletedEntries;
|
|
20
|
-
this.deleteEntry = deleteEntry;
|
|
21
18
|
}
|
|
22
19
|
async run(params) {
|
|
23
20
|
const { input, controller } = params;
|
|
24
21
|
if (controller.runtime.isAborted()) return controller.response.aborted();
|
|
25
22
|
const tenantsResult = await this.listTenants.execute();
|
|
23
|
+
if (tenantsResult.isFail()) return controller.response.error(tenantsResult.error);
|
|
26
24
|
const baseTenants = tenantsResult.value;
|
|
27
25
|
const executedTenantIds = input.executedTenantIds || [];
|
|
28
26
|
const tenants = baseTenants.filter((tenant)=>!executedTenantIds.includes(tenant.id));
|
|
29
27
|
let shouldTaskContinue = false;
|
|
30
|
-
|
|
28
|
+
for (const tenant of tenants){
|
|
31
29
|
if (controller.runtime.isCloseToTimeout()) {
|
|
32
30
|
shouldTaskContinue = true;
|
|
33
|
-
|
|
31
|
+
break;
|
|
34
32
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
33
|
+
await this.tenantScopes.withTenant(tenant, async (scope)=>{
|
|
34
|
+
const listModels = scope.resolve(ListModelsUseCase);
|
|
35
|
+
const listDeletedEntries = scope.resolve(ListDeletedEntriesUseCase);
|
|
36
|
+
const deleteEntry = scope.resolve(DeleteEntryUseCase);
|
|
37
|
+
const modelsResult = await listModels.execute({
|
|
38
|
+
includePrivate: false
|
|
39
|
+
});
|
|
40
|
+
if (modelsResult.isFail()) return void await controller.logger.error({
|
|
41
|
+
message: `Failed to list models for tenant "${tenant.id}".`,
|
|
42
|
+
error: modelsResult.error
|
|
43
|
+
});
|
|
44
|
+
const models = modelsResult.value;
|
|
45
|
+
for (const model of models){
|
|
46
|
+
const listEntriesParams = {
|
|
47
|
+
where: {
|
|
48
|
+
deletedOn_lt: calculateDateTimeString()
|
|
49
|
+
},
|
|
50
|
+
limit: 50
|
|
51
|
+
};
|
|
52
|
+
while(true){
|
|
53
|
+
const listResult = await listDeletedEntries.execute(model, listEntriesParams);
|
|
54
|
+
if (listResult.isFail()) {
|
|
55
|
+
await controller.logger.error({
|
|
56
|
+
message: `Failed to list deleted entries of model "${model.modelId}".`,
|
|
57
|
+
error: listResult.error
|
|
58
|
+
});
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
const { entries, meta } = listResult.value;
|
|
62
|
+
if (0 === meta.totalCount) break;
|
|
59
63
|
if (controller.runtime.isCloseToTimeout()) {
|
|
60
64
|
shouldTaskContinue = true;
|
|
61
65
|
break;
|
|
62
66
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
67
|
+
for (const entry of entries){
|
|
68
|
+
if (controller.runtime.isCloseToTimeout()) {
|
|
69
|
+
shouldTaskContinue = true;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
await deleteEntry.execute(model, entry.id, {
|
|
73
|
+
permanently: true
|
|
74
|
+
});
|
|
75
|
+
}
|
|
66
76
|
}
|
|
67
77
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
78
|
+
if (!shouldTaskContinue) executedTenantIds.push(tenant.id);
|
|
79
|
+
});
|
|
80
|
+
if (shouldTaskContinue) break;
|
|
81
|
+
}
|
|
71
82
|
return shouldTaskContinue ? controller.response.continue({
|
|
72
83
|
...input,
|
|
73
84
|
executedTenantIds
|
|
@@ -77,11 +88,8 @@ class EmptyTrashBinTaskHandlerImpl {
|
|
|
77
88
|
const EmptyTrashBinTaskHandler = TaskHandler.createImplementation({
|
|
78
89
|
implementation: EmptyTrashBinTaskHandlerImpl,
|
|
79
90
|
dependencies: [
|
|
80
|
-
|
|
81
|
-
ListTenantsUseCase
|
|
82
|
-
ListModelsUseCase,
|
|
83
|
-
ListDeletedEntriesUseCase,
|
|
84
|
-
DeleteEntryUseCase
|
|
91
|
+
TenantScopes,
|
|
92
|
+
ListTenantsUseCase
|
|
85
93
|
]
|
|
86
94
|
});
|
|
87
95
|
class EmptyTrashBinTask {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tasks/EmptyTrashBinTask.js","sources":["../../src/tasks/EmptyTrashBinTask.ts"],"sourcesContent":["import type { IEmptyTrashBinsInput, IEmptyTrashBinsOutput } from \"~/types.js\";\nimport {\n TaskDefinition,\n TaskHandler\n} from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { ListTenantsUseCase } from \"@webiny/api-core/features/tenancy/ListTenants/index.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { ListModelsUseCase } from \"@webiny/api-headless-cms/features/contentModel/ListModels/index.js\";\nimport { DeleteEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js\";\nimport { ListDeletedEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js\";\n\nconst calculateDateTimeString = () => {\n // Retrieve the retention period from the environment variable WEBINY_TRASH_BIN_RETENTION_PERIOD_DAYS,\n // or default to 90 days if not set or set to 0.\n const retentionPeriodFromEnv = process.env[\"WEBINY_TRASH_BIN_RETENTION_PERIOD_DAYS\"];\n const retentionPeriod =\n retentionPeriodFromEnv && Number(retentionPeriodFromEnv) !== 0\n ? Number(retentionPeriodFromEnv)\n : 90;\n\n // Calculate the date-time by subtracting the retention period (in days) from the current date.\n const currentDate = new Date();\n currentDate.setDate(currentDate.getDate() - retentionPeriod);\n\n // Return the calculated date-time string in ISO 8601 format.\n return currentDate.toISOString();\n};\n\nclass EmptyTrashBinTaskHandlerImpl implements TaskHandler.Interface<\n IEmptyTrashBinsInput,\n IEmptyTrashBinsOutput\n> {\n constructor(\n private tenantContext: TenantContext.Interface,\n private listTenants: ListTenantsUseCase.Interface,\n private listModels: ListModelsUseCase.Interface,\n private listDeletedEntries: ListDeletedEntriesUseCase.Interface,\n private deleteEntry: DeleteEntryUseCase.Interface\n ) {}\n\n async run(\n params: TaskHandler.RunParams<IEmptyTrashBinsInput, IEmptyTrashBinsOutput>\n ): Promise<TaskDefinition.Result<IEmptyTrashBinsInput, IEmptyTrashBinsOutput>> {\n const { input, controller } = params;\n\n // Abort the task if needed.\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n }\n\n // Fetch all tenants, excluding those already processed.\n const tenantsResult = await this.listTenants.execute();\n const baseTenants = tenantsResult.value;\n const executedTenantIds = input.executedTenantIds || [];\n const tenants = baseTenants.filter(tenant => !executedTenantIds.includes(tenant.id));\n\n let shouldTaskContinue = false;\n\n // Iterate over each tenant.\n await this.tenantContext.withEachTenant(tenants, async tenant => {\n if (controller.runtime.isCloseToTimeout()) {\n shouldTaskContinue = true;\n return;\n }\n\n if (controller.runtime.isCloseToTimeout()) {\n shouldTaskContinue = true;\n return;\n }\n\n // List all non-private models.\n const modelsResult = await this.listModels.execute({ includePrivate: false });\n const models = modelsResult.value;\n\n // Process each model to delete trashed entries.\n for (const model of models) {\n // Query parameters for fetching deleted entries older than a minute ago.\n const listEntriesParams = {\n where: {\n deletedOn_lt: calculateDateTimeString()\n },\n limit: 50\n };\n\n // Continue deleting entries while there are entries left to delete.\n while (true) {\n const listResult = await this.listDeletedEntries.execute(\n model,\n listEntriesParams\n );\n const { entries, meta } = listResult.value;\n\n if (meta.totalCount === 0) {\n break;\n }\n\n if (controller.runtime.isCloseToTimeout()) {\n shouldTaskContinue = true;\n break;\n }\n for (const entry of entries) {\n if (controller.runtime.isCloseToTimeout()) {\n shouldTaskContinue = true;\n break;\n }\n // Delete each entry individually.\n await this.deleteEntry.execute(model, entry.id, { permanently: true });\n }\n }\n }\n\n // If the task isn't continuing, add the tenant to the executed list.\n if (!shouldTaskContinue) {\n executedTenantIds.push(tenant.id);\n }\n });\n\n // Continue the task or mark it as done based on the `shouldContinue` flag.\n return shouldTaskContinue\n ? controller.response.continue({ ...input, executedTenantIds })\n : controller.response.done(\n \"Task done: emptied the trash bin for all registered models.\"\n );\n }\n}\n\nconst EmptyTrashBinTaskHandler = TaskHandler.createImplementation({\n implementation: EmptyTrashBinTaskHandlerImpl,\n dependencies: [\n TenantContext,\n ListTenantsUseCase,\n ListModelsUseCase,\n ListDeletedEntriesUseCase,\n DeleteEntryUseCase\n ]\n});\n\nclass EmptyTrashBinTask implements TaskDefinition.Interface {\n public readonly isPrivate = true;\n public readonly id = \"hcmsEntriesEmptyTrashBins\";\n public readonly title = \"Headless CMS - Empty all trash bins\";\n public readonly description =\n \"Delete all entries in the trash bin for each model in the system.\";\n public readonly maxIterations = 120;\n public readonly databaseLogs = false;\n\n public readonly selfCleanup = [\"onSuccess\" as const, \"onAbort\" as const];\n\n handler = EmptyTrashBinTaskHandler;\n}\n\nexport const EmptyTrashBinTaskDefinition = TaskDefinition.createImplementation({\n implementation: EmptyTrashBinTask,\n dependencies: []\n});\n"],"names":["calculateDateTimeString","retentionPeriodFromEnv","process","retentionPeriod","Number","currentDate","Date","EmptyTrashBinTaskHandlerImpl","tenantContext","listTenants","listModels","listDeletedEntries","deleteEntry","params","input","controller","tenantsResult","baseTenants","executedTenantIds","tenants","tenant","shouldTaskContinue","modelsResult","models","model","listEntriesParams","listResult","entries","meta","entry","EmptyTrashBinTaskHandler","TaskHandler","TenantContext","ListTenantsUseCase","ListModelsUseCase","ListDeletedEntriesUseCase","DeleteEntryUseCase","EmptyTrashBinTask","EmptyTrashBinTaskDefinition","TaskDefinition"],"mappings":";;;;;;AAWA,MAAMA,0BAA0B;IAG5B,MAAMC,yBAAyBC,QAAQ,GAAG,CAAC,yCAAyC;IACpF,MAAMC,kBACFF,0BAA0BG,AAAmC,MAAnCA,OAAOH,0BAC3BG,OAAOH,0BACP;IAGV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DF,OACAC;oBAEJ,MAAM,EAAEE,OAAO,EAAEC,IAAI,EAAE,GAAGF,WAAW,KAAK;oBAE1C,IAAIE,AAAoB,MAApBA,KAAK,UAAU,EACf;oBAGJ,IAAIb,WAAW,OAAO,CAAC,gBAAgB,IAAI;wBACvCM,qBAAqB;wBACrB;oBACJ;oBACA,KAAK,MAAMQ,SAASF,QAAS;wBACzB,IAAIZ,WAAW,OAAO,CAAC,gBAAgB,IAAI;4BACvCM,qBAAqB;4BACrB;wBACJ;wBAEA,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAACG,OAAOK,MAAM,EAAE,EAAE;4BAAE,aAAa;wBAAK;oBACxE;gBACJ;YACJ;YAGA,IAAI,CAACR,oBACDH,kBAAkB,IAAI,CAACE,OAAO,EAAE;QAExC;QAGA,OAAOC,qBACDN,WAAW,QAAQ,CAAC,QAAQ,CAAC;YAAE,GAAGD,KAAK;YAAEI;QAAkB,KAC3DH,WAAW,QAAQ,CAAC,IAAI,CACpB;IAEd;AACJ;AAEA,MAAMe,2BAA2BC,YAAY,oBAAoB,CAAC;IAC9D,gBAAgBxB;IAChB,cAAc;QACVyB;QACAC;QACAC;QACAC;QACAC;KACH;AACL;AAEA,MAAMC;;aACc,SAAS,GAAG;aACZ,EAAE,GAAG;aACL,KAAK,GAAG;aACR,WAAW,GACvB;aACY,aAAa,GAAG;aAChB,YAAY,GAAG;aAEf,WAAW,GAAG;YAAC;YAAsB;SAAmB;aAExE,OAAO,GAAGP;;AACd;AAEO,MAAMQ,8BAA8BC,eAAe,oBAAoB,CAAC;IAC3E,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
|
|
1
|
+
{"version":3,"file":"tasks/EmptyTrashBinTask.js","sources":["../../src/tasks/EmptyTrashBinTask.ts"],"sourcesContent":["import type { IEmptyTrashBinsInput, IEmptyTrashBinsOutput } from \"~/types.js\";\nimport {\n TaskDefinition,\n TaskHandler\n} from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { ListTenantsUseCase } from \"@webiny/api-core/features/tenancy/ListTenants/index.js\";\nimport { TenantScopes } from \"@webiny/api-core/features/tenancy/TenantScopes/index.js\";\nimport { ListModelsUseCase } from \"@webiny/api-headless-cms/features/contentModel/ListModels/index.js\";\nimport { DeleteEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js\";\nimport { ListDeletedEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js\";\n\nconst calculateDateTimeString = () => {\n // Retrieve the retention period from the environment variable WEBINY_TRASH_BIN_RETENTION_PERIOD_DAYS,\n // or default to 90 days if not set or set to 0.\n const retentionPeriodFromEnv = process.env[\"WEBINY_TRASH_BIN_RETENTION_PERIOD_DAYS\"];\n const retentionPeriod =\n retentionPeriodFromEnv && Number(retentionPeriodFromEnv) !== 0\n ? Number(retentionPeriodFromEnv)\n : 90;\n\n // Calculate the date-time by subtracting the retention period (in days) from the current date.\n const currentDate = new Date();\n currentDate.setDate(currentDate.getDate() - retentionPeriod);\n\n // Return the calculated date-time string in ISO 8601 format.\n return currentDate.toISOString();\n};\n\nclass EmptyTrashBinTaskHandlerImpl implements TaskHandler.Interface<\n IEmptyTrashBinsInput,\n IEmptyTrashBinsOutput\n> {\n constructor(\n private tenantScopes: TenantScopes.Interface,\n private listTenants: ListTenantsUseCase.Interface\n ) {}\n\n async run(\n params: TaskHandler.RunParams<IEmptyTrashBinsInput, IEmptyTrashBinsOutput>\n ): Promise<TaskDefinition.Result<IEmptyTrashBinsInput, IEmptyTrashBinsOutput>> {\n const { input, controller } = params;\n\n // Abort the task if needed.\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n }\n\n // Fetch all tenants, excluding those already processed.\n const tenantsResult = await this.listTenants.execute();\n if (tenantsResult.isFail()) {\n return controller.response.error(tenantsResult.error);\n }\n const baseTenants = tenantsResult.value;\n const executedTenantIds = input.executedTenantIds || [];\n const tenants = baseTenants.filter(tenant => !executedTenantIds.includes(tenant.id));\n\n let shouldTaskContinue = false;\n\n // Iterate over each tenant, in its scope: its models and entries are in its storage. The\n // timeout is checked before entering a scope, so no scope is built once time is up.\n for (const tenant of tenants) {\n if (controller.runtime.isCloseToTimeout()) {\n shouldTaskContinue = true;\n break;\n }\n\n await this.tenantScopes.withTenant(tenant, async scope => {\n const listModels = scope.resolve(ListModelsUseCase);\n const listDeletedEntries = scope.resolve(ListDeletedEntriesUseCase);\n const deleteEntry = scope.resolve(DeleteEntryUseCase);\n\n // List all non-private models.\n const modelsResult = await listModels.execute({ includePrivate: false });\n if (modelsResult.isFail()) {\n await controller.logger.error({\n message: `Failed to list models for tenant \"${tenant.id}\".`,\n error: modelsResult.error\n });\n return;\n }\n const models = modelsResult.value;\n\n // Process each model to delete trashed entries.\n for (const model of models) {\n // Query parameters for fetching deleted entries older than a minute ago.\n const listEntriesParams = {\n where: {\n deletedOn_lt: calculateDateTimeString()\n },\n limit: 50\n };\n\n // Continue deleting entries while there are entries left to delete.\n while (true) {\n const listResult = await listDeletedEntries.execute(\n model,\n listEntriesParams\n );\n if (listResult.isFail()) {\n await controller.logger.error({\n message: `Failed to list deleted entries of model \"${model.modelId}\".`,\n error: listResult.error\n });\n break;\n }\n const { entries, meta } = listResult.value;\n\n if (meta.totalCount === 0) {\n break;\n }\n\n if (controller.runtime.isCloseToTimeout()) {\n shouldTaskContinue = true;\n break;\n }\n for (const entry of entries) {\n if (controller.runtime.isCloseToTimeout()) {\n shouldTaskContinue = true;\n break;\n }\n // Delete each entry individually.\n await deleteEntry.execute(model, entry.id, { permanently: true });\n }\n }\n }\n\n // If the task isn't continuing, add the tenant to the executed list.\n if (!shouldTaskContinue) {\n executedTenantIds.push(tenant.id);\n }\n });\n\n if (shouldTaskContinue) {\n break;\n }\n }\n\n // Continue the task or mark it as done based on the `shouldContinue` flag.\n return shouldTaskContinue\n ? controller.response.continue({ ...input, executedTenantIds })\n : controller.response.done(\n \"Task done: emptied the trash bin for all registered models.\"\n );\n }\n}\n\nconst EmptyTrashBinTaskHandler = TaskHandler.createImplementation({\n implementation: EmptyTrashBinTaskHandlerImpl,\n dependencies: [TenantScopes, ListTenantsUseCase]\n});\n\nclass EmptyTrashBinTask implements TaskDefinition.Interface {\n public readonly isPrivate = true;\n public readonly id = \"hcmsEntriesEmptyTrashBins\";\n public readonly title = \"Headless CMS - Empty all trash bins\";\n public readonly description =\n \"Delete all entries in the trash bin for each model in the system.\";\n public readonly maxIterations = 120;\n public readonly databaseLogs = false;\n\n public readonly selfCleanup = [\"onSuccess\" as const, \"onAbort\" as const];\n\n handler = EmptyTrashBinTaskHandler;\n}\n\nexport const EmptyTrashBinTaskDefinition = TaskDefinition.createImplementation({\n implementation: EmptyTrashBinTask,\n dependencies: []\n});\n"],"names":["calculateDateTimeString","retentionPeriodFromEnv","process","retentionPeriod","Number","currentDate","Date","EmptyTrashBinTaskHandlerImpl","tenantScopes","listTenants","params","input","controller","tenantsResult","baseTenants","executedTenantIds","tenants","tenant","shouldTaskContinue","scope","listModels","ListModelsUseCase","listDeletedEntries","ListDeletedEntriesUseCase","deleteEntry","DeleteEntryUseCase","modelsResult","models","model","listEntriesParams","listResult","entries","meta","entry","EmptyTrashBinTaskHandler","TaskHandler","TenantScopes","ListTenantsUseCase","EmptyTrashBinTask","EmptyTrashBinTaskDefinition","TaskDefinition"],"mappings":";;;;;;AAWA,MAAMA,0BAA0B;IAG5B,MAAMC,yBAAyBC,QAAQ,GAAG,CAAC,yCAAyC;IACpF,MAAMC,kBACFF,0BAA0BG,AAAmC,MAAnCA,OAAOH,0BAC3BG,OAAOH,0BACP;IAGV,MAAMI,cAAc,IAAIC;IACxBD,YAAY,OAAO,CAACA,YAAY,OAAO,KAAKF;IAG5C,OAAOE,YAAY,WAAW;AAClC;AAEA,MAAME;IAIF,YACYC,YAAoC,EACpCC,WAAyC,CACnD;aAFUD,YAAY,GAAZA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,IACFC,MAA0E,EACC;QAC3E,MAAM,EAAEC,KAAK,EAAEC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src/types.ts"],"sourcesContent":["import type { CmsContext } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { Context as BaseContext } from \"@webiny/handler/types.js\";\nimport type { ITaskIdentity } from \"@webiny/background-tasks/api/types.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\n\nexport interface HcmsBulkActionsContext extends BaseContext, CmsContext {}\n\n/**\n * Bulk Action Operation\n */\n\nexport interface IBulkActionOperationInput {\n actionName: string;\n modelId: string;\n ids: string[];\n data?: Record<string, any>;\n identity: ITaskIdentity;\n done?: string[];\n failed?: string[];\n}\n\nexport interface IBulkActionOperationOutput {\n done: string[];\n failed: string[];\n}\n\nexport type IBulkActionOperationTaskParams = TaskDefinition.RunParams<\n IBulkActionOperationInput,\n IBulkActionOperationOutput\n>;\n\n/**\n * Bulk Action Operation By Model\n */\n\nexport enum BulkActionOperationByModelAction {\n CREATE_SUBTASKS = \"CREATE_SUBTASKS\",\n CHECK_MORE_SUBTASKS = \"CHECK_MORE_SUBTASKS\",\n PROCESS_SUBTASKS = \"PROCESS_SUBTASKS\",\n END_TASK = \"END_TASK\"\n}\n\nexport interface IBulkActionOperationByModelInput {\n actionName: string;\n modelId: string;\n identity?: ITaskIdentity;\n where?: Record<string, any>;\n search?: string;\n after?: string | null;\n data?: Record<string, any>;\n action?: BulkActionOperationByModelAction;\n}\n\nexport interface IBulkActionOperationByModelOutput {\n done: string[];\n failed: string[];\n}\n\nexport type IBulkActionOperationByModelTaskParams = TaskDefinition.RunParams<\n IBulkActionOperationByModelInput,\n IBulkActionOperationByModelOutput\n>;\n\n/**\n * Empty Trash Bin\n */\n\nexport interface IEmptyTrashBinsInput {\n executedTenantIds?: string[] | null;\n}\n\nexport type IEmptyTrashBinsOutput = TaskDefinition.ResultDone;\n\nexport type IEmptyTrashBinsTaskParams = TaskDefinition.RunParams<\n IEmptyTrashBinsInput,\n IEmptyTrashBinsOutput\n>;\n"],"names":["BulkActionOperationByModelAction"],"mappings":"AAmCO,IAAKA,yCAAgCA,WAAAA,GAAAA,
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../src/types.ts"],"sourcesContent":["import type { CmsContext } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { Context as BaseContext } from \"@webiny/handler/types.js\";\nimport type { ITaskIdentity } from \"@webiny/background-tasks/api/types.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\n\nexport interface HcmsBulkActionsContext extends BaseContext, CmsContext {}\n\n/**\n * Bulk Action Operation\n */\n\nexport interface IBulkActionOperationInput {\n actionName: string;\n modelId: string;\n ids: string[];\n data?: Record<string, any>;\n identity: ITaskIdentity;\n done?: string[];\n failed?: string[];\n}\n\nexport interface IBulkActionOperationOutput {\n done: string[];\n failed: string[];\n}\n\nexport type IBulkActionOperationTaskParams = TaskDefinition.RunParams<\n IBulkActionOperationInput,\n IBulkActionOperationOutput\n>;\n\n/**\n * Bulk Action Operation By Model\n */\n\nexport enum BulkActionOperationByModelAction {\n CREATE_SUBTASKS = \"CREATE_SUBTASKS\",\n CHECK_MORE_SUBTASKS = \"CHECK_MORE_SUBTASKS\",\n PROCESS_SUBTASKS = \"PROCESS_SUBTASKS\",\n END_TASK = \"END_TASK\"\n}\n\nexport interface IBulkActionOperationByModelInput {\n actionName: string;\n modelId: string;\n identity?: ITaskIdentity;\n where?: Record<string, any>;\n search?: string;\n after?: string | null;\n data?: Record<string, any>;\n action?: BulkActionOperationByModelAction;\n}\n\nexport interface IBulkActionOperationByModelOutput {\n done: string[];\n failed: string[];\n}\n\nexport type IBulkActionOperationByModelTaskParams = TaskDefinition.RunParams<\n IBulkActionOperationByModelInput,\n IBulkActionOperationByModelOutput\n>;\n\n/**\n * Empty Trash Bin\n */\n\nexport interface IEmptyTrashBinsInput {\n executedTenantIds?: string[] | null;\n}\n\nexport type IEmptyTrashBinsOutput = TaskDefinition.ResultDone;\n\nexport type IEmptyTrashBinsTaskParams = TaskDefinition.RunParams<\n IEmptyTrashBinsInput,\n IEmptyTrashBinsOutput\n>;\n"],"names":["BulkActionOperationByModelAction"],"mappings":"AAmCO,IAAKA,yCAAgCA,WAAAA,GAAAA,SAAAA,gCAAAA"}
|