import {z} from 'zod' export type GlobalSettingType = 0 | 1 | 100 | 101 | 102 | 103 | 200 | 201 | 203 | 500 | 1000 | 2000 | 3000; export type BulkUpdateGlobalSettingRequest = {id?: (string | null) | undefined, value?: (string | null) | undefined, type?: GlobalSettingType | undefined}; export type UpdateApiV1GlobalSettingsBulkArgs = {Account: unknown, body: Array}; export type UpdateApiV1GlobalSettingsBulkOptions = {baseUrl: string, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const globalSettingType = z.union([z.literal(0), z.literal(1), z.literal(100), z.literal(101), z.literal(102), z.literal(103), z.literal(200), z.literal(201), z.literal(203), z.literal(500), z.literal(1000), z.literal(2000), z.literal(3000)]); export const globalSettingsResponse = z.object({id: z.string().nullable().optional(), value: z.string().nullable().optional(), isReserved: z.boolean().optional(), type: globalSettingType.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 }; /** * Update multiple global settings with new values and types * * PUT /v1/GlobalSettings/bulk */ export const updateApiV1GlobalSettingsBulk = async (args: UpdateApiV1GlobalSettingsBulkArgs, options: UpdateApiV1GlobalSettingsBulkOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json-patch+json; x-api-version=1.0") headers.set('accept', "application/json") if (args.Account != null) query.append("Account", String(args.Account)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/GlobalSettings/bulk${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(globalSettingsResponse, await res.json()) };