import {z} from 'zod' export type TarifStatusEnum = 'ACTIVE' | 'RETIRED'; export type TarifIn = {name: string, price: number, hard_limit: number, licenses?: (number | null) | undefined, monthly_limit_per_license?: (number | null) | undefined, soft_limit_fraction?: (number | null) | undefined, status?: (TarifStatusEnum | null) | undefined, expires_at?: (string | null) | undefined, description?: (string | null) | undefined, is_unlimited?: (boolean | null) | undefined}; export type PatchApiTarifsTarifIdArgs = {tarif_id: number, cookie_name?: (string | null) | undefined, tenant_id?: number | undefined, body: TarifIn}; export type PatchApiTarifsTarifIdOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const tarifStatusEnum = z.enum(["ACTIVE", "RETIRED"]); export const tarif = z.object({id: z.number().int().optional(), name: z.string().max(100), price: z.number(), hard_limit: z.number().gte(0).nullable().optional(), licenses: z.number().int().gte(0).nullable().optional(), monthly_limit_per_license: z.number().gte(0).nullable().optional(), soft_limit_fraction: z.number().gte(0).lte(1).nullable().optional(), is_unlimited: z.boolean().optional(), description: z.string().nullable().optional(), status: tarifStatusEnum.optional(), is_default: z.boolean().optional(), creator_user_id: z.number().int().nullable(), created_at: z.string().optional(), updated_at: z.string().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 a tarif plan * * PATCH /tarifs/{tarif_id} */ export const patchApiTarifsTarifId = async (args: PatchApiTarifsTarifIdArgs, options?: PatchApiTarifsTarifIdOptions) => { 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(/\/+$/, '')}/tarifs/${encodeURIComponent(String(args.tarif_id))}${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(tarif, await res.json()) };