@nymphjs/tilmeld 1.0.0-beta.46 → 1.0.0-beta.48

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/User.ts CHANGED
@@ -40,7 +40,7 @@ export type EventType =
40
40
  */
41
41
  export type TilmeldCheckUsernameCallback = (
42
42
  user: User & UserData,
43
- data: { username: string }
43
+ data: { username: string },
44
44
  ) => Promise<{ result: boolean; message?: string }>;
45
45
  /**
46
46
  * Theses are run before the user data checks, so the only checks before are
@@ -48,11 +48,11 @@ export type TilmeldCheckUsernameCallback = (
48
48
  */
49
49
  export type TilmeldBeforeRegisterCallback = (
50
50
  user: User & UserData,
51
- data: { password: string; additionalData?: { [k: string]: any } }
51
+ data: { password: string; additionalData?: { [k: string]: any } },
52
52
  ) => Promise<void>;
53
53
  export type TilmeldAfterRegisterCallback = (
54
54
  user: User & UserData,
55
- result: { loggedin: boolean; message: string }
55
+ result: { loggedin: boolean; message: string },
56
56
  ) => Promise<void>;
57
57
  /**
58
58
  * These are run after the authentication checks, but before the login action.
@@ -63,20 +63,20 @@ export type TilmeldBeforeLoginCallback = (
63
63
  username: string;
64
64
  password: string;
65
65
  additionalData?: { [k: string]: any };
66
- }
66
+ },
67
67
  ) => Promise<void>;
68
68
  /**
69
69
  * This is run before the transaction is committed, and you can perform
70
70
  * additional functions on the transaction, which is available in `user.$nymph`.
71
71
  */
72
72
  export type TilmeldAfterLoginCallback = (
73
- user: User & UserData
73
+ user: User & UserData,
74
74
  ) => Promise<void>;
75
75
  export type TilmeldBeforeLogoutCallback = (
76
- user: User & UserData
76
+ user: User & UserData,
77
77
  ) => Promise<void>;
78
78
  export type TilmeldAfterLogoutCallback = (
79
- user: User & UserData
79
+ user: User & UserData,
80
80
  ) => Promise<void>;
81
81
 
82
82
  export type UserData = {
@@ -303,7 +303,7 @@ export default class User extends AbleObject<UserData> {
303
303
  {
304
304
  type: '&',
305
305
  ilike: ['username', username.replace(/([\\%_])/g, (s) => `\\${s}`)],
306
- }
306
+ },
307
307
  );
