@travetto/auth-session 7.0.0-rc.1 → 7.0.0-rc.3

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/auth-session",
3
- "version": "7.0.0-rc.1",
3
+ "version": "7.0.0-rc.3",
4
4
  "description": "Session provider for the travetto auth module.",
5
5
  "keywords": [
6
6
  "auth",
@@ -25,12 +25,12 @@
25
25
  "directory": "module/auth-session"
26
26
  },
27
27
  "dependencies": {
28
- "@travetto/auth": "^7.0.0-rc.1",
29
- "@travetto/config": "^7.0.0-rc.1",
30
- "@travetto/model": "^7.0.0-rc.1"
28
+ "@travetto/auth": "^7.0.0-rc.3",
29
+ "@travetto/config": "^7.0.0-rc.3",
30
+ "@travetto/model": "^7.0.0-rc.3"
31
31
  },
32
32
  "peerDependencies": {
33
- "@travetto/test": "^7.0.0-rc.1"
33
+ "@travetto/test": "^7.0.0-rc.3"
34
34
  },
35
35
  "peerDependenciesMeta": {
36
36
  "@travetto/test": {
package/src/context.ts CHANGED
@@ -38,11 +38,11 @@ export class SessionContext {
38
38
  get(createIfMissing: true): Session;
39
39
  get(): Session | undefined;
40
40
  get(createIfMissing?: boolean): Session | undefined {
41
- let val = this.#value.get();
42
- if (!val && createIfMissing) {
43
- this.set(val = this.#create());
41
+ let value = this.#value.get();
42
+ if (!value && createIfMissing) {
43
+ this.set(value = this.#create());
44
44
  }
45
- return val;
45
+ return value;
46
46
  }
47
47
 
48
48
  /**
package/src/model.ts CHANGED
@@ -6,7 +6,7 @@ import { Text } from '@travetto/schema';
6
6
  */
7
7
  export const SessionModelSymbol = Symbol.for('@travetto/auth-session:model');
8
8
 
9
- @Model({ autoCreate: false })
9
+ @Model({ autoCreate: 'production' })
10
10
  export class SessionEntry {
11
11
  id: string;
12
12
  @Text()
package/src/service.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Injectable, Inject } from '@travetto/di';
2
- import { Runtime, Util } from '@travetto/runtime';
3
- import { ModelExpirySupport, NotFoundError, ModelStorageUtil } from '@travetto/model';
2
+ import { JSONUtil } from '@travetto/runtime';
3
+ import { ModelExpirySupport, NotFoundError } from '@travetto/model';
4
4
  import { AuthContext, AuthService } from '@travetto/auth';
5
5
 
6
6
  import { Session } from './session.ts';
@@ -28,15 +28,6 @@ export class SessionService {
28
28
  this.#modelService = service;
29
29
  }
30
30
 
31
- /**
32
- * Initialize service if none defined
33
- */
34
- async postConstruct(): Promise<void> {
35
- if (ModelStorageUtil.isSupported(this.#modelService) && Runtime.dynamic) {
36
- await this.#modelService.createModel?.(SessionEntry);
37
- }
38
- }
39
-
40
31
  /**
41
32
  * Load session by id
42
33
  * @returns Session if valid
@@ -47,7 +38,7 @@ export class SessionService {
47
38
 
48
39
  const session = new Session({
49
40
  ...record,
50
- data: Util.decodeSafeJSON(record.data)
41
+ data: JSONUtil.parseBase64(record.data)
51
42
  });
52
43
 
53
44
  // Validate session
@@ -57,9 +48,9 @@ export class SessionService {
57
48
  } else {
58
49
  return session;
59
50
  }
60
- } catch (err) {
61
- if (!(err instanceof NotFoundError)) {
62
- throw err; // If not a not found error, throw
51
+ } catch (error) {
52
+ if (!(error instanceof NotFoundError)) {
53
+ throw error; // If not a not found error, throw
63
54
  }
64
55
  }
65
56
  }
@@ -78,18 +69,18 @@ export class SessionService {
78
69
  // Ensure latest expiry information before persisting
79
70
  await this.authService.manageExpiry(this.authContext.principal);
80
71
 
81
- const p = this.authContext.principal;
72
+ const principal = this.authContext.principal;
82
73
 
83
74
  // If not destroying, write to response, and store
84
- if (p && session.action !== 'destroy') {
85
- session.expiresAt = p.expiresAt;
86
- session.issuedAt = p.issuedAt!;
75
+ if (principal && session.action !== 'destroy') {
76
+ session.expiresAt = principal.expiresAt;
77
+ session.issuedAt = principal.issuedAt!;
87
78
 
88
79
  // If expiration time has changed, send new session information
89
80
  if (session.action === 'create' || session.isChanged()) {
90
81
  await this.#modelService.upsert(SessionEntry, SessionEntry.from({
91
82
  ...session,
92
- data: Util.encodeSafeJSON(session.data)
83
+ data: JSONUtil.stringifyBase64(session.data)
93
84
  }));
94
85
  }
95
86
  // If destroying