import {z} from 'zod' export type AdaptekApiCommonConstantsPeopleRelationshipType = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24; export type AdaptekApiApplicationPeopleFTKCommandsSaveFTKPersonRelationshipSaveFTKPersonRelationshipCommand = {consumer1Id?: number | undefined, consumer2Id?: number | undefined, relationshipTypeId?: AdaptekApiCommonConstantsPeopleRelationshipType | undefined, isDeleted?: boolean | undefined}; export type UpdateApiV1PeopleFTKRelationshipsArgs = {body: AdaptekApiApplicationPeopleFTKCommandsSaveFTKPersonRelationshipSaveFTKPersonRelationshipCommand}; export type UpdateApiV1PeopleFTKRelationshipsOptions = {baseUrl: string, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const microsoftAspNetCoreMvcFormattersIOutputFormatter = z.object({}); export const microsoftAspNetCoreMvcCreatedResult = z.object({location: z.string().nullable().optional(), value: z.unknown(), formatters: z.array(microsoftAspNetCoreMvcFormattersIOutputFormatter).nullable().optional(), contentTypes: z.array(z.string()).nullable().optional(), declaredType: z.string().nullable().optional(), statusCode: z.number().int().nullable().optional()}); 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 }; /** * Creates or updates a Person Relationship record * * PUT /v1/PeopleFTK/Relationships */ export const updateApiV1PeopleFTKRelationships = async (args: UpdateApiV1PeopleFTKRelationshipsArgs, options: UpdateApiV1PeopleFTKRelationshipsOptions) => { const {baseUrl, fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/PeopleFTK/Relationships${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(microsoftAspNetCoreMvcCreatedResult, await res.json()) };