@unchainedshop/plugins 2.0.0-beta8 → 2.0.0-beta9
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/delivery/send-message.js +2 -2
- package/lib/delivery/send-message.js.map +1 -1
- package/lib/payment/apple-iap/adapter.js +10 -8
- package/lib/payment/apple-iap/adapter.js.map +1 -1
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js +1 -2
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js.map +1 -1
- package/lib/payment/datatrans-v2/index.js +2 -2
- package/lib/payment/datatrans-v2/index.js.map +1 -1
- package/lib/payment/datatrans-v2/middleware.js +3 -3
- package/lib/payment/datatrans-v2/middleware.js.map +1 -1
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts +2 -2
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.js.map +1 -1
- package/lib/payment/postfinance-checkout/index.js +4 -9
- package/lib/payment/postfinance-checkout/index.js.map +1 -1
- package/lib/payment/stripe.js +6 -6
- package/lib/payment/stripe.js.map +1 -1
- package/lib/payment/worldline-saferpay/index.js +2 -6
- package/lib/payment/worldline-saferpay/index.js.map +1 -1
- package/lib/warehousing/eth-minter.js +3 -3
- package/lib/warehousing/eth-minter.js.map +1 -1
- package/lib/worker/bulk-import.js +1 -2
- package/lib/worker/bulk-import.js.map +1 -1
- package/lib/worker/enrollment-order-generator.js +13 -12
- package/lib/worker/enrollment-order-generator.js.map +1 -1
- package/lib/worker/message.js +4 -4
- package/lib/worker/message.js.map +1 -1
- package/lib/worker/update-coinbase-rates.js +3 -3
- package/lib/worker/update-coinbase-rates.js.map +1 -1
- package/lib/worker/update-ecb-rates.js +2 -2
- package/lib/worker/update-ecb-rates.js.map +1 -1
- package/lib/worker/update-token-ownership.js +3 -3
- package/lib/worker/update-token-ownership.js.map +1 -1
- package/lib/worker/zombie-killer.js +26 -6
- package/lib/worker/zombie-killer.js.map +1 -1
- package/package.json +21 -20
- package/src/delivery/send-message.ts +10 -13
- package/src/payment/apple-iap/adapter.ts +11 -16
- package/src/payment/apple-iap/module/configureAppleTransactionsModule.ts +1 -2
- package/src/payment/datatrans-v2/index.ts +2 -4
- package/src/payment/datatrans-v2/middleware.ts +6 -6
- package/src/payment/datatrans-v2/roundedAmountFromOrder.ts +2 -2
- package/src/payment/postfinance-checkout/index.ts +5 -9
- package/src/payment/stripe.ts +6 -6
- package/src/payment/worldline-saferpay/index.ts +2 -6
- package/src/warehousing/eth-minter.ts +3 -3
- package/src/worker/bulk-import.ts +1 -6
- package/src/worker/enrollment-order-generator.ts +21 -23
- package/src/worker/message.ts +6 -10
- package/src/worker/update-coinbase-rates.ts +3 -3
- package/src/worker/update-ecb-rates.ts +2 -2
- package/src/worker/update-token-ownership.ts +10 -13
- package/src/worker/zombie-killer.ts +30 -7
- package/tests/plugins-index.test.js +3 -0
|
@@ -99,16 +99,15 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
99
99
|
},
|
|
100
100
|
|
|
101
101
|
sign: async (transactionContext: any = {}) => {
|
|
102
|
+
const { orderPayment, order } = params.paymentContext;
|
|
103
|
+
|
|
102
104
|
const { integrationMode = IntegrationModes.PaymentPage }: { integrationMode: IntegrationModes } =
|
|
103
105
|
transactionContext;
|
|
104
106
|
const completionMode = adapter.getCompletionMode();
|
|
105
|
-
const { orderPayment } = params.paymentContext;
|
|
106
|
-
const order = await modules.orders.findOrder({
|
|
107
|
-
orderId: orderPayment.orderId,
|
|
108
|
-
});
|
|
109
107
|
const pricing = modules.orders.pricingSheet(order);
|
|
110
108
|
const totalAmount = pricing?.total({ useNetPrice: false }).amount;
|
|
111
109
|
const transaction = new PostFinanceCheckout.model.TransactionCreate();
|
|
110
|
+
const userId = order?.userId || params.paymentContext?.userId;
|
|
112
111
|
transaction.currency = order.currency;
|
|
113
112
|
transaction.metaData = {
|
|
114
113
|
orderPaymentId: orderPayment._id,
|
|
@@ -119,7 +118,7 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
119
118
|
transaction.failedUrl = `${transactionContext?.failedUrl || PFCHECKOUT_FAILED_URL}?order_id=${
|
|
120
119
|
orderPayment.orderId
|
|
121
120
|
}`;
|
|
122
|
-
transaction.customerId =
|
|
121
|
+
transaction.customerId = userId;
|
|
123
122
|
transaction.tokenizationMode =
|
|
124
123
|
PostFinanceCheckout.model.TokenizationMode.ALLOW_ONE_CLICK_PAYMENT;
|
|
125
124
|
if (completionMode === CompletionModes.Immediate) {
|
|
@@ -208,16 +207,13 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
208
207
|
},
|
|
209
208
|
|
|
210
209
|
cancel: async () => {
|
|
211
|
-
const { orderPayment } = params.paymentContext;
|
|
210
|
+
const { orderPayment, order } = params.paymentContext;
|
|
212
211
|
const { transactionId } = orderPayment;
|
|
213
212
|
if (!transactionId) {
|
|
214
213
|
return false;
|
|
215
214
|
}
|
|
216
215
|
const transaction = await getTransaction(transactionId);
|
|
217
216
|
const refund = transaction.state === PostFinanceCheckout.model.TransactionState.FULFILL;
|
|
218
|
-
const order = await modules.orders.findOrder({
|
|
219
|
-
orderId: orderPayment.orderId,
|
|
220
|
-
});
|
|
221
217
|
const pricing = modules.orders.pricingSheet(order);
|
|
222
218
|
const totalAmount = pricing?.total({ useNetPrice: false }).amount;
|
|
223
219
|
// For immediate settlements, try refunding. For deferred settlements, void the transaction.
|
package/src/payment/stripe.ts
CHANGED
|
@@ -25,7 +25,7 @@ const stripe = createStripeClient(STRIPE_SECRET);
|
|
|
25
25
|
export const stripeHandler = async (request, response) => {
|
|
26
26
|
const sig = request.headers['stripe-signature'];
|
|
27
27
|
const resolvedContext = request.unchainedContext as Context;
|
|
28
|
-
const { modules
|
|
28
|
+
const { modules } = resolvedContext;
|
|
29
29
|
|
|
30
30
|
let event;
|
|
31
31
|
|
|
@@ -42,7 +42,7 @@ export const stripeHandler = async (request, response) => {
|
|
|
42
42
|
const paymentIntent = event.data.object;
|
|
43
43
|
const orderPaymentId = paymentIntent.metadata?.orderPaymentId;
|
|
44
44
|
|
|
45
|
-
await modules.orders.payments.logEvent(orderPaymentId, event
|
|
45
|
+
await modules.orders.payments.logEvent(orderPaymentId, event);
|
|
46
46
|
|
|
47
47
|
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
48
48
|
orderPaymentId,
|
|
@@ -68,12 +68,13 @@ export const stripeHandler = async (request, response) => {
|
|
|
68
68
|
const setupIntent = event.data.object;
|
|
69
69
|
const { paymentProviderId, userId } = setupIntent.metadata;
|
|
70
70
|
|
|
71
|
-
await
|
|
71
|
+
await modules.payment.registerCredentials(
|
|
72
72
|
paymentProviderId,
|
|
73
73
|
{
|
|
74
74
|
transactionContext: {
|
|
75
75
|
setupIntentId: setupIntent.id,
|
|
76
76
|
},
|
|
77
|
+
userId,
|
|
77
78
|
},
|
|
78
79
|
resolvedContext,
|
|
79
80
|
);
|
|
@@ -197,11 +198,9 @@ const Stripe: IPaymentAdapter = {
|
|
|
197
198
|
|
|
198
199
|
sign: async (transactionContext = {}) => {
|
|
199
200
|
// eslint-disable-line
|
|
200
|
-
const { orderPayment, paymentProviderId } = params.paymentContext;
|
|
201
|
-
const { userId } = params.context;
|
|
201
|
+
const { orderPayment, order, paymentProviderId } = params.paymentContext;
|
|
202
202
|
|
|
203
203
|
if (orderPayment) {
|
|
204
|
-
const order = await modules.orders.findOrder({ orderId: orderPayment.orderId });
|
|
205
204
|
const pricing = await modules.orders.pricingSheet(order);
|
|
206
205
|
const paymentIntent = await createOrderPaymentIntent(
|
|
207
206
|
{ order, orderPayment, pricing },
|
|
@@ -210,6 +209,7 @@ const Stripe: IPaymentAdapter = {
|
|
|
210
209
|
return paymentIntent.client_secret;
|
|
211
210
|
}
|
|
212
211
|
|
|
212
|
+
const userId = order?.userId || params.paymentContext?.userId;
|
|
213
213
|
const user = await modules.users.findUserById(userId);
|
|
214
214
|
const email = modules.users.primaryEmail(user)?.address;
|
|
215
215
|
const name = user.profile.displayName || user.username || email;
|
|
@@ -64,10 +64,7 @@ const WordlineSaferpay: IPaymentAdapter = {
|
|
|
64
64
|
},
|
|
65
65
|
|
|
66
66
|
sign: async (transactionContext: any = {}) => {
|
|
67
|
-
const { orderPayment } = params.paymentContext;
|
|
68
|
-
const order = await modules.orders.findOrder({
|
|
69
|
-
orderId: orderPayment.orderId,
|
|
70
|
-
});
|
|
67
|
+
const { orderPayment, order } = params.paymentContext;
|
|
71
68
|
const pricing = modules.orders.pricingSheet(order);
|
|
72
69
|
const totalAmount = pricing?.total({ useNetPrice: false }).amount;
|
|
73
70
|
const paymentPageInitInput: PaymentPageInitializeInput = {
|
|
@@ -95,8 +92,7 @@ const WordlineSaferpay: IPaymentAdapter = {
|
|
|
95
92
|
},
|
|
96
93
|
|
|
97
94
|
charge: async ({ transactionId }: { transactionId: string }) => {
|
|
98
|
-
const { orderPayment } = params.paymentContext;
|
|
99
|
-
const order = await modules.orders.findOrder({ orderId: orderPayment.orderId });
|
|
95
|
+
const { orderPayment, order } = params.paymentContext;
|
|
100
96
|
const pricing = modules.orders.pricingSheet(order);
|
|
101
97
|
const totalAmount = pricing.total({ useNetPrice: false }).amount;
|
|
102
98
|
const paymentPageAssert = await saferpayClient.paymentPageAssert({
|
|
@@ -24,7 +24,7 @@ const ETHMinter: IWarehousingAdapter = {
|
|
|
24
24
|
},
|
|
25
25
|
|
|
26
26
|
actions: (configuration, context) => {
|
|
27
|
-
const { product, orderPosition, token, modules,
|
|
27
|
+
const { product, orderPosition, token, modules, locale } = context;
|
|
28
28
|
|
|
29
29
|
const getTokensCreated = async () => {
|
|
30
30
|
const existingTokens = await modules.warehousing.findTokens(
|
|
@@ -109,12 +109,12 @@ const ETHMinter: IWarehousingAdapter = {
|
|
|
109
109
|
const url = file && (await modules.files.getUrl(file, {}));
|
|
110
110
|
const text = await modules.products.texts.findLocalizedText({
|
|
111
111
|
productId: product._id,
|
|
112
|
-
locale:
|
|
112
|
+
locale: locale?.normalized || systemLocale.normalized,
|
|
113
113
|
});
|
|
114
114
|
|
|
115
115
|
const name = `${text.title} #${chainTokenId}`;
|
|
116
116
|
|
|
117
|
-
const isDefaultLanguageActive =
|
|
117
|
+
const isDefaultLanguageActive = locale ? locale?.language === systemLocale.language : true;
|
|
118
118
|
const localization = isDefaultLanguageActive
|
|
119
119
|
? {
|
|
120
120
|
uri: `${process.env.ROOT_URL}/erc-metadata/${product._id}/{locale}/${product.tokenization.tokenId}.json`,
|
|
@@ -56,15 +56,10 @@ export const BulkImportWorker: IWorkerAdapter<any, Record<string, unknown>> = {
|
|
|
56
56
|
|
|
57
57
|
doWork: async (rawPayload, unchainedAPI) => {
|
|
58
58
|
try {
|
|
59
|
-
const {
|
|
60
|
-
createShouldUpsertIfIDExists = false,
|
|
61
|
-
skipCacheInvalidation = false,
|
|
62
|
-
authorId = 'root',
|
|
63
|
-
} = rawPayload;
|
|
59
|
+
const { createShouldUpsertIfIDExists = false, skipCacheInvalidation = false } = rawPayload;
|
|
64
60
|
|
|
65
61
|
const bulkImporter = unchainedAPI.bulkImporter.createBulkImporter({
|
|
66
62
|
logger,
|
|
67
|
-
authorId,
|
|
68
63
|
createShouldUpsertIfIDExists,
|
|
69
64
|
skipCacheInvalidation,
|
|
70
65
|
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Context } from '@unchainedshop/types/api';
|
|
2
1
|
import { Enrollment } from '@unchainedshop/types/enrollments';
|
|
3
2
|
import { OrderPosition } from '@unchainedshop/types/orders.positions';
|
|
4
3
|
import { Product } from '@unchainedshop/types/products';
|
|
@@ -9,6 +8,7 @@ import {
|
|
|
9
8
|
EnrollmentStatus,
|
|
10
9
|
} from '@unchainedshop/core-enrollments';
|
|
11
10
|
import { WorkerAdapter, WorkerDirector } from '@unchainedshop/core-worker';
|
|
11
|
+
import { UnchainedCore } from '@unchainedshop/types/core';
|
|
12
12
|
|
|
13
13
|
const generateOrder = async (
|
|
14
14
|
enrollment: Enrollment,
|
|
@@ -16,29 +16,27 @@ const generateOrder = async (
|
|
|
16
16
|
orderProducts: Array<{ orderPosition: OrderPosition; product: Product }>;
|
|
17
17
|
orderContext?: any;
|
|
18
18
|
} & { [x: string]: any },
|
|
19
|
-
|
|
19
|
+
unchainedAPI: UnchainedCore,
|
|
20
20
|
) => {
|
|
21
21
|
if (!enrollment.payment || !enrollment.delivery) return null;
|
|
22
22
|
|
|
23
|
-
const { modules } =
|
|
23
|
+
const { modules } = unchainedAPI;
|
|
24
24
|
const { orderProducts, orderContext, ...configuration } = params;
|
|
25
|
-
let order = await modules.orders.create(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
enrollment.userId,
|
|
35
|
-
);
|
|
25
|
+
let order = await modules.orders.create({
|
|
26
|
+
userId: enrollment.userId,
|
|
27
|
+
currency: enrollment.currencyCode,
|
|
28
|
+
countryCode: enrollment.countryCode,
|
|
29
|
+
contact: enrollment.contact,
|
|
30
|
+
billingAddress: enrollment.billingAddress,
|
|
31
|
+
originEnrollmentId: enrollment._id,
|
|
32
|
+
...configuration,
|
|
33
|
+
});
|
|
36
34
|
const orderId = order._id;
|
|
37
35
|
|
|
38
36
|
if (orderProducts) {
|
|
39
37
|
await Promise.all(
|
|
40
38
|
orderProducts.map(({ orderPosition, product }) =>
|
|
41
|
-
modules.orders.positions.addProductItem(orderPosition, { order, product },
|
|
39
|
+
modules.orders.positions.addProductItem(orderPosition, { order, product }, unchainedAPI),
|
|
42
40
|
),
|
|
43
41
|
);
|
|
44
42
|
} else {
|
|
@@ -51,18 +49,18 @@ const generateOrder = async (
|
|
|
51
49
|
order,
|
|
52
50
|
product,
|
|
53
51
|
},
|
|
54
|
-
|
|
52
|
+
unchainedAPI,
|
|
55
53
|
);
|
|
56
54
|
}
|
|
57
55
|
|
|
58
56
|
const { paymentProviderId, context: paymentContext } = enrollment.payment;
|
|
59
57
|
|
|
60
58
|
if (paymentProviderId) {
|
|
61
|
-
await modules.orders.setPaymentProvider(orderId, paymentProviderId,
|
|
59
|
+
await modules.orders.setPaymentProvider(orderId, paymentProviderId, unchainedAPI);
|
|
62
60
|
}
|
|
63
61
|
const { deliveryProviderId, context: deliveryContext } = enrollment.delivery;
|
|
64
62
|
if (deliveryProviderId) {
|
|
65
|
-
await modules.orders.setDeliveryProvider(orderId, deliveryProviderId,
|
|
63
|
+
await modules.orders.setDeliveryProvider(orderId, deliveryProviderId, unchainedAPI);
|
|
66
64
|
}
|
|
67
65
|
|
|
68
66
|
order = await modules.orders.checkout(
|
|
@@ -72,7 +70,7 @@ const generateOrder = async (
|
|
|
72
70
|
deliveryContext,
|
|
73
71
|
orderContext,
|
|
74
72
|
},
|
|
75
|
-
|
|
73
|
+
unchainedAPI,
|
|
76
74
|
);
|
|
77
75
|
|
|
78
76
|
return order;
|
|
@@ -86,8 +84,8 @@ const GenerateOrderWorker: IWorkerAdapter<any, any> = {
|
|
|
86
84
|
version: '1.0.0',
|
|
87
85
|
type: 'ENROLLMENT_ORDER_GENERATOR',
|
|
88
86
|
|
|
89
|
-
doWork: async (input,
|
|
90
|
-
const { modules } =
|
|
87
|
+
doWork: async (input, unchainedAPI) => {
|
|
88
|
+
const { modules } = unchainedAPI;
|
|
91
89
|
|
|
92
90
|
const enrollments = await modules.enrollments.findEnrollments({
|
|
93
91
|
status: [EnrollmentStatus.ACTIVE, EnrollmentStatus.PAUSED],
|
|
@@ -97,7 +95,7 @@ const GenerateOrderWorker: IWorkerAdapter<any, any> = {
|
|
|
97
95
|
await Promise.all(
|
|
98
96
|
enrollments.map(async (enrollment) => {
|
|
99
97
|
try {
|
|
100
|
-
const director = await EnrollmentDirector.actions({ enrollment },
|
|
98
|
+
const director = await EnrollmentDirector.actions({ enrollment }, unchainedAPI);
|
|
101
99
|
const period = await director.nextPeriod();
|
|
102
100
|
if (period) {
|
|
103
101
|
const configuration = await director.configurationForOrder({
|
|
@@ -105,7 +103,7 @@ const GenerateOrderWorker: IWorkerAdapter<any, any> = {
|
|
|
105
103
|
period,
|
|
106
104
|
});
|
|
107
105
|
if (configuration) {
|
|
108
|
-
const order = await generateOrder(enrollment, configuration,
|
|
106
|
+
const order = await generateOrder(enrollment, configuration, unchainedAPI);
|
|
109
107
|
if (order) {
|
|
110
108
|
await modules.enrollments.addEnrollmentPeriod(enrollment._id, {
|
|
111
109
|
...period,
|
package/src/worker/message.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { IWorkerAdapter, Work } from '@unchainedshop/types/worker';
|
|
|
2
2
|
import { MessagingDirector } from '@unchainedshop/core-messaging';
|
|
3
3
|
import { WorkerAdapter, WorkerDirector } from '@unchainedshop/core-worker';
|
|
4
4
|
import { createLogger } from '@unchainedshop/logger';
|
|
5
|
-
import { Context } from '@unchainedshop/types/api';
|
|
6
5
|
|
|
7
6
|
export const messagingLogger = createLogger('unchained:core-messaging');
|
|
8
7
|
|
|
@@ -17,7 +16,7 @@ export const MessageWorker: IWorkerAdapter<
|
|
|
17
16
|
version: '1.0.0',
|
|
18
17
|
type: 'MESSAGE',
|
|
19
18
|
|
|
20
|
-
doWork: async ({ template, ...payload },
|
|
19
|
+
doWork: async ({ template, ...payload }, unchainedAPI, workId) => {
|
|
21
20
|
try {
|
|
22
21
|
const templateResolver = MessagingDirector.getTemplate(template);
|
|
23
22
|
|
|
@@ -26,19 +25,16 @@ export const MessageWorker: IWorkerAdapter<
|
|
|
26
25
|
template,
|
|
27
26
|
...payload,
|
|
28
27
|
},
|
|
29
|
-
|
|
28
|
+
unchainedAPI,
|
|
30
29
|
);
|
|
31
30
|
|
|
32
31
|
if (workConfigurations.length > 0) {
|
|
33
32
|
const forked = await Promise.all(
|
|
34
33
|
workConfigurations.map(async (workConfiguration: any) => {
|
|
35
|
-
const work = await
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
},
|
|
40
|
-
null,
|
|
41
|
-
);
|
|
34
|
+
const work = await unchainedAPI.modules.worker.addWork({
|
|
35
|
+
...workConfiguration,
|
|
36
|
+
originalWorkId: workId,
|
|
37
|
+
});
|
|
42
38
|
delete work.input;
|
|
43
39
|
return work;
|
|
44
40
|
}),
|
|
@@ -23,15 +23,15 @@ const UpdateCoinbaseRates: IWorkerAdapter<any, any> = {
|
|
|
23
23
|
version: '1.0.0',
|
|
24
24
|
type: 'UPDATE_COINBASE_RATES',
|
|
25
25
|
|
|
26
|
-
doWork: async (input,
|
|
27
|
-
const { modules, services } =
|
|
26
|
+
doWork: async (input, unchainedAPI) => {
|
|
27
|
+
const { modules, services } = unchainedAPI;
|
|
28
28
|
|
|
29
29
|
try {
|
|
30
30
|
const currencyCode = await services.countries.resolveDefaultCurrencyCode(
|
|
31
31
|
{
|
|
32
32
|
isoCode: systemLocale.country,
|
|
33
33
|
},
|
|
34
|
-
|
|
34
|
+
unchainedAPI,
|
|
35
35
|
);
|
|
36
36
|
|
|
37
37
|
const currencies = await modules.currencies.findCurrencies({ includeInactive: true });
|
|
@@ -32,8 +32,8 @@ const UpdateECBRates: IWorkerAdapter<any, any> = {
|
|
|
32
32
|
version: '1.0.0',
|
|
33
33
|
type: 'UPDATE_ECB_RATES',
|
|
34
34
|
|
|
35
|
-
doWork: async (input,
|
|
36
|
-
const { modules } =
|
|
35
|
+
doWork: async (input, unchainedAPI) => {
|
|
36
|
+
const { modules } = unchainedAPI;
|
|
37
37
|
|
|
38
38
|
try {
|
|
39
39
|
const data: Array<{ currency: string; rate: string }> = await getExchangeRates();
|
|
@@ -28,8 +28,8 @@ export const RefreshTokens: IWorkerAdapter<void, any> = {
|
|
|
28
28
|
type: 'REFRESH_TOKENS',
|
|
29
29
|
external: false,
|
|
30
30
|
|
|
31
|
-
async doWork(input,
|
|
32
|
-
const { modules } =
|
|
31
|
+
async doWork(input, unchainedAPI) {
|
|
32
|
+
const { modules } = unchainedAPI;
|
|
33
33
|
|
|
34
34
|
const tokens = await modules.warehousing.findTokens({});
|
|
35
35
|
const users = await modules.users.findUsers({ includeGuests: true });
|
|
@@ -48,19 +48,16 @@ export const RefreshTokens: IWorkerAdapter<void, any> = {
|
|
|
48
48
|
return { success: true, result: {} };
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
const forked = await modules.worker.addWork(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
accounts: [...new Set(accounts)],
|
|
59
|
-
},
|
|
51
|
+
const forked = await modules.worker.addWork({
|
|
52
|
+
type: 'UPDATE_TOKEN_OWNERSHIP',
|
|
53
|
+
retries: 0,
|
|
54
|
+
input: {
|
|
55
|
+
filter: {
|
|
56
|
+
tokens,
|
|
57
|
+
accounts: [...new Set(accounts)],
|
|
60
58
|
},
|
|
61
59
|
},
|
|
62
|
-
|
|
63
|
-
);
|
|
60
|
+
});
|
|
64
61
|
return { success: true, result: { forked } };
|
|
65
62
|
},
|
|
66
63
|
};
|
|
@@ -4,8 +4,6 @@ import { createLogger } from '@unchainedshop/logger';
|
|
|
4
4
|
|
|
5
5
|
const logger = createLogger('unchained:platform:zombie-killer');
|
|
6
6
|
|
|
7
|
-
const mapId = (a: any) => a._id;
|
|
8
|
-
|
|
9
7
|
export const ZombieKillerWorker: IWorkerAdapter<
|
|
10
8
|
never,
|
|
11
9
|
{
|
|
@@ -27,22 +25,43 @@ export const ZombieKillerWorker: IWorkerAdapter<
|
|
|
27
25
|
try {
|
|
28
26
|
const error = false;
|
|
29
27
|
|
|
30
|
-
// Remove unreferenced
|
|
28
|
+
// Remove unreferenced filter entities
|
|
29
|
+
const filters = await modules.filters.findFilters(
|
|
30
|
+
{ includeInactive: true },
|
|
31
|
+
{ projection: { _id: 1 } },
|
|
32
|
+
);
|
|
33
|
+
const filterIds = filters.map((a) => a._id);
|
|
34
|
+
const deletedFilterTextsCount = await modules.filters.texts.deleteMany({
|
|
35
|
+
excludedFilterIds: filterIds,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Remove unreferenced assortment entities
|
|
31
39
|
const assortments = await modules.assortments.findAssortments(
|
|
32
40
|
{ includeInactive: true, includeLeaves: true },
|
|
33
41
|
{ projection: { _id: 1 } },
|
|
34
42
|
);
|
|
43
|
+
const assortmentIds = assortments.map((a) => a._id);
|
|
44
|
+
const deletedAssortmentTextsCount = await modules.assortments.texts.deleteMany({
|
|
45
|
+
excludedAssortmentIds: assortmentIds,
|
|
46
|
+
});
|
|
35
47
|
const deletedAssortmentMediaCount = await modules.assortments.media.deleteMediaFiles({
|
|
36
|
-
excludedAssortmentIds:
|
|
48
|
+
excludedAssortmentIds: assortmentIds,
|
|
37
49
|
});
|
|
38
50
|
|
|
39
|
-
// Remove unreferenced product
|
|
51
|
+
// Remove unreferenced product entities
|
|
40
52
|
const products = await modules.products.findProducts(
|
|
41
53
|
{ includeDrafts: true },
|
|
42
54
|
{ projection: { _id: 1 } },
|
|
43
55
|
);
|
|
56
|
+
const productIds = products.map((a) => a._id);
|
|
57
|
+
const deletedProductTextsCount = await modules.products.texts.deleteMany({
|
|
58
|
+
excludedProductIds: productIds,
|
|
59
|
+
});
|
|
60
|
+
const deletedProductVariationsCount = await modules.products.variations.deleteVariations({
|
|
61
|
+
excludedProductIds: productIds,
|
|
62
|
+
});
|
|
44
63
|
const deletedProductMediaCount = await modules.products.media.deleteMediaFiles({
|
|
45
|
-
excludedProductIds:
|
|
64
|
+
excludedProductIds: productIds,
|
|
46
65
|
});
|
|
47
66
|
|
|
48
67
|
// Remove unreferenced files
|
|
@@ -61,7 +80,7 @@ export const ZombieKillerWorker: IWorkerAdapter<
|
|
|
61
80
|
{ path: { $in: ['product-media', 'assortment-media'] } },
|
|
62
81
|
{ projection: { _id: 1 } },
|
|
63
82
|
)
|
|
64
|
-
).map(
|
|
83
|
+
).map((a) => a._id);
|
|
65
84
|
|
|
66
85
|
const fileIdsToRemove = allFileIdsRelevant.filter((fileId) => {
|
|
67
86
|
return !allFileIdsLinked.includes(fileId);
|
|
@@ -81,8 +100,12 @@ export const ZombieKillerWorker: IWorkerAdapter<
|
|
|
81
100
|
|
|
82
101
|
// Return delete count
|
|
83
102
|
const result = {
|
|
103
|
+
deletedFilterTextsCount,
|
|
84
104
|
deletedProductMediaCount,
|
|
105
|
+
deletedProductTextsCount,
|
|
106
|
+
deletedProductVariationsCount,
|
|
85
107
|
deletedAssortmentMediaCount,
|
|
108
|
+
deletedAssortmentTextsCount,
|
|
86
109
|
deletedFilesCount,
|
|
87
110
|
};
|
|
88
111
|
|