import {z} from 'zod' export type ContractScopedCreatePobDto = {name?: (string | null) | undefined, itemId?: (string | null) | undefined, erpClassId?: (string | null) | undefined, category?: (string | null) | undefined, considerationType?: ('FIXED' | 'VARIABLE' | null) | undefined, recognitionPattern?: ('POINT_IN_TIME' | 'INPUT_BASED' | 'OUTPUT_BASED' | 'STRAIGHT_LINE' | 'RECOGNIZE_AS_CONSUMED' | 'RECOGNIZE_AS_BILLED' | 'SEAT_BASED_STRAIGHT_LINE' | null) | undefined, eventTypeId?: (string | null) | undefined, productId?: (string | null) | undefined, serviceStartDate: string, serviceEndDate: string, transactionPrice: string}; export type ContractScopedUpdatePobDto = {id: string, name?: (string | null) | undefined, itemId?: (string | null) | undefined, erpClassId?: (string | null) | undefined, category?: (string | null) | undefined, considerationType?: ('FIXED' | 'VARIABLE' | null) | undefined, recognitionPattern?: ('POINT_IN_TIME' | 'INPUT_BASED' | 'OUTPUT_BASED' | 'STRAIGHT_LINE' | 'RECOGNIZE_AS_CONSUMED' | 'RECOGNIZE_AS_BILLED' | 'SEAT_BASED_STRAIGHT_LINE' | null) | undefined, eventTypeId?: (string | null) | undefined, productId?: (string | null) | undefined, serviceStartDate?: string | undefined, serviceEndDate?: string | undefined, transactionPrice?: string | undefined}; export type BatchSavePobsForContractDto = {billingTermGroupId: string, toCreate: Array, toUpdate: Array, toDelete: Array}; export type CreateApiV3ContractsIdPerformanceObligationsArgs = {id: string, body: BatchSavePobsForContractDto}; export type CreateApiV3ContractsIdPerformanceObligationsOptions = {baseUrl?: string | undefined, customHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const integratorsApiError = z.object({code: z.number(), message: z.string(), details: z.object({}).optional()}); export const createApiV3ContractsIdPerformanceObligationsResponse = z.object({payload: z.object({errors: z.array(z.object({})).optional()}), success: z.boolean(), message: z.string(), error: integratorsApiError}); 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 }; /** * Bulk save contract performance obligations * * POST /v3/contracts/{id}/performance-obligations */ export const createApiV3ContractsIdPerformanceObligations = async (args: CreateApiV3ContractsIdPerformanceObligationsArgs, options?: CreateApiV3ContractsIdPerformanceObligationsOptions) => { const {baseUrl = "https://integrators.prod.api.tabsplatform.com", fetch: fetchFn = fetch, customHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (customHeader !== undefined) headers.set("Authorization", customHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v3/contracts/${encodeURIComponent(String(args.id))}/performance-obligations${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(createApiV3ContractsIdPerformanceObligationsResponse, await res.json()) };