@unchainedshop/plugins 4.6.2 → 4.7.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.
Files changed (184) hide show
  1. package/README.md +0 -2
  2. package/lib/events/node-event-emitter.d.ts +3 -1
  3. package/lib/events/node-event-emitter.js +3 -3
  4. package/lib/files/gridfs/adapter.d.ts +2 -2
  5. package/lib/files/gridfs/adapter.js +2 -5
  6. package/lib/files/gridfs/index.d.ts +5 -4
  7. package/lib/files/gridfs/index.js +30 -3
  8. package/lib/files/minio/index.d.ts +4 -5
  9. package/lib/files/minio/index.js +18 -157
  10. package/lib/payment/apple-iap/adapter.d.ts +2 -1
  11. package/lib/payment/apple-iap/adapter.js +2 -3
  12. package/lib/payment/apple-iap/index.d.ts +6 -4
  13. package/lib/payment/apple-iap/index.js +28 -3
  14. package/lib/payment/cryptopay/index.d.ts +5 -4
  15. package/lib/payment/cryptopay/index.js +31 -3
  16. package/lib/payment/datatrans-v2/index.d.ts +4 -1
  17. package/lib/payment/datatrans-v2/index.js +17 -400
  18. package/lib/payment/payrexx/index.d.ts +4 -1
  19. package/lib/payment/payrexx/index.js +19 -158
  20. package/lib/payment/postfinance-checkout/index.d.ts +5 -0
  21. package/lib/payment/postfinance-checkout/index.js +25 -186
  22. package/lib/payment/saferpay/adapter.js +1 -2
  23. package/lib/payment/saferpay/index.d.ts +5 -4
  24. package/lib/payment/saferpay/index.js +29 -3
  25. package/lib/payment/stripe/index.d.ts +4 -1
  26. package/lib/payment/stripe/index.js +22 -116
  27. package/lib/payment/stripe/stripe.js +2 -5
  28. package/lib/presets/all.d.ts +1 -70
  29. package/lib/presets/all.js +41 -27
  30. package/lib/presets/base.d.ts +1 -25
  31. package/lib/presets/base.js +56 -25
  32. package/lib/presets/countries/ch.d.ts +1 -2
  33. package/lib/presets/countries/ch.js +7 -2
  34. package/lib/presets/crypto.d.ts +3 -7
  35. package/lib/presets/crypto.js +18 -7
  36. package/package.json +15 -10
  37. package/lib/delivery/post.d.ts +0 -1
  38. package/lib/delivery/post.js +0 -23
  39. package/lib/delivery/send-message.d.ts +0 -1
  40. package/lib/delivery/send-message.js +0 -40
  41. package/lib/delivery/stores.d.ts +0 -1
  42. package/lib/delivery/stores.js +0 -43
  43. package/lib/enrollments/licensed.d.ts +0 -4
  44. package/lib/enrollments/licensed.js +0 -52
  45. package/lib/files/gridfs/handler-express.d.ts +0 -9
  46. package/lib/files/gridfs/handler-express.js +0 -110
  47. package/lib/files/gridfs/handler-fastify.d.ts +0 -3
  48. package/lib/files/gridfs/handler-fastify.js +0 -138
  49. package/lib/files/minio/handler-express.d.ts +0 -2
  50. package/lib/files/minio/handler-express.js +0 -36
  51. package/lib/files/minio/handler-fastify.d.ts +0 -3
  52. package/lib/files/minio/handler-fastify.js +0 -40
  53. package/lib/filters/local-search.d.ts +0 -3
  54. package/lib/filters/local-search.js +0 -66
  55. package/lib/filters/strict-equal.d.ts +0 -1
  56. package/lib/filters/strict-equal.js +0 -24
  57. package/lib/payment/apple-iap/handler-express.d.ts +0 -2
  58. package/lib/payment/apple-iap/handler-express.js +0 -103
  59. package/lib/payment/apple-iap/handler-fastify.d.ts +0 -3
  60. package/lib/payment/apple-iap/handler-fastify.js +0 -102
  61. package/lib/payment/braintree.d.ts +0 -1
  62. package/lib/payment/braintree.js +0 -138
  63. package/lib/payment/cryptopay/handler-express.d.ts +0 -2
  64. package/lib/payment/cryptopay/handler-express.js +0 -19
  65. package/lib/payment/cryptopay/handler-fastify.d.ts +0 -3
  66. package/lib/payment/cryptopay/handler-fastify.js +0 -17
  67. package/lib/payment/cryptopay/plugin.d.ts +0 -3
  68. package/lib/payment/cryptopay/plugin.js +0 -159
  69. package/lib/payment/datatrans-v2/handler-express.d.ts +0 -1
  70. package/lib/payment/datatrans-v2/handler-express.js +0 -71
  71. package/lib/payment/datatrans-v2/handler-fastify.d.ts +0 -2
  72. package/lib/payment/datatrans-v2/handler-fastify.js +0 -71
  73. package/lib/payment/invoice-prepaid.d.ts +0 -1
  74. package/lib/payment/invoice-prepaid.js +0 -30
  75. package/lib/payment/invoice.d.ts +0 -1
  76. package/lib/payment/invoice.js +0 -27
  77. package/lib/payment/paypal-checkout.d.ts +0 -1
  78. package/lib/payment/paypal-checkout.js +0 -87
  79. package/lib/payment/payrexx/handler-express.d.ts +0 -1
  80. package/lib/payment/payrexx/handler-express.js +0 -85
  81. package/lib/payment/payrexx/handler-fastify.d.ts +0 -2
  82. package/lib/payment/payrexx/handler-fastify.js +0 -91
  83. package/lib/payment/postfinance-checkout/handler-express.d.ts +0 -1
  84. package/lib/payment/postfinance-checkout/handler-express.js +0 -37
  85. package/lib/payment/postfinance-checkout/handler-fastify.d.ts +0 -2
  86. package/lib/payment/postfinance-checkout/handler-fastify.js +0 -40
  87. package/lib/payment/saferpay/handler-express.d.ts +0 -1
  88. package/lib/payment/saferpay/handler-express.js +0 -59
  89. package/lib/payment/saferpay/handler-fastify.d.ts +0 -2
  90. package/lib/payment/saferpay/handler-fastify.js +0 -62
  91. package/lib/payment/stripe/handler-express.d.ts +0 -5
  92. package/lib/payment/stripe/handler-express.js +0 -121
  93. package/lib/payment/stripe/handler-fastify.d.ts +0 -6
  94. package/lib/payment/stripe/handler-fastify.js +0 -131
  95. package/lib/presets/all-express.d.ts +0 -6
  96. package/lib/presets/all-express.js +0 -26
  97. package/lib/presets/all-fastify.d.ts +0 -6
  98. package/lib/presets/all-fastify.js +0 -49
  99. package/lib/presets/base-express.d.ts +0 -2
  100. package/lib/presets/base-express.js +0 -5
  101. package/lib/presets/base-fastify.d.ts +0 -3
  102. package/lib/presets/base-fastify.js +0 -16
  103. package/lib/presets/crypto-express.d.ts +0 -3
  104. package/lib/presets/crypto-express.js +0 -8
  105. package/lib/presets/crypto-fastify.d.ts +0 -3
  106. package/lib/presets/crypto-fastify.js +0 -11
  107. package/lib/pricing/delivery-swiss-tax.d.ts +0 -2
  108. package/lib/pricing/delivery-swiss-tax.js +0 -62
  109. package/lib/pricing/discount-100-off.d.ts +0 -2
  110. package/lib/pricing/discount-100-off.js +0 -30
  111. package/lib/pricing/discount-half-price-manual.d.ts +0 -2
  112. package/lib/pricing/discount-half-price-manual.js +0 -30
  113. package/lib/pricing/discount-half-price.d.ts +0 -2
  114. package/lib/pricing/discount-half-price.js +0 -33
  115. package/lib/pricing/free-delivery.d.ts +0 -2
  116. package/lib/pricing/free-delivery.js +0 -27
  117. package/lib/pricing/free-payment.d.ts +0 -2
  118. package/lib/pricing/free-payment.js +0 -27
  119. package/lib/pricing/order-delivery.d.ts +0 -2
  120. package/lib/pricing/order-delivery.js +0 -33
  121. package/lib/pricing/order-discount.d.ts +0 -2
  122. package/lib/pricing/order-discount.js +0 -74
  123. package/lib/pricing/order-items-discount.d.ts +0 -2
  124. package/lib/pricing/order-items-discount.js +0 -50
  125. package/lib/pricing/order-items.d.ts +0 -2
  126. package/lib/pricing/order-items.js +0 -43
  127. package/lib/pricing/order-payment.d.ts +0 -2
  128. package/lib/pricing/order-payment.js +0 -33
  129. package/lib/pricing/order-round.d.ts +0 -10
  130. package/lib/pricing/order-round.js +0 -135
  131. package/lib/pricing/product-catalog-price-options.d.ts +0 -2
  132. package/lib/pricing/product-catalog-price-options.js +0 -51
  133. package/lib/pricing/product-catalog-price.d.ts +0 -2
  134. package/lib/pricing/product-catalog-price.js +0 -60
  135. package/lib/pricing/product-discount.d.ts +0 -2
  136. package/lib/pricing/product-discount.js +0 -69
  137. package/lib/pricing/product-price-rateconversion.d.ts +0 -2
  138. package/lib/pricing/product-price-rateconversion.js +0 -53
  139. package/lib/pricing/product-round.d.ts +0 -10
  140. package/lib/pricing/product-round.js +0 -44
  141. package/lib/pricing/product-swiss-tax.d.ts +0 -2
  142. package/lib/pricing/product-swiss-tax.js +0 -76
  143. package/lib/quotations/manual.d.ts +0 -1
  144. package/lib/quotations/manual.js +0 -20
  145. package/lib/warehousing/eth-minter.d.ts +0 -1
  146. package/lib/warehousing/eth-minter.js +0 -120
  147. package/lib/warehousing/store.d.ts +0 -1
  148. package/lib/warehousing/store.js +0 -34
  149. package/lib/worker/budgetsms.d.ts +0 -9
  150. package/lib/worker/budgetsms.js +0 -169
  151. package/lib/worker/bulk-export.d.ts +0 -2
  152. package/lib/worker/bulk-export.js +0 -64
  153. package/lib/worker/bulk-import.d.ts +0 -2
  154. package/lib/worker/bulk-import.js +0 -65
  155. package/lib/worker/bulkgate.d.ts +0 -1
  156. package/lib/worker/bulkgate.js +0 -91
  157. package/lib/worker/email.d.ts +0 -1
  158. package/lib/worker/email.js +0 -136
  159. package/lib/worker/enrollment-order-generator.d.ts +0 -1
  160. package/lib/worker/enrollment-order-generator.js +0 -77
  161. package/lib/worker/error-notifications.d.ts +0 -9
  162. package/lib/worker/error-notifications.js +0 -61
  163. package/lib/worker/export-token.d.ts +0 -4
  164. package/lib/worker/export-token.js +0 -26
  165. package/lib/worker/external.d.ts +0 -2
  166. package/lib/worker/external.js +0 -13
  167. package/lib/worker/heartbeat.d.ts +0 -1
  168. package/lib/worker/heartbeat.js +0 -26
  169. package/lib/worker/http-request.d.ts +0 -8
  170. package/lib/worker/http-request.js +0 -56
  171. package/lib/worker/message.d.ts +0 -10
  172. package/lib/worker/message.js +0 -42
  173. package/lib/worker/push-notification.d.ts +0 -1
  174. package/lib/worker/push-notification.js +0 -87
  175. package/lib/worker/twilio.d.ts +0 -1
  176. package/lib/worker/twilio.js +0 -59
  177. package/lib/worker/update-coinbase-rates.d.ts +0 -1
  178. package/lib/worker/update-coinbase-rates.js +0 -59
  179. package/lib/worker/update-ecb-rates.d.ts +0 -1
  180. package/lib/worker/update-ecb-rates.js +0 -92
  181. package/lib/worker/update-token-ownership.d.ts +0 -3
  182. package/lib/worker/update-token-ownership.js +0 -57
  183. package/lib/worker/zombie-killer.d.ts +0 -13
  184. package/lib/worker/zombie-killer.js +0 -91
