@nymphjs/tilmeld-client 1.0.0-beta.14 → 1.0.0-beta.140
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 +559 -0
- package/README.md +7 -4
- package/dist/Group.d.ts +78 -0
- 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 +141 -14
- package/{lib → dist}/User.js +82 -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 +4 -0
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +255 -0
- package/dist/index.test.js.map +1 -0
- package/jest.config.js +31 -5
- package/package.json +37 -33
- package/src/Group.ts +37 -31
- package/src/Tilmeld.types.ts +13 -0
- package/src/User.ts +170 -78
- package/src/helpers.ts +25 -12
- package/src/index.test.ts +327 -0
- package/src/index.ts +5 -7
- package/tsconfig.json +7 -4
- package/typedoc.json +4 -0
- package/lib/Group.d.ts +0 -41
- 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}/Group.js
RENAMED
|
@@ -1,19 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class Group
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { Entity } from '@nymphjs/client';
|
|
2
|
+
export class Group extends Entity {
|
|
3
|
+
// The name of the server class
|
|
4
|
+
static class = 'Group';
|
|
5
|
+
static async factoryGroupname(groupname) {
|
|
6
|
+
const entity = new this();
|
|
7
|
+
if (groupname != null) {
|
|
8
|
+
const entity = await this.nymph.getEntity({
|
|
9
|
+
class: this,
|
|
10
|
+
}, {
|
|
11
|
+
type: '&',
|
|
12
|
+
ilike: ['groupname', groupname.replace(/([\\%_])/g, (s) => `\\${s}`)],
|
|
13
|
+
});
|
|
14
|
+
if (entity != null) {
|
|
15
|
+
return entity;
|
|
16
|
+
}
|
|
10
17
|
}
|
|
18
|
+
return entity;
|
|
11
19
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return super.factorySync(guid);
|
|
20
|
+
constructor() {
|
|
21
|
+
super();
|
|
22
|
+
this.enabled = true;
|
|
23
|
+
this.abilities = [];
|
|
17
24
|
}
|
|
18
25
|
async $checkGroupname() {
|
|
19
26
|
return await this.$serverCall('$checkGroupname', [], true);
|
|
@@ -49,6 +56,4 @@ class Group extends client_1.Entity {
|
|
|
49
56
|
]);
|
|
50
57
|
}
|
|
51
58
|
}
|
|
52
|
-
exports.default = Group;
|
|
53
|
-
Group.class = 'Group';
|
|
54
59
|
//# sourceMappingURL=Group.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Group.js","sourceRoot":"","sources":["../src/Group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAqB,MAAM,iBAAiB,CAAC;AA+D5D,MAAM,OAAO,KAAM,SAAQ,MAAiB;IAC1C,+BAA+B;IACxB,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC;IAE9B,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,SAAkB;QAC9C,MAAM,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QAC1B,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;YACtB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CACvC;gBACE,KAAK,E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Aa,CAAC,UAA0B;QACnD,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,eAAe,EAAE,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC,CAAC;IACrE,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAClC,OAAiB,EACjB,SAAsB;QAEtB,OAAO,MAAM,IAAI,CAAC,gBAAgB,CAAC,kBAAkB,EAAE;YACrD,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE;YAC9B,SAAS;SACV,CAAC,CAAC;IACL,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,kBAAkB,CACpC,OAAiB,EACjB,SAAsB;QAEtB,OAAO,MAAM,IAAI,CAAC,gBAAgB,CAAC,oBAAoB,EAAE;YACvD,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE;YAC9B,SAAS;SACV,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Group } from './Group.js';
|
|
2
|
+
import { User } from './User.js';
|
|
3
|
+
export interface AccessControlData {
|
|
4
|
+
user?: User;
|
|
5
|
+
group?: Group;
|
|
6
|
+
acUser?: number;
|
|
7
|
+
acGroup?: number;
|
|
8
|
+
acOther?: number;
|
|
9
|
+
acFull?: string[];
|
|
10
|
+
acWrite?: string[];
|
|
11
|
+
acRead?: string[];
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tilmeld.types.js","sourceRoot":"","sources":["../src/Tilmeld.types.ts"],"names":[],"mappings":""}
|
package/{lib → dist}/User.d.ts
RENAMED
|
@@ -1,10 +1,9 @@
|
|
|
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, AdminGroupData, CurrentGroupData } from './Group.js';
|
|
4
3
|
export type EventType = 'register' | 'login' | 'logout';
|
|
5
4
|
export type RegisterCallback = (user: User & CurrentUserData) => void;
|
|
6
5
|
export type LoginCallback = (user: User & CurrentUserData) => void;
|
|
7
|
-
export type LogoutCallback = (user: User
|
|
6
|
+
export type LogoutCallback = (user: User) => void;
|
|
8
7
|
export type ClientConfig = {
|
|
9
8
|
regFields: string[];
|
|
10
9
|
userFields: string[];
|
|
@@ -15,36 +14,118 @@ export type ClientConfig = {
|
|
|
15
14
|
verifyEmail: boolean;
|
|
16
15
|
unverifiedAccess: boolean;
|
|
17
16
|
};
|
|
18
|
-
export
|
|
17
|
+
export interface UserData {
|
|
18
|
+
/**
|
|
19
|
+
* The user's username.
|
|
20
|
+
*/
|
|
19
21
|
username?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The user's first name.
|
|
24
|
+
*/
|
|
20
25
|
nameFirst?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The user's middle name.
|
|
28
|
+
*/
|
|
21
29
|
nameMiddle?: string;
|
|
30
|
+
/**
|
|
31
|
+
* The user's last name.
|
|
32
|
+
*/
|
|
22
33
|
nameLast?: string;
|
|
34
|
+
/**
|
|
35
|
+
* The user's full name.
|
|
36
|
+
*/
|
|
23
37
|
name?: string;
|
|
38
|
+
/**
|
|
39
|
+
* The user's avatar URL. (Use $getAvatar() to support Gravatar.)
|
|
40
|
+
*/
|
|
24
41
|
avatar?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Whether the user can log in.
|
|
44
|
+
*/
|
|
25
45
|
enabled?: boolean;
|
|
26
|
-
}
|
|
27
|
-
export
|
|
46
|
+
}
|
|
47
|
+
export interface CurrentUserData extends UserData {
|
|
48
|
+
/**
|
|
49
|
+
* The abilities granted to the user.
|
|
50
|
+
*/
|
|
28
51
|
abilities?: string[];
|
|
52
|
+
/**
|
|
53
|
+
* The user's email address.
|
|
54
|
+
*/
|
|
29
55
|
email?: string;
|
|
56
|
+
/**
|
|
57
|
+
* The user's telephone number.
|
|
58
|
+
*/
|
|
30
59
|
phone?: string;
|
|
60
|
+
/**
|
|
61
|
+
* The user's primary group.
|
|
62
|
+
*/
|
|
31
63
|
group?: Group & CurrentGroupData;
|
|
64
|
+
/**
|
|
65
|
+
* The user's secondary groups.
|
|
66
|
+
*/
|
|
32
67
|
groups?: (Group & CurrentGroupData)[];
|
|
68
|
+
/**
|
|
69
|
+
* Whether the user should inherit the abilities of his groups.
|
|
70
|
+
*/
|
|
33
71
|
inheritAbilities?: boolean;
|
|
34
|
-
|
|
35
|
-
|
|
72
|
+
/**
|
|
73
|
+
* If the user has changed their email address, this is the new one, awaiting
|
|
74
|
+
* verification.
|
|
75
|
+
*/
|
|
76
|
+
newEmailAddress?: string;
|
|
77
|
+
}
|
|
78
|
+
export interface AdminUserData extends CurrentUserData {
|
|
79
|
+
/**
|
|
80
|
+
* The user's primary group.
|
|
81
|
+
*/
|
|
36
82
|
group?: Group & AdminGroupData;
|
|
83
|
+
/**
|
|
84
|
+
* The user's secondary groups.
|
|
85
|
+
*/
|
|
37
86
|
groups?: (Group & AdminGroupData)[];
|
|
87
|
+
/**
|
|
88
|
+
* A verification secret.
|
|
89
|
+
*/
|
|
38
90
|
secret?: string;
|
|
91
|
+
/**
|
|
92
|
+
* The timestamp of when the email address was last changed.
|
|
93
|
+
*/
|
|
39
94
|
emailChangeDate?: number;
|
|
95
|
+
/**
|
|
96
|
+
* An email change proceed secret.
|
|
97
|
+
*/
|
|
40
98
|
newEmailSecret?: string;
|
|
99
|
+
/**
|
|
100
|
+
* The new email address.
|
|
101
|
+
*/
|
|
41
102
|
newEmailAddress?: string;
|
|
103
|
+
/**
|
|
104
|
+
* An email change cancellation secret.
|
|
105
|
+
*/
|
|
42
106
|
cancelEmailSecret?: string;
|
|
107
|
+
/**
|
|
108
|
+
* The old email address.
|
|
109
|
+
*/
|
|
43
110
|
cancelEmailAddress?: string;
|
|
111
|
+
/**
|
|
112
|
+
* A recovery secret.
|
|
113
|
+
*/
|
|
44
114
|
recoverSecret?: string;
|
|
115
|
+
/**
|
|
116
|
+
* The timestamp of when the recovery secret was issued.
|
|
117
|
+
*/
|
|
45
118
|
recoverSecretDate?: number;
|
|
119
|
+
/**
|
|
120
|
+
* Used by admins to change a user's password. Not saved to the database.
|
|
121
|
+
*/
|
|
46
122
|
passwordTemp?: string;
|
|
47
|
-
|
|
123
|
+
/**
|
|
124
|
+
* If set, this timestamp is the cutoff point for JWT issue dates. Any token
|
|
125
|
+
* issued before this date will not authenticate the user.
|
|
126
|
+
*/
|
|
127
|
+
revokeTokenDate?: number;
|
|
128
|
+
}
|
|
48
129
|
type InstanceStore = {
|
|
49
130
|
registerCallbacks: RegisterCallback[];
|
|
50
131
|
loginCallbacks: LoginCallback[];
|
|
@@ -52,15 +133,23 @@ type InstanceStore = {
|
|
|
52
133
|
clientConfig?: ClientConfig;
|
|
53
134
|
clientConfigPromise?: Promise<ClientConfig>;
|
|
54
135
|
removeNymphResponseListener?: () => void;
|
|
136
|
+
currentToken?: string;
|
|
137
|
+
switchToken?: string;
|
|
55
138
|
};
|
|
56
|
-
export
|
|
139
|
+
export interface User extends UserData {
|
|
140
|
+
}
|
|
141
|
+
export declare class User extends Entity<UserData> {
|
|
57
142
|
protected static stores: WeakMap<Nymph, InstanceStore>;
|
|
58
143
|
static class: string;
|
|
59
144
|
static init(nymph: Nymph): void;
|
|
60
|
-
|
|
61
|
-
static
|
|
62
|
-
|
|
63
|
-
|
|
145
|
+
static factoryUsername(username?: string): Promise<User>;
|
|
146
|
+
static getDomainUsers(domain: string, options?: {
|
|
147
|
+
limit?: number;
|
|
148
|
+
offset?: number;
|
|
149
|
+
sort?: string;
|
|
150
|
+
reverse?: boolean;
|
|
151
|
+
}): Promise<User[]>;
|
|
152
|
+
constructor();
|
|
64
153
|
$checkUsername(): Promise<{
|
|
65
154
|
result: boolean;
|
|
66
155
|
message: string;
|
|
@@ -84,6 +173,14 @@ export default class User extends Entity<UserData> {
|
|
|
84
173
|
loggedin: boolean;
|
|
85
174
|
message: string;
|
|
86
175
|
}>;
|
|
176
|
+
$switchUser(data?: {
|
|
177
|
+
additionalData?: {
|
|
178
|
+
[k: string]: any;
|
|
179
|
+
};
|
|
180
|
+
}): Promise<{
|
|
181
|
+
result: boolean;
|
|
182
|
+
message: string;
|
|
183
|
+
}>;
|
|
87
184
|
$logout(): Promise<{
|
|
88
185
|
result: boolean;
|
|
89
186
|
message: string;
|
|
@@ -92,6 +189,34 @@ export default class User extends Entity<UserData> {
|
|
|
92
189
|
$changePassword(data: {
|
|
93
190
|
newPassword: string;
|
|
94
191
|
currentPassword: string;
|
|
192
|
+
revokeCurrentTokens?: boolean;
|
|
193
|
+
}): Promise<{
|
|
194
|
+
result: boolean;
|
|
195
|
+
message: string;
|
|
196
|
+
}>;
|
|
197
|
+
$revokeCurrentTokens(data?: {
|
|
198
|
+
password: string;
|
|
199
|
+
}): Promise<{
|
|
200
|
+
result: boolean;
|
|
201
|
+
message: string;
|
|
202
|
+
}>;
|
|
203
|
+
$hasTOTPSecret(): Promise<boolean>;
|
|
204
|
+
$getNewTOTPSecret(): Promise<{
|
|
205
|
+
uri: string;
|
|
206
|
+
qrcode: string;
|
|
207
|
+
secret: string;
|
|
208
|
+
}>;
|
|
209
|
+
$saveTOTPSecret(data: {
|
|
210
|
+
password: string;
|
|
211
|
+
secret: string;
|
|
212
|
+
code: string;
|
|
213
|
+
}): Promise<{
|
|
214
|
+
result: boolean;
|
|
215
|
+
message: string;
|
|
216
|
+
}>;
|
|
217
|
+
$removeTOTPSecret(data?: {
|
|
218
|
+
password: string;
|
|
219
|
+
code: string;
|
|
95
220
|
}): Promise<{
|
|
96
221
|
result: boolean;
|
|
97
222
|
message: string;
|
|
@@ -101,12 +226,14 @@ export default class User extends Entity<UserData> {
|
|
|
101
226
|
static loginUser(data: {
|
|
102
227
|
username: string;
|
|
103
228
|
password: string;
|
|
229
|
+
code?: string;
|
|
104
230
|
additionalData?: {
|
|
105
231
|
[k: string]: any;
|
|
106
232
|
};
|
|
107
233
|
}): Promise<{
|
|
108
234
|
result: boolean;
|
|
109
235
|
message: string;
|
|
236
|
+
needTOTP?: true;
|
|
110
237
|
user?: User & CurrentUserData;
|
|
111
238
|
}>;
|
|
112
239
|
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 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.enabled = true;
|
|
46
|
+
this.abilities = [];
|
|
47
|
+
this.groups = [];
|
|
48
|
+
this.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,64 @@ 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 || store.switchToken != switchToken) {
|
|
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
|
-
|
|
207
|
+
// Make sure entities requested under a previous user are not reused.
|
|
208
|
+
this.nymph.clearCaches();
|
|
209
|
+
delete store.currentToken;
|
|
210
|
+
delete store.switchToken;
|
|
171
211
|
}
|
|
172
212
|
}
|
|
173
213
|
else {
|
|
174
214
|
const base64Url = token.split('.')[1];
|
|
175
215
|
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
|
|
176
216
|
const json = typeof atob === 'undefined'
|
|
177
|
-
? Buffer.from(base64, 'base64').toString('binary')
|
|
178
|
-
: atob(base64);
|
|
217
|
+
? Buffer.from(base64, 'base64').toString('binary') // node
|
|
218
|
+
: atob(base64); // browser
|
|
179
219
|
const jwt = JSON.parse(json);
|
|
180
|
-
this.nymph.
|
|
220
|
+
this.nymph.headers['X-Xsrf-Token'] = jwt.xsrfToken;
|
|
221
|
+
if (hasNoCookie) {
|
|
222
|
+
this.nymph.headers['X-TILMELDAUTH'] = token;
|
|
223
|
+
delete this.nymph.headers['X-TILMELDSWITCH'];
|
|
224
|
+
if (switchToken != null) {
|
|
225
|
+
this.nymph.headers['X-TILMELDSWITCH'] = switchToken;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
181
228
|
if (this.nymph.pubsub) {
|
|
182
|
-
this.nymph.pubsub.
|
|
229
|
+
this.nymph.pubsub.authenticate(token, switchToken);
|
|
183
230
|
}
|
|
184
|
-
|
|
231
|
+
// Make sure entities requested under a previous user are not reused.
|
|
232
|
+
this.nymph.clearCaches();
|
|
233
|
+
store.currentToken = token;
|
|
234
|
+
store.switchToken = switchToken ?? undefined;
|
|
185
235
|
}
|
|
186
236
|
}
|
|
187
237
|
}
|
|
@@ -194,6 +244,7 @@ class User extends client_1.Entity {
|
|
|
194
244
|
if (!(prop in store)) {
|
|
195
245
|
throw new Error('Invalid event type.');
|
|
196
246
|
}
|
|
247
|
+
// @ts-ignore: The callback should always be the right type here.
|
|
197
248
|
store[prop].push(callback);
|
|
198
249
|
return () => this.off(event, callback);
|
|
199
250
|
}
|
|
@@ -206,14 +257,13 @@ class User extends client_1.Entity {
|
|
|
206
257
|
if (!(prop in store)) {
|
|
207
258
|
return false;
|
|
208
259
|
}
|
|
260
|
+
// @ts-ignore: The callback should always be the right type here.
|
|
209
261
|
const i = store[prop].indexOf(callback);
|
|
210
262
|
if (i > -1) {
|
|
263
|
+
// @ts-ignore: The callback should always be the right type here.
|
|
211
264
|
store[prop].splice(i, 1);
|
|
212
265
|
}
|
|
213
266
|
return true;
|
|
214
267
|
}
|
|
215
268
|
}
|
|
216
|
-
exports.default = User;
|
|
217
|
-
User.stores = new WeakMap();
|
|
218
|
-
User.class = 'User';
|
|
219
269
|
//# sourceMappingURL=User.js.map
|
package/dist/User.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"User.js","sourceRoot":"","sources":["../src/User.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAqJhD,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,C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AAM,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
|
+
}>;
|
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
|