import {z} from 'zod' export type UserSimple = {'avatar-thumb-url'?: unknown | undefined, 'created-at'?: unknown | undefined, email: unknown, 'employee-number'?: unknown | undefined, firstname: unknown, fullname?: unknown | undefined, id?: number | undefined, lastname: unknown, login: unknown, 'salesforce-id': unknown, 'updated-at'?: unknown | undefined}; export type Integration = {'business-object': unknown, code: unknown, 'created-at'?: unknown | undefined, 'created-by'?: UserSimple | undefined, direction: 'to_coupa' | 'from_coupa', 'end-system': unknown, 'end-system-type': 'payroll' | 'erp' | 'hr' | 'third_party_partner' | 'third_party_vendor' | 'other' | 'internal', id?: number | undefined, 'integration-type'?: ('flat_file' | 'api' | 'corporate_credit_card_file' | 'json' | 'xml' | 'original_format') | undefined, name: unknown, standard?: boolean | undefined, 'updated-at'?: unknown | undefined, 'updated-by'?: UserSimple | undefined}; export type Flow = Record; export type IntegrationRecordResponse = {'created-at'?: unknown | undefined, 'created-by'?: UserSimple | undefined, id?: number | undefined, 'response-code'?: unknown | undefined, 'response-message'?: unknown | undefined, 'updated-at'?: unknown | undefined, 'updated-by'?: UserSimple | undefined}; export type IntegrationError = {'contact-alert-type': unknown, 'created-at'?: unknown | undefined, 'created-by'?: UserSimple | undefined, 'creation-method'?: unknown | undefined, 'document-id'?: number | undefined, 'document-revision'?: number | undefined, 'document-status'?: unknown | undefined, 'document-type'?: ('ContingentWorkOrderHeader' | 'ExternalOrderHeader' | 'OrderHeader' | 'InventoryTransaction' | 'InvoiceHeader' | 'ExpenseReport' | 'RequisitionHeader' | 'Account' | 'Supplier' | 'User' | 'Address' | 'RemitToAddress' | 'Contract' | 'ExchangeRate' | 'Invoice' | 'Requisition' | 'Payment' | 'ApprovalChain' | 'LookupValue' | 'Item' | 'SupplierInformation' | 'Asn::Header' | 'AccountValidationRule' | 'Payables::External::Payable' | 'Charge' | 'Payables::Invoice' | 'Payables::Expense' | 'CoupaPay::Payment' | 'CoupaPay::Statement' | 'ReceiptRequest' | 'InventoryRequestHeader') | undefined, 'external-id'?: unknown | undefined, id?: number | undefined, integration?: Integration | undefined, 'integration-filename'?: unknown | undefined, 'integration-run': IntegrationRun, 'integration-run-id'?: number | undefined, resolved?: boolean | undefined, responses?: Array | undefined, status?: unknown | undefined, 'updated-at'?: unknown | undefined, 'updated-by'?: UserSimple | undefined}; export type IntegrationRun = {'created-at'?: unknown | undefined, 'created-by'?: UserSimple | undefined, 'end-time'?: unknown | undefined, flow?: Flow | undefined, id?: number | undefined, integration: Integration, 'integration-errors'?: Array | undefined, 'records-processed'?: number | undefined, 'start-time'?: unknown | undefined, status?: unknown | undefined, 'total-records'?: number | undefined, 'updated-at'?: unknown | undefined, 'updated-by'?: UserSimple | undefined}; export type IntegrationHistoryRecord = {'contact-alert-type': unknown, 'created-at'?: unknown | undefined, 'created-by'?: UserSimple | undefined, 'creation-method'?: unknown | undefined, 'document-id': number, 'document-revision'?: number | undefined, 'document-status'?: unknown | undefined, 'document-type': 'ContingentWorkOrderHeader' | 'ExternalOrderHeader' | 'OrderHeader' | 'InventoryTransaction' | 'InvoiceHeader' | 'ExpenseReport' | 'RequisitionHeader' | 'Account' | 'Supplier' | 'User' | 'Address' | 'RemitToAddress' | 'Contract' | 'ExchangeRate' | 'Invoice' | 'Requisition' | 'Payment' | 'ApprovalChain' | 'LookupValue' | 'Item' | 'SupplierInformation' | 'Asn::Header' | 'AccountValidationRule' | 'Payables::External::Payable' | 'Charge' | 'Payables::Invoice' | 'Payables::Expense' | 'CoupaPay::Payment' | 'CoupaPay::Statement' | 'ReceiptRequest' | 'InventoryRequestHeader', 'external-id'?: unknown | undefined, id?: number | undefined, integration?: Integration | undefined, 'integration-filename'?: unknown | undefined, 'integration-run'?: IntegrationRun | undefined, 'integration-run-id'?: number | undefined, resolved?: boolean | undefined, responses?: Array | undefined, status?: unknown | undefined, 'updated-at'?: unknown | undefined, 'updated-by'?: UserSimple | undefined}; export type PatchApiIntegrationHistoryRecordsIdArgs = {id: number, return_object?: ('limited' | 'shallow' | 'none') | undefined, filter?: string | undefined, body: IntegrationHistoryRecord}; export type PatchApiIntegrationHistoryRecordsIdOptions = {baseUrl?: string | undefined, OAuth2AccessCode?: string | undefined, fetch?: typeof fetch | undefined}; export const userSimple = z.object({"avatar-thumb-url": z.string().optional(), "created-at": z.string().optional(), email: z.string(), "employee-number": z.string().optional(), firstname: z.string(), fullname: z.string().optional(), id: z.number().int().optional(), lastname: z.string(), login: z.string(), "salesforce-id": z.string(), "updated-at": z.string().optional()}); export const integration = z.object({"business-object": z.string(), code: z.string(), "created-at": z.string().optional(), "created-by": userSimple.optional(), direction: z.enum(["to_coupa", "from_coupa"]), "end-system": z.string(), "end-system-type": z.enum(["payroll", "erp", "hr", "third_party_partner", "third_party_vendor", "other", "internal"]), id: z.number().int().optional(), "integration-type": z.enum(["flat_file", "api", "corporate_credit_card_file", "json", "xml", "original_format"]).optional(), name: z.string(), standard: z.boolean().optional(), "updated-at": z.string().optional(), "updated-by": userSimple.optional()}); export const flow = z.object({}); export const integrationRecordResponse = z.object({"created-at": z.string().optional(), "created-by": userSimple.optional(), id: z.number().int().optional(), "response-code": z.string().optional(), "response-message": z.string().optional(), "updated-at": z.string().optional(), "updated-by": userSimple.optional()}); export const integrationError = z.object({"contact-alert-type": z.string(), "created-at": z.string().optional(), "created-by": userSimple.optional(), "creation-method": z.string().optional(), "document-id": z.number().int().optional(), "document-revision": z.number().int().optional(), "document-status": z.string().optional(), "document-type": z.enum(["ContingentWorkOrderHeader", "ExternalOrderHeader", "OrderHeader", "InventoryTransaction", "InvoiceHeader", "ExpenseReport", "RequisitionHeader", "Account", "Supplier", "User", "Address", "RemitToAddress", "Contract", "ExchangeRate", "Invoice", "Requisition", "Payment", "ApprovalChain", "LookupValue", "Item", "SupplierInformation", "Asn::Header", "AccountValidationRule", "Payables::External::Payable", "Charge", "Payables::Invoice", "Payables::Expense", "CoupaPay::Payment", "CoupaPay::Statement", "ReceiptRequest", "InventoryRequestHeader"]).optional(), "external-id": z.string().optional(), id: z.number().int().optional(), integration: integration.optional(), "integration-filename": z.string().optional(), "integration-run": z.lazy(() => integrationRun), "integration-run-id": z.number().int().optional(), resolved: z.boolean().optional(), responses: z.array(integrationRecordResponse).optional(), status: z.string().optional(), "updated-at": z.string().optional(), "updated-by": userSimple.optional()}); export const integrationRun: z.ZodType = z.object({"created-at": z.string().optional(), "created-by": userSimple.optional(), "end-time": z.string().optional(), flow: flow.optional(), id: z.number().int().optional(), integration: integration, "integration-errors": z.array(integrationError).optional(), "records-processed": z.number().int().optional(), "start-time": z.string().optional(), status: z.string().optional(), "total-records": z.number().int().optional(), "updated-at": z.string().optional(), "updated-by": userSimple.optional()}); export const integrationHistoryRecord = z.object({"contact-alert-type": z.string(), "created-at": z.string().optional(), "created-by": userSimple.optional(), "creation-method": z.string().optional(), "document-id": z.number().int(), "document-revision": z.number().int().optional(), "document-status": z.string().optional(), "document-type": z.enum(["ContingentWorkOrderHeader", "ExternalOrderHeader", "OrderHeader", "InventoryTransaction", "InvoiceHeader", "ExpenseReport", "RequisitionHeader", "Account", "Supplier", "User", "Address", "RemitToAddress", "Contract", "ExchangeRate", "Invoice", "Requisition", "Payment", "ApprovalChain", "LookupValue", "Item", "SupplierInformation", "Asn::Header", "AccountValidationRule", "Payables::External::Payable", "Charge", "Payables::Invoice", "Payables::Expense", "CoupaPay::Payment", "CoupaPay::Statement", "ReceiptRequest", "InventoryRequestHeader"]), "external-id": z.string().optional(), id: z.number().int().optional(), integration: integration.optional(), "integration-filename": z.string().optional(), "integration-run": integrationRun.optional(), "integration-run-id": z.number().int().optional(), resolved: z.boolean().optional(), responses: z.array(integrationRecordResponse).optional(), status: z.string().optional(), "updated-at": z.string().optional(), "updated-by": userSimple.optional()}); export const patchApiIntegrationHistoryRecordsIdResponse = z.array(integrationHistoryRecord); 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 integration history record * * PATCH /integration_history_records/{id} * * Also accepts auth: OAuth2ClientCredential */ export const patchApiIntegrationHistoryRecordsId = async (args: PatchApiIntegrationHistoryRecordsIdArgs, options?: PatchApiIntegrationHistoryRecordsIdOptions) => { const {baseUrl = "https://r38.coupadev.com/api", fetch: fetchFn = fetch, OAuth2AccessCode} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.return_object != null) query.append("return_object", String(args.return_object)) if (args.filter != null) query.append("filter", String(args.filter)) if (OAuth2AccessCode !== undefined) headers.set('authorization', `Bearer ${OAuth2AccessCode}`) const url = `${baseUrl.replace(/\/+$/, '')}/integration_history_records/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiIntegrationHistoryRecordsIdResponse, await res.json()) };