import {z} from 'zod' export type UpdateOrganizationSettings = {oidcLinkingEnabled?: (boolean | null) | undefined, oidcToEmailLinkingEnabled?: (boolean | null) | undefined, supportImpersonationEnabled?: (boolean | null) | undefined, semanticLayerPgwireEnabled?: (boolean | null) | undefined, scheduledDeliveryExpirationSeconds?: (number | null) | undefined, scheduledDeliveryExpirationSecondsEmail?: (number | null) | undefined, scheduledDeliveryExpirationSecondsSlack?: (number | null) | undefined, scheduledDeliveryExpirationSecondsMsTeams?: (number | null) | undefined, scheduledDeliveryExpirationSecondsGoogleChat?: (number | null) | undefined, queryLimit?: (number | null) | undefined, csvCellsLimit?: (number | null) | undefined, corsAllowedDomains?: (Array | null) | undefined}; export type PatchApiApiV1OrgSettingsArgs = {body: UpdateOrganizationSettings}; export type PatchApiApiV1OrgSettingsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const organizationSettings = z.object({corsAllowedDomains: z.array(z.string()).nullable(), csvCellsLimit: z.number().nullable(), queryLimit: z.number().nullable(), scheduledDeliveryExpirationSecondsGoogleChat: z.number().nullable(), scheduledDeliveryExpirationSecondsMsTeams: z.number().nullable(), scheduledDeliveryExpirationSecondsSlack: z.number().nullable(), scheduledDeliveryExpirationSecondsEmail: z.number().nullable(), scheduledDeliveryExpirationSeconds: z.number().nullable(), semanticLayerPgwireEnabled: z.boolean().nullable(), supportImpersonationEnabled: z.boolean().nullable(), oidcToEmailLinkingEnabled: z.boolean().nullable(), oidcLinkingEnabled: z.boolean().nullable()}); export const apiOrganizationSettingsResponse = z.object({results: organizationSettings, status: z.literal("ok")}); 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 organization settings * * PATCH /api/v1/org/settings */ export const patchApiApiV1OrgSettings = async (args: PatchApiApiV1OrgSettingsArgs, options: PatchApiApiV1OrgSettingsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/org/settings${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(apiOrganizationSettingsResponse, await res.json()) };