@social-mail/social-mail-web-server 1.8.373 → 1.8.374

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@social-mail/social-mail-web-server",
3
- "version": "1.8.373",
3
+ "version": "1.8.374",
4
4
  "description": "## Phase 1",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -44,9 +44,10 @@ export const globalEnv = {
44
44
  ips: (process.env.SOCIAL_MAIL_IPS ?? "").split(",").map((x) => x.trim()).filter((x) => x),
45
45
  senderEmailForNotification: process.env.SOCIAL_MAIL_SENDER_EMAIL_FOR_NOTIFICATION,
46
46
  cdn,
47
- hosts:{
48
- cdnOrHost: cdn ?? host,
49
- emailContentHost: process.env.SOCIAL_MAIL_HOSTS_EMAIL_CONTENT || ""
47
+ cdnOrHost: cdn ?? host,
48
+ emailContentProxy: {
49
+ host: process.env.SOCIAL_MAIL_HOSTS_EMAIL_CONTENT || null,
50
+ encryptionKey: process.env.SOCIAL_MAIL_HOSTS_EMAIL_CONTENT_PUBLIC_KEY || process.env.SOCIAL_MAIL_PUBLIC_KEY
50
51
  },
51
52
  path: process.env.SOCIAL_MAIL_PATH || "/",
52
53
  links: {
@@ -28,7 +28,7 @@ export default class ChannelUrlService {
28
28
  eDomain
29
29
  }: IFileUrlOptions): string {
30
30
  const cid = this.ecs.general.encrypt(file.fileContentID.toString());
31
- return `https://${globalEnv.hosts.cdnOrHost}/social-mail/video-player/${eDomain}/webm-branded/${cid}/${file.name}.b1.webm`;
31
+ return `https://${globalEnv.cdnOrHost}/social-mail/video-player/${eDomain}/webm-branded/${cid}/${file.name}.b1.webm`;
32
32
  }
33
33
 
34
34
  toWebMUrl({
@@ -38,7 +38,7 @@ export default class ChannelUrlService {
38
38
  }: IFileUrlOptions): string {
39
39
  const cid = this.ecs.general.encrypt(file.fileContentID.toString());
40
40
  if (eDomain) {
41
- return `https://${globalEnv.hosts.cdnOrHost}/social-mail/c/e/${eDomain}/webm-branded/${cid}/${file.name}.b1.webm`;
41
+ return `https://${globalEnv.cdnOrHost}/social-mail/c/e/${eDomain}/webm-branded/${cid}/${file.name}.b1.webm`;
42
42
  }
43
43
  if (publicRead) {
44
44
  this.ss.injectPublicKey(file);
@@ -78,7 +78,7 @@ export default class ChannelUrlService {
78
78
  name = `${file.name}.i1-${ext}`;
79
79
  }
80
80
  if (eDomain) {
81
- return `https://${globalEnv.hosts.cdnOrHost}/social-mail/c/e/${eDomain}/${method}/${cid}/${name}`;
81
+ return `https://${globalEnv.cdnOrHost}/social-mail/c/e/${eDomain}/${method}/${cid}/${name}`;
82
82
  }
83
83
  if (publicRead) {
84
84
  this.ss.injectPublicKey(file);
@@ -98,7 +98,7 @@ export default class ChannelUrlService {
98
98
  const method = "view";
99
99
  const name = file.name;
100
100
  if(eDomain) {
101
- return `https://${globalEnv.hosts.cdnOrHost}/social-mail/c/e/${eDomain}/${method}/${cid}/${name}`;
101
+ return `https://${globalEnv.cdnOrHost}/social-mail/c/e/${eDomain}/${method}/${cid}/${name}`;
102
102
  }
103
103
  if (publicRead) {
104
104
  this.ss.injectPublicKey(file);
@@ -7,6 +7,11 @@ const cache = new Map<string, { key, encryptionIV }>();
7
7
  @RegisterSingleton
8
8
  export default class EncryptionService {
9
9
 
10
+ global = {
11
+ encrypt: (text: string, publicKey, host: string) => this.encrypt(text, publicKey, "base64url", host),
12
+ decrypt: (text: string, publicKey, host: string) => this.decrypt(text, publicKey, "base64url", host)
13
+ };
14
+
10
15
  general = {
11
16
  encrypt: (text: string) => this.encrypt(text, globalEnv.publicKey, "base64url"),
12
17
  decrypt: (text: string) => this.decrypt(text, globalEnv.publicKey, "base64url")
@@ -17,23 +22,24 @@ export default class EncryptionService {
17
22
  decrypt: (text: string) => this.decrypt(text, globalEnv.secretKey)
18
23
  };
19
24
 
20
- private encrypt(text: string, secretKey = globalEnv.secretKey, encoding: Encoding = "hex") {
21
- const { key, encryptionIV} = this.createKey(secretKey);
25
+ private encrypt(text: string, secretKey = globalEnv.secretKey, encoding: Encoding = "hex", host = globalEnv.host) {
26
+ const { key, encryptionIV} = this.createKey(secretKey, host);
22
27
  const cipher = crypto.createCipheriv("aes-256-cbc", key, encryptionIV);
23
28
  return (cipher.update(text, "utf-8", encoding)
24
29
  + cipher.final(encoding)).replaceAll("=", "*");
25
30
  }
26
31
 
27
- private decrypt(text: string, secretKey = globalEnv.secretKey, encoding: Encoding = "hex") {
28
- const { key, encryptionIV} = this.createKey(secretKey);
32
+ private decrypt(text: string, secretKey = globalEnv.secretKey, encoding: Encoding = "hex", host = globalEnv.host) {
33
+ const { key, encryptionIV} = this.createKey(secretKey, host);
29
34
  text = text.replaceAll("*" , "=");
30
35
  const decipher = crypto.createDecipheriv("aes-256-cbc", key, encryptionIV);
31
36
  return decipher.update(text, encoding, "utf-8") + decipher.final("utf-8");
32
37
  }
33
38
 
34
- private createKey(secretKey: string) {
39
+ private createKey(secretKey: string, host) {
35
40
 
36
- let result = cache.get(secretKey);
41
+ const cacheKey = `${host}:${secretKey}`;
42
+ let result = cache.get(cacheKey);
37
43
  if(!result) {
38
44
  const key = crypto.createHash("sha512")
39
45
  .update(secretKey)
@@ -41,12 +47,12 @@ export default class EncryptionService {
41
47
  .substring(0, 32);
42
48
 
43
49
  const encryptionIV = crypto.createHash("sha512")
44
- .update(globalEnv.host)
50
+ .update(host)
45
51
  .digest("hex")
46
52
  .substring(0, 16);
47
53
  result = { key, encryptionIV };
48
- cache.set(secretKey, result);
49
- setTimeout(() => cache.delete(secretKey), 60000);
54
+ cache.set(cacheKey, result);
55
+ setTimeout(() => cache.delete(cacheKey), 60000);
50
56
  }
51
57
  return result;
52
58
  }
@@ -34,7 +34,6 @@ export default class CachedEmailService {
34
34
 
35
35
  const factory = async () => {
36
36
 
37
- const ei = this.encryptionService.general.encrypt(emailID.toString());
38
37
 
39
38
  let logFile: EmailLog;
40
39
 
@@ -70,10 +69,16 @@ export default class CachedEmailService {
70
69
  }
71
70
  const htmlService = ServiceProvider.resolve(this, BlogContentTransformer);
72
71
  if (status !== "draft") {
73
- const { emailContentHost } = globalEnv.hosts;
74
- const prefix = emailContentHost
75
- ? `/api/emails/d/${ei}/${emailID}/`
76
- : `https://${emailContentHost}/api/emails/d/${ei}/${emailID}/`;
72
+ let ei;
73
+ let prefix;
74
+ const { host, encryptionKey } = globalEnv.emailContentProxy;
75
+ if (host) {
76
+ ei = this.encryptionService.global.encrypt(emailID.toString(), encryptionKey, host);
77
+ prefix = `https://${host}/api/emails/d/${ei}/${emailID}/`;
78
+ } else {
79
+ ei = this.encryptionService.general.encrypt(emailID.toString());
80
+ prefix = `/api/emails/d/${ei}/${emailID}/`;
81
+ }
77
82
  html = await htmlService.sanitizeExternalResources({
78
83
  html,
79
84
  emailID,
@@ -109,9 +109,9 @@ export default class MailDispatcherService {
109
109
 
110
110
  const downloadLink = /^video\//i.test(ea.contentType)
111
111
  ? (listID
112
- ? `https://${globalEnv.hosts.cdnOrHost}/social-mail/c/d/${domainName}/webm-branded/${postID}/${ea.appFileID}/2-${fileName}/${fileName}.3.webm`
113
- : `https://${globalEnv.hosts.cdnOrHost}/social-mail/c/d/${domainName}/webm/${postID}/${ea.appFileID}/2-${fileName}/${fileName}.3.webm`)
114
- : `https://${globalEnv.hosts.cdnOrHost}/social-mail/c/d/${domainName}/view/${postID}/${ea.appFileID}/2-${fileName}`;
112
+ ? `https://${globalEnv.cdnOrHost}/social-mail/c/d/${domainName}/webm-branded/${postID}/${ea.appFileID}/2-${fileName}/${fileName}.3.webm`
113
+ : `https://${globalEnv.cdnOrHost}/social-mail/c/d/${domainName}/webm/${postID}/${ea.appFileID}/2-${fileName}/${fileName}.3.webm`)
114
+ : `https://${globalEnv.cdnOrHost}/social-mail/c/d/${domainName}/view/${postID}/${ea.appFileID}/2-${fileName}`;
115
115
 
116
116
  return {
117
117
  content: downloadLink,