308
308
  if (entity != null) {
309
309
  return entity;
@@ -329,10 +329,10 @@ export default class User extends AbleObject<UserData> {
329
329
 
330
330
  public static current(returnObjectIfNotExist: true): User & UserData;
331
331
  public static current(
332
- returnObjectIfNotExist?: false
332
+ returnObjectIfNotExist?: false,
333
333
  ): (User & UserData) | null;
334
334
  public static current(
335
- returnObjectIfNotExist?: boolean
335
+ returnObjectIfNotExist?: boolean,
336
336
  ): (User & UserData) | null {
337
337
  const tilmeld = enforceTilmeld(this);
338
338
  if (tilmeld.currentUser == null) {
@@ -370,7 +370,7 @@ export default class User extends AbleObject<UserData> {
370
370
  {
371
371
  type: '&',
372
372
  ilike: ['email', data.account.replace(/([\\%_])/g, (s) => `\\${s}`)],
373
- }
373
+ },
374
374
  );
375
375
 
376
376
  if (getUser == null) {
@@ -466,7 +466,7 @@ export default class User extends AbleObject<UserData> {
466
466
  data.secret !== user.recoverSecret ||
467
467
  strtotime(
468
468
  '+' + tilmeld.config.pwRecoveryTimeLimit,
469
- Math.floor((user.recoverSecretDate ?? 0) / 1000)
469
+ Math.floor((user.recoverSecretDate ?? 0) / 1000),
470
470
  ) *
471
471
  1000 <
472
472
  Date.now()
@@ -745,7 +745,7 @@ export default class User extends AbleObject<UserData> {
745
745
  await Promise.all(this.$data.groups?.map((e) => e.$wake()) || []);
746
746
  for (let curGroup of this.$data.groups ?? []) {
747
747
  this.$descendantGroups = this.$descendantGroups?.concat(
748
- await curGroup.$getDescendants()
748
+ await curGroup.$getDescendants(),
749
749
  );
750
750
  }
751
751
  }
@@ -764,7 +764,7 @@ export default class User extends AbleObject<UserData> {
764
764
  !tilmeld.currentUser.abilities?.includes('system/admin'))
765
765
  ) {
766
766
  throw new BadDataError(
767
- "You don't have the authority to grant or revoke system/admin."
767
+ "You don't have the authority to grant or revoke system/admin.",
768
768
  );
769
769
  }
770
770
 
@@ -776,7 +776,7 @@ export default class User extends AbleObject<UserData> {
776
776
  !tilmeld.currentUser.abilities?.includes('system/admin'))
777
777
  ) {
778
778
  throw new BadDataError(
779
- "You don't have the authority to grant or revoke tilmeld/admin."
779
+ "You don't have the authority to grant or revoke tilmeld/admin.",
780
780
  );
781
781
  }
782
782
 
@@ -788,7 +788,7 @@ export default class User extends AbleObject<UserData> {
788
788
  !tilmeld.currentUser.abilities?.includes('system/admin'))
789
789
  ) {
790
790
  throw new BadDataError(
791
- "You don't have the authority to grant or revoke tilmeld/switch."
791
+ "You don't have the authority to grant or revoke tilmeld/switch.",
792
792
  );
793
793
  }
794
794
 
@@ -808,7 +808,7 @@ export default class User extends AbleObject<UserData> {
808
808
  !tilmeld.currentUser.abilities?.includes('system/admin'))
809
809
  ) {
810
810
  throw new BadDataError(
811
- "You don't have the authority to grant or revoke system/admin."
811
+ "You don't have the authority to grant or revoke system/admin.",
812
812
  );
813
813
  }
814
814
 
@@ -820,7 +820,7 @@ export default class User extends AbleObject<UserData> {
820
820
  !tilmeld.currentUser.abilities?.includes('system/admin'))
821
821
  ) {
822
822
  throw new BadDataError(
823
- "You don't have the authority to grant or revoke tilmeld/admin."
823
+ "You don't have the authority to grant or revoke tilmeld/admin.",
824
824
  );
825
825
  }
826
826
 
@@ -832,7 +832,7 @@ export default class User extends AbleObject<UserData> {
832
832
  !tilmeld.currentUser.abilities?.includes('system/admin'))
833
833
  ) {
834
834
  throw new BadDataError(
835
- "You don't have the authority to grant or revoke tilmeld/switch."
835
+ "You don't have the authority to grant or revoke tilmeld/switch.",
836
836
  );
837
837
  }
838
838
 
@@ -1015,7 +1015,7 @@ export default class User extends AbleObject<UserData> {
1015
1015
  }
1016
1016
  }
1017
1017
  return Object.fromEntries(
1018
- abilities.map((ability) => [ability, true as true])
1018
+ abilities.map((ability) => [ability, true as true]),
1019
1019
  );
1020
1020
  }
1021
1021
 
@@ -1044,7 +1044,7 @@ export default class User extends AbleObject<UserData> {
1044
1044
 
1045
1045
  if (this.$data.secret != null) {
1046
1046
  const link = `${verifyUrl}?action=verify&id=${encodeURIComponent(
1047
- this.guid
1047
+ this.guid,
1048
1048
  )}&secret=${encodeURIComponent(this.$data.secret)}`;
1049
1049
  success =
1050
1050
  success &&
@@ -1062,13 +1062,13 @@ export default class User extends AbleObject<UserData> {
1062
1062
  verifyLink: link,
1063
1063
  },
1064
1064
  },
1065
- this
1065
+ this,
1066
1066
  ));
