import {z} from 'zod' export type SurveyConceptInput = {name: string, body?: (string | null) | undefined, asset_id?: (string | null) | undefined}; export type OpenEndedConfigInput = {format: 'text' | 'number', min?: (number | null) | undefined, max?: (number | null) | undefined, unit?: (string | null) | undefined}; export type OpenEndedQuestionInput = {type: 'open_ended', key: string, question: string, asset_id?: (string | null) | undefined, answer_config: OpenEndedConfigInput}; export type ChoiceOptionInput = {ref?: (string | null) | undefined, label: string}; export type MultipleChoiceConfigInput = {allow_multiple?: boolean | undefined, options: Array}; export type MultipleChoiceQuestionInput = {type: 'multiple_choice', key: string, question: string, asset_id?: (string | null) | undefined, answer_config: MultipleChoiceConfigInput}; export type ScaleConfigInput = {min: number, max: number, min_label?: (string | null) | undefined, max_label?: (string | null) | undefined, scoring?: ('semantic_similarity' | null) | undefined, ssr?: ({[key: string]: unknown} | null) | undefined}; export type ScaleQuestionInput = {type: 'scale', key: string, question: string, asset_id?: (string | null) | undefined, answer_config: ScaleConfigInput}; export type RankingOptionInput = {ref?: (string | null) | undefined, label?: (string | null) | undefined, asset_id?: (string | null) | undefined}; export type RankingConfigInput = {options: Array}; export type RankingQuestionInput = {type: 'ranking', key: string, question: string, asset_id?: (string | null) | undefined, answer_config: RankingConfigInput}; export type SurveySectionInput = {title: string, section_type?: ('question_group' | 'concept_test') | undefined, concept_category: 'creatives' | 'messaging' | 'scenarios' | 'websites', concepts?: Array | undefined, questions: Array}; export type SurveyUpdateRequest = {populationId?: (string | null) | undefined, name?: (string | null) | undefined, context?: (string | null) | undefined, demographicFilter?: ({[key: string]: Array} | null) | undefined, sections?: (Array | null) | undefined}; export type PatchApiWorkspacesWorkspaceIdSurveysSurveyIdArgs = {survey_id: string, workspace_id: string, body: SurveyUpdateRequest}; export type PatchApiWorkspacesWorkspaceIdSurveysSurveyIdOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const surveyIdResponse = z.object({id: z.string()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Update Survey * * PATCH /workspaces/{workspace_id}/surveys/{survey_id} */ export const patchApiWorkspacesWorkspaceIdSurveysSurveyId = async (args: PatchApiWorkspacesWorkspaceIdSurveysSurveyIdArgs, options: PatchApiWorkspacesWorkspaceIdSurveysSurveyIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/workspaces/${encodeURIComponent(String(args.workspace_id))}/surveys/${encodeURIComponent(String(args.survey_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(surveyIdResponse, await res.json()) };