export type StoreId = string; export type StorefrontTimeRange = {startTime?: string | undefined, endTime?: string | undefined}; export type StorefrontRegularHours = {dayOfWeek: 'MONDAY' | 'TUESDAY' | 'WEDNESDAY' | 'THURSDAY' | 'FRIDAY' | 'SATURDAY' | 'SUNDAY', timeRanges: Array}; export type StorefrontSpecialHours = {date: string, timeRanges: Array, specialHourType: 'OPEN' | 'CLOSED'}; export type StoreHours = {regularHours?: Array | undefined, specialHours?: (Array | null) | undefined} | null; export type StoreHoursConfiguration = {deliveryHours?: StoreHours | undefined, pickupHours?: StoreHours | undefined, timezone: string}; export type EventResultMetadata = {operationStatus?: ('SUCCEEDED' | 'INTERNAL_ERROR' | 'AUTHENTICATION_FAILURE' | 'AUTHORIZATION_FAILURE' | 'UNKNOWN_FAILURE' | 'INVALID_STORE_STATE' | 'INVALID_STORE_CONFIGURATION' | 'OPERATION_NOT_SUPPORTED' | 'IGNORED_ALREADY_IN_REQUESTED_STATE' | 'INVALID_REQUEST') | undefined, additionalInformation?: (string | null) | undefined, operationFinishedAt?: string | undefined} | null; export type StoreHoursConfigurationEventResult = {storeHoursConfiguration?: StoreHoursConfiguration | undefined, statusChangedAt?: string | undefined, eventResultMetadata?: EventResultMetadata | undefined}; export type CreateApiV1StorefrontHoursArgs = {'X-Store-Id': StoreId, 'X-Event-Id'?: string | undefined, body: StoreHoursConfigurationEventResult}; export type CreateApiV1StorefrontHoursOptions = {baseUrl?: string | undefined, OAuth20?: string | undefined, fetch?: typeof fetch | undefined}; /** * Notify about store hours configuration change * * POST /v1/storefront/hours */ export const createApiV1StorefrontHours = async (args: CreateApiV1StorefrontHoursArgs, options?: CreateApiV1StorefrontHoursOptions) => { const {baseUrl = "https://partners.tryotter.com", fetch: fetchFn = fetch, OAuth20} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['X-Store-Id'] != null) headers.set("X-Store-Id", String(args['X-Store-Id'])) if (args['X-Event-Id'] != null) headers.set("X-Event-Id", String(args['X-Event-Id'])) if (OAuth20 !== undefined) headers.set('authorization', `Bearer ${OAuth20}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/storefront/hours${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 undefined };