import {z} from 'zod' export type EntityTypeEnum = 'unset' | 'c_corp' | 'p_corp' | 'llc' | 'llp' | 'lp' | 'gp'; export type TaxClassEnum = 'unset' | 'corp' | 's_corp' | 'partnership' | 'disregarded' | 'tax_exempt'; export type LLCManagedTypeEnum = 'member_managed' | 'manager_managed'; export type AccountingMethod = 'accrual' | 'cash'; export type AccountingPeriod = 'fiscal' | 'calendar'; export type AccountingYearEndMonthNumber = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12; export type AppApiPlatformAuthHostedSignupRequestBusinessInformation = {incorporation_region?: (string | null) | undefined, entity_type?: (EntityTypeEnum | null) | undefined, tax_classification?: (TaxClassEnum | null) | undefined, llc_managed_type?: (LLCManagedTypeEnum | null) | undefined, business_name?: (string | null) | undefined, business_purpose?: (string | null) | undefined, ein?: (string | null) | undefined, incorporation_date?: (string | null) | undefined, naics_code?: (string | null) | undefined, accounting_method?: (AccountingMethod | null) | undefined, accounting_period?: (AccountingPeriod | null) | undefined, accounting_year_end?: (AccountingYearEndMonthNumber | null) | undefined, futa_liability_year?: (string | null) | undefined}; export type AppApiPlatformAuthHostedSignupRequest = {business_name: string, user_email: string, callback_url: string, legal_entity_id?: (string | null) | undefined, business_information?: (AppApiPlatformAuthHostedSignupRequestBusinessInformation | null) | undefined, external_company_id?: (string | null) | undefined}; export type CreateApiAccountsSignupSessionsArgs = {verbose?: boolean | undefined, authorization?: (string | null) | undefined, body: AppApiPlatformAuthHostedSignupRequest}; export type CreateApiAccountsSignupSessionsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const appApiPlatformAuthHostedSignupResponse = z.object({signup_url: z.string(), url: z.string(), created_at: z.string(), expires_at: z.string(), legal_entity_id: z.string()}); 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 Hosted Signup Session * * POST /accounts/signup/sessions */ export const createApiAccountsSignupSessions = async (args: CreateApiAccountsSignupSessionsArgs, options: CreateApiAccountsSignupSessionsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.verbose != null) query.append("verbose", String(args.verbose)) if (args.authorization != null) headers.set("authorization", String(args.authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/signup/sessions${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(appApiPlatformAuthHostedSignupResponse, await res.json()) };