import {z} from 'zod' export type TenantUpdateIn = {name?: (string | null) | undefined, domain?: (string | null) | undefined, parent_tenant_id?: (number | null) | undefined, subtenants_enabled?: (boolean | null) | undefined, timezone?: (string | null) | undefined, locale?: (string | null) | undefined, tarif_id?: (number | null) | undefined, tarif_expires_at?: (string | null) | undefined, max_users?: (number | null) | undefined, max_projects?: (number | null) | undefined, licenses?: (number | null) | undefined, display_name?: (string | null) | undefined, motto?: (string | null) | undefined, logo_url?: (string | null) | undefined, square_logo_url?: (string | null) | undefined, favicon_url?: (string | null) | undefined, chat_square_logo_url?: (string | null) | undefined, primary_color?: (string | null) | undefined, secondary_color?: (string | null) | undefined, theme?: (string | null) | undefined, storage_limit_gb?: (number | null) | undefined, api_rate_limit?: (number | null) | undefined, upstream_tenant_id?: (string | null) | undefined, upstream_oidc_issuer?: (string | null) | undefined}; export type PatchApiTenantsCurrentArgs = {cookie_name?: (string | null) | undefined, tenant_id?: number | undefined, body: TenantUpdateIn}; export type PatchApiTenantsCurrentOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const tenantOut = z.object({id: z.number().int(), created_at: z.string(), creator_user_id: z.number().int().nullable().optional(), name: z.string(), slug: z.string(), domain: z.string().nullable().optional(), parent_tenant_id: z.number().int().nullable().optional(), subtenants_enabled: z.boolean(), timezone: z.string(), locale: z.string(), tarif_id: z.number().int().nullable().optional(), max_users: z.number().int().nullable().optional(), max_projects: z.number().int().nullable().optional(), licenses: z.number().int().nullable().optional(), display_name: z.string().nullable().optional(), motto: z.string().nullable().optional(), logo_url: z.string().nullable().optional(), square_logo_url: z.string().nullable().optional(), favicon_url: z.string().nullable().optional(), chat_square_logo_url: z.string().nullable().optional(), primary_color: z.string().nullable().optional(), secondary_color: z.string().nullable().optional(), theme: z.string().nullable().optional(), storage_limit_gb: z.number().int().nullable().optional(), api_rate_limit: z.number().int().nullable().optional(), state: z.string().nullable().optional(), upstream_tenant_id: z.string().nullable().optional(), upstream_oidc_issuer: z.string().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 }; /** * Update current tenant * * PATCH /tenants/current */ export const patchApiTenantsCurrent = async (args: PatchApiTenantsCurrentArgs, options?: PatchApiTenantsCurrentOptions) => { const {baseUrl = "https://api.your-domain.com", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.cookie_name != null) query.append("cookie_name", String(args.cookie_name)) if (args.tenant_id != null) query.append("tenant_id", String(args.tenant_id)) if (APIKeyHeader !== undefined) headers.set("X-API-KEY", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/tenants/current${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(tenantOut, await res.json()) };