import {z} from 'zod' export type AttributeQuery = Record; export type CreateApiV1ApplicationsApplicationIdCouponsSearchAdvancedNoTotalArgs = {pageSize?: number | undefined, skip?: number | undefined, sort?: string | undefined, applicationId: number, value?: string | undefined, createdBefore?: string | undefined, createdAfter?: string | undefined, valid?: ('expired' | 'validNow' | 'validFuture') | undefined, usable?: ('true' | 'false') | undefined, referralId?: number | undefined, recipientIntegrationId?: string | undefined, batchId?: string | undefined, exactMatch?: boolean | undefined, campaignState?: ('enabled' | 'disabled' | 'archived' | 'scheduled' | 'running' | 'expired' | 'staged') | undefined, body: AttributeQuery}; export type CreateApiV1ApplicationsApplicationIdCouponsSearchAdvancedNoTotalOptions = {baseUrl?: string | undefined, managerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const limitConfig = z.object({action: z.string(), limit: z.number().gte(0), period: z.enum(["daily", "weekly", "monthly", "yearly"]).optional(), entities: z.array(z.enum(["Coupon", "Referral", "Profile", "Identifier", "Store", "Session"]))}); export const coupon = z.object({id: z.number().int(), created: z.string(), campaignId: z.number().int(), value: z.string().min(4), usageLimit: z.number().int().gte(0).lte(999999), discountLimit: z.number().gte(0).lte(1000000000000000).optional(), reservationLimit: z.number().int().gte(0).lte(999999).optional(), startDate: z.string().optional(), expiryDate: z.string().optional(), limits: z.array(limitConfig).optional(), usageCounter: z.number().int(), discountCounter: z.number().optional(), discountRemainder: z.number().optional(), reservationCounter: z.number().optional(), attributes: z.object({}).optional(), referralId: z.number().int().optional(), recipientIntegrationId: z.string().max(1000).optional(), importId: z.number().int().optional(), reservation: z.boolean().optional(), batchId: z.string().optional(), isReservationMandatory: z.boolean().optional(), implicitlyReserved: z.boolean().optional()}); export const createApiV1ApplicationsApplicationIdCouponsSearchAdvancedNoTotalResponse = z.object({hasMore: z.boolean(), data: z.array(coupon)}); 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 }; /** * List coupons that match the given attributes (without total count) * * POST /v1/applications/{applicationId}/coupons_search_advanced/no_total * * Also accepts auth: management_key */ export const createApiV1ApplicationsApplicationIdCouponsSearchAdvancedNoTotal = async (args: CreateApiV1ApplicationsApplicationIdCouponsSearchAdvancedNoTotalArgs, options?: CreateApiV1ApplicationsApplicationIdCouponsSearchAdvancedNoTotalOptions) => { const {baseUrl = "https://yourbaseurl.talon.one", fetch: fetchFn = fetch, managerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.skip != null) query.append("skip", String(args.skip)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.value != null) query.append("value", String(args.value)) if (args.createdBefore != null) query.append("createdBefore", String(args.createdBefore)) if (args.createdAfter != null) query.append("createdAfter", String(args.createdAfter)) if (args.valid != null) query.append("valid", String(args.valid)) if (args.usable != null) query.append("usable", String(args.usable)) if (args.referralId != null) query.append("referralId", String(args.referralId)) if (args.recipientIntegrationId != null) query.append("recipientIntegrationId", String(args.recipientIntegrationId)) if (args.batchId != null) query.append("batchId", String(args.batchId)) if (args.exactMatch != null) query.append("exactMatch", String(args.exactMatch)) if (args.campaignState != null) query.append("campaignState", String(args.campaignState)) if (managerAuth !== undefined) headers.set("Authorization", managerAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/applications/${encodeURIComponent(String(args.applicationId))}/coupons_search_advanced/no_total${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(createApiV1ApplicationsApplicationIdCouponsSearchAdvancedNoTotalResponse, await res.json()) };