import {z} from 'zod' export type CreateApiDatamartUpdatefcTypeCodeArgs = {body: {operationType?: string | undefined, data?: ({version?: number | undefined, typedId: string, uniqueName: string, label?: string | undefined, sourceFile: unknown, fields: Array<{name?: string | undefined, label?: string | undefined, labelTranslations?: Record | undefined, rank?: number | undefined, format: unknown, measureType: unknown, functionalType: unknown, visibility?: number | undefined, defaultValue: unknown, sourceField: unknown, expression?: string | undefined, function: unknown, formulaElement: unknown, messages: unknown, key?: boolean | undefined, system?: boolean | undefined, numeric?: boolean | undefined, deleted?: boolean | undefined, persisted?: boolean | undefined, dimension?: boolean | undefined, calculated?: boolean | undefined, dbColumn?: string | undefined, aggregation?: boolean | undefined, time?: boolean | undefined, partitioningKey?: boolean | undefined, queryable?: boolean | undefined, auxiliary?: boolean | undefined, deployed?: boolean | undefined, dbTable?: string | undefined, type?: string | undefined, source?: string | undefined, owningFC?: string | undefined, hidden?: boolean | undefined}>, keyFields?: Array | undefined, formulaName: unknown, reload?: boolean | undefined, messages: unknown, reservedWords: unknown, rowCount: unknown, lastUpdateByName?: string | undefined, defaultDataSourceName?: string | undefined, lineSeperator: unknown, fieldSeperator: unknown, quoteChar: unknown, fetchVerb?: string | undefined, integrateVerb: unknown, bulkloadVerb?: string | undefined, identikitCriteria: unknown, draft?: boolean | undefined, queryable?: boolean | undefined, view?: boolean | undefined, sourceName?: string | undefined, type?: string | undefined, valid?: boolean | undefined, status: unknown, targetDate: unknown, calculationMessages: unknown, loadableFields?: Array | undefined, auxiliary?: boolean | undefined, deployed?: boolean | undefined, dbTable?: string | undefined, dbKey?: string | undefined, dbView: unknown, locked?: boolean | undefined, createDate?: string | undefined, createdBy?: number | undefined, lastUpdateDate?: string | undefined, lastUpdateBy?: number | undefined, query: unknown, lastDataModificationDate?: string | undefined, typeCode: unknown, isPlasma?: boolean | undefined, calculationStartDate: unknown, calculationDate: unknown}) | undefined}}; export type CreateApiDatamartUpdatefcTypeCodeOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const createApiDatamartUpdatefcTypeCodeResponse = z.object({response: z.object({node: z.string().min(1).optional(), csrfToken: z.string().min(1).optional(), data: z.array(z.object({version: z.number().optional(), typedId: z.string().min(1).optional(), uniqueName: z.string().min(1).optional(), label: z.string().min(1).optional(), fields: z.array(z.object({})).optional(), keyFields: z.array(z.object({})).optional(), lastUpdateByName: z.string().min(1).optional(), sourceTypeCode: z.string().min(1).optional(), sourceId: z.string().min(1).optional(), sourceLabel: z.string().min(1).optional(), fetchVerb: z.string().min(1).optional(), bulkloadVerb: z.string().min(1).optional(), type: z.string().min(1).optional(), queryable: z.boolean().optional(), view: z.boolean().optional(), sourceName: z.string().min(1).optional(), draft: z.boolean().optional(), locked: z.boolean().optional(), valid: z.boolean().optional(), fieldNames: z.array(z.object({})).optional(), keyFieldNames: z.array(z.object({})).optional(), deployed: z.boolean().optional(), auxiliary: z.boolean().optional(), loadableFields: z.array(z.object({})).optional(), createDate: z.string().min(1).optional(), createdBy: z.number().optional(), lastUpdateDate: z.string().min(1).optional(), lastUpdateBy: z.number().optional(), persistedObjectClass: z.string().min(1).optional(), isPlasma: z.boolean().optional()})).optional(), endRow: z.number().optional(), status: z.number().optional()}).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 }; /** * Update a Data Manager Entity * * POST /datamart.updatefc/{TypeCode} * * Also accepts auth: X-PriceFx-jwt */ export const createApiDatamartUpdatefcTypeCode = async (args: CreateApiDatamartUpdatefcTypeCodeArgs, options?: CreateApiDatamartUpdatefcTypeCodeOptions) => { const {baseUrl = "https://companynode.pricefx.com/pricefx/companypartition", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/datamart.updatefc/${encodeURIComponent(String(args.TypeCode))}${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(createApiDatamartUpdatefcTypeCodeResponse, await res.json()) };