@nymphjs/tilmeld-client 1.0.0-beta.15 → 1.0.0-beta.151

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.
@@ -1,8 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const client_1 = require("@nymphjs/client");
4
- let currentToken = null;
5
- class User extends client_1.Entity {
1
+ import { Entity } from '@nymphjs/client';
2
+ export class User extends Entity {
3
+ static stores = new WeakMap();
4
+ // The name of the server class
5
+ static class = 'User';
6
6
  static init(nymph) {
7
7
  let store = {
8
8
  registerCallbacks: [],
@@ -22,18 +22,6 @@ class User extends client_1.Entity {
22
22
  store.removeNymphResponseListener = nymph.on('response', (response) => this.handleToken(response));
23
23
  this.handleToken();
24
24
  }
25
- constructor(guid) {
26
- super(guid);
27
- if (guid == null) {
28
- this.$data.enabled = true;
29
- this.$data.abilities = [];
30
- this.$data.groups = [];
31
- this.$data.inheritAbilities = true;
32
- }
33
- }
34
- static async factory(guid) {
35
- return (await super.factory(guid));
36
- }
37
25
  static async factoryUsername(username) {
38
26
  const entity = new this();
39
27
  if (username != null) {
@@ -49,27 +37,46 @@ class User extends client_1.Entity {
49
37
  }
50
38
  return entity;
51
39
  }
52
- static factorySync(guid) {
53
- return super.factorySync(guid);
40
+ static async getDomainUsers(domain, options) {
41
+ return await this.serverCallStatic('getDomainUsers', [domain, options]);
42
+ }
43
+ constructor() {
44
+ super();
45
+ this.enabled = true;
46
+ this.abilities = [];
47
+ this.groups = [];
48
+ this.inheritAbilities = true;
49
+ this.$markClean();
54
50
  }
55
51
  async $checkUsername() {
56
- return await this.$serverCall('$checkUsername', [], true);
52
+ return await this.$serverCall('$checkUsername', [], {
53
+ pushState: true,
54
+ });
57
55
  }
58
56
  async $checkEmail() {
59
- return await this.$serverCall('$checkEmail', [], true);
57
+ return await this.$serverCall('$checkEmail', [], {
58
+ pushState: true,
59
+ });
60
60
  }
61
61
  async $checkPhone() {
62
- return await this.$serverCall('$checkPhone', [], true);
62
+ return await this.$serverCall('$checkPhone', [], {
63
+ pushState: true,
64
+ });
63
65
  }
64
66
  async $getAvatar() {
65
- return await this.$serverCall('$getAvatar', [], true);
67
+ return await this.$serverCall('$getAvatar', [], {
68
+ pushState: true,
69
+ });
66
70
  }
67
71
  async $register(data) {
68
72
  const store = User.stores.get(this.$nymph);
69
73
  if (store == null) {
70
74
  throw new Error('This user class was never initialized with an instance of Nymph');
71
75
  }
72
- const response = await this.$serverCall('$register', [data]);
76
+ const response = await this.$serverCall('$register', [data], {
77
+ pushState: true,
78
+ pullState: true,
79
+ });
73
80
  if (response.result) {
74
81
  for (let i = 0; i < store.registerCallbacks.length; i++) {
75
82
  store.registerCallbacks[i] && store.registerCallbacks[i](this);
@@ -83,6 +90,20 @@ class User extends client_1.Entity {
83
90
  }
84
91
  return response;
85
92
  }
93
+ async $switchUser(data) {
94
+ const store = User.stores.get(this.$nymph);
95
+ if (store == null) {
96
+ throw new Error('This user class was never initialized with an instance of Nymph');
97
+ }
98
+ const response = await this.$serverCall('$switchUser', [data]);
99
+ if (response.result) {
100
+ this.constructor.handleToken();
101
+ for (let i = 0; i < store.loginCallbacks.length; i++) {
102
+ store.loginCallbacks[i] && store.loginCallbacks[i](this);
103
+ }
104
+ }
105
+ return response;
106
+ }
86
107
  async $logout() {
87
108
  const store = User.stores.get(this.$nymph);
88
109
  if (store == null) {
@@ -98,10 +119,33 @@ class User extends client_1.Entity {
98
119
  return response;
99
120
  }
100
121
  async $gatekeeper(ability) {
101
- return await this.$serverCall('$gatekeeper', [ability], true);
122
+ return await this.$serverCall('$gatekeeper', [ability]);
102
123
  }
103
124
  async $changePassword(data) {
104
- return await this.$serverCall('$changePassword', [data]);
125
+ return await this.$serverCall('$changePassword', [data], {
126
+ pullState: true,
127
+ });
128
+ }
129
+ async $revokeCurrentTokens(data) {
130
+ return await this.$serverCall('$revokeCurrentTokens', [data], {
131
+ pullState: true,
132
+ });
133
+ }
134
+ async $hasTOTPSecret() {
135
+ return await this.$serverCall('$hasTOTPSecret', []);
136
+ }
137
+ async $getNewTOTPSecret() {
138
+ return await this.$serverCall('$getNewTOTPSecret', []);
139
+ }
140
+ async $saveTOTPSecret(data) {
141
+ return await this.$serverCall('$saveTOTPSecret', [data], {
142
+ pullState: true,
143
+ });
144
+ }
145
+ async $removeTOTPSecret(data) {
146
+ return await this.$serverCall('$removeTOTPSecret', [...(data ? [data] : [])], {
147
+ pullState: true,
148
+ });
105
149
  }
106
150
  static async current(returnObjectIfNotExist) {
107
151
  const currentUser = await this.serverCallStatic('current', [false]);
@@ -148,40 +192,64 @@ class User extends client_1.Entity {
148
192
  return await store.clientConfigPromise;
149
193
  }
150
194
  static handleToken(response) {
195
+ const store = User.stores.get(this.nymph);
196
+ if (store == null) {
197
+ throw new Error('This user class was never initialized with an instance of Nymph');
198
+ }
151
199
  let token = null;
200
+ let switchToken = null;
201
+ let hasNoCookie = typeof document === 'undefined' || typeof document.cookie === 'undefined';
152
202
  const authCookiePattern = /(?:(?:^|.*;\s*)TILMELDAUTH\s*=\s*([^;]*).*$)|^.*$/;
203
+ const switchCookiePattern = /(?:(?:^|.*;\s*)TILMELDSWITCH\s*=\s*([^;]*).*$)|^.*$/;
153
204
  if (response && response.headers.has('X-TILMELDAUTH')) {
154
- token = response.headers.get('X-TILMELDAUTH');
205
+ token = response.headers.get('X-TILMELDAUTH') || null;
206
+ switchToken = response.headers.get('X-TILMELDSWITCH') || null;
155
207
  }
156
208
  else if (typeof document !== 'undefined' &&
157
209
  document.cookie.match(authCookiePattern)) {
158
- token = document.cookie.replace(authCookiePattern, '$1');
210
+ token = document.cookie.replace(authCookiePattern, '$1') || null;
211
+ switchToken = document.cookie.replace(switchCookiePattern, '$1') || null;
159
212
  }
160
213
  else {
161
214
  return;
162
215
  }
163
- if (currentToken !== token) {
164
- if (token == null || token === '') {
165
- if (currentToken != null) {
166
- this.nymph.setXsrfToken(null);
216
+ if (store.currentToken != token || store.switchToken != switchToken) {
217
+ if (token == null) {
218
+ if (store.currentToken != null) {
219
+ delete this.nymph.headers['X-Xsrf-Token'];
220
+ delete this.nymph.headers['X-TILMELDAUTH'];
221
+ delete this.nymph.headers['X-TILMELDSWITCH'];
167
222
  if (this.nymph.pubsub) {
168
- this.nymph.pubsub.setToken(null);
223
+ this.nymph.pubsub.authenticate(null);
169
224
  }
170
- currentToken = null;
225
+ // Make sure entities requested under a previous user are not reused.
226
+ this.nymph.clearCaches();
227
+ delete store.currentToken;
228
+ delete store.switchToken;
171
229
  }
172
230
  }
173
231
  else {
174
232
  const base64Url = token.split('.')[1];
175
233
  const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
176
234
  const json = typeof atob === 'undefined'
177
- ? Buffer.from(base64, 'base64').toString('binary')
178
- : atob(base64);
235
+ ? Buffer.from(base64, 'base64').toString('binary') // node
236
+ : atob(base64); // browser
179
237
  const jwt = JSON.parse(json);
180
- this.nymph.setXsrfToken(jwt.xsrfToken);
238
+ this.nymph.headers['X-Xsrf-Token'] = jwt.xsrfToken;
239
+ if (hasNoCookie) {
240
+ this.nymph.headers['X-TILMELDAUTH'] = token;
241
+ delete this.nymph.headers['X-TILMELDSWITCH'];
242
+ if (switchToken != null) {
243
+ this.nymph.headers['X-TILMELDSWITCH'] = switchToken;
244
+ }
245
+ }
181
246
  if (this.nymph.pubsub) {
182
- this.nymph.pubsub.setToken(token);
247
+ this.nymph.pubsub.authenticate(token, switchToken);
183
248
  }
184
- currentToken = token;
249
+ // Make sure entities requested under a previous user are not reused.
250
+ this.nymph.clearCaches();
251
+ store.currentToken = token;
252
+ store.switchToken = switchToken ?? undefined;
185
253
  }
186
254
  }
187
255
  }
@@ -194,6 +262,7 @@ class User extends client_1.Entity {
194
262
  if (!(prop in store)) {
195
263
  throw new Error('Invalid event type.');
196
264
  }
265
+ // @ts-ignore: The callback should always be the right type here.
197
266
  store[prop].push(callback);
198
267
  return () => this.off(event, callback);
199
268
  }
@@ -206,14 +275,13 @@ class User extends client_1.Entity {
206
275
  if (!(prop in store)) {
207
276
  return false;
208
277
  }
278
+ // @ts-ignore: The callback should always be the right type here.
209
279
  const i = store[prop].indexOf(callback);
210
280
  if (i > -1) {
281
+ // @ts-ignore: The callback should always be the right type here.
211
282
  store[prop].splice(i, 1);
212
283
  }
213
284
  return true;
214
285
  }
215
286
  }
216
- exports.default = User;
217
- User.stores = new WeakMap();
218
- User.class = 'User';
219
287
  //# sourceMappingURL=User.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"User.js","sourceRoot":"","sources":["../src/User.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAAE,MAAM,iBAAiB,CAAC;AA2JhD,MAAM,OAAO,IAAK,SAAQ,MAAgB;IAC9B,MAAM,CAAC,MAAM,GAAG,IAAI,OAAO,EAAwB,CAAC;IAE9D,+BAA+B;IACxB,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC;IAEtB,MAAM,CAAC,IAAI,CAAC,KAAY;QAC7B,IAAI,KAAK,GAAkB;YACzB,iBAAiB,EAAE,EAAE;YACrB,cAAc,EAAE,EAAE;YAClB,eAAe,EAAE,EAAE;SACpB,CAAC;QAEF,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YAExC,IAAI,QAAQ,EAAE,CAAC;gBACb,KAAK,GAAG,QAAQ,CAAC;YACnB,CAAC;QACH,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAE9B,IAAI,KAAK,CAAC,2BAA2B,EAAE,CAAC;YACtC,KAAK,CAAC,2BAA2B,EAAE,CAAC;QACtC,CAAC;QACD,KAAK,CAAC,2BAA2B,GAAG,KAAK,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE,EAAE,CACpE,IAAI,C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,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CACb,iEAAiE,CAClE,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,GAAG,CAAC,KAAK,GAAG,WAAW,CAMpB,CAAC;QACd,IAAI,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;YACrB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,iEAAiE;QACjE,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACxC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YACX,iEAAiE;YACjE,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC3B,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,58 @@
1
+ import type { User as UserClass } from './User.js';
2
+ import type { ClientConfig, CurrentUserData } from './User.js';
3
+ export type RegistrationDetails = {
4
+ /**
5
+ * New user's username.
6
+ */
7
+ username: string;
8
+ /**
9
+ * New user's password.
10
+ */
11
+ password: string;
12
+ /**
13
+ * Repeat the password.
14
+ */
15
+ password2: string;
16
+ /**
17
+ * Whether the username passed verification.
18
+ */
19
+ usernameVerified: boolean;
20
+ /**
21
+ * The new user's email address.
22
+ */
23
+ email?: string;
24
+ /**
25
+ * The new user's given name.
26
+ */
27
+ nameFirst?: string;
28
+ /**
29
+ * The new user's surname.
30
+ */
31
+ nameLast?: string;
32
+ /**
33
+ * The new user's phone number.
34
+ */
35
+ phone?: string;
36
+ /**
37
+ * Additional data to be included in the request.
38
+ */
39
+ additionalData?: {
40
+ [k: string]: any;
41
+ };
42
+ };
43
+ export declare class NeedTOTPError extends Error {
44
+ }
45
+ export declare function login(User: typeof UserClass, username: string, password: string, code?: string, additionalData?: {
46
+ [k: string]: any;
47
+ }): Promise<{
48
+ message: string;
49
+ user?: UserClass & CurrentUserData;
50
+ }>;
51
+ export declare function register(User: typeof UserClass, userDetails: RegistrationDetails, clientConfig?: ClientConfig): Promise<{
52
+ loggedin: boolean;
53
+ message: string;
54
+ user?: UserClass & CurrentUserData;
55
+ }>;
56
+ export declare function checkUsername(User: typeof UserClass, username: string, clientConfig?: ClientConfig): Promise<{
57
+ message: string;
58
+ }>;
@@ -1,7 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkUsername = exports.register = exports.login = void 0;
4
- async function login(User, username, password, additionalData) {
1
+ export class NeedTOTPError extends Error {
2
+ }
3
+ export async function login(User, username, password, code, additionalData) {
5
4
  if (username === '') {
6
5
  throw new Error('You need to enter a username.');
7
6
  }
@@ -9,22 +8,28 @@ async function login(User, username, password, additionalData) {
9
8
  throw new Error('You need to enter a password');
10
9
  }
11
10
  try {
12
- const { result, ...response } = await User.loginUser({
11
+ const { result, needTOTP, ...response } = await User.loginUser({
13
12
  username,
14
13
  password,
14
+ code,
15
15
  ...(additionalData ? { additionalData } : {}),
16
16
  });
17
17
  if (!result) {
18
+ if (needTOTP) {
19
+ throw new NeedTOTPError(response.message);
20
+ }
18
21
  throw new Error(response.message);
19
22
  }
20
23
  return response;
21
24
  }
22
25
  catch (e) {
26
+ if (e instanceof NeedTOTPError) {
27
+ throw e;
28
+ }
23
29
  throw new Error(e?.message ?? 'An error occurred.');
24
30
  }
25
31
  }
26
- exports.login = login;
27
- async function register(User, userDetails, clientConfig) {
32
+ export async function register(User, userDetails, clientConfig) {
28
33
  if (userDetails.username === '') {
29
34
  throw new Error('You need to enter a username.');
30
35
  }
@@ -37,20 +42,23 @@ async function register(User, userDetails, clientConfig) {
37
42
  if (userDetails.password === '') {
38
43
  throw new Error('You need to enter a password');
39
44
  }
45
+ // Create a new user.
40
46
  let user = User.factorySync();
41
47
  user.username = userDetails.username;
42
48
  const config = clientConfig || (await User.getClientConfig());
43
- if (config.emailUsernames) {
44
- user.email = userDetails.username;
45
- }
46
- else if (config.regFields.indexOf('email') !== -1) {
47
- user.email = userDetails.email;
49
+ if (config.regFields.includes('email')) {
50
+ if (config.emailUsernames) {
51
+ user.email = userDetails.username;
52
+ }
53
+ else {
54
+ user.email = userDetails.email;
55
+ }
48
56
  }
49
- if (config.regFields.indexOf('name') !== -1) {
57
+ if (config.regFields.includes('name')) {
50
58
  user.nameFirst = userDetails.nameFirst;
51
59
  user.nameLast = userDetails.nameLast;
52
60
  }
53
- if (config.regFields.indexOf('phone') !== -1) {
61
+ if (config.regFields.includes('phone')) {
54
62
  user.phone = userDetails.phone;
55
63
  }
56
64
  try {
@@ -69,8 +77,7 @@ async function register(User, userDetails, clientConfig) {
69
77
  throw new Error(e?.message ?? 'An error occurred.');
70
78
  }
71
79
  }
72
- exports.register = register;
73
- async function checkUsername(User, username, clientConfig) {
80
+ export async function checkUsername(User, username, clientConfig) {
74
81
  let user = User.factorySync();
75
82
  user.username = username;
76
83
  const config = clientConfig || (await User.getClientConfig());
@@ -88,5 +95,4 @@ async function checkUsername(User, username, clientConfig) {
88
95
  throw new Error(e?.message ?? 'An error occurred.');
89
96
  }
90
97
  }
91
- exports.checkUsername = checkUsername;
92
98
  //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AA0CA,MAAM,OAAO,aAAc,SAAQ,KAAK;CAAG;AAE3C,MAAM,CAAC,KAAK,UAAU,KAAK,CACzB,IAAsB,EACtB,QAAgB,EAChB,QAAgB,EAChB,IAAa,EACb,cAAqC;IAErC,IAAI,QAAQ,KAAK,EAAE,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACnD,CAAC;IACD,IAAI,QAAQ,KAAK,EAAE,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAClD,CAAC;IAED,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,QAAQ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E,IAAI,EAAE,CAAC;IAC/B,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,CAAC,EAAE,OAAO,IAAI,oBAAoB,CAAC,CAAC;IACtD,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,IAAsB,EACtB,QAAgB,EAChB,YAA2B;IAE3B,IAAI,IAAI,GAAG,IAAI,CAAC,WAAW,EAAiC,CAAC;IAC7D,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAEzB,MAAM,MAAM,GAAG,YAAY,IAAI,CAAC,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC;IAC9D,IAAI,MAAM,CAAC,cAAc,EAAE,CAAC;QAC1B,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC;IACxB,CAAC;IAED,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;QAC5D,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACpC,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,CAAC,EAAE,OAAO,IAAI,oBAAoB,CAAC,CAAC;IACtD,CAAC;AACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './Group.js';
2
+ export * from './helpers.js';
3
+ export * from './LDAPSource.js';
4
+ export * from './Tilmeld.types.js';
5
+ export * from './User.js';
package/dist/index.js CHANGED
@@ -1,2 +1,6 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nymphjs/client")):"function"==typeof define&&define.amd?define(["@nymphjs/client"],t):"object"==typeof exports?exports["@nymphjs/tilmeld-client"]=t(require("@nymphjs/client")):e["@nymphjs/tilmeld-client"]=t(e["@nymphjs/client"])}(this,(e=>(()=>{"use strict";var t={848:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});const s=r(778);class n extends s.Entity{constructor(e){super(e),null==e&&(this.$data.enabled=!0,this.$data.abilities=[])}static async factory(e){return await super.factory(e)}static factorySync(e){return super.factorySync(e)}async $checkGroupname(){return await this.$serverCall("$checkGroupname",[],!0)}async $checkEmail(){return await this.$serverCall("$checkEmail",[],!0)}async $getAvatar(){return await this.$serverCall("$getAvatar",[],!0)}async $getChildren(){return await this.$serverCall("$getChildren",[],!0)}async $getDescendants(e=!1){return await this.$serverCall("$getDescendants",[e],!0)}async $getLevel(){return await this.$serverCall("$getLevel",[],!0)}async $isDescendant(e){return await this.$serverCall("$isDescendant",[e],!0)}static async getPrimaryGroups(e,t){return await this.serverCallStatic("getPrimaryGroups",[{options:e,class:this.class},t])}static async getSecondaryGroups(e,t){return await this.serverCallStatic("getSecondaryGroups",[{options:e,class:this.class},t])}}t.default=n,n.class="Group"},178:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});const s=r(778);let n=null;class a extends s.Entity{static init(e){let t={registerCallbacks:[],loginCallbacks:[],logoutCallbacks:[]};if(a.stores.has(e)){const r=a.stores.get(e);r&&(t=r)}a.stores.set(e,t),t.removeNymphResponseListener&&t.removeNymphResponseListener(),t.removeNymphResponseListener=e.on("response",(e=>this.handleToken(e))),this.handleToken()}constructor(e){super(e),null==e&&(this.$data.enabled=!0,this.$data.abilities=[],this.$data.groups=[],this.$data.inheritAbilities=!0)}static async factory(e){return await super.factory(e)}static async factoryUsername(e){const t=new this;if(null!=e){const t=await this.nymph.getEntity({class:this},{type:"&",ilike:["username",e.replace(/([\\%_])/g,(e=>`\\${e}`))]});if(null!=t)return t}return t}static factorySync(e){return super.factorySync(e)}async $checkUsername(){return await this.$serverCall("$checkUsername",[],!0)}async $checkEmail(){return await this.$serverCall("$checkEmail",[],!0)}async $checkPhone(){return await this.$serverCall("$checkPhone",[],!0)}async $getAvatar(){return await this.$serverCall("$getAvatar",[],!0)}async $register(e){const t=a.stores.get(this.$nymph);if(null==t)throw new Error("This user class was never initialized with an instance of Nymph");const r=await this.$serverCall("$register",[e]);if(r.result)for(let e=0;e<t.registerCallbacks.length;e++)t.registerCallbacks[e]&&t.registerCallbacks[e](this);if(r.loggedin){this.constructor.handleToken();for(let e=0;e<t.loginCallbacks.length;e++)t.loginCallbacks[e]&&t.loginCallbacks[e](this)}return r}async $logout(){const e=a.stores.get(this.$nymph);if(null==e)throw new Error("This user class was never initialized with an instance of Nymph");const t=await this.$serverCall("$logout",[]);if(t.result){this.constructor.handleToken();for(let t=0;t<e.logoutCallbacks.length;t++)e.logoutCallbacks[t]&&e.logoutCallbacks[t](this)}return t}async $gatekeeper(e){return await this.$serverCall("$gatekeeper",[e],!0)}async $changePassword(e){return await this.$serverCall("$changePassword",[e])}static async current(e){const t=await this.serverCallStatic("current",[!1]);return null==t?e?this.factorySync():null:t}static async loginUser(e){const t=a.stores.get(this.nymph);if(null==t)throw new Error("This user class was never initialized with an instance of Nymph");const r=await this.serverCallStatic("loginUser",[e]);if(r.result){this.handleToken();for(let e=0;e<t.loginCallbacks.length;e++)t.loginCallbacks[e]&&t.loginCallbacks[e](r.user)}return r}static async sendRecovery(e){return await this.serverCallStatic("sendRecovery",[e])}static async recover(e){return await this.serverCallStatic("recover",[e])}static async getClientConfig(){const e=a.stores.get(this.nymph);if(null==e)throw new Error("This user class was never initialized with an instance of Nymph");return e.clientConfig?e.clientConfig:(e.clientConfigPromise||(e.clientConfigPromise=this.serverCallStatic("getClientConfig",[]).then((t=>(e.clientConfig=t,e.clientConfigPromise=void 0,t)))),await e.clientConfigPromise)}static handleToken(e){let t=null;const r=/(?:(?:^|.*;\s*)TILMELDAUTH\s*=\s*([^;]*).*$)|^.*$/;if(e&&e.headers.has("X-TILMELDAUTH"))t=e.headers.get("X-TILMELDAUTH");else{if("undefined"==typeof document||!document.cookie.match(r))return;t=document.cookie.replace(r,"$1")}if(n!==t)if(null==t||""===t)null!=n&&(this.nymph.setXsrfToken(null),this.nymph.pubsub&&this.nymph.pubsub.setToken(null),n=null);else{const e=t.split(".")[1].replace(/-/g,"+").replace(/_/g,"/"),r="undefined"==typeof atob?Buffer.from(e,"base64").toString("binary"):atob(e),s=JSON.parse(r);this.nymph.setXsrfToken(s.xsrfToken),this.nymph.pubsub&&this.nymph.pubsub.setToken(t),n=t}}static on(e,t){const r=a.stores.get(this.nymph);if(null==r)throw new Error("This user class was never initialized with an instance of Nymph");const s=e+"Callbacks";if(!(s in r))throw new Error("Invalid event type.");return r[s].push(t),()=>this.off(e,t)}static off(e,t){const r=a.stores.get(this.nymph);if(null==r)throw new Error("This user class was never initialized with an instance of Nymph");const s=e+"Callbacks";if(!(s in r))return!1;const n=r[s].indexOf(t);return n>-1&&r[s].splice(n,1),!0}}t.default=a,a.stores=new WeakMap,a.class="User"},13:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.checkUsername=t.register=t.login=void 0,t.login=async function(e,t,r,s){if(""===t)throw new Error("You need to enter a username.");if(""===r)throw new Error("You need to enter a password");try{const{result:n,...a}=await e.loginUser({username:t,password:r,...s?{additionalData:s}:{}});if(!n)throw new Error(a.message);return a}catch(e){throw new Error(e?.message??"An error occurred.")}},t.register=async function(e,t,r){if(""===t.username)throw new Error("You need to enter a username.");if(!t.usernameVerified)throw new Error("The username you entered is not valid.");if(t.password!==t.password2)throw new Error("Your passwords do not match.");if(""===t.password)throw new Error("You need to enter a password");let s=e.factorySync();s.username=t.username;const n=r||await e.getClientConfig();n.emailUsernames?s.email=t.username:-1!==n.regFields.indexOf("email")&&(s.email=t.email),-1!==n.regFields.indexOf("name")&&(s.nameFirst=t.nameFirst,s.nameLast=t.nameLast),-1!==n.regFields.indexOf("phone")&&(s.phone=t.phone);try{const{result:e,...r}=await s.$register({password:t.password,...t.additionalData?{additionalData:t.additionalData}:{}});if(!e)throw new Error(r.message);return{...r,user:s}}catch(e){throw new Error(e?.message??"An error occurred.")}},t.checkUsername=async function(e,t,r){let s=e.factorySync();s.username=t,(r||await e.getClientConfig()).emailUsernames&&(s.email=t);try{const{result:e,...t}=await s.$checkUsername();if(!e)throw new Error(t.message);return t}catch(e){throw new Error(e?.message??"An error occurred.")}}},568:function(e,t,r){var s=this&&this.__createBinding||(Object.create?function(e,t,r,s){void 0===s&&(s=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,s,n)}:function(e,t,r,s){void 0===s&&(s=r),e[s]=t[r]}),n=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||s(t,e,r)},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.User=t.Group=void 0,n(r(848),t);const i=a(r(848));t.Group=i.default,n(r(13),t),n(r(178),t);const o=a(r(178));t.User=o.default},778:t=>{t.exports=e}},r={};return function e(s){var n=r[s];if(void 0!==n)return n.exports;var a=r[s]={exports:{}};return t[s].call(a.exports,a,a.exports,e),a.exports}(568)})()));
1
+ export * from './Group.js';
2
+ export * from './helpers.js';
3
+ export * from './LDAPSource.js';
4
+ export * from './Tilmeld.types.js';
5
+ export * from './User.js';
2
6
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,EAAQG,QAAQ,oBACR,mBAAXC,QAAyBA,OAAOC,IAC9CD,OAAO,CAAC,mBAAoBJ,GACF,iBAAZC,QACdA,QAAQ,2BAA6BD,EAAQG,QAAQ,oBAErDJ,EAAK,2BAA6BC,EAAQD,EAAK,oBARjD,CASGO,MAAOC,G,wCCRVC,OAAOC,eAAeR,EAAS,aAAc,CAAES,OAAO,IACtD,MAAMC,EAAW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AAGG,EAAIC,IAC5B,SAAUJ,EAAGC,EAAGC,EAAGC,QACTvD,IAAPuD,IAAkBA,EAAKD,GAC3BF,EAAEG,GAAMF,EAAEC,KAEVQ,EAAgB5H,MAAQA,KAAK4H,cAAiB,SAAST,EAAGxH,GAC1D,IAAK,IAAIkI,KAAKV,EAAa,YAANU,GAAoB3H,OAAO4H,UAAUC,eAAeC,KAAKrI,EAASkI,IAAIb,EAAgBrH,EAASwH,EAAGU,IAEvHI,EAAmBjI,MAAQA,KAAKiI,iBAAoB,SAAUC,GAC9D,OAAQA,GAAOA,EAAIV,WAAcU,EAAM,CAAE,QAAWA,IAExDhI,OAAOC,eAAeR,EAAS,aAAc,CAAES,OAAO,IACtDT,EAAQ4B,KAAO5B,EAAQW,WAAQ,EAC/BsH,EAAa,EAAQ,KAAYjI,GACjC,MAAMwI,EAAUF,EAAgB,EAAQ,MACxCtI,EAAQW,MAAQ6H,EAAQC,QACxBR,EAAa,EAAQ,IAAcjI,GACnCiI,EAAa,EAAQ,KAAWjI,GAChC,MAAM0I,EAASJ,EAAgB,EAAQ,MACvCtI,EAAQ4B,KAAO8G,EAAOD,S,QC1BtBxI,EAAOD,QAAUM,ICCbqI,EAA2B,G,OAG/B,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqB1E,IAAjB2E,EACH,OAAOA,EAAa9I,QAGrB,IAAIC,EAAS0I,EAAyBE,GAAY,CAGjD7I,QAAS,IAOV,OAHA+I,EAAoBF,GAAUR,KAAKpI,EAAOD,QAASC,EAAQA,EAAOD,QAAS4I,GAGpE3I,EAAOD,QClBW4I,CAAoB,M","sources":["webpack://@nymphjs/tilmeld-client/webpack/universalModuleDefinition","webpack://@nymphjs/tilmeld-client/./lib/Group.js","webpack://@nymphjs/tilmeld-client/./lib/User.js","webpack://@nymphjs/tilmeld-client/./lib/helpers.js","webpack://@nymphjs/tilmeld-client/./lib/index.js","webpack://@nymphjs/tilmeld-client/external umd \"@nymphjs/client\"","webpack://@nymphjs/tilmeld-client/webpack/bootstrap","webpack://@nymphjs/tilmeld-client/webpack/startup"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"@nymphjs/client\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"@nymphjs/client\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"@nymphjs/tilmeld-client\"] = factory(require(\"@nymphjs/client\"));\n\telse\n\t\troot[\"@nymphjs/tilmeld-client\"] = factory(root[\"@nymphjs/client\"]);\n})(this, (__WEBPACK_EXTERNAL_MODULE__778__) => {\nreturn ","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst client_1 = require(\"@nymphjs/client\");\nclass Group extends client_1.Entity {\n constructor(guid) {\n super(guid);\n if (guid == null) {\n this.$data.enabled = true;\n this.$data.abilities = [];\n }\n }\n static async factory(guid) {\n return (await super.factory(guid));\n }\n static factorySync(guid) {\n return super.factorySync(guid);\n }\n async $checkGroupname() {\n return await this.$serverCall('$checkGroupname', [], true);\n }\n async $checkEmail() {\n return await this.$serverCall('$checkEmail', [], true);\n }\n async $getAvatar() {\n return await this.$serverCall('$getAvatar', [], true);\n }\n async $getChildren() {\n return await this.$serverCall('$getChildren', [], true);\n }\n async $getDescendants(andSelf = false) {\n return await this.$serverCall('$getDescendants', [andSelf], true);\n }\n async $getLevel() {\n return await this.$serverCall('$getLevel', [], true);\n }\n async $isDescendant(givenGroup) {\n return await this.$serverCall('$isDescendant', [givenGroup], true);\n }\n static async getPrimaryGroups(options, selectors) {\n return await this.serverCallStatic('getPrimaryGroups', [\n { options, class: this.class },\n selectors,\n ]);\n }\n static async getSecondaryGroups(options, selectors) {\n return await this.serverCallStatic('getSecondaryGroups', [\n { options, class: this.class },\n selectors,\n ]);\n }\n}\nexports.default = Group;\nGroup.class = 'Group';\n//# sourceMappingURL=Group.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst client_1 = require(\"@nymphjs/client\");\nlet currentToken = null;\nclass User extends client_1.Entity {\n static init(nymph) {\n let store = {\n registerCallbacks: [],\n loginCallbacks: [],\n logoutCallbacks: [],\n };\n if (User.stores.has(nymph)) {\n const storeVal = User.stores.get(nymph);\n if (storeVal) {\n store = storeVal;\n }\n }\n User.stores.set(nymph, store);\n if (store.removeNymphResponseListener) {\n store.removeNymphResponseListener();\n }\n store.removeNymphResponseListener = nymph.on('response', (response) => this.handleToken(response));\n this.handleToken();\n }\n constructor(guid) {\n super(guid);\n if (guid == null) {\n this.$data.enabled = true;\n this.$data.abilities = [];\n this.$data.groups = [];\n this.$data.inheritAbilities = true;\n }\n }\n static async factory(guid) {\n return (await super.factory(guid));\n }\n static async factoryUsername(username) {\n const entity = new this();\n if (username != null) {\n const entity = await this.nymph.getEntity({\n class: this,\n }, {\n type: '&',\n ilike: ['username', username.replace(/([\\\\%_])/g, (s) => `\\\\${s}`)],\n });\n if (entity != null) {\n return entity;\n }\n }\n return entity;\n }\n static factorySync(guid) {\n return super.factorySync(guid);\n }\n async $checkUsername() {\n return await this.$serverCall('$checkUsername', [], true);\n }\n async $checkEmail() {\n return await this.$serverCall('$checkEmail', [], true);\n }\n async $checkPhone() {\n return await this.$serverCall('$checkPhone', [], true);\n }\n async $getAvatar() {\n return await this.$serverCall('$getAvatar', [], true);\n }\n async $register(data) {\n const store = User.stores.get(this.$nymph);\n if (store == null) {\n throw new Error('This user class was never initialized with an instance of Nymph');\n }\n const response = await this.$serverCall('$register', [data]);\n if (response.result) {\n for (let i = 0; i < store.registerCallbacks.length; i++) {\n store.registerCallbacks[i] && store.registerCallbacks[i](this);\n }\n }\n if (response.loggedin) {\n this.constructor.handleToken();\n for (let i = 0; i < store.loginCallbacks.length; i++) {\n store.loginCallbacks[i] && store.loginCallbacks[i](this);\n }\n }\n return response;\n }\n async $logout() {\n const store = User.stores.get(this.$nymph);\n if (store == null) {\n throw new Error('This user class was never initialized with an instance of Nymph');\n }\n const response = await this.$serverCall('$logout', []);\n if (response.result) {\n this.constructor.handleToken();\n for (let i = 0; i < store.logoutCallbacks.length; i++) {\n store.logoutCallbacks[i] && store.logoutCallbacks[i](this);\n }\n }\n return response;\n }\n async $gatekeeper(ability) {\n return await this.$serverCall('$gatekeeper', [ability], true);\n }\n async $changePassword(data) {\n return await this.$serverCall('$changePassword', [data]);\n }\n static async current(returnObjectIfNotExist) {\n const currentUser = await this.serverCallStatic('current', [false]);\n if (currentUser == null) {\n return returnObjectIfNotExist ? this.factorySync() : null;\n }\n return currentUser;\n }\n static async loginUser(data) {\n const store = User.stores.get(this.nymph);\n if (store == null) {\n throw new Error('This user class was never initialized with an instance of Nymph');\n }\n const response = await this.serverCallStatic('loginUser', [data]);\n if (response.result) {\n this.handleToken();\n for (let i = 0; i < store.loginCallbacks.length; i++) {\n store.loginCallbacks[i] && store.loginCallbacks[i](response.user);\n }\n }\n return response;\n }\n static async sendRecovery(data) {\n return await this.serverCallStatic('sendRecovery', [data]);\n }\n static async recover(data) {\n return await this.serverCallStatic('recover', [data]);\n }\n static async getClientConfig() {\n const store = User.stores.get(this.nymph);\n if (store == null) {\n throw new Error('This user class was never initialized with an instance of Nymph');\n }\n if (store.clientConfig) {\n return store.clientConfig;\n }\n if (!store.clientConfigPromise) {\n store.clientConfigPromise = this.serverCallStatic('getClientConfig', []).then((config) => {\n store.clientConfig = config;\n store.clientConfigPromise = undefined;\n return config;\n });\n }\n return await store.clientConfigPromise;\n }\n static handleToken(response) {\n let token = null;\n const authCookiePattern = /(?:(?:^|.*;\\s*)TILMELDAUTH\\s*=\\s*([^;]*).*$)|^.*$/;\n if (response && response.headers.has('X-TILMELDAUTH')) {\n token = response.headers.get('X-TILMELDAUTH');\n }\n else if (typeof document !== 'undefined' &&\n document.cookie.match(authCookiePattern)) {\n token = document.cookie.replace(authCookiePattern, '$1');\n }\n else {\n return;\n }\n if (currentToken !== token) {\n if (token == null || token === '') {\n if (currentToken != null) {\n this.nymph.setXsrfToken(null);\n if (this.nymph.pubsub) {\n this.nymph.pubsub.setToken(null);\n }\n currentToken = null;\n }\n }\n else {\n const base64Url = token.split('.')[1];\n const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');\n const json = typeof atob === 'undefined'\n ? Buffer.from(base64, 'base64').toString('binary')\n : atob(base64);\n const jwt = JSON.parse(json);\n this.nymph.setXsrfToken(jwt.xsrfToken);\n if (this.nymph.pubsub) {\n this.nymph.pubsub.setToken(token);\n }\n currentToken = token;\n }\n }\n }\n static on(event, callback) {\n const store = User.stores.get(this.nymph);\n if (store == null) {\n throw new Error('This user class was never initialized with an instance of Nymph');\n }\n const prop = (event + 'Callbacks');\n if (!(prop in store)) {\n throw new Error('Invalid event type.');\n }\n store[prop].push(callback);\n return () => this.off(event, callback);\n }\n static off(event, callback) {\n const store = User.stores.get(this.nymph);\n if (store == null) {\n throw new Error('This user class was never initialized with an instance of Nymph');\n }\n const prop = (event + 'Callbacks');\n if (!(prop in store)) {\n return false;\n }\n const i = store[prop].indexOf(callback);\n if (i > -1) {\n store[prop].splice(i, 1);\n }\n return true;\n }\n}\nexports.default = User;\nUser.stores = new WeakMap();\nUser.class = 'User';\n//# sourceMappingURL=User.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.checkUsername = exports.register = exports.login = void 0;\nasync function login(User, username, password, additionalData) {\n if (username === '') {\n throw new Error('You need to enter a username.');\n }\n if (password === '') {\n throw new Error('You need to enter a password');\n }\n try {\n const { result, ...response } = await User.loginUser({\n username,\n password,\n ...(additionalData ? { additionalData } : {}),\n });\n if (!result) {\n throw new Error(response.message);\n }\n return response;\n }\n catch (e) {\n throw new Error(e?.message ?? 'An error occurred.');\n }\n}\nexports.login = login;\nasync function register(User, userDetails, clientConfig) {\n if (userDetails.username === '') {\n throw new Error('You need to enter a username.');\n }\n if (!userDetails.usernameVerified) {\n throw new Error('The username you entered is not valid.');\n }\n if (userDetails.password !== userDetails.password2) {\n throw new Error('Your passwords do not match.');\n }\n if (userDetails.password === '') {\n throw new Error('You need to enter a password');\n }\n let user = User.factorySync();\n user.username = userDetails.username;\n const config = clientConfig || (await User.getClientConfig());\n if (config.emailUsernames) {\n user.email = userDetails.username;\n }\n else if (config.regFields.indexOf('email') !== -1) {\n user.email = userDetails.email;\n }\n if (config.regFields.indexOf('name') !== -1) {\n user.nameFirst = userDetails.nameFirst;\n user.nameLast = userDetails.nameLast;\n }\n if (config.regFields.indexOf('phone') !== -1) {\n user.phone = userDetails.phone;\n }\n try {\n const { result, ...response } = await user.$register({\n password: userDetails.password,\n ...(userDetails.additionalData\n ? { additionalData: userDetails.additionalData }\n : {}),\n });\n if (!result) {\n throw new Error(response.message);\n }\n return { ...response, user };\n }\n catch (e) {\n throw new Error(e?.message ?? 'An error occurred.');\n }\n}\nexports.register = register;\nasync function checkUsername(User, username, clientConfig) {\n let user = User.factorySync();\n user.username = username;\n const config = clientConfig || (await User.getClientConfig());\n if (config.emailUsernames) {\n user.email = username;\n }\n try {\n const { result, ...response } = await user.$checkUsername();\n if (!result) {\n throw new Error(response.message);\n }\n return response;\n }\n catch (e) {\n throw new Error(e?.message ?? 'An error occurred.');\n }\n}\nexports.checkUsername = checkUsername;\n//# sourceMappingURL=helpers.js.map","\"use strict\";\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n}));\nvar __exportStar = (this && this.__exportStar) || function(m, exports) {\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);\n};\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.User = exports.Group = void 0;\n__exportStar(require(\"./Group\"), exports);\nconst Group_1 = __importDefault(require(\"./Group\"));\nexports.Group = Group_1.default;\n__exportStar(require(\"./helpers\"), exports);\n__exportStar(require(\"./User\"), exports);\nconst User_1 = __importDefault(require(\"./User\"));\nexports.User = User_1.default;\n//# sourceMappingURL=index.js.map","module.exports = __WEBPACK_EXTERNAL_MODULE__778__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(568);\n"],"names":["root","factory","exports","module","require","define","amd","this","__WEBPACK_EXTERNAL_MODULE__778__","Object","defineProperty","value","client_1","Group","Entity","constructor","guid","super","$data","enabled","abilities","factorySync","$serverCall","andSelf","givenGroup","options","selectors","serverCallStatic","class","currentToken","User","nymph","store","registerCallbacks","loginCallbacks","logoutCallbacks","stores","has","storeVal","get","set","removeNymphResponseListener","on","response","handleToken","groups","inheritAbilities","username","entity","getEntity","type","ilike","replace","s","data","$nymph","Error","result","i","length","loggedin","ability","returnObjectIfNotExist","currentUser","user","clientConfig","clientConfigPromise","then","config","undefined","token","authCookiePattern","headers","document","cookie","match","setXsrfToken","pubsub","setToken","base64","split","json","atob","Buffer","from","toString","jwt","JSON","parse","xsrfToken","event","callback","prop","push","off","indexOf","splice","WeakMap","checkUsername","register","login","async","password","additionalData","loginUser","message","e","userDetails","usernameVerified","password2","getClientConfig","emailUsernames","email","regFields","nameFirst","nameLast","phone","$register","$checkUsername","__createBinding","create","o","m","k","k2","desc","getOwnPropertyDescriptor","__esModule","writable","configurable","enumerable","__exportStar","p","prototype","hasOwnProperty","call","__importDefault","mod","Group_1","default","User_1","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","__webpack_modules__"],"sourceRoot":""}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAE3B,cAAc,cAAc,CAAC;AAE7B,cAAc,iBAAiB,CAAC;AAEhC,cAAc,oBAAoB,CAAC;AAEnC,cAAc,WAAW,CAAC"}
@@ -0,0 +1 @@
1
+ export {};