import {z} from 'zod' export type GetApiTenantsCurrentArgs = {cookie_name?: (string | null) | undefined}; export type GetApiTenantsCurrentOptions = {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 }; /** * Get current tenant * * GET /tenants/current */ export const getApiTenantsCurrent = async (args: GetApiTenantsCurrentArgs, options?: GetApiTenantsCurrentOptions) => { const {baseUrl = "https://api.your-domain.com", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.cookie_name != null) query.append("cookie_name", String(args.cookie_name)) 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: "GET", headers}) 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()) };