import {z} from 'zod' export type ACHAccountRequest = {companyId?: string | undefined, shopId?: string | undefined, storeId?: string | undefined, environment?: ('Development' | 'Production' | 'UAT' | 'Beta') | undefined, active?: boolean | undefined, resetAch?: boolean | undefined, key?: string | undefined, paymentOption?: ('Cash' | 'Credit' | 'Check' | 'Hypur' | 'Split' | 'StoreCredit' | 'Linx' | 'CashlessATM' | 'Mtrac' | 'None' | 'Clover' | 'BlazePay' | 'ACH' | 'GiftCard' | 'LoyaltyPoints' | 'Spence' | 'Stronghold' | 'PlasticPay') | undefined, tipping?: boolean | undefined, capturing?: boolean | undefined, ignorePartnerPayLink?: boolean | undefined}; export type UpdateApiApiV1MgmtAchShopachaccountShopACHAccountIdArgs = {shopACHAccountId: string, body: ACHAccountRequest}; export type UpdateApiApiV1MgmtAchShopachaccountShopACHAccountIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const aCHAccount = z.object({id: z.string().optional(), created: z.number().int().optional(), modified: z.number().int().optional(), deleted: z.boolean().optional(), updated: z.boolean().optional(), companyId: z.string().optional(), shopId: z.string().optional(), dirty: z.boolean().optional(), storeId: z.string().optional(), key: z.string().optional(), active: z.boolean().optional(), paymentOption: z.enum(["Cash", "Credit", "Check", "Hypur", "Split", "StoreCredit", "Linx", "CashlessATM", "Mtrac", "None", "Clover", "BlazePay", "ACH", "GiftCard", "LoyaltyPoints", "Spence", "Stronghold", "PlasticPay"]).optional(), environment: z.enum(["Development", "Production", "UAT", "Beta"]).optional(), tipping: z.boolean().optional(), capturing: z.boolean().optional(), ignorePartnerPayLink: z.boolean().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 }; /** * Update Shop ACH Account * * PUT /api/v1/mgmt/ach/shopachaccount/{shopACHAccountId} */ export const updateApiApiV1MgmtAchShopachaccountShopACHAccountId = async (args: UpdateApiApiV1MgmtAchShopachaccountShopACHAccountIdArgs, options?: UpdateApiApiV1MgmtAchShopachaccountShopACHAccountIdOptions) => { const {baseUrl = "http://api.partners.blaze.me", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/mgmt/ach/shopachaccount/${encodeURIComponent(String(args.shopACHAccountId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(aCHAccount, await res.json()) };