import {z} from 'zod' export type CreateFolder = {name: string, parent_folder?: (CreateFolder | string) | undefined}; export type DocumentColloboratorType = 'USER' | 'TEAM'; export type DocumentColloboratorRole = 'READ' | 'WRITE'; export type DocumentColloboratorInput = {type?: DocumentColloboratorType | undefined, id: string, role?: DocumentColloboratorRole | undefined}; export type EditDocument = {folder?: (CreateFolder | string) | undefined, files?: Array<{[key: string]: string}> | undefined, owners?: Array | undefined, collaborators?: Array | undefined, name?: string | undefined, start_date?: string | undefined, end_date?: string | undefined, status?: number | undefined, standard_document_url?: Array<{[key: string]: string}> | undefined, renewal_date?: string | undefined, renewal_status?: number | undefined, project_id?: string | undefined, discrepencies?: number | undefined, missing_clauses_count?: number | undefined, partial_compliance_count?: number | undefined, is_contract?: boolean | undefined, risk_severity?: {[key: string]: string} | undefined}; export type UpdateApiV2ContractIdArgs = {id: string, authorization: string, body: EditDocument}; export type UpdateApiV2ContractIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const documentType = z.enum(["License Agreement", "Beta Test Agreement", "Proof of Concept Agreement", "Statement of Work", "Service Level Agreement", "Master Service Agreement", "Non-Disclosure Agreement (NDA)", "Maintenance and Support Agreement (MSA)", "Software Development Agreement (SDA)", "End User License Agreement (EULA)", "Purchase Order", "Invoice", "Custom", "Custom Document", "Contract", "Service Organization Control 2 (SOC 2)"]); export const servicesAppcatalogTypesTableTableType = z.enum(["TABLE", "TASK"]); export const entityTypeResponse = z.object({slug: z.string(), name: z.string(), is_catalog: z.boolean(), is_hidden: z.boolean()}); export const tableResponse = z.object({id: z.string(), slug: z.string(), type: servicesAppcatalogTypesTableTableType, page_size: z.number().int().optional(), entity_type: entityTypeResponse}); export const servicesAppcatalogTypesItemItemType = z.enum(["OBJECTID", "TEXT", "RICHTEXT", "HIGHLIGHTEXT", "DATEDELTA", "DATE", "SINGLESELECT", "BINARY", "MULTISELECT", "PHONE", "EMAIL", "USER", "TEAM", "NUMBER", "FILE", "URL", "CURRENCY", "ACTION", "TABLE", "CATEGORIES", "ENTITYRELATION", "TAGS", "PICKLISTSELECT", "IDENTITY", "IDENTITYLIST", "CLAUSE", "RISKSEVERITY", "DASHBOARD", "TABLE_LOOKUP", "ENTITY_REFERENCE", "CHILD_ENTITY", "DOCUMENT_SUBTYPE"]); export const servicesAppcatalogModelComputationTypeComputationType = z.enum(["NONE", "FORMULA", "CONDITION", "TABLE_LOOKUP", "AI_PROMPT"]); export const computationArgsResponse = z.object({type: servicesAppcatalogModelComputationTypeComputationType, args: z.object({}).optional()}); export const itemResponse = z.object({id: z.string(), slug: z.string(), db_field: z.string(), name: z.string(), type: servicesAppcatalogTypesItemItemType, args: z.object({}).optional(), is_default: z.boolean(), is_required: z.boolean(), entity_type: entityTypeResponse.optional(), table: z.union([tableResponse, z.string()]).optional(), created_at: z.string(), updated_at: z.string(), deleted_at: z.string().optional(), computation: computationArgsResponse.optional()}); export const createPosition = z.object({placeholder_id: z.string().optional(), grid: z.object({}).optional(), sequence: z.number().int().optional(), size: z.number().int().optional()}); export const fieldResponse = z.object({id: z.string().optional(), name: z.string(), item_slug: z.string().optional(), is_table: z.boolean().optional(), item_type: servicesAppcatalogTypesItemItemType.optional(), item_args: z.object({}).optional(), description: z.string().optional(), generate_ai_summary: z.boolean().optional(), is_hidden: z.boolean().optional(), is_summary: z.boolean().optional(), item: itemResponse, position: createPosition}); export const sectionResponse = z.object({id: z.string(), name: z.string(), table: tableResponse.optional(), sequence: z.number().int(), is_hidden: z.boolean().optional(), created_at: z.string(), updated_at: z.string(), fields: z.array(fieldResponse).optional()}); export const pageResponse = z.object({id: z.string(), slug: z.string(), name: z.string(), sections: z.array(sectionResponse), sequence: z.number().int(), created_at: z.string(), updated_at: z.string(), is_hidden: z.boolean()}); export const documentSubTypeResponse = z.object({id: z.string(), name: z.string(), description: z.string().optional(), type: documentType, slug: z.string(), page: z.union([z.string(), pageResponse]), is_contract: z.boolean(), updated_at: z.string()}); export const folderResponse: z.ZodType = z.object({id: z.string(), name: z.string(), parent_folder: z.lazy(() => folderResponse.optional())}); export const actorType = z.enum(["USER", "TEAM", "ROLE"]); export const accessType = z.enum(["READ", "WRITE", "OWNER", "BLOCKED", "SEARCH"]); export const collaboratorResponse = z.object({id: z.string(), auth_role: z.string().optional(), type: actorType, name: z.string().optional(), email: z.string().optional(), access_modes: z.array(accessType).optional()}); export const servicesAppcatalogSchemaEntityEntityResponse = z.object({id: z.string(), name: z.string(), logo: z.string().optional(), slug: z.string(), entity_type: entityTypeResponse, vendor_managers: z.array(collaboratorResponse).optional()}); export const documentColloboratorType = z.enum(["USER", "TEAM"]); export const sharedSchemaUserResponse = z.object({id: z.string(), name: z.string(), email: z.string()}); export const sharedSchemaTeamResponse = z.object({id: z.string(), name: z.string()}); export const documentColloboratorRole = z.enum(["READ", "WRITE"]); export const documentColloboratorResponse = z.object({type: documentColloboratorType.optional(), data: z.union([sharedSchemaUserResponse, sharedSchemaTeamResponse]).optional(), role: documentColloboratorRole.optional()}); export const documentResponse = z.object({id: z.string(), document_subtype: documentSubTypeResponse, folder: folderResponse.optional(), entity: servicesAppcatalogSchemaEntityEntityResponse, files: z.array(z.record(z.string(), z.union([z.string(), z.string()]))), owners: z.array(z.record(z.string(), z.string())), collaborators: z.array(documentColloboratorResponse).optional(), name: z.string().optional(), start_date: z.string().optional(), end_date: z.string().optional(), status: z.object({}), renewal_date: z.string().optional(), renewal_status: z.object({}).optional(), project_id: z.string().optional(), source_project_id: z.string().optional(), discrepencies: z.number().int().optional(), missing_clauses_count: z.number().int().optional(), partial_compliance_count: z.number().int().optional(), is_contract: z.boolean(), risk_severity: z.record(z.string(), z.string()).optional(), role: documentColloboratorRole.optional(), updated_at: z.string()}); 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 Contract * * PUT /v2/contract/{id} */ export const updateApiV2ContractId = async (args: UpdateApiV2ContractIdArgs, options: UpdateApiV2ContractIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.authorization != null) headers.set("authorization", String(args.authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/v2/contract/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(documentResponse, await res.json()) };