epicenter-libs 3.33.0 → 3.34.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.
Files changed (76) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/browser/epicenter.js +105 -2
  3. package/dist/browser/epicenter.js.map +1 -1
  4. package/dist/cjs/epicenter.js +105 -2
  5. package/dist/cjs/epicenter.js.map +1 -1
  6. package/dist/epicenter.js +105 -2
  7. package/dist/epicenter.js.map +1 -1
  8. package/dist/epicenter.min.js +1 -1
  9. package/dist/epicenter.min.js.map +1 -1
  10. package/dist/module/epicenter.js +105 -2
  11. package/dist/module/epicenter.js.map +1 -1
  12. package/dist/types/adapters/chat.d.ts +63 -0
  13. package/package.json +1 -1
  14. package/src/adapters/chat.ts +95 -0
  15. package/src/utils/identification.ts +4 -0
  16. package/dist/test/_virtual/runtime.js +0 -3
  17. package/dist/test/_virtual/runtime2.js +0 -3
  18. package/dist/test/adapters/account.js +0 -169
  19. package/dist/test/adapters/admin.js +0 -53
  20. package/dist/test/adapters/asset.js +0 -425
  21. package/dist/test/adapters/authentication.js +0 -349
  22. package/dist/test/adapters/channel.js +0 -201
  23. package/dist/test/adapters/chat.js +0 -199
  24. package/dist/test/adapters/cometd.js +0 -514
  25. package/dist/test/adapters/consensus.js +0 -484
  26. package/dist/test/adapters/daily.js +0 -244
  27. package/dist/test/adapters/email.js +0 -179
  28. package/dist/test/adapters/episode.js +0 -175
  29. package/dist/test/adapters/group.js +0 -655
  30. package/dist/test/adapters/leaderboard.js +0 -162
  31. package/dist/test/adapters/matchmaker.js +0 -159
  32. package/dist/test/adapters/presence.js +0 -85
  33. package/dist/test/adapters/project.js +0 -94
  34. package/dist/test/adapters/recaptcha.js +0 -24
  35. package/dist/test/adapters/run.js +0 -1008
  36. package/dist/test/adapters/somebody.js +0 -154
  37. package/dist/test/adapters/task.js +0 -192
  38. package/dist/test/adapters/time.js +0 -28
  39. package/dist/test/adapters/user.js +0 -105
  40. package/dist/test/adapters/vault.js +0 -403
  41. package/dist/test/adapters/video.js +0 -249
  42. package/dist/test/adapters/vonage.js +0 -130
  43. package/dist/test/adapters/wallet.js +0 -130
  44. package/dist/test/adapters/world.js +0 -507
  45. package/dist/test/apis/video.js +0 -294
  46. package/dist/test/apis/vonage.js +0 -121
  47. package/dist/test/epicenter.js +0 -121
  48. package/dist/test/node_modules/@babel/runtime/helpers/esm/defineProperty.js +0 -12
  49. package/dist/test/node_modules/@babel/runtime/helpers/esm/toPrimitive.js +0 -14
  50. package/dist/test/node_modules/@babel/runtime/helpers/esm/toPropertyKey.js +0 -9
  51. package/dist/test/node_modules/@babel/runtime/helpers/esm/typeof.js +0 -11
  52. package/dist/test/node_modules/cometd/AckExtension.js +0 -91
  53. package/dist/test/node_modules/cometd/CallbackPollingTransport.js +0 -148
  54. package/dist/test/node_modules/cometd/Client.js +0 -2160
  55. package/dist/test/node_modules/cometd/Extension.js +0 -47
  56. package/dist/test/node_modules/cometd/LongPollingTransport.js +0 -135
  57. package/dist/test/node_modules/cometd/ReloadExtension.js +0 -214
  58. package/dist/test/node_modules/cometd/RequestTransport.js +0 -252
  59. package/dist/test/node_modules/cometd/Transport.js +0 -167
  60. package/dist/test/node_modules/cometd/TransportRegistry.js +0 -107
  61. package/dist/test/node_modules/cometd/WebSocketTransport.js +0 -384
  62. package/dist/test/node_modules/cometd/cometd.js +0 -9
  63. package/dist/test/node_modules/regenerator-runtime/runtime.js +0 -773
  64. package/dist/test/utilities.js +0 -17
  65. package/dist/test/utils/config.js +0 -189
  66. package/dist/test/utils/constants.js +0 -293
  67. package/dist/test/utils/cookies.js +0 -75
  68. package/dist/test/utils/error-manager.js +0 -57
  69. package/dist/test/utils/error.js +0 -12
  70. package/dist/test/utils/fault.js +0 -34
  71. package/dist/test/utils/filter-parser.js +0 -68
  72. package/dist/test/utils/helpers.js +0 -9
  73. package/dist/test/utils/identification.js +0 -161
  74. package/dist/test/utils/result.js +0 -20
  75. package/dist/test/utils/router.js +0 -551
  76. package/dist/test/utils/store.js +0 -79
