@nymphjs/tilmeld-client 1.0.0-beta.11 → 1.0.0-beta.111
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/CHANGELOG.md +437 -0
- package/README.md +2 -2
- package/{lib → dist}/Group.d.ts +40 -5
- package/{lib → dist}/Group.js +21 -16
- package/dist/Group.js.map +1 -0
- package/dist/Tilmeld.types.d.ts +12 -0
- package/dist/Tilmeld.types.js +2 -0
- package/dist/Tilmeld.types.js.map +1 -0
- package/{lib → dist}/User.d.ts +130 -5
- package/{lib → dist}/User.js +76 -32
- package/dist/User.js.map +1 -0
- package/dist/helpers.d.ts +58 -0
- package/{lib → dist}/helpers.js +23 -17
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +257 -0
- package/dist/index.test.js.map +1 -0
- package/jest.config.js +11 -2
- package/package.json +25 -28
- package/src/Group.ts +28 -17
- package/src/Tilmeld.types.ts +13 -0
- package/src/User.ts +153 -57
- package/src/helpers.ts +25 -12
- package/src/index.test.ts +333 -0
- package/src/index.ts +7 -5
- package/tsconfig.json +6 -4
- package/typedoc.json +4 -0
- package/lib/Group.js.map +0 -1
- package/lib/User.js.map +0 -1
- package/lib/helpers.d.ts +0 -46
- package/lib/helpers.js.map +0 -1
- package/lib/index.d.ts +0 -7
- package/lib/index.js +0 -28
- package/lib/index.js.map +0 -1
- package/webpack.config.js +0 -31
package/{lib → dist}/User.d.ts
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Nymph, Entity } from '@nymphjs/client';
|
|
2
|
-
import type Group from './Group';
|
|
3
|
-
import type { AdminGroupData, CurrentGroupData } from './Group';
|
|
2
|
+
import type Group from './Group.js';
|
|
3
|
+
import type { AdminGroupData, CurrentGroupData } from './Group.js';
|
|
4
4
|
export type EventType = 'register' | 'login' | 'logout';
|
|
5
5
|
export type RegisterCallback = (user: User & CurrentUserData) => void;
|
|
6
6
|
export type LoginCallback = (user: User & CurrentUserData) => void;
|
|
@@ -16,34 +16,116 @@ export type ClientConfig = {
|
|
|
16
16
|
unverifiedAccess: boolean;
|
|
17
17
|
};
|
|
18
18
|
export type UserData = {
|
|
19
|
+
/**
|
|
20
|
+
* The user's username.
|
|
21
|
+
*/
|
|
19
22
|
username?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The user's first name.
|
|
25
|
+
*/
|
|
20
26
|
nameFirst?: string;
|
|
27
|
+
/**
|
|
28
|
+
* The user's middle name.
|
|
29
|
+
*/
|
|
21
30
|
nameMiddle?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The user's last name.
|
|
33
|
+
*/
|
|
22
34
|
nameLast?: string;
|
|
35
|
+
/**
|
|
36
|
+
* The user's full name.
|
|
37
|
+
*/
|
|
23
38
|
name?: string;
|
|
39
|
+
/**
|
|
40
|
+
* The user's avatar URL. (Use $getAvatar() to support Gravatar.)
|
|
41
|
+
*/
|
|
24
42
|
avatar?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Whether the user can log in.
|
|
45
|
+
*/
|
|
25
46
|
enabled?: boolean;
|
|
26
47
|
};
|
|
27
48
|
export type CurrentUserData = UserData & {
|
|
49
|
+
/**
|
|
50
|
+
* The abilities granted to the user.
|
|
51
|
+
*/
|
|
28
52
|
abilities?: string[];
|
|
53
|
+
/**
|
|
54
|
+
* The user's email address.
|
|
55
|
+
*/
|
|
29
56
|
email?: string;
|
|
57
|
+
/**
|
|
58
|
+
* The user's telephone number.
|
|
59
|
+
*/
|
|
30
60
|
phone?: string;
|
|
61
|
+
/**
|
|
62
|
+
* The user's primary group.
|
|
63
|
+
*/
|
|
31
64
|
group?: Group & CurrentGroupData;
|
|
65
|
+
/**
|
|
66
|
+
* The user's secondary groups.
|
|
67
|
+
*/
|
|
32
68
|
groups?: (Group & CurrentGroupData)[];
|
|
69
|
+
/**
|
|
70
|
+
* Whether the user should inherit the abilities of his groups.
|
|
71
|
+
*/
|
|
33
72
|
inheritAbilities?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* If the user has changed their email address, this is the new one, awaiting
|
|
75
|
+
* verification.
|
|
76
|
+
*/
|
|
77
|
+
newEmailAddress?: string;
|
|
34
78
|
};
|
|
35
79
|
export type AdminUserData = CurrentUserData & {
|
|
80
|
+
/**
|
|
81
|
+
* The user's primary group.
|
|
82
|
+
*/
|
|
36
83
|
group?: Group & AdminGroupData;
|
|
84
|
+
/**
|
|
85
|
+
* The user's secondary groups.
|
|
86
|
+
*/
|
|
37
87
|
groups?: (Group & AdminGroupData)[];
|
|
88
|
+
/**
|
|
89
|
+
* A verification secret.
|
|
90
|
+
*/
|
|
38
91
|
secret?: string;
|
|
92
|
+
/**
|
|
93
|
+
* The timestamp of when the email address was last changed.
|
|
94
|
+
*/
|
|
39
95
|
emailChangeDate?: number;
|
|
96
|
+
/**
|
|
97
|
+
* An email change proceed secret.
|
|
98
|
+
*/
|
|
40
99
|
newEmailSecret?: string;
|
|
100
|
+
/**
|
|
101
|
+
* The new email address.
|
|
102
|
+
*/
|
|
41
103
|
newEmailAddress?: string;
|
|
104
|
+
/**
|
|
105
|
+
* An email change cancellation secret.
|
|
106
|
+
*/
|
|
42
107
|
cancelEmailSecret?: string;
|
|
108
|
+
/**
|
|
109
|
+
* The old email address.
|
|
110
|
+
*/
|
|
43
111
|
cancelEmailAddress?: string;
|
|
112
|
+
/**
|
|
113
|
+
* A recovery secret.
|
|
114
|
+
*/
|
|
44
115
|
recoverSecret?: string;
|
|
116
|
+
/**
|
|
117
|
+
* The timestamp of when the recovery secret was issued.
|
|
118
|
+
*/
|
|
45
119
|
recoverSecretDate?: number;
|
|
120
|
+
/**
|
|
121
|
+
* Used by admins to change a user's password. Not saved to the database.
|
|
122
|
+
*/
|
|
46
123
|
passwordTemp?: string;
|
|
124
|
+
/**
|
|
125
|
+
* If set, this timestamp is the cutoff point for JWT issue dates. Any token
|
|
126
|
+
* issued before this date will not authenticate the user.
|
|
127
|
+
*/
|
|
128
|
+
revokeTokenDate?: number;
|
|
47
129
|
};
|
|
48
130
|
type InstanceStore = {
|
|
49
131
|
registerCallbacks: RegisterCallback[];
|
|
@@ -52,15 +134,20 @@ type InstanceStore = {
|
|
|
52
134
|
clientConfig?: ClientConfig;
|
|
53
135
|
clientConfigPromise?: Promise<ClientConfig>;
|
|
54
136
|
removeNymphResponseListener?: () => void;
|
|
137
|
+
currentToken?: string;
|
|
55
138
|
};
|
|
56
139
|
export default class User extends Entity<UserData> {
|
|
57
140
|
protected static stores: WeakMap<Nymph, InstanceStore>;
|
|
58
141
|
static class: string;
|
|
59
142
|
static init(nymph: Nymph): void;
|
|
60
|
-
constructor(guid?: string);
|
|
61
|
-
static factory(guid?: string): Promise<User & UserData>;
|
|
62
143
|
static factoryUsername(username?: string): Promise<User & UserData>;
|
|
63
|
-
static
|
|
144
|
+
static getDomainUsers(domain: string, options?: {
|
|
145
|
+
limit?: number;
|
|
146
|
+
offset?: number;
|
|
147
|
+
sort?: string;
|
|
148
|
+
reverse?: boolean;
|
|
149
|
+
}): Promise<(User & UserData)[]>;
|
|
150
|
+
constructor();
|
|
64
151
|
$checkUsername(): Promise<{
|
|
65
152
|
result: boolean;
|
|
66
153
|
message: string;
|
|
@@ -84,6 +171,14 @@ export default class User extends Entity<UserData> {
|
|
|
84
171
|
loggedin: boolean;
|
|
85
172
|
message: string;
|
|
86
173
|
}>;
|
|
174
|
+
$switchUser(data?: {
|
|
175
|
+
additionalData?: {
|
|
176
|
+
[k: string]: any;
|
|
177
|
+
};
|
|
178
|
+
}): Promise<{
|
|
179
|
+
result: boolean;
|
|
180
|
+
message: string;
|
|
181
|
+
}>;
|
|
87
182
|
$logout(): Promise<{
|
|
88
183
|
result: boolean;
|
|
89
184
|
message: string;
|
|
@@ -92,6 +187,34 @@ export default class User extends Entity<UserData> {
|
|
|
92
187
|
$changePassword(data: {
|
|
93
188
|
newPassword: string;
|
|
94
189
|
currentPassword: string;
|
|
190
|
+
revokeCurrentTokens?: boolean;
|
|
191
|
+
}): Promise<{
|
|
192
|
+
result: boolean;
|
|
193
|
+
message: string;
|
|
194
|
+
}>;
|
|
195
|
+
$revokeCurrentTokens(data: {
|
|
196
|
+
password: string;
|
|
197
|
+
}): Promise<{
|
|
198
|
+
result: boolean;
|
|
199
|
+
message: string;
|
|
200
|
+
}>;
|
|
201
|
+
$hasTOTPSecret(): Promise<boolean>;
|
|
202
|
+
$getNewTOTPSecret(): Promise<{
|
|
203
|
+
uri: string;
|
|
204
|
+
qrcode: string;
|
|
205
|
+
secret: string;
|
|
206
|
+
}>;
|
|
207
|
+
$saveTOTPSecret(data: {
|
|
208
|
+
password: string;
|
|
209
|
+
secret: string;
|
|
210
|
+
code: string;
|
|
211
|
+
}): Promise<{
|
|
212
|
+
result: boolean;
|
|
213
|
+
message: string;
|
|
214
|
+
}>;
|
|
215
|
+
$removeTOTPSecret(data?: {
|
|
216
|
+
password: string;
|
|
217
|
+
code: string;
|
|
95
218
|
}): Promise<{
|
|
96
219
|
result: boolean;
|
|
97
220
|
message: string;
|
|
@@ -101,12 +224,14 @@ export default class User extends Entity<UserData> {
|
|
|
101
224
|
static loginUser(data: {
|
|
102
225
|
username: string;
|
|
103
226
|
password: string;
|
|
227
|
+
code?: string;
|
|
104
228
|
additionalData?: {
|
|
105
229
|
[k: string]: any;
|
|
106
230
|
};
|
|
107
231
|
}): Promise<{
|
|
108
232
|
result: boolean;
|
|
109
233
|
message: string;
|
|
234
|
+
needTOTP?: true;
|
|
110
235
|
user?: User & CurrentUserData;
|
|
111
236
|
}>;
|
|
112
237
|
static sendRecovery(data: {
|
package/{lib → dist}/User.js
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class User
|
|
1
|
+
import { Entity } from '@nymphjs/client';
|
|
2
|
+
export default 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,8 +37,15 @@ class User extends client_1.Entity {
|
|
|
49
37
|
}
|
|
50
38
|
return entity;
|
|
51
39
|
}
|
|
52
|
-
static
|
|
53
|
-
return
|
|
40
|
+
static async getDomainUsers(domain, options) {
|
|
41
|
+
return await this.serverCallStatic('getDomainUsers', [domain, options]);
|
|
42
|
+
}
|
|
43
|
+
constructor() {
|
|
44
|
+
super();
|
|
45
|
+
this.$data.enabled = true;
|
|
46
|
+
this.$data.abilities = [];
|
|
47
|
+
this.$data.groups = [];
|
|
48
|
+
this.$data.inheritAbilities = true;
|
|
54
49
|
}
|
|
55
50
|
async $checkUsername() {
|
|
56
51
|
return await this.$serverCall('$checkUsername', [], true);
|
|
@@ -83,6 +78,20 @@ class User extends client_1.Entity {
|
|
|
83
78
|
}
|
|
84
79
|
return response;
|
|
85
80
|
}
|
|
81
|
+
async $switchUser(data) {
|
|
82
|
+
const store = User.stores.get(this.$nymph);
|
|
83
|
+
if (store == null) {
|
|
84
|
+
throw new Error('This user class was never initialized with an instance of Nymph');
|
|
85
|
+
}
|
|
86
|
+
const response = await this.$serverCall('$switchUser', [data]);
|
|
87
|
+
if (response.result) {
|
|
88
|
+
this.constructor.handleToken();
|
|
89
|
+
for (let i = 0; i < store.loginCallbacks.length; i++) {
|
|
90
|
+
store.loginCallbacks[i] && store.loginCallbacks[i](this);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return response;
|
|
94
|
+
}
|
|
86
95
|
async $logout() {
|
|
87
96
|
const store = User.stores.get(this.$nymph);
|
|
88
97
|
if (store == null) {
|
|
@@ -103,6 +112,23 @@ class User extends client_1.Entity {
|
|
|
103
112
|
async $changePassword(data) {
|
|
104
113
|
return await this.$serverCall('$changePassword', [data]);
|
|
105
114
|
}
|
|
115
|
+
async $revokeCurrentTokens(data) {
|
|
116
|
+
return await this.$serverCall('$revokeCurrentTokens', [data]);
|
|
117
|
+
}
|
|
118
|
+
async $hasTOTPSecret() {
|
|
119
|
+
return await this.$serverCall('$hasTOTPSecret', [], true);
|
|
120
|
+
}
|
|
121
|
+
async $getNewTOTPSecret() {
|
|
122
|
+
return await this.$serverCall('$getNewTOTPSecret', [], true);
|
|
123
|
+
}
|
|
124
|
+
async $saveTOTPSecret(data) {
|
|
125
|
+
return await this.$serverCall('$saveTOTPSecret', [data]);
|
|
126
|
+
}
|
|
127
|
+
async $removeTOTPSecret(data) {
|
|
128
|
+
return await this.$serverCall('$removeTOTPSecret', [
|
|
129
|
+
...(data ? [data] : []),
|
|
130
|
+
]);
|
|
131
|
+
}
|
|
106
132
|
static async current(returnObjectIfNotExist) {
|
|
107
133
|
const currentUser = await this.serverCallStatic('current', [false]);
|
|
108
134
|
if (currentUser == null) {
|
|
@@ -148,40 +174,58 @@ class User extends client_1.Entity {
|
|
|
148
174
|
return await store.clientConfigPromise;
|
|
149
175
|
}
|
|
150
176
|
static handleToken(response) {
|
|
177
|
+
const store = User.stores.get(this.nymph);
|
|
178
|
+
if (store == null) {
|
|
179
|
+
throw new Error('This user class was never initialized with an instance of Nymph');
|
|
180
|
+
}
|
|
151
181
|
let token = null;
|
|
182
|
+
let switchToken = null;
|
|
183
|
+
let hasNoCookie = typeof document === 'undefined' || typeof document.cookie === 'undefined';
|
|
152
184
|
const authCookiePattern = /(?:(?:^|.*;\s*)TILMELDAUTH\s*=\s*([^;]*).*$)|^.*$/;
|
|
185
|
+
const switchCookiePattern = /(?:(?:^|.*;\s*)TILMELDSWITCH\s*=\s*([^;]*).*$)|^.*$/;
|
|
153
186
|
if (response && response.headers.has('X-TILMELDAUTH')) {
|
|
154
187
|
token = response.headers.get('X-TILMELDAUTH');
|
|
188
|
+
switchToken = response.headers.get('X-TILMELDSWITCH');
|
|
155
189
|
}
|
|
156
190
|
else if (typeof document !== 'undefined' &&
|
|
157
191
|
document.cookie.match(authCookiePattern)) {
|
|
158
192
|
token = document.cookie.replace(authCookiePattern, '$1');
|
|
193
|
+
switchToken = document.cookie.replace(switchCookiePattern, '$1');
|
|
159
194
|
}
|
|
160
195
|
else {
|
|
161
196
|
return;
|
|
162
197
|
}
|
|
163
|
-
if (currentToken
|
|
198
|
+
if (store.currentToken != token) {
|
|
164
199
|
if (token == null || token === '') {
|
|
165
|
-
if (currentToken != null) {
|
|
166
|
-
this.nymph.
|
|
200
|
+
if (store.currentToken != null) {
|
|
201
|
+
delete this.nymph.headers['X-Xsrf-Token'];
|
|
202
|
+
delete this.nymph.headers['X-TILMELDAUTH'];
|
|
203
|
+
delete this.nymph.headers['X-TILMELDSWITCH'];
|
|
167
204
|
if (this.nymph.pubsub) {
|
|
168
|
-
this.nymph.pubsub.
|
|
205
|
+
this.nymph.pubsub.authenticate(null);
|
|
169
206
|
}
|
|
170
|
-
currentToken
|
|
207
|
+
delete store.currentToken;
|
|
171
208
|
}
|
|
172
209
|
}
|
|
173
210
|
else {
|
|
174
211
|
const base64Url = token.split('.')[1];
|
|
175
212
|
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
|
|
176
213
|
const json = typeof atob === 'undefined'
|
|
177
|
-
? Buffer.from(base64, 'base64').toString('binary')
|
|
178
|
-
: atob(base64);
|
|
214
|
+
? Buffer.from(base64, 'base64').toString('binary') // node
|
|
215
|
+
: atob(base64); // browser
|
|
179
216
|
const jwt = JSON.parse(json);
|
|
180
|
-
this.nymph.
|
|
217
|
+
this.nymph.headers['X-Xsrf-Token'] = jwt.xsrfToken;
|
|
218
|
+
if (hasNoCookie) {
|
|
219
|
+
this.nymph.headers['X-TILMELDAUTH'] = token;
|
|
220
|
+
delete this.nymph.headers['X-TILMELDSWITCH'];
|
|
221
|
+
if (switchToken != null) {
|
|
222
|
+
this.nymph.headers['X-TILMELDSWITCH'] = switchToken;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
181
225
|
if (this.nymph.pubsub) {
|
|
182
|
-
this.nymph.pubsub.
|
|
226
|
+
this.nymph.pubsub.authenticate(token, switchToken);
|
|
183
227
|
}
|
|
184
|
-
currentToken = token;
|
|
228
|
+
store.currentToken = token;
|
|
185
229
|
}
|
|
186
230
|
}
|
|
187
231
|
}
|
|
@@ -194,6 +238,7 @@ class User extends client_1.Entity {
|
|
|
194
238
|
if (!(prop in store)) {
|
|
195
239
|
throw new Error('Invalid event type.');
|
|
196
240
|
}
|
|
241
|
+
// @ts-ignore: The callback should always be the right type here.
|
|
197
242
|
store[prop].push(callback);
|
|
198
243
|
return () => this.off(event, callback);
|
|
199
244
|
}
|
|
@@ -206,14 +251,13 @@ class User extends client_1.Entity {
|
|
|
206
251
|
if (!(prop in store)) {
|
|
207
252
|
return false;
|
|
208
253
|
}
|
|
254
|
+
// @ts-ignore: The callback should always be the right type here.
|
|
209
255
|
const i = store[prop].indexOf(callback);
|
|
210
256
|
if (i > -1) {
|
|
257
|
+
// @ts-ignore: The callback should always be the right type here.
|
|
211
258
|
store[prop].splice(i, 1);
|
|
212
259
|
}
|
|
213
260
|
return true;
|
|
214
261
|
}
|
|
215
262
|
}
|
|
216
|
-
exports.default = User;
|
|
217
|
-
User.stores = new WeakMap();
|
|
218
|
-
User.class = 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AAM,IAAI,GAAG,CAAC,KAAK,GAAG,WAAW,CAMpB,CAAC;QACd,IAAI,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACzC,CAAC;QACD,iEAAiE;QACjE,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC3B,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACzC,CAAC;IAEM,MAAM,CAAC,GAAG,CACf,KAAQ,EACR,QAMa;QAEb,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1C,IAAI,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"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type 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
|
+
}>;
|
package/{lib → dist}/helpers.js
RENAMED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
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.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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.
|
|
57
|
+
if (config.regFields.includes('name')) {
|
|
50
58
|
user.nameFirst = userDetails.nameFirst;
|
|
51
59
|
user.nameLast = userDetails.nameLast;
|
|
52
60
|
}
|
|
53
|
-
if (config.regFields.
|
|
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
|
-
|
|
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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+
export * from './helpers.js';
|
|
5
|
+
export * from './Tilmeld.types.js';
|
|
6
|
+
export * from './User.js';
|
|
7
|
+
import User from './User.js';
|
|
8
|
+
export { User };
|
|
2
9
|
//# sourceMappingURL=index.js.map
|