import {z} from 'zod' export type AddressDetailDto = {line1?: string | undefined, line2?: string | undefined, city?: string | undefined, state?: string | undefined, postalCode?: string | undefined, country?: string | undefined}; export type CryptoCurrency = 'usdc' | 'usdt' | 'pyusd' | 'eurc' | 'brett' | 'dai' | 'btc' | 'eth' | 'matic' | 'bnb' | 'sol' | 'busd' | 'trx' | 'food' | 'bonk' | 'wif' | 'goat' | 'spx' | 'truf' | 'pengu'; export type UpdatePaymentSettingDto = {preferredChainId?: number | undefined, preferredCurrency?: CryptoCurrency | undefined, allowSwap?: boolean | undefined, applyFee?: boolean | undefined, applyGasFee?: boolean | undefined, allowSplitPayments?: boolean | undefined, slippagePercentage?: number | undefined}; export type CreateWithdrawalAddressDto = {name: string, address: string, chainId: number}; export type WebhookEvents = '*' | 'withdrawal_address.created' | 'withdrawal_address.updated' | 'withdrawal_address.deleted' | 'checkout_session.completed' | 'checkout_session.expired' | 'checkout_session.canceled' | 'customer.subscription.created' | 'customer.subscription.started' | 'customer.subscription.deleted' | 'customer.subscription.past_due' | 'customer.subscription.unpaid' | 'customer.subscription.incomplete_expired' | 'payment_intent.payment_failed' | 'payment_intent.canceled' | 'payment_intent.succeeded' | 'invoice.finalized' | 'invoice.paid' | 'invoice.marked_as_paid' | 'invoice.marked_uncollectible' | 'invoice.payment_failed'; export type WebhookEventsDto = {events: Array}; export type CreateWebhookEndpointDto = {description: string, url: string, enabledEvents: WebhookEventsDto}; export type AccountOnboardDto = {email: string, name: string, website?: string | undefined, phone?: string | undefined, brandColor?: string | undefined, addressDetails?: AddressDetailDto | undefined, paymentSetting?: UpdatePaymentSettingDto | undefined, withdrawalAddresses?: Array | undefined, webhookEndpoints?: Array | undefined}; export type CreateApiApiV1PartnersAccountsOnboardArgs = {body: AccountOnboardDto}; export type CreateApiApiV1PartnersAccountsOnboardOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const organizationStatus = z.enum(["pending", "active", "suspended"]); export const organizationKind = z.enum(["individual", "business"]); export const withdrawalAddressMinimalDto = z.object({id: z.string(), name: z.string(), address: z.string(), chainId: z.number(), isDefault: z.boolean()}); export const addressDetailDto = z.object({line1: z.string().optional(), line2: z.string().optional(), city: z.string().optional(), state: z.string().optional(), postalCode: z.string().optional(), country: z.string().optional()}); export const organizationDto = z.object({id: z.string(), createdAt: z.string().optional(), updatedAt: z.string().optional(), name: z.string(), type: z.string(), status: organizationStatus, kind: organizationKind, ownerId: z.string(), noOfEmployees: z.string(), monthlyPaymentVolume: z.string(), addresses: z.array(withdrawalAddressMinimalDto), email: z.string().optional(), supportEmail: z.string().optional(), phone: z.string().optional(), addressDetails: addressDetailDto.optional(), brandLogo: z.string(), brandColor: z.string(), supportUrl: z.string().optional(), termsUrl: z.string().optional(), privacyUrl: z.string().optional(), websiteUrl: z.string().optional(), featureAccessRequests: z.array(z.string()), companyIdentificationNumber: z.string().optional(), taxIdentificationNumber: z.string().optional(), referralCode: z.string().optional(), referrerId: z.string().optional()}); export const userStatus = z.enum(["pending", "active", "suspended"]); export const userFlagsDto = z.object({introModal: z.boolean().optional()}); export const userDto = z.object({id: z.string(), firstName: z.string(), lastName: z.string(), email: z.string().optional(), role: z.string(), profilePicture: z.string().optional(), phone: z.string().optional(), position: z.string().optional(), status: userStatus, createdAt: z.string().optional(), updatedAt: z.string().optional(), flags: userFlagsDto.optional()}); export const paymentMethodType = z.enum(["superfluid", "wallet", "allowance_based_recurring", "stripe", "binance_pay"]); export const cryptoCurrency = z.enum(["usdc", "usdt", "pyusd", "eurc", "brett", "dai", "btc", "eth", "matic", "bnb", "sol", "busd", "trx", "food", "bonk", "wif", "goat", "spx", "truf", "pengu"]); export const checkoutSessionSplitWithdrawalAddressDto = z.object({splitPercentage: z.number().gte(0).lte(100), address: z.string()}); export const paymentSettingChainDto = z.object({chainId: z.number(), blacklistCurrencies: z.array(cryptoCurrency).optional(), withdrawalAddress: z.string().optional(), withdrawalAddresses: z.array(checkoutSessionSplitWithdrawalAddressDto).optional()}); export const paymentSettingDto = z.object({id: z.string(), createdAt: z.string().optional(), updatedAt: z.string().optional(), paymentMethodTypes: z.array(paymentMethodType).optional(), allowedChains: z.array(paymentSettingChainDto).optional(), allowedCurrencies: z.array(cryptoCurrency).optional(), preferredChainId: z.number().optional(), preferredCurrency: cryptoCurrency.optional(), allowSwap: z.boolean().optional(), applyFee: z.boolean().optional(), feePercentage: z.number().gte(0).lte(100), applyGasFee: z.boolean().optional(), allowSplitPayments: z.boolean().optional(), slippagePercentage: z.number().gte(0).lte(100).optional()}); export const withdrawalAddressDto = z.object({id: z.string(), name: z.string(), address: z.string(), chainId: z.number(), isDefault: z.boolean(), createdAt: z.string(), updatedAt: z.string()}); export const personalAccessTokenWithPlainTokenDto = z.object({id: z.string(), name: z.string(), tokenIdentifier: z.string(), organizationId: z.string(), userId: z.string(), createdAt: z.string(), updatedAt: z.string(), token: z.string()}); export const accountOnboardResponseDto = z.object({organization: organizationDto, user: userDto, paymentSetting: paymentSettingDto, webhookEndpoints: z.array(addressDetailDto), withdrawalAddresses: z.array(withdrawalAddressDto), personalAccessToken: personalAccessTokenWithPlainTokenDto}); 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 }; /** * Create an account for a partner * * POST /api/v1/partners/accounts/onboard */ export const createApiApiV1PartnersAccountsOnboard = async (args: CreateApiApiV1PartnersAccountsOnboardArgs, options?: CreateApiApiV1PartnersAccountsOnboardOptions) => { const {baseUrl = "https://api.copperx.dev", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/partners/accounts/onboard${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(accountOnboardResponseDto, await res.json()) };