import {z} from 'zod' export type GetChangeLogsByUserIdRequest = {limit?: number | undefined, continuationToken?: string | undefined}; export type CreateApiChangelogsV1UsersUserIdArgs = {userId: string, body: GetChangeLogsByUserIdRequest}; export type CreateApiChangelogsV1UsersUserIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const changeLogEvent = z.enum(["Added", "Deleted", "Enabled", "Disabled", "Edited", "Created", "Triggered", "Configured", "Refreshed", "Changed"]); export const changeLogDomain = z.enum(["StoreLifecycle", "ChannelLifecycle", "CategoryMapping", "ColumnsMapping", "CategoryMappingExportDump", "ColumnsMappingExportDump", "ApiSettings", "ProductExclusion", "ExclusionFilter", "AutoAccept", "OrderHarvestGlobal", "OrderHarvestOrder", "ChannelConvLifecycle", "ManualPublication", "CustomColumns"]); export const changeLogDto = z.object({changeLogEvent: changeLogEvent.optional(), changeLogDomain: changeLogDomain.optional(), userId: z.string().optional(), channelCatalogId: z.string().optional(), storeId: z.string().optional(), correlationId: z.string().optional(), context: z.record(z.string(), z.unknown()).optional(), createdUtcDate: z.string().optional()}); export const getChangeLogsByUserIdResponse = z.object({userId: z.string().optional(), changeLogs: z.array(changeLogDto).optional(), continuationToken: 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 }; /** * GetAllChangeLogsByUserId * * POST /changelogs/v1/users/{userId} */ export const createApiChangelogsV1UsersUserId = async (args: CreateApiChangelogsV1UsersUserIdArgs, options?: CreateApiChangelogsV1UsersUserIdOptions) => { const {baseUrl = "https://api.beezup.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(/\/+$/, '')}/changelogs/v1/users/${encodeURIComponent(String(args.userId))}${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(getChangeLogsByUserIdResponse, await res.json()) };