import {z} from 'zod' export type GetApiV1OrgOrgIdGoalGoalIdQuestionArgs = {orgId: string, goalId: string, phase?: ('FIRST' | 'UPDATE' | 'DONE') | undefined}; export type GetApiV1OrgOrgIdGoalGoalIdQuestionOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const translations = z.object({values: z.record(z.string(), z.string())}); export const enumValue = z.object({name: z.string(), label: z.string(), color: z.string().optional(), expr: z.string().optional(), num: z.number().optional(), sort: z.number().int().optional(), rank: z.number().int().optional(), id: z.string().optional(), labelTr: translations.optional()}); export const fieldOptions = z.object({min: z.string().optional(), max: z.string().optional(), minItems: z.number().int().optional(), maxItems: z.number().int().optional(), stackRank: z.boolean().optional(), step: z.number().optional(), enableEditDialog: z.boolean().optional(), requiredJobField: z.boolean().optional(), excludeTargetPersonId: z.boolean().optional(), maxLength: z.number().int().optional(), readOnly: z.boolean().optional(), includeFormer: z.boolean().optional(), groupTypeIds: z.array(z.string()).optional(), effectiveDated: z.boolean().optional(), unique: z.boolean().optional(), required: z.boolean().optional()}); export const goalQuestionInfo = z.object({id: z.string(), phase: z.enum(["FIRST", "UPDATE", "DONE"]), required: z.boolean().optional(), question: z.string(), questionTr: translations.optional(), type: z.enum(["ADDRESS", "ALLOCATIONS", "AUDIO", "BOOLEAN", "COMP", "COMPOUND", "COMP_BAND", "CONTACTS", "CURRENCY", "DATE", "DECIMAL", "ELAPSED_DAYS", "ELAPSED_MONTHS", "ELAPSED_YEARS", "EMAIL", "ENUM", "ENUM_EXPR", "ENUM_MULTI", "ENUM_SCALE", "EXPR", "FILE", "GROUP", "GROUPS", "GROUP_ASSIGNMENTS", "GROUP_TYPE", "GROUP_POSITION_ASSIGNMENTS", "IMAGE", "INTEGER", "JOB", "JOB_CODE", "JOBS", "JOB_TIER", "LIST", "MAP", "MONEY", "NAME", "OBJECT", "PAY_INTERVAL", "PERCENT", "PERSON", "PERSONS", "PHONE", "STOCKGRANT", "STRING", "TABLE_REF", "TEXT", "TIMEOFF", "TIMESTAMP", "TRACKED_GROUP", "URL", "USER", "VARIABLE_COMP", "VARIABLE_COMPS"]), plural: z.enum(["SINGLE", "LIST", "SET"]), values: z.array(enumValue).optional(), options: fieldOptions}); export const getApiV1OrgOrgIdGoalGoalIdQuestionResponse = z.array(goalQuestionInfo); 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 }; /** * Get the configured questions (hydrated with text) for a goal's progress updates, by phase * * GET /v1/org/{orgId}/goal/{goalId}/question */ export const getApiV1OrgOrgIdGoalGoalIdQuestion = async (args: GetApiV1OrgOrgIdGoalGoalIdQuestionArgs, options?: GetApiV1OrgOrgIdGoalGoalIdQuestionOptions) => { const {baseUrl = "https://localhost", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.phase != null) query.append("phase", String(args.phase)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/org/${encodeURIComponent(String(args.orgId))}/goal/${encodeURIComponent(String(args.goalId))}/question${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV1OrgOrgIdGoalGoalIdQuestionResponse, await res.json()) };