@@ -1,655 +0,0 @@
1
- import { ROLE } from '../utils/constants.js';
2
- import '../utils/helpers.js';
3
- import { parseFilterInput } from '../utils/filter-parser.js';
4
- import EpicenterError from '../utils/error.js';
5
- import '../utils/config.js';
6
- import identification from '../utils/identification.js';
7
- import '../utils/error-manager.js';
8
- import Router from '../utils/router.js';
9
-
10
- // Aliases for backward compatibility
11
-
12
- /**
13
- * Provides information on a particular Epicenter group.
14
- * Base URL: GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/group/{GROUP_KEY}` or GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/group/member/{GROUP_KEY}` or GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/group/quantized/{GROUP_KEY}`
15
- *
16
- * @example
17
- * import { authAdapter, groupAdapter } from 'epicenter-libs';
18
- * const session = authAdapter.getLocalSession();
19
- * // include members of the group in the response
20
- * const group = await groupAdapter.get({ groupKey: session.groupKey, augment: 'MEMBERS' });
21
- * // include metrics relating to the group in the response
22
- * const group = await groupAdapter.get({ groupKey: session.groupKey, augment: 'QUANTIZED' });
23
- *
24
- * @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
25
- * @param [optionals.augment] Specifies which additional information you'd like returned with the group
26
- * @param [optionals.groupKey] Group key; if omitted will attempt to use the group associated with the current session
27
- * @returns promise that resolves to a group
28
- */
29
- async function get(optionals = {}) {
30
- const {
31
- groupKey,
32
- augment,
33
- ...routingOptions
34
- } = optionals;
35
- let uriComponent = '';
36
- if (augment === 'MEMBERS') uriComponent = '/member';
37
- if (augment === 'QUANTIZED') uriComponent = '/quantized';
38
- const session = identification.session;
39
- return await new Router().get(`/group${uriComponent}/${groupKey !== null && groupKey !== void 0 ? groupKey : session === null || session === void 0 ? void 0 : session.groupKey}`, routingOptions).then(({
40
- body
41
- }) => body);
42
- }
43
-
44
- /**
45
- * Deletes the group; available only to Epicenter admins
46
- * Base URL: DELETE `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/group/{GROUP_KEY}`
47
- *
48
- * @example
49
- * import { groupAdapter } from 'epicenter-libs';
50
- * await groupAdapter.destroy('0000017dd3bf540e5ada5b1e058f08f20461');
51
- *
52
- * @param groupKey Key associated with group
53
- * @param [optionals] Optional arguments; pass network call options overrides here.
54
- * @returns promise that resolves to undefined if successful
55
- */
56
- async function destroy(groupKey, optionals = {}) {
57
- return await new Router().delete(`/group/${groupKey}`, optionals).then(({
58
- body
59
- }) => body);
60
- }
61
-
62
- /**
63
- * Provides information for all groups in the project
64
- * Base URL: GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/group`
65
- *
66
- * @example
67
- * import { groupAdapter } from 'epicenter-libs';
68
- * const groups = await groupAdapter.gather();
69
- *
70
- * @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
71
- * @param [optionals.includeExpired] Indicates whether to include expired groups in the query
72
- * @returns promise that resolves to a list of groups
73
- */
74
- async function gather(optionals = {}) {
75
- const {
76
- includeExpired,
77
- ...routingOptions
78
- } = optionals;
79
- return await new Router().withSearchParams({
80
- includeExpired
81
- }).get('/group', routingOptions).then(({
82
- body
83
- }) => body);
84
- }
85
-
86
- /**
87
- * Updates fields for a particular group; available only to Epicenter admins
88
- * Base URL: PATCH `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/group/{GROUP_KEY}`
89
- *
90
- * @example
91
- * import { groupAdapter } from 'epicenter-libs';
92
- * await groupAdapter.update('0000017dd3bf540e5ada5b1e058f08f20461', { event: 'Orientation Day' });
93
- *
94
- * @param groupKey Key associated with group
95
- * @param update Attributes you wish to update
96
- * @param [update.runLimit] Defines the upper limit of runs allowed in the group
97
- * @param [update.organization] Name of the organization owning the group
98
- * @param [update.allowSelfRegistration] Whether users can register to join the group without being invited
99
- * @param [update.flightRecorder] Diagnostic tool for logging HTTP requests for the server
100
- * @param [update.flightRecorder.start] Start time (epoch time)
101
- * @param [update.flightRecorder.stop] End time (epoch time)
102
- * @param [update.flightRecorder.enabled] Enabled flag for the flight recorder
103
- * @param [update.event] Name of the event the group is playing for
104
- * @param [update.allowMembershipChanges] Locks the group so members cannot be added and member permissions cannot be changed
105
- * @param [update.pricing] Group pricing information
106
- * @param [update.pricing.amount] Amount (in cents) for user signup
107
- * @param [update.startDate] Start date for group event
108
- * @param [update.expirationDate] Date the group expires
109
- * @param [update.capacity] Defines the upper limit on the number of users allowed in the group
110
- * @param [update.allowChannel] Opt into push notifications for this resource; applicable to projects with phylogeny >= SILENT
111
- * @param [optionals] Optional arguments; pass network call options overrides here.
112
- * @returns promise that resolves to the updated group
113
- */
114
- async function update(groupKey, update, optionals = {}) {
115
- const {
116
- runLimit,
117
- organization,
118
- allowSelfRegistration,
119
- flightRecorder,
120
- event,
121
- allowMembershipChanges,
122
- pricing,
123
- startDate,
124
- expirationDate,
125
- capacity,
126
- allowChannel
127
- } = update;
128
- return await new Router().patch(`/group/${groupKey}`, {
129
- body: {
130
- runLimit,
131
- organization,
132
- allowSelfRegistration,
133
- flightRecorder,
134
- event,
135
- allowMembershipChanges,
136
- pricing,
137
- startDate,
138
- expirationDate,
139
- capacity,
140
- allowChannel
141
- },
142
- ...optionals
143
- }).then(({
144
- body
145
- }) => body);
146
- }
147
-
148
- /**
149
- * Creates a new group; available only to Epicenter admins
150
- * Base URL: POST `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/group`
151
- *
152
- * @example
153
- * import { groupAdapter } from 'epicenter-libs';
154
- * const group = await groupAdapter.create({
155
- * runLimit: 10,
156
- * name: 'my-group-name',
157
- * });
158
- *
159
- * @param group Group object
160
- * @param group.name Group name (required)
161
- * @param [group.runLimit] Defines the upper limit on the number of runs allowed in the group
162
- * @param [group.organization] Name of the organization owning the group
163
- * @param [group.allowSelfRegistration] Whether users can register to join the group without being invited
164
- * @param [group.flightRecorder] Diagnostic tool for logging HTTP requests for the server
165
- * @param [group.flightRecorder.start] Start time (epoch time)
166
- * @param [group.flightRecorder.stop] End time (epoch time)
167
- * @param [group.flightRecorder.enabled] Enabled flag for the flight recorder
168
- * @param [group.event] Name of the event the group is playing for
169
- * @param [group.allowMembershipChanges] Locks the group so members cannot be added and member permissions cannot be changed
170
- * @param [group.pricing] Group pricing information
171
- * @param [group.pricing.amount] Amount (in cents) for user signup
172
- * @param [group.startDate] Start date for group event
173
- * @param [group.expirationDate] Date the group expires
174
- * @param [group.capacity] Defines the upper limit on the number of users allowed in the group
175
- * @param [group.allowChannel] Opt into push notifications for this resource; applicable to projects with phylogeny >= SILENT
176
- * @param [optionals] Optional arguments; pass network call options overrides here.
177
- * @returns promise that resolves to the newly created group
178
- */
179
- async function create(group, optionals = {}) {
180
- const {
181
- name,
182
- runLimit,
183
- organization,
184
- allowSelfRegistration,
185
- flightRecorder,
186
- event,
187
- allowMembershipChanges,
188
- pricing,
189
- startDate,
190
- expirationDate,
191
- capacity,
192
- allowChannel
193
- } = group;
194
- if (!name) throw new EpicenterError('Cannot create a group with no name');
195
- return await new Router().post('/group', {
196
- body: {
197
- name,
198
- runLimit,
199
- organization,
200
- allowSelfRegistration,
201
- flightRecorder,
202
- event,
203
- allowMembershipChanges,
204
- pricing,
205
- startDate,
206
- expirationDate,
207
- capacity,
208
- allowChannel
209
- },
210
- ...optionals
211
- }).then(({
212
- body
213
- }) => body);
214
- }
215
-
216
- /**
217
- * Queries for groups
218
- * Base URL: GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/group/search` or GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/group/quantized/search`
219
- *
220
- * @example
221
- * import { groupAdapter } from 'epicenter-libs';
222
- * const filter = [
223
- * 'name|=group1|group2', // look for groups whose name is 'group1' or 'group2'
224
- * 'groupKey=0000017dd3bf540e5ada5b1e058f08f20461', // look for groups with the specific group key
225
- * 'approximateMemberCount>30', // look for groups larger than 30
226
- * 'startDate<2022-01-03T20:30:53.054Z', // look for groups with start date before Jan 3rd 2022
227
- * 'expirationDate<2022-01-03T20:30:53.054Z', // look for groups with expiration date before Jan 3rd 2022
228
- * // 'account.shortName=acme', // specifies account, intended for admin use
229
- * // 'project.shortName=simulations', // specifies project, intended for admin use
230
- * ];
231
- * const page = await groupAdapter.query({
232
- * filter,
233
- * sort: ['+group.name'], // sort all findings by group name ascending (lexicographically)
234
- * first: 3, // page should start with the 4th item found (will default to 0)
235
- * max: 10, // page should only include the first 10 items
236
- * });
237
- *
238
- * @param searchOptions Search options for the query
239
- * @param [searchOptions.filter] Filters for searching
240
- * @param [searchOptions.sort] Sorting criteria
241
- * @param [searchOptions.first] The starting index of the page returned
242
- * @param [searchOptions.max] The number of entries per page
243
- * @param [optionals] Optional arguments; pass network call options overrides here.
244
- * @returns promise that resolves to a page of groups
245
- */
246
- async function query(searchOptions, optionals = {}) {
247
- const {
248
- filter,
249
- sort = [],
250
- first,
251
- max,
252
- quantized
253
- } = searchOptions;
254
- const searchParams = {
255
- filter: parseFilterInput(filter),
256
- sort: sort.join(';') || undefined,
257
- first,
258
- max
259
- };
260
- return await new Router().withSearchParams(searchParams).get(`/group${quantized ? '/quantized' : ''}/search`, {
261
- paginated: true,
262
- ...optionals
263
- }).then(({
264
- body
265
- }) => body);
266
- }
267
- /** DEPRECATED -- use groupAdapter.query instead */
268
- async function search(optionals = {}) {
269
- console.warn('DEPRECATION WARNING: groupAdapter.search is deprecated and will be removed with the next release. Use groupAdapter.query instead.');
270
- const {
271
- filter = [],
272
- sort = [],
273
- first,
274
- max,
275
- quantized,
276
- ...routingOptions
277
- } = optionals;
278
- const searchOptions = {
279
- filter,
280
- sort,
281
- first,
282
- max,
283
- quantized
284
- };
285
- return await query(searchOptions, routingOptions);
286
- }
287
-
288
- /**
289
- * Retrieves a group with given group name
290
- * Base URL: GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/group/with/{NAME}`
291
- *
292
- * @example
293
- * import { groupAdapter } from 'epicenter-libs';
294
- * const group = await groupAdapter.withGroupName('my-group-name');
295
- *
296
- * @param name Name associated with the group
297
- * @param [optionals] Optional arguments; pass network call options overrides here.
298
- * @returns promise that resolves to a group
299
- */
300
- async function withGroupName(name, optionals = {}) {
301
- return await new Router().get(`/group/with/${name}`, optionals).then(({
302
- body
303
- }) => body);
304
- }
305
-
306
- /**
307
- * Retrieves the list of groups a particular user is in; intended for admin use
308
- * Base URL: GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/group/member/for/{USER_KEY}`
309
- *
310
- * @example
311
- * import { groupAdapter } from 'epicenter-libs';
312
- * const groups = await groupAdapter.forUser(
313
- * '000001796733eef0842f4d6d960997018a3b', // get groups where this user is a member of
314
- * { role: ['FACILITATOR'] } // where this user is a facilitator in the group
315
- * );
316
- *
317
- * @param userKey User key associated with the user
318
- * @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
319
- * @param [optionals.includeExpired] Indicates whether to include expired groups in the query
320
- * @param [optionals.includeAllMembers] Indicates whether to include the other members in the group (by default, only the requested user appears)
321
- * @param [optionals.role] Role or list of possible roles the user holds in the group
322
- * @returns promise that resolves to a list of groups
323
- */
324
- async function forUser(userKey, optionals = {}) {
325
- const {
326
- includeExpired,
327
- includeAllMembers,
328
- role,
329
- ...routingOptions
330
- } = optionals;
331
- const isMultiple = Array.isArray(role) && role.length > 0;
332
- const roleList = isMultiple ? role : [role];
333
- const searchParams = {
334
- includeExpired,
335
- includeAllMembers,
336
- role: role ? roleList : undefined
337
- };
338
- return await new Router().withSearchParams(searchParams).get(`/group/member/for/${userKey}`, routingOptions).then(({
339
- body
340
- }) => body);
341
- }
342
-
343
- /**
344
- * Retrieves the list of groups particular to the current session
345
- * Base URL: GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/group/member`
346
- *
347
- * @example
348
- * import { groupAdapter } from 'epicenter-libs';
349
- * const groups = await groupAdapter.getSessionGroups();
350
- *
351
- * @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
352
- * @param [optionals.includeExpired] Indicates whether to include expired groups in the query
353
- * @param [optionals.includeAllMembers] Indicates whether to include the other members in the group (by default, only the requested user appears)
354
- * @param [optionals.role] Role or list of possible roles the user holds in the group
355
- * @returns promise that resolves to a list of groups
356
- */
357
- async function getSessionGroups(optionals = {}) {
358
- const {
359
- includeExpired,
360
- role,
361
- ...routingOptions
362
- } = optionals;
363
- const isMultiple = Array.isArray(role) && role.length > 0;
364
- const roleList = isMultiple ? role : [role];
365
- const searchParams = {
366
- includeExpired,
367
- role: role ? roleList : undefined
368
- };
369
- return await new Router().withSearchParams(searchParams).get('/group/member', routingOptions).then(({
370
- body
371
- }) => body);
372
- }
373
-
374
- /**
375
- * Permits a list of users to self-register for membership in a group; will only work if the group has allowSelfRegistration set to true
376
- * Base URL: POST `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/group/self/{GROUP_KEY}`
377
- *
378
- * @example
379
- * import { groupAdapter } from 'epicenter-libs';
380
- * await groupAdapter.whitelistUsers('0000017dd3bf540e5ada5b1e058f08f20461', {
381
- * allow: true,
382
- * emails: ['user1@test.com', 'user2@test.com'],
383
- * });
384
- *
385
- * @param groupKey Key associated with group
386
- * @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
387
- * @param [optionals.allow] Whether to allow or disallow self-registration for the specified users; defaults to true if unset
388
- * @param [optionals.emails] List of emails to allow or disallow; a value of "*" is interpreted as all users; defaults to all users if unset
389
- * @returns promise that resolves to undefined (indicating success)
390
- */
391
- async function whitelistUsers(groupKey, optionals = {}) {
392
- const {
393
- allow = true,
394
- emails = ['*'],
395
- ...routingOptions
396
- } = optionals;
397
- return await new Router().post(`/group/self/${groupKey}`, {
398
- body: {
399
- allow,
400
- emails
401
- },
402
- ...routingOptions
403
- }).then(({
404
- body
405
- }) => body);
406
- }
407
-
408
- /**
409
- * Retrieves a list of users allowed to self-register for membership in a group with a given groupKey
410
- * Base URL: GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/group/self/{GROUP_KEY}`
411
- *
412
- * @example
413
- * import { groupAdapter } from 'epicenter-libs';
414
- * const users = await groupAdapter.getWhitelistedUsers('0000017dd3bf540e5ada5b1e058f08f20461');
415
- *
416
- * @param groupKey Key associated with the group
417
- * @param [optionals] Optional arguments; pass network call options overrides here.
418
- * @returns promise that resolves to a list of users
419
- */
420
- async function getWhitelistedUsers(groupKey, optionals = {}) {
421
- return await new Router().get(`/group/self/${groupKey}`, optionals).then(({
422
- body
423
- }) => body);
424
- }
425
-
426
- /**
427
- * Sends an email to the specified email address with a link to complete self-registration for a group
428
- * Base URL: POST `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/registration/self/{GROUP_KEY}`
429
- *
430
- * @example
431
- * import { groupAdapter } from 'epicenter-libs';
432
- * await groupAdapter.sendRegistrationEmail('0000017dd3bf540e5ada5b1e058f08f20461', 'user1@test.com', {
433
- * redirectURL: '/login',
434
- * linkURL: '/register',
435
- * subject: 'Complete your registration!',
436
- * });
437
- *
438
- * @param groupKey Key associated with group
439
- * @param email Email address to send the link to
440
- * @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
441
- * @param [optionals.linkURL] Relative path to link sent in email to complete registration (<forio scheme>://<forio host>/app/<account>/<project><linkURL>)
442
- * @param [optionals.redirectURL] Relative path to redirect to after completing registration (<forio scheme>://<forio host>/app/<account>/<project><redirectURL>)
443
- * @param [optionals.subject] The subject of the email that will be sent
444
- * @returns promise that resolves to undefined (indicating success)
445
- */
446
- async function sendRegistrationEmail(groupKey, email, optionals = {}) {
447
- const {
448
- redirectURL,
449
- linkURL,
450
- subject,
451
- ...routingOptions
452
- } = optionals;
453
- return await new Router().post(`/registration/self/${groupKey}`, {
454
- body: {
455
- email,
456
- linkUrl: linkURL,
457
- redirectUrl: redirectURL,
458
- subject
459
- },
460
- ...routingOptions
461
- }).then(({
462
- body
463
- }) => body);
464
- }
465
-
466
- /**
467
- * Finalizes a user's self-registration process for a group; requires the project to have deployment.autoCreatePlayer set to true
468
- * Base URL: PATCH `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/registration/self/{TOKEN}`
469
- *
470
- * @example
471
- * import { groupAdapter } from 'epicenter-libs';
472
- * const result = await groupAdapter.selfRegister('myregistrationtoken', 'pass', {
473
- * displayName: 'My Display Name',
474
- * givenName: 'Leonard',
475
- * familyName: 'Nimoy',
476
- * handle: 'the_real_spock',
477
- * });
478
- *
479
- * @param token Registration token
480
- * @param password Password the user would use to log in
481
- * @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
482
- * @param [optionals.displayName] Display name chosen by user
483
- * @param [optionals.givenName] User's given name
484
- * @param [optionals.familyName] User's family name
485
- * @param [optionals.handle] Handle the user would use to log in; defaults to email address if not specified
486
- * @returns promise resolving to an object containing the redirect URL and the session
487
- */
488
- async function selfRegister(token, password, optionals = {}) {
489
- const {
490
- displayName,
491
- givenName,
492
- familyName,
493
- handle,
494
- ...routingOptions
495
- } = optionals;
496
- return await new Router().patch(`/registration/self/${token}`, {
497
- body: {
498
- password,
499
- displayName,
500
- givenName,
501
- familyName,
502
- handle
503
- },
504
- ...routingOptions
505
- }).then(({
506
- body
507
- }) => body);
508
- }
509
-
510
- /**
511
- * Adds user(s) to the group
512
- * Base URL: POST `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/group/member/{GROUP_KEY}`
513
- *
514
- * @example
515
- * import { groupAdapter } from 'epicenter-libs';
516
- * await groupAdapter.addUser('000001796733eef0842f4d6d960997018a3b');
517
- * await groupAdapter.addUser([{
518
- * userKey: '000001796733eef0842f4d6d960997018a3b',
519
- * role: 'REVIEWER',
520
- * available: false,
521
- * }]);
522
- *
523
- * @param usersInput List of user keys or user input objects (properties defined below)
524
- * @param usersInput[].userKey User key
525
- * @param [usersInput[].role] User's role; defaults to PARTICIPANT if unset; See [ROLE](#ROLE) for all types
526
- * @param [usersInput[].available] Indicates whether or not the user is 'active' (for semantic labeling); defaults to true if unset
527
- * @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
528
- * @param [optionals.groupKey] Group key to indicate the group; will default to the group key associated with the current session
529
- * @returns promise that resolves to the group the user was added to
530
- */
531
- async function addUser(usersInput, optionals = {}) {
532
- const {
533
- groupKey,
534
- ...routingOptions
535
- } = optionals;
536
- const users = Array.isArray(usersInput) ? usersInput : [usersInput];
537
- const session = identification.session;
538
- return await new Router().post(`/group/member/${groupKey !== null && groupKey !== void 0 ? groupKey : session === null || session === void 0 ? void 0 : session.groupKey}`, {
539
- body: users.map(u => {
540
- const userKey = typeof u === 'string' ? u : u.userKey;
541
- const role = typeof u === 'string' ? ROLE.PARTICIPANT : u.role;
542
- const available = typeof u === 'string' ? true : u.available;
543
- return {
544
- role,
545
- userKey,
546
- objectType: 'group',
547
- available: available !== null && available !== void 0 ? available : true
548
- };
549
- }),
550
- ...routingOptions
551
- }).then(({
552
- body
553
- }) => body);
554
- }
555
-
556
- /**
557
- * Updates a user's group membership information
558
- * Base URL: PATCH `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/group/member/{GROUP_KEY}/{USER_KEY}`
559
- *
560
- * @example
561
- * import { groupAdapter } from 'epicenter-libs';
562
- * const group = await groupAdapter.updateUser('000001796733eef0842f4d6d960997018a3b', { role: 'LEADER' });
563
- *
564
- * @param userKey User key
565
- * @param update Object containing the updates to a user's group membership information
566
- * @param [update.role] User's role; See [ROLE](#ROLE) for all types
567
- * @param [update.available] Indicates whether or not the user is 'active' (for semantic labeling)
568
- * @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
569
- * @param [optionals.groupKey] Group key; defaults to the group key associated with the current session
570
- * @returns promise that resolves to the membership information that was updated
571
- */
572
- async function updateUser(userKey, update, optionals = {}) {
573
- const {
574
- role,
575
- available
576
- } = update;
577
- const {
578
- groupKey,
579
- ...routingOptions
580
- } = optionals;
581
- const session = identification.session;
582
- return await new Router().patch(`/group/member/${groupKey !== null && groupKey !== void 0 ? groupKey : session === null || session === void 0 ? void 0 : session.groupKey}/${userKey}`, {
583
- body: {
584
- objectType: 'group',
585
- role,
586
- available
587
- },
588
- ...routingOptions
589
- }).then(({
590
- body
591
- }) => body);
592
- }
593
-
594
- /**
595
- * Removes user(s) from the group
596
- * Base URL: DELETE `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/group/member/{GROUP_KEY}/{USER_KEY}` or DELETE `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/group/member/{GROUP_KEY}` (for multiple users)
597
- *
598
- * @example
599
- * import { groupAdapter } from 'epicenter-libs';
600
- * const userKeys = members.map(({ userKey }) => userKey);
601
- * await groupAdapter.removeUser(userKeys);
602
- *
603
- * @param userKey Key associated with the user or an array of user keys to remove from group
604
- * @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
605
- * @param [optionals.groupKey] Group key for the group you want to remove from; defaults to the group in the current session
606
- * @returns promise that resolves to undefined when successful
607
- */
608
- async function removeUser(userKey, optionals = {}) {
609
- const {
610
- groupKey,
611
- ...routingOptions
612
- } = optionals;
613
- const hasMultiple = Array.isArray(userKey) && userKey.length > 1;
614
- const uriComponent = hasMultiple ? '' : `/${userKey.length === 1 ? userKey[0] : userKey}`;
615
- const searchParams = hasMultiple ? {
616
- userKey
617
- } : undefined;
618
- const session = identification.session;
619
- return await new Router().withSearchParams(searchParams).delete(`/group/member/${groupKey !== null && groupKey !== void 0 ? groupKey : session === null || session === void 0 ? void 0 : session.groupKey}${uriComponent}`, routingOptions).then(({
620
- body
621
- }) => body);
622
- }
623
-
624
- /**
625
- * Updates the status of a group
626
- * Base URL: PATCH `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/group/status/{GROUP_KEY}`
627
- *
628
- * @example
629
- * import { groupAdapter } from 'epicenter-libs';
630
- * const group = await groupAdapter.statusUpdate('active', 'Group is currently active');
631
- *
632
- * @param code Status code
633
- * @param message Status message
634
- * @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
635
- * @param [optionals.groupKey] Group key; defaults to the group key associated with the current session
636
- * @returns promise that resolves to the updated group
637
- */
638
- async function statusUpdate(code, message, optionals = {}) {
639
- const {
640
- groupKey,
641
- ...routingOptions
642
- } = optionals;
643
- const session = identification.session;
644
- return await new Router().patch(`/group/status/${groupKey !== null && groupKey !== void 0 ? groupKey : session === null || session === void 0 ? void 0 : session.groupKey}`, {
645
- body: {
646
- code,
647
- message
648
- },
649
- ...routingOptions
650
- }).then(({
651
- body
652
- }) => body);
653
- }
654
-
655
- export { addUser, create, destroy, forUser, gather, get, getSessionGroups, getWhitelistedUsers, query, removeUser, search, selfRegister, sendRegistrationEmail, statusUpdate, update, updateUser, whitelistUsers, withGroupName };