Environment
The sdk.env
object provides essential runtime information about the environment in which the custom function is being executed. This includes data about the authenticated user, the current tenant, locale, public settings, and more. It is especially useful for adapting UI or logic based on context, such as rendering user-specific content or localizing views.
Properties
Property | Type | Description |
---|---|---|
user | object | The currently authenticated user object. May represent an agent. |
userId | string | ID of the authenticated user. |
tenant | object | The tenant in which the function is running. |
current | ReactiveVar | A reactive version of the tenant object, updated dynamically. |
currentSlug | string | Slug identifier of the current tenant. |
customAppInstanceId | string | ID of the installed app instance if the function is running within an app. |
customerUser | object | If applicable, the customer-facing user object. |
currentLocale | string | The currently active locale. |
publicSettings | object | Shared environment settings across all tenants. |
Example
CustomFunction(async function ({ sdk }, reject, resolve) {
resolve(async function CustomFunction({ sdk }) {
const currentUser = sdk.env.user
const tenantName = sdk.env.tenant?.payload?.name
const locale = sdk.env.currentLocale
sdk.options = function () {
return {
html: `<div>
<p>Welcome, ${currentUser?.profile?.firstname}!</p>
<p>Tenant: ${tenantName}</p>
<p>Locale: ${locale}</p>
</div>`
}
}
})
})
Notes
- Use
sdk.env.current.get()
to access the latest reactive version of the tenant. publicSettings
can include flags or configurations defined globally.- Always null-check nested fields when rendering to avoid runtime errors.