@social-mail/social-mail-web-server 1.9.82 → 1.9.84

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.9.82",
3
+ "version": "1.9.84",
4
4
  "description": "## Phase 1",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -30,9 +30,9 @@ export default class JsonClient {
30
30
  line += text;
31
31
  }
32
32
  this.socket.write(`${line}\n`, (error) => error && console.error(error));
33
- if (log) {
34
- console.log(line);
35
- }
33
+ // if (log) {
34
+ // console.log(line);
35
+ // }
36
36
  const v: any = await p;
37
37
  if(v?.value) {
38
38
  this.resolveReferences(v, new Map());
@@ -179,7 +179,7 @@ export default class JsonClient {
179
179
  let buffer = null as Buffer;
180
180
  s.on("data", (d) => {
181
181
  try {
182
- console.log(d.toString("utf-8"));
182
+ // console.log(d.toString("utf-8"));
183
183
  for(;;) {
184
184
  const i = d.indexOf(n);
185
185
  if (i === -1) {
@@ -11,7 +11,10 @@ class LocalCacheClient {
11
11
  async get(key: string) {
12
12
  const r = await localCacheJsonClient.sendCommand({ cmd: "get", bucket: this.bucket, key });
13
13
  const value = r.value;
14
- return value?.value ?? void 0;
14
+ if(!value) {
15
+ return void 0;
16
+ }
17
+ return value.value;
15
18
  }
16
19
 
17
20
  async delete(key: string) {
@@ -28,7 +31,7 @@ class LocalCacheClient {
28
31
 
29
32
  async getOrCreateAsync<T>(key: string, factory: (k: string) => Promise<T> ): Promise<T> {
30
33
  let r = await this.get(key);
31
- if (!r) {
34
+ if (r === void 0) {
32
35
  r = await factory(key);
33
36
  await this.set(key, r);
34
37
  }
@@ -48,7 +51,7 @@ export class ObjectLocalCache<T> implements Disposable {
48
51
  for(name: keyof T) {
49
52
  let tc = this.cache.get(name);
50
53
  if (!tc) {
51
- tc = new LocalCacheClient(this.bucketName, this.ttl);
54
+ tc = new LocalCacheClient(`${this.bucketName}.${name as any}`, this.ttl);
52
55
  this.cache.set(name, tc);
53
56
  }
54
57
  return tc;
@@ -81,7 +84,7 @@ export function localCache<T>() {
81
84
  return function(target:ILocalCacheContainer<T>, key) {
82
85
  const oldMethod = target[key] as (... a: any[]) => any;
83
86
  function value(... a: any[]) {
84
- const cache = (this.cache ??= new ObjectLocalCache<T>((target as any).constructor.name + "." + key + "." + globalEnv.serverID)).for(key);
87
+ const cache = (this.cache ??= new ObjectLocalCache<T>(`${globalEnv.serverID}:${(target as any).constructor.name}`)).for(key);
85
88
  const cacheKey = a.join();
86
89
  return cache.getOrCreateAsync(cacheKey, (k) => {
87
90
  const nv = oldMethod.apply(this, a);
@@ -16,7 +16,7 @@ export default class DomainReputationService
16
16
  ms: MessagingService;
17
17
 
18
18
  @localCache()
19
- async checkReputation(domainName: string, from?: string) {
19
+ async checkReputation(domainName: string) {
20
20
  using scope = ServiceProvider.createScope(this);
21
21
  const db = scope.resolve(SocialMailContext);
22
22
 
@@ -33,7 +33,7 @@ export default class DomainReputationService
33
33
 
34
34
  if (failed > 3) {
35
35
  if (failed > (reputation.received / 10)) {
36
- return new SmtpError(`Sender ${domainName} Blocked for 24 Hours from ${from}`, SmtpStatusCodes.SenderBlocked);
36
+ return new SmtpError(`Sender ${domainName} Blocked for 24 Hours`, SmtpStatusCodes.SenderBlocked);
37
37
  }
38
38
  }
39
39
 
@@ -107,8 +107,9 @@ export default class MailReceiverService {
107
107
 
108
108
  const domain = this.fromDomain = this.from.address.split("@",2).pop();
109
109
 
110
- const error = await this.domainReputation.checkReputation(domain, this.from.address);
110
+ const error = await this.domainReputation.checkReputation(domain);
111
111
  if (error) {
112
+ console.error(`Reputation failed for ${this.from.address}`);
112
113
  throw error;
113
114
  }
114
115