World Functions
To manage worlds, use the functions exported by the World adapter.
Importing the adapter
import { worldAdapter } from 'epicenter-libs';
The worldAdapter namespace exports functions that make calls to the World API.
For descriptions of the objects used by the World adapter functions, read World entities.
Worlds
Create a world
To create a world , use the create() function. You have the options of specifying a group and/or an episode.
The name of the new world must be unique within the world's scope. You don't have to provide a name. If the name is omitted, Epicenter generates one using a world name generator. There are two types of world name generators:
- Sequential (default): Generates names of format "World###", where ### is a numeral starting with 001.
- Color + animal: Randomly combines a color and an animal.
You can specify the type of world name generator you want to use in the worldNameGenerator parameter.
Permissions
Requires a role of PARTICIPANT or higher.
Function description
The create() function:
- Constructs a
POSTrequest to the endpoint/world/{GROUP_NAME}or/world/{GROUP_NAME}/{EPISODE_NAME}if an episode name is provided. - Sends optional parameters as the request body to configure the world.
- Returns a
WorldReadOutViewobject object.
export async function create<R extends WorldRole = WorldRole>(
optionals: {
name?: string;
displayName?: string;
groupName?: string;
episodeName?: string;
worldNameGenerator?: WorldNameGenerator;
allowChannel?: boolean;
} & RoutingOptions = {},
): Promise<WorldReadOutView<R>>
Parameters
A world's name and displayName cannot be an empty string and cannot contain any of these characters:
`$%^*={}[]|;\"<>?\r\n
optionals: Optional parameters and aRoutingOptionsobject.name(string): (Optional) A name for the world. Must be unique within the world's scope.displayName(string): (Optional) An informative display name for the world. Doe not need to be unique.groupName(string): (Optional) The name of the group where the world is created. If not provided, defaults to thegroupNamestored in the session.episodeName(string): (Optional) The name of the episode in which the world is created.worldNameGenerator(WorldNameGenerator object): (Optional) Specifies the method for generating the world name.allowChannel(boolean): (Optional) Iftrue, send out push notifications for this world. Applicable to projects with phylogeny >= SILENT.
Return value
A promise that resolves to a WorldReadOutView object object.
import { worldAdapter } from 'epicenter-libs';
await worldAdapter.create({ name: 'Whole New World' });
List worlds for group or episode
To retrieve worlds associated with a group or episode, use the get() function.
Permissions
Requires a role of PARTICIPANT or higher.
Function description
The get() function:
- Constructs a
GETrequest to/world/{GROUP_NAME}or/world/{GROUP_NAME}/{EPISODE_NAME}if an episode name is provided. - If
mineis set totrue, only worlds owned by the current user are returned. - Defaults to the user's session group if
groupNameis not provided. - Returns an array of
WorldReadOutViewobjects.
export async function get<R extends WorldRole = WorldRole>(
optionals: {
groupName?: string;
episodeName?: string;
mine?: boolean;
} & RoutingOptions = {},
): Promise<WorldReadOutView<R>[]>
Parameters
optionals: Optional parameters and aRoutingOptionsobject.
Return value
A promise that resolves to an array of WorldReadOutView objects.
Usage example
import { worldAdapter } from 'epicenter-libs';
// Retrieve the world for the groupName stored in the session
worldAdapter.get();
// Retrieve the world for a specific group and episode
worldAdapter.get({ groupName: 'group_1', episodeName: 'episode_1' });
// Retrieve only worlds the current user is in
worldAdapter.get({ mine: true });
List worlds for the current user
Permissions
Requires a role of PARTICIPANT or higher.
Function description
The getSessionWorlds() function:
- Constructs a
GETrequest to the endpoint/world/assignment. - Retrieves the worlds associated with the current session.
- Returns a list of
WorldReadOutViewobjects assigned to the current user.
export async function getSessionWorlds<R extends WorldRole = WorldRole>(
optionals: RoutingOptions = {},
): Promise<WorldReadOutView<R>[]>
Parameters
optionals(Type:RoutingOptions = {}): Additional routing options.
Return value
A promise that resolves to an array of WorldReadOutView objects.
Usage example
import { worldAdapter } from 'epicenter-libs';
const worlds = await worldAdapter.getSessionWorlds();
Update a world
To update an existing world, use the update() function.
Permissions
Requires a role of PARTICIPANT or higher.
Function description
The update() function:
- Constructs a
PATCHrequest to/world/{WORLD_KEY}. - Sends updated world attributes in the request body.
- Returns a
WorldReadOutViewobject with the updated fields.
export async function update<R extends WorldRole = WorldRole>(
worldKey: string,
update: {
displayName?: string;
runKey?: string;
allowChannel?: boolean;
},
optionals: RoutingOptions = {},
): Promise<WorldReadOutView<R>>
Parameters
A world's displayName cannot contain any of these characters:
`$%^*={}[]|;\"<>?\r\n
worldKey(string): The key identifying the world.update(Type:{ displayName?: string, runKey?: string, allowChannel?: boolean }): The world's attributes you are updating.displayName(string): The new display name for the world. Does not need to be unique.runKey(string): The new model run key to associate the world with.allowChannel(boolean): Iftrue, send out push notifications for this world. Applicable to projects with phylogeny >= SILENT.
optionals(Type:RoutingOptions = {}): Additional routing options.
Return value
A promise that resolves to an updated WorldReadOutView object.
Usage example
import { worldAdapter } from 'epicenter-libs';
worldAdapter.update('0000017a445032dc38cb2cecd5fc56706934',
{ runKey: '0000018d61f1217b22ce0ae605ff00649d6i', displayName: 'World A1' });
Assign a run to a world
To assign an existing run to a world, call the assignRun() function.
Use this function when you need to assign the world to a different run.
Permissions
Requires a role of PARTICIPANT or higher.
Function description
The assignRun() function:
- Constructs a
PATCHrequest to/world/run/{WORLD_KEY}. - Sends the
runKeyin the request body to associate the run with the world. - Returns a
WorldReadOutViewobject representing the updated world.
export async function assignRun<R extends WorldRole = WorldRole>(
worldKey: string,
runKey: string,
optionals: RoutingOptions = {},
): Promise<WorldReadOutView<R>>
Parameters
worldKey(string): The unique key identifying the world.runKey(string): The key of the run to be assigned to the world.optionals(Type:RoutingOptions = {}): Additional routing options. Pass network call options overrides here.
Return value
A promise that resolves to an updated WorldReadOutView object.
Usage example
import { worldAdapter } from 'epicenter-libs';
await worldAdapter.assignRun('0000017a445032dc38cb2cecd5fc56679324',
'0000018d61f1217b22ce0ae605ff00669d8o');
Delete a world
To delete a world, use the destroy() function.
Permissions
Requires a role of FACILITATOR or higher.
Function description
The destroy() function:
- Constructs a
DELETErequest to the endpoint/world/{WORLD_KEY}. - Executes the request and returns a
voidpromise upon success.
export async function destroy(
worldKey: string,
optionals: RoutingOptions = {}
): Promise<void>
Parameters
worldKey(string): The unique key identifying the world to be deleted.optionals(Type:RoutingOptions = {}): Additional routing options.
Return value
A promise that resolves to void when the world is successfully deleted.
Usage example
import { worldAdapter } from 'epicenter-libs';
worldAdapter.destroy('0000017a445032dc38cb2cecd5fc13563218');
User assignments
List assignments
Retrieves a list of user assignments with some information on the world included for a group or episode (if specified).
Permissions
Requires a role of PARTICIPANT or higher.
Function description
The getAssignments() function:
- Constructs a
GETrequest to/world/assignment/for/{GROUP_NAME}or/world/assignment/for/{GROUP_NAME}/{EPISODE_NAME}if an episode name is provided. - Optionally filters results to only the worlds the requesting user is assigned to.
- Returns a list of
WorldReadOutViewobjects representing the assignments.
export async function getAssignments<R extends WorldRole = WorldRole>(
optionals: {
groupName?: string;
episodeName?: string;
mine?: boolean;
} & RoutingOptions = {},
): Promise<WorldReadOutView<R>[]>
Parameters
optionals: Filters and aRoutingOptionsobject.
Return value
A promise that resolves to an array of WorldReadOutView objects.
Usage example
import { worldAdapter } from 'epicenter-libs';
worldAdapter.getAssignments({ mine: true }); // Get only the worlds the current user is assigned to.
Assign the current user
Automatically assigns the current session's user to a world.
Permissions
Requires a role of FACILITATOR or higher.
Function description
The selfAssign() function:
- Constructs a
POSTrequest to/world/selfassign/{GROUP_NAME}or/world/selfassign/{GROUP_NAME}/{EPISODE_NAME}if an episode name is provided. - Sends optional parameters — such as role, objective, populace, and world‑name generation strategy—in the request body.
- Returns a
WorldReadOutViewobject representing the world the user was assigned to.
export async function selfAssign<R extends WorldRole = WorldRole>(
optionals: {
role?: R;
groupName?: string;
episodeName?: string;
objective?: keyof typeof OBJECTIVE;
worldNameGenerator?: WorldNameGenerator;
populace?: PersonaCreateInView<R>[];
allowChannel?: boolean;
} & RoutingOptions = {},
): Promise<WorldReadOutView<R>>
Parameters
optionals: Optional parameters and aRoutingOptionsobject.role(R): The world role to be assigned to the user.groupName(string): The name of the group. Defaults to the session's group name.episodeName(string): The episode name for worlds scoped to an episode.objective(keyof typeof OBJECTIVE): The assignment objective type. Defaults toOBJECTIVE.MINIMUM.worldNameGenerator(WorldNameGenerator object): Defines the naming convention for the world.populace(PersonaCreateInView<R>[]): List of personas to dictate the self assignment.allowChannel(boolean): Iftrue, enables push notifications for the world. Applicable to projects with phylogeny >= SILENT.
Return value
A promise that resolves to an assigned WorldReadOutView object.
Usage example
import { worldAdapter } from 'epicenter-libs';
// Assigns user to a group-scoped world
epicenter.worldAdapter.selfAssign();
// Assigns user to a group-scoped world with role "cartographer"
epicenter.worldAdapter.selfAssign({ role: 'cartographer' });
// Assigns user to an episode-scoped world with role "cartographer"
epicenter.worldAdapter.selfAssign({ role: 'cartographer', episodeName: 'my-episode-name' });
Auto-assign users to worlds
To assign a list of users to world personas, call the autoAssignUsers() function.
This function completes the persona assignments for all existing worlds and creates new worlds for remaining unassigned users. The assignment is done according to the specified assignment objective.
You can make this an all-or-nothing operation by setting the requireAllAssignments to true. In this case all the users in the list must be assigned or none.
Permissions
Requires a role of FACILITATOR or higher.
Function description
The autoAssignUsers() function:
- Constructs a
POSTrequest to/world/assignment/{GROUP_NAME}or/world/assignment/{GROUP_NAME}/{EPISODE_NAME}if an episode name is provided. - Sends assignment data—including user assignments, objectives, populace constraints, and world‑name generation strategy—in the request body.
- Returns a list of
WorldReadOutViewobjects representing the worlds created or updated by the assignment.
export async function autoAssignUsers<R extends WorldRole = WorldRole>(
assignments: AssignmentCreateInView<R>[],
optionals: {
groupName?: string;
episodeName?: string;
objective?: keyof typeof OBJECTIVE;
worldNameGenerator?: WorldNameGenerator;
requireAllAssignments?: boolean;
keepEmptyWorlds?: boolean;
populace?: PersonaCreateInView<R>[];
allowChannel?: boolean;
} & RoutingOptions = {},
): Promise<WorldReadOutView<R>[]>
Parameters
assignments(Type:AssignmentCreateInView<R>[]): An array of user assignment objects.optionals: Optional parameters and aRoutingOptionsobject.groupName(string): The name of the group. Defaults to the session's group name.episodeName(string): The episode name for episode scoped worlds.objective(keyof typeof OBJECTIVE): Defaults toOBJECTIVE.MINIMUM.worldNameGenerator(WorldNameGenerator object): Defines the naming convention for the world.requireAllAssignments(boolean): Iftrue, return an error when an assignment was not made (instead of silently leaving the user as unassigned).keepEmptyWorlds(boolean): Iffalse, worlds that are now empty should be deleted.populace(PersonaCreateInView<R>[]): Array of persona objects to assign to worlds.allowChannel(boolean): Iftrue, enables push notifications for the world. Applicable to projects with phylogeny >= SILENT.
Return value
A promise that resolves to an array of WorldReadOutView objects.
Usage example
import { worldAdapter } from 'epicenter-libs';
const worlds = await worldAdapter.assignUsers([
{ userKey: '000001796733eef0842f4d6d960997035d69', role: 'locksmith' },
{ userKey: '000001796733eef0842f4d6d960997069s5w' },
]);
Edit assignments
Manually assign users to a world. You have the option of specifying a persona for each user.
You can make this an all-or-nothing operation by setting the requireAllAssignments to true. In this case all the users in the list must be assigned or none.
Permissions
Requires a role of FACILITATOR or higher.
Function description
The editAssignments() function:
- Constructs a
PUTrequest to/world/assignment/{GROUP_NAME}or/world/assignment/{GROUP_NAME}/{EPISODE_NAME}if an episode name is provided. - Sends a map of world keys to updated assignment lists in the request body.
- Returns a list of
WorldReadOutViewobjects representing the updated worlds.
export async function editAssignments<R extends WorldRole = WorldRole>(
assignments: AssignmentMap<R>,
optionals: {
groupName?: string;
episodeName?: string;
objective?: keyof typeof OBJECTIVE;
keepEmptyWorlds?: boolean;
requireAllAssignments?: boolean;
} & RoutingOptions = {},
): Promise<WorldReadOutView<R>[]>
Parameters
assignments(Type:AssignmentMap<R>): A mapping of world keys to user assignments.optionals: Optional parameters and aRoutingOptionsobject.groupName(string): The name of the group for which assignments are updated. Defaults to the session's group name.episodeName(string): The episode name for worlds scoped to an episode.objective(keyof typeof OBJECTIVE): Defaults toOBJECTIVE.MINIMUM.keepEmptyWorlds(boolean): Iftrue, worlds with no assigned users are still maintained.requireAllAssignments(boolean): Iftrue, return an error when an assignment was not made (instead of silently leaving the user as unassigned).
Return value
A promise that resolves to an array of WorldReadOutView objects.
Usage example
import { worldAdapter } from 'epicenter-libs';
const updatedWorlds = await worldAdapter.editAssignments({
'0000017a445032dc38cb2cecd5fc13708314': [
{ userKey: '000001796733eef0842f4d6d960997018a43', role: 'locksmith' },
{ userKey: '000001796733eef0842f4d6d960997018d9h' },
],
'0000017a445032dc38cb2cecd5fc13708315': [
{ userKey: '000001796733eef0842f4d6d960997018a4c', role: 'navigator' },
],
});
Get assignments for a world
To retrieve the current assignments for a world, call the getAssignmentsByKey() function.
Permissions
Requires a role of PARTICIPANT or higher.
Function description
The getAssignmentsByKey() function:
- Constructs a
GETrequest to/world/assignment/{WORLD_KEY}. - Retrieves the assignment information associated with the specified world.
- Returns a
WorldReadOutViewobject containing the assignment data.
export async function getAssignmentsByKey<R extends WorldRole = WorldRole>(
worldKey: string,
optionals: RoutingOptions = {},
): Promise<WorldReadOutView<R>>
Parameters
worldKey(string): The unique key identifying the world.optionals(Type:RoutingOptions = {}): Additional routing options. Pass network call options overrides here.
Return value
A promise that resolves to a WorldReadOutView object.
Usage example
import { worldAdapter } from 'epicenter-libs';
const assignments = await worldAdapter.getAssignmentsByKey(world.worldKey);
Remove users
To remove a user of a set of users from assignments, call removeUsers() function.
Any worlds that do not contain users within them will be automatically deleted in the process unless you unless you set the keepEmptyWorlds parameter to true.
Permissions
Requires a role of FACILITATOR or higher.
Function description
The removeUsers() function:
- Constructs a
DELETErequest to/world/assignment/{GROUP_NAME}or/world/assignment/{GROUP_NAME}/{EPISODE_NAME}if an episode name is provided. - Removes users from world assignments based on specified parameters.
- Deletes any worlds that become empty unless
keepEmptyWorldsis set totrue. - Returns a
voidpromise upon success.
export async function removeUsers(
userKeys: string[],
optionals: {
groupName?: string,
episodeName?: string,
keepEmptyWorlds?: boolean,
} & RoutingOptions = {}
): Promise<void>
Parameters
userKeys(Type:string[]): An array of user keys to be removed from their world persona assignments.optionals: Optional parameters and aRoutingOptionsobject.
Return value
A promise that resolves to void when the users are successfully removed.
Usage example
import { worldAdapter } from 'epicenter-libs';
const usersToRemove = ['000001796733eef0842f4d6d960997639ww5r'];
await worldAdapter.removeUsers(usersToRemove);
Personas
List personas
To get a list of the personas for a given scope (project, group, episode, or world), call the getPersonas() function.
Permissions
Requires a role of PARTICIPANT or higher.
Function description
The getPersonas() function:
- Constructs a
GETrequest to/world/persona/{SCOPE_BOUNDARY}/{SCOPE_KEY}. - Determines the correct URI components based on the provided scope boundary and scope key.
- Returns an array of
PersonaReadOutViewobjects for the specified scope.
export async function getPersonas<R extends WorldRole = WorldRole>(
scope: GenericScope,
optionals: RoutingOptions = {},
): Promise<PersonaReadOutView<R>[]>
Parameters
scope(Type:GenericScope): The scope defining the level at which personas are retrieved.optionals(Type:RoutingOptions = {}): Additional routing options.
Return value
A promise that resolves to an array of PersonaReadOutView objects when the personas are successfully retrieved.
Usage example
import { worldAdapter } from 'epicenter-libs';
await worldAdapter.getPersonas({ scopeBoundary: SCOPE_BOUNDARY.GROUP, scopeKey: GROUP_KEY });
Set personas
To set the personas of a given entity (project, group, episode, or world), call the setPersonas() function.
The setPersonas() function performs an overwrite of the set of personas for an entity. You must always pass the entire array.
Permissions
Requires a role of FACILITATOR or higher.
Function description
The setPersonas() function:
- Constructs a
PUTrequest to/world/persona/{SCOPE_BOUNDARY}/{SCOPE_KEY}. - Returns
undefinedwhen the personas are successfully updated.
export async function setPersonas<R extends WorldRole = WorldRole>(
personas: PersonaCreateInView<R>[],
scope?: GenericScope,
optionals: RoutingOptions = {},
): Promise<void>
Parameters
personas(Type:PersonaCreateInView<R>[]): A list of persona objects:role(string): See description of thePersonaCreateInViewinterface.minimum(number, optional): See description of thePersonaCreateInViewinterface.maximum(number, optional): See description of thePersonaCreateInViewinterface.marginal(number, optional): See description of thePersonaCreateInViewinterface.
scope(Type:GenericScope): The scope object defining the level at which personas are set.optionals(Type:RoutingOptions = {}): Additional routing options.
Return value
A promise that resolves to void when the personas are successfully set.
Usage example
import { worldAdapter } from 'epicenter-libs';
const personas = [{ role: 'leader', minimum: 1 },];
const scope = { scopeBoundary: SCOPE_BOUNDARY.GROUP, scopeKey: GROUP_KEY };
await worldAdapter.setPersonas(personas, scope);