import {z} from 'zod' export type PriceCategory = 'none' | 'platform'; export type Country = 'VA' | 'MM' | 'PE' | 'DK' | 'PY' | 'SV' | 'US' | 'SI' | 'SG' | 'CZ' | 'KE' | 'JP' | 'KR' | 'NZ' | 'KZ' | 'AE' | 'IQ' | 'AU' | 'CL' | 'QA' | 'NL' | 'IN' | 'GE' | 'EE' | 'BM' | 'AT' | 'VN' | 'LI' | 'KW' | 'TC' | 'BR' | 'PL' | 'MY' | 'HK' | 'MC' | 'VG' | 'GI' | 'SE' | 'EG' | 'GH' | 'CH' | 'LK' | 'SA' | 'SM' | 'PK' | 'DE' | 'TW' | 'LU' | 'BO' | 'FM' | 'CA' | 'SK' | 'LT' | 'FR' | 'KY' | 'LV' | 'CY' | 'MX' | 'RO' | 'TZ' | 'HU' | 'PH' | 'MO' | 'FI' | 'RS' | 'EC' | 'IE' | 'ID' | 'OM' | 'BD' | 'PA' | 'UA' | 'ZA' | 'ES' | 'PT' | 'NO' | 'NG' | 'TH' | 'IL' | 'GB' | 'JO' | 'IT' | 'BG' | 'TR' | 'BH' | 'CR' | 'MA' | 'HR' | 'GR' | 'KH' | 'CO' | 'BE' | 'DZ' | 'CN' | 'AD' | 'AL' | 'BA' | 'IS' | 'MD' | 'ME' | 'MK' | 'MT' | 'RU' | 'AR'; export type Currency = 'USD' | 'EUR' | 'AED' | 'AFN' | 'ALL' | 'AMD' | 'ANG' | 'AOA' | 'ARS' | 'AUD' | 'AWG' | 'AZN' | 'BAM' | 'BBD' | 'BDT' | 'BGN' | 'BHD' | 'BIF' | 'BMD' | 'BND' | 'BOB' | 'BRL' | 'BSD' | 'BTN' | 'BWP' | 'BYN' | 'BZD' | 'CAD' | 'CDF' | 'CHF' | 'CLP' | 'CNY' | 'COP' | 'CRC' | 'CUP' | 'CVE' | 'CZK' | 'DJF' | 'DKK' | 'DOP' | 'DZD' | 'EGP' | 'ERN' | 'ETB' | 'FJD' | 'FKP' | 'GBP' | 'GEL' | 'GHS' | 'GIP' | 'GMD' | 'GNF' | 'GTQ' | 'GYD' | 'HKD' | 'HNL' | 'HTG' | 'HUF' | 'IDR' | 'ILS' | 'INR' | 'IQD' | 'IRR' | 'ISK' | 'JMD' | 'JOD' | 'JPY' | 'KES' | 'KGS' | 'KHR' | 'KMF' | 'KPW' | 'KRW' | 'KWD' | 'KYD' | 'KZT' | 'LAK' | 'LBP' | 'LKR' | 'LRD' | 'LSL' | 'LYD' | 'MAD' | 'MDL' | 'MGA' | 'MKD' | 'MMK' | 'MNT' | 'MOP' | 'MRU' | 'MUR' | 'MVR' | 'MWK' | 'MXN' | 'MYR' | 'MZN' | 'NAD' | 'NGN' | 'NIO' | 'NOK' | 'NPR' | 'NZD' | 'OMR' | 'PAB' | 'PEN' | 'PGK' | 'PHP' | 'PKR' | 'PLN' | 'PYG' | 'QAR' | 'RON' | 'RSD' | 'RUB' | 'RWF' | 'SAR' | 'SBD' | 'SCR' | 'SDG' | 'SEK' | 'SGD' | 'SHP' | 'SLE' | 'SOS' | 'SRD' | 'SSP' | 'STN' | 'SVC' | 'SYP' | 'SZL' | 'THB' | 'TJS' | 'TMT' | 'TND' | 'TOP' | 'TRY' | 'TTD' | 'TWD' | 'TZS' | 'UAH' | 'UGX' | 'UYU' | 'UZS' | 'VED' | 'VES' | 'VND' | 'VUV' | 'WST' | 'XAF' | 'XCD' | 'XCG' | 'XOF' | 'XPF' | 'YER' | 'ZAR' | 'ZMW' | 'ZWG' | 'ZWL' | 'RP' | 'VC'; export type Platform = 'any' | 'ios' | 'android' | 'other'; export type Price = {country: Country, currency: Currency, platform: Platform, price: number}; export type PriceTemplateUpdate = {key?: string | undefined, name?: string | undefined, price?: number | undefined, category?: PriceCategory | undefined, customs?: Array | undefined}; export type UpdateApiV1PriceTemplatesPriceTemplateIdArgs = {price_template_id: string, body: PriceTemplateUpdate}; export type UpdateApiV1PriceTemplatesPriceTemplateIdOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const priceCategory = z.enum(["none", "platform"]); export const country = z.enum(["VA", "MM", "PE", "DK", "PY", "SV", "US", "SI", "SG", "CZ", "KE", "JP", "KR", "NZ", "KZ", "AE", "IQ", "AU", "CL", "QA", "NL", "IN", "GE", "EE", "BM", "AT", "VN", "LI", "KW", "TC", "BR", "PL", "MY", "HK", "MC", "VG", "GI", "SE", "EG", "GH", "CH", "LK", "SA", "SM", "PK", "DE", "TW", "LU", "BO", "FM", "CA", "SK", "LT", "FR", "KY", "LV", "CY", "MX", "RO", "TZ", "HU", "PH", "MO", "FI", "RS", "EC", "IE", "ID", "OM", "BD", "PA", "UA", "ZA", "ES", "PT", "NO", "NG", "TH", "IL", "GB", "JO", "IT", "BG", "TR", "BH", "CR", "MA", "HR", "GR", "KH", "CO", "BE", "DZ", "CN", "AD", "AL", "BA", "IS", "MD", "ME", "MK", "MT", "RU", "AR"]); export const currency = z.enum(["USD", "EUR", "AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF", "CHF", "CLP", "CNY", "COP", "CRC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "FJD", "FKP", "GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HTG", "HUF", "IDR", "ILS", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRU", "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLE", "SOS", "SRD", "SSP", "STN", "SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "UYU", "UZS", "VED", "VES", "VND", "VUV", "WST", "XAF", "XCD", "XCG", "XOF", "XPF", "YER", "ZAR", "ZMW", "ZWG", "ZWL", "RP", "VC"]); export const platform = z.enum(["any", "ios", "android", "other"]); export const templatePrice = z.object({country: country, currency: currency, platform: platform, price: z.number().int().gte(0).lte(1000000000000), is_custom: z.boolean()}); export const priceTemplateRead = z.object({key: z.string().optional(), name: z.string(), price: z.number().int(), category: priceCategory, id: z.string().max(32), items_count: z.number().int().optional(), created_at: z.number().int(), modified_at: z.number().int().optional(), prices: z.array(templatePrice)}); 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 }; /** * Update Price Template * * PUT /v1/price_templates/{price_template_id} */ export const updateApiV1PriceTemplatesPriceTemplateId = async (args: UpdateApiV1PriceTemplatesPriceTemplateIdArgs, options?: UpdateApiV1PriceTemplatesPriceTemplateIdOptions) => { const {baseUrl = "https://api.aghanim.com/s2s", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/price_templates/${encodeURIComponent(String(args.price_template_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(priceTemplateRead, await res.json()) };