1067
1067
  }
1068
1068
 
1069
1069
  if (this.$data.newEmailSecret != null) {
1070
1070
  const link = `${verifyUrl}?action=verifychange&id=${encodeURIComponent(
1071
- this.guid
1071
+ this.guid,
1072
1072
  )}&secret=${encodeURIComponent(this.$data.newEmailSecret)}`;
1073
1073
  success =
1074
1074
  success &&
@@ -1088,13 +1088,13 @@ export default class User extends AbleObject<UserData> {
1088
1088
  newEmail: this.$data.newEmailAddress,
1089
1089
  },
1090
1090
  },
1091
- this
1091
+ this,
1092
1092
  ));
1093
1093
  }
1094
1094
 
1095
1095
  if (this.$data.cancelEmailSecret != null) {
1096
1096
  const link = `${verifyUrl}?action=cancelchange&id=${encodeURIComponent(
1097
- this.guid
1097
+ this.guid,
1098
1098
  )}&secret=${encodeURIComponent(this.$data.cancelEmailSecret)}`;
1099
1099
  success =
1100
1100
  success &&
@@ -1114,7 +1114,7 @@ export default class User extends AbleObject<UserData> {
1114
1114
  newEmail: this.$data.newEmailAddress ?? this.$data.email,
1115
1115
  },
1116
1116
  },
1117
- this
1117
+ this,
1118
1118
  ));
1119
1119
  }
1120
1120
 
@@ -1286,7 +1286,7 @@ export default class User extends AbleObject<UserData> {
1286
1286
  default:
1287
1287
  this.$data.salt = nanoid();
1288
1288
  this.$data.password = sha256(password + this.$data.salt).toString(
1289
- Base64
1289
+ Base64,
1290
1290
  );
1291
1291
  break;
1292
1292
  }
