Repository navigation
API requests
const api = await widgetSDK.api.init("uniqueId");
Initialises the SDK. Requires string uniqueId as the parameter. Note that the uniqueId is generated on every component render, however the it is formatted as [widgetId]_[randomString] where the [widgetId] is always consistent.
api.getCurrentUser();
Returns the full current user who is viewing this widget. This includes user data and organisation data. Important, object keys may be null so remember to do falsy checks.
{
id: string,
name: {
givenName: string,
familyName: string,
fullName: string
},
thumbnailPhotoUrl: string,
primaryEmail: string,
organizations: [{
primary: boolean,
department: string,
costCenter: string,
title: string,
}],
addresses: [{
formatted: string,
type: string
}],
phones: [{
value: string,
type: string
}],
birthday: {
millis: number,
isoString: string
},
organisation: {
id: string,
name: string,
primaryDomain: string,
logo: string,
primaryColor: string,
secondaryColor: string,
}
}
api.getUser(id: string);
Returns the full user by id. This includes user data and organisation data.
{
id: string,
name: {
givenName: string,
familyName: string,
fullName: string
},
thumbnailPhotoUrl: string,
primaryEmail: string,
organizations: [{
primary: boolean,
department: string,
costCenter: string,
title: string,
}],
addresses: [{
formatted: string,
type: string
}],
phones: [{
value: string,
type: string
}],
birthday: {
millis: number,
isoString: string
},
organisation: {
id: string,
name: string,
primaryDomain: string,
logo: string,
primaryColor: string,
secondaryColor: string,
}
}
api.searchUsers( query: string, options: { page: number; pageSize: number });
Searches users. Provide at least 2 chars for the query.
{
total: number;
hits: User[]
}
api.getContext();
Context gives you overall information about the widget, where it is located and rendered.
{
userId: "123",
organisationId: "223",
mode: "edit",
token: "adadadad",
scopedData: {
user: {
id: "123",
primaryEmail: "example@example.com"
},
organisation: {
id: "223"
}
},
context: {
hostname: "app.happeo.com",
href: "https://app.happeo.com/...",
pathname: "/pages/..."
},
location: {
channelId: "333",
pageId: "111",
pageGroupId: "223",
localWidgetId: "3443"
}
}
api.getJWT();
Gets the JWT for the widget if the widget has attached scopes refreshes the JWT automatically if needed. Call this always before utilising the JWT because the JWT will expire and the user may idle on the page before interacting with your widget.
api.getContent();
Gets the content for the widget. Content is not specific to the widget, but to the context. As an example, if this widget is added to a page in 2 places, widget will have own content for both places.
Important note: Everything in the content is indexed in the Happeo search. So when you set this content (see below), note that you should consider this when making decisions on the data structure.
api.setContent();
Sets string content to widget. This is the primary way of storing data in this widget. Data is stored in Happeo's servers.
Important note: Everything in the content is indexed in the Happeo search. So when you set this content, note that you should consider this when making decisions on the data structure.
api.getSettings();
Gets the settings for this widget. These may include things like background color, font sizes or other things you want the user to configure.
The settings object is always a simple key - value object with no nested structures. If you want nested structures, then you need to stringify the value.
{
mySetting: "this is a setting",
stringifiedJson: "{1:2}"
}
api.setSettings();
Sets settings for this widget. This can be useful if you want to save some properties in the settings object and not in the content. The settings object is always a simple key - value object with no nested structures. If you want nested structures, then you need to stringify the value.
{
mySetting: "this is a setting",
stringifiedJson: "{1:2}"
}
api.declareSettings();
Creates new settings that are shown to the user in the Happeo UI. This allows a seamless experience for the user where they can fill in overall configurations for this widget.
The function takes in the settings object and a callback. The callback is returned on init, with the existing settings and on every settings change. The callback always returns the full widget settings object.
Settings object structure and example:
[
{
placeholder: "Text placeholder",
key: "uniqueStringKey",
value: "defaultValue",
type: "color",
},
{
placeholder: "Another setting",
key: "anotherUniqueKey",
value: "this is text",
type: "text",
},
]
api.uploadImage(input: UploadInput);
Upload images to Happeo CDN with current user's credentials.
interface UploadInput {
files: FileList;
channelId: string;
startUpload: (entry: UploadEntry) => void;
updateUploadProgress: (entry: UploadEntry) => void;
onUploadError: (id: string, error: Error) => void;
chooseDestinationDirectory: () => Promise<{ file: File }>;
}