import {z} from 'zod' export type ParsedAddressInputSerializer = {number?: (string | null) | undefined, secondaryNumber?: (string | null) | undefined, street: string, county?: (string | null) | undefined, city: string, state?: (string | null) | undefined, postalCode?: (string | null) | undefined, country: string, latitude?: (number | null) | undefined, longitude?: (number | null) | undefined}; export type CreateStoreLocationInputSerializer = {name: string, firstName?: (string | null) | undefined, lastName?: (string | null) | undefined, phoneNumber: string, email?: (string | null) | undefined, pickupInstructions?: (string | null) | undefined, address?: (string | null) | undefined, addressComponents?: (ParsedAddressInputSerializer | null) | undefined, externalId?: (string | null) | undefined, tags?: (Array | null) | undefined, operatingHours?: ({[key: string]: unknown} | null) | undefined, prepTimeMinutes?: (number | null) | undefined, zoneIds?: (Array | null) | undefined, zoneAssociations?: (Array<{[key: string]: unknown}> | null) | undefined}; export type CreateApiV1StoreLocationsExternalIdentifierExternalIdentifierArgs = {externalIdentifier: string, body: CreateStoreLocationInputSerializer}; export type CreateApiV1StoreLocationsExternalIdentifierExternalIdentifierOptions = {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 }; /** * Create or update store location by external identifier * * POST /v1/store_locations/external-identifier/{externalIdentifier} */ export const createApiV1StoreLocationsExternalIdentifierExternalIdentifier = async (args: CreateApiV1StoreLocationsExternalIdentifierExternalIdentifierArgs, options?: CreateApiV1StoreLocationsExternalIdentifierExternalIdentifierOptions) => { 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/store_locations/external-identifier/${encodeURIComponent(String(args.externalIdentifier))}${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()) };