@nu-art/user-account-backend 0.401.5 → 0.401.7

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.
@@ -34,6 +34,7 @@ export declare class ModuleBE_SessionDB_Class extends ModuleBE_BaseDB<DBProto_Se
34
34
  constructor();
35
35
  init(): void;
36
36
  private collectSessionData;
37
+ preWriteProcessing: (instance: DBProto_Session["dbType"]) => Promise<void>;
37
38
  token: {
38
39
  create: (initialClaims: BaseSessionClaims, ttlInMs?: number, transaction?: Transaction) => Promise<string>;
39
40
  refresh: (jwtOrigin: string) => Promise<string>;
@@ -72,6 +73,7 @@ export declare class ModuleBE_SessionDB_Class extends ModuleBE_BaseDB<DBProto_Se
72
73
  deviceId: string;
73
74
  };
74
75
  }>;
76
+ cleanOldOrExpiredSessions: () => Promise<void>;
75
77
  }
76
78
  export declare const ModuleBE_SessionDB: ModuleBE_SessionDB_Class;
77
79
  export {};
@@ -1,4 +1,4 @@
1
- import { ApiException, currentTimeMillis, Day, Dispatcher, filterKeys, isErrorOfType, JwtTools, md5, MUSTNeverHappenException } from '@nu-art/ts-common';
1
+ import { ApiException, currentTimeMillis, Day, Dispatcher, filterInstances, filterKeys, isErrorOfType, JwtTools, md5, MUSTNeverHappenException } from '@nu-art/ts-common';
2
2
  import { ModuleBE_BaseDB } from '@nu-art/thunderstorm-backend';
3
3
  import { DBDef_Session } from '@nu-art/user-account-shared';
4
4
  import { Header_Authorization, MemKey_DB_Session, MemKey_Jwt, MemKey_SessionData, SessionKey_Account_BE } from './consts.js';
@@ -6,6 +6,7 @@ import { MemKey_HttpResponse } from '@nu-art/thunderstorm-backend/modules/server
6
6
  import { ResponseHeaderKey_JWTToken } from '@nu-art/thunderstorm-shared';
7
7
  import { ModuleBE_JWT } from './ModuleBE_JWT.js';
8
8
  import { HttpCodes } from '@nu-art/ts-common/core/exceptions/http-codes';
9
+ import { _EmptyQuery } from '@nu-art/firebase-shared';
9
10
  export const dispatch_CollectSessionData = new Dispatcher('__collectSessionData');
10
11
  export const Const_Default_SessionJWT_SecretKey = 'jwt-signer--account-session';
11
12
  export class ModuleBE_SessionDB_Class extends ModuleBE_BaseDB {
@@ -38,6 +39,14 @@ export class ModuleBE_SessionDB_Class extends ModuleBE_BaseDB {
38
39
  return sessionData;
39
40
  }, { ...content });
40
41
  };
42
+ preWriteProcessing = async (instance) => {
43
+ if ('sessionId' in instance)
44
+ delete instance.sessionId;
45
+ if ('timestamp' in instance)
46
+ delete instance.timestamp;
47
+ if ('prevSession' in instance)
48
+ delete instance.prevSession;
49
+ };
41
50
  token = {
42
51
  create: async (initialClaims, ttlInMs, transaction) => {
43
52
  const claims = await this.collectSessionData(initialClaims, transaction);
@@ -228,6 +237,17 @@ export class ModuleBE_SessionDB_Class extends ModuleBE_BaseDB {
228
237
  }
229
238
  };
230
239
  }
240
+ cleanOldOrExpiredSessions = async () => {
241
+ const sessions = await this.query.custom(_EmptyQuery);
242
+ const toDelete = filterInstances(await Promise.all(sessions.map(async (session) => {
243
+ const isExpired = await JwtTools.isJwtExpired(session.sessionIdJwt);
244
+ if (isExpired)
245
+ return session;
246
+ const decoded = await JwtTools.decode(session.sessionIdJwt);
247
+ if ('sessionData' in decoded)
248
+ return session;
249
+ })));
250
+ await this.delete.allItems(toDelete);
251
+ };
231
252
  }
232
- ;
233
253
  export const ModuleBE_SessionDB = new ModuleBE_SessionDB_Class();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nu-art/user-account-backend",
3
- "version": "0.401.5",
3
+ "version": "0.401.7",
4
4
  "description": "User Account Backend",
5
5
  "keywords": [
6
6
  "TacB0sS",
@@ -34,14 +34,14 @@
34
34
  "test": "ts-mocha -w -p src/test/tsconfig.json --timeout 0 --inspect=8107 --watch-files 'src/test/**/*.test.ts' src/test/**/*.test.ts"
35
35
  },
36
36
  "dependencies": {
37
- "@nu-art/user-account-shared": "0.401.5",
38
- "@nu-art/firebase-backend": "0.401.5",
39
- "@nu-art/firebase-shared": "0.401.5",
40
- "@nu-art/slack-backend": "0.401.5",
41
- "@nu-art/slack-shared": "0.401.5",
42
- "@nu-art/thunderstorm-backend": "0.401.5",
43
- "@nu-art/thunderstorm-shared": "0.401.5",
44
- "@nu-art/ts-common": "0.401.5",
37
+ "@nu-art/user-account-shared": "0.401.7",
38
+ "@nu-art/firebase-backend": "0.401.7",
39
+ "@nu-art/firebase-shared": "0.401.7",
40
+ "@nu-art/slack-backend": "0.401.7",
41
+ "@nu-art/slack-shared": "0.401.7",
42
+ "@nu-art/thunderstorm-backend": "0.401.7",
43
+ "@nu-art/thunderstorm-shared": "0.401.7",
44
+ "@nu-art/ts-common": "0.401.7",
45
45
  "express": "^4.18.2",
46
46
  "firebase": "^11.9.0",
47
47
  "firebase-admin": "13.4.0",
@@ -53,8 +53,8 @@
53
53
  "xmlbuilder": "^15.1.1"
54
54
  },
55
55
  "devDependencies": {
56
- "@nu-art/testalot": "0.401.5",
57
- "@nu-art/google-services-backend": "0.401.5",
56
+ "@nu-art/testalot": "0.401.7",
57
+ "@nu-art/google-services-backend": "0.401.7",
58
58
  "@types/react": "^18.0.0",
59
59
  "@types/express": "^4.17.17",
60
60
  "@types/history": "^4.7.2",