@webqit/webflo 1.0.24 → 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,10 +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
|
-
});
|
|
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;
|
|
209
209
|
console.log('Redis capabilities');
|
|
210
210
|
}
|
|
211
211
|
if (this.#cx.server.capabilities?.webpush) {
|
|
@@ -229,7 +229,6 @@ export class WebfloServer extends WebfloRuntime {
|
|
|
229
229
|
|
|
230
230
|
#globalMessagingRegistry = new Map;
|
|
231
231
|
async handleNodeWsRequest(wss, nodeRequest, socket, head) {
|
|
232
|
-
await this.setupCapabilities();
|
|
233
232
|
const proto = this.getRequestProto(nodeRequest).replace('http', 'ws');
|
|
234
233
|
const [fullUrl, requestInit] = this.parseNodeRequest(proto, nodeRequest, false);
|
|
235
234
|
const scope = {};
|
|
@@ -260,7 +259,13 @@ export class WebfloServer extends WebfloRuntime {
|
|
|
260
259
|
// Level 3 validation
|
|
261
260
|
// and actual processing
|
|
262
261
|
scope.request = this.createRequest(scope.url.href, requestInit);
|
|
263
|
-
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
|
+
});
|
|
264
269
|
if (!scope.error) {
|
|
265
270
|
if (!(scope.clientMessagingRegistry = this.#globalMessagingRegistry.get(scope.session.sessionID))) {
|
|
266
271
|
scope.error = `Lost or invalid clientID`;
|
|
@@ -290,7 +295,6 @@ export class WebfloServer extends WebfloRuntime {
|
|
|
290
295
|
}
|
|
291
296
|
|
|
292
297
|
async handleNodeHttpRequest(nodeRequest, nodeResponse) {
|
|
293
|
-
await this.setupCapabilities();
|
|
294
298
|
const proto = this.getRequestProto(nodeRequest);
|
|
295
299
|
const [fullUrl, requestInit] = this.parseNodeRequest(proto, nodeRequest);
|
|
296
300
|
const scope = {};
|
|
@@ -562,8 +566,8 @@ export class WebfloServer extends WebfloRuntime {
|
|
|
562
566
|
scope.session = this.constructor.SessionStorage.create(scope.request, {
|
|
563
567
|
secret: process.env[this.#cx.server.session_key_variable],
|
|
564
568
|
registry: this.#sdk.redis && {
|
|
565
|
-
get: async (key) => { return await this.#sdk.redis.
|
|
566
|
-
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) },
|
|
567
571
|
},
|
|
568
572
|
});
|
|
569
573
|
const sessionID = scope.session.sessionID;
|