@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,91 @@
1
+ import { WorkerDirector } from '@unchainedshop/core-worker';
2
+ import { createLogger } from '@unchainedshop/logger';
3
+ import { BaseAdapter } from '@unchainedshop/utils';
4
+ import fs from 'fs';
5
+ import JSONStream from 'JSONStream';
6
+ import { EventIterator } from 'event-iterator';
7
+ const logger = createLogger('unchained:platform:bulk-import');
8
+ const streamPayloadToBulkImporter = async (bulkImporter, createReadStream) => {
9
+ logger.profile(`parseAsync`, { level: 'verbose' });
10
+ const eventIterator = new EventIterator((queue) => {
11
+ const readStream = createReadStream();
12
+ const jsonStream = JSONStream.parse('events.*'); // rows, ANYTHING, doc
13
+ jsonStream.on('data', queue.push);
14
+ jsonStream.on('close', queue.stop);
15
+ jsonStream.on('error', queue.fail);
16
+ queue.on('highWater', () => readStream.pause());
17
+ queue.on('lowWater', () => readStream.resume());
18
+ readStream.pipe(jsonStream);
19
+ return () => {
20
+ jsonStream.removeListener('data', queue.push);
21
+ jsonStream.removeListener('close', queue.stop);
22
+ jsonStream.removeListener('error', queue.fail);
23
+ jsonStream.destroy();
24
+ };
25
+ }, { highWaterMark: 100, lowWaterMark: 5 });
26
+ for await (const event of eventIterator) { // eslint-disable-line
27
+ await bulkImporter.prepare(event);
28
+ }
29
+ logger.profile(`parseAsync`, { level: 'verbose' });
30
+ };
31
+ export const BulkImportWorker = {
32
+ ...BaseAdapter,
33
+ key: 'shop.unchained.worker-plugin.bulk-import',
34
+ label: 'Bulk Import',
35
+ version: '1.0',
36
+ type: 'BULK_IMPORT',
37
+ doWork: async (rawPayload, context) => {
38
+ try {
39
+ const { createShouldUpsertIfIDExists = false, skipCacheInvalidation = false, authorId = 'root', } = rawPayload;
40
+ const bulkImporter = context.bulkImporter.createBulkImporter({
41
+ logger,
42
+ authorId,
43
+ createShouldUpsertIfIDExists,
44
+ skipCacheInvalidation,
45
+ }, context);
46
+ if (rawPayload.payloadFilePath) {
47
+ // stream payload from file system
48
+ await streamPayloadToBulkImporter(bulkImporter, () => fs.createReadStream(rawPayload.payloadFilePath));
49
+ }
50
+ else if (rawPayload.payloadId) {
51
+ // stream payload from gridfs
52
+ await streamPayloadToBulkImporter(bulkImporter, () => context.bulkImporter.BulkImportPayloads.openDownloadStream(rawPayload.payloadId));
53
+ }
54
+ else {
55
+ const { events } = rawPayload;
56
+ if (!events?.length)
57
+ throw new Error('No events submitted');
58
+ await events.reduce(async (currentEventPromise, nextEvent) => {
59
+ await currentEventPromise;
60
+ return bulkImporter.prepare(nextEvent);
61
+ }, Promise.resolve());
62
+ }
63
+ const [result, error] = await bulkImporter.execute();
64
+ await bulkImporter.invalidateCaches();
65
+ if (error) {
66
+ return {
67
+ success: false,
68
+ result,
69
+ error,
70
+ };
71
+ }
72
+ return {
73
+ success: true,
74
+ result,
75
+ };
76
+ }
77
+ catch (err) {
78
+ logger.error(err.message, err);
79
+ return {
80
+ success: false,
81
+ error: {
82
+ name: err.name,
83
+ message: err.message,
84
+ stack: err.stack,
85
+ },
86
+ };
87
+ }
88
+ },
89
+ };
90
+ WorkerDirector.registerAdapter(BulkImportWorker);
91
+ //# sourceMappingURL=BulkImportWorker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BulkImportWorker.js","sourceRoot":"","sources":["../../src/worker/BulkImportWorker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,MAAM,GAAG,YAAY,CAAC,gCAAgC,CAAC,CAAC;AAE9D,MAAM,2BAA2B,GAAG,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,EAAE;IAC3E,M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AAmB,CAAC;oBAC1B,OAAO,YAAY,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;gBACzC,CAAC,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;aACvB;YAED,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,MAAM,YAAY,CAAC,OAAO,EAAE,CAAC;YACrD,MAAM,YAAY,CAAC,gBAAgB,EAAE,CAAC;YAEtC,IAAI,KAAK,EAAE;gBACT,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,MAAM;oBACN,KAAK;iBACN,CAAC;aACH;YACD,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,MAAM;aACP,CAAC;SACH;QAAC,OAAO,GAAG,EAAE;YACZ,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YAC/B,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE;oBACL,IAAI,EAAE,GAAG,CAAC,IAAI;oBACd,OAAO,EAAE,GAAG,CAAC,OAAO;oBACpB,KAAK,EAAE,GAAG,CAAC,KAAK;iBACjB;aACF,CAAC;SACH;IACH,CAAC;CACF,CAAC;AAEF,cAAc,CAAC,eAAe,CAAC,gBAAgB,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const configureGenerateOrderAutoscheduling: () => void;
@@ -0,0 +1,110 @@
1
+ import { EnrollmentDirector, enrollmentsSettings, EnrollmentStatus, } from 'meteor/unchained:core-enrollments';
2
+ import { WorkerAdapter, WorkerDirector } from '@unchainedshop/core-worker';
3
+ const generateOrder = async (enrollment, params, requestContext) => {
4
+ if (!enrollment.payment || !enrollment.delivery)
5
+ return null;
6
+ const { modules } = requestContext;
7
+ const { orderProducts, orderContext, ...configuration } = params;
8
+ let order = await modules.orders.create({
9
+ currency: enrollment.currencyCode,
10
+ countryCode: enrollment.countryCode,
11
+ contact: enrollment.contact,
12
+ billingAddress: enrollment.billingAddress,
13
+ originEnrollmentId: enrollment._id,
14
+ ...configuration,
15
+ }, enrollment.userId);
16
+ const orderId = order._id;
17
+ if (orderProducts) {
18
+ await Promise.all(orderProducts.map(({ orderPosition, product }) => modules.orders.positions.addProductItem(orderPosition, { order, product }, requestContext)));
19
+ }
20
+ else {
21
+ const product = await modules.products.findProduct({
22
+ productId: enrollment.productId,
23
+ });
24
+ await modules.orders.positions.addProductItem({ quantity: 1 }, {
25
+ order,
26
+ product,
27
+ }, requestContext);
28
+ }
29
+ const { paymentProviderId, context: paymentContext } = enrollment.payment;
30
+ if (paymentProviderId) {
31
+ await modules.orders.setPaymentProvider(orderId, paymentProviderId, requestContext);
32
+ }
33
+ const { deliveryProviderId, context: deliveryContext } = enrollment.delivery;
34
+ if (deliveryProviderId) {
35
+ await modules.orders.setDeliveryProvider(orderId, deliveryProviderId, requestContext);
36
+ }
37
+ order = await modules.orders.checkout(order._id, {
38
+ paymentContext,
39
+ deliveryContext,
40
+ orderContext,
41
+ }, requestContext);
42
+ return order;
43
+ };
44
+ const GenerateOrderWorker = {
45
+ ...WorkerAdapter,
46
+ key: 'shop.unchained.worker-plugin.generate-enrollment-orders',
47
+ label: 'Generates new Orders from Enrollments',
48
+ version: '1.0',
49
+ type: 'ENROLLMENT_ORDER_GENERATOR',
50
+ doWork: async (input, requestContext) => {
51
+ const { modules } = requestContext;
52
+ const enrollments = await modules.enrollments.findEnrollments({
53
+ status: [EnrollmentStatus.ACTIVE, EnrollmentStatus.PAUSED],
54
+ });
55
+ const errors = (await Promise.all(enrollments.map(async (enrollment) => {
56
+ try {
57
+ const director = await EnrollmentDirector.actions({ enrollment }, requestContext);
58
+ const period = await director.nextPeriod();
59
+ if (period) {
60
+ const configuration = await director.configurationForOrder({
61
+ ...input,
62
+ period,
63
+ });
64
+ if (configuration) {
65
+ const order = await generateOrder(enrollment, configuration, requestContext);
66
+ if (order) {
67
+ await modules.enrollments.addEnrollmentPeriod(enrollment._id, {
68
+ ...period,
69
+ orderId: order._id,
70
+ });
71
+ }
72
+ }
73
+ }
74
+ }
75
+ catch (e) {
76
+ return {
77
+ name: e.name,
78
+ message: e.message,
79
+ stack: e.stack,
80
+ };
81
+ }
82
+ return null;
83
+ }))).filter(Boolean);
84
+ if (errors.length) {
85
+ return {
86
+ success: false,
87
+ error: {
88
+ name: 'SOME_ENROLLMENTS_COULD_NOT_PROCESS',
89
+ message: 'Some errors have been reported during order generation',
90
+ logs: errors,
91
+ },
92
+ result: {},
93
+ };
94
+ }
95
+ return {
96
+ success: true,
97
+ result: input,
98
+ };
99
+ },
100
+ };
101
+ WorkerDirector.registerAdapter(GenerateOrderWorker);
102
+ export const configureGenerateOrderAutoscheduling = () => {
103
+ if (enrollmentsSettings.autoSchedulingSchedule) {
104
+ WorkerDirector.configureAutoscheduling(GenerateOrderWorker, {
105
+ schedule: enrollmentsSettings.autoSchedulingSchedule,
106
+ input: enrollmentsSettings.autoSchedulingInput,
107
+ });
108
+ }
109
+ };
110
+ //# sourceMappingURL=GenerateOrderWorker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GenerateOrderWorker.js","sourceRoot":"","sources":["../../src/worker/GenerateOrderWorker.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE3E,MAAM,aAAa,GAAG,KAAK,EACzB,UAAsB,EACtB,MAGwB,EACxB,cAAuB,EACvB,EAAE;IACF,IAAI,CAAC,UAAU,CAAC,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAE7D,MAAM,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC;IACnC,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,GAAG,aAAa,EAAE,GAAG,MAAM,CAAC;IACjE,IAAI,KAAK,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,CACrC;QACE,QAA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,CAAC,UAAU,CAAC,GAAG,EAAE;gCAC5D,GAAG,MAAM;gCACT,OAAO,EAAE,KAAK,CAAC,GAAG;6BACnB,CAAC,CAAC;yBACJ;qBACF;iBACF;aACF;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO;oBACL,IAAI,EAAE,CAAC,CAAC,IAAI;oBACZ,OAAO,EAAE,CAAC,CAAC,OAAO;oBAClB,KAAK,EAAE,CAAC,CAAC,KAAK;iBACf,CAAC;aACH;YACD,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CACH,CACF,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAElB,IAAI,MAAM,CAAC,MAAM,EAAE;YACjB,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE;oBACL,IAAI,EAAE,oCAAoC;oBAC1C,OAAO,EAAE,wDAAwD;oBACjE,IAAI,EAAE,MAAM;iBACb;gBACD,MAAM,EAAE,EAAE;aACX,CAAC;SACH;QACD,OAAO;YACL,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,KAAK;SACd,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,cAAc,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAC;AAEpD,MAAM,CAAC,MAAM,oCAAoC,GAAG,GAAG,EAAE;IACvD,IAAI,mBAAmB,CAAC,sBAAsB,EAAE;QAC9C,cAAc,CAAC,uBAAuB,CAAC,mBAAmB,EAAE;YAC1D,QAAQ,EAAE,mBAAmB,CAAC,sBAAsB;YACpD,KAAK,EAAE,mBAAmB,CAAC,mBAAmB;SAC/C,CAAC,CAAC;KACJ;AACH,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { IWorkerAdapter, Work } from '@unchainedshop/types/worker';
2
+ export declare const messagingLogger: import("winston").Logger;
3
+ export declare const MessageWorker: IWorkerAdapter<{
4
+ template: string;
5
+ _id?: string;
6
+ [x: string]: any;
7
+ }, {
8
+ info?: string;
9
+ forked?: Array<Work>;
10
+ }>;
@@ -0,0 +1,45 @@
1
+ import { MessagingDirector } from '@unchainedshop/core-messaging';
2
+ import { WorkerAdapter, WorkerDirector } from '@unchainedshop/core-worker';
3
+ import { createLogger } from '@unchainedshop/logger';
4
+ export const messagingLogger = createLogger('unchained:core-messaging');
5
+ export const MessageWorker = {
6
+ ...WorkerAdapter,
7
+ key: 'shop.unchained.worker-plugin.message',
8
+ label: 'Send Message by combining payload with a template and start concrete jobs',
9
+ version: '1.0',
10
+ type: 'MESSAGE',
11
+ doWork: async ({ template, ...payload }, requestContext, workId) => {
12
+ try {
13
+ const templateResolver = MessagingDirector.getTemplate(template);
14
+ const workConfigurations = await templateResolver({
15
+ template,
16
+ ...payload,
17
+ }, requestContext);
18
+ if (workConfigurations.length > 0) {
19
+ const forked = await Promise.all(workConfigurations.map(async (workConfiguration) => {
20
+ const work = await requestContext.modules.worker.addWork({
21
+ ...workConfiguration,
22
+ originalWorkId: workId,
23
+ }, requestContext.userId);
24
+ delete work.input;
25
+ return work;
26
+ }));
27
+ return { success: true, result: { forked } };
28
+ }
29
+ return { success: true, result: { info: 'Skipped Message' } };
30
+ }
31
+ catch (err) {
32
+ messagingLogger.warn(err.stack);
33
+ return {
34
+ success: false,
35
+ error: {
36
+ name: err.name,
37
+ message: err.message,
38
+ stack: err.stack,
39
+ },
40
+ };
41
+ }
42
+ },
43
+ };
44
+ WorkerDirector.registerAdapter(MessageWorker);
45
+ //# sourceMappingURL=MessageWorker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MessageWorker.js","sourceRoot":"","sources":["../../src/worker/MessageWorker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,MAAM,CAAC,MAAM,eAAe,GAAG,YAAY,CAAC,0BAA0B,CAAC,CAAC;AAExE,MAAM,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oBACd,OAAO,EAAE,GAAG,CAAC,OAAO;oBACpB,KAAK,EAAE,GAAG,CAAC,KAAK;iBACjB;aACF,CAAC;SACH;IACH,CAAC;CACF,CAAC;AAEF,cAAc,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { IWorkerAdapter } from '@unchainedshop/types/worker';
2
+ export declare const ZombieKillerWorker: IWorkerAdapter<never, {
3
+ deletedProductMediaCount: number;
4
+ deletedAssortmentMediaCount: number;
5
+ deletedFilesCount: number;
6
+ }>;
7
+ export default ZombieKillerWorker;
@@ -0,0 +1,88 @@
1
+ import { WorkerDirector } from '@unchainedshop/core-worker';
2
+ import { createLogger } from '@unchainedshop/logger';
3
+ import { BaseAdapter } from '@unchainedshop/utils';
4
+ const logger = createLogger('unchained:platform:zombie-killer');
5
+ const findId = { projection: { _id: 1 } };
6
+ const findFileId = { projection: { mediaId: 1 } };
7
+ const mapId = (a) => a._id;
8
+ export const ZombieKillerWorker = {
9
+ ...BaseAdapter,
10
+ key: 'shop.unchained.worker-plugin.zombie-killer',
11
+ label: 'Zombie Killer',
12
+ version: '1.0',
13
+ type: 'ZOMBIE_KILLER',
14
+ doWork: async (_, unchainedAPI) => {
15
+ const { modules, services } = unchainedAPI;
16
+ try {
17
+ const error = false;
18
+ // Remove unreferenced product media objects
19
+ const products = await modules.products.findProducts({}, findId);
20
+ const deletedProductMediaCount = await modules.products.media.deleteMediaFiles({
21
+ excludedProdcutIds: products.map(mapId),
22
+ });
23
+ // Remove unreferenced assortment media objects
24
+ const assortments = await modules.assortments.findAssortments({}, findId);
25
+ const deletedAssortmentMediaCount = await modules.assortments.media.deleteMediaFiles({
26
+ excludedAssortmentIds: assortments.map(mapId),
27
+ });
28
+ // Remove unreferenced files
29
+ const fileIdsToRemove = [];
30
+ const productMedia = await modules.products.media.findProductMedias({}, findFileId);
31
+ const assortmentMedia = await modules.assortments.media.findAssortmentMedias({}, findFileId);
32
+ const filesWithProductId = await modules.files.findFilesByMetaData({
33
+ meta: {
34
+ productId: { $exists: true },
35
+ },
36
+ });
37
+ const filesWithAssortmentId = await modules.files.findFilesByMetaData({
38
+ meta: {
39
+ assortmentId: { $exists: true },
40
+ },
41
+ });
42
+ filesWithProductId
43
+ .concat(filesWithAssortmentId)
44
+ .filter((file) => {
45
+ const fileInProductMedia = productMedia.some((media) => media.mediaId === file._id);
46
+ const fileInAssortmentMedia = assortmentMedia.some((media) => media.mediaId === file._id);
47
+ return !fileInProductMedia && !fileInAssortmentMedia;
48
+ })
49
+ .forEach((m) => fileIdsToRemove.push(m._id));
50
+ const deletedFilesCount = fileIdsToRemove.length > 0
51
+ ? await services.files.removeFiles({
52
+ fileIds: fileIdsToRemove,
53
+ }, unchainedAPI)
54
+ : 0;
55
+ // Return delete count
56
+ const result = {
57
+ deletedProductMediaCount,
58
+ deletedAssortmentMediaCount,
59
+ deletedFilesCount,
60
+ };
61
+ if (error) {
62
+ return {
63
+ success: false,
64
+ result,
65
+ error,
66
+ };
67
+ }
68
+ return {
69
+ success: true,
70
+ result,
71
+ };
72
+ }
73
+ catch (err) {
74
+ logger.error(err.message, err);
75
+ return {
76
+ success: false,
77
+ error: {
78
+ name: err.name,
79
+ message: err.message,
80
+ stack: err.stack,
81
+ },
82
+ };
83
+ }
84
+ },
85
+ };
86
+ export default ZombieKillerWorker;
87
+ WorkerDirector.registerAdapter(ZombieKillerWorker);
88
+ //# sourceMappingURL=ZombieKillerWorker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ZombieKillerWorker.js","sourceRoot":"","sources":["../../src/worker/ZombieKillerWorker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,MAAM,MAAM,GAAG,YAAY,CAAC,kCAAkC,CAAC,CAAC;AAEhE,MAA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sBAAsB;YACtB,MAAM,MAAM,GAAG;gBACb,wBAAwB;gBACxB,2BAA2B;gBAC3B,iBAAiB;aAClB,CAAC;YAEF,IAAI,KAAK,EAAE;gBACT,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,MAAM;oBACN,KAAK;iBACN,CAAC;aACH;YACD,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,MAAM;aACP,CAAC;SACH;QAAC,OAAO,GAAG,EAAE;YACZ,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YAC/B,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE;oBACL,IAAI,EAAE,GAAG,CAAC,IAAI;oBACd,OAAO,EAAE,GAAG,CAAC,OAAO;oBACpB,KAAK,EAAE,GAAG,CAAC,KAAK;iBACjB;aACF,CAAC;SACH;IACH,CAAC;CACF,CAAC;AAEF,eAAe,kBAAkB,CAAC;AAElC,cAAc,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,45 @@
1
+ import { WorkerDirector, WorkerAdapter } from '@unchainedshop/core-worker';
2
+ import { createLogger } from '@unchainedshop/logger';
3
+ import { Email } from 'meteor/email';
4
+ const logger = createLogger('unchained:plugins:worker:email');
5
+ const EmailWorkerPlugin = {
6
+ ...WorkerAdapter,
7
+ key: 'shop.unchained.worker-plugin.email',
8
+ label: 'Send a Mail through Meteor Mailer',
9
+ version: '1.0',
10
+ type: 'EMAIL',
11
+ doWork: async ({ from, to, subject, ...rest }) => {
12
+ logger.debug(`${EmailWorkerPlugin.key} -> doWork: ${from} -> ${to} (${subject})`);
13
+ if (!to) {
14
+ return {
15
+ success: false,
16
+ error: {
17
+ name: 'RECIPIENT_REQUIRED',
18
+ message: 'EMAIL requires a to',
19
+ },
20
+ };
21
+ }
22
+ try {
23
+ // https://docs.meteor.com/api/email.html#Email-send
24
+ const result = Email.send({
25
+ from,
26
+ to,
27
+ subject,
28
+ ...rest,
29
+ });
30
+ return { success: true, result };
31
+ }
32
+ catch (err) {
33
+ return {
34
+ success: false,
35
+ error: {
36
+ name: err.name,
37
+ message: err.message,
38
+ stack: err.stack,
39
+ },
40
+ };
41
+ }
42
+ },
43
+ };
44
+ WorkerDirector.registerAdapter(EmailWorkerPlugin);
45
+ //# sourceMappingURL=email.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email.js","sourceRoot":"","sources":["../../src/worker/email.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAGrC,MAAM,MAAM,GAAG,YAAY,CAAC,gCAAgC,CAAC,CAAC;AAE9D,MAAM,iBAAiB,GAQnB;IACF,GAAG,aAAa;IAEhB,GAAG,EAAE,oCAAoC;IACzC,KAAK,EAAE,mCAAmC;IAC1C,OAAO,EAAE,KAAK;IAEd,IAAI,EAAE,OAAO;IAEb,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE;QAC/C,MAAM,CAAC,KAAK,CAAC,GAAG,iBAAiB,CAAC,GAAG,eAAe,IAAI,OAAO,EAAE,KAAK,OAAO,GAAG,CAAC,CAAC;QAElF,IAAI,CAAC,EAAE,EAAE;YACP,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE;oBACL,IAAI,EAAE,oBAAoB;oBAC1B,OAAO,EAAE,qBAAqB;iBAC/B;aACF,CAAC;SACH;QAED,IAAI;YACF,oDAAoD;YACpD,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC;gBACxB,IAAI;gBACJ,EAAE;gBACF,OAAO;gBACP,GAAG,IAAI;aACR,CAAC,CAAC;YACH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;SAClC;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE;oBACL,IAAI,EAAE,GAAG,CAAC,IAAI;oBACd,OAAO,EAAE,GAAG,CAAC,OAAO;oBACpB,KAAK,EAAE,GAAG,CAAC,KAAK;iBACjB;aACF,CAAC;SACH;IACH,CAAC;CACF,CAAC;AAEF,cAAc,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { IWorkerAdapter } from '@unchainedshop/types/worker';
2
+ export declare const ExternalWorkerPlugin: IWorkerAdapter<void, void>;
@@ -0,0 +1,13 @@
1
+ import { WorkerDirector, WorkerAdapter } from '@unchainedshop/core-worker';
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',
7
+ type: 'EXTERNAL',
8
+ async doWork() {
9
+ throw new Error('Cannot do work for external workers');
10
+ },
11
+ };
12
+ WorkerDirector.registerAdapter(ExternalWorkerPlugin);
13
+ //# sourceMappingURL=external.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"external.js","sourceRoot":"","sources":["../../src/worker/external.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3E,MAAM,CAAC,MAAM,oBAAoB,GAA+B;IAC9D,GAAG,aAAa;IAEhB,GAAG,EAAE,uCAAuC;IAC5C,KAAK,EAAE,4FAA4F;IACnG,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,UAAU;IAEhB,KAAK,CAAC,MAAM;QACV,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;CACF,CAAC;AAEF,cAAc,CAAC,eAAe,CAAC,oBAAoB,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
1
+ import { WorkerDirector, WorkerAdapter } from '@unchainedshop/core-worker';
2
+ const wait = async (time) => {
3
+ return new Promise((resolve) => {
4
+ setTimeout(() => {
5
+ resolve(true);
6
+ }, time);
7
+ });
8
+ };
9
+ const Heartbeat = {
10
+ ...WorkerAdapter,
11
+ key: 'shop.unchained.worker-plugin.heartbeat',
12
+ label: 'Heartbeat plugin to check if workers are working',
13
+ version: '1.0',
14
+ type: 'HEARTBEAT',
15
+ doWork: async (input) => {
16
+ if (input?.wait) {
17
+ await wait(input.wait);
18
+ }
19
+ if (input?.fails) {
20
+ return {
21
+ success: false,
22
+ result: input,
23
+ };
24
+ }
25
+ return {
26
+ success: true,
27
+ result: input,
28
+ };
29
+ },
30
+ };
31
+ WorkerDirector.registerAdapter(Heartbeat);
32
+ //# sourceMappingURL=heartbeat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"heartbeat.js","sourceRoot":"","sources":["../../src/worker/heartbeat.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3E,MAAM,IAAI,GAAG,KAAK,EAAE,IAAY,EAAE,EAAE;IAClC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,UAAU,CAAC,GAAG,EAAE;YACd,OAAO,CAAC,IAAI,CAAC,CAAC;QAChB,CAAC,EAAE,IAAI,CAAC,CAAC;IACX,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AASF,MAAM,SAAS,GAAgC;IAC7C,GAAG,aAAa;IAEhB,GAAG,EAAE,wCAAwC;IAC7C,KAAK,EAAE,kDAAkD;IACzD,OAAO,EAAE,KAAK;IAEd,IAAI,EAAE,WAAW;IAEjB,MAAM,EAAE,KAAK,EAAE,KAAU,EAAiD,EAAE;QAC1E,IAAI,KAAK,EAAE,IAAI,EAAE;YACf,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;SACxB;QACD,IAAI,KAAK,EAAE,KAAK,EAAE;YAChB,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,KAAK;aACd,CAAC;SACH;QACD,OAAO;YACL,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,KAAK;SACd,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,cAAc,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { IWorkerAdapter } from '@unchainedshop/types/worker';
2
+ 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,61 @@
1
+ import fetch from 'isomorphic-unfetch';
2
+ import { WorkerDirector, WorkerAdapter } from '@unchainedshop/core-worker';
3
+ import { log, LogLevel } from '@unchainedshop/logger';
4
+ const postFetch = async (url, { data, headers }) => {
5
+ return fetch(url, {
6
+ method: 'POST',
7
+ body: JSON.stringify(data),
8
+ headers: { 'Content-Type': 'application/json', ...headers },
9
+ });
10
+ };
11
+ const nonPostFetch = async (url, { headers, method = 'GET' }) => {
12
+ return fetch(url, {
13
+ method,
14
+ headers,
15
+ });
16
+ };
17
+ const HttpRequestWorkerPlugin = {
18
+ ...WorkerAdapter,
19
+ key: 'shop.unchained.worker-plugin.http-request',
20
+ label: 'Request a resource via http request. 200 = success',
21
+ version: '1.0',
22
+ type: 'HTTP_REQUEST',
23
+ async doWork({ url, data = {}, headers, method = 'POST' } = { method: 'POST' }) {
24
+ log(`${this.key} -> doWork: ${method} ${url} ${data}`, {
25
+ level: LogLevel.Debug,
26
+ });
27
+ if (!url) {
28
+ return {
29
+ success: false,
30
+ error: {
31
+ name: 'URL_REQUIRED',
32
+ message: 'HTTP_REQUEST requires an url',
33
+ },
34
+ };
35
+ }
36
+ try {
37
+ const normalizedFetch = method.toUpperCase() === 'POST' ? postFetch : nonPostFetch;
38
+ const res = await normalizedFetch(url, { data, headers, method });
39
+ const contentType = res.headers.get('content-type');
40
+ const isJson = contentType && contentType.includes('application/json');
41
+ const result = isJson ? await res.json() : { text: await res.text() };
42
+ if (res.status === 200 && res.ok) {
43
+ return { success: true, result };
44
+ }
45
+ return { success: false, result };
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(HttpRequestWorkerPlugin);
60
+ export default HttpRequestWorkerPlugin;
61
+ //# sourceMappingURL=http-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-request.js","sourceRoot":"","sources":["../../src/worker/http-request.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,oBAAoB,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEtD,MAAM,SAAS,GAAG,KAAK,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE;IACjD,OAAO,KAAK,CAAC,GAAG,EAAE;QAChB,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;QAC1B,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,GAAG,OAAO,EAAE;KAC5D,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,KAAK,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE,EAAE,EAAE;IAC9D,OAAO,KAAK,CAAC,GAAG,EAAE;QAChB,MAAM;QACN,OAAO;KACR,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,uBAAuB,GAGzB;IACF,GAAG,aA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