import {z} from 'zod' export type GetApiApiV2VirtualPhoneAccountsIdSmsMessagesArgs = {id: string, page: number, pageSize: number, receivedAtFrom?: string | undefined, receivedAtTo?: string | undefined, service?: (Array<'none' | 'whatsapp' | 'google' | 'telegram' | 'tiktok' | 'shopee' | 'amazon' | 'facebook' | 'nubank' | 'microsoft' | 'instagram' | 'hotmart' | 'discord' | 'godaddy' | 'twilio' | 'youtube' | 'claude' | 'samsung' | 'c6' | 'ifood' | 'paypal' | 'autodesk' | 'globo' | 'apple' | 'asaas' | 'mercado-livre' | 'wechat' | 'alipay' | 'airbnb' | 'snapchat' | 'hostgator' | 'messages' | 'sendpulse' | 'kwai' | 'salvy' | 'santander' | 'itau' | 'temu' | 'mercado-pago' | 'indeed' | 'zoom' | 'x' | 'hostinger' | 'unknown'>) | undefined}; export type GetApiApiV2VirtualPhoneAccountsIdSmsMessagesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV2VirtualPhoneAccountsIdSmsMessagesResponse = z.object({smsMessages: z.array(z.object({id: z.string(), receivedAt: z.string(), originPhoneNumber: z.string(), destinationPhoneNumber: z.string(), message: z.string(), detections: z.object({whatsapp: z.object({verificationCode: z.string()}).optional(), google: z.object({verificationCode: z.string()}).optional(), telegram: z.object({verificationCode: z.string()}).optional(), tiktok: z.object({verificationCode: z.string()}).optional(), shopee: z.object({verificationCode: z.string()}).optional(), amazon: z.object({verificationCode: z.string()}).optional(), facebook: z.object({verificationCode: z.string()}).optional(), nubank: z.object({verificationCode: z.string()}).optional(), microsoft: z.object({verificationCode: z.string()}).optional(), instagram: z.object({verificationCode: z.string()}).optional(), hotmart: z.object({verificationCode: z.string()}).optional(), discord: z.object({verificationCode: z.string()}).optional(), godaddy: z.object({verificationCode: z.string()}).optional(), twilio: z.object({verificationCode: z.string()}).optional(), youtube: z.object({verificationCode: z.string()}).optional(), claude: z.object({verificationCode: z.string()}).optional(), samsung: z.object({verificationCode: z.string()}).optional(), c6: z.object({verificationCode: z.string()}).optional(), ifood: z.object({verificationCode: z.string()}).optional(), paypal: z.object({verificationCode: z.string()}).optional(), autodesk: z.object({verificationCode: z.string()}).optional(), globo: z.object({verificationCode: z.string()}).optional(), apple: z.object({verificationCode: z.string()}).optional(), asaas: z.object({verificationCode: z.string()}).optional(), "mercado-livre": z.object({verificationCode: z.string()}).optional(), wechat: z.object({verificationCode: z.string()}).optional(), alipay: z.object({verificationCode: z.string()}).optional(), airbnb: z.object({verificationCode: z.string()}).optional(), snapchat: z.object({verificationCode: z.string()}).optional(), hostgator: z.object({verificationCode: z.string()}).optional(), messages: z.object({verificationCode: z.string()}).optional(), sendpulse: z.object({verificationCode: z.string()}).optional(), kwai: z.object({verificationCode: z.string()}).optional(), salvy: z.object({verificationCode: z.string()}).optional(), santander: z.object({verificationCode: z.string()}).optional(), itau: z.object({verificationCode: z.string()}).optional(), temu: z.object({verificationCode: z.string()}).optional(), "mercado-pago": z.object({verificationCode: z.string()}).optional(), indeed: z.object({verificationCode: z.string()}).optional(), zoom: z.object({verificationCode: z.string()}).optional(), x: z.object({verificationCode: z.string()}).optional(), hostinger: z.object({verificationCode: z.string()}).optional()})})), pagination: z.object({page: z.number().int().gte(-9007199254740991).lte(9007199254740991), pageSize: z.number().int().gte(-9007199254740991).lte(9007199254740991), totalCount: z.number().int().gte(-9007199254740991).lte(9007199254740991), totalPages: z.number().int().gte(-9007199254740991).lte(9007199254740991)})}); 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 }; /** * Lista as mensagens SMS recebidas por um número virtual, ordenadas por data de recebimento decrescente (`receivedAt`), com paginação. Útil para reprocessar notificações de webhook perdidas. * * GET /api/v2/virtual-phone-accounts/{id}/sms-messages */ export const getApiApiV2VirtualPhoneAccountsIdSmsMessages = async (args: GetApiApiV2VirtualPhoneAccountsIdSmsMessagesArgs, options?: GetApiApiV2VirtualPhoneAccountsIdSmsMessagesOptions) => { const {baseUrl = "https://api.salvy.com.br", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.receivedAtFrom != null) query.append("receivedAtFrom", String(args.receivedAtFrom)) if (args.receivedAtTo != null) query.append("receivedAtTo", String(args.receivedAtTo)) for (const item of args.service ?? []) query.append("service", String(item)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/virtual-phone-accounts/${encodeURIComponent(String(args.id))}/sms-messages${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(getApiApiV2VirtualPhoneAccountsIdSmsMessagesResponse, await res.json()) };