import {z} from 'zod' export type Shift = {start_time?: string | undefined, end_time?: string | undefined}; export type OperationalHour = {shifts?: Array | undefined, active?: boolean | undefined, day_of_week?: number | undefined}; export type CreateFullCatalogCategory = {id: string, deleted?: boolean | undefined, name: string, name_localized?: Record | undefined, description?: string | undefined, description_localized?: Record | undefined, preparation_time?: number | undefined, priority?: number | undefined, media?: string | undefined, operational_hours?: Array | undefined, sub_categories?: Array | undefined, items?: Array | undefined}; export type CreateFullCatalogSubCategory = {id: string, deleted?: boolean | undefined, name: string, name_localized?: Record | undefined, description?: string | undefined, description_localized?: Record | undefined, preparation_time?: number | undefined, media?: string | undefined, priority?: number | undefined, operational_hours?: Array | undefined, items?: Array | undefined}; export type CreateFullCatalogItem = {id: string, deleted?: boolean | undefined, name: string, name_localized?: Record | undefined, description?: string | undefined, description_localized?: Record | undefined, active: boolean, price: number, calorie_counts?: string | undefined, allergic_information?: string | undefined, operational_hours?: Array | undefined, media?: string | undefined, priority?: number | undefined, tags?: Array<'careem-mealson'> | undefined, groups?: Array | undefined}; export type CreateFullCatalogGroup = {id: string, deleted?: boolean | undefined, name: string, name_localized?: Record | undefined, description?: string | undefined, description_localized?: Record | undefined, multi_select?: boolean | undefined, min?: number | undefined, max?: number | undefined, priority?: number | undefined, options?: Array | undefined}; export type CreateFullCatalogOption = {id: string, deleted?: boolean | undefined, name: string, name_localized?: Record | undefined, active?: boolean | undefined, price?: number | undefined, priority?: number | undefined, groups?: Array | undefined}; export type ItemCategory = {item_id: string, category_id: string, deleted?: boolean | undefined}; export type CreateFullCatalogRequest = {diff?: boolean | undefined, catalog: {id: string, name: string, include_tax?: boolean | undefined, tax?: number | undefined, avg_price?: number | undefined, file?: string | undefined, currency_id: number, category_ids?: Array | undefined}, categories?: Array | undefined, sub_categories?: Array | undefined, items?: Array | undefined, groups?: Array | undefined, options?: Array | undefined, item_categories?: Array | undefined}; export type UpdateFullCatalogCategory = {id: string, deleted?: boolean | undefined, name?: string | undefined, name_localized?: Record | undefined, description?: string | undefined, description_localized?: Record | undefined, preparation_time?: number | undefined, priority?: number | undefined, operational_hours?: Array | undefined, sub_categories?: Array | undefined, items?: Array | undefined}; export type UpdateFullCatalogSubCategory = {id: string, deleted?: boolean | undefined, name?: string | undefined, name_localized?: Record | undefined, description?: string | undefined, description_localized?: Record | undefined, preparation_time?: number | undefined, priority?: number | undefined, operational_hours?: Array | undefined, items?: Array | undefined}; export type UpdateFullCatalogItem = {id: string, deleted?: boolean | undefined, name?: string | undefined, name_localized?: Record | undefined, description?: string | undefined, description_localized?: Record | undefined, active: boolean, price?: number | undefined, calorie_counts?: string | undefined, allergic_information?: string | undefined, operational_hours?: Array | undefined, media?: string | undefined, priority?: number | undefined, tags?: Array<'careem-mealson'> | undefined, groups?: Array | undefined}; export type UpdateFullCatalogGroup = {id: string, deleted?: boolean | undefined, name?: string | undefined, name_localized?: Record | undefined, description?: string | undefined, description_localized?: Record | undefined, multi_select?: boolean | undefined, min?: number | undefined, max?: number | undefined, priority?: number | undefined, options?: Array | undefined}; export type UpdateFullCatalogOption = {id: string, deleted?: boolean | undefined, name?: string | undefined, name_localized?: Record | undefined, active?: boolean | undefined, price?: number | undefined, priority?: number | undefined, groups?: Array | undefined}; export type UpdateFullCatalogRequest = {diff?: boolean | undefined, catalog: {id: string, name?: string | undefined, include_tax?: boolean | undefined, tax?: number | undefined, avg_price?: number | undefined, file?: string | undefined, category_ids?: Array | undefined}, categories?: Array | undefined, sub_categories?: Array | undefined, items?: Array | undefined, groups?: Array | undefined, options?: Array | undefined, item_categories?: Array | undefined}; export type UpdateApiCatalogsArgs = {Authorization: string, 'User-Agent': string, 'Brand-Id'?: string | undefined, 'Branch-Id': string, body: CreateFullCatalogRequest | UpdateFullCatalogRequest}; export type UpdateApiCatalogsOptions = {baseUrl?: string | undefined, CareemIDPClientCredentials?: string | undefined, fetch?: typeof fetch | undefined}; export const createFullCatalogStatusResponse = z.object({request_id: z.string().optional(), created_at: z.string().optional(), url: z.string().optional(), message: z.string().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 }; /** * Create/update full catalog * * PUT /catalogs */ export const updateApiCatalogs = async (args: UpdateApiCatalogsArgs, options?: UpdateApiCatalogsOptions) => { const {baseUrl = "https://apigateway.careemdash.com/pos/api/v1", fetch: fetchFn = fetch, CareemIDPClientCredentials} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args['User-Agent'] != null) headers.set("User-Agent", String(args['User-Agent'])) if (args['Brand-Id'] != null) headers.set("Brand-Id", String(args['Brand-Id'])) if (args['Branch-Id'] != null) headers.set("Branch-Id", String(args['Branch-Id'])) if (CareemIDPClientCredentials !== undefined) headers.set('authorization', `Bearer ${CareemIDPClientCredentials}`) const url = `${baseUrl.replace(/\/+$/, '')}/catalogs${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(createFullCatalogStatusResponse, await res.json()) };