@unchainedshop/plugins 1.1.3

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 (76) hide show
  1. package/lib/events/node-event-emitter.d.ts +1 -0
  2. package/lib/events/node-event-emitter.js +16 -0
  3. package/lib/events/node-event-emitter.js.map +1 -0
  4. package/lib/events/redis.d.ts +1 -0
  5. package/lib/events/redis.js +24 -0
  6. package/lib/events/redis.js.map +1 -0
  7. package/lib/files/gridfs/gridfs-adapter.d.ts +2 -0
  8. package/lib/files/gridfs/gridfs-adapter.js +106 -0
  9. package/lib/files/gridfs/gridfs-adapter.js.map +1 -0
  10. package/lib/files/gridfs/gridfs-webhook.d.ts +1 -0
  11. package/lib/files/gridfs/gridfs-webhook.js +54 -0
  12. package/lib/files/gridfs/gridfs-webhook.js.map +1 -0
  13. package/lib/files/gridfs/index.d.ts +8 -0
  14. package/lib/files/gridfs/index.js +21 -0
  15. package/lib/files/gridfs/index.js.map +1 -0
  16. package/lib/files/gridfs/promisePipe.d.ts +2 -0
  17. package/lib/files/gridfs/promisePipe.js +21 -0
  18. package/lib/files/gridfs/promisePipe.js.map +1 -0
  19. package/lib/files/gridfs/sign.d.ts +2 -0
  20. package/lib/files/gridfs/sign.js +12 -0
  21. package/lib/files/gridfs/sign.js.map +1 -0
  22. package/lib/files/minio/minio-adapter.d.ts +4 -0
  23. package/lib/files/minio/minio-adapter.js +166 -0
  24. package/lib/files/minio/minio-adapter.js.map +1 -0
  25. package/lib/files/minio/minio-webhook.d.ts +1 -0
  26. package/lib/files/minio/minio-webhook.js +45 -0
  27. package/lib/files/minio/minio-webhook.js.map +1 -0
  28. package/lib/worker/BulkImportWorker.d.ts +2 -0
  29. package/lib/worker/BulkImportWorker.js +91 -0
  30. package/lib/worker/BulkImportWorker.js.map +1 -0
  31. package/lib/worker/GenerateOrderWorker.d.ts +1 -0
  32. package/lib/worker/GenerateOrderWorker.js +110 -0
  33. package/lib/worker/GenerateOrderWorker.js.map +1 -0
  34. package/lib/worker/MessageWorker.d.ts +10 -0
  35. package/lib/worker/MessageWorker.js +45 -0
  36. package/lib/worker/MessageWorker.js.map +1 -0
  37. package/lib/worker/ZombieKillerWorker.d.ts +7 -0
  38. package/lib/worker/ZombieKillerWorker.js +88 -0
  39. package/lib/worker/ZombieKillerWorker.js.map +1 -0
  40. package/lib/worker/email.d.ts +1 -0
  41. package/lib/worker/email.js +45 -0
  42. package/lib/worker/email.js.map +1 -0
  43. package/lib/worker/external.d.ts +2 -0
  44. package/lib/worker/external.js +13 -0
  45. package/lib/worker/external.js.map +1 -0
  46. package/lib/worker/heartbeat.d.ts +1 -0
  47. package/lib/worker/heartbeat.js +32 -0
  48. package/lib/worker/heartbeat.js.map +1 -0
  49. package/lib/worker/http-request.d.ts +8 -0
  50. package/lib/worker/http-request.js +61 -0
  51. package/lib/worker/http-request.js.map +1 -0
  52. package/lib/worker/sms.d.ts +1 -0
  53. package/lib/worker/sms.js +69 -0
  54. package/lib/worker/sms.js.map +1 -0
  55. package/package.json +44 -0
  56. package/readme.md +1 -0
  57. package/src/events/node-event-emitter.ts +20 -0
  58. package/src/events/redis.ts +30 -0
  59. package/src/files/gridfs/gridfs-adapter.ts +136 -0
  60. package/src/files/gridfs/gridfs-webhook.js +60 -0
  61. package/src/files/gridfs/index.js +21 -0
  62. package/src/files/gridfs/promisePipe.js +19 -0
  63. package/src/files/gridfs/sign.js +16 -0
  64. package/src/files/minio/minio-adapter.ts +215 -0
  65. package/src/files/minio/minio-webhook.js +51 -0
  66. package/src/worker/BulkImportWorker.ts +117 -0
  67. package/src/worker/GenerateOrderWorker.ts +156 -0
  68. package/src/worker/MessageWorker.ts +62 -0
  69. package/src/worker/ZombieKillerWorker.ts +114 -0
  70. package/src/worker/email.ts +60 -0
  71. package/src/worker/external.ts +17 -0
  72. package/src/worker/heartbeat.ts +45 -0
  73. package/src/worker/http-request.ts +75 -0
  74. package/src/worker/sms.ts +85 -0
  75. package/tsconfig.build.json +26 -0
  76. package/tsconfig.json +8 -0
