@unchainedshop/plugins 4.7.2 → 4.8.0

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.
Files changed (184) hide show
  1. package/README.md +2 -0
  2. package/lib/delivery/post.d.ts +1 -0
  3. package/lib/delivery/post.js +23 -0
  4. package/lib/delivery/send-message.d.ts +1 -0
  5. package/lib/delivery/send-message.js +40 -0
  6. package/lib/delivery/stores.d.ts +1 -0
  7. package/lib/delivery/stores.js +43 -0
  8. package/lib/enrollments/licensed.d.ts +4 -0
  9. package/lib/enrollments/licensed.js +52 -0
  10. package/lib/events/node-event-emitter.d.ts +1 -3
  11. package/lib/events/node-event-emitter.js +3 -3
  12. package/lib/files/gridfs/adapter.d.ts +2 -2
  13. package/lib/files/gridfs/adapter.js +5 -2
  14. package/lib/files/gridfs/handler-express.d.ts +9 -0
  15. package/lib/files/gridfs/handler-express.js +110 -0
  16. package/lib/files/gridfs/handler-fastify.d.ts +3 -0
  17. package/lib/files/gridfs/handler-fastify.js +138 -0
  18. package/lib/files/gridfs/index.d.ts +4 -5
  19. package/lib/files/gridfs/index.js +3 -30
  20. package/lib/files/minio/handler-express.d.ts +2 -0
  21. package/lib/files/minio/handler-express.js +36 -0
  22. package/lib/files/minio/handler-fastify.d.ts +3 -0
  23. package/lib/files/minio/handler-fastify.js +40 -0
  24. package/lib/files/minio/index.d.ts +5 -4
  25. package/lib/files/minio/index.js +157 -18
  26. package/lib/filters/local-search.d.ts +3 -0
  27. package/lib/filters/local-search.js +66 -0
  28. package/lib/filters/strict-equal.d.ts +1 -0
  29. package/lib/filters/strict-equal.js +24 -0
  30. package/lib/payment/apple-iap/adapter.d.ts +1 -2
  31. package/lib/payment/apple-iap/adapter.js +3 -2
  32. package/lib/payment/apple-iap/handler-express.d.ts +2 -0
  33. package/lib/payment/apple-iap/handler-express.js +103 -0
  34. package/lib/payment/apple-iap/handler-fastify.d.ts +3 -0
  35. package/lib/payment/apple-iap/handler-fastify.js +102 -0
  36. package/lib/payment/apple-iap/index.d.ts +4 -6
  37. package/lib/payment/apple-iap/index.js +3 -28
  38. package/lib/payment/braintree.d.ts +1 -0
  39. package/lib/payment/braintree.js +138 -0
  40. package/lib/payment/cryptopay/handler-express.d.ts +2 -0
  41. package/lib/payment/cryptopay/handler-express.js +19 -0
  42. package/lib/payment/cryptopay/handler-fastify.d.ts +3 -0
  43. package/lib/payment/cryptopay/handler-fastify.js +17 -0
  44. package/lib/payment/cryptopay/index.d.ts +4 -5
  45. package/lib/payment/cryptopay/index.js +3 -31
  46. package/lib/payment/cryptopay/plugin.d.ts +3 -0
  47. package/lib/payment/cryptopay/plugin.js +159 -0
  48. package/lib/payment/datatrans-v2/handler-express.d.ts +1 -0
  49. package/lib/payment/datatrans-v2/handler-express.js +71 -0
  50. package/lib/payment/datatrans-v2/handler-fastify.d.ts +2 -0
  51. package/lib/payment/datatrans-v2/handler-fastify.js +71 -0
  52. package/lib/payment/datatrans-v2/index.d.ts +1 -4
  53. package/lib/payment/datatrans-v2/index.js +400 -17
  54. package/lib/payment/invoice-prepaid.d.ts +1 -0
  55. package/lib/payment/invoice-prepaid.js +30 -0
  56. package/lib/payment/invoice.d.ts +1 -0
  57. package/lib/payment/invoice.js +27 -0
  58. package/lib/payment/paypal-checkout.d.ts +1 -0
  59. package/lib/payment/paypal-checkout.js +87 -0
  60. package/lib/payment/payrexx/handler-express.d.ts +1 -0
  61. package/lib/payment/payrexx/handler-express.js +85 -0
  62. package/lib/payment/payrexx/handler-fastify.d.ts +2 -0
  63. package/lib/payment/payrexx/handler-fastify.js +91 -0
  64. package/lib/payment/payrexx/index.d.ts +1 -4
  65. package/lib/payment/payrexx/index.js +158 -19
  66. package/lib/payment/postfinance-checkout/handler-express.d.ts +1 -0
  67. package/lib/payment/postfinance-checkout/handler-express.js +37 -0
  68. package/lib/payment/postfinance-checkout/handler-fastify.d.ts +2 -0
  69. package/lib/payment/postfinance-checkout/handler-fastify.js +40 -0
  70. package/lib/payment/postfinance-checkout/index.d.ts +0 -5
  71. package/lib/payment/postfinance-checkout/index.js +186 -25
  72. package/lib/payment/saferpay/adapter.js +2 -1
  73. package/lib/payment/saferpay/handler-express.d.ts +1 -0
  74. package/lib/payment/saferpay/handler-express.js +59 -0
  75. package/lib/payment/saferpay/handler-fastify.d.ts +2 -0
  76. package/lib/payment/saferpay/handler-fastify.js +62 -0
  77. package/lib/payment/saferpay/index.d.ts +4 -5
  78. package/lib/payment/saferpay/index.js +3 -29
  79. package/lib/payment/stripe/handler-express.d.ts +5 -0
  80. package/lib/payment/stripe/handler-express.js +121 -0
  81. package/lib/payment/stripe/handler-fastify.d.ts +6 -0
  82. package/lib/payment/stripe/handler-fastify.js +131 -0
  83. package/lib/payment/stripe/index.d.ts +1 -4
  84. package/lib/payment/stripe/index.js +116 -22
  85. package/lib/payment/stripe/stripe.js +4 -1
  86. package/lib/presets/all-express.d.ts +6 -0
  87. package/lib/presets/all-express.js +26 -0
  88. package/lib/presets/all-fastify.d.ts +6 -0
  89. package/lib/presets/all-fastify.js +49 -0
  90. package/lib/presets/all.d.ts +70 -1
  91. package/lib/presets/all.js +27 -41
  92. package/lib/presets/base-express.d.ts +2 -0
  93. package/lib/presets/base-express.js +5 -0
  94. package/lib/presets/base-fastify.d.ts +3 -0
  95. package/lib/presets/base-fastify.js +16 -0
  96. package/lib/presets/base.d.ts +25 -1
  97. package/lib/presets/base.js +25 -56
  98. package/lib/presets/countries/ch.d.ts +2 -1
  99. package/lib/presets/countries/ch.js +2 -7
  100. package/lib/presets/crypto-express.d.ts +3 -0
  101. package/lib/presets/crypto-express.js +8 -0
  102. package/lib/presets/crypto-fastify.d.ts +3 -0
  103. package/lib/presets/crypto-fastify.js +11 -0
  104. package/lib/presets/crypto.d.ts +7 -3
  105. package/lib/presets/crypto.js +7 -18
  106. package/lib/pricing/delivery-swiss-tax.d.ts +2 -0
  107. package/lib/pricing/delivery-swiss-tax.js +62 -0
  108. package/lib/pricing/discount-100-off.d.ts +2 -0
  109. package/lib/pricing/discount-100-off.js +30 -0
  110. package/lib/pricing/discount-half-price-manual.d.ts +2 -0
  111. package/lib/pricing/discount-half-price-manual.js +30 -0
  112. package/lib/pricing/discount-half-price.d.ts +2 -0
  113. package/lib/pricing/discount-half-price.js +33 -0
  114. package/lib/pricing/free-delivery.d.ts +2 -0
  115. package/lib/pricing/free-delivery.js +27 -0
  116. package/lib/pricing/free-payment.d.ts +2 -0
  117. package/lib/pricing/free-payment.js +27 -0
  118. package/lib/pricing/order-delivery.d.ts +2 -0
  119. package/lib/pricing/order-delivery.js +33 -0
  120. package/lib/pricing/order-discount.d.ts +2 -0
  121. package/lib/pricing/order-discount.js +74 -0
  122. package/lib/pricing/order-items-discount.d.ts +2 -0
  123. package/lib/pricing/order-items-discount.js +50 -0
  124. package/lib/pricing/order-items.d.ts +2 -0
  125. package/lib/pricing/order-items.js +43 -0
  126. package/lib/pricing/order-payment.d.ts +2 -0
  127. package/lib/pricing/order-payment.js +33 -0
  128. package/lib/pricing/order-round.d.ts +10 -0
  129. package/lib/pricing/order-round.js +135 -0
  130. package/lib/pricing/product-catalog-price-options.d.ts +2 -0
  131. package/lib/pricing/product-catalog-price-options.js +51 -0
  132. package/lib/pricing/product-catalog-price.d.ts +2 -0
  133. package/lib/pricing/product-catalog-price.js +60 -0
  134. package/lib/pricing/product-discount.d.ts +2 -0
  135. package/lib/pricing/product-discount.js +69 -0
  136. package/lib/pricing/product-price-rateconversion.d.ts +2 -0
  137. package/lib/pricing/product-price-rateconversion.js +53 -0
  138. package/lib/pricing/product-round.d.ts +10 -0
  139. package/lib/pricing/product-round.js +44 -0
  140. package/lib/pricing/product-swiss-tax.d.ts +2 -0
  141. package/lib/pricing/product-swiss-tax.js +76 -0
  142. package/lib/quotations/manual.d.ts +1 -0
  143. package/lib/quotations/manual.js +20 -0
  144. package/lib/warehousing/eth-minter.d.ts +1 -0
  145. package/lib/warehousing/eth-minter.js +120 -0
  146. package/lib/warehousing/store.d.ts +1 -0
  147. package/lib/warehousing/store.js +34 -0
  148. package/lib/worker/budgetsms.d.ts +9 -0
  149. package/lib/worker/budgetsms.js +169 -0
  150. package/lib/worker/bulk-export.d.ts +2 -0
  151. package/lib/worker/bulk-export.js +64 -0
  152. package/lib/worker/bulk-import.d.ts +2 -0
  153. package/lib/worker/bulk-import.js +65 -0
  154. package/lib/worker/bulkgate.d.ts +1 -0
  155. package/lib/worker/bulkgate.js +91 -0
  156. package/lib/worker/email.d.ts +1 -0
  157. package/lib/worker/email.js +136 -0
  158. package/lib/worker/enrollment-order-generator.d.ts +1 -0
  159. package/lib/worker/enrollment-order-generator.js +77 -0
  160. package/lib/worker/error-notifications.d.ts +9 -0
  161. package/lib/worker/error-notifications.js +61 -0
  162. package/lib/worker/export-token.d.ts +4 -0
  163. package/lib/worker/export-token.js +26 -0
  164. package/lib/worker/external.d.ts +2 -0
  165. package/lib/worker/external.js +13 -0
  166. package/lib/worker/heartbeat.d.ts +1 -0
  167. package/lib/worker/heartbeat.js +26 -0
  168. package/lib/worker/http-request.d.ts +8 -0
  169. package/lib/worker/http-request.js +56 -0
  170. package/lib/worker/message.d.ts +10 -0
  171. package/lib/worker/message.js +42 -0
  172. package/lib/worker/push-notification.d.ts +1 -0
  173. package/lib/worker/push-notification.js +87 -0
  174. package/lib/worker/twilio.d.ts +1 -0
  175. package/lib/worker/twilio.js +59 -0
  176. package/lib/worker/update-coinbase-rates.d.ts +1 -0
  177. package/lib/worker/update-coinbase-rates.js +59 -0
  178. package/lib/worker/update-ecb-rates.d.ts +1 -0
  179. package/lib/worker/update-ecb-rates.js +92 -0
  180. package/lib/worker/update-token-ownership.d.ts +3 -0
  181. package/lib/worker/update-token-ownership.js +57 -0
  182. package/lib/worker/zombie-killer.d.ts +13 -0
  183. package/lib/worker/zombie-killer.js +91 -0
  184. package/package.json +10 -15
