import {z} from 'zod' export type GetApiPublicUserServiceAdjustmentRetrieveServiceAdjustmentIdArgs = {service_adjustment_id: string}; export type GetApiPublicUserServiceAdjustmentRetrieveServiceAdjustmentIdOptions = {baseUrl?: string | undefined, APIPrivateKey?: string | undefined, APIPublicKey?: string | undefined, fetch?: typeof fetch | undefined}; export const proxyReplacement = z.object({proxy_replacement_creation_datetime: z.string().optional(), proxy_replacement_http_port: z.number().int().optional(), proxy_replacement_id: z.number().int().optional(), proxy_replacement_ip_address_ipv4: z.string().optional(), proxy_replacement_ip_address_ipv6: z.string().optional(), proxy_replacement_new_http_port: z.number().int().optional(), proxy_replacement_new_ip_address_ipv4: z.string().optional(), proxy_replacement_new_ip_address_ipv6: z.string().optional(), proxy_replacement_new_socks5_port: z.number().int().optional(), proxy_replacement_reason: z.enum(["customer_request", "ip_reputation", "end_of_deployment", "outage", "other"]).optional(), proxy_replacement_socks5_port: z.number().int().optional()}); export const getApiPublicUserServiceAdjustmentRetrieveServiceAdjustmentIdResponse = z.object({data: z.object({invoice_id: z.string().optional(), service_adjustment_creation_datetime: z.string().optional(), service_adjustment_eval: z.object({}).optional(), service_adjustment_id: z.number().int().optional(), service_adjustment_is_administrator: z.boolean().optional(), service_adjustment_is_automatic: z.boolean().optional(), service_adjustment_is_customer: z.boolean().optional(), service_adjustment_last_update_datetime: z.string().optional(), service_adjustment_post: z.object({}).optional(), service_adjustment_pre: z.object({}).optional(), service_adjustment_status: z.enum(["complete", "pending", "failed"]).optional(), service_adjustment_type: z.enum(["ingestion", "fulfillment", "remove_proxy", "additional_fulfillment", "update", "proxy_replacement", "extension", "top_up", "top_up_and_extension", "cancel"]).optional(), service_id: z.string().optional(), proxy_replacements: z.array(proxyReplacement).optional()}).optional(), message: z.string().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 }; /** * Retrieve Service Adjustment * * GET /public/user/service_adjustment/retrieve/{service_adjustment_id} */ export const getApiPublicUserServiceAdjustmentRetrieveServiceAdjustmentId = async (args: GetApiPublicUserServiceAdjustmentRetrieveServiceAdjustmentIdArgs, options?: GetApiPublicUserServiceAdjustmentRetrieveServiceAdjustmentIdOptions) => { const {baseUrl = "https://api.byteful.com/1.0", fetch: fetchFn = fetch, APIPrivateKey, APIPublicKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (APIPrivateKey !== undefined) headers.set("X-API-Private-Key", APIPrivateKey) if (APIPublicKey !== undefined) headers.set("X-API-Public-Key", APIPublicKey) const url = `${baseUrl.replace(/\/+$/, '')}/public/user/service_adjustment/retrieve/${encodeURIComponent(String(args.service_adjustment_id))}${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(getApiPublicUserServiceAdjustmentRetrieveServiceAdjustmentIdResponse, await res.json()) };