import {z} from 'zod' export type GetApiOutletsIdArgs = {id: string}; export type GetApiOutletsIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const attribute = z.object({key: z.string(), value: z.string()}); export const outlet = z.object({attributes: z.array(attribute), currency: z.string(), currency_symbol: z.string(), default_tax_id: z.string(), deleted_at: z.string().nullable().optional(), display_prices: z.enum(["inclusive", "exclusive"]), email: z.string().nullable().optional(), id: z.string(), latitude: z.string().nullable().optional(), longitude: z.string().nullable().optional(), name: z.string(), phone: z.string().nullable().optional(), physical_address_1: z.string().nullable().optional(), physical_address_2: z.string().nullable().optional(), physical_city: z.string().nullable().optional(), physical_country_id: z.string().nullable().optional(), physical_postcode: z.string().nullable().optional(), physical_state: z.string().nullable().optional(), physical_suburb: z.string().nullable().optional(), time_zone: z.string().nullable(), version: z.number().int()}); export const outletResponse = z.object({data: outlet.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 single outlet * * GET /outlets/{id} */ export const getApiOutletsId = async (args: GetApiOutletsIdArgs, options?: GetApiOutletsIdOptions) => { const {baseUrl = "https://example.retail.lightspeed.app/api/2026-10", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/outlets/${encodeURIComponent(String(args.id))}${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(outletResponse, await res.json()) };