import {z} from 'zod' export type PatchApi30EcommerceStoresStoreIdArgs = {store_id: string, body: {address?: ({address1?: string | undefined, address2?: string | undefined, city?: string | undefined, country?: string | undefined, country_code?: string | undefined, latitude?: (number | string) | undefined, longitude?: (number | string) | undefined, postal_code?: string | undefined, province?: string | undefined, province_code?: string | undefined}) | undefined, currency_code?: string | undefined, domain?: string | undefined, email_address?: string | undefined, is_syncing?: boolean | undefined, money_format?: string | undefined, name?: string | undefined, phone?: string | undefined, platform?: string | undefined, primary_locale?: string | undefined, timezone?: string | undefined}}; export type PatchApi30EcommerceStoresStoreIdOptions = {baseUrl?: string | undefined, bearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApi30EcommerceStoresStoreIdResponse = z.object({_links: z.array(z.object({href: z.string().optional(), method: z.enum(["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"]).optional(), rel: z.string().optional(), schema: z.string().optional(), targetSchema: z.string().optional()})).optional(), address: z.object({address1: z.string().optional(), address2: z.string().optional(), city: z.string().optional(), country: z.string().optional(), country_code: z.string().optional(), latitude: z.number().optional(), longitude: z.number().optional(), postal_code: z.string().optional(), province: z.string().optional(), province_code: z.string().optional()}).optional(), automations: z.object({abandoned_browse: z.object({id: z.string().optional(), is_supported: z.boolean().optional(), status: z.enum(["save", "sending", "paused"]).optional()}).optional(), abandoned_cart: z.object({id: z.string().optional(), is_supported: z.boolean().optional(), status: z.enum(["save", "sending", "paused"]).optional()}).optional()}).optional(), connected_site: z.object({site_foreign_id: z.string().optional(), site_script: z.object({fragment: z.string().optional(), url: z.string().optional()}).optional()}).optional(), created_at: z.string().optional(), currency_code: z.string().optional(), domain: z.string().optional(), email_address: z.string().optional(), id: z.string().optional(), is_syncing: z.boolean().optional(), list_id: z.string().optional(), list_is_active: z.boolean().optional(), money_format: z.string().optional(), name: z.string().optional(), phone: z.string().optional(), platform: z.string().optional(), primary_locale: z.string().optional(), timezone: z.string().optional(), updated_at: z.string().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 store * * PATCH /3.0/ecommerce/stores/{store_id} * * Also accepts auth: oauth2 */ export const patchApi30EcommerceStoresStoreId = async (args: PatchApi30EcommerceStoresStoreIdArgs, options?: PatchApi30EcommerceStoresStoreIdOptions) => { const {baseUrl = "https://api.mailchimp.com", fetch: fetchFn = fetch, bearerToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerToken !== undefined) headers.set('authorization', `Bearer ${bearerToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/3.0/ecommerce/stores/${encodeURIComponent(String(args.store_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApi30EcommerceStoresStoreIdResponse, await res.json()) };