Skip to main content

Frontend Appnest Functions

This document describes window.AppnestFunctions, loaded by client.js inside your marketplace app iframe.

Prerequisites

  1. client.js is loaded in your app page (before you call AppnestFunctions).
  2. Your app is embedded in the product iframe so window.parent is 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.

TypeSynchronous
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

Signaturebackend({ apiFunctionName, functionPayload?, options? })
ReturnsPromise<object> - parsed JSON body of the HTTP response

Parameters

NameTypeRequiredDescription
apiFunctionNamestringYesBackend method name (serverMethod sent to the API). Non-empty string.
functionPayloadanyNoJSON-serializable argument for the server method.
optionsobjectNoReserved; may include timeout (ms) forwarded to the underlying request (default 120000).

Behavior

  • Sends POST with body: { serverMethod, functionPayload, appVersionId, appId, traceId } (traceId is 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

ReturnsPromise - product parent identifier (e.g. surveysparrow)
const name = await window.AppnestFunctions.$productParent.getName();

$productParent.getRegion

ReturnsPromise - 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

Signatureinvoke({ actionName, actionPayload? })
ReturnsPromise - 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:

actionNameDescription (typical)
getSurveyIdSurvey id inferred from parent URL; resolves to { surveyId }.
getLoggedInUserDetailsResolves to { loggedInUserDetails } from window.getLoggedInUserDetails().
getLocationResolves to window.marketplaceLocalAppLocation.

Other product parents may reject unsupported actions.

Example

const { surveyId } = await window.AppnestFunctions.$productParent.invoke({
actionName: 'getSurveyId',
});