A JavaScript SDK for communicating with the Kontent.ai Custom App API. It facilitates the communication between the Kontent.ai app and the custom app providing access to the configuration and context data.
npm install @kontent-ai/custom-app-sdk
Important
The SDK attaches event listeners to communicate with the Kontent.ai app. Make sure to include the SDK only in the browser environment.
import { getCustomAppContext, CustomAppContext } from "@kontent-ai/custom-app-sdk";
const response: CustomAppContext = await getCustomAppContext();
if (response.isError) {
console.error({ errorCode: response.code, description: response.description});
} else {
console.log({ config: response.config, context: response.context });
}
Use the getCustomAppContext
function to retrieve the context of the custom app. The function takes no arguments and returns a promise with a value of an object of type CustomAppContext
.
Property | Type | Description |
---|---|---|
isError |
boolean | Determines if there was an error while getting the context of the custom app |
code |
ErrorCode enum | null | The code of the error message |
description |
string | null | The description of the error message |
context |
object | null | Contains data provided by the Kontent.ai application |
config |
object | null | Contains JSON object specified in the custom app configuration |
The config
object is a JSON object that can be defined within the Custom App configuration under Environment settings in the Kontent.ai app.
The context
object contains data provided by the Kontent.ai application that you can leverage in your custom app.
Property | Type | Description |
---|---|---|
environmentId |
UUID | The environment's ID |
userId |
string | The current user's ID |
userEmail |
string | The current user's email |
userRoles |
Array of UserRole | An array containing all the roles of the current user in the environment |
Property | Type | Description |
---|---|---|
id |
UUID | The role's ID |
codename |
string | The role's codename - applicable only for the Project manager role |
For Contributing please see CONTRIBUTING.md
for more information.
Distributed under the MIT License. See LICENSE.md
for more information.