Wallet Functions
To manage wallets, use the functions exported by the Wallet adapter.
Importing the adapter
import { walletAdapter } from 'epicenter-libs';
The walletAdapter namespace exports functions that make calls to the Wallet API.
For descriptions of the objects used by the Wallet adapter functions, read Wallet entities.
Update
The update() function creates a new wallet or updates an existing one. The wallet is identified by the user-specific scope.
Wallet entries can be updated. They are key/value pairs containing user data required in the specified scope.
If userKey is not provided, the function automatically uses the userKey from the current session.
Permissions
Requires a role of PARTICIPANT or higher.
Function description
- Constructs a
POSTrequest to the/walletendpoint. - Accepts a list of wallet items consisting of
labelandvaluepairs. - Returns the updated wallet.
export async function update(
scope: { userKey: string | undefined } & GenericScope,
items: WalletItemCreateInView[],
optionals: RoutingOptions = {},
): Promise<WalletReadOutView>
Parameters
scope({ userKey: string | undefined } & GenericScope) – The user-specific scope of the walletscopeBoundary– Scope entityscopeKey(string) – Scope keyuserKey(string) – The user whose wallet is being updated. If omitted, the current session'suserKeyis used
items(WalletItemCreateInView[]) – List of wallet items to updatelabel(string) – Identifier for the wallet entryvalue(string) – Value associated with the label
optionals(Type:RoutingOptions): Additional routing options
Return value
A promise that resolves to a WalletReadOutView object containing the updated wallet.
Usage example
import { walletAdapter, SCOPE_BOUNDARY } from 'epicenter-libs';
// Add a user's phone number to their wallet
const scope = {
userKey: '000001796733eef0842f4d6d960997018a33',
scopeBoundary: SCOPE_BOUNDARY.GROUP,
scopeKey: '0000017dd3bf540e5ada5b1e058f08f20461',
};
const wallet = await walletAdapter.update(scope, [
{ label: 'phone', value: '555-555-5555' }
]);
Retrieve
Retrieve a single wallet or a list of wallets in a scope.
Get wallet
The get() function retrieves a user's wallet within a specified scope.
If userKey is not provided, the function automatically uses the userKey from the current session.
Permissions
Requires a role of PARTICIPANT or higher.
Function description
- Constructs a
GETrequest to the/wallet/{SCOPE_BOUNDARY}/{SCOPE_KEY}/{USER_KEY}endpoint. - Returns a
WalletReadOutViewobject. - If the wallet does not exist, the function returns
undefined.
export async function get(
scope: { userKey: string } & GenericScope,
optionals: RoutingOptions = {},
): Promise<WalletReadOutView | undefined>
Parameters
scope({ userKey: string } & GenericScope) – The user-specific scope of the walletscopeBoundary– Scope entityscopeKey(string) – Scope keyuserKey(string) – The user whose wallet is being updated. If omitted, the current session'suserKeyis used
optionals(Type:RoutingOptions): Additional routing options
Return value
A promise that resolves to one of the following:
- A
WalletReadOutViewobject containing the wallet data, or undefinedif the wallet is not found.
Usage example
import { walletAdapter, SCOPE_BOUNDARY } from 'epicenter-libs';
// Get a user's wallet
const scope = {
userKey: '000001796733eef0842f4d6d960997018a33',
scopeBoundary: SCOPE_BOUNDARY.GROUP,
scopeKey: '0000017dd3bf540e5ada5b1e058f08f20461',
};
const wallet = await walletAdapter.get(scope);
Get wallets in scope
The withScope() function retrieves all wallets within a specified scope.
Permissions
Requires a role of PARTICIPANT or higher.
Function description
- Constructs a
GETrequest to the/wallet/with/{SCOPE_BOUNDARY}/{SCOPE_KEY}endpoint. - Supports pagination using the
firstandmaxparameters. - Returns a paginated list of wallet objects.
export async function withScope(
scope: GenericScope,
optionals: {
first?: number;
max?: number;
} & RoutingOptions = {},
): Promise<Page<WalletReadOutView>>
Parameters
scope(GenericScope) – Scope of the walletsscopeBoundary– Scope entityscopeKey(string) – Scope key
optionals(Type:{ first?: number; max?: number } & RoutingOptions):first?(number) – Index from which to begin returning resultsmax?(number) – Maximum number of wallets to returnRoutingOptions– Additional routing options
Return value
A promise that resolves to a Page<WalletReadOutView> object containing a paginated list of wallets.
Usage example
import { walletAdapter, SCOPE_BOUNDARY } from 'epicenter-libs';
// Get all wallets under a group
const scope = {
scopeBoundary: SCOPE_BOUNDARY.GROUP,
scopeKey: '0000017dd3bf540e5ada5b1e058f08f20461',
};
const wallets = await walletAdapter.withScope(scope);