import {z} from 'zod' export type PeriodEntry = {id?: string | undefined, type?: string | undefined, attributes?: ({start_date?: string | undefined, end_date?: string | undefined}) | undefined, meta?: ({temp_id?: string | undefined}) | undefined}; export type CreateApiV3AdministrationsAdministrationIdPeriodsArgs = {administration_id: string, 'fields[period]'?: string | undefined, include?: string | undefined, 'Accept-Language'?: string | undefined, body: {data?: ({type?: string | undefined, attributes?: ({name?: ({cs?: string | undefined, 'da-DK'?: string | undefined, de?: string | undefined, 'de-AT'?: string | undefined, 'de-CH'?: string | undefined, 'en-US'?: string | undefined, 'en-GB'?: string | undefined, es?: string | undefined, fr?: string | undefined, 'fr-BE'?: string | undefined, 'fr-LU'?: string | undefined, it?: string | undefined, nb?: string | undefined, nl?: string | undefined, 'nl-BE'?: string | undefined, pl?: string | undefined, pt?: string | undefined, tr?: string | undefined, en?: string | undefined, da?: string | undefined}) | undefined}) | undefined, relationships?: ({period_entries?: ({data?: (Array<{id?: string | undefined, type?: string | undefined, meta?: ({temp_id?: string | undefined, method?: string | undefined}) | undefined}>) | undefined}) | undefined}) | undefined, meta?: ({temp_id?: string | undefined}) | undefined}) | undefined, included?: Array | undefined}}; export type CreateApiV3AdministrationsAdministrationIdPeriodsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const period = z.object({id: z.string().optional(), type: z.string().optional(), attributes: z.object({name: z.object({cs: z.string().optional(), "da-DK": z.string().optional(), de: z.string().optional(), "de-AT": z.string().optional(), "de-CH": z.string().optional(), "en-US": z.string().optional(), "en-GB": z.string().optional(), es: z.string().optional(), fr: z.string().optional(), "fr-BE": z.string().optional(), "fr-LU": z.string().optional(), it: z.string().optional(), nb: z.string().optional(), nl: z.string().optional(), "nl-BE": z.string().optional(), pl: z.string().optional(), pt: z.string().optional(), tr: z.string().optional(), en: z.string().optional(), da: z.string().optional()}).optional()}).optional(), relationships: z.object({period_entries: z.object({data: z.array(z.object({id: z.string().optional(), type: z.string().optional(), meta: z.object({temp_id: z.string().optional(), method: z.string().optional()}).optional()})).optional()}).optional()}).optional(), meta: z.object({temp_id: z.string().optional()}).optional()}); export const periodEntry = z.object({id: z.string().optional(), type: z.string().optional(), attributes: z.object({start_date: z.string().optional(), end_date: z.string().optional()}).optional(), meta: z.object({temp_id: z.string().optional()}).optional()}); export const createApiV3AdministrationsAdministrationIdPeriodsResponse = z.object({data: period.optional(), included: z.array(periodEntry).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 period * * POST /v3/administrations/{administration_id}/periods * * Also accepts auth: OAuth2 */ export const createApiV3AdministrationsAdministrationIdPeriods = async (args: CreateApiV3AdministrationsAdministrationIdPeriodsArgs, options?: CreateApiV3AdministrationsAdministrationIdPeriodsOptions) => { const {baseUrl = "https://api.bookingexperts.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/vnd.api+json") headers.set('accept', "application/vnd.api+json") if (args['fields[period]'] != null) query.append("fields[period]", String(args['fields[period]'])) if (args.include != null) query.append("include", String(args.include)) if (args['Accept-Language'] != null) headers.set("Accept-Language", String(args['Accept-Language'])) if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v3/administrations/${encodeURIComponent(String(args.administration_id))}/periods${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(createApiV3AdministrationsAdministrationIdPeriodsResponse, await res.json()) };