const applet = await sdk.newApplet<Msg, Params>()();
if (applet.isBox) {
// applet has typeof BoxApplet<Msg, Params>
} else {
// applet has typeof ClientApplet<Msg, Params>
}
Pass `requiredBoxFeatures`/`requiredClientFeatures` to assert which features the applet needs to function.
If any of those features are not present, initialisation will throw an error.
This also narrows the type for gated methods covered by the list, so they become non-nullable.
const applet = await sdk.newApplet<Msg, Params>()({
requiredBoxFeatures: ['box-display-status'],
requiredClientFeatures: ['client-user-roles-listing']
});
if (applet.isBox) {
// requiredBoxFeatures lists 'box-display-status', so getDisplayStatus will not be null
await applet.getDisplayStatus();
} else {
// requiredClientFeatures lists 'client-user-roles-listing', so getUserRoles will not be null
await applet.getUserRoles();
}
Initialise a new
Applet<Msg, Params>instance.Dynamically creates either a BoxApplet
<Msg, Params>or a ClientApplet<Msg, Params> depending on the environment.Due to limitations in Typescript, this function needs to be called in two steps so that
Msg&Paramscan be specified explicitly without breaking inferences for therequiredFeaturesoption.Msgshould be set to the type of the applet-messages to send and receive between.Paramsshould be set to the type of the custom parameters that were passed to the applet on start. (from the startApplet message).The
applet.isBoxorapplet.isClientfields can be used to narrow the type of applet.