@@ -1,61 +0,0 @@
1
- import { WorkStatus } from '@unchainedshop/core-worker';
2
- import { WorkerDirector, WorkerAdapter, schedule } from '@unchainedshop/core';
3
- const everyDayAtFourInTheNight = schedule.parse.cron('0 3 * * *');
4
- export const ErrorNotifications = {
5
- ...WorkerAdapter,
6
- key: 'shop.unchained.worker.error-notifications',
7
- label: 'Send a daily report about errors that failed permanently/unrecoverable',
8
- version: '1.0',
9
- type: 'ERROR_NOTIFICATIONS',
10
- doWork: async (args, context, workId) => {
11
- const work = (await context.modules.worker.findWork({ workId }));
12
- const secondsPassed = args?.secondsPassed || 60;
13
- const to = new Date();
14
- const from = new Date(new Date(work.scheduled).getTime() - secondsPassed * 1000);
15
- try {
16
- const workItems = (await context.modules.worker.findWorkQueue({
17
- scheduled: {
18
- end: to,
19
- start: from,
20
- },
21
- types: undefined,
22
- status: [WorkStatus.FAILED],
23
- })).filter((workItem) => workItem.type !== ErrorNotifications.type && workItem.retries === 0);
24
- if (!workItems.length) {
25
- return { success: true, result: {} };
26
- }
27
- const message = await context.modules.worker.addWork({
28
- type: 'MESSAGE',
29
- retries: 0,
30
- input: {
31
- workItems,
32
- template: 'ERROR_REPORT',
33
- },
34
- originalWorkId: workId,
35
- });
36
- return {
37
- success: true,
38
- result: { forked: message._id },
39
- };
40
- }
41
- catch (err) {
42
- return {
43
- success: false,
44
- error: {
45
- name: err.name,
46
- message: err.message,
47
- stack: err.stack,
48
- },
49
- };
50
- }
51
- },
52
- };
53
- WorkerDirector.registerAdapter(ErrorNotifications);
54
- export default ErrorNotifications;
55
- const ONE_DAY_IN_SECONDS = 24 * 60 * 60;
56
- WorkerDirector.configureAutoscheduling({
57
- type: ErrorNotifications.type,
58
- schedule: everyDayAtFourInTheNight,
59
- input: async () => ({ secondsPassed: ONE_DAY_IN_SECONDS }),
60
- retries: 0,
61
- });
@@ -1,4 +0,0 @@
1
- import { type IWorkerAdapter, type UnchainedCore } from '@unchainedshop/core';
2
- export declare const ExportTokenWorker: IWorkerAdapter<void, void>;
3
- export declare const configureExportToken: (unchainedAPI: UnchainedCore) => void;
4
- export default configureExportToken;
@@ -1,26 +0,0 @@
1
- import { WorkerEventTypes } from '@unchainedshop/core-worker';
2
- import { WorkerAdapter, WorkerDirector, } from '@unchainedshop/core';
3
- import { subscribe } from '@unchainedshop/events';
4
- export const ExportTokenWorker = {
5
- ...WorkerAdapter,
6
- key: 'shop.unchained.worker-plugin.export-token',
7
- label: 'External worker to hold the state of the minting/export process of tokens',
8
- version: '1.0.0',
9
- type: 'EXPORT_TOKEN',
10
- external: true,
11
- async doWork() {
12
- throw new Error('Cannot do work for external workers');
13
- },
14
- };
15
- export const configureExportToken = (unchainedAPI) => {
16
- subscribe(WorkerEventTypes.FINISHED, async ({ payload: work }) => {
17
- if (work.type === 'EXPORT_TOKEN' && work.success) {
18
- await unchainedAPI.modules.warehousing.updateTokenOwnership({
19
- tokenId: work.input.token._id,
20
- walletAddress: work.input.recipientWalletAddress,
21
- });
22
- }
23
- });
24
- };
25
- export default configureExportToken;
26
- WorkerDirector.registerAdapter(ExportTokenWorker);
@@ -1,2 +0,0 @@
1
- import { type IWorkerAdapter } from '@unchainedshop/core';
2
- export declare const ExternalWorkerPlugin: IWorkerAdapter<void, void>;
@@ -1,13 +0,0 @@
1
- import { WorkerAdapter, WorkerDirector } from '@unchainedshop/core';
2
- export const ExternalWorkerPlugin = {
3
- ...WorkerAdapter,
4
- key: 'shop.unchained.worker-plugin.external',
5
- label: 'External plugin as a placeholder for workers who interact with the system only via GraphQL',
6
- version: '1.0.0',
7
- type: 'EXTERNAL',
8
- external: true,
9
- async doWork() {
10
- throw new Error('Cannot do work for external workers');
11
- },
12
- };
13
- WorkerDirector.registerAdapter(ExternalWorkerPlugin);
@@ -1 +0,0 @@
1
- export {};
@@ -1,26 +0,0 @@
1
- import { WorkerAdapter, WorkerDirector } from '@unchainedshop/core';
2
- import { setTimeout } from 'node:timers/promises';
3
- const Heartbeat = {
4
- ...WorkerAdapter,
5
- key: 'shop.unchained.worker-plugin.heartbeat',
6
- label: 'Heartbeat plugin to check if workers are working',
7
- version: '1.0.0',
8
- type: 'HEARTBEAT',
9
- maxParallelAllocations: 1,
10
- doWork: async (input) => {
11
- if (input?.wait) {
12
- await setTimeout(input.wait);
13
- }
14
- if (input?.fails) {
15
- return {
16
- success: false,
17
- result: input,
18
- };
19
- }
20
- return {
21
- success: true,
22
- result: input,
23
- };
24
- },
25
- };
26
- WorkerDirector.registerAdapter(Heartbeat);
@@ -1,8 +0,0 @@
1
- import { type IWorkerAdapter } from '@unchainedshop/core';
2
- declare const HttpRequestWorkerPlugin: IWorkerAdapter<{
3
- url?: string;
4
- data?: any;
5
- headers?: any;
6
- method: 'POST' | 'GET';
7
- }, any>;
8
- export default HttpRequestWorkerPlugin;
@@ -1,56 +0,0 @@
1
- import { WorkerAdapter, WorkerDirector } from '@unchainedshop/core';
2
- const postFetch = async (url, { data, headers }) => {
3
- return fetch(url, {
4
- method: 'POST',
5
- body: JSON.stringify(data),
6
- duplex: 'half',
7
- headers: { 'Content-Type': 'application/json', ...headers },
8
- });
9
- };
10
- const nonPostFetch = async (url, { headers, method = 'GET' }) => {
11
- return fetch(url, {
12
- method,
13
- headers,
14
- });
15
- };
16
- const HttpRequestWorkerPlugin = {
17
- ...WorkerAdapter,
18
- key: 'shop.unchained.worker-plugin.http-request',
19
- label: 'Request a resource via http request. 200 = success',
20
- version: '1.0.0',
21
- type: 'HTTP_REQUEST',
22
- async doWork({ url, data = {}, headers, method = 'POST' } = { method: 'POST' }) {
23
- if (!url) {
24
- return {
25
- success: false,
26
- error: {
27
- name: 'URL_REQUIRED',
28
- message: 'HTTP_REQUEST requires an url',
29
- },
30
- };
31
- }
32
- try {
33
- const normalizedFetch = method.toUpperCase() === 'POST' ? postFetch : nonPostFetch;
34
- const res = await normalizedFetch(url, { data, headers, method });
35
- const contentType = res.headers.get('content-type');
36
- const isJson = contentType && contentType.includes('application/json');
37
- const result = isJson ? await res.json() : { text: await res.text() };
38
- if (res.status === 200 && res.ok) {
39
- return { success: true, result };
40
- }
41
- return { success: false, result };
42
- }
43
- catch (err) {
44
- return {
45
- success: false,
46
- error: {
47
- name: err.name,
48
- message: err.message,
49
- stack: err.stack,
50
- },
51
- };
52
- }
53
- },
54
- };
55
- WorkerDirector.registerAdapter(HttpRequestWorkerPlugin);
56
- export default HttpRequestWorkerPlugin;
@@ -1,10 +0,0 @@
1
- import { type IWorkerAdapter } from '@unchainedshop/core';
2
- import type { Work } from '@unchainedshop/core-worker';
3
- export declare const MessageWorker: IWorkerAdapter<{
4
- template: string;
5
- _id: string;
6
- [x: string]: any;
7
- }, {
8
- info?: string;
9
- forked?: Work[];
10
- }>;
@@ -1,42 +0,0 @@
1
- import { MessagingDirector, WorkerAdapter, WorkerDirector, } from '@unchainedshop/core';
2
- export const MessageWorker = {
3
- ...WorkerAdapter,
4
- key: 'shop.unchained.worker-plugin.message',
5
- label: 'Send Message by combining payload with a template and start concrete jobs',
6
- version: '1.0.0',
7
- type: 'MESSAGE',
8
- doWork: async ({ template, ...payload }, unchainedAPI, workId) => {
9
- try {
10
- const templateResolver = MessagingDirector.getTemplate(template);
11
- if (!templateResolver)
12
- throw new Error(`No template resolver found for template ${template}`);
13
- const workConfigurations = await templateResolver({
14
- template,
15
- ...payload,
16
- }, unchainedAPI);
17
- if (workConfigurations.length > 0) {
18
- const forked = await Promise.all(workConfigurations.map(async (workConfiguration) => {
19
- const work = await unchainedAPI.modules.worker.addWork({
20
- ...workConfiguration,
21
- originalWorkId: workId,
22
- });
23
- delete work.input;
24
- return work;
25
- }));
26
- return { success: true, result: { forked } };
27
- }
28
- return { success: true, result: { forked: [] } };
29
- }
30
- catch (err) {
31
- return {
32
- success: false,
33
- error: {
34
- name: err.name,
35
- message: err.message,
36
- stack: err.stack,
37
- },
38
- };
39
- }
40
- },
41
- };
42
- WorkerDirector.registerAdapter(MessageWorker);
@@ -1 +0,0 @@
1
- export {};
@@ -1,87 +0,0 @@
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);
@@ -1 +0,0 @@
1
- export {};
@@ -1,59 +0,0 @@
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);
@@ -1 +0,0 @@
1
- export {};
@@ -1,59 +0,0 @@
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
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,92 +0,0 @@
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
- }
@@ -1,3 +0,0 @@
1
- import { type IWorkerAdapter } from '@unchainedshop/core';
2
- export declare const UpdateTokenOwnership: IWorkerAdapter<void, void>;
3
- export declare const RefreshTokens: IWorkerAdapter<void, any>;
@@ -1,57 +0,0 @@
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
- });
@@ -1,13 +0,0 @@
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;