@@ -1536,7 +1536,7 @@ export default class User extends AbleObject<UserData> {
1536
1536
  if (
1537
1537
  difference(
1538
1538
  this.$data.username.split(''),
1539
- tilmeld.config.validChars.split('')
1539
+ tilmeld.config.validChars.split(''),
1540
1540
  ).length
1541
1541
  ) {
1542
1542
  return {
@@ -1563,7 +1563,7 @@ export default class User extends AbleObject<UserData> {
1563
1563
  }
1564
1564
  const test = await this.$nymph.getEntity(
1565
1565
  { class: tilmeld.User, skipAc: true },
1566
- selector
1566
+ selector,
1567
1567
  );
1568
1568
  if (test != null) {
1569
1569
  return { result: false, message: 'That username is taken.' };
@@ -1643,7 +1643,7 @@ export default class User extends AbleObject<UserData> {
1643
1643
  }
1644
1644
  const test = await this.$nymph.getEntity(
1645
1645
  { class: tilmeld.User, skipAc: true },
1646
- selector
1646
+ selector,
1647
1647
  );
1648
1648
  if (test != null) {
1649
1649
  return {
@@ -1687,7 +1687,7 @@ export default class User extends AbleObject<UserData> {
1687
1687
  }
1688
1688
  const test = await this.$nymph.getEntity(
1689
1689
  { class: tilmeld.User, skipAc: true },
1690
- selector
1690
+ selector,
1691
1691
  );
1692
1692
  if (test != null) {
1693
1693
  return { result: false, message: 'Phone number is in use.' };
@@ -1768,6 +1768,9 @@ export default class User extends AbleObject<UserData> {
1768
1768
  this.$nymph = tnymph;
1769
1769
  tilmeld = enforceTilmeld(this);
1770
1770
 
1771
+ let message = '';
1772
+ let loggedin = false;
1773
+
1771
1774
  try {
1772
1775
  // Add primary group.
1773
1776
  let generatedPrimaryGroup: (Group & GroupData) | null = null;
@@ -1783,7 +1786,7 @@ export default class User extends AbleObject<UserData> {
1783
1786
  {
1784
1787
  type: '&',
1785
1788
  equal: ['defaultPrimary', true],
1786
- }
1789
+ },
1787
1790
  );
1788
1791
  if (parent != null) {
1789
1792
  generatedPrimaryGroup.parent = parent;
@@ -1805,7 +1808,7 @@ export default class User extends AbleObject<UserData> {
1805
1808
  {
1806
1809
  type: '&',
1807
1810
  equal: ['defaultPrimary', true],
1808
- }
1811
+ },
1809
1812
  );
1810
1813
  if (group != null) {
1811
1814
  this.$data.group = group;
@@ -1820,7 +1823,7 @@ export default class User extends AbleObject<UserData> {
1820
1823
  {
1821
1824
  type: '&',
1822
1825
  equal: ['unverifiedSecondary', true],
1823
- }
1826
+ },
1824
1827
  );
1825
1828
  } else {
1826
1829
  // Add the default secondaries.
@@ -1829,7 +1832,7 @@ export default class User extends AbleObject<UserData> {
1829
1832
  {
1830
1833
  type: '&',
1831
1834
  equal: ['defaultSecondary', true],
1832
- }
1835
+ },
1833
1836
  );
1834
1837
  }
1835
1838
 
@@ -1879,13 +1882,10 @@ export default class User extends AbleObject<UserData> {
1879
1882
  userPhone: this.$data.phone,
1880
1883
  },
1881
1884
  },
1882
- this
1885
+ this,
1883
1886
  );
1884
1887
  }
1885
1888
 
1886
- let message = '';
1887
- let loggedin = false;
1888
-
1889
1889
  // Save the primary group.
1890
1890
  if (generatedPrimaryGroup != null) {
1891
1891
  generatedPrimaryGroup.user = this;
@@ -1940,20 +1940,6 @@ export default class User extends AbleObject<UserData> {
1940
1940
  });
1941
1941
  }
1942
1942
  }
1943
-
1944
- try {
1945
- await tnymph.commit(transaction);
1946
- this.$nymph = nymph;
1947
- await this.$nymph.tilmeld?.fillSession(this);
1948
- } catch (e: any) {
1949
- throw e;
1950
- }
1951
-
1952
- return {
1953
- result: true,
1954
- loggedin,
1955
- message,
1956
- };
1957
1943
  } else {
1958
1944
  await tnymph.rollback(transaction);
1959
1945
  this.$nymph = nymph;
@@ -1968,6 +1954,20 @@ export default class User extends AbleObject<UserData> {
1968
1954
  this.$nymph = nymph;
1969
1955
  throw e;
1970
1956
  }
1957
+
1958
+ try {
1959
+ await tnymph.commit(transaction);
1960
+ this.$nymph = nymph;
1961
+ await this.$nymph.tilmeld?.fillSession(this);
1962
+ } catch (e: any) {
1963
+ throw e;
1964
+ }
1965
+
1966
+ return {
1967
+ result: true,
1968
+ loggedin,
1969
+ message,
1970
+ };
1971
1971
  }
1972
1972
 
1973
1973
  public async $save() {
@@ -1982,7 +1982,7 @@ export default class User extends AbleObject<UserData> {
1982
1982
  this.$data.abilities?.includes('system/admin')
1983
1983
  ) {
1984
1984
  throw new BadDataError(
1985
- "You don't have the authority to modify system admins."
1985
+ "You don't have the authority to modify system admins.",
1986
1986
  );
1987
1987
  }
1988
1988
 
@@ -2100,10 +2100,10 @@ export default class User extends AbleObject<UserData> {
2100
2100
  new Date(
2101
2101
  strtotime(
2102
2102
  '+' + tilmeld.config.emailRateLimit,
2103
- Math.floor(this.$data.emailChangeDate / 1000)
2104
- ) * 1000
2103
+ Math.floor(this.$data.emailChangeDate / 1000),
2104
+ ) * 1000,
2105
2105
  ).toString() +
2106
- ' to change your email address again.'
2106
+ ' to change your email address again.',
2107
2107
  );
