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,507 +0,0 @@
1
- import { SCOPE_BOUNDARY } from '../utils/constants.js';
2
- import '../utils/helpers.js';
3
- import '../utils/config.js';
4
- import identification from '../utils/identification.js';
5
- import '../utils/error-manager.js';
6
- import Router from '../utils/router.js';
7
-
8
- // Generic type parameter for world role names
9
-
10
- const OBJECTIVE = {
11
- MINIMUM: 'MINIMUM',
12
- MAXIMUM: 'MAXIMUM',
13
- MARGINAL: 'MARGINAL',
14
- OPTIMAL: 'OPTIMAL'
15
- };
16
- const WORLD_NAME_GENERATOR_TYPE = {
17
- colorAnimal: 'colorAnimal',
18
- sequential: 'sequential'
19
- };
20
- /**
21
- * Updates fields for a particular world
22
- * Base URL: PATCH `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/world/{WORLD_KEY}`
23
- *
24
- * @example
25
- * import { worldAdapter } from 'epicenter-libs';
26
- * await worldAdapter.update('0000017a445032dc38cb2cecd5fc13708314', { runKey: '0000018d61f1217b22ce0ae605ff00609f5e', displayName: 'World A1' });
27
- *
28
- * @param worldKey Key associated with world
29
- * @param update Attributes you wish to update
30
- * @param [update.displayName] Display name of the world
31
- * @param [update.runKey] Key for the run you want to attach to the world
32
- * @param [update.allowChannel] Opt into push notifications for this resource. Applicable to projects with phylogeny >= SILENT
33
- * @param [optionals] Optional arguments; pass network call options overrides here.
34
- * @returns promise that resolves to the world with updated attributes
35
- */
36
- async function update(worldKey, update, optionals = {}) {
37
- const {
38
- displayName,
39
- runKey,
40
- allowChannel
41
- } = update;
42
- return await new Router().patch(`/world/${worldKey}`, {
43
- body: {
44
- displayName,
45
- runKey,
46
- allowChannel
47
- },
48
- ...optionals
49
- }).then(({
50
- body
51
- }) => body);
52
- }
53
-
54
- /**
55
- * Deletes a world
56
- * Base URL: DELETE `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/world/{WORLD_KEY}`
57
- *
58
- * @example
59
- * import { worldAdapter } from 'epicenter-libs';
60
- * await worldAdapter.destroy('0000017a445032dc38cb2cecd5fc13708314');
61
- *
62
- * @param worldKey Key associated with world
63
- * @param [optionals] Optional arguments; pass network call options overrides here.
64
- * @returns promise that resolves to undefined when successful
65
- */
66
- async function destroy(worldKey, optionals = {}) {
67
- return await new Router().delete(`/world/${worldKey}`, optionals).then(({
68
- body
69
- }) => body);
70
- }
71
-
72
- /**
73
- * Creates a world
74
- * Base URL: POST `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/world/{GROUP_NAME}`
75
- *
76
- * @example
77
- * import { worldAdapter } from 'epicenter-libs';
78
- * await worldAdapter.create({ name: 'Whole New World' });
79
- *
80
- * @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
81
- * @param [optionals.name] Name of the new world (if omitted one will be provided by Epicenter). Must be unique within the world's scope.
82
- * @param [optionals.displayName] Display name of the new world
83
- * @param [optionals.groupName] Name of the group (defaults to name of group associated with session)
84
- * @param [optionals.episodeName] Name of the episode for episode scoping
85
- * @param [optionals.worldNameGenerator] Specifies how world names are generated
86
- * @param [optionals.worldNameGenerator.objectType] Can be either colorAnimal or sequential
87
- * @param [optionals.allowChannel] Opt into push notifications for this resource. Applicable to projects with phylogeny >= SILENT
88
- * @returns promise that resolves to the newly created world
89
- */
90
- async function create(optionals = {}) {
91
- const {
92
- name,
93
- displayName,
94
- groupName,
95
- episodeName,
96
- worldNameGenerator,
97
- allowChannel,
98
- ...routingOptions
99
- } = optionals;
100
- const session = identification.session;
101
- return await new Router().post(`/world/${groupName !== null && groupName !== void 0 ? groupName : session === null || session === void 0 ? void 0 : session.groupName}${episodeName ? `/${episodeName}` : ''}`, {
102
- body: {
103
- name,
104
- worldNameGenerator,
105
- displayName,
106
- allowChannel
107
- },
108
- ...routingOptions
109
- }).then(({
110
- body
111
- }) => body);
112
- }
113
-
114
- /**
115
- * Fetches the worlds in a group or episode if specified
116
- * Base URL: GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/world/{GROUP_NAME}`
117
- *
118
- * @example
119
- * // Gets all the worlds in the group attached to the session
120
- * import { worldAdapter } from 'epicenter-libs';
121
- * await worldAdapter.get();
122
- * // Gets all the worlds in the group attached to the session that the user is assigned to
123
- * import { worldAdapter } from 'epicenter-libs';
124
- * await worldAdapter.get({ mine: true });
125
- *
126
- * @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
127
- * @param [optionals.groupName] Name of the group (defaults to name of group associated with session)
128
- * @param [optionals.episodeName] Name of the episode for episode scoped worlds
129
- * @param [optionals.mine] Flag for indicating to get only the worlds the requesting user is in (based on session token)
130
- * @returns promise that resolves to a list of worlds
131
- */
132
- async function get(optionals = {}) {
133
- const {
134
- groupName,
135
- episodeName,
136
- mine,
137
- ...routingOptions
138
- } = optionals;
139
- const session = identification.session;
140
- return await new Router().withSearchParams({
141
- mine
142
- }).get(`/world/${groupName !== null && groupName !== void 0 ? groupName : session === null || session === void 0 ? void 0 : session.groupName}${episodeName ? `/${episodeName}` : ''}`, routingOptions).then(({
143
- body
144
- }) => body);
145
- }
146
-
147
- /**
148
- * Fetches the assignments (plus some world info) in a group or episode if specified
149
- * Base URL: GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/world/assignment/for/{GROUP_NAME}`
150
- *
151
- * @example
152
- * import { worldAdapter } from 'epicenter-libs';
153
- * worldAdapter.getAssignments({ mine: true });
154
- *
155
- * @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
156
- * @param [optionals.groupName] Name of the group (defaults to name of group associated with session)
157
- * @param [optionals.episodeName] Name of the episode for episode scoped worlds
158
- * @param [optionals.mine] Flag for indicating to get only the worlds the requesting user is in (based on session token)
159
- * @returns promise that resolves to a list of worlds the user is assigned to
160
- */
161
- async function getAssignments(optionals = {}) {
162
- const {
163
- groupName,
164
- episodeName,
165
- mine,
166
- ...routingOptions
167
- } = optionals;
168
- const session = identification.session;
169
- return await new Router().withSearchParams({
170
- mine
171
- }).get(`/world/assignment/for/${groupName !== null && groupName !== void 0 ? groupName : session === null || session === void 0 ? void 0 : session.groupName}${episodeName ? `/${episodeName}` : ''}`, routingOptions).then(({
172
- body
173
- }) => body);
174
- }
175
-
176
- /**
177
- * Fetches all worlds assigned to the current session's user
178
- * Base URL: GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/world/assignment`
179
- *
180
- * @example
181
- * import { worldAdapter } from 'epicenter-libs';
182
- * const worlds = await worldAdapter.getSessionWorlds();
183
- *
184
- * @param [optionals] Optional arguments; pass network call options overrides here.
185
- * @returns promise that resolves to an array of worlds assigned to the current user
186
- */
187
- async function getSessionWorlds(optionals = {}) {
188
- return await new Router().get('/world/assignment', optionals).then(({
189
- body
190
- }) => body);
191
- }
192
-
193
- /**
194
- * Automatically assigns the current session's user a world
195
- * Base URL: POST `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/world/assignment`
196
- *
197
- * @example
198
- * // Assigns user to a group-scoped world
199
- * import { worldAdapter } from 'epicenter-libs';
200
- * await worldAdapter.selfAssign();
201
- * // Assigns user to a group-scoped world with role "cartographer"
202
- * import { worldAdapter } from 'epicenter-libs';
203
- * await worldAdapter.selfAssign({ role: 'cartographer' });
204
- * // Assigns user to an episode-scoped world with role "cartographer"
205
- * import { worldAdapter } from 'epicenter-libs';
206
- * await worldAdapter.selfAssign({ role: 'cartographer', episodeName: 'my-episode-name' });
207
- *
208
- * @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
209
- * @param [optionals.role] Role constraint -- will put the user in a world with a role
210
- * @param [optionals.groupName] Name of the group (defaults to name of group associated with session)
211
- * @param [optionals.episodeName] Name of the episode for episode scoped worlds
212
- * @param [optionals.objective] Allows platform to assign users beyond minimum amount
213
- * @param [optionals.worldNameGenerator] Specifies how world names are generated
214
- * @param [optionals.worldNameGenerator.objectType] Can be either colorAnimal or sequential
215
- * @param [optionals.populace] List of role description objects (personas) to dictate the self assignment
216
- * @param [optionals.populace[].role] Name of the role
217
- * @param [optionals.populace[].minimum] The minimum number of users that required for this role
218
- * @param [optionals.populace[].maximum] The maximum number of users that can be assigned to this role
219
- * @param [optionals.populace[].marginal] The maximum number of users that can be assigned to this role when using objective MARGINAL
220
- * @param [optionals.allowChannel] Opt into push notifications for this resource. Applicable to projects with phylogeny >= SILENT
221
- * @returns promise that resolves to the world the user was assigned to
222
- */
223
- async function selfAssign(optionals = {}) {
224
- const {
225
- role,
226
- groupName,
227
- episodeName,
228
- objective = OBJECTIVE.MINIMUM,
229
- worldNameGenerator,
230
- populace,
231
- allowChannel,
232
- ...routingOptions
233
- } = optionals;
234
- const session = identification.session;
235
- return await new Router().post(`/world/selfassign/${groupName !== null && groupName !== void 0 ? groupName : session === null || session === void 0 ? void 0 : session.groupName}${episodeName ? `/${episodeName}` : ''}`, {
236
- body: {
237
- role,
238
- objective,
239
- worldNameGenerator,
240
- populace,
241
- allowChannel
242
- },
243
- ...routingOptions
244
- }).then(({
245
- body
246
- }) => body);
247
- }
248
-
249
- /**
250
- * (Auto assign) -- makes worlds given a list of users.
251
- * Base URL: POST `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/world/assignment`
252
- *
253
- * @example
254
- * import { worldAdapter } from 'epicenter-libs';
255
- * const worlds = await worldAdapter.assignUsers([
256
- * { userKey: '000001796733eef0842f4d6d960997018a43', role: 'locksmith' },
257
- * { userKey: '000001796733eef0842f4d6d960997018a3b' },
258
- * ]);
259
- *
260
- * @param assignments List of users assignment objects
261
- * @param assignments[].userKey User key
262
- * @param [assignments[].role] Role to assign to the user
263
- * @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
264
- * @param [optionals.role] Role constraint -- will put the user in a world with a role
265
- * @param [optionals.groupName] Name of the group (defaults to name of group associated with session)
266
- * @param [optionals.episodeName] Name of the episode for episode scoped worlds
267
- * @param [optionals.objective] Allows platform to assign users beyond minimum amount
268
- * @param [optionals.requireAllAssignments] Have the server return w/ an error whenever an assignment was not made (instead of silently leaving the user as unassigned)
269
- * @param [optionals.keepEmptyWorlds] Specify whether worlds that are now empty should be deleted
270
- * @param [optionals.worldNameGenerator] Specifies how world names are generated
271
- * @param [optionals.worldNameGenerator.objectType] Can be either colorAnimal or sequential
272
- * @param [optionals.populace] List of role description objects (personas) to use while creating assignments
273
- * @param [optionals.populace[].role] Name of the role
274
- * @param [optionals.populace[].minimum] The minimum number of users that required for this role
275
- * @param [optionals.populace[].maximum] The maximum number of users that can be assigned to this role
276
- * @param [optionals.populace[].marginal] The maximum number of users that can be assigned to this role when using objective MARGINAL
277
- * @param [optionals.allowChannel] Opt into push notifications for this resource. Applicable to projects with phylogeny >= SILENT
278
- * @returns promise that resolves to the list of worlds created by the assignment
279
- */
280
- async function autoAssignUsers(assignments, optionals = {}) {
281
- const {
282
- groupName,
283
- episodeName,
284
- objective = OBJECTIVE.MINIMUM,
285
- requireAllAssignments,
286
- worldNameGenerator,
287
- keepEmptyWorlds,
288
- populace,
289
- allowChannel,
290
- ...routingOptions
291
- } = optionals;
292
- const session = identification.session;
293
- return await new Router().post(`/world/assignment/${groupName !== null && groupName !== void 0 ? groupName : session === null || session === void 0 ? void 0 : session.groupName}${episodeName ? `/${episodeName}` : ''}`, {
294
- body: {
295
- assignments,
296
- objective,
297
- requireAllAssignments,
298
- worldNameGenerator,
299
- keepEmptyWorlds,
300
- populace,
301
- allowChannel
302
- },
303
- ...routingOptions
304
- }).then(({
305
- body
306
- }) => body);
307
- }
308
-
309
- /**
310
- * Edits assignments across specified worlds
311
- * Base URL: PUT `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/world/assignment/{GROUP_NAME}`
312
- *
313
- * @example
314
- * import { worldAdapter } from 'epicenter-libs';
315
- * const updatedWorlds = await worldAdapter.editAssignments({
316
- * '0000017a445032dc38cb2cecd5fc13708314': [
317
- * { userKey: '000001796733eef0842f4d6d960997018a43', role: 'locksmith' },
318
- * { userKey: '000001796733eef0842f4d6d960997018a3b' },
319
- * ],
320
- * '0000017a445032dc38cb2cecd5fc13708315': [
321
- * { userKey: '000001796733eef0842f4d6d960997018a4c', role: 'navigator' },
322
- * ],
323
- * });
324
- *
325
- * @param assignments Map of world keys to list of user assignment objects
326
- * @param assignments[].userKey User key
327
- * @param [assignments[].role] Role to assign to the user
328
- * @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
329
- * @param [optionals.groupName] Name of the group (defaults to name of group associated with session)
330
- * @param [optionals.episodeName] Name of the episode for episode scoped worlds
331
- * @param [optionals.objective] Allows platform to assign users beyond minimum amount
332
- * @param [optionals.requireAllAssignments] Have the server return w/ an error whenever an assignment was not made (instead of silently leaving the user as unassigned)
333
- * @param [optionals.keepEmptyWorlds] Specify whether worlds that are now empty should be deleted
334
- * @returns promise that resolves to the list of worlds updated by the assignment
335
- */
336
- async function editAssignments(assignments, optionals = {}) {
337
- const {
338
- groupName,
339
- episodeName,
340
- objective = OBJECTIVE.MINIMUM,
341
- requireAllAssignments,
342
- keepEmptyWorlds,
343
- ...routingOptions
344
- } = optionals;
345
- const session = identification.session;
346
- return await new Router().put(`/world/assignment/${groupName !== null && groupName !== void 0 ? groupName : session === null || session === void 0 ? void 0 : session.groupName}${episodeName ? `/${episodeName}` : ''}`, {
347
- body: {
348
- assignments,
349
- objective,
350
- requireAllAssignments,
351
- keepEmptyWorlds
352
- },
353
- ...routingOptions
354
- }).then(({
355
- body
356
- }) => body);
357
- }
358
-
359
- /**
360
- * Retrieves the current assignment information for a given world
361
- * Base URL: GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/world/assignment/{WORLD_KEY}`
362
- *
363
- * @example
364
- * import { worldAdapter } from 'epicenter-libs';
365
- * const assignments = await worldAdapter.getAssignmentsByKey(world.worldKey);
366
- *
367
- * @param worldKey Key associated with the world
368
- * @param [optionals] Optional arguments; pass network call options overrides here.
369
- * @returns promise that resolves to the world containing the assignment object
370
- */
371
- async function getAssignmentsByKey(worldKey, optionals = {}) {
372
- return await new Router().get(`/world/assignment/${worldKey}`, optionals).then(({
373
- body
374
- }) => body);
375
- }
376
-
377
- /**
378
- * Removes a user or list of users from all worlds in a given group or episode. Any worlds that do not contain users within them will be automatically deleted in the process.
379
- * Base URL: DELETE `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/world/assignment/{GROUP_NAME}`
380
- *
381
- * @example
382
- * import { worldAdapter } from 'epicenter-libs';
383
- * await worldAdapter.removeUser(user.userKey);
384
- *
385
- * @param userKeys List of keys associated with users to remove from worlds
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.groupName] Name of the group (defaults to name of group associated with session)
388
- * @param [optionals.episodeName] Name of the episode for episode scoped worlds
389
- * @param [optionals.keepEmptyWorlds] If the unassignment results in an empty world, whether to delete it
390
- * @returns promise that resolves to undefined when successful
391
- */
392
- async function removeUsers(userKeys, optionals = {}) {
393
- const {
394
- groupName,
395
- episodeName,
396
- keepEmptyWorlds,
397
- ...routingOptions
398
- } = optionals;
399
- const session = identification.session;
400
- return await new Router().withSearchParams({
401
- userKey: userKeys,
402
- keepEmptyWorlds: Boolean(keepEmptyWorlds)
403
- }).delete(`/world/assignment/${groupName !== null && groupName !== void 0 ? groupName : session === null || session === void 0 ? void 0 : session.groupName}${episodeName ? `/${episodeName}` : ''}`, routingOptions).then(({
404
- body
405
- }) => body);
406
- }
407
-
408
- /**
409
- * Gets the personas of a given scope (project, group, episode, world). Personas correspond to a role that a user in the world can be assigned to.
410
- * Base URL: GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/world/persona/{SCOPE_BOUNDARY}/{SCOPE_KEY}`
411
- *
412
- * @example
413
- * import { worldAdapter, SCOPE_BOUNDARY } from 'epicenter-libs';
414
- * await worldAdapter.getPersonas({
415
- * scopeBoundary: SCOPE_BOUNDARY.GROUP,
416
- * scopeKey: '0000017dd3bf540e5ada5b1e058f08f20461',
417
- * });
418
- *
419
- * @param scope Scope associated with the persona set (by default the scope used will be the current project). Use this to do any specific overrides.
420
- * @param scope.scopeBoundary Scope boundary, defines the type of scope; See [scope boundary](#SCOPE_BOUNDARY) for all types
421
- * @param scope.scopeKey Scope key, a unique identifier tied to the scope. E.g., if your `scopeBoundary` is `GROUP`, your `scopeKey` will be your `groupKey`; for `EPISODE`, `episodeKey`, etc.
422
- * @param [optionals] Optional arguments; pass network call options overrides here.
423
- * @returns promise that resolves to an array of personas for the specified scope
424
- */
425
- async function getPersonas(scope, optionals = {}) {
426
- const {
427
- scopeBoundary,
428
- scopeKey
429
- } = scope;
430
- const boundary = scopeBoundary || SCOPE_BOUNDARY.PROJECT;
431
- /* We will at some point remove the need to explicitly lower case this */
432
- const boundaryComponent = boundary === SCOPE_BOUNDARY.WORLD ? '' : `/${boundary.toLowerCase()}`;
433
- const scopeKeyComponent = boundary === SCOPE_BOUNDARY.PROJECT ? '' : `/${scopeKey}`;
434
- const uriComponent = `${boundaryComponent}${scopeKeyComponent}`;
435
- return await new Router().get(`/world/persona${uriComponent}`, {
436
- ...optionals
437
- }).then(({
438
- body
439
- }) => body);
440
- }
441
-
442
- /**
443
- * Sets the personas of a given scope (project, group, episode, world). Personas correspond to a role a user in the world can be assigned to.
444
- * A null value for minimum is 0, but a null maximum is uncapped. A null marginal defaults to maximum. Personas with greater specificity override more general ones (which are by default PROJECT scoped).
445
- * Base URL: POST `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/world/persona/{SCOPE_BOUNDARY}/{SCOPE_KEY}`
446
- *
447
- * @example
448
- * import { worldAdapter } from 'epicenter-libs';
449
- * const scope = {
450
- * scopeBoundary: SCOPE_BOUNDARY.GROUP,
451
- * scopeKey: '0000017dd3bf540e5ada5b1e058f08f20461',
452
- * };
453
- * const personas = [
454
- * { role: 'leader', minimum: 1 },
455
- * ];
456
- * await worldAdapter.setPersonas(personas, scope);
457
- *
458
- * @param personas List of role description objects (personas)
459
- * @param personas[].role Name of the role
460
- * @param [personas[].minimum] The minimum number of users that required for this role
461
- * @param [personas[].maximum] The maximum number of users that can be assigned to this role
462
- * @param [personas[].marginal] The maximum number of users that can be assigned to this role when using objective MARGINAL
463
- * @param scope Scope associated with the persona set (by default the scope used will be the current project). Use this to do any specific overrides.
464
- * @param scope.scopeBoundary Scope boundary, defines the type of scope; See [scope boundary](#SCOPE_BOUNDARY) for all types
465
- * @param scope.scopeKey Scope key, a unique identifier tied to the scope. E.g., if your `scopeBoundary` is `GROUP`, your `scopeKey` will be your `groupKey`; for `EPISODE`, `episodeKey`, etc.
466
- * @param [optionals] Optional arguments; pass network call options overrides here.
467
- * @returns promise that resolves with undefined when successful
468
- */
469
- async function setPersonas(personas, scope, optionals = {}) {
470
- const boundary = (scope === null || scope === void 0 ? void 0 : scope.scopeBoundary) || SCOPE_BOUNDARY.PROJECT;
471
- /* We will at some point remove the need to explicitly lower case this */
472
- const boundaryComponent = boundary === SCOPE_BOUNDARY.WORLD ? '' : `/${boundary.toLowerCase()}`;
473
- const scopeKeyComponent = boundary === SCOPE_BOUNDARY.PROJECT ? '' : `/${scope === null || scope === void 0 ? void 0 : scope.scopeKey}`;
474
- const uriComponent = `${boundaryComponent}${scopeKeyComponent}`;
475
- return await new Router().put(`/world/persona${uriComponent}`, {
476
- body: personas,
477
- ...optionals
478
- }).then(({
479
- body
480
- }) => body);
481
- }
482
-
483
- /**
484
- * Assigns an existing run to the given world.
485
- * Base URL: PATCH `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/world/run/{WORLD_KEY}`
486
- *
487
- * @example
488
- * import { worldAdapter } from 'epicenter-libs';
489
- * await worldAdapter.assignRun(world.worldKey, { runKey: run.runKey });
490
- *
491
- * @param worldKey Key associated with the world
492
- * @param runKey Key associated with the run
493
- * @param [optionals] Optional arguments; pass network call options overrides here.
494
- * @returns promise that resolves to the newly resolved world
495
- */
496
- async function assignRun(worldKey, runKey, optionals = {}) {
497
- return await new Router().patch(`/world/run/${worldKey}`, {
498
- body: {
499
- runKey
500
- },
501
- ...optionals
502
- }).then(({
503
- body
504
- }) => body);
505
- }
506
-
507
- export { OBJECTIVE, WORLD_NAME_GENERATOR_TYPE, assignRun, autoAssignUsers, create, destroy, editAssignments, get, getAssignments, getAssignmentsByKey, getPersonas, getSessionWorlds, removeUsers, selfAssign, setPersonas, update };