@@ -0,0 +1,85 @@
1
+ import { WorkerDirector, WorkerAdapter } from '@unchainedshop/core-worker';
2
+ import { createLogger } from '@unchainedshop/logger';
3
+ import { IWorkerAdapter } from '@unchainedshop/types/worker';
4
+ import Twilio from 'twilio';
5
+
6
+ const { TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO_SMS_FROM } = process.env;
7
+
8
+ const logger = createLogger('unchained:plugins:worker:sms');
9
+
10
+ const SmsWorkerPlugin: IWorkerAdapter<
11
+ {
12
+ from?: string;
13
+ to?: string;
14
+ text?: string;
15
+ },
16
+ any
17
+ > = {
18
+ ...WorkerAdapter,
19
+
20
+ key: 'shop.unchained.worker-plugin.sms',
21
+ label: 'Send a SMS through Twilio',
22
+ version: '1.0',
23
+
24
+ type: 'SMS',
25
+
26
+ doWork: async ({ from, to, text }) => {
27
+ logger.debug(`${SmsWorkerPlugin.key} -> doWork: ${from} -> ${to}`);
28
+
29
+ if (!TWILIO_SMS_FROM && !from) {
30
+ return {
31
+ success: false,
32
+ error: {
33
+ name: 'SENDER_REQUIRED',
34
+ message: 'SMS requires a from, TWILIO_SMS_FROM not set',
35
+ },
36
+ };
37
+ }
38
+
39
+ if (!to) {
40
+ return {
41
+ success: false,
42
+ error: {
43
+ name: 'RECIPIENT_REQUIRED',
44
+ message: 'SMS requires a to',
45
+ },
46
+ };
47
+ }
48
+
49
+ try {
50
+ const client = Twilio(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN);
51
+ const { sid, errorMessage } = await client.messages.create({
52
+ body: text,
53
+ from: from || TWILIO_SMS_FROM,
54
+ to,
55
+ });
56
+ if (errorMessage) {
57
+ return {
58
+ success: false,
59
+ error: {
60
+ name: 'TWILIO_ERROR',
61
+ message: errorMessage.toString(),
62
+ },
63
+ };
64
+ }
65
+ return {
66
+ success: true,
67
+ result: {
68
+ sid,
69
+ },
70
+ error: null,
71
+ };
72
+ } catch (err) {
73
+ return {
74
+ success: false,
75
+ error: {
76
+ name: err.name,
77
+ message: err.message,
78
+ stack: err.stack,
79
+ },
80
+ };
81
+ }
82
+ },
83
+ };
84
+
85
+ WorkerDirector.registerAdapter(SmsWorkerPlugin);
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "allowSyntheticDefaultImports": true,
5
+ "declaration": true,
6
+ "esModuleInterop": true,
7
+ "experimentalDecorators": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "lib": ["esnext"],
10
+ "module": "esnext",
11
+ "moduleResolution": "node",
12
+ "noImplicitReturns": true,
13
+ "noUnusedLocals": false,
14
+ "outDir": "lib",
15
+ "preserveWatchOutput": true,
16
+ "skipLibCheck": true,
17
+ "sourceMap": true,
18
+ "target": "esnext",
19
+ "types": ["node"],
20
+ "baseUrl": ".", // This must be specified if "paths" is.
21
+ "paths": {
22
+ "meteor/unchained:*": ["node_modules/@unchainedshop/types/index.d.ts"]
23
+ }
24
+ },
25
+ "include": ["src"]
26
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.build.json",
3
+ "compilerOptions": {
4
+ "noEmit": true,
5
+ "types": ["node"]
6
+ },
7
+ "include": ["src"]
8
+ }