@unchainedshop/plugins 1.2.50 → 1.2.52
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.
|
@@ -1,52 +1,37 @@
|
|
|
1
|
-
import { WorkerDirector } from '@unchainedshop/core-worker';
|
|
1
|
+
import { WorkerDirector, WorkerAdapter } from '@unchainedshop/core-worker';
|
|
2
2
|
import { createLogger } from '@unchainedshop/logger';
|
|
3
|
-
import { BaseAdapter } from '@unchainedshop/utils';
|
|
4
3
|
const logger = createLogger('unchained:platform:zombie-killer');
|
|
5
|
-
const findId = { projection: { _id: 1 } };
|
|
6
|
-
const findFileId = { projection: { mediaId: 1 } };
|
|
7
|
-
const mapId = (a) => a._id;
|
|
8
4
|
export const ZombieKillerWorker = {
|
|
9
|
-
...
|
|
5
|
+
...WorkerAdapter,
|
|
10
6
|
key: 'shop.unchained.worker-plugin.zombie-killer',
|
|
11
7
|
label: 'Zombie Killer',
|
|
12
|
-
version: '1.0',
|
|
8
|
+
version: '1.0.0',
|
|
13
9
|
type: 'ZOMBIE_KILLER',
|
|
14
10
|
doWork: async (_, unchainedAPI) => {
|
|
15
11
|
const { modules, services } = unchainedAPI;
|
|
16
12
|
try {
|
|
17
13
|
const error = false;
|
|
18
|
-
// Remove unreferenced product
|
|
19
|
-
const products = await modules.products.findProducts({},
|
|
14
|
+
// Remove unreferenced product entities
|
|
15
|
+
const products = await modules.products.findProducts({ includeDrafts: true }, { projection: { _id: 1 } });
|
|
16
|
+
const productIds = products.map((a) => a._id);
|
|
20
17
|
const deletedProductMediaCount = await modules.products.media.deleteMediaFiles({
|
|
21
|
-
excludedProductIds:
|
|
18
|
+
excludedProductIds: productIds,
|
|
22
19
|
});
|
|
23
|
-
// Remove unreferenced assortment
|
|
24
|
-
const assortments = await modules.assortments.findAssortments({},
|
|
20
|
+
// Remove unreferenced assortment entities
|
|
21
|
+
const assortments = await modules.assortments.findAssortments({ includeInactive: true, includeLeaves: true }, { projection: { _id: 1 } });
|
|
22
|
+
const assortmentIds = assortments.map((a) => a._id);
|
|
25
23
|
const deletedAssortmentMediaCount = await modules.assortments.media.deleteMediaFiles({
|
|
26
|
-
excludedAssortmentIds:
|
|
24
|
+
excludedAssortmentIds: assortmentIds,
|
|
27
25
|
});
|
|
28
26
|
// Remove unreferenced files
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
const filesWithAssortmentId = await modules.files.findFilesByMetaData({
|
|
38
|
-
meta: {
|
|
39
|
-
assortmentId: { $exists: true },
|
|
40
|
-
},
|
|
27
|
+
const productMedia = await modules.products.media.findProductMedias({}, { projection: { mediaId: 1 } });
|
|
28
|
+
const assortmentMedia = await modules.assortments.media.findAssortmentMedias({}, { projection: { mediaId: 1 } });
|
|
29
|
+
const allFileIdsLinked = [...productMedia, ...assortmentMedia].map((l) => l?.mediaId);
|
|
30
|
+
const allFileIdsRelevant = (await modules.files.findFiles({ path: { $in: ['product-media', 'assortment-media'] } })).map((a) => a._id);
|
|
31
|
+
const fileIdsToRemove = allFileIdsRelevant.filter((fileId) => {
|
|
32
|
+
return !allFileIdsLinked.includes(fileId);
|
|
41
33
|
});
|
|
42
|
-
|
|
43
|
-
.concat(filesWithAssortmentId)
|
|
44
|
-
.filter((file) => {
|
|
45
|
-
const fileInProductMedia = productMedia.some((media) => media.mediaId === file._id);
|
|
46
|
-
const fileInAssortmentMedia = assortmentMedia.some((media) => media.mediaId === file._id);
|
|
47
|
-
return !fileInProductMedia && !fileInAssortmentMedia;
|
|
48
|
-
})
|
|
49
|
-
.forEach((m) => fileIdsToRemove.push(m._id));
|
|
34
|
+
logger.verbose(`File Id's to remove: ${fileIdsToRemove.join(', ')}`);
|
|
50
35
|
const deletedFilesCount = fileIdsToRemove.length > 0
|
|
51
36
|
? await services.files.removeFiles({
|
|
52
37
|
fileIds: fileIdsToRemove,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ZombieKillerWorker.js","sourceRoot":"","sources":["../../src/worker/ZombieKillerWorker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"ZombieKillerWorker.js","sourceRoot":"","sources":["../../src/worker/ZombieKillerWorker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,MAAM,MAAM,GAAG,YAAY,CAAC,kCAAkC,CAAC,CAAC;AAEhE,MAAM,CAAC,MAAM,kBAAkB,GAO3B;IACF,GAAG,aAAa;IAEhB,GAAG,EAAE,4CAA4C;IACjD,KAAK,EAAE,eAAe;IACtB,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,eAAe;IAErB,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,YAAY,EAAE,EAAE;QAChC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,YAAY,CAAC;QAE3C,IAAI;YACF,MAAM,KAAK,GAAG,KAAK,CAAC;YAEpB,uCAAuC;YACvC,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,YAAY,CAClD,EAAE,aAAa,EAAE,IAAI,EAAE,EACvB,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAC3B,CAAC;YACF,MAAM,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YAC9C,MAAM,wBAAwB,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC;gBAC7E,kBAAkB,EAAE,UAAU;aAC/B,CAAC,CAAC;YAEH,0CAA0C;YAC1C,MAAM,WAAW,GAAG,MAAM,OAAO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C,QAAQ,CAAC,MAAM,CAAC,CAAC;YAC5C,CAAC,CAAC,CAAC;YAEH,MAAM,CAAC,OAAO,CAAC,wBAAwB,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAErE,MAAM,iBAAiB,GACrB,eAAe,CAAC,MAAM,GAAG,CAAC;gBACxB,CAAC,CAAC,MAAM,QAAQ,CAAC,KAAK,CAAC,WAAW,CAC9B;oBACE,OAAO,EAAE,eAAe;iBACzB,EACD,YAAY,CACb;gBACH,CAAC,CAAC,CAAC,CAAC;YAER,sBAAsB;YACtB,MAAM,MAAM,GAAG;gBACb,wBAAwB;gBACxB,2BAA2B;gBAC3B,iBAAiB;aAClB,CAAC;YAEF,IAAI,KAAK,EAAE;gBACT,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,MAAM;oBACN,KAAK;iBACN,CAAC;aACH;YACD,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,MAAM;aACP,CAAC;SACH;QAAC,OAAO,GAAG,EAAE;YACZ,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YAC/B,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE;oBACL,IAAI,EAAE,GAAG,CAAC,IAAI;oBACd,OAAO,EAAE,GAAG,CAAC,OAAO;oBACpB,KAAK,EAAE,GAAG,CAAC,KAAK;iBACjB;aACF,CAAC;SACH;IACH,CAAC;CACF,CAAC;AAEF,eAAe,kBAAkB,CAAC;AAElC,cAAc,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/plugins",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.52",
|
|
4
4
|
"main": "lib/plugins-index.js",
|
|
5
5
|
"types": "lib/plugins-index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -64,38 +64,38 @@
|
|
|
64
64
|
},
|
|
65
65
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@types/node": "^16.18.
|
|
68
|
-
"@unchainedshop/api": "^1.2.
|
|
67
|
+
"@types/node": "^16.18.10",
|
|
68
|
+
"@unchainedshop/api": "^1.2.52",
|
|
69
69
|
"@unchainedshop/client-oauth2": "^4.3.3",
|
|
70
|
-
"@unchainedshop/core-delivery": "^1.2.
|
|
71
|
-
"@unchainedshop/core-enrollments": "^1.2.
|
|
72
|
-
"@unchainedshop/core-filters": "^1.2.
|
|
73
|
-
"@unchainedshop/core-messaging": "^1.2.
|
|
74
|
-
"@unchainedshop/core-orders": "^1.2.
|
|
75
|
-
"@unchainedshop/core-payment": "^1.2.
|
|
76
|
-
"@unchainedshop/core-products": "^1.2.
|
|
77
|
-
"@unchainedshop/core-quotations": "^1.2.
|
|
78
|
-
"@unchainedshop/core-warehousing": "^1.2.
|
|
79
|
-
"@unchainedshop/core-worker": "^1.2.
|
|
80
|
-
"@unchainedshop/events": "^1.2.
|
|
81
|
-
"@unchainedshop/file-upload": "^1.2.
|
|
82
|
-
"@unchainedshop/logger": "^1.2.
|
|
83
|
-
"@unchainedshop/types": "^1.2.
|
|
84
|
-
"@unchainedshop/utils": "^1.2.
|
|
70
|
+
"@unchainedshop/core-delivery": "^1.2.52",
|
|
71
|
+
"@unchainedshop/core-enrollments": "^1.2.52",
|
|
72
|
+
"@unchainedshop/core-filters": "^1.2.52",
|
|
73
|
+
"@unchainedshop/core-messaging": "^1.2.52",
|
|
74
|
+
"@unchainedshop/core-orders": "^1.2.52",
|
|
75
|
+
"@unchainedshop/core-payment": "^1.2.52",
|
|
76
|
+
"@unchainedshop/core-products": "^1.2.52",
|
|
77
|
+
"@unchainedshop/core-quotations": "^1.2.52",
|
|
78
|
+
"@unchainedshop/core-warehousing": "^1.2.52",
|
|
79
|
+
"@unchainedshop/core-worker": "^1.2.52",
|
|
80
|
+
"@unchainedshop/events": "^1.2.52",
|
|
81
|
+
"@unchainedshop/file-upload": "^1.2.52",
|
|
82
|
+
"@unchainedshop/logger": "^1.2.52",
|
|
83
|
+
"@unchainedshop/types": "^1.2.52",
|
|
84
|
+
"@unchainedshop/utils": "^1.2.52",
|
|
85
85
|
"bluebird": "^3.7.2",
|
|
86
86
|
"body-parser": "^1.20.0",
|
|
87
87
|
"event-iterator": "^2.0.0",
|
|
88
88
|
"jest": "^29.3.1",
|
|
89
89
|
"JSONStream": "^1.3.5",
|
|
90
90
|
"minio": "^7.0.32",
|
|
91
|
-
"mongodb": "^4.
|
|
91
|
+
"mongodb": "^4.13.0",
|
|
92
92
|
"node-sheets": "^1.2.0",
|
|
93
93
|
"nodemailer": "^6.8.0",
|
|
94
94
|
"open": "^8.4.0",
|
|
95
95
|
"redis": "^4.5.1",
|
|
96
96
|
"request": "^2.88.2",
|
|
97
97
|
"ts-jest": "^29.0.3",
|
|
98
|
-
"typescript": "^4.9.
|
|
98
|
+
"typescript": "^4.9.4",
|
|
99
99
|
"xml-js": "^1.6.11",
|
|
100
100
|
"xml2js": "0.4.23"
|
|
101
101
|
}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import { IWorkerAdapter } from '@unchainedshop/types/worker';
|
|
2
|
-
import { WorkerDirector } from '@unchainedshop/core-worker';
|
|
2
|
+
import { WorkerDirector, WorkerAdapter } from '@unchainedshop/core-worker';
|
|
3
3
|
import { createLogger } from '@unchainedshop/logger';
|
|
4
|
-
import { BaseAdapter } from '@unchainedshop/utils';
|
|
5
4
|
|
|
6
5
|
const logger = createLogger('unchained:platform:zombie-killer');
|
|
7
6
|
|
|
8
|
-
const findId = { projection: { _id: 1 } };
|
|
9
|
-
const findFileId = { projection: { mediaId: 1 } };
|
|
10
|
-
const mapId = (a: any) => a._id;
|
|
11
|
-
|
|
12
7
|
export const ZombieKillerWorker: IWorkerAdapter<
|
|
13
8
|
never,
|
|
14
9
|
{
|
|
@@ -17,11 +12,11 @@ export const ZombieKillerWorker: IWorkerAdapter<
|
|
|
17
12
|
deletedFilesCount: number;
|
|
18
13
|
}
|
|
19
14
|
> = {
|
|
20
|
-
...
|
|
15
|
+
...WorkerAdapter,
|
|
21
16
|
|
|
22
17
|
key: 'shop.unchained.worker-plugin.zombie-killer',
|
|
23
18
|
label: 'Zombie Killer',
|
|
24
|
-
version: '1.0',
|
|
19
|
+
version: '1.0.0',
|
|
25
20
|
type: 'ZOMBIE_KILLER',
|
|
26
21
|
|
|
27
22
|
doWork: async (_, unchainedAPI) => {
|
|
@@ -30,42 +25,46 @@ export const ZombieKillerWorker: IWorkerAdapter<
|
|
|
30
25
|
try {
|
|
31
26
|
const error = false;
|
|
32
27
|
|
|
33
|
-
// Remove unreferenced product
|
|
34
|
-
const products = await modules.products.findProducts(
|
|
28
|
+
// Remove unreferenced product entities
|
|
29
|
+
const products = await modules.products.findProducts(
|
|
30
|
+
{ includeDrafts: true },
|
|
31
|
+
{ projection: { _id: 1 } },
|
|
32
|
+
);
|
|
33
|
+
const productIds = products.map((a) => a._id);
|
|
35
34
|
const deletedProductMediaCount = await modules.products.media.deleteMediaFiles({
|
|
36
|
-
excludedProductIds:
|
|
35
|
+
excludedProductIds: productIds,
|
|
37
36
|
});
|
|
38
37
|
|
|
39
|
-
// Remove unreferenced assortment
|
|
40
|
-
const assortments = await modules.assortments.findAssortments(
|
|
38
|
+
// Remove unreferenced assortment entities
|
|
39
|
+
const assortments = await modules.assortments.findAssortments(
|
|
40
|
+
{ includeInactive: true, includeLeaves: true },
|
|
41
|
+
{ projection: { _id: 1 } },
|
|
42
|
+
);
|
|
43
|
+
const assortmentIds = assortments.map((a) => a._id);
|
|
41
44
|
const deletedAssortmentMediaCount = await modules.assortments.media.deleteMediaFiles({
|
|
42
|
-
excludedAssortmentIds:
|
|
45
|
+
excludedAssortmentIds: assortmentIds,
|
|
43
46
|
});
|
|
44
47
|
|
|
45
48
|
// Remove unreferenced files
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
const productMedia = await modules.products.media.findProductMedias(
|
|
50
|
+
{},
|
|
51
|
+
{ projection: { mediaId: 1 } },
|
|
52
|
+
);
|
|
53
|
+
const assortmentMedia = await modules.assortments.media.findAssortmentMedias(
|
|
54
|
+
{},
|
|
55
|
+
{ projection: { mediaId: 1 } },
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
const allFileIdsLinked = [...productMedia, ...assortmentMedia].map((l) => l?.mediaId);
|
|
59
|
+
const allFileIdsRelevant = (
|
|
60
|
+
await modules.files.findFiles({ path: { $in: ['product-media', 'assortment-media'] } })
|
|
61
|
+
).map((a) => a._id);
|
|
62
|
+
|
|
63
|
+
const fileIdsToRemove = allFileIdsRelevant.filter((fileId) => {
|
|
64
|
+
return !allFileIdsLinked.includes(fileId);
|
|
59
65
|
});
|
|
60
66
|
|
|
61
|
-
|
|
62
|
-
.concat(filesWithAssortmentId)
|
|
63
|
-
.filter((file) => {
|
|
64
|
-
const fileInProductMedia = productMedia.some((media) => media.mediaId === file._id);
|
|
65
|
-
const fileInAssortmentMedia = assortmentMedia.some((media) => media.mediaId === file._id);
|
|
66
|
-
return !fileInProductMedia && !fileInAssortmentMedia;
|
|
67
|
-
})
|
|
68
|
-
.forEach((m) => fileIdsToRemove.push(m._id));
|
|
67
|
+
logger.verbose(`File Id's to remove: ${fileIdsToRemove.join(', ')}`);
|
|
69
68
|
|
|
70
69
|
const deletedFilesCount =
|
|
71
70
|
fileIdsToRemove.length > 0
|