import {z} from 'zod' export type GetApiV1ApplicationsApplicationIdSessionsArgs = {pageSize?: number | undefined, skip?: number | undefined, sort?: string | undefined, partialMatch?: boolean | undefined, profile?: string | undefined, state?: ('open' | 'closed' | 'partially_returned' | 'cancelled') | undefined, createdBefore?: string | undefined, createdAfter?: string | undefined, coupon?: string | undefined, referral?: string | undefined, integrationId?: string | undefined, storeIntegrationId?: string | undefined, applicationId: number}; export type GetApiV1ApplicationsApplicationIdSessionsOptions = {baseUrl?: string | undefined, managerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const product = z.object({name: z.string()}); export const additionalCost = z.object({price: z.number()}); export const priceDetail = z.object({price: z.number().optional(), adjustmentContextId: z.string().optional(), adjustmentReferenceId: z.string().optional(), adjustmentEffectiveFrom: z.string().optional(), adjustmentEffectiveUntil: z.string().optional()}); export const cartItem = z.object({name: z.string().optional(), sku: z.string().min(1), quantity: z.number().int().gte(1), returnedQuantity: z.number().int().optional(), remainingQuantity: z.number().int().optional(), price: z.number().optional(), category: z.string().optional(), product: product.optional(), weight: z.number().optional(), height: z.number().optional(), width: z.number().optional(), length: z.number().optional(), position: z.number().optional(), attributes: z.object({}).optional(), additionalCosts: z.record(z.string(), additionalCost).optional(), catalogItemID: z.number().int().optional(), selectedPriceType: z.string().optional(), adjustmentReferenceId: z.string().optional(), adjustmentEffectiveFrom: z.string().optional(), adjustmentEffectiveUntil: z.string().optional(), prices: z.record(z.string(), priceDetail).optional()}); export const applicationSession = z.object({id: z.number().int(), created: z.string(), integrationId: z.string().max(1000), storeIntegrationId: z.string().min(1).max(1000).optional(), applicationId: z.number().int(), profileId: z.number().int().optional(), profileintegrationid: z.string().max(1000).optional(), coupon: z.string(), referral: z.string(), state: z.enum(["open", "closed", "partially_returned", "cancelled"]), cartItems: z.array(cartItem), discounts: z.record(z.string(), z.number()), totalDiscounts: z.number(), total: z.number(), attributes: z.object({}).optional()}); export const getApiV1ApplicationsApplicationIdSessionsResponse = z.object({hasMore: z.boolean().optional(), data: z.array(applicationSession)}); 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 Application sessions * * GET /v1/applications/{applicationId}/sessions * * Also accepts auth: management_key */ export const getApiV1ApplicationsApplicationIdSessions = async (args: GetApiV1ApplicationsApplicationIdSessionsArgs, options?: GetApiV1ApplicationsApplicationIdSessionsOptions) => { const {baseUrl = "https://yourbaseurl.talon.one", fetch: fetchFn = fetch, managerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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.partialMatch != null) query.append("partialMatch", String(args.partialMatch)) if (args.profile != null) query.append("profile", String(args.profile)) if (args.state != null) query.append("state", String(args.state)) if (args.createdBefore != null) query.append("createdBefore", String(args.createdBefore)) if (args.createdAfter != null) query.append("createdAfter", String(args.createdAfter)) if (args.coupon != null) query.append("coupon", String(args.coupon)) if (args.referral != null) query.append("referral", String(args.referral)) if (args.integrationId != null) query.append("integrationId", String(args.integrationId)) if (args.storeIntegrationId != null) query.append("storeIntegrationId", String(args.storeIntegrationId)) if (managerAuth !== undefined) headers.set("Authorization", managerAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/applications/${encodeURIComponent(String(args.applicationId))}/sessions${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV1ApplicationsApplicationIdSessionsResponse, await res.json()) };