@unchainedshop/plugins 4.6.0 → 4.6.2
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/post/adapter.d.ts +2 -0
- package/lib/delivery/post/adapter.js +22 -0
- package/lib/delivery/post/index.d.ts +4 -0
- package/lib/delivery/post/index.js +10 -0
- package/lib/delivery/send-message/adapter.d.ts +2 -0
- package/lib/delivery/send-message/adapter.js +39 -0
- package/lib/delivery/send-message/index.d.ts +4 -0
- package/lib/delivery/send-message/index.js +10 -0
- package/lib/delivery/stores/adapter.d.ts +2 -0
- package/lib/delivery/stores/adapter.js +42 -0
- package/lib/delivery/stores/index.d.ts +4 -0
- package/lib/delivery/stores/index.js +10 -0
- package/lib/enrollments/licensed/adapter.d.ts +6 -0
- package/lib/enrollments/licensed/adapter.js +51 -0
- package/lib/enrollments/licensed/index.d.ts +4 -0
- package/lib/enrollments/licensed/index.js +10 -0
- package/lib/files/gridfs/api.d.ts +7 -0
- package/lib/files/gridfs/api.js +163 -0
- package/lib/files/minio/adapter.d.ts +4 -0
- package/lib/files/minio/adapter.js +160 -0
- package/lib/files/minio/api.d.ts +2 -0
- package/lib/files/minio/api.js +41 -0
- package/lib/files/temp-upload/api.d.ts +6 -0
- package/lib/files/temp-upload/api.js +49 -0
- package/lib/files/temp-upload/index.d.ts +3 -0
- package/lib/files/temp-upload/index.js +15 -0
- package/lib/filters/local-search/adapter.d.ts +2 -0
- package/lib/filters/local-search/adapter.js +56 -0
- package/lib/filters/local-search/index.d.ts +4 -0
- package/lib/filters/local-search/index.js +16 -0
- package/lib/filters/strict-equal/adapter.d.ts +2 -0
- package/lib/filters/strict-equal/adapter.js +23 -0
- package/lib/filters/strict-equal/index.d.ts +4 -0
- package/lib/filters/strict-equal/index.js +10 -0
- package/lib/payment/apple-iap/api.d.ts +2 -0
- package/lib/payment/apple-iap/api.js +119 -0
- package/lib/payment/cryptopay/adapter.d.ts +2 -0
- package/lib/payment/cryptopay/adapter.js +157 -0
- package/lib/payment/cryptopay/api.d.ts +2 -0
- package/lib/payment/cryptopay/api.js +23 -0
- package/lib/payment/datatrans-v2/adapter.d.ts +2 -0
- package/lib/payment/datatrans-v2/adapter.js +406 -0
- package/lib/payment/datatrans-v2/api.d.ts +2 -0
- package/lib/payment/datatrans-v2/api.js +108 -0
- package/lib/payment/invoice/adapter.d.ts +2 -0
- package/lib/payment/invoice/adapter.js +26 -0
- package/lib/payment/invoice/index.d.ts +4 -0
- package/lib/payment/invoice/index.js +10 -0
- package/lib/payment/invoice-prepaid/adapter.d.ts +2 -0
- package/lib/payment/invoice-prepaid/adapter.js +29 -0
- package/lib/payment/invoice-prepaid/index.d.ts +4 -0
- package/lib/payment/invoice-prepaid/index.js +10 -0
- package/lib/payment/payrexx/adapter.d.ts +2 -0
- package/lib/payment/payrexx/adapter.js +161 -0
- package/lib/payment/payrexx/api.d.ts +2 -0
- package/lib/payment/payrexx/api.js +97 -0
- package/lib/payment/postfinance-checkout/adapter.d.ts +2 -0
- package/lib/payment/postfinance-checkout/adapter.js +189 -0
- package/lib/payment/postfinance-checkout/webhook.d.ts +2 -0
- package/lib/payment/postfinance-checkout/webhook.js +48 -0
- package/lib/payment/saferpay/webhook.d.ts +2 -0
- package/lib/payment/saferpay/webhook.js +64 -0
- package/lib/payment/stripe/adapter.d.ts +2 -0
- package/lib/payment/stripe/adapter.js +121 -0
- package/lib/payment/stripe/api.d.ts +6 -0
- package/lib/payment/stripe/api.js +165 -0
- package/lib/payment/stripe/stripe.js +12 -10
- package/lib/presets/base.d.ts +1 -0
- package/lib/presets/base.js +1 -0
- package/lib/pricing/delivery-swiss-tax/adapter.d.ts +3 -0
- package/lib/pricing/delivery-swiss-tax/adapter.js +62 -0
- package/lib/pricing/delivery-swiss-tax/index.d.ts +4 -0
- package/lib/pricing/delivery-swiss-tax/index.js +10 -0
- package/lib/pricing/discount-100-off/adapter.d.ts +3 -0
- package/lib/pricing/discount-100-off/adapter.js +30 -0
- package/lib/pricing/discount-100-off/index.d.ts +4 -0
- package/lib/pricing/discount-100-off/index.js +10 -0
- package/lib/pricing/discount-half-price-manual/adapter.d.ts +3 -0
- package/lib/pricing/discount-half-price-manual/adapter.js +30 -0
- package/lib/pricing/discount-half-price-manual/index.d.ts +4 -0
- package/lib/pricing/discount-half-price-manual/index.js +10 -0
- package/lib/pricing/free-delivery/adapter.d.ts +3 -0
- package/lib/pricing/free-delivery/adapter.js +27 -0
- package/lib/pricing/free-delivery/index.d.ts +4 -0
- package/lib/pricing/free-delivery/index.js +10 -0
- package/lib/pricing/free-payment/adapter.d.ts +3 -0
- package/lib/pricing/free-payment/adapter.js +27 -0
- package/lib/pricing/free-payment/index.d.ts +4 -0
- package/lib/pricing/free-payment/index.js +10 -0
- package/lib/pricing/order-delivery/adapter.d.ts +3 -0
- package/lib/pricing/order-delivery/adapter.js +33 -0
- package/lib/pricing/order-delivery/index.d.ts +4 -0
- package/lib/pricing/order-delivery/index.js +10 -0
- package/lib/pricing/order-discount/adapter.d.ts +3 -0
- package/lib/pricing/order-discount/adapter.js +74 -0
- package/lib/pricing/order-discount/index.d.ts +4 -0
- package/lib/pricing/order-discount/index.js +10 -0
- package/lib/pricing/order-items/adapter.d.ts +3 -0
- package/lib/pricing/order-items/adapter.js +43 -0
- package/lib/pricing/order-items/index.d.ts +4 -0
- package/lib/pricing/order-items/index.js +10 -0
- package/lib/pricing/order-payment/adapter.d.ts +3 -0
- package/lib/pricing/order-payment/adapter.js +33 -0
- package/lib/pricing/order-payment/index.d.ts +4 -0
- package/lib/pricing/order-payment/index.js +10 -0
- package/lib/pricing/product-catalog-price/adapter.d.ts +3 -0
- package/lib/pricing/product-catalog-price/adapter.js +60 -0
- package/lib/pricing/product-catalog-price/index.d.ts +4 -0
- package/lib/pricing/product-catalog-price/index.js +10 -0
- package/lib/pricing/product-discount/adapter.d.ts +3 -0
- package/lib/pricing/product-discount/adapter.js +69 -0
- package/lib/pricing/product-discount/index.d.ts +4 -0
- package/lib/pricing/product-discount/index.js +10 -0
- package/lib/pricing/product-price-rateconversion/adapter.d.ts +3 -0
- package/lib/pricing/product-price-rateconversion/adapter.js +53 -0
- package/lib/pricing/product-price-rateconversion/index.d.ts +4 -0
- package/lib/pricing/product-price-rateconversion/index.js +10 -0
- package/lib/pricing/product-swiss-tax/adapter.d.ts +3 -0
- package/lib/pricing/product-swiss-tax/adapter.js +76 -0
- package/lib/pricing/product-swiss-tax/index.d.ts +4 -0
- package/lib/pricing/product-swiss-tax/index.js +10 -0
- package/lib/quotations/manual/adapter.d.ts +2 -0
- package/lib/quotations/manual/adapter.js +19 -0
- package/lib/quotations/manual/index.d.ts +4 -0
- package/lib/quotations/manual/index.js +10 -0
- package/lib/warehousing/erc-metadata/api.d.ts +12 -0
- package/lib/warehousing/erc-metadata/api.js +43 -0
- package/lib/warehousing/erc-metadata/index.d.ts +3 -0
- package/lib/warehousing/erc-metadata/index.js +15 -0
- package/lib/warehousing/eth-minter/adapter.d.ts +2 -0
- package/lib/warehousing/eth-minter/adapter.js +119 -0
- package/lib/warehousing/eth-minter/index.d.ts +4 -0
- package/lib/warehousing/eth-minter/index.js +10 -0
- package/lib/warehousing/store/adapter.d.ts +2 -0
- package/lib/warehousing/store/adapter.js +33 -0
- package/lib/warehousing/store/index.d.ts +4 -0
- package/lib/warehousing/store/index.js +10 -0
- package/lib/worker/budgetsms/adapter.d.ts +22 -0
- package/lib/worker/budgetsms/adapter.js +169 -0
- package/lib/worker/budgetsms/index.d.ts +4 -0
- package/lib/worker/budgetsms/index.js +10 -0
- package/lib/worker/bulk-export/adapter.d.ts +3 -0
- package/lib/worker/bulk-export/adapter.js +64 -0
- package/lib/worker/bulk-export/index.d.ts +4 -0
- package/lib/worker/bulk-export/index.js +10 -0
- package/lib/worker/bulk-export.d.ts +2 -0
- package/lib/worker/bulk-export.js +64 -0
- package/lib/worker/bulk-import/adapter.d.ts +3 -0
- package/lib/worker/bulk-import/adapter.js +65 -0
- package/lib/worker/bulk-import/api.d.ts +7 -0
- package/lib/worker/bulk-import/api.js +53 -0
- package/lib/worker/bulk-import/index.d.ts +4 -0
- package/lib/worker/bulk-import/index.js +18 -0
- package/lib/worker/bulkgate/adapter.d.ts +12 -0
- package/lib/worker/bulkgate/adapter.js +91 -0
- package/lib/worker/bulkgate/index.d.ts +4 -0
- package/lib/worker/bulkgate/index.js +10 -0
- package/lib/worker/email/adapter.d.ts +9 -0
- package/lib/worker/email/adapter.js +150 -0
- package/lib/worker/email/index.d.ts +4 -0
- package/lib/worker/email/index.js +10 -0
- package/lib/worker/enrollment-order-generator/adapter.d.ts +4 -0
- package/lib/worker/enrollment-order-generator/adapter.js +77 -0
- package/lib/worker/enrollment-order-generator/index.d.ts +4 -0
- package/lib/worker/enrollment-order-generator/index.js +13 -0
- package/lib/worker/error-notifications/adapter.d.ts +10 -0
- package/lib/worker/error-notifications/adapter.js +62 -0
- package/lib/worker/error-notifications/index.d.ts +4 -0
- package/lib/worker/error-notifications/index.js +13 -0
- package/lib/worker/export-token/adapter.d.ts +4 -0
- package/lib/worker/export-token/adapter.js +25 -0
- package/lib/worker/export-token/index.d.ts +4 -0
- package/lib/worker/export-token/index.js +13 -0
- package/lib/worker/external/adapter.d.ts +3 -0
- package/lib/worker/external/adapter.js +13 -0
- package/lib/worker/external/index.d.ts +4 -0
- package/lib/worker/external/index.js +10 -0
- package/lib/worker/heartbeat/adapter.d.ts +8 -0
- package/lib/worker/heartbeat/adapter.js +26 -0
- package/lib/worker/heartbeat/index.d.ts +4 -0
- package/lib/worker/heartbeat/index.js +10 -0
- package/lib/worker/http-request/adapter.d.ts +8 -0
- package/lib/worker/http-request/adapter.js +55 -0
- package/lib/worker/http-request/index.d.ts +4 -0
- package/lib/worker/http-request/index.js +10 -0
- package/lib/worker/message/adapter.d.ts +11 -0
- package/lib/worker/message/adapter.js +42 -0
- package/lib/worker/message/index.d.ts +4 -0
- package/lib/worker/message/index.js +10 -0
- package/lib/worker/push-notification/adapter.d.ts +9 -0
- package/lib/worker/push-notification/adapter.js +87 -0
- package/lib/worker/push-notification/index.d.ts +4 -0
- package/lib/worker/push-notification/index.js +10 -0
- package/lib/worker/twilio/adapter.d.ts +8 -0
- package/lib/worker/twilio/adapter.js +59 -0
- package/lib/worker/twilio/index.d.ts +4 -0
- package/lib/worker/twilio/index.js +10 -0
- package/lib/worker/update-coinbase-rates/adapter.d.ts +4 -0
- package/lib/worker/update-coinbase-rates/adapter.js +61 -0
- package/lib/worker/update-coinbase-rates/index.d.ts +4 -0
- package/lib/worker/update-coinbase-rates/index.js +13 -0
- package/lib/worker/update-ecb-rates/adapter.d.ts +4 -0
- package/lib/worker/update-ecb-rates/adapter.js +94 -0
- package/lib/worker/update-ecb-rates/index.d.ts +4 -0
- package/lib/worker/update-ecb-rates/index.js +13 -0
- package/lib/worker/update-token-ownership/adapter.d.ts +5 -0
- package/lib/worker/update-token-ownership/adapter.js +58 -0
- package/lib/worker/update-token-ownership/index.d.ts +4 -0
- package/lib/worker/update-token-ownership/index.js +13 -0
- package/lib/worker/zombie-killer/adapter.d.ts +13 -0
- package/lib/worker/zombie-killer/adapter.js +90 -0
- package/lib/worker/zombie-killer/index.d.ts +4 -0
- package/lib/worker/zombie-killer/index.js +10 -0
- package/package.json +1 -1
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { WorkerAdapter, WorkerDirector, schedule } from '@unchainedshop/core';
|
|
2
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
3
|
+
const logger = createLogger('unchained:worker:update-ecb-rates');
|
|
4
|
+
let xml2json;
|
|
5
|
+
try {
|
|
6
|
+
const module = await import('xml-js');
|
|
7
|
+
xml2json = module.xml2json;
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
logger.warn(`optional peer npm package 'xml-js' not installed, skipped ECB rate updates`);
|
|
11
|
+
}
|
|
12
|
+
const getExchangeRates = async () => {
|
|
13
|
+
return fetch(`https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml`, {
|
|
14
|
+
method: 'GET',
|
|
15
|
+
})
|
|
16
|
+
.then((res) => res.text())
|
|
17
|
+
.then((text) => JSON.parse(xml2json(text)))
|
|
18
|
+
.then((json) => json.elements?.[0]?.elements
|
|
19
|
+
.filter((e) => e.name.toLowerCase() === 'cube')[0]
|
|
20
|
+
?.elements[0]?.elements.map((element) => element.attributes));
|
|
21
|
+
};
|
|
22
|
+
const everyDayAtFour = schedule.parse.cron('0 15 * * *');
|
|
23
|
+
const baseCurrency = 'EUR';
|
|
24
|
+
export const UpdateECBRates = {
|
|
25
|
+
...WorkerAdapter,
|
|
26
|
+
key: 'shop.unchained.worker.update-ecb-rates',
|
|
27
|
+
label: 'Update ECB Rates',
|
|
28
|
+
version: '1.0.0',
|
|
29
|
+
type: 'UPDATE_ECB_RATES',
|
|
30
|
+
doWork: async (input, unchainedAPI) => {
|
|
31
|
+
const { modules } = unchainedAPI;
|
|
32
|
+
if (!xml2json) {
|
|
33
|
+
return {
|
|
34
|
+
success: false,
|
|
35
|
+
error: {
|
|
36
|
+
name: 'XML2JSON_NOT_INSTALLED',
|
|
37
|
+
message: 'npm dependency xml2json is not installed, please install it to use this worker',
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const data = await getExchangeRates();
|
|
43
|
+
const timestamp = new Date();
|
|
44
|
+
const expiresAt = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
|
|
45
|
+
const currencies = await modules.currencies.findCurrencies({ includeInactive: true });
|
|
46
|
+
const currencyCodes = currencies.map((currency) => currency.isoCode);
|
|
47
|
+
if (!currencyCodes.includes(baseCurrency))
|
|
48
|
+
return {
|
|
49
|
+
success: true,
|
|
50
|
+
result: {
|
|
51
|
+
ratesUpdated: 0,
|
|
52
|
+
info: 'EUR not enabled',
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
const rates = data
|
|
56
|
+
.map((d) => {
|
|
57
|
+
return {
|
|
58
|
+
baseCurrency,
|
|
59
|
+
quoteCurrency: d.currency,
|
|
60
|
+
rate: parseFloat(d.rate),
|
|
61
|
+
timestamp,
|
|
62
|
+
expiresAt,
|
|
63
|
+
};
|
|
64
|
+
})
|
|
65
|
+
.filter((rate) => currencyCodes.includes(rate.quoteCurrency) && rate.quoteCurrency !== rate.baseCurrency);
|
|
66
|
+
const success = await modules.products.prices.rates.updateRates(rates);
|
|
67
|
+
return {
|
|
68
|
+
success,
|
|
69
|
+
result: {
|
|
70
|
+
ratesUpdated: rates.length,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return {
|
|
76
|
+
success: false,
|
|
77
|
+
error: {
|
|
78
|
+
name: 'UPDATE_ECB_RATES_FAILED',
|
|
79
|
+
message: 'Updating ECB Rates failed',
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
export default UpdateECBRates;
|
|
86
|
+
export const configureUpdateECBRatesAutoscheduling = () => {
|
|
87
|
+
if (xml2json) {
|
|
88
|
+
WorkerDirector.configureAutoscheduling({
|
|
89
|
+
type: UpdateECBRates.type,
|
|
90
|
+
schedule: everyDayAtFour,
|
|
91
|
+
retries: 5,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {} from '@unchainedshop/core';
|
|
2
|
+
import { UpdateECBRates, configureUpdateECBRatesAutoscheduling } from "./adapter.js";
|
|
3
|
+
export const UpdateECBRatesPlugin = {
|
|
4
|
+
key: 'shop.unchained.worker.update-ecb-rates',
|
|
5
|
+
label: 'Update ECB Rates Worker Plugin',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
adapters: [UpdateECBRates],
|
|
8
|
+
onRegister: () => {
|
|
9
|
+
configureUpdateECBRatesAutoscheduling();
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
export default UpdateECBRatesPlugin;
|
|
13
|
+
export { UpdateECBRates, configureUpdateECBRatesAutoscheduling } from "./adapter.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type IWorkerAdapter } from '@unchainedshop/core';
|
|
2
|
+
export declare const UpdateTokenOwnership: IWorkerAdapter<void, void>;
|
|
3
|
+
export declare const RefreshTokens: IWorkerAdapter<void, any>;
|
|
4
|
+
export default UpdateTokenOwnership;
|
|
5
|
+
export declare const configureRefreshTokensAutoscheduling: () => void;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { WorkerAdapter, WorkerDirector, schedule } from '@unchainedshop/core';
|
|
2
|
+
const everyMinute = schedule.parse.cron('* * * * *');
|
|
3
|
+
export const UpdateTokenOwnership = {
|
|
4
|
+
...WorkerAdapter,
|
|
5
|
+
key: 'shop.unchained.worker-plugin.update-token-ownership',
|
|
6
|
+
label: 'External worker to update ownership of provided tokens',
|
|
7
|
+
version: '1.0.0',
|
|
8
|
+
type: 'UPDATE_TOKEN_OWNERSHIP',
|
|
9
|
+
external: true,
|
|
10
|
+
async doWork() {
|
|
11
|
+
throw new Error('Cannot do work for external workers');
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
export const RefreshTokens = {
|
|
15
|
+
...WorkerAdapter,
|
|
16
|
+
key: 'shop.unchained.worker-plugin.refresh-tokens',
|
|
17
|
+
label: 'Worker to refresh tokens for accounts',
|
|
18
|
+
version: '1.0.0',
|
|
19
|
+
type: 'REFRESH_TOKENS',
|
|
20
|
+
external: false,
|
|
21
|
+
async doWork(input, unchainedAPI) {
|
|
22
|
+
const { modules } = unchainedAPI;
|
|
23
|
+
const tokens = await modules.warehousing.findTokens({ walletAddressExists: true });
|
|
24
|
+
const users = await modules.users.findUsers({ includeGuests: true, web3Verified: true });
|
|
25
|
+
const accounts = users.flatMap((user) => {
|
|
26
|
+
return user?.services?.web3?.flatMap((service) => {
|
|
27
|
+
if (service.verified)
|
|
28
|
+
return [service.address];
|
|
29
|
+
return [];
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
tokens.forEach((token) => {
|
|
33
|
+
accounts.push(token.walletAddress);
|
|
34
|
+
});
|
|
35
|
+
if (!tokens?.length) {
|
|
36
|
+
return { success: true, result: {} };
|
|
37
|
+
}
|
|
38
|
+
const forked = await modules.worker.addWork({
|
|
39
|
+
type: 'UPDATE_TOKEN_OWNERSHIP',
|
|
40
|
+
retries: 0,
|
|
41
|
+
input: {
|
|
42
|
+
filter: {
|
|
43
|
+
tokens,
|
|
44
|
+
accounts: [...new Set(accounts)],
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
return { success: true, result: { forked } };
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
export default UpdateTokenOwnership;
|
|
52
|
+
export const configureRefreshTokensAutoscheduling = () => {
|
|
53
|
+
WorkerDirector.configureAutoscheduling({
|
|
54
|
+
type: RefreshTokens.type,
|
|
55
|
+
schedule: everyMinute,
|
|
56
|
+
retries: 0,
|
|
57
|
+
});
|
|
58
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {} from '@unchainedshop/core';
|
|
2
|
+
import { UpdateTokenOwnership, RefreshTokens, configureRefreshTokensAutoscheduling } from "./adapter.js";
|
|
3
|
+
export const UpdateTokenOwnershipPlugin = {
|
|
4
|
+
key: 'shop.unchained.worker.update-token-ownership',
|
|
5
|
+
label: 'Update Token Ownership Worker Plugin',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
adapters: [UpdateTokenOwnership, RefreshTokens],
|
|
8
|
+
onRegister: () => {
|
|
9
|
+
configureRefreshTokensAutoscheduling();
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
export default UpdateTokenOwnershipPlugin;
|
|
13
|
+
export { UpdateTokenOwnership, RefreshTokens, configureRefreshTokensAutoscheduling } from "./adapter.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type IWorkerAdapter } from '@unchainedshop/core';
|
|
2
|
+
export declare const ZombieKillerWorker: IWorkerAdapter<{
|
|
3
|
+
bulkImportMaxAgeInDays: number;
|
|
4
|
+
}, {
|
|
5
|
+
deletedProductMediaCount: number;
|
|
6
|
+
deletedAssortmentMediaCount: number;
|
|
7
|
+
deletedFilesCount: number;
|
|
8
|
+
deletedFilterTextsCount: number;
|
|
9
|
+
deletedProductTextsCount: number;
|
|
10
|
+
deletedProductVariationsCount: number;
|
|
11
|
+
deletedAssortmentTextsCount: number;
|
|
12
|
+
}>;
|
|
13
|
+
export default ZombieKillerWorker;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { WorkerAdapter } from '@unchainedshop/core';
|
|
2
|
+
export const ZombieKillerWorker = {
|
|
3
|
+
...WorkerAdapter,
|
|
4
|
+
key: 'shop.unchained.worker-plugin.zombie-killer',
|
|
5
|
+
label: 'Zombie Killer',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
type: 'ZOMBIE_KILLER',
|
|
8
|
+
doWork: async ({ bulkImportMaxAgeInDays } = { bulkImportMaxAgeInDays: 5 }, unchainedAPI) => {
|
|
9
|
+
const { modules, services } = unchainedAPI;
|
|
10
|
+
try {
|
|
11
|
+
const error = false;
|
|
12
|
+
const filters = await modules.filters.findFilters({ includeInactive: true }, { projection: { _id: 1 } });
|
|
13
|
+
const filterIds = filters.map((a) => a._id);
|
|
14
|
+
const deletedFilterTextsCount = await modules.filters.texts.deleteMany({
|
|
15
|
+
excludedFilterIds: filterIds,
|
|
16
|
+
});
|
|
17
|
+
const assortments = await modules.assortments.findAssortments({
|
|
18
|
+
includeInactive: true,
|
|
19
|
+
includeLeaves: true,
|
|
20
|
+
});
|
|
21
|
+
const assortmentIds = assortments.map((a) => a._id);
|
|
22
|
+
const deletedAssortmentTextsCount = await modules.assortments.texts.deleteMany({
|
|
23
|
+
excludedAssortmentIds: assortmentIds,
|
|
24
|
+
});
|
|
25
|
+
const deletedAssortmentMediaCount = await modules.assortments.media.deleteMediaFiles({
|
|
26
|
+
excludedAssortmentIds: assortmentIds,
|
|
27
|
+
});
|
|
28
|
+
const productIds = await modules.products.findProductIds({ includeDrafts: true });
|
|
29
|
+
const deletedProductTextsCount = await modules.products.texts.deleteMany({
|
|
30
|
+
excludedProductIds: productIds,
|
|
31
|
+
});
|
|
32
|
+
const deletedProductVariationsCount = await modules.products.variations.deleteVariations({
|
|
33
|
+
excludedProductIds: productIds,
|
|
34
|
+
});
|
|
35
|
+
const deletedProductMediaCount = await modules.products.media.deleteMediaFiles({
|
|
36
|
+
excludedProductIds: productIds,
|
|
37
|
+
});
|
|
38
|
+
const productMedia = await modules.products.media.findProductMedias({}, { projection: { mediaId: 1 } });
|
|
39
|
+
const assortmentMedia = await modules.assortments.media.findAssortmentMedias({}, { projection: { mediaId: 1 } });
|
|
40
|
+
const allFileIdsLinked = [...productMedia, ...assortmentMedia].map((l) => l?.mediaId);
|
|
41
|
+
const allFileIdsRelevant = (await modules.files.findFiles({ paths: ['product-media', 'assortment-media'] }, { projection: { _id: 1 } })).map((a) => a._id);
|
|
42
|
+
const fileIdsToRemove = allFileIdsRelevant.filter((fileId) => {
|
|
43
|
+
return !allFileIdsLinked.includes(fileId);
|
|
44
|
+
}) || [];
|
|
45
|
+
const bulkImportMedia = await await modules.files.findFiles({
|
|
46
|
+
path: 'bulk-import-streams',
|
|
47
|
+
createdBefore: new Date(Date.now() - 1000 * 60 * 60 * 24 * bulkImportMaxAgeInDays),
|
|
48
|
+
});
|
|
49
|
+
bulkImportMedia.forEach(async (media) => {
|
|
50
|
+
fileIdsToRemove.push(media._id);
|
|
51
|
+
});
|
|
52
|
+
const deletedFilesCount = fileIdsToRemove.length > 0
|
|
53
|
+
? await services.files.removeFiles({
|
|
54
|
+
fileIds: fileIdsToRemove,
|
|
55
|
+
})
|
|
56
|
+
: 0;
|
|
57
|
+
const result = {
|
|
58
|
+
deletedFilterTextsCount,
|
|
59
|
+
deletedProductMediaCount,
|
|
60
|
+
deletedProductTextsCount,
|
|
61
|
+
deletedProductVariationsCount,
|
|
62
|
+
deletedAssortmentMediaCount,
|
|
63
|
+
deletedAssortmentTextsCount,
|
|
64
|
+
deletedFilesCount,
|
|
65
|
+
};
|
|
66
|
+
if (error) {
|
|
67
|
+
return {
|
|
68
|
+
success: false,
|
|
69
|
+
result,
|
|
70
|
+
error,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
success: true,
|
|
75
|
+
result,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
return {
|
|
80
|
+
success: false,
|
|
81
|
+
error: {
|
|
82
|
+
name: err.name,
|
|
83
|
+
message: err.message,
|
|
84
|
+
stack: err.stack,
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
export default ZombieKillerWorker;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {} from '@unchainedshop/core';
|
|
2
|
+
import { ZombieKillerWorker } from "./adapter.js";
|
|
3
|
+
export const ZombieKillerPlugin = {
|
|
4
|
+
key: 'shop.unchained.worker-plugin.zombie-killer',
|
|
5
|
+
label: 'Zombie Killer Worker Plugin',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
adapters: [ZombieKillerWorker],
|
|
8
|
+
};
|
|
9
|
+
export default ZombieKillerPlugin;
|
|
10
|
+
export { ZombieKillerWorker } from "./adapter.js";
|
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.6.
|
|
4
|
+
"version": "4.6.2",
|
|
5
5
|
"main": "lib/plugins-index.js",
|
|
6
6
|
"types": "lib/plugins-index.d.ts",
|
|
7
7
|
"exports": {
|