Frontend Appnest Functions
This document describes window.AppnestFunctions, loaded by client.js inside your marketplace app iframe.
Prerequisites
client.jsis loaded in your app page (before you callAppnestFunctions).- Your app is embedded in the product iframe so
window.parentis the host that runs the matching parent script (parent.js).
Global: window.AppnestFunctions
window.AppnestFunctions = {
$check,
$app: {
backend,
},
$productParent,
};
$check
Purpose: Quick sanity check that the bridge script loaded.
| Type | Synchronous |
| Signature | $check() |
| Returns | { data: { message: string } } |
Example
const ok = window.AppnestFunctions.$check();
console.log(ok.data.message); // "Hello from Frontend AppnestFunctions"
$app
$app.backend is used to call your app backend functions.
$app.backend
| Signature | backend({ apiFunctionName, functionPayload?, options? }) |
| Returns | Promise<object> - parsed JSON body of the HTTP response |
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
apiFunctionName | string | Yes | Backend method name (serverMethod sent to the API). Non-empty string. |
functionPayload | any | No | JSON-serializable argument for the server method. |
options | object | No | Reserved; may include timeout (ms) forwarded to the underlying request (default 120000). |
Behavior
- Sends
POSTwith body:{ serverMethod, functionPayload, appVersionId, appId, traceId }(traceIdis generated per call). - On HTTP 401, shows a toastr error on the client.
- On status > 300, shows a toastr error and rejects with
Error('Sparrowapps API Error').
Example
const result = await window.AppnestFunctions.$app.backend({
apiFunctionName: 'myServerHandler',
functionPayload: { foo: 'bar' },
});
$productParent
$productParent is used to call the parent product-the page that embeds your app in its iframe.
$productParent.getName
| Returns | Promise - product parent identifier (e.g. surveysparrow) |
const name = await window.AppnestFunctions.$productParent.getName();
$productParent.getRegion
| Returns | Promise - region claim from the host |
const region = await window.AppnestFunctions.$productParent.getRegion();
Note: Internally, these methods return response.body from the resolved postMessage result. The parent should return a shape consistent with that (e.g. { body: ... }) or the client should be updated to return the raw result if the parent sends a plain value.
$productParent.invoke
| Signature | invoke({ actionName, actionPayload? }) |
| Returns | Promise - whatever the parent returns for that action |
Dispatches a product-specific action. Support depends on the current product parent. For surveysparrow, the parent typically supports actions such as:
actionName | Description (typical) |
|---|---|
getSurveyId | Survey id inferred from parent URL; resolves to { surveyId }. |
getLoggedInUserDetails | Resolves to { loggedInUserDetails } from window.getLoggedInUserDetails(). |
getLocation | Resolves to window.marketplaceLocalAppLocation. |
Other product parents may reject unsupported actions.
Example
const { surveyId } = await window.AppnestFunctions.$productParent.invoke({
actionName: 'getSurveyId',
});