@travetto/auth-model 6.0.0 → 7.0.0-rc.0

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-model",
3
- "version": "6.0.0",
3
+ "version": "7.0.0-rc.0",
4
4
  "description": "Authentication model support for the Travetto framework",
5
5
  "keywords": [
6
6
  "authentication",
@@ -25,11 +25,11 @@
25
25
  "directory": "module/auth-model"
26
26
  },
27
27
  "dependencies": {
28
- "@travetto/auth": "^6.0.0",
29
- "@travetto/model": "^6.0.0"
28
+ "@travetto/auth": "^7.0.0-rc.0",
29
+ "@travetto/model": "^7.0.0-rc.0"
30
30
  },
31
31
  "peerDependencies": {
32
- "@travetto/test": "^6.0.0"
32
+ "@travetto/test": "^7.0.0-rc.0"
33
33
  },
34
34
  "peerDependenciesMeta": {
35
35
  "@travetto/test": {
package/src/model.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Util, Class, TimeUtil, Runtime } from '@travetto/runtime';
1
+ import { Util, Class, TimeUtil, Runtime, castTo } from '@travetto/runtime';
2
2
  import { ModelCrudSupport, ModelType, NotFoundError, OptionalId, ModelStorageUtil } from '@travetto/model';
3
3
  import { Principal, Authenticator, Authorizer, AuthenticationError } from '@travetto/auth';
4
4
 
@@ -93,7 +93,6 @@ export class ModelAuthService<T extends ModelType> implements Authenticator<T>,
93
93
  if (hash !== ident.hash) {
94
94
  throw new AuthenticationError('Invalid password');
95
95
  } else {
96
- delete ident.password;
97
96
  return ident;
98
97
  }
99
98
  }
@@ -123,13 +122,8 @@ export class ModelAuthService<T extends ModelType> implements Authenticator<T>,
123
122
  }
124
123
 
125
124
  const fields = await AuthModelUtil.generatePassword(ident.password!);
126
-
127
- ident.password = undefined; // Clear it out on set
128
-
129
- Object.assign(user, this.fromPrincipal(fields));
130
-
131
- const res: T = await this.#modelService.create(this.#cls, user);
132
- return res;
125
+ const output: Partial<T> = { ...user, ...this.fromPrincipal(fields) };
126
+ return await this.#modelService.create(this.#cls, this.#cls.from(castTo(output)));
133
127
  }
134
128
 
135
129
  /**
@@ -154,9 +148,8 @@ export class ModelAuthService<T extends ModelType> implements Authenticator<T>,
154
148
  }
155
149
 
156
150
  const fields = await AuthModelUtil.generatePassword(password);
157
- Object.assign(user, this.fromPrincipal(fields));
158
-
159
- return await this.#modelService.update(this.#cls, user);
151
+ const output: Partial<T> = { ...user, ...this.fromPrincipal(fields) };
152
+ return await this.#modelService.update(this.#cls, this.#cls.from(castTo(output)));
160
153
  }
161
154
 
162
155
  /**
@@ -171,10 +164,8 @@ export class ModelAuthService<T extends ModelType> implements Authenticator<T>,
171
164
  ident.resetToken = await AuthModelUtil.generateHash(Util.uuid(), salt, 25000, 32);
172
165
  ident.resetExpires = TimeUtil.fromNow(1, 'h');
173
166
 
174
- Object.assign(user, this.fromPrincipal(ident));
175
-
176
- await this.#modelService.update(this.#cls, user);
177
-
167
+ const output: Partial<T> = { ...user, ...this.fromPrincipal(ident) };
168
+ await this.#modelService.update(this.#cls, this.#cls.from(castTo(output)));
178
169
  return ident;
179
170
  }
180
171
 
@@ -3,7 +3,7 @@ import assert from 'node:assert';
3
3
  import { AppError, castTo, Class } from '@travetto/runtime';
4
4
  import { Suite, Test } from '@travetto/test';
5
5
  import { Inject, InjectableFactory } from '@travetto/di';
6
- import { ModelCrudSupport, Model } from '@travetto/model';
6
+ import { ModelCrudSupport, Model, Transient } from '@travetto/model';
7
7
  import { InjectableSuite } from '@travetto/di/support/test/suite.ts';
8
8
  import { ModelSuite } from '@travetto/model/support/test/suite.ts';
9
9
 
@@ -14,6 +14,7 @@ export const TestModelSvcSymbol = Symbol.for('@travetto/auth:test-model-svc');
14
14
  @Model({ autoCreate: false })
15
15
  class User implements RegisteredPrincipal {
16
16
  id: string;
17
+ @Transient()
17
18
  password?: string;
18
19
  salt?: string;
19
20
  hash?: string;
@@ -58,6 +59,7 @@ export abstract class AuthModelServiceSuite {
58
59
  });
59
60
 
60
61
  const user = await this.authService.register(pre);
62
+ assert(user.password === undefined);
61
63
  assert.ok(user.hash);
62
64
  assert.ok(user.id);
63
65
  }
@@ -78,6 +80,7 @@ export abstract class AuthModelServiceSuite {
78
80
  const user = await this.authService.register(pre);
79
81
  assert.ok(user.hash);
80
82
  assert.ok(user.id);
83
+ assert(user.password === undefined);
81
84
  } else {
82
85
  throw err;
83
86
  }