import {z} from 'zod' export type GetApiProfileBusinessMeOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiProfileBusinessMeResponse = z.object({success: z.boolean().optional(), message: z.string().optional(), data: z.object({settings: z.object({feeBearer: z.string().optional(), settlementDestination: z.string().optional(), enableWebhook: z.boolean().optional(), callbackURL: z.string().optional()}).optional(), emailSettings: z.object({collectionNotification: z.boolean().optional(), topupNotification: z.boolean().optional(), settlementNotification: z.boolean().optional(), paymentReceiptNotification: z.boolean().optional()}).optional(), checkoutSettings: z.object({useBrandLogo: z.boolean().optional(), buttonTextColor: z.unknown(), buttonColor: z.unknown(), fontColor: z.unknown(), fontFamily: z.unknown(), backgroundColor: z.unknown(), backgroundTextColor: z.unknown()}).optional(), status: z.string().optional(), countryCallingCode: z.string().optional(), businessTag: z.number().int().optional(), settlementSettings: z.unknown(), isKYCApproved: z.boolean().optional(), isBlocked: z.boolean().optional(), _id: z.string().optional(), name: z.string().optional(), businessType: z.string().optional(), website: z.string().optional(), email: z.string().optional(), country: z.string().optional(), mobile: z.string().optional(), businessKey: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().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 Business Information * * GET /profile/business/me */ export const getApiProfileBusinessMe = async (options?: GetApiProfileBusinessMeOptions) => { const {baseUrl = "https://sandboxapi.fincra.com", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (sec0 !== undefined) headers.set("api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/profile/business/me${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(getApiProfileBusinessMeResponse, await res.json()) };