@webqit/webflo 1.0.25 → 1.0.27

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
@@ -12,7 +12,7 @@
12
12
  "vanila-javascript"
13
13
  ],
14
14
  "homepage": "https://webqit.io/tooling/webflo",
15
- "version": "1.0.25",
15
+ "version": "1.0.27",
16
16
  "license": "MIT",
17
17
  "repository": {
18
18
  "type": "git",
@@ -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
- response.headers.append('Set-Cookie', `__sessid=${this.#sessionID}; Path=/; Secure; HttpOnly; SameSite=Lax; Max-Age=31536000`);
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
  }
@@ -202,11 +202,9 @@ export class WebfloServer extends WebfloRuntime {
202
202
  }
203
203
  if (this.#cx.server.capabilities?.redis && process.env[this.#cx.server.capabilities.redis_url_variable]) {
204
204
  const { Redis } = await import('ioredis');
205
- this.#sdk.redis = !process.env[this.#cx.server.capabilities.redis_url_variable]
206
- ? new Redis : new Redis(process.env[this.#cx.server.capabilities.redis_url_variable], {
207
- tls: { rejectUnauthorized: false }, // Required for Upstash
208
- family: 6
209
- });
205
+ this.#sdk.redis = process.env[this.#cx.server.capabilities.redis_url_variable]
206
+ ? new Redis(process.env[this.#cx.server.capabilities.redis_url_variable])
207
+ : new Redis;
210
208
  console.log('Redis capabilities');
211
209
  }
212
210
  if (this.#cx.server.capabilities?.webpush) {
@@ -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, { secret: process.env[this.#cx.server.session_key_variable] });
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`;
@@ -563,8 +567,8 @@ export class WebfloServer extends WebfloRuntime {
563
567
  scope.session = this.constructor.SessionStorage.create(scope.request, {
564
568
  secret: process.env[this.#cx.server.session_key_variable],
565
569
  registry: this.#sdk.redis && {
566
- get: async (key) => { return await this.#sdk.redis.hgetall(key) },
567
- set: async (key, value) => { return await this.#sdk.redis.hset(key, value) },
570
+ get: async (key) => { return JSON.parse(await this.#sdk.redis.get(key) || null) },
571
+ set: async (key, value) => { return await this.#sdk.redis.set(key, JSON.stringify(value), 'EX', 15768000) },
568
572
  },
569
573
  });
570
574
  const sessionID = scope.session.sessionID;