@webex/internal-plugin-user 3.0.0-beta.9 → 3.0.0-bnr.0
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/README.md +1 -3
- package/dist/config.js +0 -3
- package/dist/config.js.map +1 -1
- package/dist/index.js +2 -9
- package/dist/index.js.map +1 -1
- package/dist/internal-plugin-user.d.ts +7 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/types/config.d.ts +17 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/user-uuid-batcher.d.ts +5 -0
- package/dist/types/user-uuid-store.d.ts +34 -0
- package/dist/types/user.d.ts +5 -0
- package/dist/user-uuid-batcher.js +4 -21
- package/dist/user-uuid-batcher.js.map +1 -1
- package/dist/user-uuid-store.js +17 -37
- package/dist/user-uuid-store.js.map +1 -1
- package/dist/user.js +18 -82
- package/dist/user.js.map +1 -1
- package/package.json +8 -8
- package/src/config.js +5 -5
- package/src/index.js +2 -3
- package/src/user-uuid-batcher.js +22 -22
- package/src/user-uuid-store.js +7 -6
- package/src/user.js +90 -81
- package/test/integration/spec/user.js +130 -87
- package/test/unit/spec/user-uuid-batcher.js +22 -19
- package/test/unit/spec/user.js +83 -35
package/src/user-uuid-batcher.js
CHANGED
|
@@ -23,20 +23,21 @@ const AbstractUserUUIDRequestBatcher = Batcher.extend({
|
|
|
23
23
|
* @returns {Promise}
|
|
24
24
|
*/
|
|
25
25
|
handleHttpSuccess(res) {
|
|
26
|
-
return Promise.all(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
return Promise.all(
|
|
27
|
+
Object.keys(res.body).map((email) => {
|
|
28
|
+
if (res.body[email] && res.body[email].id) {
|
|
29
|
+
return this.handleItemSuccess(email, res.body[email]);
|
|
30
|
+
}
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
return this.handleItemFailure(email, res.body[email]);
|
|
33
|
+
})
|
|
34
|
+
);
|
|
33
35
|
},
|
|
34
36
|
|
|
35
37
|
handleItemFailure(email, response) {
|
|
36
|
-
return this.getDeferredForResponse(email)
|
|
37
|
-
.
|
|
38
|
-
|
|
39
|
-
});
|
|
38
|
+
return this.getDeferredForResponse(email).then((defer) => {
|
|
39
|
+
defer.reject(response);
|
|
40
|
+
});
|
|
40
41
|
},
|
|
41
42
|
|
|
42
43
|
/**
|
|
@@ -45,10 +46,9 @@ const AbstractUserUUIDRequestBatcher = Batcher.extend({
|
|
|
45
46
|
* @returns {Promise}
|
|
46
47
|
*/
|
|
47
48
|
handleItemSuccess(email, response) {
|
|
48
|
-
return this.getDeferredForResponse(email)
|
|
49
|
-
.
|
|
50
|
-
|
|
51
|
-
});
|
|
49
|
+
return this.getDeferredForResponse(email).then((defer) => {
|
|
50
|
+
defer.resolve(response);
|
|
51
|
+
});
|
|
52
52
|
},
|
|
53
53
|
|
|
54
54
|
/**
|
|
@@ -65,7 +65,7 @@ const AbstractUserUUIDRequestBatcher = Batcher.extend({
|
|
|
65
65
|
*/
|
|
66
66
|
fingerprintResponse(email) {
|
|
67
67
|
return Promise.resolve(email);
|
|
68
|
-
}
|
|
68
|
+
},
|
|
69
69
|
});
|
|
70
70
|
|
|
71
71
|
/**
|
|
@@ -81,9 +81,9 @@ const FakeUserUUIDRequestBatcher = AbstractUserUUIDRequestBatcher.extend({
|
|
|
81
81
|
method: 'POST',
|
|
82
82
|
service: 'conversation',
|
|
83
83
|
resource: '/users',
|
|
84
|
-
body: payload
|
|
84
|
+
body: payload,
|
|
85
85
|
});
|
|
86
|
-
}
|
|
86
|
+
},
|
|
87
87
|
});
|
|
88
88
|
|
|
89
89
|
/**
|
|
@@ -101,10 +101,10 @@ const RealUserUUIDRequestBatcher = AbstractUserUUIDRequestBatcher.extend({
|
|
|
101
101
|
resource: '/users',
|
|
102
102
|
body: payload,
|
|
103
103
|
qs: {
|
|
104
|
-
shouldCreateUsers: true
|
|
105
|
-
}
|
|
104
|
+
shouldCreateUsers: true,
|
|
105
|
+
},
|
|
106
106
|
});
|
|
107
|
-
}
|
|
107
|
+
},
|
|
108
108
|
});
|
|
109
109
|
|
|
110
110
|
/**
|
|
@@ -113,7 +113,7 @@ const RealUserUUIDRequestBatcher = AbstractUserUUIDRequestBatcher.extend({
|
|
|
113
113
|
const UserUUIDBatcher = WebexPlugin.extend({
|
|
114
114
|
children: {
|
|
115
115
|
faker: FakeUserUUIDRequestBatcher,
|
|
116
|
-
creator: RealUserUUIDRequestBatcher
|
|
116
|
+
creator: RealUserUUIDRequestBatcher,
|
|
117
117
|
},
|
|
118
118
|
|
|
119
119
|
/**
|
|
@@ -122,7 +122,7 @@ const UserUUIDBatcher = WebexPlugin.extend({
|
|
|
122
122
|
*/
|
|
123
123
|
request(payload) {
|
|
124
124
|
return payload.create ? this.creator.request(payload.email) : this.faker.request(payload.email);
|
|
125
|
-
}
|
|
125
|
+
},
|
|
126
126
|
});
|
|
127
127
|
|
|
128
128
|
export default UserUUIDBatcher;
|
package/src/user-uuid-store.js
CHANGED
|
@@ -40,16 +40,18 @@ export default class UserUUIDStore {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
if (!patterns.email.test(user.emailAddress)) {
|
|
43
|
-
return Promise.reject(
|
|
43
|
+
return Promise.reject(
|
|
44
|
+
new Error('`user.emailAddress` does not appear to be an email address')
|
|
45
|
+
);
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
const p1 = this.getById(user.id)
|
|
47
|
-
.then((u) => usersById.get(this).set(user.id,
|
|
48
|
-
.catch(() => usersById.get(this).set(user.id,
|
|
49
|
+
.then((u) => usersById.get(this).set(user.id, {...u, ...user}))
|
|
50
|
+
.catch(() => usersById.get(this).set(user.id, {...user}));
|
|
49
51
|
|
|
50
52
|
const p2 = this.getByEmail(user.emailAddress)
|
|
51
|
-
.then((u) => usersByEmail.get(this).set(user.emailAddress,
|
|
52
|
-
.catch(() => usersByEmail.get(this).set(user.emailAddress,
|
|
53
|
+
.then((u) => usersByEmail.get(this).set(user.emailAddress, {...u, ...user}))
|
|
54
|
+
.catch(() => usersByEmail.get(this).set(user.emailAddress, {...user}));
|
|
53
55
|
|
|
54
56
|
return Promise.all([p1, p2]);
|
|
55
57
|
}
|
|
@@ -86,7 +88,6 @@ export default class UserUUIDStore {
|
|
|
86
88
|
return Promise.reject(new Error('No user found by specified id'));
|
|
87
89
|
}
|
|
88
90
|
|
|
89
|
-
|
|
90
91
|
/**
|
|
91
92
|
* Retrieves the specified user object by id from the store
|
|
92
93
|
* @param {Object} email
|
package/src/user.js
CHANGED
|
@@ -16,7 +16,7 @@ const User = WebexPlugin.extend({
|
|
|
16
16
|
namespace: 'User',
|
|
17
17
|
|
|
18
18
|
children: {
|
|
19
|
-
batcher: UserUUIDBatcher
|
|
19
|
+
batcher: UserUUIDBatcher,
|
|
20
20
|
},
|
|
21
21
|
|
|
22
22
|
props: {
|
|
@@ -28,8 +28,8 @@ const User = WebexPlugin.extend({
|
|
|
28
28
|
*/
|
|
29
29
|
hasPassword: {
|
|
30
30
|
default: false,
|
|
31
|
-
type: 'boolean'
|
|
32
|
-
}
|
|
31
|
+
type: 'boolean',
|
|
32
|
+
},
|
|
33
33
|
},
|
|
34
34
|
|
|
35
35
|
session: {
|
|
@@ -37,8 +37,8 @@ const User = WebexPlugin.extend({
|
|
|
37
37
|
default() {
|
|
38
38
|
return new UserUUIDStore();
|
|
39
39
|
},
|
|
40
|
-
type: 'any'
|
|
41
|
-
}
|
|
40
|
+
type: 'any',
|
|
41
|
+
},
|
|
42
42
|
},
|
|
43
43
|
|
|
44
44
|
@waitForValue('@')
|
|
@@ -55,7 +55,11 @@ const User = WebexPlugin.extend({
|
|
|
55
55
|
*/
|
|
56
56
|
activate(options = {}) {
|
|
57
57
|
if (!(options.verificationToken || (options.confirmationCode && options.id))) {
|
|
58
|
-
return Promise.reject(
|
|
58
|
+
return Promise.reject(
|
|
59
|
+
new Error(
|
|
60
|
+
'either options.verificationToken is required or both options.confirmationCode and options.id are required'
|
|
61
|
+
)
|
|
62
|
+
);
|
|
59
63
|
}
|
|
60
64
|
|
|
61
65
|
options.scope = this.webex.config.credentials.scope;
|
|
@@ -63,7 +67,7 @@ const User = WebexPlugin.extend({
|
|
|
63
67
|
// if we have options.email and options.verificationToken
|
|
64
68
|
// and Federation flag is enabled, flag that we need to
|
|
65
69
|
// lookup user's CI.
|
|
66
|
-
const activateOptions =
|
|
70
|
+
const activateOptions = {...options};
|
|
67
71
|
|
|
68
72
|
delete activateOptions.email;
|
|
69
73
|
|
|
@@ -74,14 +78,13 @@ const User = WebexPlugin.extend({
|
|
|
74
78
|
auth: {
|
|
75
79
|
user: this.webex.config.credentials.client_id,
|
|
76
80
|
pass: this.webex.config.credentials.client_secret,
|
|
77
|
-
sendImmediately: true
|
|
78
|
-
}
|
|
79
|
-
})
|
|
80
|
-
.
|
|
81
|
-
this.webex.credentials.set({supertoken: res.body.tokenData});
|
|
81
|
+
sendImmediately: true,
|
|
82
|
+
},
|
|
83
|
+
}).then((res) => {
|
|
84
|
+
this.webex.credentials.set({supertoken: res.body.tokenData});
|
|
82
85
|
|
|
83
|
-
|
|
84
|
-
|
|
86
|
+
return res.body;
|
|
87
|
+
});
|
|
85
88
|
},
|
|
86
89
|
|
|
87
90
|
/**
|
|
@@ -126,12 +129,12 @@ const User = WebexPlugin.extend({
|
|
|
126
129
|
* @returns {Promise<string>}
|
|
127
130
|
*/
|
|
128
131
|
fetchUUID(email, options) {
|
|
129
|
-
return this.batcher
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
return this.batcher
|
|
133
|
+
.request({
|
|
134
|
+
email,
|
|
135
|
+
create: options && options.create,
|
|
136
|
+
})
|
|
137
|
+
.then((user) => this.recordUUID({emailAddress: email, ...user}).then(() => user.id));
|
|
135
138
|
},
|
|
136
139
|
/**
|
|
137
140
|
* Generates One Time Password.
|
|
@@ -152,10 +155,9 @@ const User = WebexPlugin.extend({
|
|
|
152
155
|
body: options,
|
|
153
156
|
auth: {
|
|
154
157
|
user: this.webex.config.credentials.client_id,
|
|
155
|
-
pass: this.webex.config.credentials.client_secret
|
|
156
|
-
}
|
|
157
|
-
})
|
|
158
|
-
.then((res) => res.body);
|
|
158
|
+
pass: this.webex.config.credentials.client_secret,
|
|
159
|
+
},
|
|
160
|
+
}).then((res) => res.body);
|
|
159
161
|
},
|
|
160
162
|
|
|
161
163
|
/**
|
|
@@ -165,15 +167,19 @@ const User = WebexPlugin.extend({
|
|
|
165
167
|
get() {
|
|
166
168
|
return this.request({
|
|
167
169
|
service: 'conversation',
|
|
168
|
-
resource: 'users'
|
|
170
|
+
resource: 'users',
|
|
169
171
|
})
|
|
170
172
|
.then((res) => res.body)
|
|
171
|
-
.then(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
173
|
+
.then(
|
|
174
|
+
tap((user) =>
|
|
175
|
+
this.recordUUID({
|
|
176
|
+
id: user.id,
|
|
177
|
+
// CI endpoints don't use the same user format as actors, so, email may
|
|
178
|
+
// be in one of a few fields
|
|
179
|
+
emailAddress: user.email || user.emailAddress,
|
|
180
|
+
})
|
|
181
|
+
)
|
|
182
|
+
);
|
|
177
183
|
},
|
|
178
184
|
|
|
179
185
|
/**
|
|
@@ -185,7 +191,8 @@ const User = WebexPlugin.extend({
|
|
|
185
191
|
*/
|
|
186
192
|
@oneFlight({keyFactory: (email, options) => email + String(options && options.create)})
|
|
187
193
|
getUUID(email, options) {
|
|
188
|
-
return this.store
|
|
194
|
+
return this.store
|
|
195
|
+
.getByEmail(email)
|
|
189
196
|
.then((user) => {
|
|
190
197
|
if (options && options.create && !user.userExists) {
|
|
191
198
|
return Promise.reject(new Error('User for specified email cannot be confirmed to exist'));
|
|
@@ -248,15 +255,16 @@ const User = WebexPlugin.extend({
|
|
|
248
255
|
* @returns {Promise} Resolves with a response from PATCH request
|
|
249
256
|
*/
|
|
250
257
|
_setUser(body) {
|
|
251
|
-
return this.webex.credentials.getUserToken()
|
|
252
|
-
|
|
258
|
+
return this.webex.credentials.getUserToken().then((token) =>
|
|
259
|
+
this.request({
|
|
253
260
|
uri: `${this.webex.config.credentials.setPasswordUrl}/${this.webex.internal.device.userId}`,
|
|
254
261
|
method: 'PATCH',
|
|
255
262
|
headers: {
|
|
256
|
-
authorization: token.toString()
|
|
263
|
+
authorization: token.toString(),
|
|
257
264
|
},
|
|
258
|
-
body
|
|
259
|
-
})
|
|
265
|
+
body,
|
|
266
|
+
})
|
|
267
|
+
);
|
|
260
268
|
},
|
|
261
269
|
|
|
262
270
|
/**
|
|
@@ -276,13 +284,12 @@ const User = WebexPlugin.extend({
|
|
|
276
284
|
|
|
277
285
|
return this._setUser({
|
|
278
286
|
schemas: ['urn:scim:schemas:core:1.0', 'urn:scim:schemas:extension:cisco:commonidentity:1.0'],
|
|
279
|
-
password: options.password
|
|
280
|
-
})
|
|
281
|
-
.
|
|
282
|
-
this.hasPassword = true;
|
|
287
|
+
password: options.password,
|
|
288
|
+
}).then((res) => {
|
|
289
|
+
this.hasPassword = true;
|
|
283
290
|
|
|
284
|
-
|
|
285
|
-
|
|
291
|
+
return res.body;
|
|
292
|
+
});
|
|
286
293
|
},
|
|
287
294
|
|
|
288
295
|
/**
|
|
@@ -296,15 +303,16 @@ const User = WebexPlugin.extend({
|
|
|
296
303
|
*/
|
|
297
304
|
updateName({givenName, familyName, displayName} = {}) {
|
|
298
305
|
if (!(givenName || familyName || displayName)) {
|
|
299
|
-
return Promise.reject(
|
|
306
|
+
return Promise.reject(
|
|
307
|
+
new Error('One of `givenName` and `familyName` or `displayName` is required')
|
|
308
|
+
);
|
|
300
309
|
}
|
|
301
310
|
|
|
302
311
|
return this._setUser({
|
|
303
312
|
schemas: ['urn:scim:schemas:core:1.0', 'urn:scim:schemas:extension:cisco:commonidentity:1.0'],
|
|
304
313
|
name: {givenName, familyName},
|
|
305
|
-
displayName
|
|
306
|
-
})
|
|
307
|
-
.then((res) => res.body);
|
|
314
|
+
displayName,
|
|
315
|
+
}).then((res) => res.body);
|
|
308
316
|
},
|
|
309
317
|
|
|
310
318
|
/**
|
|
@@ -323,9 +331,8 @@ const User = WebexPlugin.extend({
|
|
|
323
331
|
method: 'PATCH',
|
|
324
332
|
service: 'conversation',
|
|
325
333
|
resource: 'users/user',
|
|
326
|
-
body: options
|
|
327
|
-
})
|
|
328
|
-
.then((res) => res.body);
|
|
334
|
+
body: options,
|
|
335
|
+
}).then((res) => res.body);
|
|
329
336
|
},
|
|
330
337
|
|
|
331
338
|
/**
|
|
@@ -339,7 +346,11 @@ const User = WebexPlugin.extend({
|
|
|
339
346
|
*/
|
|
340
347
|
validateOTP(options = {}) {
|
|
341
348
|
if (!(options.email || options.id) || !options.oneTimePassword) {
|
|
342
|
-
return Promise.reject(
|
|
349
|
+
return Promise.reject(
|
|
350
|
+
new Error(
|
|
351
|
+
'One of `options.email` or `options.id` and `options.oneTimePassword` are required'
|
|
352
|
+
)
|
|
353
|
+
);
|
|
343
354
|
}
|
|
344
355
|
|
|
345
356
|
options.scope = this.webex.config.credentials.scope;
|
|
@@ -350,14 +361,13 @@ const User = WebexPlugin.extend({
|
|
|
350
361
|
body: options,
|
|
351
362
|
auth: {
|
|
352
363
|
user: this.webex.config.credentials.client_id,
|
|
353
|
-
pass: this.webex.config.credentials.client_secret
|
|
354
|
-
}
|
|
355
|
-
})
|
|
356
|
-
.
|
|
357
|
-
this.webex.credentials.set({supertoken: res.body.tokenData});
|
|
364
|
+
pass: this.webex.config.credentials.client_secret,
|
|
365
|
+
},
|
|
366
|
+
}).then((res) => {
|
|
367
|
+
this.webex.credentials.set({supertoken: res.body.tokenData});
|
|
358
368
|
|
|
359
|
-
|
|
360
|
-
|
|
369
|
+
return res.body;
|
|
370
|
+
});
|
|
361
371
|
},
|
|
362
372
|
|
|
363
373
|
/**
|
|
@@ -370,27 +380,30 @@ const User = WebexPlugin.extend({
|
|
|
370
380
|
* @returns {Promise<Object>}
|
|
371
381
|
*/
|
|
372
382
|
verify(options) {
|
|
373
|
-
options =
|
|
383
|
+
options = {...this.config.verifyDefaults, ...options};
|
|
374
384
|
const {email} = options;
|
|
375
385
|
|
|
376
386
|
if (!email) {
|
|
377
387
|
return Promise.reject(new Error('`options.email` is required'));
|
|
378
388
|
}
|
|
379
389
|
|
|
380
|
-
return this.webex.internal.services
|
|
390
|
+
return this.webex.internal.services
|
|
391
|
+
.collectPreauthCatalog({email})
|
|
381
392
|
.then(() => this.webex.credentials.getUserToken())
|
|
382
393
|
.catch(() => this.webex.credentials.getClientToken())
|
|
383
|
-
.then((token) =>
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
+
.then((token) =>
|
|
395
|
+
this.request({
|
|
396
|
+
service: 'atlas',
|
|
397
|
+
resource: 'users/activations',
|
|
398
|
+
method: 'POST',
|
|
399
|
+
headers: {
|
|
400
|
+
authorization: token.toString(),
|
|
401
|
+
'x-prelogin-userid': options.preloginId,
|
|
402
|
+
},
|
|
403
|
+
body: options,
|
|
404
|
+
shouldRefreshAccessToken: false,
|
|
405
|
+
})
|
|
406
|
+
)
|
|
394
407
|
.then((res) => {
|
|
395
408
|
if (res.body.hasPassword || res.body.sso) {
|
|
396
409
|
this.hasPassword = true;
|
|
@@ -400,7 +413,6 @@ const User = WebexPlugin.extend({
|
|
|
400
413
|
});
|
|
401
414
|
},
|
|
402
415
|
|
|
403
|
-
|
|
404
416
|
/**
|
|
405
417
|
* If the passed-in lookupCI is true, retrieve the user's
|
|
406
418
|
* CI from Atlas and return the URL's via a Promise.
|
|
@@ -418,18 +430,16 @@ const User = WebexPlugin.extend({
|
|
|
418
430
|
// call verify first to get the user's CI, but suppress sending another email
|
|
419
431
|
const verifyOptions = {
|
|
420
432
|
email,
|
|
421
|
-
suppressEmail: true
|
|
433
|
+
suppressEmail: true,
|
|
422
434
|
};
|
|
423
435
|
|
|
424
436
|
return this.verify(verifyOptions).then((res) => Promise.resolve(res.userEntities));
|
|
425
437
|
}
|
|
426
438
|
|
|
427
|
-
return Promise.resolve(
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
}
|
|
432
|
-
);
|
|
439
|
+
return Promise.resolve({
|
|
440
|
+
idBrokerUrl: this.webex.config.credentials.idbroker.url,
|
|
441
|
+
identityUrl: this.webex.config.credentials.identity.url,
|
|
442
|
+
});
|
|
433
443
|
},
|
|
434
444
|
|
|
435
445
|
/**
|
|
@@ -450,8 +460,7 @@ const User = WebexPlugin.extend({
|
|
|
450
460
|
*/
|
|
451
461
|
_extractEmailAddress(user) {
|
|
452
462
|
return user.email || user.emailAddress || user.entryEmail || user;
|
|
453
|
-
}
|
|
454
|
-
|
|
463
|
+
},
|
|
455
464
|
});
|
|
456
465
|
|
|
457
466
|
export default User;
|