import {z} from 'zod' export type GetApiApiV1PublishingBundleIdArgs = {bundleId: string}; export type GetApiApiV1PublishingBundleIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const errorEntity = z.object({errorCode: z.string().optional(), message: z.string().optional(), fieldName: z.string().optional()}); export const endpointDetailView = z.object({id: z.string(), serverName: z.string(), address: z.string(), port: z.string(), protocol: z.string(), status: z.enum(["BUNDLE_REQUESTED", "BUNDLING", "SENDING_TO_ENDPOINTS", "FAILED_TO_SEND_TO_ALL_GROUPS", "FAILED_TO_SEND_TO_SOME_GROUPS", "FAILED_TO_BUNDLE", "FAILED_TO_SENT", "FAILED_TO_PUBLISH", "SUCCESS", "BUNDLE_SENT_SUCCESSFULLY", "RECEIVED_BUNDLE", "PUBLISHING_BUNDLE", "WAITING_FOR_PUBLISHING", "BUNDLE_SAVED_SUCCESSFULLY", "INVALID_TOKEN", "LICENSE_REQUIRED", "SUCCESS_WITH_WARNINGS", "FAILED_INTEGRITY_CHECK", "SCHEDULED"]).optional(), statusMessage: z.string().optional(), stackTrace: z.string().optional()}); export const environmentDetailView = z.object({id: z.string(), name: z.string(), endpoints: z.array(endpointDetailView)}); export const timestampsView = z.object({bundleStart: z.string().optional(), bundleEnd: z.string().optional(), publishStart: z.string().optional(), publishEnd: z.string().optional(), createDate: z.string(), statusUpdated: z.string().optional()}); export const publishingJobDetailView = z.object({bundleId: z.string(), bundleName: z.string().optional(), status: z.enum(["BUNDLE_REQUESTED", "BUNDLING", "SENDING_TO_ENDPOINTS", "FAILED_TO_SEND_TO_ALL_GROUPS", "FAILED_TO_SEND_TO_SOME_GROUPS", "FAILED_TO_BUNDLE", "FAILED_TO_SENT", "FAILED_TO_PUBLISH", "SUCCESS", "BUNDLE_SENT_SUCCESSFULLY", "RECEIVED_BUNDLE", "PUBLISHING_BUNDLE", "WAITING_FOR_PUBLISHING", "BUNDLE_SAVED_SUCCESSFULLY", "INVALID_TOKEN", "LICENSE_REQUIRED", "SUCCESS_WITH_WARNINGS", "FAILED_INTEGRITY_CHECK", "SCHEDULED"]), filterName: z.string().optional(), filterKey: z.string().optional(), assetCount: z.number().int(), environments: z.array(environmentDetailView), timestamps: timestampsView, numTries: z.number().int(), scheduledPublishDate: z.string().optional()}); export const messageEntity = z.object({message: z.string().optional()}); export const pagination = z.object({currentPage: z.number().int().optional(), perPage: z.number().int().optional(), totalEntries: z.number().int().optional()}); export const responseEntityPublishingJobDetailView = z.object({errors: z.array(errorEntity).optional(), entity: publishingJobDetailView.optional(), messages: z.array(messageEntity).optional(), i18nMessagesMap: z.record(z.string(), z.string()).optional(), permissions: z.array(z.string()).optional(), pagination: pagination.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 }; /** * Get publishing job details * * GET /api/v1/publishing/{bundleId} */ export const getApiApiV1PublishingBundleId = async (args: GetApiApiV1PublishingBundleIdArgs, options: GetApiApiV1PublishingBundleIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/publishing/${encodeURIComponent(String(args.bundleId))}${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(responseEntityPublishingJobDetailView, await res.json()) };