import {z} from 'zod' export type InventoryGroupTarif = {id: number, weekdays?: Array | undefined, created_at: string, updated_at: string, start?: (string | null) | undefined, end?: (string | null) | undefined, published?: boolean | undefined, order?: number | undefined, name?: string | undefined, price?: unknown | undefined, tenant?: number | undefined, inventory: number | null, inventory_group?: (number | null) | undefined, inventory_set?: (number | null) | undefined, inventory_set_price?: (number | null) | undefined, time_period?: (number | null) | undefined}; export type CreateApiV1CrmGroupsGroupIdTarifsArgs = {group_id: number, body: InventoryGroupTarif}; export type CreateApiV1CrmGroupsGroupIdTarifsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const inventoryGroupTarif = z.object({id: z.number().int(), weekdays: z.array(z.number().int()).optional(), created_at: z.string(), updated_at: z.string(), start: z.string().nullable().optional(), end: z.string().nullable().optional(), published: z.boolean().optional(), order: z.number().int().gte(-2147483648).lte(2147483647).optional(), name: z.string().max(255).optional(), price: z.string().optional(), tenant: z.number().int().optional(), inventory: z.number().int().nullable(), inventory_group: z.number().int().nullable().optional(), inventory_set: z.number().int().nullable().optional(), inventory_set_price: z.number().int().nullable().optional(), time_period: z.number().int().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 }; /** * POST /v1/crm/groups/{group_id}/tarifs/ */ export const createApiV1CrmGroupsGroupIdTarifs = async (args: CreateApiV1CrmGroupsGroupIdTarifsArgs, options?: CreateApiV1CrmGroupsGroupIdTarifsOptions) => { const {baseUrl = "https://api.yume.cloud", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/crm/groups/${encodeURIComponent(String(args.group_id))}/tarifs/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(inventoryGroupTarif, await res.json()) };