@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.
Files changed (214) 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/payment/stripe/stripe.js +12 -10
  68. package/lib/presets/base.d.ts +1 -0
  69. package/lib/presets/base.js +1 -0
  70. package/lib/pricing/delivery-swiss-tax/adapter.d.ts +3 -0
  71. package/lib/pricing/delivery-swiss-tax/adapter.js +62 -0
  72. package/lib/pricing/delivery-swiss-tax/index.d.ts +4 -0
  73. package/lib/pricing/delivery-swiss-tax/index.js +10 -0
  74. package/lib/pricing/discount-100-off/adapter.d.ts +3 -0
  75. package/lib/pricing/discount-100-off/adapter.js +30 -0
  76. package/lib/pricing/discount-100-off/index.d.ts +4 -0
  77. package/lib/pricing/discount-100-off/index.js +10 -0
  78. package/lib/pricing/discount-half-price-manual/adapter.d.ts +3 -0
  79. package/lib/pricing/discount-half-price-manual/adapter.js +30 -0
  80. package/lib/pricing/discount-half-price-manual/index.d.ts +4 -0
  81. package/lib/pricing/discount-half-price-manual/index.js +10 -0
  82. package/lib/pricing/free-delivery/adapter.d.ts +3 -0
  83. package/lib/pricing/free-delivery/adapter.js +27 -0
  84. package/lib/pricing/free-delivery/index.d.ts +4 -0
  85. package/lib/pricing/free-delivery/index.js +10 -0
  86. package/lib/pricing/free-payment/adapter.d.ts +3 -0
  87. package/lib/pricing/free-payment/adapter.js +27 -0
  88. package/lib/pricing/free-payment/index.d.ts +4 -0
  89. package/lib/pricing/free-payment/index.js +10 -0
  90. package/lib/pricing/order-delivery/adapter.d.ts +3 -0
  91. package/lib/pricing/order-delivery/adapter.js +33 -0
  92. package/lib/pricing/order-delivery/index.d.ts +4 -0
  93. package/lib/pricing/order-delivery/index.js +10 -0
  94. package/lib/pricing/order-discount/adapter.d.ts +3 -0
  95. package/lib/pricing/order-discount/adapter.js +74 -0
  96. package/lib/pricing/order-discount/index.d.ts +4 -0
  97. package/lib/pricing/order-discount/index.js +10 -0
  98. package/lib/pricing/order-items/adapter.d.ts +3 -0
  99. package/lib/pricing/order-items/adapter.js +43 -0
  100. package/lib/pricing/order-items/index.d.ts +4 -0
  101. package/lib/pricing/order-items/index.js +10 -0
  102. package/lib/pricing/order-payment/adapter.d.ts +3 -0
  103. package/lib/pricing/order-payment/adapter.js +33 -0
  104. package/lib/pricing/order-payment/index.d.ts +4 -0
  105. package/lib/pricing/order-payment/index.js +10 -0
  106. package/lib/pricing/product-catalog-price/adapter.d.ts +3 -0
  107. package/lib/pricing/product-catalog-price/adapter.js +60 -0
  108. package/lib/pricing/product-catalog-price/index.d.ts +4 -0
  109. package/lib/pricing/product-catalog-price/index.js +10 -0
  110. package/lib/pricing/product-discount/adapter.d.ts +3 -0
  111. package/lib/pricing/product-discount/adapter.js +69 -0
  112. package/lib/pricing/product-discount/index.d.ts +4 -0
  113. package/lib/pricing/product-discount/index.js +10 -0
  114. package/lib/pricing/product-price-rateconversion/adapter.d.ts +3 -0
  115. package/lib/pricing/product-price-rateconversion/adapter.js +53 -0
  116. package/lib/pricing/product-price-rateconversion/index.d.ts +4 -0
  117. package/lib/pricing/product-price-rateconversion/index.js +10 -0
  118. package/lib/pricing/product-swiss-tax/adapter.d.ts +3 -0
  119. package/lib/pricing/product-swiss-tax/adapter.js +76 -0
  120. package/lib/pricing/product-swiss-tax/index.d.ts +4 -0
  121. package/lib/pricing/product-swiss-tax/index.js +10 -0
  122. package/lib/quotations/manual/adapter.d.ts +2 -0
  123. package/lib/quotations/manual/adapter.js +19 -0
  124. package/lib/quotations/manual/index.d.ts +4 -0
  125. package/lib/quotations/manual/index.js +10 -0
  126. package/lib/warehousing/erc-metadata/api.d.ts +12 -0
  127. package/lib/warehousing/erc-metadata/api.js +43 -0
  128. package/lib/warehousing/erc-metadata/index.d.ts +3 -0
  129. package/lib/warehousing/erc-metadata/index.js +15 -0
  130. package/lib/warehousing/eth-minter/adapter.d.ts +2 -0
  131. package/lib/warehousing/eth-minter/adapter.js +119 -0
  132. package/lib/warehousing/eth-minter/index.d.ts +4 -0
  133. package/lib/warehousing/eth-minter/index.js +10 -0
  134. package/lib/warehousing/store/adapter.d.ts +2 -0
  135. package/lib/warehousing/store/adapter.js +33 -0
  136. package/lib/warehousing/store/index.d.ts +4 -0
  137. package/lib/warehousing/store/index.js +10 -0
  138. package/lib/worker/budgetsms/adapter.d.ts +22 -0
  139. package/lib/worker/budgetsms/adapter.js +169 -0
  140. package/lib/worker/budgetsms/index.d.ts +4 -0
  141. package/lib/worker/budgetsms/index.js +10 -0
  142. package/lib/worker/bulk-export/adapter.d.ts +3 -0
  143. package/lib/worker/bulk-export/adapter.js +64 -0
  144. package/lib/worker/bulk-export/index.d.ts +4 -0
  145. package/lib/worker/bulk-export/index.js +10 -0
  146. package/lib/worker/bulk-export.d.ts +2 -0
  147. package/lib/worker/bulk-export.js +64 -0
  148. package/lib/worker/bulk-import/adapter.d.ts +3 -0
  149. package/lib/worker/bulk-import/adapter.js +65 -0
  150. package/lib/worker/bulk-import/api.d.ts +7 -0
  151. package/lib/worker/bulk-import/api.js +53 -0
  152. package/lib/worker/bulk-import/index.d.ts +4 -0
  153. package/lib/worker/bulk-import/index.js +18 -0
  154. package/lib/worker/bulkgate/adapter.d.ts +12 -0
  155. package/lib/worker/bulkgate/adapter.js +91 -0
  156. package/lib/worker/bulkgate/index.d.ts +4 -0
  157. package/lib/worker/bulkgate/index.js +10 -0
  158. package/lib/worker/email/adapter.d.ts +9 -0
  159. package/lib/worker/email/adapter.js +150 -0
  160. package/lib/worker/email/index.d.ts +4 -0
  161. package/lib/worker/email/index.js +10 -0
  162. package/lib/worker/enrollment-order-generator/adapter.d.ts +4 -0
  163. package/lib/worker/enrollment-order-generator/adapter.js +77 -0
  164. package/lib/worker/enrollment-order-generator/index.d.ts +4 -0
  165. package/lib/worker/enrollment-order-generator/index.js +13 -0
  166. package/lib/worker/error-notifications/adapter.d.ts +10 -0
  167. package/lib/worker/error-notifications/adapter.js +62 -0
  168. package/lib/worker/error-notifications/index.d.ts +4 -0
  169. package/lib/worker/error-notifications/index.js +13 -0
  170. package/lib/worker/export-token/adapter.d.ts +4 -0
  171. package/lib/worker/export-token/adapter.js +25 -0
  172. package/lib/worker/export-token/index.d.ts +4 -0
  173. package/lib/worker/export-token/index.js +13 -0
  174. package/lib/worker/external/adapter.d.ts +3 -0
  175. package/lib/worker/external/adapter.js +13 -0
  176. package/lib/worker/external/index.d.ts +4 -0
  177. package/lib/worker/external/index.js +10 -0
  178. package/lib/worker/heartbeat/adapter.d.ts +8 -0
  179. package/lib/worker/heartbeat/adapter.js +26 -0
  180. package/lib/worker/heartbeat/index.d.ts +4 -0
  181. package/lib/worker/heartbeat/index.js +10 -0
  182. package/lib/worker/http-request/adapter.d.ts +8 -0
  183. package/lib/worker/http-request/adapter.js +55 -0
  184. package/lib/worker/http-request/index.d.ts +4 -0
  185. package/lib/worker/http-request/index.js +10 -0
  186. package/lib/worker/message/adapter.d.ts +11 -0
  187. package/lib/worker/message/adapter.js +42 -0
  188. package/lib/worker/message/index.d.ts +4 -0
  189. package/lib/worker/message/index.js +10 -0
  190. package/lib/worker/push-notification/adapter.d.ts +9 -0
  191. package/lib/worker/push-notification/adapter.js +87 -0
  192. package/lib/worker/push-notification/index.d.ts +4 -0
  193. package/lib/worker/push-notification/index.js +10 -0
  194. package/lib/worker/twilio/adapter.d.ts +8 -0
  195. package/lib/worker/twilio/adapter.js +59 -0
  196. package/lib/worker/twilio/index.d.ts +4 -0
  197. package/lib/worker/twilio/index.js +10 -0
  198. package/lib/worker/update-coinbase-rates/adapter.d.ts +4 -0
  199. package/lib/worker/update-coinbase-rates/adapter.js +61 -0
  200. package/lib/worker/update-coinbase-rates/index.d.ts +4 -0
  201. package/lib/worker/update-coinbase-rates/index.js +13 -0
  202. package/lib/worker/update-ecb-rates/adapter.d.ts +4 -0
  203. package/lib/worker/update-ecb-rates/adapter.js +94 -0
  204. package/lib/worker/update-ecb-rates/index.d.ts +4 -0
  205. package/lib/worker/update-ecb-rates/index.js +13 -0
  206. package/lib/worker/update-token-ownership/adapter.d.ts +5 -0
  207. package/lib/worker/update-token-ownership/adapter.js +58 -0
  208. package/lib/worker/update-token-ownership/index.d.ts +4 -0
  209. package/lib/worker/update-token-ownership/index.js +13 -0
  210. package/lib/worker/zombie-killer/adapter.d.ts +13 -0
  211. package/lib/worker/zombie-killer/adapter.js +90 -0
  212. package/lib/worker/zombie-killer/index.d.ts +4 -0
  213. package/lib/worker/zombie-killer/index.js +10 -0
  214. package/package.json +1 -1
