@unchainedshop/plugins 4.6.1 → 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.
Files changed (209) hide show
  1. package/lib/delivery/post/adapter.d.ts +2 -0
  2. package/lib/delivery/post/adapter.js +22 -0
  3. package/lib/delivery/post/index.d.ts +4 -0
  4. package/lib/delivery/post/index.js +10 -0
  5. package/lib/delivery/send-message/adapter.d.ts +2 -0
  6. package/lib/delivery/send-message/adapter.js +39 -0
  7. package/lib/delivery/send-message/index.d.ts +4 -0
  8. package/lib/delivery/send-message/index.js +10 -0
  9. package/lib/delivery/stores/adapter.d.ts +2 -0
  10. package/lib/delivery/stores/adapter.js +42 -0
  11. package/lib/delivery/stores/index.d.ts +4 -0
  12. package/lib/delivery/stores/index.js +10 -0
  13. package/lib/enrollments/licensed/adapter.d.ts +6 -0
  14. package/lib/enrollments/licensed/adapter.js +51 -0
  15. package/lib/enrollments/licensed/index.d.ts +4 -0
  16. package/lib/enrollments/licensed/index.js +10 -0
  17. package/lib/files/gridfs/api.d.ts +7 -0
  18. package/lib/files/gridfs/api.js +163 -0
  19. package/lib/files/minio/adapter.d.ts +4 -0
  20. package/lib/files/minio/adapter.js +160 -0
  21. package/lib/files/minio/api.d.ts +2 -0
  22. package/lib/files/minio/api.js +41 -0
  23. package/lib/files/temp-upload/api.d.ts +6 -0
  24. package/lib/files/temp-upload/api.js +49 -0
  25. package/lib/files/temp-upload/index.d.ts +3 -0
  26. package/lib/files/temp-upload/index.js +15 -0
  27. package/lib/filters/local-search/adapter.d.ts +2 -0
  28. package/lib/filters/local-search/adapter.js +56 -0
  29. package/lib/filters/local-search/index.d.ts +4 -0
  30. package/lib/filters/local-search/index.js +16 -0
  31. package/lib/filters/strict-equal/adapter.d.ts +2 -0
  32. package/lib/filters/strict-equal/adapter.js +23 -0
  33. package/lib/filters/strict-equal/index.d.ts +4 -0
  34. package/lib/filters/strict-equal/index.js +10 -0
  35. package/lib/payment/apple-iap/api.d.ts +2 -0
  36. package/lib/payment/apple-iap/api.js +119 -0
  37. package/lib/payment/cryptopay/adapter.d.ts +2 -0
  38. package/lib/payment/cryptopay/adapter.js +157 -0
  39. package/lib/payment/cryptopay/api.d.ts +2 -0
  40. package/lib/payment/cryptopay/api.js +23 -0
  41. package/lib/payment/datatrans-v2/adapter.d.ts +2 -0
  42. package/lib/payment/datatrans-v2/adapter.js +406 -0
  43. package/lib/payment/datatrans-v2/api.d.ts +2 -0
  44. package/lib/payment/datatrans-v2/api.js +108 -0
  45. package/lib/payment/invoice/adapter.d.ts +2 -0
  46. package/lib/payment/invoice/adapter.js +26 -0
  47. package/lib/payment/invoice/index.d.ts +4 -0
  48. package/lib/payment/invoice/index.js +10 -0
  49. package/lib/payment/invoice-prepaid/adapter.d.ts +2 -0
  50. package/lib/payment/invoice-prepaid/adapter.js +29 -0
  51. package/lib/payment/invoice-prepaid/index.d.ts +4 -0
  52. package/lib/payment/invoice-prepaid/index.js +10 -0
  53. package/lib/payment/payrexx/adapter.d.ts +2 -0
  54. package/lib/payment/payrexx/adapter.js +161 -0
  55. package/lib/payment/payrexx/api.d.ts +2 -0
  56. package/lib/payment/payrexx/api.js +97 -0
  57. package/lib/payment/postfinance-checkout/adapter.d.ts +2 -0
  58. package/lib/payment/postfinance-checkout/adapter.js +189 -0
  59. package/lib/payment/postfinance-checkout/webhook.d.ts +2 -0
  60. package/lib/payment/postfinance-checkout/webhook.js +48 -0
  61. package/lib/payment/saferpay/webhook.d.ts +2 -0
  62. package/lib/payment/saferpay/webhook.js +64 -0
  63. package/lib/payment/stripe/adapter.d.ts +2 -0
  64. package/lib/payment/stripe/adapter.js +121 -0
  65. package/lib/payment/stripe/api.d.ts +6 -0
  66. package/lib/payment/stripe/api.js +165 -0
  67. package/lib/pricing/delivery-swiss-tax/adapter.d.ts +3 -0
  68. package/lib/pricing/delivery-swiss-tax/adapter.js +62 -0
  69. package/lib/pricing/delivery-swiss-tax/index.d.ts +4 -0
  70. package/lib/pricing/delivery-swiss-tax/index.js +10 -0
  71. package/lib/pricing/discount-100-off/adapter.d.ts +3 -0
  72. package/lib/pricing/discount-100-off/adapter.js +30 -0
  73. package/lib/pricing/discount-100-off/index.d.ts +4 -0
  74. package/lib/pricing/discount-100-off/index.js +10 -0
  75. package/lib/pricing/discount-half-price-manual/adapter.d.ts +3 -0
  76. package/lib/pricing/discount-half-price-manual/adapter.js +30 -0
  77. package/lib/pricing/discount-half-price-manual/index.d.ts +4 -0
  78. package/lib/pricing/discount-half-price-manual/index.js +10 -0
  79. package/lib/pricing/free-delivery/adapter.d.ts +3 -0
  80. package/lib/pricing/free-delivery/adapter.js +27 -0
  81. package/lib/pricing/free-delivery/index.d.ts +4 -0
  82. package/lib/pricing/free-delivery/index.js +10 -0
  83. package/lib/pricing/free-payment/adapter.d.ts +3 -0
  84. package/lib/pricing/free-payment/adapter.js +27 -0
  85. package/lib/pricing/free-payment/index.d.ts +4 -0
  86. package/lib/pricing/free-payment/index.js +10 -0
  87. package/lib/pricing/order-delivery/adapter.d.ts +3 -0
  88. package/lib/pricing/order-delivery/adapter.js +33 -0
  89. package/lib/pricing/order-delivery/index.d.ts +4 -0
  90. package/lib/pricing/order-delivery/index.js +10 -0
  91. package/lib/pricing/order-discount/adapter.d.ts +3 -0
  92. package/lib/pricing/order-discount/adapter.js +74 -0
  93. package/lib/pricing/order-discount/index.d.ts +4 -0
  94. package/lib/pricing/order-discount/index.js +10 -0
  95. package/lib/pricing/order-items/adapter.d.ts +3 -0
  96. package/lib/pricing/order-items/adapter.js +43 -0
  97. package/lib/pricing/order-items/index.d.ts +4 -0
  98. package/lib/pricing/order-items/index.js +10 -0
  99. package/lib/pricing/order-payment/adapter.d.ts +3 -0
  100. package/lib/pricing/order-payment/adapter.js +33 -0
  101. package/lib/pricing/order-payment/index.d.ts +4 -0
  102. package/lib/pricing/order-payment/index.js +10 -0
  103. package/lib/pricing/product-catalog-price/adapter.d.ts +3 -0
  104. package/lib/pricing/product-catalog-price/adapter.js +60 -0
  105. package/lib/pricing/product-catalog-price/index.d.ts +4 -0
  106. package/lib/pricing/product-catalog-price/index.js +10 -0
  107. package/lib/pricing/product-discount/adapter.d.ts +3 -0
  108. package/lib/pricing/product-discount/adapter.js +69 -0
  109. package/lib/pricing/product-discount/index.d.ts +4 -0
  110. package/lib/pricing/product-discount/index.js +10 -0
  111. package/lib/pricing/product-price-rateconversion/adapter.d.ts +3 -0
  112. package/lib/pricing/product-price-rateconversion/adapter.js +53 -0
  113. package/lib/pricing/product-price-rateconversion/index.d.ts +4 -0
  114. package/lib/pricing/product-price-rateconversion/index.js +10 -0
  115. package/lib/pricing/product-swiss-tax/adapter.d.ts +3 -0
  116. package/lib/pricing/product-swiss-tax/adapter.js +76 -0
  117. package/lib/pricing/product-swiss-tax/index.d.ts +4 -0
  118. package/lib/pricing/product-swiss-tax/index.js +10 -0
  119. package/lib/quotations/manual/adapter.d.ts +2 -0
  120. package/lib/quotations/manual/adapter.js +19 -0
  121. package/lib/quotations/manual/index.d.ts +4 -0
  122. package/lib/quotations/manual/index.js +10 -0
  123. package/lib/warehousing/erc-metadata/api.d.ts +12 -0
  124. package/lib/warehousing/erc-metadata/api.js +43 -0
  125. package/lib/warehousing/erc-metadata/index.d.ts +3 -0
  126. package/lib/warehousing/erc-metadata/index.js +15 -0
  127. package/lib/warehousing/eth-minter/adapter.d.ts +2 -0
  128. package/lib/warehousing/eth-minter/adapter.js +119 -0
  129. package/lib/warehousing/eth-minter/index.d.ts +4 -0
  130. package/lib/warehousing/eth-minter/index.js +10 -0
  131. package/lib/warehousing/store/adapter.d.ts +2 -0
  132. package/lib/warehousing/store/adapter.js +33 -0
  133. package/lib/warehousing/store/index.d.ts +4 -0
  134. package/lib/warehousing/store/index.js +10 -0
  135. package/lib/worker/budgetsms/adapter.d.ts +22 -0
  136. package/lib/worker/budgetsms/adapter.js +169 -0
  137. package/lib/worker/budgetsms/index.d.ts +4 -0
  138. package/lib/worker/budgetsms/index.js +10 -0
  139. package/lib/worker/bulk-export/adapter.d.ts +3 -0
  140. package/lib/worker/bulk-export/adapter.js +64 -0
  141. package/lib/worker/bulk-export/index.d.ts +4 -0
  142. package/lib/worker/bulk-export/index.js +10 -0
  143. package/lib/worker/bulk-import/adapter.d.ts +3 -0
  144. package/lib/worker/bulk-import/adapter.js +65 -0
  145. package/lib/worker/bulk-import/api.d.ts +7 -0
  146. package/lib/worker/bulk-import/api.js +53 -0
  147. package/lib/worker/bulk-import/index.d.ts +4 -0
  148. package/lib/worker/bulk-import/index.js +18 -0
  149. package/lib/worker/bulkgate/adapter.d.ts +12 -0
  150. package/lib/worker/bulkgate/adapter.js +91 -0
  151. package/lib/worker/bulkgate/index.d.ts +4 -0
  152. package/lib/worker/bulkgate/index.js +10 -0
  153. package/lib/worker/email/adapter.d.ts +9 -0
  154. package/lib/worker/email/adapter.js +150 -0
  155. package/lib/worker/email/index.d.ts +4 -0
  156. package/lib/worker/email/index.js +10 -0
  157. package/lib/worker/enrollment-order-generator/adapter.d.ts +4 -0
  158. package/lib/worker/enrollment-order-generator/adapter.js +77 -0
  159. package/lib/worker/enrollment-order-generator/index.d.ts +4 -0
  160. package/lib/worker/enrollment-order-generator/index.js +13 -0
  161. package/lib/worker/error-notifications/adapter.d.ts +10 -0
  162. package/lib/worker/error-notifications/adapter.js +62 -0
  163. package/lib/worker/error-notifications/index.d.ts +4 -0
  164. package/lib/worker/error-notifications/index.js +13 -0
  165. package/lib/worker/export-token/adapter.d.ts +4 -0
  166. package/lib/worker/export-token/adapter.js +25 -0
  167. package/lib/worker/export-token/index.d.ts +4 -0
  168. package/lib/worker/export-token/index.js +13 -0
  169. package/lib/worker/external/adapter.d.ts +3 -0
  170. package/lib/worker/external/adapter.js +13 -0
  171. package/lib/worker/external/index.d.ts +4 -0
  172. package/lib/worker/external/index.js +10 -0
  173. package/lib/worker/heartbeat/adapter.d.ts +8 -0
  174. package/lib/worker/heartbeat/adapter.js +26 -0
  175. package/lib/worker/heartbeat/index.d.ts +4 -0
  176. package/lib/worker/heartbeat/index.js +10 -0
  177. package/lib/worker/http-request/adapter.d.ts +8 -0
  178. package/lib/worker/http-request/adapter.js +55 -0
  179. package/lib/worker/http-request/index.d.ts +4 -0
  180. package/lib/worker/http-request/index.js +10 -0
  181. package/lib/worker/message/adapter.d.ts +11 -0
  182. package/lib/worker/message/adapter.js +42 -0
  183. package/lib/worker/message/index.d.ts +4 -0
  184. package/lib/worker/message/index.js +10 -0
  185. package/lib/worker/push-notification/adapter.d.ts +9 -0
  186. package/lib/worker/push-notification/adapter.js +87 -0
  187. package/lib/worker/push-notification/index.d.ts +4 -0
  188. package/lib/worker/push-notification/index.js +10 -0
  189. package/lib/worker/twilio/adapter.d.ts +8 -0
  190. package/lib/worker/twilio/adapter.js +59 -0
  191. package/lib/worker/twilio/index.d.ts +4 -0
  192. package/lib/worker/twilio/index.js +10 -0
  193. package/lib/worker/update-coinbase-rates/adapter.d.ts +4 -0
  194. package/lib/worker/update-coinbase-rates/adapter.js +61 -0
  195. package/lib/worker/update-coinbase-rates/index.d.ts +4 -0
  196. package/lib/worker/update-coinbase-rates/index.js +13 -0
  197. package/lib/worker/update-ecb-rates/adapter.d.ts +4 -0
  198. package/lib/worker/update-ecb-rates/adapter.js +94 -0
  199. package/lib/worker/update-ecb-rates/index.d.ts +4 -0
  200. package/lib/worker/update-ecb-rates/index.js +13 -0
  201. package/lib/worker/update-token-ownership/adapter.d.ts +5 -0
  202. package/lib/worker/update-token-ownership/adapter.js +58 -0
  203. package/lib/worker/update-token-ownership/index.d.ts +4 -0
  204. package/lib/worker/update-token-ownership/index.js +13 -0
  205. package/lib/worker/zombie-killer/adapter.d.ts +13 -0
  206. package/lib/worker/zombie-killer/adapter.js +90 -0
  207. package/lib/worker/zombie-killer/index.d.ts +4 -0
  208. package/lib/worker/zombie-killer/index.js +10 -0
  209. package/package.json +1 -1
