@unchainedshop/plugins 4.0.0-rc.19 → 4.0.0-rc.20
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.
- package/lib/worker/email.d.ts.map +1 -1
- package/lib/worker/email.js +25 -7
- package/lib/worker/email.js.map +1 -1
- package/package.json +13 -18
- package/src/worker/email.ts +30 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../../src/worker/email.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../../src/worker/email.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,6BAA6B,eAEzC,CAAC"}
|
package/lib/worker/email.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { WorkerDirector, WorkerAdapter } from '@unchainedshop/core';
|
|
2
2
|
import nodemailer from 'nodemailer';
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { writeFile, mkdtemp } from 'node:fs/promises';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
6
|
+
import { join } from 'node:path';
|
|
3
7
|
export const checkEmailInterceptionEnabled = () => {
|
|
4
8
|
return process.env.NODE_ENV !== 'production' && !process.env.UNCHAINED_DISABLE_EMAIL_INTERCEPTION;
|
|
5
9
|
};
|
|
@@ -16,9 +20,14 @@ const buildLink = async ({ filename, content, href, contentType, encoding, path
|
|
|
16
20
|
return '';
|
|
17
21
|
};
|
|
18
22
|
const openInBrowser = async (options) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
const command = {
|
|
24
|
+
darwin: 'open',
|
|
25
|
+
win32: 'explorer.exe',
|
|
26
|
+
linux: 'xdg-open',
|
|
27
|
+
}[process.platform];
|
|
28
|
+
if (!command) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
22
31
|
const messageBody = options.html || options.text.replace(/(\r\n|\n|\r)/gm, '<br/>');
|
|
23
32
|
const attachmentLinks = await Promise.all((options.attachments || []).map(buildLink));
|
|
24
33
|
const content = `
|
|
@@ -41,10 +50,19 @@ const openInBrowser = async (options) => {
|
|
|
41
50
|
${messageBody}
|
|
42
51
|
</body>
|
|
43
52
|
</html>`;
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
53
|
+
// Create a temporary directory and file
|
|
54
|
+
const tempDir = await mkdtemp(join(tmpdir(), 'unchained-email-'));
|
|
55
|
+
const tempFile = join(tempDir, 'email-preview.html');
|
|
56
|
+
await writeFile(tempFile, content, 'utf8');
|
|
57
|
+
return new Promise((resolve) => {
|
|
58
|
+
const child = spawn(command, [tempFile], {
|
|
59
|
+
detached: true,
|
|
60
|
+
stdio: 'ignore',
|
|
61
|
+
});
|
|
62
|
+
child.unref();
|
|
63
|
+
// Resolve immediately after spawning since process is detached
|
|
64
|
+
resolve(true);
|
|
65
|
+
});
|
|
48
66
|
};
|
|
49
67
|
const EmailWorkerPlugin = {
|
|
50
68
|
...WorkerAdapter,
|
package/lib/worker/email.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email.js","sourceRoot":"","sources":["../../src/worker/email.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAkB,MAAM,qBAAqB,CAAC;AACpF,OAAO,UAAU,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"email.js","sourceRoot":"","sources":["../../src/worker/email.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAkB,MAAM,qBAAqB,CAAC;AACpF,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EA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,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC;AAEF,cAAc,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/plugins",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.20",
|
|
4
4
|
"main": "lib/plugins-index.js",
|
|
5
5
|
"types": "lib/plugins-index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -34,18 +34,18 @@
|
|
|
34
34
|
},
|
|
35
35
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@unchainedshop/api": "^4.0.0-rc.
|
|
38
|
-
"@unchainedshop/core-delivery": "^4.0.0-rc.
|
|
39
|
-
"@unchainedshop/core-enrollments": "^4.0.0-rc.
|
|
40
|
-
"@unchainedshop/core-orders": "^4.0.0-rc.
|
|
41
|
-
"@unchainedshop/core-payment": "^4.0.0-rc.
|
|
42
|
-
"@unchainedshop/core-products": "^4.0.0-rc.
|
|
43
|
-
"@unchainedshop/core-warehousing": "^4.0.0-rc.
|
|
44
|
-
"@unchainedshop/core-worker": "^4.0.0-rc.
|
|
45
|
-
"@unchainedshop/events": "^4.0.0-rc.
|
|
46
|
-
"@unchainedshop/file-upload": "^4.0.0-rc.
|
|
47
|
-
"@unchainedshop/logger": "^4.0.0-rc.
|
|
48
|
-
"@unchainedshop/utils": "^4.0.0-rc.
|
|
37
|
+
"@unchainedshop/api": "^4.0.0-rc.20",
|
|
38
|
+
"@unchainedshop/core-delivery": "^4.0.0-rc.20",
|
|
39
|
+
"@unchainedshop/core-enrollments": "^4.0.0-rc.20",
|
|
40
|
+
"@unchainedshop/core-orders": "^4.0.0-rc.20",
|
|
41
|
+
"@unchainedshop/core-payment": "^4.0.0-rc.20",
|
|
42
|
+
"@unchainedshop/core-products": "^4.0.0-rc.20",
|
|
43
|
+
"@unchainedshop/core-warehousing": "^4.0.0-rc.20",
|
|
44
|
+
"@unchainedshop/core-worker": "^4.0.0-rc.20",
|
|
45
|
+
"@unchainedshop/events": "^4.0.0-rc.20",
|
|
46
|
+
"@unchainedshop/file-upload": "^4.0.0-rc.20",
|
|
47
|
+
"@unchainedshop/logger": "^4.0.0-rc.20",
|
|
48
|
+
"@unchainedshop/utils": "^4.0.0-rc.20"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@aws-sdk/client-eventbridge": ">= 3.714 < 4",
|
|
@@ -60,7 +60,6 @@
|
|
|
60
60
|
"fastify": ">= 5.2 < 6",
|
|
61
61
|
"minio": "8.x",
|
|
62
62
|
"nodemailer": ">= 6.9 < 8",
|
|
63
|
-
"open": "10.x",
|
|
64
63
|
"p-memoize": "8.x",
|
|
65
64
|
"stripe": ">= 19 < 20",
|
|
66
65
|
"web-push": ">= 3.6 <4",
|
|
@@ -100,9 +99,6 @@
|
|
|
100
99
|
"nodemailer": {
|
|
101
100
|
"optional": true
|
|
102
101
|
},
|
|
103
|
-
"open": {
|
|
104
|
-
"optional": true
|
|
105
|
-
},
|
|
106
102
|
"p-memoize": {
|
|
107
103
|
"optional": true
|
|
108
104
|
},
|
|
@@ -130,7 +126,6 @@
|
|
|
130
126
|
"fastify": "^5.4.0",
|
|
131
127
|
"minio": "^8.0.5",
|
|
132
128
|
"nodemailer": "^7.0.5",
|
|
133
|
-
"open": "^10.1.2",
|
|
134
129
|
"p-memoize": "^8.0.0",
|
|
135
130
|
"stripe": "^19.1.0",
|
|
136
131
|
"tsx": "^4.20.3",
|
package/src/worker/email.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { WorkerDirector, WorkerAdapter, IWorkerAdapter } from '@unchainedshop/core';
|
|
2
2
|
import nodemailer from 'nodemailer';
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { writeFile, mkdtemp } from 'node:fs/promises';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
6
|
+
import { join } from 'node:path';
|
|
3
7
|
|
|
4
8
|
export const checkEmailInterceptionEnabled = () => {
|
|
5
9
|
return process.env.NODE_ENV !== 'production' && !process.env.UNCHAINED_DISABLE_EMAIL_INTERCEPTION;
|
|
@@ -18,10 +22,16 @@ const buildLink = async ({ filename, content, href, contentType, encoding, path
|
|
|
18
22
|
return '';
|
|
19
23
|
};
|
|
20
24
|
|
|
21
|
-
const openInBrowser = async (options) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
const openInBrowser = async (options): Promise<boolean> => {
|
|
26
|
+
const command = {
|
|
27
|
+
darwin: 'open',
|
|
28
|
+
win32: 'explorer.exe',
|
|
29
|
+
linux: 'xdg-open',
|
|
30
|
+
}[process.platform];
|
|
31
|
+
|
|
32
|
+
if (!command) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
25
35
|
|
|
26
36
|
const messageBody = options.html || options.text.replace(/(\r\n|\n|\r)/gm, '<br/>');
|
|
27
37
|
const attachmentLinks = await Promise.all((options.attachments || []).map(buildLink));
|
|
@@ -46,11 +56,23 @@ const openInBrowser = async (options) => {
|
|
|
46
56
|
</body>
|
|
47
57
|
</html>`;
|
|
48
58
|
|
|
49
|
-
|
|
50
|
-
const
|
|
59
|
+
// Create a temporary directory and file
|
|
60
|
+
const tempDir = await mkdtemp(join(tmpdir(), 'unchained-email-'));
|
|
61
|
+
const tempFile = join(tempDir, 'email-preview.html');
|
|
62
|
+
|
|
63
|
+
await writeFile(tempFile, content, 'utf8');
|
|
64
|
+
|
|
65
|
+
return new Promise((resolve) => {
|
|
66
|
+
const child = spawn(command, [tempFile], {
|
|
67
|
+
detached: true,
|
|
68
|
+
stdio: 'ignore',
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
child.unref();
|
|
51
72
|
|
|
52
|
-
|
|
53
|
-
|
|
73
|
+
// Resolve immediately after spawning since process is detached
|
|
74
|
+
resolve(true);
|
|
75
|
+
});
|
|
54
76
|
};
|
|
55
77
|
|
|
56
78
|
const EmailWorkerPlugin: IWorkerAdapter<
|