@unchainedshop/plugins 2.0.0-beta7 → 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/db/AppleTransactionsCollection.d.ts +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/braintree.js +14 -12
- package/lib/payment/braintree.js.map +1 -1
- package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts +1 -1
- package/lib/payment/cryptopay/middleware.js +1 -1
- package/lib/payment/cryptopay/middleware.js.map +1 -1
- package/lib/payment/datatrans-v2/getPaths.d.ts +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/postfinance-checkout/types.d.ts +3 -3
- 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/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.js +3 -2
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.js.map +1 -1
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.d.ts +1 -1
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.d.ts +2 -2
- package/lib/plugins-index.d.ts +4 -1
- package/lib/plugins-index.js +11 -11
- package/lib/plugins-index.js.map +1 -1
- package/lib/pricing/utils/cache.d.ts +2 -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 +35 -30
- package/lib/worker/zombie-killer.js.map +1 -1
- package/package.json +27 -23
- 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/braintree.ts +14 -12
- package/src/payment/cryptopay/middleware.ts +1 -1
- 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/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.ts +3 -2
- package/src/plugins-index.ts +15 -11
- 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 +58 -32
- package/tests/plugins-index.test.js +3 -0
|
@@ -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,10 +4,6 @@ import { createLogger } from '@unchainedshop/logger';
|
|
|
4
4
|
|
|
5
5
|
const logger = createLogger('unchained:platform:zombie-killer');
|
|
6
6
|
|
|
7
|
-
const findId = { projection: { _id: 1 } };
|
|
8
|
-
const findFileId = { projection: { mediaId: 1 } };
|
|
9
|
-
const mapId = (a: any) => a._id;
|
|
10
|
-
|
|
11
7
|
export const ZombieKillerWorker: IWorkerAdapter<
|
|
12
8
|
never,
|
|
13
9
|
{
|
|
@@ -29,42 +25,68 @@ export const ZombieKillerWorker: IWorkerAdapter<
|
|
|
29
25
|
try {
|
|
30
26
|
const error = false;
|
|
31
27
|
|
|
32
|
-
// Remove unreferenced
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
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
36
|
});
|
|
37
37
|
|
|
38
|
-
// Remove unreferenced assortment
|
|
39
|
-
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);
|
|
44
|
+
const deletedAssortmentTextsCount = await modules.assortments.texts.deleteMany({
|
|
45
|
+
excludedAssortmentIds: assortmentIds,
|
|
46
|
+
});
|
|
40
47
|
const deletedAssortmentMediaCount = await modules.assortments.media.deleteMediaFiles({
|
|
41
|
-
excludedAssortmentIds:
|
|
48
|
+
excludedAssortmentIds: assortmentIds,
|
|
42
49
|
});
|
|
43
50
|
|
|
44
|
-
// Remove unreferenced
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
},
|
|
51
|
+
// Remove unreferenced product entities
|
|
52
|
+
const products = await modules.products.findProducts(
|
|
53
|
+
{ includeDrafts: true },
|
|
54
|
+
{ projection: { _id: 1 } },
|
|
55
|
+
);
|
|
56
|
+
const productIds = products.map((a) => a._id);
|
|
57
|
+
const deletedProductTextsCount = await modules.products.texts.deleteMany({
|
|
58
|
+
excludedProductIds: productIds,
|
|
53
59
|
});
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
const deletedProductVariationsCount = await modules.products.variations.deleteVariations({
|
|
61
|
+
excludedProductIds: productIds,
|
|
62
|
+
});
|
|
63
|
+
const deletedProductMediaCount = await modules.products.media.deleteMediaFiles({
|
|
64
|
+
excludedProductIds: productIds,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// Remove unreferenced files
|
|
68
|
+
const productMedia = await modules.products.media.findProductMedias(
|
|
69
|
+
{},
|
|
70
|
+
{ projection: { mediaId: 1 } },
|
|
71
|
+
);
|
|
72
|
+
const assortmentMedia = await modules.assortments.media.findAssortmentMedias(
|
|
73
|
+
{},
|
|
74
|
+
{ projection: { mediaId: 1 } },
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const allFileIdsLinked = [...productMedia, ...assortmentMedia].map((l) => l?.mediaId);
|
|
78
|
+
const allFileIdsRelevant = (
|
|
79
|
+
await modules.files.findFiles(
|
|
80
|
+
{ path: { $in: ['product-media', 'assortment-media'] } },
|
|
81
|
+
{ projection: { _id: 1 } },
|
|
82
|
+
)
|
|
83
|
+
).map((a) => a._id);
|
|
84
|
+
|
|
85
|
+
const fileIdsToRemove = allFileIdsRelevant.filter((fileId) => {
|
|
86
|
+
return !allFileIdsLinked.includes(fileId);
|
|
58
87
|
});
|
|
59
88
|
|
|
60
|
-
|
|
61
|
-
.concat(filesWithAssortmentId)
|
|
62
|
-
.filter((file) => {
|
|
63
|
-
const fileInProductMedia = productMedia.some((media) => media.mediaId === file._id);
|
|
64
|
-
const fileInAssortmentMedia = assortmentMedia.some((media) => media.mediaId === file._id);
|
|
65
|
-
return !fileInProductMedia && !fileInAssortmentMedia;
|
|
66
|
-
})
|
|
67
|
-
.forEach((m) => fileIdsToRemove.push(m._id));
|
|
89
|
+
logger.verbose(`File Id's to remove: ${fileIdsToRemove.join(', ')}`);
|
|
68
90
|
|
|
69
91
|
const deletedFilesCount =
|
|
70
92
|
fileIdsToRemove.length > 0
|
|
@@ -78,8 +100,12 @@ export const ZombieKillerWorker: IWorkerAdapter<
|
|
|
78
100
|
|
|
79
101
|
// Return delete count
|
|
80
102
|
const result = {
|
|
103
|
+
deletedFilterTextsCount,
|
|
81
104
|
deletedProductMediaCount,
|
|
105
|
+
deletedProductTextsCount,
|
|
106
|
+
deletedProductVariationsCount,
|
|
82
107
|
deletedAssortmentMediaCount,
|
|
108
|
+
deletedAssortmentTextsCount,
|
|
83
109
|
deletedFilesCount,
|
|
84
110
|
};
|
|
85
111
|
|