@webqit/webflo 1.0.25 → 1.0.26
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
|
@@ -8,6 +8,7 @@ export class WebfloStorage {
|
|
|
8
8
|
#registry;
|
|
9
9
|
#key;
|
|
10
10
|
#store;
|
|
11
|
+
#modified = false;
|
|
11
12
|
|
|
12
13
|
constructor(registry, key, request, session = null) {
|
|
13
14
|
this.#registry = registry;
|
|
@@ -22,13 +23,12 @@ export class WebfloStorage {
|
|
|
22
23
|
}
|
|
23
24
|
if (!this.#store && !(this.#store = await this.#registry.get(this.#key))) {
|
|
24
25
|
this.#store = {};
|
|
25
|
-
await this.#registry.set(this.#key, this.#store);
|
|
26
26
|
}
|
|
27
27
|
return this.#store;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
async commit() {
|
|
31
|
-
if (!this.#store || !this.#key) return;
|
|
31
|
+
if (!this.#store || !this.#key || !this.#modified) return;
|
|
32
32
|
await this.#registry.set(this.#key, this.#store);
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -62,12 +62,14 @@ export class WebfloStorage {
|
|
|
62
62
|
|
|
63
63
|
async set(key, value) {
|
|
64
64
|
Reflect.set(await this.store(), key, value);
|
|
65
|
+
this.#modified = true;
|
|
65
66
|
await this.emit(key, value);
|
|
66
67
|
return this;
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
async delete(key) {
|
|
70
71
|
Reflect.deleteProperty(await this.store(), key);
|
|
72
|
+
this.#modified = true;
|
|
71
73
|
await this.emit(key);
|
|
72
74
|
return this;
|
|
73
75
|
}
|
|
@@ -44,7 +44,8 @@ export class SessionStorage extends WebfloStorage {
|
|
|
44
44
|
|
|
45
45
|
async commit(response = null) {
|
|
46
46
|
if (response && !response.headers.get('Set-Cookie', true).find((c) => c.name === '__sessid')) {
|
|
47
|
-
|
|
47
|
+
// expires six months
|
|
48
|
+
response.headers.append('Set-Cookie', `__sessid=${this.#sessionID}; Path=/; Secure; HttpOnly; SameSite=Lax; Max-Age=15768000`);
|
|
48
49
|
}
|
|
49
50
|
await super.commit();
|
|
50
51
|
}
|
|
@@ -102,6 +102,7 @@ export class WebfloServer extends WebfloRuntime {
|
|
|
102
102
|
}));
|
|
103
103
|
}
|
|
104
104
|
// ---------------
|
|
105
|
+
await this.setupCapabilities();
|
|
105
106
|
this.control();
|
|
106
107
|
if (this.#cx.logger) {
|
|
107
108
|
if (this.#servers.size) {
|
|
@@ -202,11 +203,9 @@ export class WebfloServer extends WebfloRuntime {
|
|
|
202
203
|
}
|
|
203
204
|
if (this.#cx.server.capabilities?.redis && process.env[this.#cx.server.capabilities.redis_url_variable]) {
|
|
204
205
|
const { Redis } = await import('ioredis');
|
|
205
|
-
this.#sdk.redis =
|
|
206
|
-
? new Redis
|
|
207
|
-
|
|
208
|
-
family: 6
|
|
209
|
-
});
|
|
206
|
+
this.#sdk.redis = process.env[this.#cx.server.capabilities.redis_url_variable]
|
|
207
|
+
? new Redis(process.env[this.#cx.server.capabilities.redis_url_variable])
|
|
208
|
+
: new Redis;
|
|
210
209
|
console.log('Redis capabilities');
|
|
211
210
|
}
|
|
212
211
|
if (this.#cx.server.capabilities?.webpush) {
|
|
@@ -230,7 +229,6 @@ export class WebfloServer extends WebfloRuntime {
|
|
|
230
229
|
|
|
231
230
|
#globalMessagingRegistry = new Map;
|
|
232
231
|
async handleNodeWsRequest(wss, nodeRequest, socket, head) {
|
|
233
|
-
await this.setupCapabilities();
|
|
234
232
|
const proto = this.getRequestProto(nodeRequest).replace('http', 'ws');
|
|
235
233
|
const [fullUrl, requestInit] = this.parseNodeRequest(proto, nodeRequest, false);
|
|
236
234
|
const scope = {};
|
|
@@ -261,7 +259,13 @@ export class WebfloServer extends WebfloRuntime {
|
|
|
261
259
|
// Level 3 validation
|
|
262
260
|
// and actual processing
|
|
263
261
|
scope.request = this.createRequest(scope.url.href, requestInit);
|
|
264
|
-
scope.session = this.constructor.SessionStorage.create(scope.request, {
|
|
262
|
+
scope.session = this.constructor.SessionStorage.create(scope.request, {
|
|
263
|
+
secret: process.env[this.#cx.server.session_key_variable],
|
|
264
|
+
registry: this.#sdk.redis && {
|
|
265
|
+
get: async (key) => { return JSON.parse(await this.#sdk.redis.get(key) || null) },
|
|
266
|
+
set: async (key, value) => { return await this.#sdk.redis.set(key, JSON.stringify(value), 'EX', 15768000) },
|
|
267
|
+
},
|
|
268
|
+
});
|
|
265
269
|
if (!scope.error) {
|
|
266
270
|
if (!(scope.clientMessagingRegistry = this.#globalMessagingRegistry.get(scope.session.sessionID))) {
|
|
267
271
|
scope.error = `Lost or invalid clientID`;
|
|
@@ -291,7 +295,6 @@ export class WebfloServer extends WebfloRuntime {
|
|
|
291
295
|
}
|
|
292
296
|
|
|
293
297
|
async handleNodeHttpRequest(nodeRequest, nodeResponse) {
|
|
294
|
-
await this.setupCapabilities();
|
|
295
298
|
const proto = this.getRequestProto(nodeRequest);
|
|
296
299
|
const [fullUrl, requestInit] = this.parseNodeRequest(proto, nodeRequest);
|
|
297
300
|
const scope = {};
|
|
@@ -563,8 +566,8 @@ export class WebfloServer extends WebfloRuntime {
|
|
|
563
566
|
scope.session = this.constructor.SessionStorage.create(scope.request, {
|
|
564
567
|
secret: process.env[this.#cx.server.session_key_variable],
|
|
565
568
|
registry: this.#sdk.redis && {
|
|
566
|
-
get: async (key) => { return await this.#sdk.redis.
|
|
567
|
-
set: async (key, value) => { return await this.#sdk.redis.
|
|
569
|
+
get: async (key) => { return JSON.parse(await this.#sdk.redis.get(key) || null) },
|
|
570
|
+
set: async (key, value) => { return await this.#sdk.redis.set(key, JSON.stringify(value), 'EX', 15768000) },
|
|
568
571
|
},
|
|
569
572
|
});
|
|
570
573
|
const sessionID = scope.session.sessionID;
|