import {z} from 'zod' export type GetApiAdminIrPagesSymbolVersionsVersionIdArgs = {symbol: string, versionId: number}; export type GetApiAdminIrPagesSymbolVersionsVersionIdOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const fireAntApiModelsIRIRPageVersionItem = z.object({versionId: z.number().int().optional(), versionNo: z.number().int().optional(), revision: z.number().int().optional(), schemaVersion: z.number().int().optional(), status: z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6)]).optional(), sizeBytes: z.number().int().optional(), contentHash: z.string().optional(), note: z.string().optional(), reviewReasons: z.object({}).optional(), createdBy: z.string().optional(), createdDate: z.string().optional(), modifiedBy: z.string().optional(), modifiedDate: z.string().optional(), submittedBy: z.string().optional(), submittedDate: z.string().optional(), reviewedBy: z.string().optional(), reviewedDate: z.string().optional(), reviewNote: z.string().optional(), scheduledDate: z.string().optional(), publishedBy: z.string().optional(), publishedDate: z.string().optional(), content: z.object({}).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 }; /** * Một phiên bản kèm nội dung * * GET /admin/ir/pages/{symbol}/versions/{versionId} */ export const getApiAdminIrPagesSymbolVersionsVersionId = async (args: GetApiAdminIrPagesSymbolVersionsVersionIdArgs, options?: GetApiAdminIrPagesSymbolVersionsVersionIdOptions) => { const {baseUrl = "https://api.fireant.vn", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/admin/ir/pages/${encodeURIComponent(String(args.symbol))}/versions/${encodeURIComponent(String(args.versionId))}${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(fireAntApiModelsIRIRPageVersionItem, await res.json()) };