function toCustomISOString(date) { // Ensure input is a Date object if (!(date instanceof Date)) throw new Error("Input must be a Date object"); // Get ISO string, then trim to 3 ms digits and add 'Z' return date.toISOString().replace(/\d{3}Z$/, match => match.slice(0, 3) + 'Z'); } return { /** * * @param {String} customerId Customer identifier (i.e. 10000050) * @param {[String]} notes Array on notes * @param {Date} startTime Start time of the interaction * @param {Date} endTime End time of the interaction * @param {String} external URL */ post(customerId, notes, startTime, endTime, url) { return new Promise(async (resolve, reject) => { try { const OIDC = await CAInterface().getOIDC(); let config = CAInterface().settings().url.CA; const contextServiceURL = `https://${config.base}/context-service/${config.tenant}/contexts`; const { data } = await CAInterface().axios("contextService", { method: "post", url: contextServiceURL, headers: { "Content-Type": "application/ld+json", Authorization: `OIDC_id_token ${OIDC.access_token}`, }, data: { "@type": "vctx:Context", "vctx:contacts": [ { "@type": "vctc:ExternalContact", "vctc:subtype": "iva", "vctc:direction": "vctc:inbound", "vctc:startTime": toCustomISOString(startTime), "vctc:endTime": toCustomISOString(endTime), "vctc:externalUrl": url, "vctc:notes": notes, }, ], "vctx:customer": { "@type": "vcust:Customer", "vcust:identifier": `${customerId}`, }, }, }); console.log({ contextServiceData: data, }); resolve(); } catch (error) { reject(error); } }); }, };