Account Functions
To create functionality that manages you personal and team Epicenter accounts, leverage the Account adapter.
Importing the adapter
import { accountAdapter } from 'epicenter-libs';
The accountAdapter namespace exports functions that make calls to the Account API.
For descriptions of the objects used by the account adapter functions, read Account entities.
Create an account
Create a personal or team account.
Permissions
Requires a SYSTEM role.
Function description
The createAccount() function:
- Constructs a
POSTrequest to to the{ACCOUNT_SHORT_NAME}/{PROJECT_SHORT_NAME}/accountendpoint setting the path parameters{ACCOUNT_SHORT_NAME}='epicenter'and{PROJECT_SHORT_NAME}='manager'. - Returns an
AccountReadOutViewrepresenting the newly created personal or team account.
export async function createAccount(
view: PersonalAccountCreateInView | TeamAccountCreateInView,
): Promise<AccountReadOutView>
Parameters
view (Union Type: PersonalAccountCreateInView or TeamAccountCreateInView): An object containing the account creation details. It can be either of the following types:
PersonalAccountCreateInView: Represents the details required for creating a personal account.TeamAccountCreateInView: Represents the details required for creating a team account.
Return value
A promise that resolves to an AccountReadOutView.
Usage example
import { accountAdapter } from 'epicenter-libs';
// Create a personal account
const personalAccount = await accountAdapter.createAccount({
objectType: 'personal',
adminKey: 'admin-key',
name: 'John Doe',
shortName: 'johndoe',
});
// Create a team account with billing
const teamAccount = await accountAdapter.createAccount({
objectType: 'team',
adminKey: 'admin-key',
name: 'Acme Corp',
shortName: 'acme',
billingInformation: {
billingInterval: 'monthly',
subscriptionPlan: 'standard',
},
});
Get an account
Retrieve the details of an account by accountShortName.
Permissions
Requires a role of SUPPORT or higher.
Function description
The getAccount() function:
- Constructs a
GETrequest to/accountusing the provided account short name. - Returns an
AccountReadOutView, which may represent either a personal or team account depending on the account type.
export async function getAccount(accountShortName: string): Promise<AccountReadOutView>
Parameters
accountShortName (Type: string): Serves as the unique identifier of the account.
Return value
A promise that resolves to an AccountReadOutView.
Usage example
import { accountAdapter } from 'epicenter-libs';
const account = await accountAdapter.getAccount('acme');
List team accounts
Retrieve a filtered list of team accounts which a specific admin has permission to access.
Permissions
Requires a SYSTEM role.
Function description
The teamForAdmin() function:
- Constructs a
GETrequest to{ACCOUNT_SHORT_NAME}/{PROJECT_SHORT_NAME}/account/team/for/{ADMIN_KEY}setting the path parameters{ACCOUNT_SHORT_NAME}='epicenter'and{PROJECT_SHORT_NAME}='manager'. - Accepts optional filters such as member inclusion, result filtering, and pagination.
- Returns an array of
AccountReadOutViewobjects representing the team accounts administered by the specified admin.
export async function teamForAdmin(
adminKey: string,
optionals: {
includeAllMembers?: boolean;
filter?: string;
first?: number;
max?: number;
} & RoutingOptions = {},
): Promise<AccountReadOutView[]>
Parameters
adminKey(type:string): A GUID that identifies the admin.optionals(optional, type:object): Filter, pagination, and routing options.includeAllMembers(boolean): IfTrue, includes all members of the team in the response.filter(string): A filter string to narrow down the results.first(number): Specifies the starting index for pagination.max(number): Defines the maximum number of results to return.RoutingOptions(object): An optional parameter providing additional routing options. Defaults to an empty object.
Return value
A promise that resolves to an array of AccountReadOutView, each representing a team account.
Update an account
Update account details.
Permissions
Requires a role of AUTHOR or higher.
Function description
The updateAccount() function:
- Constructs a
PATCHrequest to the/accountendpoint. - Sends either a
PersonalAccountUpdateInVieworTeamAccountUpdateInViewobject in the request body. - Accepts optional routing overrides through a
RoutingOptionsobject. - Returns an
AccountReadOutViewrepresenting the updated account.
export async function updateAccount(
view: PersonalAccountUpdateInView | TeamAccountUpdateInView,
optionals: RoutingOptions = {},
): Promise<AccountReadOutView> {
return await new Router()
.patch('/account', {
body: view,
...optionals,
}).then(({ body }) => body);
}
Parameters
view(Type:PersonalAccountUpdateInVieworTeamAccountUpdateInView): Configuration object describing the updates to apply to the account.optionals(optional, type:RoutingOptions): An optional parameter providing additional routing options. Defaults to an empty object.
Return value
A promise that resolves to an AccountReadOutView representing the updated account.
Remove an account
Delete an account and all account details.
Permissions
Requires a role of OWNER or higher.
Function description
The removeAccount() function:
- Constructs a
DELETErequest to/accountusing the provided account short name. - Returns a promise that resolves to
voidwhen the deletion is complete.
export async function removeAccount(
accountShortName: string,
): Promise<void> {
return await new Router()
.withAccountShortName(accountShortName)
.delete('/account')
.then(({ body }) => body);
}
Parameters
accountShortName (Type: string): Account short name.
Return value
A promise that resolves to void.
Usage example
import { accountAdapter } from 'epicenter-libs';
await accountAdapter.removeAccount('acme');