@@ -0,0 +1,25 @@
1
+ import { WorkerEventTypes } from '@unchainedshop/core-worker';
2
+ import { WorkerAdapter } 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 ExportTokenWorker;
@@ -0,0 +1,4 @@
1
+ import { type IPlugin } from '@unchainedshop/core';
2
+ export declare const ExportTokenPlugin: IPlugin;
3
+ export default ExportTokenPlugin;
4
+ export { ExportTokenWorker, configureExportToken } from './adapter.ts';
@@ -0,0 +1,13 @@
1
+ import {} from '@unchainedshop/core';
2
+ import { ExportTokenWorker, configureExportToken } from "./adapter.js";
3
+ export const ExportTokenPlugin = {
4
+ key: 'shop.unchained.worker.export-token',
5
+ label: 'Export Token Worker Plugin',
6
+ version: '1.0.0',
7
+ adapters: [ExportTokenWorker],
8
+ onRegister: (unchainedAPI) => {
9
+ configureExportToken(unchainedAPI);
10
+ },
11
+ };
12
+ export default ExportTokenPlugin;
13
+ export { ExportTokenWorker, configureExportToken } from "./adapter.js";
@@ -0,0 +1,3 @@
1
+ import { type IWorkerAdapter } from '@unchainedshop/core';
2
+ export declare const ExternalWorkerPlugin: IWorkerAdapter<void, void>;
3
+ export default ExternalWorkerPlugin;
@@ -0,0 +1,13 @@
1
+ import { WorkerAdapter } 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
+ export default ExternalWorkerPlugin;
@@ -0,0 +1,4 @@
1
+ import { type IPlugin } from '@unchainedshop/core';
2
+ export declare const ExternalPlugin: IPlugin;
3
+ export default ExternalPlugin;
4
+ export { ExternalWorkerPlugin } from './adapter.ts';
@@ -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;