@@ -0,0 +1,10 @@
1
+ import {} from '@unchainedshop/core';
2
+ import { ExternalWorkerPlugin as ExternalWorker } from "./adapter.js";
3
+ export const ExternalPlugin = {
4
+ key: 'shop.unchained.worker-plugin.external',
5
+ label: 'External Worker Plugin',
6
+ version: '1.0.0',
7
+ adapters: [ExternalWorker],
8
+ };
9
+ export default ExternalPlugin;
10
+ export { ExternalWorkerPlugin } from "./adapter.js";
@@ -0,0 +1,8 @@
1
+ import { type IWorkerAdapter } from '@unchainedshop/core';
2
+ interface Arg {
3
+ wait?: number;
4
+ fails?: boolean;
5
+ }
6
+ type Result = Arg;
7
+ export declare const Heartbeat: IWorkerAdapter<Arg, Result>;
8
+ export default Heartbeat;
@@ -0,0 +1,26 @@
1
+ import { WorkerAdapter } from '@unchainedshop/core';
2
+ import { setTimeout } from 'node:timers/promises';
3
+ export 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
+ export default Heartbeat;
@@ -0,0 +1,4 @@
1
+ import { type IPlugin } from '@unchainedshop/core';
2
+ export declare const HeartbeatPlugin: IPlugin;
3
+ export default HeartbeatPlugin;
4
+ export { Heartbeat } from './adapter.ts';
@@ -0,0 +1,10 @@
1
+ import {} from '@unchainedshop/core';
2
+ import { Heartbeat } from "./adapter.js";
3
+ export const HeartbeatPlugin = {
4
+ key: 'shop.unchained.worker-plugin.heartbeat',
5
+ label: 'Heartbeat Worker Plugin',
6
+ version: '1.0.0',
7
+ adapters: [Heartbeat],
8
+ };
9
+ export default HeartbeatPlugin;
10
+ export { Heartbeat } from "./adapter.js";
@@ -0,0 +1,8 @@
1
+ import { type IWorkerAdapter } from '@unchainedshop/core';
2
+ export declare const HttpRequestWorkerPlugin: IWorkerAdapter<{
3
+ url?: string;
4
+ data?: any;
5
+ headers?: any;
6
+ method: 'POST' | 'GET';
7
+ }, any>;
8
+ export default HttpRequestWorkerPlugin;
@@ -0,0 +1,55 @@
1
+ import { WorkerAdapter } 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
+ export 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
+ export default HttpRequestWorkerPlugin;
@@ -0,0 +1,4 @@
1
+ import { type IPlugin } from '@unchainedshop/core';
2
+ export declare const HttpRequestPlugin: IPlugin;
3
+ export default HttpRequestPlugin;
4
+ export { HttpRequestWorkerPlugin } from './adapter.ts';
@@ -0,0 +1,10 @@
1
+ import {} from '@unchainedshop/core';
2
+ import { HttpRequestWorkerPlugin as HttpRequestWorker } from "./adapter.js";
3
+ export const HttpRequestPlugin = {
4
+ key: 'shop.unchained.worker-plugin.http-request',
5
+ label: 'HTTP Request Worker Plugin',
6
+ version: '1.0.0',
7
+ adapters: [HttpRequestWorker],
8
+ };
9
+ export default HttpRequestPlugin;
10
+ export { HttpRequestWorkerPlugin } from "./adapter.js";
@@ -0,0 +1,11 @@
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
+ }>;
11
+ export default MessageWorker;
@@ -0,0 +1,42 @@
1
+ import { MessagingDirector, WorkerAdapter } 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
+ export default MessageWorker;
@@ -0,0 +1,4 @@
1
+ import { type IPlugin } from '@unchainedshop/core';
2
+ export declare const MessagePlugin: IPlugin;
3
+ export default MessagePlugin;
4
+ export * from './adapter.ts';
@@ -0,0 +1,10 @@
1
+ import {} from '@unchainedshop/core';
2
+ import { MessageWorker } from "./adapter.js";
3
+ export const MessagePlugin = {
4
+ key: 'shop.unchained.worker-plugin.message',
5
+ label: 'Message Worker Plugin',
6
+ version: '1.0.0',
7
+ adapters: [MessageWorker],
8
+ };
9
+ export default MessagePlugin;
10
+ export * from "./adapter.js";
@@ -0,0 +1,9 @@
1
+ import { type IWorkerAdapter } from '@unchainedshop/core';
2
+ export declare const PushNotificationWorkerPlugin: IWorkerAdapter<{
3
+ subscription: any;
4
+ payload: string;
5
+ subject: string;
6
+ urgency?: 'very-low' | 'low' | 'normal' | 'high';
7
+ topic?: string;
8
+ }, any>;
9
+ export default PushNotificationWorkerPlugin;
@@ -0,0 +1,87 @@
1
+ import { WorkerAdapter } 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
+ export 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
+ export default PushNotificationWorkerPlugin;
@@ -0,0 +1,4 @@
1
+ import { type IPlugin } from '@unchainedshop/core';
2
+ export declare const PushNotificationPlugin: IPlugin;
3
+ export default PushNotificationPlugin;
4
+ export { PushNotificationWorkerPlugin } from './adapter.ts';
@@ -0,0 +1,10 @@
1
+ import {} from '@unchainedshop/core';
2
+ import { PushNotificationWorkerPlugin as PushNotificationWorker } from "./adapter.js";
3
+ export const PushNotificationPlugin = {
4
+ key: 'shop.unchained.worker-plugin.push-notification',
5
+ label: 'Push Notification Worker Plugin',
6
+ version: '1.0.0',
7
+ adapters: [PushNotificationWorker],
8
+ };
9
+ export default PushNotificationPlugin;
10
+ export { PushNotificationWorkerPlugin } from "./adapter.js";
@@ -0,0 +1,8 @@
1
+ import { type IWorkerAdapter } from '@unchainedshop/core';
2
+ export declare const SmsWorkerPlugin: IWorkerAdapter<{
3
+ from?: string;
4
+ to: string;
5
+ text: string;
6
+ [key: string]: any;
7
+ }, any>;
8
+ export default SmsWorkerPlugin;
@@ -0,0 +1,59 @@
1
+ import { WorkerAdapter } from '@unchainedshop/core';
2
+ const { TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO_SMS_FROM } = process.env;
3
+ export 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
+ export default SmsWorkerPlugin;
@@ -0,0 +1,4 @@
1
+ import { type IPlugin } from '@unchainedshop/core';
2
+ export declare const TwilioPlugin: IPlugin;
3
+ export default TwilioPlugin;
4
+ export { SmsWorkerPlugin } from './adapter.ts';
@@ -0,0 +1,10 @@
1
+ import {} from '@unchainedshop/core';
2
+ import { SmsWorkerPlugin as TwilioWorker } from "./adapter.js";
3
+ export const TwilioPlugin = {
4
+ key: 'shop.unchained.worker-plugin.twilio',
5
+ label: 'Twilio SMS Worker Plugin',
6
+ version: '1.0.0',
7
+ adapters: [TwilioWorker],
8
+ };
9
+ export default TwilioPlugin;
10
+ export { SmsWorkerPlugin } from "./adapter.js";
@@ -0,0 +1,4 @@
1
+ import { type IWorkerAdapter } from '@unchainedshop/core';
2
+ export declare const UpdateCoinbaseRates: IWorkerAdapter<any, any>;
3
+ export default UpdateCoinbaseRates;
4
+ export declare const configureUpdateCoinbaseRatesAutoscheduling: () => void;
@@ -0,0 +1,61 @@
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
+ export 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
+ export default UpdateCoinbaseRates;
56
+ export const configureUpdateCoinbaseRatesAutoscheduling = () => {
57
+ WorkerDirector.configureAutoscheduling({
58
+ type: UpdateCoinbaseRates.type,
59
+ schedule: everyMinute,
60
+ });
61
+ };
@@ -0,0 +1,4 @@
1
+ import { type IPlugin } from '@unchainedshop/core';
2
+ export declare const UpdateCoinbaseRatesPlugin: IPlugin;
3
+ export default UpdateCoinbaseRatesPlugin;
4
+ export { UpdateCoinbaseRates, configureUpdateCoinbaseRatesAutoscheduling } from './adapter.ts';
@@ -0,0 +1,13 @@
1
+ import {} from '@unchainedshop/core';
2
+ import { UpdateCoinbaseRates, configureUpdateCoinbaseRatesAutoscheduling } from "./adapter.js";
3
+ export const UpdateCoinbaseRatesPlugin = {
4
+ key: 'shop.unchained.worker.update-coinbase-rates',
5
+ label: 'Update Coinbase Rates Worker Plugin',
6
+ version: '1.0.0',
7
+ adapters: [UpdateCoinbaseRates],
8
+ onRegister: () => {
9
+ configureUpdateCoinbaseRatesAutoscheduling();
10
+ },
11
+ };
12
+ export default UpdateCoinbaseRatesPlugin;
13
+ export { UpdateCoinbaseRates, configureUpdateCoinbaseRatesAutoscheduling } from "./adapter.js";
@@ -0,0 +1,4 @@
1
+ import { type IWorkerAdapter } from '@unchainedshop/core';
2
+ export declare const UpdateECBRates: IWorkerAdapter<any, any>;
3
+ export default UpdateECBRates;
4
+ export declare const configureUpdateECBRatesAutoscheduling: () => void;
@@ -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,4 @@
1
+ import { type IPlugin } from '@unchainedshop/core';
2
+ export declare const UpdateECBRatesPlugin: IPlugin;
3
+ export default UpdateECBRatesPlugin;
4
+ export { UpdateECBRates, configureUpdateECBRatesAutoscheduling } from './adapter.ts';
@@ -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;