import {z} from 'zod' export type QPilotCoreModelsQuickLinkActionType = 'Resume' | 'Pause' | 'ProcessNow' | 'Reactivate'; export type QPilotCoreModelsQuickLinkUsageLimitType = 'SingleUse' | 'LimitedUse' | 'Unlimited'; export type QPilotCoreModelsQuickLinkRedirectType = 'ThankYouPage' | 'V2Portal' | 'CustomUrl'; export type QPilotCoreModelsDtoQuickLinksRedirectConfigDto = {type: QPilotCoreModelsQuickLinkRedirectType, message?: (string | null) | undefined, customUrl?: (string | null) | undefined, utmParams?: (string | null) | undefined}; export type QPilotCoreModelsDtoQuickLinksCreateQuickLinkDto = {name: string, slug?: (string | null) | undefined, actionType: QPilotCoreModelsQuickLinkActionType, usageLimitType: QPilotCoreModelsQuickLinkUsageLimitType, maxUses?: (number | null) | undefined, requiresLogin?: boolean | undefined, requiresConfirmation?: boolean | undefined, expiredUtc?: (string | null) | undefined, redirect?: QPilotCoreModelsDtoQuickLinksRedirectConfigDto | undefined}; export type CreateApiSitesSiteIdQuicklinksArgs = {siteId: number, body: QPilotCoreModelsDtoQuickLinksCreateQuickLinkDto}; export type CreateApiSitesSiteIdQuicklinksOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const qPilotCoreModelsQuickLinkActionType = z.enum(["Resume", "Pause", "ProcessNow", "Reactivate"]); export const qPilotCoreModelsQuickLinkStatusType = z.enum(["Disabled", "Enabled", "Deleted"]); export const qPilotCoreModelsQuickLinkUsageLimitType = z.enum(["SingleUse", "LimitedUse", "Unlimited"]); export const qPilotCoreModelsQuickLinkRedirectType = z.enum(["ThankYouPage", "V2Portal", "CustomUrl"]); export const qPilotCoreModelsDtoQuickLinksRedirectConfigDto = z.object({type: qPilotCoreModelsQuickLinkRedirectType, message: z.string().nullable().optional(), customUrl: z.string().max(500).nullable().optional(), utmParams: z.string().nullable().optional()}); export const qPilotCoreModelsDtoQuickLinksQuickLinkDetailDto = z.object({id: z.number().int().optional(), siteId: z.number().int().optional(), name: z.string().nullable().optional(), slug: z.string().nullable().optional(), actionType: qPilotCoreModelsQuickLinkActionType.optional(), status: qPilotCoreModelsQuickLinkStatusType.optional(), usageLimitType: qPilotCoreModelsQuickLinkUsageLimitType.optional(), maxUses: z.number().int().nullable().optional(), currentUsageCount: z.number().int().optional(), requiresLogin: z.boolean().optional(), requiresConfirmation: z.boolean().optional(), createdUtc: z.string().optional(), updatedUtc: z.string().optional(), expiredUtc: z.string().nullable().optional(), redirect: qPilotCoreModelsDtoQuickLinksRedirectConfigDto.optional(), templateUrl: 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 }; /** * Creates a new QuickLink for a site. * * POST /Sites/{siteId}/Quicklinks */ export const createApiSitesSiteIdQuicklinks = async (args: CreateApiSitesSiteIdQuicklinksArgs, options?: CreateApiSitesSiteIdQuicklinksOptions) => { const {baseUrl = "https://api.qpilot.cloud", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/Sites/${encodeURIComponent(String(args.siteId))}/Quicklinks${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(qPilotCoreModelsDtoQuickLinksQuickLinkDetailDto, await res.json()) };