import {z} from 'zod' export type StoreLocationDefaultCapacityInputSerializer = {storeLocationId: string, defaultCapacity: {[key: string]: unknown}}; export type CreateApiV1SetStoreLocationDefaultCapacityArgs = {body: StoreLocationDefaultCapacityInputSerializer}; export type CreateApiV1SetStoreLocationDefaultCapacityOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const storeLocationAddressResponse = z.object({number: z.string().nullable().optional(), secondaryNumber: z.string().nullable().optional(), street: z.string(), county: z.string().nullable().optional(), city: z.string(), state: z.string().nullable().optional(), postalCode: z.string().nullable().optional(), country: z.string(), latitude: z.number().nullable().optional(), longitude: z.number().nullable().optional(), timezoneId: z.string().nullable().optional()}); export const storeLocationResponse = z.object({externalId: z.string().nullable().optional(), operatingHours: z.record(z.string(), z.unknown()).nullable().optional(), prepTimeMinutes: z.number().int().nullable().optional(), blackoutDates: z.array(z.string()).nullable().optional(), firstName: z.string().nullable().optional(), lastName: z.string().nullable().optional(), email: z.string().nullable().optional(), pickupInstructions: z.string().nullable().optional(), id: z.string(), name: z.string(), phoneNumber: z.string(), location: storeLocationAddressResponse, zoneIds: z.array(z.string()).nullable(), zoneAssociations: z.array(z.record(z.string(), z.unknown())).nullable(), tags: z.array(z.string()).nullable(), integrationMetadata: z.record(z.string(), z.unknown()).nullable()}); 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 }; /** * Set the weekly default capacity for a store location * * POST /v1/set_store_location_default_capacity */ export const createApiV1SetStoreLocationDefaultCapacity = async (args: CreateApiV1SetStoreLocationDefaultCapacityArgs, options?: CreateApiV1SetStoreLocationDefaultCapacityOptions) => { const {baseUrl = "https://api.sandbox.usenash.com", 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(/\/+$/, '')}/v1/set_store_location_default_capacity${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(storeLocationResponse, await res.json()) };