@social-mail/social-mail-web-server 1.8.461 → 1.8.463
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/dist/server/services/html/HtmlForEmailService.d.ts +12 -0
- package/dist/server/services/html/HtmlForEmailService.d.ts.map +1 -0
- package/dist/server/services/html/HtmlForEmailService.js +223 -0
- package/dist/server/services/html/HtmlForEmailService.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/wwwroot/routes/index.d.ts +2 -0
- package/dist/wwwroot/routes/index.d.ts.map +1 -1
- package/dist/wwwroot/routes/index.js +10 -1
- package/dist/wwwroot/routes/index.js.map +1 -1
- package/package.json +2 -2
- package/src/server/services/html/HtmlForEmailService.ts +252 -0
- package/src/wwwroot/routes/index.tsx +11 -1
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import DBConfig from "../../server/services/DBConfig.js";
|
|
2
2
|
import Page from "@entity-access/server-pages/dist/Page.js";
|
|
3
3
|
import WebSiteContentService from "../../server/services/files/WebSiteContentService.js";
|
|
4
|
+
import HtmlForEmailService from "../../server/services/html/HtmlForEmailService.js";
|
|
4
5
|
export default class extends Page {
|
|
5
6
|
config: DBConfig;
|
|
6
7
|
siteContentService: WebSiteContentService;
|
|
8
|
+
htmlForEmail: HtmlForEmailService;
|
|
7
9
|
req: any;
|
|
8
10
|
run(): Promise<import("@entity-access/server-pages/dist/Content.js").default>;
|
|
9
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/wwwroot/routes/index.tsx"],"names":[],"mappings":"AAEA,OAAO,QAAQ,MAAM,mCAAmC,CAAC;AAGzD,OAAO,IAAI,MAAM,0CAA0C,CAAC;AAG5D,OAAO,qBAAqB,MAAM,sDAAsD,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/wwwroot/routes/index.tsx"],"names":[],"mappings":"AAEA,OAAO,QAAQ,MAAM,mCAAmC,CAAC;AAGzD,OAAO,IAAI,MAAM,0CAA0C,CAAC;AAG5D,OAAO,qBAAqB,MAAM,sDAAsD,CAAC;AAIzF,OAAO,mBAAmB,MAAM,mDAAmD,CAAC;AAEpF,MAAM,CAAC,OAAO,MAAO,SAAQ,IAAI;IAG7B,MAAM,EAAE,QAAQ,CAAC;IAGjB,kBAAkB,EAAE,qBAAqB,CAAC;IAG1C,YAAY,EAAE,mBAAmB,CAAC;IAElC,GAAG,EAAE,GAAG,CAAC;IAEH,GAAG;CA+IZ"}
|
|
@@ -19,6 +19,7 @@ import WebSiteContentService from "../../server/services/files/WebSiteContentSer
|
|
|
19
19
|
import HttpProxyService from "../../server/services/http/HttpProxyService.js";
|
|
20
20
|
import sleep from "../../common/sleep.js";
|
|
21
21
|
import { globalEnv } from "../../common/globalEnv.js";
|
|
22
|
+
import HtmlForEmailService from "../../server/services/html/HtmlForEmailService.js";
|
|
22
23
|
export default class default_1 extends Page {
|
|
23
24
|
async run() {
|
|
24
25
|
const { forceDownload } = this.query;
|
|
@@ -31,7 +32,7 @@ export default class default_1 extends Page {
|
|
|
31
32
|
// if path is empty... load /index.html....
|
|
32
33
|
ScopeVars.fromScope(this).fromWebSite = true;
|
|
33
34
|
let notFound = false;
|
|
34
|
-
let path = this.childPath;
|
|
35
|
+
let path = [...this.childPath];
|
|
35
36
|
if (!file) {
|
|
36
37
|
path = ["index.html"];
|
|
37
38
|
}
|
|
@@ -73,6 +74,10 @@ export default class default_1 extends Page {
|
|
|
73
74
|
await sleep(3000);
|
|
74
75
|
return this.notFound();
|
|
75
76
|
}
|
|
77
|
+
if (this.request.URL.searchParams.has("for-email")) {
|
|
78
|
+
const siteID = webSite.folderID;
|
|
79
|
+
appFile = await this.htmlForEmail.prepare({ appFile, siteID, path: this.childPath, url: this.request.URL.toString() });
|
|
80
|
+
}
|
|
76
81
|
return new TempFileResult(appFile, {
|
|
77
82
|
contentDisposition: forceDownload
|
|
78
83
|
? "attachment"
|
|
@@ -145,4 +150,8 @@ __decorate([
|
|
|
145
150
|
Inject,
|
|
146
151
|
__metadata("design:type", WebSiteContentService)
|
|
147
152
|
], default_1.prototype, "siteContentService", void 0);
|
|
153
|
+
__decorate([
|
|
154
|
+
Inject,
|
|
155
|
+
__metadata("design:type", HtmlForEmailService)
|
|
156
|
+
], default_1.prototype, "htmlForEmail", void 0);
|
|
148
157
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/wwwroot/routes/index.tsx"],"names":[],"mappings":";;;;;;;;;AAAA,+BAA+B;AAC/B,OAAO,MAAM,MAAM,4CAA4C,CAAC;AAChE,OAAO,QAAQ,MAAM,mCAAmC,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,6CAA6C,CAAC;AACzF,OAAO,IAAI,MAAM,0CAA0C,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAC;AAC5E,OAAO,SAAS,MAAM,2BAA2B,CAAC;AAClD,OAAO,qBAAqB,MAAM,sDAAsD,CAAC;AACzF,OAAO,gBAAgB,MAAM,gDAAgD,CAAC;AAC9E,OAAO,KAAK,MAAM,uBAAuB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/wwwroot/routes/index.tsx"],"names":[],"mappings":";;;;;;;;;AAAA,+BAA+B;AAC/B,OAAO,MAAM,MAAM,4CAA4C,CAAC;AAChE,OAAO,QAAQ,MAAM,mCAAmC,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,6CAA6C,CAAC;AACzF,OAAO,IAAI,MAAM,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AM;8BACa,qBAAqB;qDAAC;AAG1C;IADC,MAAM;8BACO,mBAAmB;+CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@social-mail/social-mail-web-server",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.463",
|
|
4
4
|
"description": "## Phase 1",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"iconv-lite": "^0.6.3",
|
|
44
44
|
"ip": "^2.0.1",
|
|
45
45
|
"isomorphic-dompurify": "^2.29.0",
|
|
46
|
-
"jsdom": "^27.0
|
|
46
|
+
"jsdom": "^27.2.0",
|
|
47
47
|
"mailauth": "^4.9.5",
|
|
48
48
|
"mailparser": "^3.7.1",
|
|
49
49
|
"mime-types": "^2.1.35",
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/* eslint-disable eqeqeq */
|
|
2
|
+
/* eslint-disable guard-for-in */
|
|
3
|
+
/* eslint-disable @typescript-eslint/prefer-for-of */
|
|
4
|
+
import Inject, { RegisterScoped } from "@entity-access/entity-access/dist/di/di.js";
|
|
5
|
+
import { LocalFile } from "@entity-access/server-pages/dist/core/LocalFile.js";
|
|
6
|
+
import SiteDiskContentCache from "../files/SiteDiskContentCache.js";
|
|
7
|
+
import { join } from "path";
|
|
8
|
+
import { JSDOM } from 'jsdom';
|
|
9
|
+
|
|
10
|
+
@RegisterScoped
|
|
11
|
+
export default class HtmlForEmailService {
|
|
12
|
+
|
|
13
|
+
@Inject
|
|
14
|
+
diskCache: SiteDiskContentCache;
|
|
15
|
+
|
|
16
|
+
async prepare({ appFile, siteID, path, url }: { appFile: LocalFile, url :string, siteID, path: string[] }) {
|
|
17
|
+
return this.diskCache.htmlCache.getOrCreateAsync(join("for-email-10", siteID, ... path), async (dest) => {
|
|
18
|
+
|
|
19
|
+
let html = await appFile.readAsText();
|
|
20
|
+
const browser = new JSDOM(html, { url});
|
|
21
|
+
await new Promise((resolve, reject) => {
|
|
22
|
+
browser.window.addEventListener("load", () => {
|
|
23
|
+
void inlineCSS(browser.window, browser.window.document).then(resolve);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
html = browser.window.document.documentElement.outerHTML;
|
|
27
|
+
await dest.writeAllText(html);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function inlineCSS(window, document){
|
|
34
|
+
|
|
35
|
+
window.CSS ??= {};
|
|
36
|
+
|
|
37
|
+
window.CSS.escape = function(value) {
|
|
38
|
+
if (arguments.length == 0) {
|
|
39
|
+
throw new TypeError('`CSS.escape` requires an argument.');
|
|
40
|
+
}
|
|
41
|
+
const text = String(value);
|
|
42
|
+
const length = text.length;
|
|
43
|
+
let index = -1;
|
|
44
|
+
let codeUnit;
|
|
45
|
+
let result = '';
|
|
46
|
+
const firstCodeUnit = text.charCodeAt(0);
|
|
47
|
+
|
|
48
|
+
if (
|
|
49
|
+
// If the character is the first character and is a `-` (U+002D), and
|
|
50
|
+
// there is no second character, […]
|
|
51
|
+
length === 1 &&
|
|
52
|
+
firstCodeUnit === 0x002D
|
|
53
|
+
) {
|
|
54
|
+
return '\\' + text;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
while (++index < length) {
|
|
58
|
+
codeUnit = text.charCodeAt(index);
|
|
59
|
+
// Note: there’s no need to special-case astral symbols, surrogate
|
|
60
|
+
// pairs, or lone surrogates.
|
|
61
|
+
|
|
62
|
+
// If the character is NULL (U+0000), then the REPLACEMENT CHARACTER
|
|
63
|
+
// (U+FFFD).
|
|
64
|
+
if (codeUnit == 0x0000) {
|
|
65
|
+
result += '\uFFFD';
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (
|
|
70
|
+
// If the character is in the range [\1-\1F] (U+0001 to U+001F) or is
|
|
71
|
+
// U+007F, […]
|
|
72
|
+
(codeUnit >= 0x0001 && codeUnit <= 0x001F) || codeUnit == 0x007F ||
|
|
73
|
+
// If the character is the first character and is in the range [0-9]
|
|
74
|
+
// (U+0030 to U+0039), […]
|
|
75
|
+
(index == 0 && codeUnit >= 0x0030 && codeUnit <= 0x0039) ||
|
|
76
|
+
// If the character is the second character and is in the range [0-9]
|
|
77
|
+
// (U+0030 to U+0039) and the first character is a `-` (U+002D), […]
|
|
78
|
+
(
|
|
79
|
+
index == 1 &&
|
|
80
|
+
codeUnit >= 0x0030 && codeUnit <= 0x0039 &&
|
|
81
|
+
firstCodeUnit == 0x002D
|
|
82
|
+
)
|
|
83
|
+
) {
|
|
84
|
+
// https://drafts.csswg.org/cssom/#escape-a-character-as-code-point
|
|
85
|
+
result += '\\' + codeUnit.toString(16) + ' ';
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// If the character is not handled by one of the above rules and is
|
|
90
|
+
// greater than or equal to U+0080, is `-` (U+002D) or `_` (U+005F), or
|
|
91
|
+
// is in one of the ranges [0-9] (U+0030 to U+0039), [A-Z] (U+0041 to
|
|
92
|
+
// U+005A), or [a-z] (U+0061 to U+007A), […]
|
|
93
|
+
if (
|
|
94
|
+
codeUnit >= 0x0080 ||
|
|
95
|
+
codeUnit == 0x002D ||
|
|
96
|
+
codeUnit == 0x005F ||
|
|
97
|
+
codeUnit >= 0x0030 && codeUnit <= 0x0039 ||
|
|
98
|
+
codeUnit >= 0x0041 && codeUnit <= 0x005A ||
|
|
99
|
+
codeUnit >= 0x0061 && codeUnit <= 0x007A
|
|
100
|
+
) {
|
|
101
|
+
// the character itself
|
|
102
|
+
result += text.charAt(index);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Otherwise, the escaped character.
|
|
107
|
+
// https://drafts.csswg.org/cssom/#escape-a-character
|
|
108
|
+
result += '\\' + text.charAt(index);
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
let id = Date.now();
|
|
115
|
+
|
|
116
|
+
async function flattenStyleSheets() {
|
|
117
|
+
const styleSheets = document.querySelectorAll(`link[rel="stylesheet"]`);
|
|
118
|
+
const tasks = [];
|
|
119
|
+
const remove = [];
|
|
120
|
+
for(let i=0;i<styleSheets.length;i++) {
|
|
121
|
+
const styleSheet = styleSheets[i];
|
|
122
|
+
const href = new URL(styleSheet.getAttribute("href"), window.location.href).toString();
|
|
123
|
+
tasks.push(fetch(href)
|
|
124
|
+
.then((x) => x.text())
|
|
125
|
+
.then((text) => ({ styleSheet, text }))
|
|
126
|
+
);
|
|
127
|
+
remove.push(styleSheet);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
const results = await Promise.all(tasks);
|
|
132
|
+
for(const { styleSheet, text} of results) {
|
|
133
|
+
const style = document.createElement("style");
|
|
134
|
+
style.textContent = text;
|
|
135
|
+
document.head.appendChild(style);
|
|
136
|
+
remove.push(styleSheet);
|
|
137
|
+
remove.push(style);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const adoptedStyle = document.createElement("style");
|
|
141
|
+
const map = new Set();
|
|
142
|
+
const all = document.querySelectorAll("*");
|
|
143
|
+
const styles = [];
|
|
144
|
+
for(let i=0;i<all.length;i++) {
|
|
145
|
+
const e = all[i] as HTMLElement;
|
|
146
|
+
for (const name of e.getAttributeNames()) {
|
|
147
|
+
if (name.startsWith("styler-")) {
|
|
148
|
+
const v = e.getAttribute(name);
|
|
149
|
+
const key = `[${name}="${window.CSS.escape(v)}"]`;
|
|
150
|
+
if(!map.has(key)) {
|
|
151
|
+
map.add(key);
|
|
152
|
+
styles.push(`${key} { --${name}: ${v}; }`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
adoptedStyle.textContent = styles.join("\n");
|
|
158
|
+
document.head.appendChild(adoptedStyle);
|
|
159
|
+
remove.push(adoptedStyle);
|
|
160
|
+
|
|
161
|
+
return () => remove.forEach((x)=>x.remove());
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function css(el) {
|
|
165
|
+
const cs = window.getComputedStyle(el);
|
|
166
|
+
const root = window.getComputedStyle(window.document.documentElement);
|
|
167
|
+
|
|
168
|
+
const sheets = document.styleSheets;
|
|
169
|
+
const ret = [];
|
|
170
|
+
el.matches = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector
|
|
171
|
+
|| el.msMatchesSelector || el.oMatchesSelector;
|
|
172
|
+
for (const i in sheets) {
|
|
173
|
+
const sheet = sheets[i];
|
|
174
|
+
try {
|
|
175
|
+
const rules = sheet.cssRules;
|
|
176
|
+
for (const r in rules) {
|
|
177
|
+
const rule = rules[r] as any;
|
|
178
|
+
if (el.matches(rule.selectorText)) {
|
|
179
|
+
const { style } = rule;
|
|
180
|
+
const properties = [];
|
|
181
|
+
for(let n=0;n<style.length;n++) {
|
|
182
|
+
const key = style[n];
|
|
183
|
+
if (key === "box-sizing") {
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
let value = style[key];
|
|
187
|
+
if (value) {
|
|
188
|
+
// we need to evaluate every var(--)
|
|
189
|
+
value = value.replace(/(var\(([^\)]+)\))/gm, (m, p1, p2) => {
|
|
190
|
+
const varName = p2.split(",")[0];
|
|
191
|
+
const cssValue = cs.getPropertyValue(varName)
|
|
192
|
+
|| root.getPropertyValue(varName);
|
|
193
|
+
return p1 ? cssValue : m;
|
|
194
|
+
});
|
|
195
|
+
properties.push({ key, value });
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
ret.push(...properties);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
} catch {
|
|
202
|
+
// do nothing..
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return ret;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function flattenStyler(rules) {
|
|
209
|
+
|
|
210
|
+
const all = document.querySelectorAll(":not(head) > *:not(style,head)");
|
|
211
|
+
for(let i=0;i<all.length;i++) {
|
|
212
|
+
const e = all[i];
|
|
213
|
+
|
|
214
|
+
const remove = [];
|
|
215
|
+
|
|
216
|
+
for(const name of e.getAttributeNames()) {
|
|
217
|
+
if (!name.startsWith("styler-")) {
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
remove.push(name);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const styles = css(e);
|
|
224
|
+
if (styles.length) {
|
|
225
|
+
const className = "c-" + (id++).toString(36);
|
|
226
|
+
e.classList.add(className);
|
|
227
|
+
|
|
228
|
+
rules.push(`.${className} {
|
|
229
|
+
${styles.map((s) => s.key + ":" + s.value).join(";\n")};
|
|
230
|
+
}`);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
for(const n of remove) {
|
|
234
|
+
e.removeAttribute(n);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
const defer = await flattenStyleSheets();
|
|
241
|
+
|
|
242
|
+
const newRules = [];
|
|
243
|
+
await flattenStyler(newRules);
|
|
244
|
+
|
|
245
|
+
const newStyle = document.createElement("style");
|
|
246
|
+
document.head.appendChild(newStyle);
|
|
247
|
+
newStyle.textContent = `* { box-sizing: border-box; }\n${newRules.join("\n")}`;
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
defer();
|
|
251
|
+
|
|
252
|
+
}
|
|
@@ -10,6 +10,7 @@ import WebSiteContentService from "../../server/services/files/WebSiteContentSer
|
|
|
10
10
|
import HttpProxyService from "../../server/services/http/HttpProxyService.js";
|
|
11
11
|
import sleep from "../../common/sleep.js";
|
|
12
12
|
import { globalEnv } from "../../common/globalEnv.js";
|
|
13
|
+
import HtmlForEmailService from "../../server/services/html/HtmlForEmailService.js";
|
|
13
14
|
|
|
14
15
|
export default class extends Page {
|
|
15
16
|
|
|
@@ -19,6 +20,9 @@ export default class extends Page {
|
|
|
19
20
|
@Inject
|
|
20
21
|
siteContentService: WebSiteContentService;
|
|
21
22
|
|
|
23
|
+
@Inject
|
|
24
|
+
htmlForEmail: HtmlForEmailService;
|
|
25
|
+
|
|
22
26
|
req: any;
|
|
23
27
|
|
|
24
28
|
async run() {
|
|
@@ -38,7 +42,7 @@ export default class extends Page {
|
|
|
38
42
|
|
|
39
43
|
let notFound = false;
|
|
40
44
|
|
|
41
|
-
let path = this.childPath;
|
|
45
|
+
let path = [ ... this.childPath];
|
|
42
46
|
if (!file) {
|
|
43
47
|
path = ["index.html"];
|
|
44
48
|
}
|
|
@@ -84,6 +88,12 @@ export default class extends Page {
|
|
|
84
88
|
await sleep(3000);
|
|
85
89
|
return this.notFound();
|
|
86
90
|
}
|
|
91
|
+
|
|
92
|
+
if (this.request.URL.searchParams.has("for-email")) {
|
|
93
|
+
const siteID = webSite.folderID;
|
|
94
|
+
appFile = await this.htmlForEmail.prepare({ appFile, siteID, path: this.childPath , url: this.request.URL.toString()});
|
|
95
|
+
}
|
|
96
|
+
|
|
87
97
|
return new TempFileResult(
|
|
88
98
|
appFile,
|
|
89
99
|
{
|