import {z} from 'zod' export type CreateApiV1OrgOrgIdCompReviewCompReviewIdDryRunArgs = {orgId: string, compReviewId: string}; export type CreateApiV1OrgOrgIdCompReviewCompReviewIdDryRunOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const revieweeChange = z.object({revieweeJobId: z.string(), revieweePersonId: z.string().optional(), reviewerJobId: z.string(), reviewerPersonId: z.string().optional()}); export const revieweeMove = z.object({revieweeJobId: z.string(), revieweePersonId: z.string().optional(), oldReviewerJobId: z.string(), oldReviewerPersonId: z.string().optional(), newReviewerJobId: z.string(), newReviewerPersonId: z.string().optional()}); export const ownershipChange = z.object({scenarioId: z.string(), oldOwnerJobId: z.string(), oldOwnerPersonId: z.string().optional(), newOwnerJobId: z.string(), newOwnerPersonId: z.string().optional()}); export const compReviewDryRunResponse = z.object({additions: z.array(revieweeChange), removals: z.array(revieweeChange), moves: z.array(revieweeMove), ownershipChanges: z.array(ownershipChange), hasChanges: z.boolean()}); 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 }; /** * Preview changes that will occur when resuming a paused comp review * * POST /v1/org/{orgId}/comp-review/{compReviewId}/dry-run */ export const createApiV1OrgOrgIdCompReviewCompReviewIdDryRun = async (args: CreateApiV1OrgOrgIdCompReviewCompReviewIdDryRunArgs, options?: CreateApiV1OrgOrgIdCompReviewCompReviewIdDryRunOptions) => { const {baseUrl = "https://localhost", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/org/${encodeURIComponent(String(args.orgId))}/comp-review/${encodeURIComponent(String(args.compReviewId))}/dry-run${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(compReviewDryRunResponse, await res.json()) };