import {z} from 'zod' export type GetApiApiCompaniesResellerIdArgs = {id: number}; export type GetApiApiCompaniesResellerIdOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiCompaniesResellerIdResponse = z.object({data: z.object({id: z.number().int().optional(), name: z.string().optional(), email: z.string().optional(), phone: z.string().optional(), cnpj: z.string().optional(), address: z.string().optional(), payment_end: z.string().optional(), access: z.object({token: z.string().optional()}).optional(), can_login: z.number().int().optional(), limits: z.array(z.object({id: z.number().int().optional(), companie: z.number().int().optional(), type: z.string().optional(), new_limit: z.number().int().optional()})).optional(), mail_host: z.string().optional(), mail_from: z.string().optional(), mail_username: z.string().optional(), mail_encryption: z.string().optional(), mail_port: z.number().int().optional(), unlimited: z.number().int().optional(), company_name: z.string().optional(), editablevalidate: z.number().int().optional(), signer_month: z.number().int().optional(), webhook_header_name: z.string().optional(), webhook_header_value: z.string().optional(), reseller_login: 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 Single company * * GET /api/companies/reseller/{id} */ export const getApiApiCompaniesResellerId = async (args: GetApiApiCompaniesResellerIdArgs, options?: GetApiApiCompaniesResellerIdOptions) => { const {baseUrl = "https://app.plugsign.com.br", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (sec0 !== undefined) headers.set("Authorization", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/api/companies/reseller/${encodeURIComponent(String(args.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(getApiApiCompaniesResellerIdResponse, await res.json()) };