@nymphjs/tilmeld 1.0.0-beta.0 → 1.0.0-beta.10

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/src/Tilmeld.ts CHANGED
@@ -6,6 +6,7 @@ import {
6
6
  TilmeldInterface,
7
7
  TilmeldAccessLevels,
8
8
  } from '@nymphjs/nymph';
9
+ import { URL } from 'url';
9
10
  import { Request, Response } from 'express';
10
11
  import { xor } from 'lodash';
11
12
 
@@ -83,6 +84,7 @@ export default class Tilmeld implements TilmeldInterface {
83
84
 
84
85
  /**
85
86
  * This is used internally by Nymph. Don't call it yourself.
87
+ *
86
88
  * @returns A clone of this instance.
87
89
  */
88
90
  public clone() {
@@ -104,6 +106,7 @@ export default class Tilmeld implements TilmeldInterface {
104
106
  */
105
107
  public init(nymph: Nymph) {
106
108
  this.nymph = nymph;
109
+ const tilmeld = this;
107
110
 
108
111
  // Set up access control hooks when Nymph is called.
109
112
  if (this.nymph.driver == null) {
@@ -111,18 +114,18 @@ export default class Tilmeld implements TilmeldInterface {
111
114
  }
112
115
 
113
116
  // Configure the classes.
114
- class NymphUser extends User {}
115
- NymphUser.nymph = this.nymph;
116
- NymphUser.tilmeld = this;
117
+ class NymphUser extends User {
118
+ static nymph: Nymph = nymph;
119
+ static tilmeld: Tilmeld = tilmeld;
120
+ }
117
121
  (NymphUser as any).skipOnClone = true;
118
- this.User = NymphUser;
119
- this.nymph.addEntityClass(NymphUser);
120
- class NymphGroup extends Group {}
121
- NymphGroup.nymph = this.nymph;
122
- NymphGroup.tilmeld = this;
122
+ this.User = this.nymph.addEntityClass(NymphUser);
123
+ class NymphGroup extends Group {
124
+ static nymph: Nymph = nymph;
125
+ static tilmeld: Tilmeld = tilmeld;
126
+ }
123
127
  (NymphUser as any).skipOnClone = true;
124
- this.Group = NymphGroup;
125
- this.nymph.addEntityClass(NymphGroup);
128
+ this.Group = this.nymph.addEntityClass(NymphGroup);
126
129
 
127
130
  this.initAccessControl();
128
131
  if (this.request != null && !this.skipAuthenticate) {
@@ -190,7 +193,7 @@ export default class Tilmeld implements TilmeldInterface {
190
193
  handleQuery.skipOnClone = true;
191
194
 
192
195
  // Filter entities being deleted for user permissions.
193
- const checkPermissionsDelete = function (
196
+ const checkPermissionsDelete = async function (
194
197
  nymph: Nymph,
195
198
  entity: EntityInterface
196
199
  ) {
@@ -209,7 +212,7 @@ export default class Tilmeld implements TilmeldInterface {
209
212
  checkPermissionsDelete.skipOnClone = true;
210
213
 
211
214
  // Filter entities being deleted for user permissions.
212
- const checkPermissionsDeleteByID = function (
215
+ const checkPermissionsDeleteByID = async function (
213
216
  nymph: Nymph,
214
217
  guid: string,
215
218
  className?: string
@@ -226,7 +229,7 @@ export default class Tilmeld implements TilmeldInterface {
226
229
 
227
230
  // Filter entities being saved for user permissions, and filter any
228
231
  // disallowed changes to AC properties.
229
- const checkPermissionsSaveAndFilterAcChanges = function (
232
+ const checkPermissionsSaveAndFilterAcChanges = async function (
230
233
  nymph: Nymph,
231
234
  entity: EntityInterface & AccessControlData
232
235
  ) {
@@ -393,7 +396,7 @@ export default class Tilmeld implements TilmeldInterface {
393
396
  * - acGroup = TilmeldAccessLevels.READ_ACCESS
394
397
  * - acOther = TilmeldAccessLevels.NO_ACCESS
395
398
  */
396
- const addAccess = function (
399
+ const addAccess = async function (
397
400
  nymph: Nymph,
398
401
  entity: EntityInterface & AccessControlData
399
402
  ) {
@@ -437,7 +440,7 @@ export default class Tilmeld implements TilmeldInterface {
437
440
  };
438
441
  addAccess.skipOnClone = true;
439
442
 
440
- const validate = function (
443
+ const validate = async function (
441
444
  _nymph: Nymph,
442
445
  entity: EntityInterface & AccessControlData
443
446
  ) {
package/src/User.ts CHANGED
@@ -37,11 +37,11 @@ export type EventType =
37
37
  export type TilmeldBeforeRegisterCallback = (
38
38
  user: User & UserData,
39
39
  data: { password: string; additionalData?: { [k: string]: any } }
40
- ) => Promise<void> | void;
40
+ ) => Promise<void>;
41
41
  export type TilmeldAfterRegisterCallback = (
42
42
  user: User & UserData,
43
43
  result: { loggedin: boolean; message: string }
44
- ) => Promise<void> | void;
44
+ ) => Promise<void>;
45
45
  /**
46
46
  * These are run after the authentication checks, but before the login action.
47
47
  */
@@ -52,14 +52,20 @@ export type TilmeldBeforeLoginCallback = (
52
52
  password: string;
53
53
  additionalData?: { [k: string]: any };
54
54
  }
55
- ) => void;
55
+ ) => Promise<void>;
56
56
  /**
57
57
  * This is run before the transaction is committed, and you can perform
58
58
  * additional functions on the transaction, which is available in `user.$nymph`.
59
59
  */
60
- export type TilmeldAfterLoginCallback = (user: User & UserData) => void;
61
- export type TilmeldBeforeLogoutCallback = (user: User & UserData) => void;
62
- export type TilmeldAfterLogoutCallback = (user: User & UserData) => void;
60
+ export type TilmeldAfterLoginCallback = (
61
+ user: User & UserData
62
+ ) => Promise<void>;
63
+ export type TilmeldBeforeLogoutCallback = (
64
+ user: User & UserData
65
+ ) => Promise<void>;
66
+ export type TilmeldAfterLogoutCallback = (
67
+ user: User & UserData
68
+ ) => Promise<void>;
63
69
 
64
70
  export type UserData = {
65
71
  /**
@@ -482,7 +488,7 @@ export default class User extends AbleObject<UserData> {
482
488
  }
483
489
  const user = await this.tilmeld.User.factoryUsername(data.username);
484
490
  const result: { result: boolean; message: string; user?: User & UserData } =
485
- user.$login(data);
491
+ await user.$login(data);
486
492
  if (result.result) {
487
493
  user.$updateDataProtection();
488
494
  result.user = user;
@@ -490,7 +496,7 @@ export default class User extends AbleObject<UserData> {
490
496
  return result;
491
497
  }
492
498
 
493
- public $login(data: {
499
+ public async $login(data: {
494
500
  username: string;
495
501
  password: string;
496
502
  additionalData?: { [k: string]: any };
@@ -513,7 +519,7 @@ export default class User extends AbleObject<UserData> {
513
519
  for (let callback of (this.constructor as typeof User)
514
520
  .beforeLoginCallbacks) {
515
521
  if (callback) {
516
- callback(this, data);
522
+ await callback(this, data);
517
523
  }
518
524
  }
519
525
  } catch (e: any) {
@@ -531,7 +537,7 @@ export default class User extends AbleObject<UserData> {
531
537
  for (let callback of (this.constructor as typeof User)
532
538
  .afterLoginCallbacks) {
533
539
  if (callback) {
534
- callback(this);
540
+ await callback(this);
535
541
  }
536
542
  }
537
543
 
@@ -543,14 +549,14 @@ export default class User extends AbleObject<UserData> {
543
549
  * Log a user out of the system.
544
550
  * @returns An object with a boolean 'result' entry and a 'message' entry.
545
551
  */
546
- public $logout() {
552
+ public async $logout() {
547
553
  const tilmeld = this.$nymph.tilmeld as Tilmeld;
548
554
 
549
555
  try {
550
556
  for (let callback of (this.constructor as typeof User)
551
557
  .beforeLogoutCallbacks) {
552
558
  if (callback) {
553
- callback(this);
559
+ await callback(this);
554
560
  }
555
561
  }
556
562
  } catch (e: any) {
@@ -565,7 +571,7 @@ export default class User extends AbleObject<UserData> {
565
571
  for (let callback of (this.constructor as typeof User)
566
572
  .afterLogoutCallbacks) {
567
573
  if (callback) {
568
- callback(this);
574
+ await callback(this);
569
575
  }
570
576
  }
571
577
 
@@ -627,7 +633,8 @@ export default class User extends AbleObject<UserData> {
627
633
  this.$referenceWake();
628
634
 
629
635
  if (
630
- input.data.abilities?.indexOf('system/admin') !== -1 &&
636
+ 'abilities' in input.data &&
637
+ input.data.abilities.indexOf('system/admin') !== -1 &&
631
638
  this.$data.abilities?.indexOf('system/admin') === -1 &&
632
639
  tilmeld.gatekeeper('tilmeld/admin') &&
633
640
  !tilmeld.gatekeeper('system/admin')
@@ -646,7 +653,8 @@ export default class User extends AbleObject<UserData> {
646
653
  this.$referenceWake();
647
654
 
648
655
  if (
649
- patch.set.abilities?.indexOf('system/admin') !== -1 &&
656
+ 'abilities' in patch.set &&
657
+ patch.set.abilities.indexOf('system/admin') !== -1 &&
650
658
  this.$data.abilities?.indexOf('system/admin') === -1 &&
651
659
  tilmeld.gatekeeper('tilmeld/admin') &&
652
660
  !tilmeld.gatekeeper('system/admin')
@@ -1777,7 +1785,7 @@ export default class User extends AbleObject<UserData> {
1777
1785
  );
1778
1786
  }
1779
1787
  if (tilmeld.User.current(true).$is(this)) {
1780
- this.$logout();
1788
+ await this.$logout();
1781
1789
  }
1782
1790
  return await super.$delete();
1783
1791
  }
@@ -1,4 +1,5 @@
1
1
  import path from 'path';
2
+ import { URL } from 'url';
2
3
  import jwt from 'jsonwebtoken';
3
4
  import Email from 'email-templates';
4
5
  import Joi from 'joi';
package/tsconfig.json CHANGED
@@ -2,6 +2,8 @@
2
2
  "extends": "@tsconfig/recommended/tsconfig.json",
3
3
 
4
4
  "compilerOptions": {
5
+ "lib": ["ES2021"],
6
+ "target": "ES2021",
5
7
  "noImplicitAny": true,
6
8
  "removeComments": true,
7
9
  "sourceMap": true,