@webiny/api-headless-cms-bulk-actions 5.41.0-dbt.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +15 -0
- package/abstractions/IListEntries.d.ts +7 -0
- package/abstractions/IListEntries.js +7 -0
- package/abstractions/IListEntries.js.map +1 -0
- package/abstractions/IProcessEntry.d.ts +4 -0
- package/abstractions/IProcessEntry.js +7 -0
- package/abstractions/IProcessEntry.js.map +1 -0
- package/abstractions/IUseCase.d.ts +3 -0
- package/abstractions/IUseCase.js +7 -0
- package/abstractions/IUseCase.js.map +1 -0
- package/abstractions/index.d.ts +3 -0
- package/abstractions/index.js +40 -0
- package/abstractions/index.js.map +1 -0
- package/handlers/eventBridgeEventHandler.d.ts +1 -0
- package/handlers/eventBridgeEventHandler.js +49 -0
- package/handlers/eventBridgeEventHandler.js.map +1 -0
- package/handlers/index.d.ts +1 -0
- package/handlers/index.js +14 -0
- package/handlers/index.js.map +1 -0
- package/handlers/setupEventsTenant.d.ts +1 -0
- package/handlers/setupEventsTenant.js +19 -0
- package/handlers/setupEventsTenant.js.map +1 -0
- package/index.d.ts +4 -0
- package/index.js +51 -0
- package/index.js.map +1 -0
- package/package.json +52 -0
- package/plugins/createBulkAction.d.ts +9 -0
- package/plugins/createBulkAction.js +35 -0
- package/plugins/createBulkAction.js.map +1 -0
- package/plugins/createBulkActionGraphQL.d.ts +7 -0
- package/plugins/createBulkActionGraphQL.js +56 -0
- package/plugins/createBulkActionGraphQL.js.map +1 -0
- package/plugins/createBulkActionTasks.d.ts +8 -0
- package/plugins/createBulkActionTasks.js +108 -0
- package/plugins/createBulkActionTasks.js.map +1 -0
- package/plugins/createDefaultGraphQL.d.ts +3 -0
- package/plugins/createDefaultGraphQL.js +57 -0
- package/plugins/createDefaultGraphQL.js.map +1 -0
- package/plugins/index.d.ts +2 -0
- package/plugins/index.js +29 -0
- package/plugins/index.js.map +1 -0
- package/tasks/createBulkActionEntriesTasks.d.ts +1 -0
- package/tasks/createBulkActionEntriesTasks.js +38 -0
- package/tasks/createBulkActionEntriesTasks.js.map +1 -0
- package/tasks/createEmptyTrashBinsTask.d.ts +2 -0
- package/tasks/createEmptyTrashBinsTask.js +84 -0
- package/tasks/createEmptyTrashBinsTask.js.map +1 -0
- package/tasks/index.d.ts +1 -0
- package/tasks/index.js +14 -0
- package/tasks/index.js.map +1 -0
- package/types.d.ts +41 -0
- package/types.js +7 -0
- package/types.js.map +1 -0
- package/useCases/DeleteEntry.d.ts +10 -0
- package/useCases/DeleteEntry.js +26 -0
- package/useCases/DeleteEntry.js.map +1 -0
- package/useCases/ListDeletedEntries.d.ts +13 -0
- package/useCases/ListDeletedEntries.js +28 -0
- package/useCases/ListDeletedEntries.js.map +1 -0
- package/useCases/ListLatestEntries.d.ts +13 -0
- package/useCases/ListLatestEntries.js +28 -0
- package/useCases/ListLatestEntries.js.map +1 -0
- package/useCases/ListPublishedEntries.d.ts +13 -0
- package/useCases/ListPublishedEntries.js +28 -0
- package/useCases/ListPublishedEntries.js.map +1 -0
- package/useCases/MoveEntryToFolder.d.ts +13 -0
- package/useCases/MoveEntryToFolder.js +23 -0
- package/useCases/MoveEntryToFolder.js.map +1 -0
- package/useCases/MoveEntryToTrash.d.ts +10 -0
- package/useCases/MoveEntryToTrash.js +26 -0
- package/useCases/MoveEntryToTrash.js.map +1 -0
- package/useCases/PublishEntry.d.ts +10 -0
- package/useCases/PublishEntry.js +20 -0
- package/useCases/PublishEntry.js.map +1 -0
- package/useCases/RestoreEntryFromTrash.d.ts +10 -0
- package/useCases/RestoreEntryFromTrash.js +24 -0
- package/useCases/RestoreEntryFromTrash.js.map +1 -0
- package/useCases/UnpublishEntry.d.ts +10 -0
- package/useCases/UnpublishEntry.js +20 -0
- package/useCases/UnpublishEntry.js.map +1 -0
- package/useCases/index.d.ts +9 -0
- package/useCases/index.js +106 -0
- package/useCases/index.js.map +1 -0
- package/useCases/internals/ChildTaskCleanup/ChildTasksCleanup.d.ts +13 -0
- package/useCases/internals/ChildTaskCleanup/ChildTasksCleanup.js +63 -0
- package/useCases/internals/ChildTaskCleanup/ChildTasksCleanup.js.map +1 -0
- package/useCases/internals/ChildTaskCleanup/index.d.ts +1 -0
- package/useCases/internals/ChildTaskCleanup/index.js +18 -0
- package/useCases/internals/ChildTaskCleanup/index.js.map +1 -0
- package/useCases/internals/CreateTasksByModel/CreateTasksByModel.d.ts +12 -0
- package/useCases/internals/CreateTasksByModel/CreateTasksByModel.js +107 -0
- package/useCases/internals/CreateTasksByModel/CreateTasksByModel.js.map +1 -0
- package/useCases/internals/CreateTasksByModel/TaskCache.d.ts +31 -0
- package/useCases/internals/CreateTasksByModel/TaskCache.js +68 -0
- package/useCases/internals/CreateTasksByModel/TaskCache.js.map +1 -0
- package/useCases/internals/CreateTasksByModel/index.d.ts +1 -0
- package/useCases/internals/CreateTasksByModel/index.js +18 -0
- package/useCases/internals/CreateTasksByModel/index.js.map +1 -0
- package/useCases/internals/ProcessTask/ProcessTask.d.ts +14 -0
- package/useCases/internals/ProcessTask/ProcessTask.js +92 -0
- package/useCases/internals/ProcessTask/ProcessTask.js.map +1 -0
- package/useCases/internals/ProcessTask/Result.d.ts +9 -0
- package/useCases/internals/ProcessTask/Result.js +29 -0
- package/useCases/internals/ProcessTask/Result.js.map +1 -0
- package/useCases/internals/ProcessTask/index.d.ts +1 -0
- package/useCases/internals/ProcessTask/index.js +18 -0
- package/useCases/internals/ProcessTask/index.js.map +1 -0
- package/useCases/internals/ProcessTasksByModel/ProcessTasksByModel.d.ts +11 -0
- package/useCases/internals/ProcessTasksByModel/ProcessTasksByModel.js +61 -0
- package/useCases/internals/ProcessTasksByModel/ProcessTasksByModel.js.map +1 -0
- package/useCases/internals/ProcessTasksByModel/index.d.ts +1 -0
- package/useCases/internals/ProcessTasksByModel/index.js +18 -0
- package/useCases/internals/ProcessTasksByModel/index.js.map +1 -0
- package/useCases/internals/index.d.ts +4 -0
- package/useCases/internals/index.js +51 -0
- package/useCases/internals/index.js.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @webiny/api-headless-cms-bulk-actions
|
|
2
|
+
[](https://www.npmjs.com/package/@webinyapi-headless-cms-bulk-actions)
|
|
3
|
+
[](https://www.npmjs.com/package/@webiny/api-headless-cms-bulk-actions)
|
|
4
|
+
[](https://github.com/prettier/prettier)
|
|
5
|
+
[](http://makeapullrequest.com)
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
```
|
|
9
|
+
npm install --save @webiny/api-headless-cms-bulk-actions
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Or if you prefer yarn:
|
|
13
|
+
```
|
|
14
|
+
yarn add @webiny/api-headless-cms-bulk-actions
|
|
15
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["IListEntries.ts"],"sourcesContent":["import { CmsEntry, CmsEntryListParams, CmsEntryMeta } from \"@webiny/api-headless-cms/types\";\n\nexport interface IListEntries {\n execute: (\n modelId: string,\n params: CmsEntryListParams\n ) => Promise<{ entries: CmsEntry[]; meta: CmsEntryMeta }>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["IProcessEntry.ts"],"sourcesContent":["import { CmsModel } from \"@webiny/api-headless-cms/types\";\n\nexport interface IProcessEntry {\n execute: (model: CmsModel, id: string, data?: any) => Promise<void>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["IUseCase.ts"],"sourcesContent":["export interface IUseCase<TInput, TOutput> {\n execute(params: TInput): Promise<TOutput>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _IListEntries = require("./IListEntries");
|
|
7
|
+
Object.keys(_IListEntries).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _IListEntries[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _IListEntries[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _IProcessEntry = require("./IProcessEntry");
|
|
18
|
+
Object.keys(_IProcessEntry).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _IProcessEntry[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _IProcessEntry[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _IUseCase = require("./IUseCase");
|
|
29
|
+
Object.keys(_IUseCase).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _IUseCase[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _IUseCase[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_IListEntries","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_IProcessEntry","_IUseCase"],"sources":["index.ts"],"sourcesContent":["export * from \"./IListEntries\";\nexport * from \"./IProcessEntry\";\nexport * from \"./IUseCase\";\n"],"mappings":";;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,aAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,aAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,aAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,cAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,cAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,cAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,cAAA,CAAAL,GAAA;IAAA;EAAA;AAAA;AACA,IAAAM,SAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,SAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,SAAA,CAAAN,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAE,SAAA,CAAAN,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createEventBridgeHandler: () => import("@webiny/handler-aws").EventBridgeEventHandler<"WebinyEmptyTrashBin", Record<string, any>, any>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createEventBridgeHandler = void 0;
|
|
7
|
+
var _handlerAws = require("@webiny/handler-aws");
|
|
8
|
+
const DETAIL_TYPE = "WebinyEmptyTrashBin";
|
|
9
|
+
const createEventBridgeHandler = () => {
|
|
10
|
+
return (0, _handlerAws.createEventBridgeEventHandler)(async ({
|
|
11
|
+
context: ctx,
|
|
12
|
+
payload
|
|
13
|
+
}) => {
|
|
14
|
+
try {
|
|
15
|
+
/**
|
|
16
|
+
* If we receive an event that is not "WebinyEmptyTrashBin", we should exit.
|
|
17
|
+
*/
|
|
18
|
+
if (payload["detail-type"] !== DETAIL_TYPE) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const context = ctx;
|
|
22
|
+
if (!context.tasks || !context.tenancy) {
|
|
23
|
+
console.error("Missing tasks or tenancy definition on context.");
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Since the event is at the infrastructure level, it has no knowledge about tenancy.
|
|
29
|
+
* We loop through all tenants in the system and trigger the "EmptyTrashBins" task.
|
|
30
|
+
*/
|
|
31
|
+
const tenants = await context.tenancy.listTenants();
|
|
32
|
+
await context.tenancy.withEachTenant(tenants, async () => {
|
|
33
|
+
await context.tasks.trigger({
|
|
34
|
+
definition: "hcmsEntriesEmptyTrashBins"
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
return;
|
|
38
|
+
} catch (ex) {
|
|
39
|
+
console.error("[EVENT_BRIDGE_HANDLER_EMPTY_TRASH_BIN] => ", JSON.stringify({
|
|
40
|
+
message: ex.message,
|
|
41
|
+
code: ex.code,
|
|
42
|
+
data: ex.data
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
exports.createEventBridgeHandler = createEventBridgeHandler;
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=eventBridgeEventHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_handlerAws","require","DETAIL_TYPE","createEventBridgeHandler","createEventBridgeEventHandler","context","ctx","payload","tasks","tenancy","console","error","tenants","listTenants","withEachTenant","trigger","definition","ex","JSON","stringify","message","code","data","exports"],"sources":["eventBridgeEventHandler.ts"],"sourcesContent":["import { createEventBridgeEventHandler } from \"@webiny/handler-aws\";\nimport { HcmsBulkActionsContext } from \"~/types\";\n\nconst DETAIL_TYPE = \"WebinyEmptyTrashBin\";\n\nexport const createEventBridgeHandler = () => {\n return createEventBridgeEventHandler<typeof DETAIL_TYPE, Record<string, any>>(\n async ({ context: ctx, payload }) => {\n try {\n /**\n * If we receive an event that is not \"WebinyEmptyTrashBin\", we should exit.\n */\n if (payload[\"detail-type\"] !== DETAIL_TYPE) {\n return;\n }\n\n const context = ctx as unknown as HcmsBulkActionsContext;\n\n if (!context.tasks || !context.tenancy) {\n console.error(\"Missing tasks or tenancy definition on context.\");\n return;\n }\n\n /**\n * Since the event is at the infrastructure level, it has no knowledge about tenancy.\n * We loop through all tenants in the system and trigger the \"EmptyTrashBins\" task.\n */\n const tenants = await context.tenancy.listTenants();\n await context.tenancy.withEachTenant(tenants, async () => {\n await context.tasks.trigger({\n definition: \"hcmsEntriesEmptyTrashBins\"\n });\n });\n\n return;\n } catch (ex) {\n console.error(\n \"[EVENT_BRIDGE_HANDLER_EMPTY_TRASH_BIN] => \",\n JSON.stringify({\n message: ex.message,\n code: ex.code,\n data: ex.data\n })\n );\n }\n }\n );\n};\n"],"mappings":";;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAGA,MAAMC,WAAW,GAAG,qBAAqB;AAElC,MAAMC,wBAAwB,GAAGA,CAAA,KAAM;EAC1C,OAAO,IAAAC,yCAA6B,EAChC,OAAO;IAAEC,OAAO,EAAEC,GAAG;IAAEC;EAAQ,CAAC,KAAK;IACjC,IAAI;MACA;AAChB;AACA;MACgB,IAAIA,OAAO,CAAC,aAAa,CAAC,KAAKL,WAAW,EAAE;QACxC;MACJ;MAEA,MAAMG,OAAO,GAAGC,GAAwC;MAExD,IAAI,CAACD,OAAO,CAACG,KAAK,IAAI,CAACH,OAAO,CAACI,OAAO,EAAE;QACpCC,OAAO,CAACC,KAAK,CAAC,iDAAiD,CAAC;QAChE;MACJ;;MAEA;AAChB;AACA;AACA;MACgB,MAAMC,OAAO,GAAG,MAAMP,OAAO,CAACI,OAAO,CAACI,WAAW,CAAC,CAAC;MACnD,MAAMR,OAAO,CAACI,OAAO,CAACK,cAAc,CAACF,OAAO,EAAE,YAAY;QACtD,MAAMP,OAAO,CAACG,KAAK,CAACO,OAAO,CAAC;UACxBC,UAAU,EAAE;QAChB,CAAC,CAAC;MACN,CAAC,CAAC;MAEF;IACJ,CAAC,CAAC,OAAOC,EAAE,EAAE;MACTP,OAAO,CAACC,KAAK,CACT,4CAA4C,EAC5CO,IAAI,CAACC,SAAS,CAAC;QACXC,OAAO,EAAEH,EAAE,CAACG,OAAO;QACnBC,IAAI,EAAEJ,EAAE,CAACI,IAAI;QACbC,IAAI,EAAEL,EAAE,CAACK;MACb,CAAC,CACL,CAAC;IACL;EACJ,CACJ,CAAC;AACL,CAAC;AAACC,OAAA,CAAApB,wBAAA,GAAAA,wBAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createHandlers: () => (import("@webiny/handler").HandlerOnRequestPlugin | import("@webiny/handler-aws").EventBridgeEventHandler<"WebinyEmptyTrashBin", Record<string, any>, any>)[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createHandlers = void 0;
|
|
7
|
+
var _eventBridgeEventHandler = require("./eventBridgeEventHandler");
|
|
8
|
+
var _setupEventsTenant = require("./setupEventsTenant");
|
|
9
|
+
const createHandlers = () => {
|
|
10
|
+
return [(0, _setupEventsTenant.setupEventsTenant)(), (0, _eventBridgeEventHandler.createEventBridgeHandler)()];
|
|
11
|
+
};
|
|
12
|
+
exports.createHandlers = createHandlers;
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_eventBridgeEventHandler","require","_setupEventsTenant","createHandlers","setupEventsTenant","createEventBridgeHandler","exports"],"sources":["index.ts"],"sourcesContent":["import { createEventBridgeHandler } from \"./eventBridgeEventHandler\";\nimport { setupEventsTenant } from \"./setupEventsTenant\";\n\nexport const createHandlers = () => {\n return [setupEventsTenant(), createEventBridgeHandler()];\n};\n"],"mappings":";;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AACA,IAAAC,kBAAA,GAAAD,OAAA;AAEO,MAAME,cAAc,GAAGA,CAAA,KAAM;EAChC,OAAO,CAAC,IAAAC,oCAAiB,EAAC,CAAC,EAAE,IAAAC,iDAAwB,EAAC,CAAC,CAAC;AAC5D,CAAC;AAACC,OAAA,CAAAH,cAAA,GAAAA,cAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const setupEventsTenant: () => import("@webiny/handler").HandlerOnRequestPlugin;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.setupEventsTenant = void 0;
|
|
7
|
+
var _handler = require("@webiny/handler");
|
|
8
|
+
const setupEventsTenant = () => {
|
|
9
|
+
return (0, _handler.createHandlerOnRequest)(async request => {
|
|
10
|
+
request.headers = {
|
|
11
|
+
...request.headers,
|
|
12
|
+
"x-tenant": request.headers["x-tenant"] || "root"
|
|
13
|
+
};
|
|
14
|
+
return;
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
exports.setupEventsTenant = setupEventsTenant;
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=setupEventsTenant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_handler","require","setupEventsTenant","createHandlerOnRequest","request","headers","exports"],"sources":["setupEventsTenant.ts"],"sourcesContent":["import { createHandlerOnRequest } from \"@webiny/handler\";\n\nexport const setupEventsTenant = () => {\n return createHandlerOnRequest(async request => {\n request.headers = {\n ...request.headers,\n \"x-tenant\": request.headers[\"x-tenant\"] || \"root\"\n };\n\n return;\n });\n};\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAEO,MAAMC,iBAAiB,GAAGA,CAAA,KAAM;EACnC,OAAO,IAAAC,+BAAsB,EAAC,MAAMC,OAAO,IAAI;IAC3CA,OAAO,CAACC,OAAO,GAAG;MACd,GAAGD,OAAO,CAACC,OAAO;MAClB,UAAU,EAAED,OAAO,CAACC,OAAO,CAAC,UAAU,CAAC,IAAI;IAC/C,CAAC;IAED;EACJ,CAAC,CAAC;AACN,CAAC;AAACC,OAAA,CAAAJ,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export * from "./abstractions";
|
|
2
|
+
export * from "./useCases";
|
|
3
|
+
export * from "./plugins";
|
|
4
|
+
export declare const createHcmsBulkActions: () => (import("@webiny/api").ContextPlugin<import("./types").HcmsBulkActionsContext> | ((import("@webiny/api").ContextPlugin<import("./types").HcmsBulkActionsContext> | (import("@webiny/tasks").TaskDefinitionPlugin<import("./types").HcmsBulkActionsContext, import("./types").IBulkActionOperationByModelInput, import("./types").IBulkActionOperationByModelOutput> | import("@webiny/tasks").TaskDefinitionPlugin<import("./types").HcmsBulkActionsContext, import("./types").IBulkActionOperationInput, import("./types").IBulkActionOperationOutput>)[])[][] | import("@webiny/tasks").TaskDefinitionPlugin<import("./types").HcmsBulkActionsContext, any, import("@webiny/tasks").ITaskResponseDoneResultOutput>)[] | (import("@webiny/handler").HandlerOnRequestPlugin | import("@webiny/handler-aws").EventBridgeEventHandler<"WebinyEmptyTrashBin", Record<string, any>, any>)[])[];
|
package/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
createHcmsBulkActions: true
|
|
8
|
+
};
|
|
9
|
+
exports.createHcmsBulkActions = void 0;
|
|
10
|
+
var _tasks = require("./tasks");
|
|
11
|
+
var _handlers = require("./handlers");
|
|
12
|
+
var _plugins = require("./plugins");
|
|
13
|
+
Object.keys(_plugins).forEach(function (key) {
|
|
14
|
+
if (key === "default" || key === "__esModule") return;
|
|
15
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
16
|
+
if (key in exports && exports[key] === _plugins[key]) return;
|
|
17
|
+
Object.defineProperty(exports, key, {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () {
|
|
20
|
+
return _plugins[key];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
var _abstractions = require("./abstractions");
|
|
25
|
+
Object.keys(_abstractions).forEach(function (key) {
|
|
26
|
+
if (key === "default" || key === "__esModule") return;
|
|
27
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
28
|
+
if (key in exports && exports[key] === _abstractions[key]) return;
|
|
29
|
+
Object.defineProperty(exports, key, {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function () {
|
|
32
|
+
return _abstractions[key];
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
var _useCases = require("./useCases");
|
|
37
|
+
Object.keys(_useCases).forEach(function (key) {
|
|
38
|
+
if (key === "default" || key === "__esModule") return;
|
|
39
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
40
|
+
if (key in exports && exports[key] === _useCases[key]) return;
|
|
41
|
+
Object.defineProperty(exports, key, {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: function () {
|
|
44
|
+
return _useCases[key];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
const createHcmsBulkActions = () => [(0, _tasks.createTasks)(), (0, _handlers.createHandlers)(), (0, _plugins.createDefaultGraphQL)()];
|
|
49
|
+
exports.createHcmsBulkActions = createHcmsBulkActions;
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_tasks","require","_handlers","_plugins","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_abstractions","_useCases","createHcmsBulkActions","createTasks","createHandlers","createDefaultGraphQL"],"sources":["index.ts"],"sourcesContent":["import { createTasks } from \"~/tasks\";\nimport { createHandlers } from \"~/handlers\";\nimport { createDefaultGraphQL } from \"~/plugins\";\n\nexport * from \"./abstractions\";\nexport * from \"./useCases\";\nexport * from \"./plugins\";\n\nexport const createHcmsBulkActions = () => [\n createTasks(),\n createHandlers(),\n createDefaultGraphQL()\n];\n"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAIAG,MAAA,CAAAC,IAAA,CAAAF,QAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,QAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,QAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AAFA,IAAAS,aAAA,GAAAf,OAAA;AAAAG,MAAA,CAAAC,IAAA,CAAAW,aAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAS,aAAA,CAAAT,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,aAAA,CAAAT,GAAA;IAAA;EAAA;AAAA;AACA,IAAAU,SAAA,GAAAhB,OAAA;AAAAG,MAAA,CAAAC,IAAA,CAAAY,SAAA,EAAAX,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAU,SAAA,CAAAV,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAE,SAAA,CAAAV,GAAA;IAAA;EAAA;AAAA;AAGO,MAAMW,qBAAqB,GAAGA,CAAA,KAAM,CACvC,IAAAC,kBAAW,EAAC,CAAC,EACb,IAAAC,wBAAc,EAAC,CAAC,EAChB,IAAAC,6BAAoB,EAAC,CAAC,CACzB;AAACT,OAAA,CAAAM,qBAAA,GAAAA,qBAAA","ignoreList":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/api-headless-cms-bulk-actions",
|
|
3
|
+
"version": "5.41.0-dbt.0",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"description": "Webiny Headless CMS bulk actions",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"api-headless-cms-bulk-actions:base"
|
|
8
|
+
],
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/webiny/webiny-js.git",
|
|
12
|
+
"directory": "packages/api-headless-cms-bulk-actions"
|
|
13
|
+
},
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@webiny/api-headless-cms": "5.41.0-dbt.0",
|
|
17
|
+
"@webiny/handler": "5.41.0-dbt.0",
|
|
18
|
+
"@webiny/handler-aws": "5.41.0-dbt.0",
|
|
19
|
+
"@webiny/tasks": "5.41.0-dbt.0",
|
|
20
|
+
"@webiny/utils": "5.41.0-dbt.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@babel/cli": "7.24.1",
|
|
24
|
+
"@babel/core": "7.24.3",
|
|
25
|
+
"@babel/preset-env": "7.24.3",
|
|
26
|
+
"@babel/preset-typescript": "7.24.1",
|
|
27
|
+
"@babel/runtime": "7.24.1",
|
|
28
|
+
"@webiny/api": "5.41.0-dbt.0",
|
|
29
|
+
"@webiny/api-admin-users": "5.41.0-dbt.0",
|
|
30
|
+
"@webiny/api-i18n": "5.41.0-dbt.0",
|
|
31
|
+
"@webiny/api-security": "5.41.0-dbt.0",
|
|
32
|
+
"@webiny/api-tenancy": "5.41.0-dbt.0",
|
|
33
|
+
"@webiny/api-wcp": "5.41.0-dbt.0",
|
|
34
|
+
"@webiny/cli": "5.41.0-dbt.0",
|
|
35
|
+
"@webiny/handler-graphql": "5.41.0-dbt.0",
|
|
36
|
+
"@webiny/plugins": "5.41.0-dbt.0",
|
|
37
|
+
"@webiny/project-utils": "5.41.0-dbt.0",
|
|
38
|
+
"@webiny/wcp": "5.41.0-dbt.0",
|
|
39
|
+
"graphql": "15.8.0",
|
|
40
|
+
"ttypescript": "1.5.15",
|
|
41
|
+
"typescript": "4.9.5"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "yarn webiny run build",
|
|
45
|
+
"watch": "yarn webiny run watch"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public",
|
|
49
|
+
"directory": "dist"
|
|
50
|
+
},
|
|
51
|
+
"gitHead": "bbaec4dd1685579548c08bbde386aee5d96b80f8"
|
|
52
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IListEntries, IProcessEntry } from "../abstractions";
|
|
2
|
+
import { HcmsBulkActionsContext } from "../types";
|
|
3
|
+
export interface CreateBulkActionConfig {
|
|
4
|
+
name: string;
|
|
5
|
+
dataLoader: (context: HcmsBulkActionsContext) => IListEntries;
|
|
6
|
+
dataProcessor: (context: HcmsBulkActionsContext) => IProcessEntry;
|
|
7
|
+
modelIds?: string[];
|
|
8
|
+
}
|
|
9
|
+
export declare const createBulkAction: (config: CreateBulkActionConfig) => (import("@webiny/api").ContextPlugin<HcmsBulkActionsContext> | (import("@webiny/tasks").TaskDefinitionPlugin<HcmsBulkActionsContext, import("../types").IBulkActionOperationByModelInput, import("../types").IBulkActionOperationByModelOutput> | import("@webiny/tasks").TaskDefinitionPlugin<HcmsBulkActionsContext, import("../types").IBulkActionOperationInput, import("../types").IBulkActionOperationOutput>)[])[];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createBulkAction = void 0;
|
|
7
|
+
var _createBulkActionGraphQL = require("./createBulkActionGraphQL");
|
|
8
|
+
var _createBulkActionTasks = require("./createBulkActionTasks");
|
|
9
|
+
function toPascalCase(str) {
|
|
10
|
+
// Step 1: Remove non-alphanumeric characters and replace them with spaces
|
|
11
|
+
str = str.replace(/[^a-zA-Z0-9]+/g, " ");
|
|
12
|
+
|
|
13
|
+
// Step 2: Split the string into words
|
|
14
|
+
const words = str.split(" ");
|
|
15
|
+
|
|
16
|
+
// Step 3: Capitalize the first letter of each word
|
|
17
|
+
const capitalizedWords = words.map(word => word.charAt(0).toUpperCase() + word.slice(1));
|
|
18
|
+
|
|
19
|
+
// Step 4: Join all the capitalized words together
|
|
20
|
+
return capitalizedWords.join("");
|
|
21
|
+
}
|
|
22
|
+
const createBulkAction = config => {
|
|
23
|
+
const name = toPascalCase(config.name);
|
|
24
|
+
return [(0, _createBulkActionTasks.createBulkActionTasks)({
|
|
25
|
+
name,
|
|
26
|
+
dataLoader: config.dataLoader,
|
|
27
|
+
dataProcessor: config.dataProcessor
|
|
28
|
+
}), (0, _createBulkActionGraphQL.createBulkActionGraphQL)({
|
|
29
|
+
name,
|
|
30
|
+
modelIds: config.modelIds
|
|
31
|
+
})];
|
|
32
|
+
};
|
|
33
|
+
exports.createBulkAction = createBulkAction;
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=createBulkAction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_createBulkActionGraphQL","require","_createBulkActionTasks","toPascalCase","str","replace","words","split","capitalizedWords","map","word","charAt","toUpperCase","slice","join","createBulkAction","config","name","createBulkActionTasks","dataLoader","dataProcessor","createBulkActionGraphQL","modelIds","exports"],"sources":["createBulkAction.ts"],"sourcesContent":["import { createBulkActionGraphQL } from \"./createBulkActionGraphQL\";\nimport { createBulkActionTasks } from \"~/plugins/createBulkActionTasks\";\nimport { IListEntries, IProcessEntry } from \"~/abstractions\";\nimport { HcmsBulkActionsContext } from \"~/types\";\n\nexport interface CreateBulkActionConfig {\n name: string;\n dataLoader: (context: HcmsBulkActionsContext) => IListEntries;\n dataProcessor: (context: HcmsBulkActionsContext) => IProcessEntry;\n modelIds?: string[];\n}\n\nfunction toPascalCase(str: string) {\n // Step 1: Remove non-alphanumeric characters and replace them with spaces\n str = str.replace(/[^a-zA-Z0-9]+/g, \" \");\n\n // Step 2: Split the string into words\n const words = str.split(\" \");\n\n // Step 3: Capitalize the first letter of each word\n const capitalizedWords = words.map(word => word.charAt(0).toUpperCase() + word.slice(1));\n\n // Step 4: Join all the capitalized words together\n return capitalizedWords.join(\"\");\n}\n\nexport const createBulkAction = (config: CreateBulkActionConfig) => {\n const name = toPascalCase(config.name);\n\n return [\n createBulkActionTasks({\n name,\n dataLoader: config.dataLoader,\n dataProcessor: config.dataProcessor\n }),\n createBulkActionGraphQL({\n name,\n modelIds: config.modelIds\n })\n ];\n};\n"],"mappings":";;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AACA,IAAAC,sBAAA,GAAAD,OAAA;AAWA,SAASE,YAAYA,CAACC,GAAW,EAAE;EAC/B;EACAA,GAAG,GAAGA,GAAG,CAACC,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC;;EAExC;EACA,MAAMC,KAAK,GAAGF,GAAG,CAACG,KAAK,CAAC,GAAG,CAAC;;EAE5B;EACA,MAAMC,gBAAgB,GAAGF,KAAK,CAACG,GAAG,CAACC,IAAI,IAAIA,IAAI,CAACC,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC,GAAGF,IAAI,CAACG,KAAK,CAAC,CAAC,CAAC,CAAC;;EAExF;EACA,OAAOL,gBAAgB,CAACM,IAAI,CAAC,EAAE,CAAC;AACpC;AAEO,MAAMC,gBAAgB,GAAIC,MAA8B,IAAK;EAChE,MAAMC,IAAI,GAAGd,YAAY,CAACa,MAAM,CAACC,IAAI,CAAC;EAEtC,OAAO,CACH,IAAAC,4CAAqB,EAAC;IAClBD,IAAI;IACJE,UAAU,EAAEH,MAAM,CAACG,UAAU;IAC7BC,aAAa,EAAEJ,MAAM,CAACI;EAC1B,CAAC,CAAC,EACF,IAAAC,gDAAuB,EAAC;IACpBJ,IAAI;IACJK,QAAQ,EAAEN,MAAM,CAACM;EACrB,CAAC,CAAC,CACL;AACL,CAAC;AAACC,OAAA,CAAAR,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ContextPlugin } from "@webiny/api";
|
|
2
|
+
import { HcmsBulkActionsContext } from "../types";
|
|
3
|
+
export interface CreateBulkActionGraphQL {
|
|
4
|
+
name: string;
|
|
5
|
+
modelIds?: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare const createBulkActionGraphQL: (config: CreateBulkActionGraphQL) => ContextPlugin<HcmsBulkActionsContext>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createBulkActionGraphQL = void 0;
|
|
7
|
+
var _api = require("@webiny/api");
|
|
8
|
+
var _apiHeadlessCms = require("@webiny/api-headless-cms");
|
|
9
|
+
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
10
|
+
const createBulkActionGraphQL = config => {
|
|
11
|
+
return new _api.ContextPlugin(async context => {
|
|
12
|
+
if (!(await (0, _apiHeadlessCms.isHeadlessCmsReady)(context))) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const models = await context.security.withoutAuthorization(async () => {
|
|
16
|
+
const allModels = await context.cms.listModels();
|
|
17
|
+
return allModels.filter(model => !model.isPrivate && (!config.modelIds?.length || config.modelIds.includes(model.modelId)));
|
|
18
|
+
});
|
|
19
|
+
const plugins = [];
|
|
20
|
+
models.forEach(model => {
|
|
21
|
+
const plugin = new _apiHeadlessCms.CmsGraphQLSchemaPlugin({
|
|
22
|
+
typeDefs: /* GraphQL */`
|
|
23
|
+
extend enum BulkAction${model.singularApiName}Name {
|
|
24
|
+
${config.name}
|
|
25
|
+
}
|
|
26
|
+
`,
|
|
27
|
+
resolvers: {
|
|
28
|
+
Mutation: {
|
|
29
|
+
[`bulkAction${model.singularApiName}`]: async (_, args) => {
|
|
30
|
+
const identity = context.security.getIdentity();
|
|
31
|
+
const response = await context.tasks.trigger({
|
|
32
|
+
definition: `hcmsBulkList${args.action}Entries`,
|
|
33
|
+
input: {
|
|
34
|
+
modelId: model.modelId,
|
|
35
|
+
where: args.where,
|
|
36
|
+
search: args.search,
|
|
37
|
+
data: args.data,
|
|
38
|
+
identity
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return new _handlerGraphql.Response({
|
|
42
|
+
id: response.id
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
plugin.name = `headless-cms.graphql.schema.bulkAction.${model.modelId}.${config.name}`;
|
|
49
|
+
plugins.push(plugin);
|
|
50
|
+
});
|
|
51
|
+
context.plugins.register([...plugins]);
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
exports.createBulkActionGraphQL = createBulkActionGraphQL;
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=createBulkActionGraphQL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_api","require","_apiHeadlessCms","_handlerGraphql","createBulkActionGraphQL","config","ContextPlugin","context","isHeadlessCmsReady","models","security","withoutAuthorization","allModels","cms","listModels","filter","model","isPrivate","modelIds","length","includes","modelId","plugins","forEach","plugin","CmsGraphQLSchemaPlugin","typeDefs","singularApiName","name","resolvers","Mutation","_","args","identity","getIdentity","response","tasks","trigger","definition","action","input","where","search","data","Response","id","push","register","exports"],"sources":["createBulkActionGraphQL.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport { HcmsBulkActionsContext } from \"~/types\";\nimport { CmsGraphQLSchemaPlugin, isHeadlessCmsReady } from \"@webiny/api-headless-cms\";\nimport { Response } from \"@webiny/handler-graphql\";\n\nexport interface CreateBulkActionGraphQL {\n name: string;\n modelIds?: string[];\n}\n\nexport const createBulkActionGraphQL = (config: CreateBulkActionGraphQL) => {\n return new ContextPlugin<HcmsBulkActionsContext>(async context => {\n if (!(await isHeadlessCmsReady(context))) {\n return;\n }\n\n const models = await context.security.withoutAuthorization(async () => {\n const allModels = await context.cms.listModels();\n return allModels.filter(\n model =>\n !model.isPrivate &&\n (!config.modelIds?.length || config.modelIds.includes(model.modelId))\n );\n });\n\n const plugins: CmsGraphQLSchemaPlugin<HcmsBulkActionsContext>[] = [];\n\n models.forEach(model => {\n const plugin = new CmsGraphQLSchemaPlugin({\n typeDefs: /* GraphQL */ `\n extend enum BulkAction${model.singularApiName}Name {\n ${config.name}\n }\n `,\n resolvers: {\n Mutation: {\n [`bulkAction${model.singularApiName}`]: async (_, args) => {\n const identity = context.security.getIdentity();\n\n const response = await context.tasks.trigger({\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.id\n });\n }\n }\n }\n });\n\n plugin.name = `headless-cms.graphql.schema.bulkAction.${model.modelId}.${config.name}`;\n plugins.push(plugin);\n });\n\n context.plugins.register([...plugins]);\n });\n};\n"],"mappings":";;;;;;AAAA,IAAAA,IAAA,GAAAC,OAAA;AAEA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AAOO,MAAMG,uBAAuB,GAAIC,MAA+B,IAAK;EACxE,OAAO,IAAIC,kBAAa,CAAyB,MAAMC,OAAO,IAAI;IAC9D,IAAI,EAAE,MAAM,IAAAC,kCAAkB,EAACD,OAAO,CAAC,CAAC,EAAE;MACtC;IACJ;IAEA,MAAME,MAAM,GAAG,MAAMF,OAAO,CAACG,QAAQ,CAACC,oBAAoB,CAAC,YAAY;MACnE,MAAMC,SAAS,GAAG,MAAML,OAAO,CAACM,GAAG,CAACC,UAAU,CAAC,CAAC;MAChD,OAAOF,SAAS,CAACG,MAAM,CACnBC,KAAK,IACD,CAACA,KAAK,CAACC,SAAS,KACf,CAACZ,MAAM,CAACa,QAAQ,EAAEC,MAAM,IAAId,MAAM,CAACa,QAAQ,CAACE,QAAQ,CAACJ,KAAK,CAACK,OAAO,CAAC,CAC5E,CAAC;IACL,CAAC,CAAC;IAEF,MAAMC,OAAyD,GAAG,EAAE;IAEpEb,MAAM,CAACc,OAAO,CAACP,KAAK,IAAI;MACpB,MAAMQ,MAAM,GAAG,IAAIC,sCAAsB,CAAC;QACtCC,QAAQ,EAAE,aAAe;AACzC,6CAA6CV,KAAK,CAACW,eAAgB;AACnE,0BAA0BtB,MAAM,CAACuB,IAAK;AACtC;AACA,iBAAiB;QACDC,SAAS,EAAE;UACPC,QAAQ,EAAE;YACN,CAAE,aAAYd,KAAK,CAACW,eAAgB,EAAC,GAAG,OAAOI,CAAC,EAAEC,IAAI,KAAK;cACvD,MAAMC,QAAQ,GAAG1B,OAAO,CAACG,QAAQ,CAACwB,WAAW,CAAC,CAAC;cAE/C,MAAMC,QAAQ,GAAG,MAAM5B,OAAO,CAAC6B,KAAK,CAACC,OAAO,CAAC;gBACzCC,UAAU,EAAG,eAAcN,IAAI,CAACO,MAAO,SAAQ;gBAC/CC,KAAK,EAAE;kBACHnB,OAAO,EAAEL,KAAK,CAACK,OAAO;kBACtBoB,KAAK,EAAET,IAAI,CAACS,KAAK;kBACjBC,MAAM,EAAEV,IAAI,CAACU,MAAM;kBACnBC,IAAI,EAAEX,IAAI,CAACW,IAAI;kBACfV;gBACJ;cACJ,CAAC,CAAC;cAEF,OAAO,IAAIW,wBAAQ,CAAC;gBAChBC,EAAE,EAAEV,QAAQ,CAACU;cACjB,CAAC,CAAC;YACN;UACJ;QACJ;MACJ,CAAC,CAAC;MAEFrB,MAAM,CAACI,IAAI,GAAI,0CAAyCZ,KAAK,CAACK,OAAQ,IAAGhB,MAAM,CAACuB,IAAK,EAAC;MACtFN,OAAO,CAACwB,IAAI,CAACtB,MAAM,CAAC;IACxB,CAAC,CAAC;IAEFjB,OAAO,CAACe,OAAO,CAACyB,QAAQ,CAAC,CAAC,GAAGzB,OAAO,CAAC,CAAC;EAC1C,CAAC,CAAC;AACN,CAAC;AAAC0B,OAAA,CAAA5C,uBAAA,GAAAA,uBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IListEntries, IProcessEntry } from "../abstractions";
|
|
2
|
+
import { HcmsBulkActionsContext, IBulkActionOperationByModelInput, IBulkActionOperationByModelOutput, IBulkActionOperationInput, IBulkActionOperationOutput } from "../types";
|
|
3
|
+
export interface CreateBackgroundTasksConfig {
|
|
4
|
+
name: string;
|
|
5
|
+
dataLoader: (context: HcmsBulkActionsContext) => IListEntries;
|
|
6
|
+
dataProcessor: (context: HcmsBulkActionsContext) => IProcessEntry;
|
|
7
|
+
}
|
|
8
|
+
export declare const createBulkActionTasks: (config: CreateBackgroundTasksConfig) => (import("@webiny/tasks").TaskDefinitionPlugin<HcmsBulkActionsContext, IBulkActionOperationByModelInput, IBulkActionOperationByModelOutput> | import("@webiny/tasks").TaskDefinitionPlugin<HcmsBulkActionsContext, IBulkActionOperationInput, IBulkActionOperationOutput>)[];
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createBulkActionTasks = void 0;
|
|
7
|
+
var _tasks = require("@webiny/tasks");
|
|
8
|
+
var _internals = require("../useCases/internals");
|
|
9
|
+
class BulkActionTasks {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.name = config.name;
|
|
12
|
+
this.dataLoader = config.dataLoader;
|
|
13
|
+
this.dataProcessor = config.dataProcessor;
|
|
14
|
+
}
|
|
15
|
+
createListTaskDefinition() {
|
|
16
|
+
return (0, _tasks.createPrivateTaskDefinition)({
|
|
17
|
+
id: this.createListTaskDefinitionName(),
|
|
18
|
+
title: `Headless CMS: list "${this.name}" entries by model`,
|
|
19
|
+
maxIterations: 500,
|
|
20
|
+
run: async params => {
|
|
21
|
+
const {
|
|
22
|
+
response,
|
|
23
|
+
input,
|
|
24
|
+
context
|
|
25
|
+
} = params;
|
|
26
|
+
try {
|
|
27
|
+
if (!input.modelId) {
|
|
28
|
+
return response.error(`Missing "modelId" in the input.`);
|
|
29
|
+
}
|
|
30
|
+
if (input.processing) {
|
|
31
|
+
const processTasks = new _internals.ProcessTasksByModel(this.createProcessTaskDefinitionName());
|
|
32
|
+
return await processTasks.execute(params);
|
|
33
|
+
}
|
|
34
|
+
const createTasks = new _internals.CreateTasksByModel(this.createProcessTaskDefinitionName(), this.dataLoader(context));
|
|
35
|
+
return await createTasks.execute(params);
|
|
36
|
+
} catch (ex) {
|
|
37
|
+
return response.error(ex.message ?? "Error while executing list task");
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
onDone: async ({
|
|
41
|
+
context,
|
|
42
|
+
task
|
|
43
|
+
}) => {
|
|
44
|
+
/**
|
|
45
|
+
* We want to clean all child tasks and logs, which have no errors.
|
|
46
|
+
*/
|
|
47
|
+
const childTasksCleanup = new _internals.ChildTasksCleanup();
|
|
48
|
+
try {
|
|
49
|
+
await childTasksCleanup.execute({
|
|
50
|
+
context,
|
|
51
|
+
task
|
|
52
|
+
});
|
|
53
|
+
} catch (ex) {
|
|
54
|
+
console.error("Error while cleaning list child tasks.", ex);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
createProcessTaskDefinition() {
|
|
60
|
+
return (0, _tasks.createPrivateTaskDefinition)({
|
|
61
|
+
id: this.createProcessTaskDefinitionName(),
|
|
62
|
+
title: `Headless CMS: process "${this.name}" entries`,
|
|
63
|
+
maxIterations: 2,
|
|
64
|
+
run: async params => {
|
|
65
|
+
const {
|
|
66
|
+
response,
|
|
67
|
+
context
|
|
68
|
+
} = params;
|
|
69
|
+
try {
|
|
70
|
+
const processTask = new _internals.ProcessTask(this.dataProcessor(context));
|
|
71
|
+
return await processTask.execute(params);
|
|
72
|
+
} catch (ex) {
|
|
73
|
+
return response.error(ex.message ?? "Error while executing process task");
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
onDone: async ({
|
|
77
|
+
context,
|
|
78
|
+
task
|
|
79
|
+
}) => {
|
|
80
|
+
/**
|
|
81
|
+
* We want to clean all child tasks and logs, which have no errors.
|
|
82
|
+
*/
|
|
83
|
+
const childTasksCleanup = new _internals.ChildTasksCleanup();
|
|
84
|
+
try {
|
|
85
|
+
await childTasksCleanup.execute({
|
|
86
|
+
context,
|
|
87
|
+
task
|
|
88
|
+
});
|
|
89
|
+
} catch (ex) {
|
|
90
|
+
console.error("Error while cleaning process child tasks.", ex);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
createListTaskDefinitionName() {
|
|
96
|
+
return `hcmsBulkList${this.name}Entries`;
|
|
97
|
+
}
|
|
98
|
+
createProcessTaskDefinitionName() {
|
|
99
|
+
return `hcmsBulkProcess${this.name}Entries`;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const createBulkActionTasks = config => {
|
|
103
|
+
const backgroundTasks = new BulkActionTasks(config);
|
|
104
|
+
return [backgroundTasks.createListTaskDefinition(), backgroundTasks.createProcessTaskDefinition()];
|
|
105
|
+
};
|
|
106
|
+
exports.createBulkActionTasks = createBulkActionTasks;
|
|
107
|
+
|
|
108
|
+
//# sourceMappingURL=createBulkActionTasks.js.map
|