import {z} from 'zod' export type ObjectReference = {id?: number | undefined, name?: (string | null) | undefined}; export type AgreementType = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13; export type Agreement = {id?: number | undefined, organization?: ObjectReference | undefined, name?: (string | null) | undefined, salesPriceCurrencyCode?: (string | null) | undefined, startDate?: string | undefined, endDate?: string | undefined, disabled?: boolean | undefined, publisher?: ObjectReference | undefined, program?: ObjectReference | undefined, number?: (string | null) | undefined, customerNumber?: (string | null) | undefined, masterAgreement?: (string | null) | undefined, hasTerms?: boolean | undefined, agreementType?: AgreementType | undefined, parentAgreementId?: (number | null) | undefined, commitmentLevel?: number | undefined, consumerId?: (number | null) | undefined}; export type AgreementAccess = {hasAccess?: boolean | undefined, agreement?: Agreement | undefined}; export type Organization = {id?: number | undefined, name?: (string | null) | undefined, parentId?: number | undefined, crayonCompanyName?: (string | null) | undefined, accountNumber?: (string | null) | undefined}; export type UserProfile = {id?: (string | null) | undefined, userName?: (string | null) | undefined, email?: (string | null) | undefined, firstName?: (string | null) | undefined, lastName?: (string | null) | undefined}; export type OrganizationAccessRole = 0 | 1 | 2 | 3 | 4 | 8 | 16 | 32 | 63; export type OrganizationAccess = {id?: number | undefined, allAgreements?: boolean | undefined, agreements?: (Array | null) | undefined, organization?: Organization | undefined, user?: UserProfile | undefined, role?: OrganizationAccessRole | undefined, crayonCompanyName?: (string | null) | undefined, timestamp?: string | undefined}; export type UpdateApiApiV1OrganizationAccessArgs = {body: Array | null}; export type UpdateApiApiV1OrganizationAccessOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const objectReference = z.object({id: z.number().int().optional(), name: z.string().nullable().optional()}); export const agreementType = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6), z.literal(7), z.literal(8), z.literal(9), z.literal(10), z.literal(11), z.literal(12), z.literal(13)]); export const agreement = z.object({id: z.number().int().optional(), organization: objectReference.optional(), name: z.string().nullable().optional(), salesPriceCurrencyCode: z.string().nullable().optional(), startDate: z.string().optional(), endDate: z.string().optional(), disabled: z.boolean().optional(), publisher: objectReference.optional(), program: objectReference.optional(), number: z.string().nullable().optional(), customerNumber: z.string().nullable().optional(), masterAgreement: z.string().nullable().optional(), hasTerms: z.boolean().optional(), agreementType: agreementType.optional(), parentAgreementId: z.number().int().nullable().optional(), commitmentLevel: z.number().optional(), consumerId: z.number().int().nullable().optional()}); export const agreementAccess = z.object({hasAccess: z.boolean().optional(), agreement: agreement.optional()}); export const organization = z.object({id: z.number().int().optional(), name: z.string().nullable().optional(), parentId: z.number().int().optional(), crayonCompanyName: z.string().nullable().optional(), accountNumber: z.string().nullable().optional()}); export const userProfile = z.object({id: z.string().nullable().optional(), userName: z.string().nullable().optional(), email: z.string().nullable().optional(), firstName: z.string().nullable().optional(), lastName: z.string().nullable().optional()}); export const organizationAccessRole = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(8), z.literal(16), z.literal(32), z.literal(63)]); export const organizationAccess = z.object({id: z.number().int().optional(), allAgreements: z.boolean().optional(), agreements: z.array(agreementAccess).nullable().optional(), organization: organization.optional(), user: userProfile.optional(), role: organizationAccessRole.optional(), crayonCompanyName: z.string().nullable().optional(), timestamp: z.string().optional()}); export const updateApiApiV1OrganizationAccessResponse = z.array(organizationAccess); 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 }; /** * PUT /api/v1/OrganizationAccess */ export const updateApiApiV1OrganizationAccess = async (args: UpdateApiApiV1OrganizationAccessArgs, options: UpdateApiApiV1OrganizationAccessOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/OrganizationAccess${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(updateApiApiV1OrganizationAccessResponse, await res.json()) };