import {z} from 'zod' export type Limitation = {Count: number, Cursor?: (string | null) | undefined}; export type TimeFilterInterval = {StartUtc?: (string | null) | undefined, EndUtc?: (string | null) | undefined}; export type ActivityStates = 'Deleted' | 'Active'; export type CancellationPolicyFilterParameters = {ClientToken: string, AccessToken: string, Client: string, Limitation: Limitation, EnterpriseIds?: (Array | null) | undefined, ServiceIds: Array, CancellationPolicyIds?: (Array | null) | undefined, RateGroupIds?: (Array | null) | undefined, UpdatedUtc?: (TimeFilterInterval | null) | undefined, ActivityStates?: (Array | null) | undefined}; export type CreateApiApiConnectorV1CancellationPoliciesGetAllArgs = {body: CancellationPolicyFilterParameters}; export type CreateApiApiConnectorV1CancellationPoliciesGetAllOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const cancellationPolicyApplicability = z.enum(["Creation", "Start", "StartDate"]); export const cancellationFeeExtent = z.enum(["TimeUnits", "Products"]); export const currencyValue = z.object({Currency: z.string().min(1), Value: z.number()}); export const cancellationPolicy = z.object({Id: z.string(), RateGroupId: z.string(), CreatedUtc: z.string().min(1), UpdatedUtc: z.string().min(1), Applicability: cancellationPolicyApplicability, FeeExtent: z.array(cancellationFeeExtent), ApplicabilityOffset: z.string().min(1), FeeMaximumTimeUnits: z.number().int().nullable().optional(), AbsoluteFee: currencyValue, RelativeFee: z.number(), IsActive: z.boolean()}); export const cancellationPolicyResult = z.object({CancellationPolicies: z.array(cancellationPolicy), Cursor: 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 all cancellation policies * * POST /api/connector/v1/cancellationPolicies/getAll */ export const createApiApiConnectorV1CancellationPoliciesGetAll = async (args: CreateApiApiConnectorV1CancellationPoliciesGetAllArgs, options?: CreateApiApiConnectorV1CancellationPoliciesGetAllOptions) => { const {baseUrl = "https://api.mews.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/connector/v1/cancellationPolicies/getAll${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(cancellationPolicyResult, await res.json()) };