@@ -0,0 +1,87 @@
1
+ import { WorkerAdapter, WorkerDirector } from '@unchainedshop/core';
2
+ import { createLogger } from '@unchainedshop/logger';
3
+ const logger = createLogger('unchained:worker:push-notification');
4
+ let webPush;
5
+ try {
6
+ const module = await import('web-push');
7
+ webPush = module.default;
8
+ }
9
+ catch {
10
+ logger.warn(`optional peer npm package 'web-push' not installed, push notifications will not work`);
11
+ }
12
+ const { PUSH_NOTIFICATION_PUBLIC_KEY, PUSH_NOTIFICATION_PRIVATE_KEY } = process.env;
13
+ const PushNotificationWorkerPlugin = {
14
+ ...WorkerAdapter,
15
+ key: 'shop.unchained.worker-plugin.push-notification',
16
+ label: 'Push Notification',
17
+ version: '1.0',
18
+ type: 'PUSH',
19
+ doWork: async ({ subscription, subject, payload, urgency = null, topic = null }) => {
20
+ if (!webPush) {
21
+ return {
22
+ success: false,
23
+ error: {
24
+ name: 'WEB_PUSH_NOT_INSTALLED',
25
+ message: 'npm dependency web-push is not installed, please install it to use this worker',
26
+ },
27
+ };
28
+ }
29
+ if (!PUSH_NOTIFICATION_PUBLIC_KEY)
30
+ return {
31
+ success: false,
32
+ error: {
33
+ name: 'VAPID_PUBLIC_KEY_REQUIRED',
34
+ message: 'vapidPublicKey key required to send push notifications',
35
+ },
36
+ };
37
+ if (!PUSH_NOTIFICATION_PRIVATE_KEY)
38
+ return {
39
+ success: false,
40
+ error: {
41
+ name: 'VAPID_PRIVATE_KEY_REQUIRED',
42
+ message: 'vapidPrivateKey key are required to send push notifications',
43
+ },
44
+ };
45
+ if (!subscription) {
46
+ return {
47
+ success: false,
48
+ error: {
49
+ name: 'USER_SUBSCRIPTION_OBJECT_REQUIRED',
50
+ message: 'PUSH service subscription required',
51
+ },
52
+ };
53
+ }
54
+ const options = {
55
+ vapidDetails: {
56
+ subject,
57
+ publicKey: PUSH_NOTIFICATION_PUBLIC_KEY,
58
+ privateKey: PUSH_NOTIFICATION_PRIVATE_KEY,
59
+ },
60
+ TTL: 60,
61
+ };
62
+ if (urgency) {
63
+ options.urgency = urgency;
64
+ }
65
+ if (topic) {
66
+ options.topic = topic;
67
+ }
68
+ try {
69
+ await webPush.sendNotification(subscription, payload, options);
70
+ return {
71
+ success: true,
72
+ error: null,
73
+ };
74
+ }
75
+ catch (err) {
76
+ return {
77
+ success: false,
78
+ error: {
79
+ name: err.name,
80
+ message: err.message,
81
+ stack: err.stack,
82
+ },
83
+ };
84
+ }
85
+ },
86
+ };
87
+ WorkerDirector.registerAdapter(PushNotificationWorkerPlugin);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,59 @@
1
+ import { WorkerAdapter, WorkerDirector } from '@unchainedshop/core';
2
+ const { TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO_SMS_FROM } = process.env;
3
+ const SmsWorkerPlugin = {
4
+ ...WorkerAdapter,
5
+ key: 'shop.unchained.worker-plugin.twilio',
6
+ label: 'Send Messages through Twilio',
7
+ version: '1.0.0',
8
+ type: 'TWILIO',
9
+ doWork: async ({ from, to, text, ...params }) => {
10
+ try {
11
+ if (!TWILIO_SMS_FROM && !from)
12
+ throw new Error('Missing Twilio "from" number. Set TWILIO_SMS_FROM env var or provide "from" in input');
13
+ if (!to)
14
+ throw new Error('Missing "to" in input');
15
+ const url = `https://api.twilio.com/2010-04-01/Accounts/${TWILIO_ACCOUNT_SID}/Messages.json`;
16
+ const response = await fetch(url, {
17
+ method: 'POST',
18
+ headers: {
19
+ Authorization: `Basic ${Buffer.from(`${TWILIO_ACCOUNT_SID}:${TWILIO_AUTH_TOKEN}`).toString('base64')}`,
20
+ 'Content-Type': 'application/x-www-form-urlencoded',
21
+ },
22
+ body: new URLSearchParams({
23
+ Body: text || '',
24
+ From: from || TWILIO_SMS_FROM,
25
+ To: to,
26
+ ...params,
27
+ }),
28
+ });
29
+ const data = await response.json();
30
+ if (!response.ok) {
31
+ return {
32
+ success: false,
33
+ error: {
34
+ name: 'TWILIO_ERROR',
35
+ message: data.message || 'Failed to send SMS',
36
+ },
37
+ };
38
+ }
39
+ return {
40
+ success: true,
41
+ result: {
42
+ sid: data.sid,
43
+ },
44
+ error: null,
45
+ };
46
+ }
47
+ catch (err) {
48
+ return {
49
+ success: false,
50
+ error: {
51
+ name: err.name,
52
+ message: err.message,
53
+ stack: err.stack,
54
+ },
55
+ };
56
+ }
57
+ },
58
+ };
59
+ WorkerDirector.registerAdapter(SmsWorkerPlugin);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,59 @@
1
+ import { WorkerAdapter, WorkerDirector, schedule } from '@unchainedshop/core';
2
+ import { resolveBestCurrency } from '@unchainedshop/utils';
3
+ const getExchangeRates = async (base) => {
4
+ return fetch(`https://api.coinbase.com/v2/exchange-rates?currency=${base}`, {
5
+ method: 'GET',
6
+ })
7
+ .then((res) => res.json())
8
+ .then((r) => r?.data);
9
+ };
10
+ const everyMinute = schedule.parse.cron('* * * * *');
11
+ const UpdateCoinbaseRates = {
12
+ ...WorkerAdapter,
13
+ key: 'shop.unchained.worker.update-coinbase-rates',
14
+ label: 'Update Coinbase Rates',
15
+ version: '1.0.0',
16
+ type: 'UPDATE_COINBASE_RATES',
17
+ doWork: async (input, unchainedAPI) => {
18
+ try {
19
+ const currencies = await unchainedAPI.modules.currencies.findCurrencies({ includeInactive: true });
20
+ const currencyCode = resolveBestCurrency(null, currencies);
21
+ const currencyCodes = currencies.map((currency) => currency.isoCode);
22
+ const { currency: baseCurrency, rates: pairs } = await getExchangeRates(currencyCode);
23
+ const timestamp = new Date();
24
+ const expiresAt = new Date(new Date().getTime() + 5 * 60 * 1000);
25
+ const rates = Object.entries(pairs)
26
+ .map(([quoteCurrency, rate]) => {
27
+ return {
28
+ baseCurrency,
29
+ quoteCurrency,
30
+ rate: parseFloat(rate),
31
+ timestamp,
32
+ expiresAt,
33
+ };
34
+ })
35
+ .filter((rate) => currencyCodes.includes(rate.quoteCurrency) && rate.quoteCurrency !== rate.baseCurrency);
36
+ const success = await unchainedAPI.modules.products.prices.rates.updateRates(rates);
37
+ return {
38
+ success,
39
+ result: {
40
+ ratesUpdated: rates.length,
41
+ },
42
+ };
43
+ }
44
+ catch {
45
+ return {
46
+ success: false,
47
+ error: {
48
+ name: 'UPDATE_COINBASE_RATES_FAILED',
49
+ message: 'Updating Coinbase Rates failed',
50
+ },
51
+ };
52
+ }
53
+ },
54
+ };
55
+ WorkerDirector.registerAdapter(UpdateCoinbaseRates);
56
+ WorkerDirector.configureAutoscheduling({
57
+ type: UpdateCoinbaseRates.type,
58
+ schedule: everyMinute,
59
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,92 @@
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
+ 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
+ WorkerDirector.registerAdapter(UpdateECBRates);
86
+ if (xml2json) {
87
+ WorkerDirector.configureAutoscheduling({
88
+ type: UpdateECBRates.type,
89
+ schedule: everyDayAtFour,
90
+ retries: 5,
91
+ });
92
+ }
@@ -0,0 +1,3 @@
1
+ import { type IWorkerAdapter } from '@unchainedshop/core';
2
+ export declare const UpdateTokenOwnership: IWorkerAdapter<void, void>;
3
+ export declare const RefreshTokens: IWorkerAdapter<void, any>;
@@ -0,0 +1,57 @@
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
+ WorkerDirector.registerAdapter(RefreshTokens);
52
+ WorkerDirector.registerAdapter(UpdateTokenOwnership);
53
+ WorkerDirector.configureAutoscheduling({
54
+ type: RefreshTokens.type,
55
+ schedule: everyMinute,
56
+ retries: 0,
57
+ });
@@ -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,91 @@
1
+ import { WorkerAdapter, WorkerDirector } 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;
91
+ WorkerDirector.registerAdapter(ZombieKillerWorker);
package/package.json CHANGED
@@ -1,22 +1,11 @@
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.7.2",
4
+ "version": "4.8.0",
5
5
  "main": "lib/plugins-index.js",
6
6
  "types": "lib/plugins-index.d.ts",
7
7
  "exports": {
8
- "./presets/*": "./lib/presets/*.js",
9
- "./presets/countries/*": "./lib/presets/countries/*.js",
10
- "./events/*": "./lib/events/*.js",
11
- "./enrollments/*": "./lib/enrollments/*/index.js",
12
- "./quotations/*": "./lib/quotations/*/index.js",
13
- "./filters/*": "./lib/filters/*/index.js",
14
- "./delivery/*": "./lib/delivery/*/index.js",
15
- "./warehousing/*": "./lib/warehousing/*/index.js",
16
- "./payment/*": "./lib/payment/*/index.js",
17
- "./files/*": "./lib/files/*/index.js",
18
- "./pricing/*": "./lib/pricing/*/index.js",
19
- "./worker/*": "./lib/worker/*/index.js"
8
+ "./*": "./lib/*"
20
9
  },
21
10
  "type": "module",
22
11
  "scripts": {
@@ -57,11 +46,13 @@
57
46
  "@unchainedshop/core-warehousing": "^4.6.0",
58
47
  "@unchainedshop/core-worker": "^4.6.0",
59
48
  "@unchainedshop/events": "^4.6.0",
49
+ "@unchainedshop/file-upload": "^4.6.0",
60
50
  "@unchainedshop/logger": "^4.6.0",
61
51
  "@unchainedshop/utils": "^4.6.0"
62
52
  },
63
53
  "peerDependencies": {
64
54
  "@aws-sdk/client-eventbridge": ">= 3.714 < 4",
55
+ "@paypal/checkout-server-sdk": "1.x",
65
56
  "@redis/client": ">= 1 < 6",
66
57
  "@scure/bip32": ">= 2",
67
58
  "@scure/btc-signer": ">= 2",
@@ -70,7 +61,7 @@
70
61
  "express": ">= 5 < 6",
71
62
  "fastify": ">= 5.2 < 6",
72
63
  "minio": "8.x",
73
- "nodemailer": ">= 6.9 < 9",
64
+ "nodemailer": ">= 6.9 < 8",
74
65
  "p-memoize": "8.x",
75
66
  "stripe": ">= 19 < 21",
76
67
  "web-push": ">= 3.6 <4",
@@ -80,6 +71,9 @@
80
71
  "@aws-sdk/client-eventbridge": {
81
72
  "optional": true
82
73
  },
74
+ "@paypal/checkout-server-sdk": {
75
+ "optional": true
76
+ },
83
77
  "@redis/client": {
84
78
  "optional": true
85
79
  },
@@ -118,6 +112,7 @@
118
112
  }
119
113
  },
120
114
  "devDependencies": {
115
+ "@paypal/checkout-server-sdk": "^1.0.3",
121
116
  "@redis/client": "^5.6.0",
122
117
  "@scure/bip32": "^2.0.0",
123
118
  "@scure/btc-signer": "^2.0.0",
@@ -127,7 +122,7 @@
127
122
  "express": "^5.1.0",
128
123
  "fastify": "^5.4.0",
129
124
  "minio": "^8.0.5",
130
- "nodemailer": "^8.0.1",
125
+ "nodemailer": "^7.0.5",
131
126
  "p-memoize": "^8.0.0",
132
127
  "stripe": "^20.0.0",
133
128
  "typescript": "^5.8.3",