1import { d as apiClient, l as logger } from "./index-D967GsUD.js"; 2async function findDocumentInstanceByContractId(contractId) { 3 try { 4 const data = await apiClient.documents.getByContract(contractId); 5 return data.document ?? null; 6 } catch (error) { 7 logger.error({ 8 message: "[contractActions] Error searching for document instance", 9 contractId, 10 error 11 }); 12 throw error; 13 } 14} 15async function createDocumentInstance(params) { 16 const { contractId, contractType } = params; 17 const payload = { 18 type: contractType, 19 contractId 20 }; 21 const data = await apiClient.documents.create(payload); 22 return data.document ?? null; 23} 24async function ensureDocumentInstance(params) { 25 const { contractId, contractType } = params; 26 const existing = await findDocumentInstanceByContractId(contractId); 27 if (existing == null ? void 0 : existing._id) { 28 return existing; 29 } 30 if (!contractType) { 31 const error = new Error("contractType is required to create a document instance"); 32 logger.error({ 33 message: "[contractActions] Missing contractType when creating document instance", 34 contractId 35 }); 36 throw error; 37 } 38 return createDocumentInstance({ contractId, contractType }); 39} 40async function sendContractDocument(params) { 41 const { contractId, contractType, senderRole, readAndSign } = params; 42 const document = await ensureDocumentInstance({ contractId, contractType }); 43 if (!(document == null ? void 0 : document._id)) { 44 const error = new Error("Document instance not found for contract"); 45 logger.error({ 46 message: "[contractActions] No document instance available to send contract", 47 contractId 48 }); 49 throw error; 50 } 51 const sendBody = { senderRole }; 52 if (readAndSign !== void 0) { 53 sendBody.readAndSign = readAndSign; 54 } 55 const data = await apiClient.documents.send(document._id, sendBody); 56 return { 57 ...data, 58 document: data.document ?? document 59 }; 60} 61async function cancelContractNegotiation(contractId) { 62 const data = await apiClient.contracts.update(contractId, { action: "cancel" }); 63 return data.contract ?? null; 64} 65async function resumeContractNegotiation(contractId) { 66 const data = await apiClient.contracts.update(contractId, { action: "reopen" }); 67 return data.contract ?? null; 68} 69function filenameFromContentDispositionHeader(header) { 70 if (!header) return void 0; 71 const quoted = /filename="([^"]+)"/i.exec(header); 72 if (quoted == null ? void 0 : quoted[1]) return quoted[1]; 73 const unquoted = /filename=([^;\s]+)/i.exec(header); 74 if (unquoted == null ? void 0 : unquoted[1]) return unquoted[1].replace(/^UTF-8''/i, ""); 75 return void 0; 76} 77export { 78 cancelContractNegotiation as c, 79 ensureDocumentInstance as e, 80 filenameFromContentDispositionHeader as f, 81 resumeContractNegotiation as r, 82 sendContractDocument as s 83};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.