import {z} from 'zod' export type PayoutDestinationId = string; export type StoreUpdateInput = {organization: {organization_number: string, country?: string | undefined, type?: ('main_unit' | 'sub_unit') | undefined, name?: string | undefined, trade_name?: string | undefined}, store_name: string, email?: string | undefined, phone_number: unknown, address?: ({address_line: string, address_line_2?: string | undefined, postal_code: string, postal_place: string, country: unknown}) | undefined, coordinates?: {latitude: number, longitude: number} | undefined, website?: string | undefined, payout_destination?: {payout_destination_id: PayoutDestinationId} | undefined}; export type UpdateApiAccountsAidStoresStoreIdArgs = {aid: unknown, store_id: string, body: StoreUpdateInput}; export type UpdateApiAccountsAidStoresStoreIdOptions = {baseUrl?: string | undefined, JWT?: string | undefined, fetch?: typeof fetch | undefined}; export const address = z.object({address_line: z.string(), address_line_2: z.string().optional(), postal_code: z.string().optional(), postal_place: z.string(), country: z.string()}); export const store = z.object({id: z.string(), name: z.string().optional(), business_name: z.string().optional(), address: address.optional(), chain: z.string().optional(), email: z.string().optional(), gln: z.string().optional(), organization_number: z.string().optional(), phone_number: z.string().optional(), mcc: z.string().optional(), bax: z.string().optional(), terminal_id: z.string().optional(), payout_destination_id: z.string().max(40).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 }; /** * aid_account_management_stores_sid_put * * PUT /accounts/{aid}/stores/{store_id} */ export const updateApiAccountsAidStoresStoreId = async (args: UpdateApiAccountsAidStoresStoreIdArgs, options?: UpdateApiAccountsAidStoresStoreIdOptions) => { const {baseUrl = "https://api.dintero.com/v1", fetch: fetchFn = fetch, JWT} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (JWT !== undefined) headers.set('authorization', `Bearer ${JWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/${encodeURIComponent(String(args.aid))}/stores/${encodeURIComponent(String(args.store_id))}${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(store, await res.json()) };