@unchainedshop/plugins 4.8.15 → 4.8.17
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/presets/base.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ import '../events/node-event-emitter.ts';
|
|
|
15
15
|
import '../worker/bulk-import.ts';
|
|
16
16
|
import '../worker/zombie-killer.ts';
|
|
17
17
|
import '../worker/gc-guests.ts';
|
|
18
|
+
import '../worker/invalidate-carts.ts';
|
|
18
19
|
import '../worker/message.ts';
|
|
19
20
|
import '../worker/external.ts';
|
|
20
21
|
import '../worker/http-request.ts';
|
package/lib/presets/base.js
CHANGED
|
@@ -15,6 +15,7 @@ import "../events/node-event-emitter.js";
|
|
|
15
15
|
import "../worker/bulk-import.js";
|
|
16
16
|
import "../worker/zombie-killer.js";
|
|
17
17
|
import "../worker/gc-guests.js";
|
|
18
|
+
import "../worker/invalidate-carts.js";
|
|
18
19
|
import "../worker/message.js";
|
|
19
20
|
import "../worker/external.js";
|
|
20
21
|
import "../worker/http-request.js";
|
package/lib/worker/gc-guests.js
CHANGED
|
@@ -15,12 +15,7 @@ export const GCGuestsWorker = {
|
|
|
15
15
|
try {
|
|
16
16
|
const maxAgeInDays = guestUserMaxAgeInDays ?? userSettings.guestUserMaxAgeInDays;
|
|
17
17
|
const before = new Date(Date.now() - maxAgeInDays * ONE_DAY_IN_MILLISECONDS);
|
|
18
|
-
const
|
|
19
|
-
const recentCarts = candidateIds.length
|
|
20
|
-
? await modules.orders.findCarts({ userIds: candidateIds }, { projection: { userId: 1, updated: 1 } })
|
|
21
|
-
: [];
|
|
22
|
-
const userIdsWithRecentCart = new Set(recentCarts.filter((cart) => cart.updated && cart.updated >= before).map((c) => c.userId));
|
|
23
|
-
const userIdsToDelete = candidateIds.filter((id) => !userIdsWithRecentCart.has(id));
|
|
18
|
+
const userIdsToDelete = await modules.users.findGuestUserIds({ before });
|
|
24
19
|
let deletedGuestCount = 0;
|
|
25
20
|
await Array.fromAsync(userIdsToDelete, async (userId) => {
|
|
26
21
|
try {
|
|
@@ -34,7 +29,7 @@ export const GCGuestsWorker = {
|
|
|
34
29
|
return {
|
|
35
30
|
success: true,
|
|
36
31
|
result: {
|
|
37
|
-
scannedGuestCount:
|
|
32
|
+
scannedGuestCount: userIdsToDelete.length,
|
|
38
33
|
deletedGuestCount,
|
|
39
34
|
},
|
|
40
35
|
};
|
|
@@ -56,5 +51,5 @@ WorkerDirector.registerAdapter(GCGuestsWorker);
|
|
|
56
51
|
WorkerDirector.configureAutoscheduling({
|
|
57
52
|
type: GCGuestsWorker.type,
|
|
58
53
|
schedule: everyDayAtHalfPastTwo,
|
|
59
|
-
retries:
|
|
54
|
+
retries: 0,
|
|
60
55
|
});
|
|
@@ -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
|
+
});
|
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": "4.8.
|
|
4
|
+
"version": "4.8.17",
|
|
5
5
|
"main": "lib/plugins-index.js",
|
|
6
6
|
"types": "lib/plugins-index.d.ts",
|
|
7
7
|
"exports": {
|