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

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
 
@@ -149,7 +150,7 @@ export default class Tilmeld implements TilmeldInterface {
149
150
 
150
151
  private initAccessControl() {
151
152
  // Check for the skip access control option and add AC selectors.
152
- const handleQuery = function (
153
+ const handleQuery = async function (
153
154
  nymph: Nymph,
154
155
  options: Options,
155
156
  selectors: FormattedSelector[]
@@ -190,7 +191,7 @@ export default class Tilmeld implements TilmeldInterface {
190
191
  handleQuery.skipOnClone = true;
191
192
 
192
193
  // Filter entities being deleted for user permissions.
193
- const checkPermissionsDelete = function (
194
+ const checkPermissionsDelete = async function (
194
195
  nymph: Nymph,
195
196
  entity: EntityInterface
196
197
  ) {
@@ -209,7 +210,7 @@ export default class Tilmeld implements TilmeldInterface {
209
210
  checkPermissionsDelete.skipOnClone = true;
210
211
 
211
212
  // Filter entities being deleted for user permissions.
212
- const checkPermissionsDeleteByID = function (
213
+ const checkPermissionsDeleteByID = async function (
213
214
  nymph: Nymph,
214
215
  guid: string,
215
216
  className?: string
@@ -226,7 +227,7 @@ export default class Tilmeld implements TilmeldInterface {
226
227
 
227
228
  // Filter entities being saved for user permissions, and filter any
228
229
  // disallowed changes to AC properties.
229
- const checkPermissionsSaveAndFilterAcChanges = function (
230
+ const checkPermissionsSaveAndFilterAcChanges = async function (
230
231
  nymph: Nymph,
231
232
  entity: EntityInterface & AccessControlData
232
233
  ) {
@@ -393,7 +394,7 @@ export default class Tilmeld implements TilmeldInterface {
393
394
  * - acGroup = TilmeldAccessLevels.READ_ACCESS
394
395
  * - acOther = TilmeldAccessLevels.NO_ACCESS
395
396
  */
396
- const addAccess = function (
397
+ const addAccess = async function (
397
398
  nymph: Nymph,
398
399
  entity: EntityInterface & AccessControlData
399
400
  ) {
@@ -437,7 +438,7 @@ export default class Tilmeld implements TilmeldInterface {
437
438
  };
438
439
  addAccess.skipOnClone = true;
439
440
 
440
- const validate = function (
441
+ const validate = async function (
441
442
  _nymph: Nymph,
442
443
  entity: EntityInterface & AccessControlData
443
444
  ) {
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
 
@@ -1777,7 +1783,7 @@ export default class User extends AbleObject<UserData> {
1777
1783
  );
1778
1784
  }
1779
1785
  if (tilmeld.User.current(true).$is(this)) {
1780
- this.$logout();
1786
+ await this.$logout();
1781
1787
  }
1782
1788
  return await super.$delete();
1783
1789
  }
@@ -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,