@webex/internal-plugin-user 2.59.2 → 2.59.3-next.1

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,128 +1,128 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import {Batcher, WebexPlugin} from '@webex/webex-core';
6
-
7
- /**
8
- * @class
9
- */
10
- const AbstractUserUUIDRequestBatcher = Batcher.extend({
11
- namespace: 'User',
12
-
13
- /**
14
- * @param {string} item
15
- * @returns {Promise<Object>}
16
- */
17
- prepareItem(item) {
18
- return Promise.resolve({email: item});
19
- },
20
-
21
- /**
22
- * @param {HttpResponseObject} res
23
- * @returns {Promise}
24
- */
25
- handleHttpSuccess(res) {
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
- }
31
-
32
- return this.handleItemFailure(email, res.body[email]);
33
- })
34
- );
35
- },
36
-
37
- handleItemFailure(email, response) {
38
- return this.getDeferredForResponse(email).then((defer) => {
39
- defer.reject(response);
40
- });
41
- },
42
-
43
- /**
44
- * @param {string} email
45
- * @param {Object} response
46
- * @returns {Promise}
47
- */
48
- handleItemSuccess(email, response) {
49
- return this.getDeferredForResponse(email).then((defer) => {
50
- defer.resolve(response);
51
- });
52
- },
53
-
54
- /**
55
- * @param {string} email
56
- * @returns {Promise<string>}
57
- */
58
- fingerprintRequest(email) {
59
- return Promise.resolve(email.email || email);
60
- },
61
-
62
- /**
63
- * @param {string} email
64
- * @returns {Promise<string>}
65
- */
66
- fingerprintResponse(email) {
67
- return Promise.resolve(email);
68
- },
69
- });
70
-
71
- /**
72
- * @class
73
- */
74
- const FakeUserUUIDRequestBatcher = AbstractUserUUIDRequestBatcher.extend({
75
- /**
76
- * @param {Object} payload
77
- * @returns {Promise<HttpResponseObject>}
78
- */
79
- submitHttpRequest(payload) {
80
- return this.webex.request({
81
- method: 'POST',
82
- service: 'conversation',
83
- resource: '/users',
84
- body: payload,
85
- });
86
- },
87
- });
88
-
89
- /**
90
- * @class
91
- */
92
- const RealUserUUIDRequestBatcher = AbstractUserUUIDRequestBatcher.extend({
93
- /**
94
- * @param {Object} payload
95
- * @returns {Promise<HttpResponseObject>}
96
- */
97
- submitHttpRequest(payload) {
98
- return this.webex.request({
99
- method: 'POST',
100
- service: 'conversation',
101
- resource: '/users',
102
- body: payload,
103
- qs: {
104
- shouldCreateUsers: true,
105
- },
106
- });
107
- },
108
- });
109
-
110
- /**
111
- * @class
112
- */
113
- const UserUUIDBatcher = WebexPlugin.extend({
114
- children: {
115
- faker: FakeUserUUIDRequestBatcher,
116
- creator: RealUserUUIDRequestBatcher,
117
- },
118
-
119
- /**
120
- * @param {Object} payload
121
- * @returns {Promise<Object>}
122
- */
123
- request(payload) {
124
- return payload.create ? this.creator.request(payload.email) : this.faker.request(payload.email);
125
- },
126
- });
127
-
128
- export default UserUUIDBatcher;
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import {Batcher, WebexPlugin} from '@webex/webex-core';
6
+
7
+ /**
8
+ * @class
9
+ */
10
+ const AbstractUserUUIDRequestBatcher = Batcher.extend({
11
+ namespace: 'User',
12
+
13
+ /**
14
+ * @param {string} item
15
+ * @returns {Promise<Object>}
16
+ */
17
+ prepareItem(item) {
18
+ return Promise.resolve({email: item});
19
+ },
20
+
21
+ /**
22
+ * @param {HttpResponseObject} res
23
+ * @returns {Promise}
24
+ */
25
+ handleHttpSuccess(res) {
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
+ }
31
+
32
+ return this.handleItemFailure(email, res.body[email]);
33
+ })
34
+ );
35
+ },
36
+
37
+ handleItemFailure(email, response) {
38
+ return this.getDeferredForResponse(email).then((defer) => {
39
+ defer.reject(response);
40
+ });
41
+ },
42
+
43
+ /**
44
+ * @param {string} email
45
+ * @param {Object} response
46
+ * @returns {Promise}
47
+ */
48
+ handleItemSuccess(email, response) {
49
+ return this.getDeferredForResponse(email).then((defer) => {
50
+ defer.resolve(response);
51
+ });
52
+ },
53
+
54
+ /**
55
+ * @param {string} email
56
+ * @returns {Promise<string>}
57
+ */
58
+ fingerprintRequest(email) {
59
+ return Promise.resolve(email.email || email);
60
+ },
61
+
62
+ /**
63
+ * @param {string} email
64
+ * @returns {Promise<string>}
65
+ */
66
+ fingerprintResponse(email) {
67
+ return Promise.resolve(email);
68
+ },
69
+ });
70
+
71
+ /**
72
+ * @class
73
+ */
74
+ const FakeUserUUIDRequestBatcher = AbstractUserUUIDRequestBatcher.extend({
75
+ /**
76
+ * @param {Object} payload
77
+ * @returns {Promise<HttpResponseObject>}
78
+ */
79
+ submitHttpRequest(payload) {
80
+ return this.webex.request({
81
+ method: 'POST',
82
+ service: 'conversation',
83
+ resource: '/users',
84
+ body: payload,
85
+ });
86
+ },
87
+ });
88
+
89
+ /**
90
+ * @class
91
+ */
92
+ const RealUserUUIDRequestBatcher = AbstractUserUUIDRequestBatcher.extend({
93
+ /**
94
+ * @param {Object} payload
95
+ * @returns {Promise<HttpResponseObject>}
96
+ */
97
+ submitHttpRequest(payload) {
98
+ return this.webex.request({
99
+ method: 'POST',
100
+ service: 'conversation',
101
+ resource: '/users',
102
+ body: payload,
103
+ qs: {
104
+ shouldCreateUsers: true,
105
+ },
106
+ });
107
+ },
108
+ });
109
+
110
+ /**
111
+ * @class
112
+ */
113
+ const UserUUIDBatcher = WebexPlugin.extend({
114
+ children: {
115
+ faker: FakeUserUUIDRequestBatcher,
116
+ creator: RealUserUUIDRequestBatcher,
117
+ },
118
+
119
+ /**
120
+ * @param {Object} payload
121
+ * @returns {Promise<Object>}
122
+ */
123
+ request(payload) {
124
+ return payload.create ? this.creator.request(payload.email) : this.faker.request(payload.email);
125
+ },
126
+ });
127
+
128
+ export default UserUUIDBatcher;
@@ -1,105 +1,105 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import {patterns} from '@webex/common';
6
-
7
- const usersByEmail = new WeakMap();
8
- const usersById = new WeakMap();
9
-
10
- /**
11
- * @class
12
- */
13
- export default class UserUUIDStore {
14
- /**
15
- * @constructs {UserUUIDStore}
16
- */
17
- constructor() {
18
- usersByEmail.set(this, new Map());
19
- usersById.set(this, new Map());
20
- }
21
-
22
- /**
23
- * Adds a user object to the store
24
- * @param {Object} user
25
- * @param {string} user.id
26
- * @param {string} user.emailAddress
27
- * @returns {Promise}
28
- */
29
- add(user) {
30
- if (!user.id) {
31
- return Promise.reject(new Error('`user.id` is required'));
32
- }
33
-
34
- if (!user.emailAddress) {
35
- return Promise.reject(new Error('`user.emailAddress` is required'));
36
- }
37
-
38
- if (!patterns.uuid.test(user.id)) {
39
- return Promise.reject(new Error('`user.id` does not appear to be a uuid'));
40
- }
41
-
42
- if (!patterns.email.test(user.emailAddress)) {
43
- return Promise.reject(
44
- new Error('`user.emailAddress` does not appear to be an email address')
45
- );
46
- }
47
-
48
- const p1 = this.getById(user.id)
49
- .then((u) => usersById.get(this).set(user.id, {...u, ...user}))
50
- .catch(() => usersById.get(this).set(user.id, {...user}));
51
-
52
- const p2 = this.getByEmail(user.emailAddress)
53
- .then((u) => usersByEmail.get(this).set(user.emailAddress, {...u, ...user}))
54
- .catch(() => usersByEmail.get(this).set(user.emailAddress, {...user}));
55
-
56
- return Promise.all([p1, p2]);
57
- }
58
-
59
- /**
60
- * Retrieves the specified user object from the store
61
- * @param {string} id
62
- * @returns {Promise<Object>}
63
- */
64
- get(id) {
65
- if (patterns.uuid.test(id)) {
66
- return this.getById(id);
67
- }
68
-
69
- if (patterns.email.test(id)) {
70
- return this.getByEmail(id);
71
- }
72
-
73
- return Promise.reject(new Error('`id` does not appear to be a valid user identifier'));
74
- }
75
-
76
- /**
77
- * Retrieves the specified user object by id from the store
78
- * @param {Object} id
79
- * @returns {Promise<Object>}
80
- */
81
- getById(id) {
82
- const ret = usersById.get(this).get(id);
83
-
84
- if (ret) {
85
- return Promise.resolve(ret);
86
- }
87
-
88
- return Promise.reject(new Error('No user found by specified id'));
89
- }
90
-
91
- /**
92
- * Retrieves the specified user object by id from the store
93
- * @param {Object} email
94
- * @returns {Promise<Object>}
95
- */
96
- getByEmail(email) {
97
- const ret = usersByEmail.get(this).get(email);
98
-
99
- if (ret) {
100
- return Promise.resolve(ret);
101
- }
102
-
103
- return Promise.reject(new Error('No user found by specified email address'));
104
- }
105
- }
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import {patterns} from '@webex/common';
6
+
7
+ const usersByEmail = new WeakMap();
8
+ const usersById = new WeakMap();
9
+
10
+ /**
11
+ * @class
12
+ */
13
+ export default class UserUUIDStore {
14
+ /**
15
+ * @constructs {UserUUIDStore}
16
+ */
17
+ constructor() {
18
+ usersByEmail.set(this, new Map());
19
+ usersById.set(this, new Map());
20
+ }
21
+
22
+ /**
23
+ * Adds a user object to the store
24
+ * @param {Object} user
25
+ * @param {string} user.id
26
+ * @param {string} user.emailAddress
27
+ * @returns {Promise}
28
+ */
29
+ add(user) {
30
+ if (!user.id) {
31
+ return Promise.reject(new Error('`user.id` is required'));
32
+ }
33
+
34
+ if (!user.emailAddress) {
35
+ return Promise.reject(new Error('`user.emailAddress` is required'));
36
+ }
37
+
38
+ if (!patterns.uuid.test(user.id)) {
39
+ return Promise.reject(new Error('`user.id` does not appear to be a uuid'));
40
+ }
41
+
42
+ if (!patterns.email.test(user.emailAddress)) {
43
+ return Promise.reject(
44
+ new Error('`user.emailAddress` does not appear to be an email address')
45
+ );
46
+ }
47
+
48
+ const p1 = this.getById(user.id)
49
+ .then((u) => usersById.get(this).set(user.id, {...u, ...user}))
50
+ .catch(() => usersById.get(this).set(user.id, {...user}));
51
+
52
+ const p2 = this.getByEmail(user.emailAddress)
53
+ .then((u) => usersByEmail.get(this).set(user.emailAddress, {...u, ...user}))
54
+ .catch(() => usersByEmail.get(this).set(user.emailAddress, {...user}));
55
+
56
+ return Promise.all([p1, p2]);
57
+ }
58
+
59
+ /**
60
+ * Retrieves the specified user object from the store
61
+ * @param {string} id
62
+ * @returns {Promise<Object>}
63
+ */
64
+ get(id) {
65
+ if (patterns.uuid.test(id)) {
66
+ return this.getById(id);
67
+ }
68
+
69
+ if (patterns.email.test(id)) {
70
+ return this.getByEmail(id);
71
+ }
72
+
73
+ return Promise.reject(new Error('`id` does not appear to be a valid user identifier'));
74
+ }
75
+
76
+ /**
77
+ * Retrieves the specified user object by id from the store
78
+ * @param {Object} id
79
+ * @returns {Promise<Object>}
80
+ */
81
+ getById(id) {
82
+ const ret = usersById.get(this).get(id);
83
+
84
+ if (ret) {
85
+ return Promise.resolve(ret);
86
+ }
87
+
88
+ return Promise.reject(new Error('No user found by specified id'));
89
+ }
90
+
91
+ /**
92
+ * Retrieves the specified user object by id from the store
93
+ * @param {Object} email
94
+ * @returns {Promise<Object>}
95
+ */
96
+ getByEmail(email) {
97
+ const ret = usersByEmail.get(this).get(email);
98
+
99
+ if (ret) {
100
+ return Promise.resolve(ret);
101
+ }
102
+
103
+ return Promise.reject(new Error('No user found by specified email address'));
104
+ }
105
+ }