2108
2108
  } else {
2109
2109
  if (
@@ -2258,7 +2258,7 @@ export default class User extends AbleObject<UserData> {
2258
2258
  this.$data.abilities?.includes('system/admin')
2259
2259
  ) {
2260
2260
  throw new BadDataError(
2261
- "You don't have the authority to delete system admins."
2261
+ "You don't have the authority to delete system admins.",
2262
2262
  );
2263
2263
  }
2264
2264
  if (tilmeld.User.current(true).$is(this)) {
@@ -2283,7 +2283,7 @@ export default class User extends AbleObject<UserData> {
2283
2283
  ? TilmeldBeforeLogoutCallback
2284
2284
  : T extends 'afterLogout'
2285
2285
  ? TilmeldAfterLogoutCallback
2286
- : never
2286
+ : never,
2287
2287
  ) {
2288
2288
  const prop = (event + 'Callbacks') as T extends 'checkUsername'
2289
2289
  ? 'checkUsernameCallbacks'
@@ -2324,7 +2324,7 @@ export default class User extends AbleObject<UserData> {
2324
2324
  ? TilmeldBeforeLogoutCallback
2325
2325
  : T extends 'afterLogout'
2326
2326
  ? TilmeldAfterLogoutCallback
2327
- : never
2327
+ : never,
2328
2328
  ) {
2329
2329
  const prop = (event + 'Callbacks') as T extends 'checkUsername'
2330
2330
  ? 'checkUsernameCallbacks'
package/src/conf/d.ts CHANGED
@@ -237,7 +237,7 @@ export interface Config {
237
237
  jwtBuilder: (
238
238
  config: Config,
239
239
  user: User & UserData,
240
- switchToken?: boolean
240
+ switchToken?: boolean,
241
241
  ) => string;
242
242
  /**
243
243
  * Function to verify that a JWT was signed with the secret key, validate its
@@ -251,7 +251,7 @@ export interface Config {
251
251
  jwtExtract: (
252
252
  config: Config,
253
253
  token: string,
254
- xsrfToken?: string
254
+ xsrfToken?: string,
255
255
  ) => { guid: string; issued: Date; expire: Date } | null;
256
256
  /**
257
257
  * The absolute path to the email template directory. Used by the default
@@ -268,7 +268,7 @@ export interface Config {
268
268
  configEmail: (
269
269
  tilmeld: Tilmeld,
270
270
  options: EmailOptions,
271
- user: User & UserData
271
+ user: User & UserData,
272
272
  ) => Promise<EmailConfig>;
273
273
  /**
274
274
  * Send an email to a user. Uses `email-templates` by default.
@@ -298,7 +298,7 @@ export interface Config {
298
298
  sendEmail: (
299
299
  tilmeld: Tilmeld,
300
300
  options: EmailOptions,
301
- user: User & UserData
301
+ user: User & UserData,
302
302
  ) => Promise<boolean>;
303
303
  /**
304
304
  * The address you'd like to receive a notification of registered users, if
@@ -69,7 +69,7 @@ export default {
69
69
  xsrfToken: 'TILMELDXSRF-' + nanoid(),
70
70
  },
71
71
  secret,
72
- { expiresIn: switchToken ? config.jwtSwitchExpire : config.jwtExpire }
72
+ { expiresIn: switchToken ? config.jwtSwitchExpire : config.jwtExpire },
73
73
  );
74
74
  },
75
75
  jwtExtract: (config, token, xsrfToken?) => {
@@ -129,14 +129,14 @@ export default {
129
129
  },
130
130
  sendEmail: async (tilmeld, options, user) => {
131
131
  const email = new Email(
132
- await tilmeld.config.configEmail(tilmeld, options, user)
132
+ await tilmeld.config.configEmail(tilmeld, options, user),
133
133
  );
134
134
  try {
135
135
  const result = await email.send({
136
136
  ...options,
137
137
  template: path.join(
138
138
  tilmeld.config.emailTemplateDir,
139
- options.template ?? '.'
139
+ options.template ?? '.',
140
140
  ),
141
141
  locals: {
142
142
  // System
@@ -206,13 +206,13 @@ export default {
206
206
  name: 'control characters',
207
207
  invert: true,
208
208
  })
209
- .max(256)
209
+ .max(256),
210
210
  ),
211
211
  defaultPrimary: Joi.boolean(),
212
212
  defaultSecondary: Joi.boolean(),
213
213
  unverifiedSecondary: Joi.boolean(),
214
214
  }),
215
- 'Invalid Group: '
215
+ 'Invalid Group: ',
216
216
  );
217
217
  },
218
218
  validatorUser: (user) => {
@@ -275,7 +275,7 @@ export default {
275
275
  name: 'control characters',
276
276
  invert: true,
277
277
  })
278
- .max(256)
278
+ .max(256),
279
279
  ),
280
280
  inheritAbilities: Joi.boolean(),
281
281
  secret: Joi.string()
@@ -323,7 +323,7 @@ export default {
323
323
  .max(40)
324
324
  .pattern(/^[A-Z234567]+$/, 'base32 encoded unpadded'),
325
325
  }),
326
- 'Invalid User: '
326
+ 'Invalid User: ',
327
327
  );
328
328
  },
329
329
  } as Config;
@@ -11,36 +11,36 @@ export default {
11
11
  TilmeldAccessLevels.NO_ACCESS,
12
12
  TilmeldAccessLevels.READ_ACCESS,
13
13
  TilmeldAccessLevels.WRITE_ACCESS,
14
- TilmeldAccessLevels.FULL_ACCESS
14
+ TilmeldAccessLevels.FULL_ACCESS,
15
15
  ),
16
16
  acGroup: Joi.number().valid(
17
17
  TilmeldAccessLevels.NO_ACCESS,
18
18
  TilmeldAccessLevels.READ_ACCESS,
19
19
  TilmeldAccessLevels.WRITE_ACCESS,
20
- TilmeldAccessLevels.FULL_ACCESS
20
+ TilmeldAccessLevels.FULL_ACCESS,
21
21
  ),
22
22
  acOther: Joi.number().valid(
23
23
  TilmeldAccessLevels.NO_ACCESS,
24
24
  TilmeldAccessLevels.READ_ACCESS,
25
25
  TilmeldAccessLevels.WRITE_ACCESS,
26
- TilmeldAccessLevels.FULL_ACCESS
26
+ TilmeldAccessLevels.FULL_ACCESS,
27
27
  ),
28
28
  acRead: Joi.array().items(
29
29
  Joi.alternatives().try(
30
30
  Joi.object().instance(User),
31
- Joi.object().instance(Group)
32
- )
31
+ Joi.object().instance(Group),
32
+ ),
33
33
  ),
34
34
  acWrite: Joi.array().items(
35
35
  Joi.alternatives().try(
36
36
  Joi.object().instance(User),
37
- Joi.object().instance(Group)
38
- )
37
+ Joi.object().instance(Group),
38
+ ),
39
39
  ),
40
40
  acFull: Joi.array().items(
41
41
  Joi.alternatives().try(
42
42
  Joi.object().instance(User),
43
- Joi.object().instance(Group)
44
- )
43
+ Joi.object().instance(Group),
44
+ ),
45
45
  ),
46
46
  };