@social-mail/social-mail-web-server 1.16.310 → 1.16.312
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/.tsbuildinfo +1 -1
- package/dist/common/globalEnv.d.ts +0 -3
- package/dist/common/globalEnv.d.ts.map +1 -1
- package/dist/common/globalEnv.js +0 -3
- package/dist/common/globalEnv.js.map +1 -1
- package/dist/server/services/EmailAddressService.d.ts +3 -3
- package/dist/server/services/EmailAddressService.d.ts.map +1 -1
- package/dist/server/services/EmailAddressService.js +15 -15
- package/dist/server/services/EmailAddressService.js.map +1 -1
- package/dist/server/services/geo-ip/GeoIPService.d.ts +3 -3
- package/dist/server/services/geo-ip/GeoIPService.d.ts.map +1 -1
- package/dist/server/services/geo-ip/GeoIPService.js +2 -2
- package/dist/server/services/geo-ip/GeoIPService.js.map +1 -1
- package/dist/server/smtp/services/DomainReputationService.d.ts +3 -3
- package/dist/server/smtp/services/DomainReputationService.d.ts.map +1 -1
- package/dist/server/smtp/services/DomainReputationService.js +2 -2
- package/dist/server/smtp/services/DomainReputationService.js.map +1 -1
- package/dist/wwwroot/routes/social-mail/site/preview/[host]/[type]/[cacheKey]/get.js +1 -1
- package/dist/wwwroot/routes/social-mail/site/preview/[host]/[type]/[cacheKey]/get.js.map +1 -1
- package/package.json +1 -1
- package/src/common/globalEnv.ts +0 -3
- package/src/server/services/EmailAddressService.ts +17 -17
- package/src/server/services/geo-ip/GeoIPService.ts +4 -4
- package/src/server/smtp/services/DomainReputationService.ts +4 -4
- package/src/wwwroot/routes/social-mail/site/preview/[host]/[type]/[cacheKey]/get.tsx +1 -1
- package/dist/common/JsonClient.d.ts +0 -13
- package/dist/common/JsonClient.d.ts.map +0 -1
- package/dist/common/JsonClient.js +0 -203
- package/dist/common/JsonClient.js.map +0 -1
- package/dist/common/LocalCache.d.ts +0 -21
- package/dist/common/LocalCache.d.ts.map +0 -1
- package/dist/common/LocalCache.js +0 -120
- package/dist/common/LocalCache.js.map +0 -1
- package/src/common/JsonClient.ts +0 -228
- package/src/common/LocalCache.ts +0 -148
package/src/common/LocalCache.ts
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { globalEnv } from "./globalEnv.js";
|
|
2
|
-
import JsonClient from "./JsonClient.js";
|
|
3
|
-
|
|
4
|
-
const localCacheJsonClient = new JsonClient(globalEnv.localCache.port);
|
|
5
|
-
|
|
6
|
-
interface ILocalCacheClient {
|
|
7
|
-
get(key: string): Promise<any>;
|
|
8
|
-
delete(key: string): Promise<void>;
|
|
9
|
-
set(key: string, value: string, ttl, maxAge): Promise<void>;
|
|
10
|
-
clear();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
class LocalCacheClient implements ILocalCacheClient {
|
|
14
|
-
|
|
15
|
-
constructor(public readonly bucket: string, public readonly ttlSeconds = 60, public readonly maxAge = 4) {
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async get(key: string) {
|
|
19
|
-
const r = await localCacheJsonClient.sendCommand({ cmd: "get", bucket: this.bucket, key });
|
|
20
|
-
const value = r.value;
|
|
21
|
-
if(!value) {
|
|
22
|
-
return void 0;
|
|
23
|
-
}
|
|
24
|
-
return value.value;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async delete(key: string) {
|
|
28
|
-
await localCacheJsonClient.sendCommand({ cmd: "delete", bucket: this.bucket, key });
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async set(key: string, value: string, ttl = this.ttlSeconds, maxAge = this.maxAge) {
|
|
32
|
-
await localCacheJsonClient.sendCommand({ cmd: "set", bucket: this.bucket, key, value: { value }, ttl, maxAge });
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
clear() {
|
|
36
|
-
localCacheJsonClient.sendCommand({ cmd: "clear", bucket: this.bucket }).catch(console.error);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async getOrCreateAsync<T>(key: string, factory: (k: string) => Promise<T> ): Promise<T> {
|
|
40
|
-
let r = await this.get(key);
|
|
41
|
-
if (r === void 0) {
|
|
42
|
-
r = await factory(key);
|
|
43
|
-
await this.set(key, r);
|
|
44
|
-
}
|
|
45
|
-
return r;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
class TestLocalCacheClient implements ILocalCacheClient {
|
|
51
|
-
|
|
52
|
-
map = new Map<string, string>();
|
|
53
|
-
|
|
54
|
-
constructor(...a: any[]) {
|
|
55
|
-
// do nothing
|
|
56
|
-
}
|
|
57
|
-
async get(key: string): Promise<any> {
|
|
58
|
-
return this.map.get(key);
|
|
59
|
-
}
|
|
60
|
-
async delete(key: string): Promise<void> {
|
|
61
|
-
this.map.delete(key);
|
|
62
|
-
}
|
|
63
|
-
async set(key: string, value: string, ttl: any, maxAge: any) {
|
|
64
|
-
this.map.set(key, value);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
clear() {
|
|
68
|
-
this.map.clear();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async getOrCreateAsync<T>(key: string, factory: (k: string) => Promise<T> ): Promise<T> {
|
|
72
|
-
let r = await this.get(key);
|
|
73
|
-
if (r === void 0) {
|
|
74
|
-
r = await factory(key);
|
|
75
|
-
await this.set(key, r, 0, 0);
|
|
76
|
-
}
|
|
77
|
-
return r;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export class ObjectLocalCache<T> implements Disposable {
|
|
83
|
-
|
|
84
|
-
private cache: Map<any, ILocalCacheClient> = new Map();
|
|
85
|
-
|
|
86
|
-
constructor(private readonly bucketName: string, private readonly ttl?) {
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
for(name: keyof T) {
|
|
91
|
-
let tc = this.cache.get(name);
|
|
92
|
-
if (!tc) {
|
|
93
|
-
tc = globalEnv.isLocalTestMode
|
|
94
|
-
? new TestLocalCacheClient(`${this.bucketName}.${name as any}`, this.ttl)
|
|
95
|
-
: new LocalCacheClient(`${this.bucketName}.${name as any}`, this.ttl);
|
|
96
|
-
this.cache.set(name, tc);
|
|
97
|
-
}
|
|
98
|
-
return tc;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
clear(name?: keyof T) {
|
|
102
|
-
if (!name) {
|
|
103
|
-
for (const element of this.cache.values()) {
|
|
104
|
-
element.clear();
|
|
105
|
-
}
|
|
106
|
-
this.cache.clear();
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
this.cache.get(name)?.clear();
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
[Symbol.dispose]() {
|
|
113
|
-
for (const element of this.cache.values()) {
|
|
114
|
-
element.clear();
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export interface ILocalCacheContainer<T> {
|
|
120
|
-
cache: ObjectLocalCache<T> | undefined;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
export function localCache<T>() {
|
|
125
|
-
return function(target:ILocalCacheContainer<T>, key) {
|
|
126
|
-
const oldMethod = target[key] as (... a: any[]) => any;
|
|
127
|
-
function value(... a: any[]) {
|
|
128
|
-
const cache = (this.cache ??= new ObjectLocalCache<T>(`${globalEnv.serverID}:${(target as any).constructor.name}`)).for(key);
|
|
129
|
-
const cacheKey = a.join();
|
|
130
|
-
return cache.getOrCreateAsync(cacheKey, (k) => {
|
|
131
|
-
const nv = oldMethod.apply(this, a);
|
|
132
|
-
nv?.catch((error) => {
|
|
133
|
-
console.error(`${key}(${cacheKey}) failed with`);
|
|
134
|
-
console.error(error);
|
|
135
|
-
cache.delete(cacheKey);
|
|
136
|
-
});
|
|
137
|
-
return nv;
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
const d = {
|
|
141
|
-
value,
|
|
142
|
-
enumerable: true,
|
|
143
|
-
configurable: true
|
|
144
|
-
};
|
|
145
|
-
Object.defineProperty(target, key, d);
|
|
146
|
-
return d;
|
|
147
|
-
} as any;
|
|
148
|
-
}
|