@adminforth/two-factors-auth 7.1.0 → 7.1.1

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/build.log CHANGED
@@ -21,5 +21,5 @@ custom/tsconfig.json
21
21
  custom/use2faApi.ts
22
22
  custom/utils.js
23
23
 
24
- sent 300,012 bytes received 324 bytes 600,672.00 bytes/sec
24
+ sent 300,029 bytes received 324 bytes 600,706.00 bytes/sec
25
25
  total size is 298,778 speedup is 0.99
@@ -15,4 +15,9 @@ export declare class PasskeyRepository {
15
15
  updateMeta(passkeyRecord: AnyRecord, meta: AnyRecord): Promise<void>;
16
16
  update(passkeyRecord: AnyRecord, newRecord: AnyRecord, adminUser: AdminUser): Promise<void>;
17
17
  delete(passkeyRecord: AnyRecord, adminUser: AdminUser): Promise<void>;
18
+ /**
19
+ * Users manage their own passkeys and the plugin checks the ownership itself, so these are system
20
+ * writes on the user's behalf, which run the resource hooks (e.g. the audit log).
21
+ */
22
+ private ownerWriter;
18
23
  }
@@ -49,11 +49,10 @@ export class PasskeyRepository {
49
49
  }
50
50
  create(record, adminUser) {
51
51
  return __awaiter(this, void 0, void 0, function* () {
52
- yield this.adminforth.createResourceRecord({
53
- resource: this.getCredentialResource(),
54
- record,
55
- adminUser,
56
- });
52
+ const { error } = yield this.ownerWriter(adminUser).create(record);
53
+ if (error) {
54
+ throw new Error(error);
55
+ }
57
56
  });
58
57
  }
59
58
  updateMeta(passkeyRecord, meta) {
@@ -67,23 +66,24 @@ export class PasskeyRepository {
67
66
  }
68
67
  update(passkeyRecord, newRecord, adminUser) {
69
68
  return __awaiter(this, void 0, void 0, function* () {
70
- yield this.adminforth.updateResourceRecord({
71
- resource: this.getCredentialResource(),
72
- recordId: passkeyRecord[this.getCredentialResourcePkField()],
73
- oldRecord: passkeyRecord,
74
- updates: newRecord,
75
- adminUser,
76
- });
69
+ const { error } = yield this.ownerWriter(adminUser, { oldRecord: passkeyRecord })
70
+ .update(passkeyRecord[this.getCredentialResourcePkField()], newRecord);
71
+ if (error) {
72
+ throw new Error(error);
73
+ }
77
74
  });
78
75
  }
79
76
  delete(passkeyRecord, adminUser) {
80
77
  return __awaiter(this, void 0, void 0, function* () {
81
- yield this.adminforth.deleteResourceRecord({
82
- resource: this.getCredentialResource(),
83
- recordId: passkeyRecord[this.getCredentialResourcePkField()],
84
- record: passkeyRecord,
85
- adminUser,
86
- });
78
+ yield this.ownerWriter(adminUser, { record: passkeyRecord })
79
+ .delete(passkeyRecord[this.getCredentialResourcePkField()]);
87
80
  });
88
81
  }
82
+ /**
83
+ * Users manage their own passkeys and the plugin checks the ownership itself, so these are system
84
+ * writes on the user's behalf, which run the resource hooks (e.g. the audit log).
85
+ */
86
+ ownerWriter(adminUser, snapshot = {}) {
87
+ return this.adminforth.resource(this.options.passkeys.credentialResourceID).asSystem(Object.assign({ adminUser }, snapshot));
88
+ }
89
89
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/two-factors-auth",
3
- "version": "7.1.0",
3
+ "version": "7.1.1",
4
4
  "description": "AdminForth plugin for two factors authentication",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -29,11 +29,11 @@
29
29
  "zod": "^4.3.6"
30
30
  },
31
31
  "peerDependencies": {
32
- "adminforth": "^4.7.3"
32
+ "adminforth": "^4.22.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/node": "^22.10.7",
36
- "adminforth": "^4.7.3",
36
+ "adminforth": "^4.22.0",
37
37
  "semantic-release": "^24.2.1",
38
38
  "semantic-release-slack-bot": "^4.0.2",
39
39
  "typescript": "^5.7.3"
@@ -42,11 +42,10 @@ export class PasskeyRepository {
42
42
  }
43
43
 
44
44
  public async create(record: AnyRecord, adminUser: AdminUser): Promise<void> {
45
- await this.adminforth.createResourceRecord({
46
- resource: this.getCredentialResource(),
47
- record,
48
- adminUser,
49
- });
45
+ const { error } = await this.ownerWriter(adminUser).create(record);
46
+ if (error) {
47
+ throw new Error(error);
48
+ }
50
49
  }
51
50
 
52
51
  public async updateMeta(passkeyRecord: AnyRecord, meta: AnyRecord): Promise<void> {
@@ -58,21 +57,23 @@ export class PasskeyRepository {
58
57
  }
59
58
 
60
59
  public async update(passkeyRecord: AnyRecord, newRecord: AnyRecord, adminUser: AdminUser): Promise<void> {
61
- await this.adminforth.updateResourceRecord({
62
- resource: this.getCredentialResource(),
63
- recordId: passkeyRecord[this.getCredentialResourcePkField()],
64
- oldRecord: passkeyRecord,
65
- updates: newRecord,
66
- adminUser,
67
- });
60
+ const { error } = await this.ownerWriter(adminUser, { oldRecord: passkeyRecord })
61
+ .update(passkeyRecord[this.getCredentialResourcePkField()], newRecord);
62
+ if (error) {
63
+ throw new Error(error);
64
+ }
68
65
  }
69
66
 
70
67
  public async delete(passkeyRecord: AnyRecord, adminUser: AdminUser): Promise<void> {
71
- await this.adminforth.deleteResourceRecord({
72
- resource: this.getCredentialResource(),
73
- recordId: passkeyRecord[this.getCredentialResourcePkField()],
74
- record: passkeyRecord,
75
- adminUser,
76
- });
68
+ await this.ownerWriter(adminUser, { record: passkeyRecord })
69
+ .delete(passkeyRecord[this.getCredentialResourcePkField()]);
70
+ }
71
+
72
+ /**
73
+ * Users manage their own passkeys and the plugin checks the ownership itself, so these are system
74
+ * writes on the user's behalf, which run the resource hooks (e.g. the audit log).
75
+ */
76
+ private ownerWriter(adminUser: AdminUser, snapshot: { record?: AnyRecord; oldRecord?: AnyRecord } = {}) {
77
+ return this.adminforth.resource(this.options.passkeys.credentialResourceID).asSystem({ adminUser, ...snapshot });
77
78
  }
78
79
  }