import {z} from 'zod' export type GetApiNetworksOfferurlsOfferUrlIdArgs = {offerUrlId: number}; export type GetApiNetworksOfferurlsOfferUrlIdOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const offerUrl = z.object({network_offer_url_id: z.number().int().optional(), network_id: z.number().int().optional(), network_offer_id: z.number().int().optional(), name: z.string().optional(), destination_url: z.string().optional(), preview_url: z.string().optional(), url_status: z.enum(["active", "paused", "deleted"]).optional(), network_affiliate_ids: z.array(z.number().int()).nullable().optional(), is_apply_specific_affiliates: z.boolean().optional(), is_hidden_affiliate: z.boolean().optional(), time_created: z.number().int().optional(), time_saved: z.number().int().optional(), remote_offer_resource: z.object({network_offer_id: z.number().int().optional(), network_id: z.number().int().optional(), resource_type: z.string().optional(), remote_resource_id: z.string().optional(), resource_id: z.number().int().optional(), last_value_md5: z.string().optional(), json_config: z.string().optional(), json_data: z.string().optional(), time_created: z.number().int().optional(), time_saved: z.number().int().optional()}).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 Offer URL by ID * * GET /networks/offerurls/{offerUrlId} */ export const getApiNetworksOfferurlsOfferUrlId = async (args: GetApiNetworksOfferurlsOfferUrlIdArgs, options?: GetApiNetworksOfferurlsOfferUrlIdOptions) => { const {baseUrl = "https://api.eflow.team/v1", fetch: fetchFn = fetch, APIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (APIKey !== undefined) headers.set("X-Eflow-Api-Key", APIKey) const url = `${baseUrl.replace(/\/+$/, '')}/networks/offerurls/${encodeURIComponent(String(args.offerUrlId))}${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(offerUrl, await res.json()) };