import {z} from 'zod' export type GetApiMerchantsMerchantIdStoresStoreIdArgs = {merchantId: string, storeId: string}; export type GetApiMerchantsMerchantIdStoresStoreIdOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const linksElement = z.object({href: z.string().optional()}); export const links = z.object({self: linksElement}); export const storeLocation = z.object({city: z.string().optional(), country: z.string(), line1: z.string().optional(), line2: z.string().optional(), line3: z.string().optional(), postalCode: z.string().optional(), stateOrProvince: z.string().optional()}); export const localShopperStatement = z.object({script: z.string(), value: z.string()}); export const localStoreName = z.object({script: z.string(), value: z.string()}); export const japaneseLocalizedAddressFields = z.object({building: z.string().optional(), city: z.string(), district: z.string().optional(), line1: z.string(), postalCode: z.string().optional(), prefecture: z.string()}); export const japaneseLocalizedAddress = z.object({fields: japaneseLocalizedAddressFields, script: z.enum(["ja-Kana", "ja-Hani"])}); export const localizedInformation = z.object({localShopperStatement: z.array(localShopperStatement), localStoreName: z.array(localStoreName).optional(), localizedAddress: z.array(japaneseLocalizedAddress).optional()}); export const storeSplitConfiguration = z.object({balanceAccountId: z.string().optional(), splitConfigurationId: z.string().optional()}); export const store = z.object({_links: links.optional(), address: storeLocation.optional(), businessLineIds: z.array(z.string()).optional(), description: z.string().optional(), externalReferenceId: z.string().optional(), id: z.string().optional(), localizedInformation: localizedInformation.optional(), merchantId: z.string().optional(), phoneNumber: z.string().optional(), reference: z.string().optional(), shopperStatement: z.string().optional(), splitConfiguration: storeSplitConfiguration.optional(), status: z.enum(["active", "closed", "inactive"]).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 }; /** * Get a store * * GET /merchants/{merchantId}/stores/{storeId} * * Also accepts auth: ApiKeyAuth */ export const getApiMerchantsMerchantIdStoresStoreId = async (args: GetApiMerchantsMerchantIdStoresStoreIdArgs, options?: GetApiMerchantsMerchantIdStoresStoreIdOptions) => { const {baseUrl = "https://management-test.adyen.com/v1", fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/merchants/${encodeURIComponent(String(args.merchantId))}/stores/${encodeURIComponent(String(args.storeId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) 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()) };