Skip to main content

Type definitions

InitOpts‚Äč

/**
* The options sent to the `setup` call
*/
type InitOpts = {
color?: string;
logo?: string;
background?: string;
hideLogout?: boolean;
collections: []string;
};

Response‚Äč

interface Response<T = unknown> {
succeed: boolean
data?: T
error?: Error
}

Listener‚Äč

/** Callback listeners used on requests and event capture */
type Listener<D = any> = (data: D) => void;

Outputs‚Äč

/**
* All the events that can be heard by the clients connected to the iframe
*/
type Outputs = {
'avatar-select': AvatarOut;
'camera-ready': unknown;
'logged-in': unknown;
'avatar-created': AvatarOut;
};

Requests‚Äč

/**
* All the requests that can be done to the iframe
* the key is the name of the request
* the function parameters are the parameters of the request
* the return is the value returned by the request
*/
export type Requests = {
login: (user: string, pass: string) => Response<string>;
logout: () => Response;
register: (user: string, pass: string) => Response<string>;
authenticate: (token: string) => Response;
'recover-password': (email: string) => Response;
'reset-password': (token: string, password: string) => Response;
'take-picture': () => Response;
'send-picture': (picture: string) => Response;
'confirm-picture': () => Response;
'complete-avatar': (name: string, bodyId: string) => Response;
'convert-avatar': (id: string) => Response<string>;
'create-avatar': (name: string, head: File | string, body: string) => Response<AvatarOut>;
avatars: () => Response<AvatarOut[]>;
bodies: () => Response<BodyOut[]>;
goto: (view: View) => Response;
'set-logo': (logo: string) => Response;
'set-color': (color: string) => Response;
'set-background': (background: string) => Response;
};

setup‚Äč

/**
* The setup method is the constructor of the "eventer" which can:
* - request anything in the "Requests"
* - listen to anything in the "Outputs"
*
* listen can be done "on" continously, "once" for a single capture.
* the method "off" is just to disconnect the "on".
*/
function setup(ifr: HTMLIFrameElement, opts?: InitOpts): {
on<O extends keyof Outputs = keyof Outputs, D extends Outputs = Outputs>(key: O, cb: Listener<D[O]>): void;
once<O_1 extends keyof Outputs = keyof Outputs, D_1 extends Outputs = Outputs>(key: O_1, cb: Listener<D_1[O_1]>): void;
off<O_2 extends keyof Outputs = keyof Outputs, D_2 extends Outputs = Outputs>(key: O_2, cb: Listener<D_2[O_2]>): void;
request<K extends keyof Requests = keyof Requests, P extends unknown[] = Parameters<Requests[K]>, R = ReturnType<Requests[K]>>(key: K, ...params: P): Promise<R>;
};

View‚Äč

type View = 'Login' | 'PreviewAvatar' | 'Register' | 'RecoverPassword' | 'ResetPassword' | 'SelectAvatar' | 'SelectBody' | 'CreateAvatar';

AssetStyle‚Äč

interface AssetStyles {
readonly Phr: "phr";
readonly Vox: "vox";
readonly Sca: "sca";
}

OutputFormat‚Äč

interface OutputFormat {
readonly Glb: "glb";
readonly Fbx: "fbx";
}

AvatarOut‚Äč

interface AvatarOut {
avatarLink: string;
bodyId?: string;
createdAt: Date;
headId?: string;
id: string;
name: string;
outputFormat?: OutputFormat;
style?: AssetStyles;
thumbnailUrl?: string;
}

BodyOut‚Äč

interface BodyOut {
name: string;
thumbnailUrl?: string;
style?: AssetStyles;
id: string;
createdAt: Date;
url: string;
}