import {z} from 'zod' export type GetApiV2UserCatalogsStoreIdReplicationLogsArgs = {storeId: unknown, executionId?: unknown | undefined, minReplicationUtcDate?: string | undefined, maxReplicationUtcDate?: string | undefined}; export type GetApiV2UserCatalogsStoreIdReplicationLogsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const executionId = z.string(); export const beezUPCommonStoreId = z.string(); export const processingStatus = z.enum(["None", "InProgress", "Done", "Failed", "Aborted"]); export const catalogReplicationLogCounters = z.object({totalCreatedCount: z.number().int().optional(), totalUpdatedCount: z.number().int().optional(), totalDeletedCount: z.number().int().optional(), totalIgnoredCount: z.number().int().optional(), totalErrorCount: z.number().int().optional()}); export const replicationStrategy = z.enum(["None", "Standard", "AddOnly", "PurgeAndReplace"]); export const catalogReplicationLogItem = z.object({actionType: z.string(), count: z.number().int(), entities: z.array(z.string()).optional()}); export const catalogReplicationErrorLogItem = z.object({item: catalogReplicationLogItem, errorType: z.string(), errorMessage: z.string()}); export const catalogReplicationLogItems = z.object({customColumnStrategy: replicationStrategy.optional(), createdItems: z.array(catalogReplicationLogItem).optional(), updatedItems: z.array(catalogReplicationLogItem).optional(), deleteItems: z.array(catalogReplicationLogItem).optional(), ignoreItems: z.array(catalogReplicationLogItem).optional(), errorItems: z.array(catalogReplicationErrorLogItem).optional()}); export const catalogReplicationLog = z.object({executionId: executionId, fromStoreId: beezUPCommonStoreId, status: processingStatus, sourceUpdateUtcDate: z.string(), targetUpdateUtcDate: z.string().optional(), totalCounters: catalogReplicationLogCounters.optional(), logs: z.record(z.string(), catalogReplicationLogItems).optional()}); export const getApiV2UserCatalogsStoreIdReplicationLogsResponse = z.array(catalogReplicationLog); 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 }; /** * [PREVIEW] [Mocked] Get Replication Logs - Can be filtered by ExecutionId * * GET /v2/user/catalogs/{storeId}/replication/logs */ export const getApiV2UserCatalogsStoreIdReplicationLogs = async (args: GetApiV2UserCatalogsStoreIdReplicationLogsArgs, options?: GetApiV2UserCatalogsStoreIdReplicationLogsOptions) => { const {baseUrl = "https://api.beezup.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.executionId != null) query.append("executionId", String(args.executionId)) if (args.minReplicationUtcDate != null) query.append("minReplicationUtcDate", String(args.minReplicationUtcDate)) if (args.maxReplicationUtcDate != null) query.append("maxReplicationUtcDate", String(args.maxReplicationUtcDate)) const url = `${baseUrl.replace(/\/+$/, '')}/v2/user/catalogs/${encodeURIComponent(String(args.storeId))}/replication/logs${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(getApiV2UserCatalogsStoreIdReplicationLogsResponse, await res.json()) };