@webex/plugin-people 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.
package/src/people.js CHANGED
@@ -1,200 +1,200 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import {WebexPlugin, Page} from '@webex/webex-core';
6
- import {base64, oneFlight} from '@webex/common';
7
-
8
- import PeopleBatcher from './people-batcher';
9
-
10
- /**
11
- * @typedef {Object} PersonObject
12
- * @property {string} id - (server generated) Unique identifier for the person
13
- * @property {Array<email>} emails - Email addresses of the person
14
- * @property {string} displayName - Display name of the person
15
- * @property {isoDate} created - (server generated) The date and time that the person was created
16
- */
17
-
18
- /**
19
- * @class
20
- */
21
- const People = WebexPlugin.extend({
22
- namespace: 'People',
23
-
24
- children: {
25
- batcher: PeopleBatcher,
26
- },
27
- /**
28
- * Returns a single person by ID
29
- * @instance
30
- * @memberof People
31
- * @param {PersonObject|uuid|string} person
32
- * @returns {Promise<PersonObject>}
33
- * @example
34
- * webex.rooms.create({title: 'Get Person Example'})
35
- * .then(function(room) {
36
- * return webex.memberships.create({
37
- * personEmail: 'alice@example.com',
38
- * roomId: room.id
39
- * });
40
- * })
41
- * .then(function(membership) {
42
- * return webex.people.get(membership.personId);
43
- * })
44
- * .then(function(alice) {
45
- * var assert = require('assert');
46
- * assert(alice.id);
47
- * assert(Array.isArray(alice.emails));
48
- * assert.equal(alice.emails.filter(function(email) {
49
- * return email === 'alice@example.com';
50
- * }).length, 1);
51
- * assert(alice.displayName);
52
- * assert(alice.created);
53
- * return 'success';
54
- * });
55
- * // => success
56
- */
57
- get(person) {
58
- if (!person) {
59
- return Promise.reject(new Error('A person with an id is required'));
60
- }
61
- if (person === 'me') {
62
- return this._getMe();
63
- }
64
- const id = person.personId || person.id || person;
65
-
66
- return this.batcher.request(id);
67
- },
68
-
69
- /**
70
- * Returns a list of people
71
- * @instance
72
- * @memberof People
73
- * @param {Object | uuid[]} options or array of uuids
74
- * @param {email} options.email - Returns people with an email that contains this string
75
- * @param {string} options.displayName - Returns people with a name that contains this string
76
- * @param {bool} showAllTypes optional flag that requires Hydra to send every type field,
77
- * even if the type is not "person" (e.g.: SX10, webhook_integration, etc.)
78
- * @returns {Promise<Page<PersonObject>>}
79
- * @example
80
- * var room;
81
- * webex.rooms.create({title: 'List People Example'})
82
- * .then(function(r) {
83
- * room = r;
84
- * return webex.memberships.create({
85
- * personEmail: 'alice@example.com',
86
- * roomId: room.id
87
- * });
88
- * })
89
- * .then(function() {
90
- * return webex.memberships.create({
91
- * personEmail: 'bob@example.com',
92
- * roomId: room.id
93
- * });
94
- * })
95
- * .then(function() {
96
- * return webex.people.list({email: 'alice@example.com'});
97
- * })
98
- * .then(function(people) {
99
- * var assert = require('assert');
100
- * assert.equal(people.length, 1);
101
- * var person = people.items[0];
102
- * assert(person.id);
103
- * assert(Array.isArray(person.emails));
104
- * assert(person.displayName);
105
- * assert(person.created);
106
- * return 'success';
107
- * });
108
- * // => success
109
- * @example <caption>Example usage of array method</caption>
110
- * var room;
111
- * var aliceId;
112
- * var bobId;
113
- * webex.rooms.create({title: 'List People Array Example'})
114
- * .then(function(r) {
115
- * room = r;
116
- * return webex.memberships.create({
117
- * personEmail: 'alice@example.com',
118
- * roomId: room.id
119
- * });
120
- * })
121
- * .then(function(membership) {
122
- * aliceId = membership.personId;
123
- * })
124
- * .then(function() {
125
- * return webex.memberships.create({
126
- * personEmail: 'bob@example.com',
127
- * roomId: room.id
128
- * });
129
- * })
130
- * .then(function(membership) {
131
- * bobId = membership.personId;
132
- * })
133
- * .then(function() {
134
- * return webex.people.list([aliceId, bobId]);
135
- * })
136
- * .then(function(people) {
137
- * var assert = require('assert');
138
- * assert.equal(people.length, 2);
139
- * var person = people.items[0];
140
- * assert(person.id);
141
- * assert(Array.isArray(person.emails));
142
- * assert(person.displayName);
143
- * assert(person.created);
144
- * return 'success';
145
- * });
146
- * // => success
147
- */
148
- list(options) {
149
- if (Array.isArray(options)) {
150
- const peopleIds = options;
151
-
152
- return Promise.all(peopleIds.map((personId) => this.batcher.request(personId)));
153
- }
154
-
155
- return this.request({
156
- service: 'hydra',
157
- resource: 'people',
158
- qs: options,
159
- }).then((res) => new Page(res, this.webex));
160
- },
161
-
162
- /**
163
- * Converts a uuid to a hydra id without a network dip.
164
- * @param {string} id
165
- * @private
166
- * @returns {string}
167
- */
168
- inferPersonIdFromUuid(id) {
169
- // base64.validate seems to return true for uuids, so we need a different
170
- // check
171
- try {
172
- if (base64.decode(id).includes('ciscospark://')) {
173
- return id;
174
- }
175
- } catch (err) {
176
- // ignore
177
- }
178
-
179
- return base64.encode(`ciscospark://us/PEOPLE/${id}`);
180
- },
181
-
182
- /**
183
- * Fetches the current user from the /people/me endpoint
184
- * @instance
185
- * @memberof People
186
- * @private
187
- * @returns {Promise<PersonObject>}
188
- */
189
- @oneFlight
190
- _getMe() {
191
- return this.webex
192
- .request({
193
- service: 'hydra',
194
- resource: 'people/me',
195
- })
196
- .then((res) => res.body);
197
- },
198
- });
199
-
200
- export default People;
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import {WebexPlugin, Page} from '@webex/webex-core';
6
+ import {base64, oneFlight} from '@webex/common';
7
+
8
+ import PeopleBatcher from './people-batcher';
9
+
10
+ /**
11
+ * @typedef {Object} PersonObject
12
+ * @property {string} id - (server generated) Unique identifier for the person
13
+ * @property {Array<email>} emails - Email addresses of the person
14
+ * @property {string} displayName - Display name of the person
15
+ * @property {isoDate} created - (server generated) The date and time that the person was created
16
+ */
17
+
18
+ /**
19
+ * @class
20
+ */
21
+ const People = WebexPlugin.extend({
22
+ namespace: 'People',
23
+
24
+ children: {
25
+ batcher: PeopleBatcher,
26
+ },
27
+ /**
28
+ * Returns a single person by ID
29
+ * @instance
30
+ * @memberof People
31
+ * @param {PersonObject|uuid|string} person
32
+ * @returns {Promise<PersonObject>}
33
+ * @example
34
+ * webex.rooms.create({title: 'Get Person Example'})
35
+ * .then(function(room) {
36
+ * return webex.memberships.create({
37
+ * personEmail: 'alice@example.com',
38
+ * roomId: room.id
39
+ * });
40
+ * })
41
+ * .then(function(membership) {
42
+ * return webex.people.get(membership.personId);
43
+ * })
44
+ * .then(function(alice) {
45
+ * var assert = require('assert');
46
+ * assert(alice.id);
47
+ * assert(Array.isArray(alice.emails));
48
+ * assert.equal(alice.emails.filter(function(email) {
49
+ * return email === 'alice@example.com';
50
+ * }).length, 1);
51
+ * assert(alice.displayName);
52
+ * assert(alice.created);
53
+ * return 'success';
54
+ * });
55
+ * // => success
56
+ */
57
+ get(person) {
58
+ if (!person) {
59
+ return Promise.reject(new Error('A person with an id is required'));
60
+ }
61
+ if (person === 'me') {
62
+ return this._getMe();
63
+ }
64
+ const id = person.personId || person.id || person;
65
+
66
+ return this.batcher.request(id);
67
+ },
68
+
69
+ /**
70
+ * Returns a list of people
71
+ * @instance
72
+ * @memberof People
73
+ * @param {Object | uuid[]} options or array of uuids
74
+ * @param {email} options.email - Returns people with an email that contains this string
75
+ * @param {string} options.displayName - Returns people with a name that contains this string
76
+ * @param {bool} showAllTypes optional flag that requires Hydra to send every type field,
77
+ * even if the type is not "person" (e.g.: SX10, webhook_integration, etc.)
78
+ * @returns {Promise<Page<PersonObject>>}
79
+ * @example
80
+ * var room;
81
+ * webex.rooms.create({title: 'List People Example'})
82
+ * .then(function(r) {
83
+ * room = r;
84
+ * return webex.memberships.create({
85
+ * personEmail: 'alice@example.com',
86
+ * roomId: room.id
87
+ * });
88
+ * })
89
+ * .then(function() {
90
+ * return webex.memberships.create({
91
+ * personEmail: 'bob@example.com',
92
+ * roomId: room.id
93
+ * });
94
+ * })
95
+ * .then(function() {
96
+ * return webex.people.list({email: 'alice@example.com'});
97
+ * })
98
+ * .then(function(people) {
99
+ * var assert = require('assert');
100
+ * assert.equal(people.length, 1);
101
+ * var person = people.items[0];
102
+ * assert(person.id);
103
+ * assert(Array.isArray(person.emails));
104
+ * assert(person.displayName);
105
+ * assert(person.created);
106
+ * return 'success';
107
+ * });
108
+ * // => success
109
+ * @example <caption>Example usage of array method</caption>
110
+ * var room;
111
+ * var aliceId;
112
+ * var bobId;
113
+ * webex.rooms.create({title: 'List People Array Example'})
114
+ * .then(function(r) {
115
+ * room = r;
116
+ * return webex.memberships.create({
117
+ * personEmail: 'alice@example.com',
118
+ * roomId: room.id
119
+ * });
120
+ * })
121
+ * .then(function(membership) {
122
+ * aliceId = membership.personId;
123
+ * })
124
+ * .then(function() {
125
+ * return webex.memberships.create({
126
+ * personEmail: 'bob@example.com',
127
+ * roomId: room.id
128
+ * });
129
+ * })
130
+ * .then(function(membership) {
131
+ * bobId = membership.personId;
132
+ * })
133
+ * .then(function() {
134
+ * return webex.people.list([aliceId, bobId]);
135
+ * })
136
+ * .then(function(people) {
137
+ * var assert = require('assert');
138
+ * assert.equal(people.length, 2);
139
+ * var person = people.items[0];
140
+ * assert(person.id);
141
+ * assert(Array.isArray(person.emails));
142
+ * assert(person.displayName);
143
+ * assert(person.created);
144
+ * return 'success';
145
+ * });
146
+ * // => success
147
+ */
148
+ list(options) {
149
+ if (Array.isArray(options)) {
150
+ const peopleIds = options;
151
+
152
+ return Promise.all(peopleIds.map((personId) => this.batcher.request(personId)));
153
+ }
154
+
155
+ return this.request({
156
+ service: 'hydra',
157
+ resource: 'people',
158
+ qs: options,
159
+ }).then((res) => new Page(res, this.webex));
160
+ },
161
+
162
+ /**
163
+ * Converts a uuid to a hydra id without a network dip.
164
+ * @param {string} id
165
+ * @private
166
+ * @returns {string}
167
+ */
168
+ inferPersonIdFromUuid(id) {
169
+ // base64.validate seems to return true for uuids, so we need a different
170
+ // check
171
+ try {
172
+ if (base64.decode(id).includes('ciscospark://')) {
173
+ return id;
174
+ }
175
+ } catch (err) {
176
+ // ignore
177
+ }
178
+
179
+ return base64.encode(`ciscospark://us/PEOPLE/${id}`);
180
+ },
181
+
182
+ /**
183
+ * Fetches the current user from the /people/me endpoint
184
+ * @instance
185
+ * @memberof People
186
+ * @private
187
+ * @returns {Promise<PersonObject>}
188
+ */
189
+ @oneFlight
190
+ _getMe() {
191
+ return this.webex
192
+ .request({
193
+ service: 'hydra',
194
+ resource: 'people/me',
195
+ })
196
+ .then((res) => res.body);
197
+ },
198
+ });
199
+
200
+ export default People;