IntegrationTypeScript SDK
Remote choices and server validation
Connect host-owned data and validation services without giving the runtime network authority.
Choose a loading seam
Use fetchJson for an authored choicesByUrl list. Use loadChoicePage for server-filtered paging with skip, take, and the respondent’s filter text.
import type { ChoiceFetcher, ChoicePageLoader } from '@kajay/core';
const fetchJson: ChoiceFetcher = async (url) => {
const response = await fetch(url);
if (!response.ok) throw new Error('Choice request failed');
return response.json();
};
const loadChoicePage: ChoicePageLoader = async ({ skip, take, filter }) => {
const query = new URLSearchParams({
skip: String(skip), take: String(take), filter,
});
const response = await fetch('/api/cities?' + query);
return response.json();
};
const { survey } = parseSurvey(definition, { fetchJson, loadChoicePage });Secure remote data
- Kajay requests choices and displays loading, failure, filtering, and pagination state.
- The author selects the question and source metadata.
- The host authenticates requests, restricts destinations, validates response shape, and observes failures.
Prefer named endpoints for portable definitions
Add server validation
A server validator receives the current data and question names under the active gate. Return errors by question name. Reject only for host or network failure; Kajay keeps that separate from an invalid answer.
import type { ServerValidator } from '@kajay/core';
const validateOnServer: ServerValidator = async ({ data, questionNames }) => {
const response = await fetch('/api/validate-survey', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ data, questionNames }),
});
if (!response.ok) throw new Error('Validation service unavailable');
return response.json();
};
survey.validation.setServerValidator(validateOnServer);