@unchainedshop/plugins 5.0.0-alpha.2 → 5.0.0-alpha.3
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/lib/events/aws-eventbridge.d.ts +7 -1
- package/lib/events/aws-eventbridge.js +5 -11
- package/lib/events/redis.d.ts +3 -1
- package/lib/events/redis.js +5 -5
- package/lib/files/gridfs/api.js +1 -1
- package/lib/files/gridfs/handler-express.js +1 -1
- package/lib/payment/datatrans-v2/adapter.js +12 -9
- package/lib/payment/datatrans-v2/build3DSCardholder.d.ts +12 -0
- package/lib/payment/datatrans-v2/build3DSCardholder.js +44 -0
- package/lib/payment/paypal-checkout.js +17 -5
- package/lib/payment/stripe/stripe.js +1 -1
- package/lib/presets/base.js +4 -0
- package/lib/presets/countries/eu.d.ts +1 -0
- package/lib/presets/countries/eu.js +7 -0
- package/lib/presets/countries/uk.d.ts +1 -0
- package/lib/presets/countries/uk.js +7 -0
- package/lib/presets/countries/us.d.ts +1 -0
- package/lib/presets/countries/us.js +7 -0
- package/lib/pricing/delivery-eu-tax/adapter.d.ts +3 -0
- package/lib/pricing/delivery-eu-tax/adapter.js +55 -0
- package/lib/pricing/delivery-eu-tax/index.d.ts +4 -0
- package/lib/pricing/delivery-eu-tax/index.js +10 -0
- package/lib/pricing/delivery-eu-tax.d.ts +2 -0
- package/lib/pricing/delivery-eu-tax.js +55 -0
- package/lib/pricing/delivery-swiss-tax/adapter.js +7 -26
- package/lib/pricing/delivery-swiss-tax.js +7 -26
- package/lib/pricing/delivery-uk-tax/adapter.d.ts +3 -0
- package/lib/pricing/delivery-uk-tax/adapter.js +43 -0
- package/lib/pricing/delivery-uk-tax/index.d.ts +4 -0
- package/lib/pricing/delivery-uk-tax/index.js +10 -0
- package/lib/pricing/delivery-uk-tax.d.ts +2 -0
- package/lib/pricing/delivery-uk-tax.js +43 -0
- package/lib/pricing/delivery-us-sales-tax/adapter.d.ts +3 -0
- package/lib/pricing/delivery-us-sales-tax/adapter.js +58 -0
- package/lib/pricing/delivery-us-sales-tax/index.d.ts +4 -0
- package/lib/pricing/delivery-us-sales-tax/index.js +10 -0
- package/lib/pricing/delivery-us-sales-tax.d.ts +2 -0
- package/lib/pricing/delivery-us-sales-tax.js +58 -0
- package/lib/pricing/product-eu-tax/adapter.d.ts +3 -0
- package/lib/pricing/product-eu-tax/adapter.js +56 -0
- package/lib/pricing/product-eu-tax/index.d.ts +4 -0
- package/lib/pricing/product-eu-tax/index.js +10 -0
- package/lib/pricing/product-eu-tax.d.ts +2 -0
- package/lib/pricing/product-eu-tax.js +56 -0
- package/lib/pricing/product-quotation-price.d.ts +2 -0
- package/lib/pricing/product-quotation-price.js +40 -0
- package/lib/pricing/product-swiss-tax/adapter.js +7 -26
- package/lib/pricing/product-swiss-tax.js +7 -26
- package/lib/pricing/product-uk-tax/adapter.d.ts +3 -0
- package/lib/pricing/product-uk-tax/adapter.js +57 -0
- package/lib/pricing/product-uk-tax/index.d.ts +4 -0
- package/lib/pricing/product-uk-tax/index.js +10 -0
- package/lib/pricing/product-uk-tax.d.ts +2 -0
- package/lib/pricing/product-uk-tax.js +57 -0
- package/lib/pricing/product-us-sales-tax/adapter.d.ts +3 -0
- package/lib/pricing/product-us-sales-tax/adapter.js +52 -0
- package/lib/pricing/product-us-sales-tax/index.d.ts +4 -0
- package/lib/pricing/product-us-sales-tax/index.js +10 -0
- package/lib/pricing/product-us-sales-tax.d.ts +2 -0
- package/lib/pricing/product-us-sales-tax.js +52 -0
- package/lib/pricing/tax/applyTaxRateToTaxableRows.d.ts +23 -0
- package/lib/pricing/tax/applyTaxRateToTaxableRows.js +30 -0
- package/lib/pricing/tax/ch-tax-rates.json +24 -0
- package/lib/pricing/tax/ch.js +6 -30
- package/lib/pricing/tax/eraRates.d.ts +10 -0
- package/lib/pricing/tax/eraRates.js +15 -0
- package/lib/pricing/tax/eu-tax-rates.json +797 -0
- package/lib/pricing/tax/eu.d.ts +12 -0
- package/lib/pricing/tax/eu.js +38 -0
- package/lib/pricing/tax/uk-tax-rates.json +18 -0
- package/lib/pricing/tax/uk.d.ts +10 -0
- package/lib/pricing/tax/uk.js +23 -0
- package/lib/pricing/tax/us-tax-rates.json +334 -0
- package/lib/pricing/tax/us.d.ts +11 -0
- package/lib/pricing/tax/us.js +20 -0
- package/lib/pricing/utils/isDeliveryAddressInCountry.d.ts +1 -1
- package/lib/pricing/utils/isDeliveryAddressInCountry.js +3 -8
- package/lib/pricing/utils/resolveDeliveryLocation.d.ts +10 -0
- package/lib/pricing/utils/resolveDeliveryLocation.js +9 -0
- package/lib/quotations/manual/adapter.js +6 -1
- package/lib/quotations/manual.js +6 -1
- package/lib/worker/gc-guests/adapter.d.ts +9 -0
- package/lib/worker/gc-guests/adapter.js +56 -0
- package/lib/worker/gc-guests/index.d.ts +4 -0
- package/lib/worker/gc-guests/index.js +13 -0
- package/lib/worker/gc-guests.d.ts +8 -0
- package/lib/worker/gc-guests.js +55 -0
- package/lib/worker/invalidate-carts/adapter.d.ts +9 -0
- package/lib/worker/invalidate-carts/adapter.js +52 -0
- package/lib/worker/invalidate-carts/index.d.ts +4 -0
- package/lib/worker/invalidate-carts/index.js +13 -0
- package/lib/worker/invalidate-carts.d.ts +8 -0
- package/lib/worker/invalidate-carts.js +51 -0
- package/lib/worker/zombie-killer/adapter.d.ts +2 -0
- package/lib/worker/zombie-killer/adapter.js +26 -3
- package/lib/worker/zombie-killer/index.js +4 -1
- package/lib/worker/zombie-killer.d.ts +1 -0
- package/lib/worker/zombie-killer.js +24 -3
- package/package.json +24 -7
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { WorkerAdapter, WorkerDirector, schedule } from '@unchainedshop/core';
|
|
2
|
+
import { userSettings } from '@unchainedshop/core-users';
|
|
3
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
4
|
+
const logger = createLogger('unchained:worker:gc-guests');
|
|
5
|
+
const ONE_DAY_IN_MILLISECONDS = 86400000;
|
|
6
|
+
const everyDayAtHalfPastTwo = schedule.parse.cron('30 2 * * *');
|
|
7
|
+
export const GCGuestsWorker = {
|
|
8
|
+
...WorkerAdapter,
|
|
9
|
+
key: 'shop.unchained.worker-plugin.gc-guests',
|
|
10
|
+
label: 'Garbage Collect Guests',
|
|
11
|
+
version: '1.0.0',
|
|
12
|
+
type: 'GC_GUESTS',
|
|
13
|
+
doWork: async ({ guestUserMaxAgeInDays } = {}, unchainedAPI) => {
|
|
14
|
+
const { modules, services } = unchainedAPI;
|
|
15
|
+
try {
|
|
16
|
+
const maxAgeInDays = guestUserMaxAgeInDays ?? userSettings.guestUserMaxAgeInDays;
|
|
17
|
+
const before = new Date(Date.now() - maxAgeInDays * ONE_DAY_IN_MILLISECONDS);
|
|
18
|
+
const userIdsToDelete = await modules.users.findGuestUserIds({ before });
|
|
19
|
+
let deletedGuestCount = 0;
|
|
20
|
+
await Array.fromAsync(userIdsToDelete, async (userId) => {
|
|
21
|
+
try {
|
|
22
|
+
await services.users.deleteUser({ userId });
|
|
23
|
+
deletedGuestCount += 1;
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
logger.warn(`Failed to garbage-collect guest ${userId}: ${err.message}`);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
success: true,
|
|
31
|
+
result: {
|
|
32
|
+
scannedGuestCount: userIdsToDelete.length,
|
|
33
|
+
deletedGuestCount,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
return {
|
|
39
|
+
success: false,
|
|
40
|
+
error: {
|
|
41
|
+
name: err.name,
|
|
42
|
+
message: err.message,
|
|
43
|
+
stack: err.stack,
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
export default GCGuestsWorker;
|
|
50
|
+
WorkerDirector.registerAdapter(GCGuestsWorker);
|
|
51
|
+
WorkerDirector.configureAutoscheduling({
|
|
52
|
+
type: GCGuestsWorker.type,
|
|
53
|
+
schedule: everyDayAtHalfPastTwo,
|
|
54
|
+
retries: 0,
|
|
55
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type IWorkerAdapter } from '@unchainedshop/core';
|
|
2
|
+
export declare const InvalidateCartsWorker: IWorkerAdapter<{
|
|
3
|
+
maxAgeDays?: number;
|
|
4
|
+
}, {
|
|
5
|
+
scannedCartCount: number;
|
|
6
|
+
recalculatedCartCount: number;
|
|
7
|
+
}>;
|
|
8
|
+
export default InvalidateCartsWorker;
|
|
9
|
+
export declare const configureInvalidateCartsAutoscheduling: () => void;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { WorkerAdapter, WorkerDirector, schedule } from '@unchainedshop/core';
|
|
2
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
3
|
+
const logger = createLogger('unchained:worker:invalidate-carts');
|
|
4
|
+
const firstOfMonthAtLocalMidnight = schedule.parse.cron('0 0 1 * *');
|
|
5
|
+
export const InvalidateCartsWorker = {
|
|
6
|
+
...WorkerAdapter,
|
|
7
|
+
key: 'shop.unchained.worker-plugin.invalidate-carts',
|
|
8
|
+
label: 'Invalidate Carts',
|
|
9
|
+
version: '1.0.0',
|
|
10
|
+
type: 'INVALIDATE_CARTS',
|
|
11
|
+
doWork: async ({ maxAgeDays } = {}, unchainedAPI) => {
|
|
12
|
+
const { modules, services } = unchainedAPI;
|
|
13
|
+
try {
|
|
14
|
+
const orderIds = await modules.orders.findCartIdsToInvalidate(maxAgeDays);
|
|
15
|
+
let recalculatedCartCount = 0;
|
|
16
|
+
for (const orderId of orderIds) {
|
|
17
|
+
try {
|
|
18
|
+
await services.orders.updateCalculation(orderId);
|
|
19
|
+
recalculatedCartCount += 1;
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
logger.warn(`Failed to recalculate cart ${orderId}: ${err.message}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
success: true,
|
|
27
|
+
result: {
|
|
28
|
+
scannedCartCount: orderIds.length,
|
|
29
|
+
recalculatedCartCount,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
return {
|
|
35
|
+
success: false,
|
|
36
|
+
error: {
|
|
37
|
+
name: err.name,
|
|
38
|
+
message: err.message,
|
|
39
|
+
stack: err.stack,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
export default InvalidateCartsWorker;
|
|
46
|
+
export const configureInvalidateCartsAutoscheduling = () => {
|
|
47
|
+
WorkerDirector.configureAutoscheduling({
|
|
48
|
+
type: InvalidateCartsWorker.type,
|
|
49
|
+
schedule: firstOfMonthAtLocalMidnight,
|
|
50
|
+
retries: 0,
|
|
51
|
+
});
|
|
52
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {} from '@unchainedshop/core';
|
|
2
|
+
import { InvalidateCartsWorker, configureInvalidateCartsAutoscheduling } from "./adapter.js";
|
|
3
|
+
export const InvalidateCartsPlugin = {
|
|
4
|
+
key: 'shop.unchained.worker-plugin.invalidate-carts',
|
|
5
|
+
label: 'Invalidate Carts Worker Plugin',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
adapters: [InvalidateCartsWorker],
|
|
8
|
+
onRegister: () => {
|
|
9
|
+
configureInvalidateCartsAutoscheduling();
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
export default InvalidateCartsPlugin;
|
|
13
|
+
export * from "./adapter.js";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { WorkerAdapter, WorkerDirector, schedule } from '@unchainedshop/core';
|
|
2
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
3
|
+
const logger = createLogger('unchained:worker:invalidate-carts');
|
|
4
|
+
const firstOfMonthAtLocalMidnight = schedule.parse.cron('0 0 1 * *');
|
|
5
|
+
export const InvalidateCartsWorker = {
|
|
6
|
+
...WorkerAdapter,
|
|
7
|
+
key: 'shop.unchained.worker-plugin.invalidate-carts',
|
|
8
|
+
label: 'Invalidate Carts',
|
|
9
|
+
version: '1.0.0',
|
|
10
|
+
type: 'INVALIDATE_CARTS',
|
|
11
|
+
doWork: async ({ maxAgeDays } = {}, unchainedAPI) => {
|
|
12
|
+
const { modules, services } = unchainedAPI;
|
|
13
|
+
try {
|
|
14
|
+
const orderIds = await modules.orders.findCartIdsToInvalidate(maxAgeDays);
|
|
15
|
+
let recalculatedCartCount = 0;
|
|
16
|
+
for (const orderId of orderIds) {
|
|
17
|
+
try {
|
|
18
|
+
await services.orders.updateCalculation(orderId);
|
|
19
|
+
recalculatedCartCount += 1;
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
logger.warn(`Failed to recalculate cart ${orderId}: ${err.message}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
success: true,
|
|
27
|
+
result: {
|
|
28
|
+
scannedCartCount: orderIds.length,
|
|
29
|
+
recalculatedCartCount,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
return {
|
|
35
|
+
success: false,
|
|
36
|
+
error: {
|
|
37
|
+
name: err.name,
|
|
38
|
+
message: err.message,
|
|
39
|
+
stack: err.stack,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
export default InvalidateCartsWorker;
|
|
46
|
+
WorkerDirector.registerAdapter(InvalidateCartsWorker);
|
|
47
|
+
WorkerDirector.configureAutoscheduling({
|
|
48
|
+
type: InvalidateCartsWorker.type,
|
|
49
|
+
schedule: firstOfMonthAtLocalMidnight,
|
|
50
|
+
retries: 0,
|
|
51
|
+
});
|
|
@@ -9,5 +9,7 @@ export declare const ZombieKillerWorker: IWorkerAdapter<{
|
|
|
9
9
|
deletedProductTextsCount: number;
|
|
10
10
|
deletedProductVariationsCount: number;
|
|
11
11
|
deletedAssortmentTextsCount: number;
|
|
12
|
+
deletedCartsCount: number;
|
|
12
13
|
}>;
|
|
13
14
|
export default ZombieKillerWorker;
|
|
15
|
+
export declare const configureZombieKillerAutoscheduling: () => void;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { WorkerAdapter } from '@unchainedshop/core';
|
|
1
|
+
import { WorkerAdapter, WorkerDirector, schedule } from '@unchainedshop/core';
|
|
2
|
+
const everyDayAtTwo = schedule.parse.cron('0 2 * * *');
|
|
2
3
|
export const ZombieKillerWorker = {
|
|
3
4
|
...WorkerAdapter,
|
|
4
5
|
key: 'shop.unchained.worker-plugin.zombie-killer',
|
|
5
6
|
label: 'Zombie Killer',
|
|
6
7
|
version: '1.0.0',
|
|
7
8
|
type: 'ZOMBIE_KILLER',
|
|
8
|
-
doWork: async (
|
|
9
|
+
doWork: async (input, unchainedAPI) => {
|
|
9
10
|
const { modules, services } = unchainedAPI;
|
|
11
|
+
const { bulkImportMaxAgeInDays = 5 } = input || {};
|
|
10
12
|
try {
|
|
11
13
|
const error = false;
|
|
12
14
|
const filters = await modules.filters.findFilters({ includeInactive: true }, { projection: { _id: 1 } });
|
|
@@ -38,7 +40,9 @@ export const ZombieKillerWorker = {
|
|
|
38
40
|
const productMedia = await modules.products.media.findProductMedias({}, { projection: { mediaId: 1 } });
|
|
39
41
|
const assortmentMedia = await modules.assortments.media.findAssortmentMedias({}, { projection: { mediaId: 1 } });
|
|
40
42
|
const allFileIdsLinked = [...productMedia, ...assortmentMedia].map((l) => l?.mediaId);
|
|
41
|
-
const allFileIdsRelevant = (await modules.files.findFiles({ paths: ['product-media', 'assortment-media'] }, { projection: { _id: 1 } }))
|
|
43
|
+
const allFileIdsRelevant = (await modules.files.findFiles({ paths: ['product-media', 'assortment-media'] }, { projection: { _id: 1, expires: 1 } }))
|
|
44
|
+
.filter((file) => !file.expires)
|
|
45
|
+
.map((a) => a._id);
|
|
42
46
|
const fileIdsToRemove = allFileIdsRelevant.filter((fileId) => {
|
|
43
47
|
return !allFileIdsLinked.includes(fileId);
|
|
44
48
|
}) || [];
|
|
@@ -54,6 +58,17 @@ export const ZombieKillerWorker = {
|
|
|
54
58
|
fileIds: fileIdsToRemove,
|
|
55
59
|
})
|
|
56
60
|
: 0;
|
|
61
|
+
const cartUserIds = (await modules.orders.findCartUserIds()).filter(Boolean);
|
|
62
|
+
const existingUserIds = new Set(cartUserIds.length ? await modules.users.findExistingUserIds({ userIds: cartUserIds }) : []);
|
|
63
|
+
const deadUserIds = cartUserIds.filter((userId) => !existingUserIds.has(userId));
|
|
64
|
+
const deadCarts = deadUserIds.length
|
|
65
|
+
? await modules.orders.findCarts({ userIds: deadUserIds }, { projection: { _id: 1 } })
|
|
66
|
+
: [];
|
|
67
|
+
let deletedCartsCount = 0;
|
|
68
|
+
await Array.fromAsync(deadCarts, async (cart) => {
|
|
69
|
+
await services.orders.deleteCart(cart._id);
|
|
70
|
+
deletedCartsCount += 1;
|
|
71
|
+
});
|
|
57
72
|
const result = {
|
|
58
73
|
deletedFilterTextsCount,
|
|
59
74
|
deletedProductMediaCount,
|
|
@@ -62,6 +77,7 @@ export const ZombieKillerWorker = {
|
|
|
62
77
|
deletedAssortmentMediaCount,
|
|
63
78
|
deletedAssortmentTextsCount,
|
|
64
79
|
deletedFilesCount,
|
|
80
|
+
deletedCartsCount,
|
|
65
81
|
};
|
|
66
82
|
if (error) {
|
|
67
83
|
return {
|
|
@@ -88,3 +104,10 @@ export const ZombieKillerWorker = {
|
|
|
88
104
|
},
|
|
89
105
|
};
|
|
90
106
|
export default ZombieKillerWorker;
|
|
107
|
+
export const configureZombieKillerAutoscheduling = () => {
|
|
108
|
+
WorkerDirector.configureAutoscheduling({
|
|
109
|
+
type: ZombieKillerWorker.type,
|
|
110
|
+
schedule: everyDayAtTwo,
|
|
111
|
+
retries: 0,
|
|
112
|
+
});
|
|
113
|
+
};
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import {} from '@unchainedshop/core';
|
|
2
|
-
import { ZombieKillerWorker } from "./adapter.js";
|
|
2
|
+
import { ZombieKillerWorker, configureZombieKillerAutoscheduling } from "./adapter.js";
|
|
3
3
|
export const ZombieKillerPlugin = {
|
|
4
4
|
key: 'shop.unchained.worker-plugin.zombie-killer',
|
|
5
5
|
label: 'Zombie Killer Worker Plugin',
|
|
6
6
|
version: '1.0.0',
|
|
7
7
|
adapters: [ZombieKillerWorker],
|
|
8
|
+
onRegister: () => {
|
|
9
|
+
configureZombieKillerAutoscheduling();
|
|
10
|
+
},
|
|
8
11
|
};
|
|
9
12
|
export default ZombieKillerPlugin;
|
|
10
13
|
export { ZombieKillerWorker } from "./adapter.js";
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { WorkerAdapter, WorkerDirector } from '@unchainedshop/core';
|
|
1
|
+
import { WorkerAdapter, WorkerDirector, schedule } from '@unchainedshop/core';
|
|
2
|
+
const everyDayAtTwo = schedule.parse.cron('0 2 * * *');
|
|
2
3
|
export const ZombieKillerWorker = {
|
|
3
4
|
...WorkerAdapter,
|
|
4
5
|
key: 'shop.unchained.worker-plugin.zombie-killer',
|
|
5
6
|
label: 'Zombie Killer',
|
|
6
7
|
version: '1.0.0',
|
|
7
8
|
type: 'ZOMBIE_KILLER',
|
|
8
|
-
doWork: async (
|
|
9
|
+
doWork: async (input, unchainedAPI) => {
|
|
9
10
|
const { modules, services } = unchainedAPI;
|
|
11
|
+
const { bulkImportMaxAgeInDays = 5 } = input || {};
|
|
10
12
|
try {
|
|
11
13
|
const error = false;
|
|
12
14
|
const filters = await modules.filters.findFilters({ includeInactive: true }, { projection: { _id: 1 } });
|
|
@@ -38,7 +40,9 @@ export const ZombieKillerWorker = {
|
|
|
38
40
|
const productMedia = await modules.products.media.findProductMedias({}, { projection: { mediaId: 1 } });
|
|
39
41
|
const assortmentMedia = await modules.assortments.media.findAssortmentMedias({}, { projection: { mediaId: 1 } });
|
|
40
42
|
const allFileIdsLinked = [...productMedia, ...assortmentMedia].map((l) => l?.mediaId);
|
|
41
|
-
const allFileIdsRelevant = (await modules.files.findFiles({ paths: ['product-media', 'assortment-media'] }, { projection: { _id: 1 } }))
|
|
43
|
+
const allFileIdsRelevant = (await modules.files.findFiles({ paths: ['product-media', 'assortment-media'] }, { projection: { _id: 1, expires: 1 } }))
|
|
44
|
+
.filter((file) => !file.expires)
|
|
45
|
+
.map((a) => a._id);
|
|
42
46
|
const fileIdsToRemove = allFileIdsRelevant.filter((fileId) => {
|
|
43
47
|
return !allFileIdsLinked.includes(fileId);
|
|
44
48
|
}) || [];
|
|
@@ -54,6 +58,17 @@ export const ZombieKillerWorker = {
|
|
|
54
58
|
fileIds: fileIdsToRemove,
|
|
55
59
|
})
|
|
56
60
|
: 0;
|
|
61
|
+
const cartUserIds = (await modules.orders.findCartUserIds()).filter(Boolean);
|
|
62
|
+
const existingUserIds = new Set(cartUserIds.length ? await modules.users.findExistingUserIds({ userIds: cartUserIds }) : []);
|
|
63
|
+
const deadUserIds = cartUserIds.filter((userId) => !existingUserIds.has(userId));
|
|
64
|
+
const deadCarts = deadUserIds.length
|
|
65
|
+
? await modules.orders.findCarts({ userIds: deadUserIds }, { projection: { _id: 1 } })
|
|
66
|
+
: [];
|
|
67
|
+
let deletedCartsCount = 0;
|
|
68
|
+
await Array.fromAsync(deadCarts, async (cart) => {
|
|
69
|
+
await services.orders.deleteCart(cart._id);
|
|
70
|
+
deletedCartsCount += 1;
|
|
71
|
+
});
|
|
57
72
|
const result = {
|
|
58
73
|
deletedFilterTextsCount,
|
|
59
74
|
deletedProductMediaCount,
|
|
@@ -62,6 +77,7 @@ export const ZombieKillerWorker = {
|
|
|
62
77
|
deletedAssortmentMediaCount,
|
|
63
78
|
deletedAssortmentTextsCount,
|
|
64
79
|
deletedFilesCount,
|
|
80
|
+
deletedCartsCount,
|
|
65
81
|
};
|
|
66
82
|
if (error) {
|
|
67
83
|
return {
|
|
@@ -89,3 +105,8 @@ export const ZombieKillerWorker = {
|
|
|
89
105
|
};
|
|
90
106
|
export default ZombieKillerWorker;
|
|
91
107
|
WorkerDirector.registerAdapter(ZombieKillerWorker);
|
|
108
|
+
WorkerDirector.configureAutoscheduling({
|
|
109
|
+
type: ZombieKillerWorker.type,
|
|
110
|
+
schedule: everyDayAtTwo,
|
|
111
|
+
retries: 0,
|
|
112
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/plugins",
|
|
3
3
|
"description": "Official plugin collection for the Unchained Engine with payment, delivery, and pricing adapters",
|
|
4
|
-
"version": "5.0.0-alpha.
|
|
4
|
+
"version": "5.0.0-alpha.3",
|
|
5
5
|
"main": "lib/plugins-index.js",
|
|
6
6
|
"types": "lib/plugins-index.d.ts",
|
|
7
7
|
"exports": {
|
|
@@ -49,27 +49,36 @@
|
|
|
49
49
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@unchainedshop/api": "^5.0.0-alpha.1",
|
|
52
|
+
"@unchainedshop/core": "^5.0.0-alpha.1",
|
|
53
|
+
"@unchainedshop/core-countries": "^5.0.0-alpha.1",
|
|
52
54
|
"@unchainedshop/core-delivery": "^5.0.0-alpha.1",
|
|
53
55
|
"@unchainedshop/core-enrollments": "^5.0.0-alpha.1",
|
|
56
|
+
"@unchainedshop/core-files": "^5.0.0-alpha.1",
|
|
57
|
+
"@unchainedshop/core-languages": "^5.0.0-alpha.1",
|
|
54
58
|
"@unchainedshop/core-orders": "^5.0.0-alpha.1",
|
|
55
59
|
"@unchainedshop/core-payment": "^5.0.0-alpha.1",
|
|
56
60
|
"@unchainedshop/core-products": "^5.0.0-alpha.1",
|
|
61
|
+
"@unchainedshop/core-users": "^5.0.0-alpha.1",
|
|
57
62
|
"@unchainedshop/core-warehousing": "^5.0.0-alpha.1",
|
|
58
63
|
"@unchainedshop/core-worker": "^5.0.0-alpha.1",
|
|
59
64
|
"@unchainedshop/events": "^5.0.0-alpha.1",
|
|
60
65
|
"@unchainedshop/logger": "^5.0.0-alpha.1",
|
|
66
|
+
"@unchainedshop/mongodb": "^5.0.0-alpha.1",
|
|
67
|
+
"@unchainedshop/roles": "^5.0.0-alpha.1",
|
|
61
68
|
"@unchainedshop/utils": "^5.0.0-alpha.1"
|
|
62
69
|
},
|
|
63
70
|
"peerDependencies": {
|
|
64
71
|
"@aws-sdk/client-eventbridge": ">= 3.714 < 4",
|
|
65
|
-
"@
|
|
72
|
+
"@noble/curves": "^2.0.0",
|
|
73
|
+
"@noble/hashes": "^2.0.0",
|
|
74
|
+
"@redis/client": ">= 1 < 7",
|
|
66
75
|
"@scure/bip32": ">= 2",
|
|
67
76
|
"@scure/btc-signer": ">= 2",
|
|
68
77
|
"mime": ">= 4 < 5",
|
|
69
78
|
"express": ">= 5 < 6",
|
|
70
79
|
"fastify": ">= 5.2 < 6",
|
|
71
80
|
"minio": "8.x",
|
|
72
|
-
"nodemailer": ">= 6.9 <
|
|
81
|
+
"nodemailer": ">= 6.9 < 10",
|
|
73
82
|
"stripe": ">= 19 < 23",
|
|
74
83
|
"web-push": ">= 3.6 <4",
|
|
75
84
|
"xml-js": ">= 1.6 < 2"
|
|
@@ -78,6 +87,12 @@
|
|
|
78
87
|
"@aws-sdk/client-eventbridge": {
|
|
79
88
|
"optional": true
|
|
80
89
|
},
|
|
90
|
+
"@noble/curves": {
|
|
91
|
+
"optional": true
|
|
92
|
+
},
|
|
93
|
+
"@noble/hashes": {
|
|
94
|
+
"optional": true
|
|
95
|
+
},
|
|
81
96
|
"@redis/client": {
|
|
82
97
|
"optional": true
|
|
83
98
|
},
|
|
@@ -110,16 +125,18 @@
|
|
|
110
125
|
}
|
|
111
126
|
},
|
|
112
127
|
"devDependencies": {
|
|
113
|
-
"@
|
|
128
|
+
"@noble/curves": "^2.0.0",
|
|
129
|
+
"@noble/hashes": "^2.0.0",
|
|
130
|
+
"@redis/client": "^6.0.0",
|
|
114
131
|
"@scure/bip32": "^2.0.0",
|
|
115
132
|
"@scure/btc-signer": "^2.0.0",
|
|
116
133
|
"@types/express": "^5.0.3",
|
|
117
|
-
"@types/node": "^
|
|
134
|
+
"@types/node": "^26.2.0",
|
|
118
135
|
"express": "^5.1.0",
|
|
119
136
|
"fastify": "^5.4.0",
|
|
120
137
|
"minio": "^8.0.5",
|
|
121
|
-
"nodemailer": "^
|
|
122
|
-
"stripe": "^22.
|
|
138
|
+
"nodemailer": "^9.0.0",
|
|
139
|
+
"stripe": "^22.5.0",
|
|
123
140
|
"typescript": "^5.8.3",
|
|
124
141
|
"web-push": "^3.6.7",
|
|
125
142
|
"xml-js": "^1.6.11"
|