From 0e38783560e48e0584a4372f5a6b714844b36276 Mon Sep 17 00:00:00 2001 From: prafull-opensignlabs Date: Tue, 16 Apr 2024 19:54:22 +0530 Subject: [PATCH 1/2] style: change design of buttons in report --- apps/OpenSign/src/json/ReportJson.js | 163 +++++++++++------- .../src/primitives/GetReportDisplay.js | 133 ++++++++------ 2 files changed, 184 insertions(+), 112 deletions(-) diff --git a/apps/OpenSign/src/json/ReportJson.js b/apps/OpenSign/src/json/ReportJson.js index 728ef175b..21066f669 100644 --- a/apps/OpenSign/src/json/ReportJson.js +++ b/apps/OpenSign/src/json/ReportJson.js @@ -13,7 +13,7 @@ export default function reportJson(id) { actions: [ { btnId: "1231", - btnLabel: "Edit", + hoverLabel: "Edit", btnColor: "#4bd396", textColor: "white", btnIcon: "fa-solid fa-pen", @@ -22,7 +22,7 @@ export default function reportJson(id) { }, { btnId: "2142", - btnLabel: "Delete", + hoverLabel: "Delete", btnColor: "#ff4848", textColor: "white", btnIcon: "fa fa-trash", @@ -41,10 +41,11 @@ export default function reportJson(id) { actions: [ { btnId: "4536", - btnLabel: "Sign", + btnLabel: "sign", + hoverLabel: "Sign", btnColor: "#3ac9d6", textColor: "white", - btnIcon: "fa fa-eye", + btnIcon: "fa-solid fa-signature", redirectUrl: "pdfRequestFiles", action: "redirect" } @@ -60,8 +61,8 @@ export default function reportJson(id) { actions: [ { btnId: "8901", - btnLabel: "Share", - btnColor: "#3ac9d6", + hoverLabel: "Share", + btnColor: "#4bd396", textColor: "white", btnIcon: "fa-solid fa-share", redirectUrl: "", @@ -69,7 +70,7 @@ export default function reportJson(id) { }, { btnId: "1588", - btnLabel: "View", + hoverLabel: "View", btnColor: "#3ac9d6", textColor: "white", btnIcon: "fa fa-eye", @@ -77,22 +78,30 @@ export default function reportJson(id) { action: "redirect" }, { - btnId: "1488", - btnLabel: "Delete", - btnColor: "#ff4848", - textColor: "white", - btnIcon: "fa fa-trash", - redirectUrl: "", - action: "delete" - }, - { - btnId: "1688", - btnLabel: "Revoke", - btnColor: "#ff4848", - textColor: "white", - btnIcon: "fa-solid fa-file-circle-xmark", - redirectUrl: "", - action: "revoke" + btnId: "2234", + hoverLabel: "option", + btnColor: "transparent", + textColor: "black", + btnIcon: "fa-solid fa-ellipsis-vertical fa-lg", + action: "option", + subaction: [ + { + btnId: "1688", + btnLabel: "Revoke", + hoverLabel: "Revoke", + btnIcon: "fa-solid fa-file-circle-xmark", + redirectUrl: "", + action: "revoke" + }, + { + btnId: "1488", + btnLabel: "Delete", + hoverLabel: "Delete", + btnIcon: "fa fa-trash", + redirectUrl: "", + action: "delete" + } + ] } ], helpMsg: @@ -106,7 +115,7 @@ export default function reportJson(id) { actions: [ { btnId: "1378", - btnLabel: "Edit", + hoverLabel: "Edit", btnColor: "#4bd396", textColor: "white", btnIcon: "fa fa-eye", @@ -115,7 +124,7 @@ export default function reportJson(id) { }, { btnId: "1278", - btnLabel: "Delete", + hoverLabel: "Delete", btnColor: "#ff4848", textColor: "white", btnIcon: "fa fa-trash", @@ -134,7 +143,7 @@ export default function reportJson(id) { actions: [ { btnId: "1458", - btnLabel: "View", + hoverLabel: "View", btnColor: "#4bd396", textColor: "white", btnIcon: "fa fa-eye", @@ -143,7 +152,7 @@ export default function reportJson(id) { }, { btnId: "1358", - btnLabel: "Delete", + hoverLabel: "Delete", btnColor: "#ff4848", textColor: "white", btnIcon: "fa fa-trash", @@ -162,7 +171,7 @@ export default function reportJson(id) { actions: [ { btnId: "1898", - btnLabel: "View", + hoverLabel: "View", btnColor: "#4bd396", textColor: "white", btnIcon: "fa fa-eye", @@ -171,7 +180,7 @@ export default function reportJson(id) { }, { btnId: "1998", - btnLabel: "Delete", + hoverLabel: "Delete", btnColor: "#ff4848", textColor: "white", btnIcon: "fa fa-trash", @@ -190,21 +199,47 @@ export default function reportJson(id) { actions: [ { btnId: "1999", - btnLabel: "View", + hoverLabel: "Share", btnColor: "#4bd396", textColor: "white", + btnIcon: "fa-solid fa-share", + redirectUrl: "", + action: "share" + }, + { + btnId: "1999", + hoverLabel: "View", + btnColor: "#3ac9d6", + textColor: "white", btnIcon: "fa fa-eye", redirectUrl: "pdfRequestFiles", action: "redirect" }, { - btnId: "2000", - btnLabel: "Delete", - btnColor: "#ff4848", - textColor: "white", - btnIcon: "fa fa-trash", - redirectUrl: "", - action: "delete" + btnId: "2234", + hoverLabel: "option", + btnColor: "transparent", + textColor: "black", + btnIcon: "fa-solid fa-ellipsis-vertical fa-lg", + action: "option", + subaction: [ + { + btnId: "6788", + btnLabel: "Revoke", + hoverLabel: "Revoke", + btnIcon: "fa-solid fa-file-circle-xmark", + redirectUrl: "", + action: "revoke" + }, + { + btnId: "2000", + btnLabel: "Delete", + hoverLabel: "Delete", + btnIcon: "fa fa-trash", + redirectUrl: "", + action: "delete" + } + ] } ] }; @@ -216,8 +251,9 @@ export default function reportJson(id) { actions: [ { btnId: "2001", - btnLabel: "Sign", - btnColor: "#4bd396", + btnLabel: "sign", + hoverLabel: "Sign", + btnColor: "#3ac9d6", textColor: "white", btnIcon: "fa-solid fa-signature", redirectUrl: "pdfRequestFiles", @@ -233,7 +269,7 @@ export default function reportJson(id) { actions: [ { btnId: "2003", - btnLabel: "Edit", + hoverLabel: "Edit", btnColor: "#4bd396", textColor: "white", btnIcon: "fa-solid fa-pen", @@ -242,7 +278,7 @@ export default function reportJson(id) { }, { btnId: "2004", - btnLabel: "Delete", + hoverLabel: "Delete", btnColor: "#ff4848", textColor: "white", btnIcon: "fa fa-trash", @@ -259,7 +295,7 @@ export default function reportJson(id) { actions: [ { btnId: "2204", - btnLabel: "Delete", + hoverLabel: "Delete", btnColor: "#f55a42", textColor: "white", btnIcon: "fa-solid fa-trash", @@ -278,7 +314,8 @@ export default function reportJson(id) { actions: [ { btnId: "2234", - btnLabel: "Create document", + btnLabel: "Use", + hoverLabel: "Use", btnColor: "#4bd396", textColor: "white", btnIcon: "fa fa-plus", @@ -286,22 +323,30 @@ export default function reportJson(id) { action: "redirect" }, { - btnLabel: "Edit", - btnId: "2434", - btnColor: "#00c9d5", - textColor: "white", - btnIcon: "fa-solid fa-pen", - redirectUrl: "template", - action: "redirect" - }, - { - btnId: "1834", - btnLabel: "Delete", - btnColor: "#ff4848", - textColor: "white", - btnIcon: "fa fa-trash", - redirectUrl: "", - action: "delete" + btnId: "2234", + hoverLabel: "option", + btnColor: "transparent", + textColor: "black", + btnIcon: "fa-solid fa-ellipsis-vertical fa-lg", + action: "option", + subaction: [ + { + btnId: "2434", + btnLabel: "Edit", + hoverLabel: "Edit", + btnIcon: "fa-solid fa-pen", + redirectUrl: "template", + action: "redirect" + }, + { + btnId: "1834", + btnLabel: "Delete", + hoverLabel: "Delete", + btnIcon: "fa fa-trash", + redirectUrl: "", + action: "delete" + } + ] } ], helpMsg: diff --git a/apps/OpenSign/src/primitives/GetReportDisplay.js b/apps/OpenSign/src/primitives/GetReportDisplay.js index b6bbd34ba..4684b3058 100644 --- a/apps/OpenSign/src/primitives/GetReportDisplay.js +++ b/apps/OpenSign/src/primitives/GetReportDisplay.js @@ -1,4 +1,4 @@ - import React, { useState, useEffect, useMemo } from "react"; +import React, { useState, useEffect, useMemo } from "react"; import pad from "../assets/images/pad.svg"; import { useNavigate } from "react-router-dom"; import axios from "axios"; @@ -9,18 +9,7 @@ import Alert from "./Alert"; import Tooltip from "./Tooltip"; import { RWebShare } from "react-web-share"; -const ReportTable = ({ - ReportName, - List, - setList, - actions, - heading, - setIsNextRecord, - isMoreDocs, - docPerPage, - form, - report_help -}) => { +const ReportTable = (props) => { const navigate = useNavigate(); const [currentPage, setCurrentPage] = useState(1); const [actLoader, setActLoader] = useState({}); @@ -32,18 +21,19 @@ const ReportTable = ({ const [isShare, setIsShare] = useState({}); const [shareUrls, setShareUrls] = useState([]); const [copied, setCopied] = useState(false); + const [isOption, setIsOption] = useState({}); const [alertMsg, setAlertMsg] = useState({ type: "success", message: "" }); - const startIndex = (currentPage - 1) * docPerPage; - + const startIndex = (currentPage - 1) * props.docPerPage; + const { isMoreDocs, setIsNextRecord } = props; // For loop is used to calculate page numbers visible below table // Initialize pageNumbers using useMemo to avoid unnecessary re-creation const pageNumbers = useMemo(() => { const calculatedPageNumbers = []; - for (let i = 1; i <= Math.ceil(List.length / docPerPage); i++) { + for (let i = 1; i <= Math.ceil(props.List.length / props.docPerPage); i++) { calculatedPageNumbers.push(i); } return calculatedPageNumbers; - }, [List, docPerPage]); + }, [props.List, props.docPerPage]); // below useEffect reset currenpage to 1 if user change route useEffect(() => { return () => setCurrentPage(1); @@ -73,8 +63,8 @@ const ReportTable = ({ // `handleURL` is used to open microapp const handleURL = async (item, act) => { - if (ReportName === "Templates") { - if (act.btnLabel === "Edit") { + if (props.ReportName === "Templates") { + if (act.hoverLabel === "Edit") { navigate(`/${act.redirectUrl}/${item.objectId}`); } else { setActLoader({ [`${item.objectId}_${act.btnId}`]: true }); @@ -212,13 +202,15 @@ const ReportTable = ({ handleShare(item); } else if (act.action === "revoke") { setIsRevoke({ [item.objectId]: true }); + } else if (act.action === "option") { + setIsOption({ [item.objectId]: !isOption[item.objectId] }); } }; // Get current list - const indexOfLastDoc = currentPage * docPerPage; - const indexOfFirstDoc = indexOfLastDoc - docPerPage; + const indexOfLastDoc = currentPage * props.docPerPage; + const indexOfFirstDoc = indexOfLastDoc - props.docPerPage; // `currentLists` is total record render on current page - const currentLists = List?.slice(indexOfFirstDoc, indexOfLastDoc); + const currentLists = props.List?.slice(indexOfFirstDoc, indexOfLastDoc); // Change page const paginateFront = () => setCurrentPage(currentPage + 1); @@ -229,7 +221,7 @@ const ReportTable = ({ }; const handleUserData = (data) => { - setList((prevData) => [data, ...prevData]); + props.setList((prevData) => [data, ...prevData]); }; const handleDelete = async (item) => { @@ -243,10 +235,10 @@ const ReportTable = ({ const serverUrl = process.env.REACT_APP_SERVERURL ? process.env.REACT_APP_SERVERURL : window.location.origin + "/api/app"; - const cls = clsObj[ReportName] || "contracts_Document"; + const cls = clsObj[props.ReportName] || "contracts_Document"; const url = serverUrl + `/classes/${cls}/`; const body = - ReportName === "Contactbook" + props.ReportName === "Contactbook" ? { IsDeleted: true } : { IsArchive: true }; const res = await axios.put(url + item.objectId, body, { @@ -265,8 +257,10 @@ const ReportTable = ({ message: "Record deleted successfully!" }); setTimeout(() => setIsAlert(false), 1500); - const upldatedList = List.filter((x) => x.objectId !== item.objectId); - setList(upldatedList); + const upldatedList = props.List.filter( + (x) => x.objectId !== item.objectId + ); + props.setList(upldatedList); } } catch (err) { console.log("err", err); @@ -335,8 +329,10 @@ const ReportTable = ({ message: "Record revoked successfully!" }); setTimeout(() => setIsAlert(false), 1500); - const upldatedList = List.filter((x) => x.objectId !== item.objectId); - setList(upldatedList); + const upldatedList = props.List.filter( + (x) => x.objectId !== item.objectId + ); + props.setList(upldatedList); } }) .catch((err) => { @@ -364,20 +360,20 @@ const ReportTable = ({ {isAlert && {alertMsg.message}}
- {ReportName}{" "} - {report_help && ( + {props.ReportName}{" "} + {props.report_help && ( - + )}
- {ReportName === "Templates" && ( + {props.ReportName === "Templates" && ( navigate("/form/template")} className="fa-solid fa-square-plus text-sky-400 text-[25px]" > )} - {form && ( + {props.form && (
handleContactFormModal()} @@ -389,36 +385,36 @@ const ReportTable = ({ - {heading?.map((item, index) => ( + {props.heading?.map((item, index) => ( ))} - {actions?.length > 0 && ( + {props.actions?.length > 0 && ( )} - {List?.length > 0 && ( + {props.List?.length > 0 && ( <> {currentLists.map((item, index) => - ReportName === "Contactbook" ? ( + props.ReportName === "Contactbook" ? ( - {heading.includes("Sr.No") && ( + {props.heading.includes("Sr.No") && ( )} ) : ( - {heading.includes("Sr.No") && ( + {props.heading.includes("Sr.No") && ( )} - {heading.includes("Note") && ( + {props.heading.includes("Note") && ( )} - {heading.includes("Folder") && ( + {props.heading.includes("Folder") && ( @@ -500,14 +496,18 @@ const ReportTable = ({ -
{item} Action
{startIndex + index + 1}{item?.Name} {item?.Email || "-"} {item?.Phone || "-"} - {actions?.length > 0 && - actions.map((act, index) => ( + {props.actions?.length > 0 && + props.actions.map((act, index) => (
{startIndex + index + 1} {item?.Name}{" "} {item?.Note || "-"} {item?.Folder?.Name || "OpenSign™ Drive"} {item?.Signers ? formatRow(item?.Signers) : "-"} - {actions?.length > 0 && - actions.map((act, index) => ( + + {props.actions?.length > 0 && + props.actions.map((act, index) => ( ))} {isDeleteModal[item.objectId] && ( @@ -637,7 +664,7 @@ const ReportTable = ({
- {List.length > docPerPage && ( + {props.List.length > props.docPerPage && ( <> {currentPage > 1 && ( )} - {List.length > docPerPage && ( + {props.List.length > props.docPerPage && ( <> {pageNumbers.includes(currentPage + 1) && (
- {List?.length <= 0 && ( + {props.List?.length <= 0 && (
Date: Wed, 17 Apr 2024 12:12:08 +0530 Subject: [PATCH 2/2] feat: send custom completion mail if available --- .../cloud/parsefunction/pdf/PDF.min.js | 204 ++++++++++-------- 1 file changed, 118 insertions(+), 86 deletions(-) diff --git a/apps/OpenSignServer/cloud/parsefunction/pdf/PDF.min.js b/apps/OpenSignServer/cloud/parsefunction/pdf/PDF.min.js index 0a8630125..5f73f8c62 100644 --- a/apps/OpenSignServer/cloud/parsefunction/pdf/PDF.min.js +++ b/apps/OpenSignServer/cloud/parsefunction/pdf/PDF.min.js @@ -3,7 +3,7 @@ import fs from 'node:fs'; import axios from 'axios'; import { pdflibAddPlaceholder } from './customSignPdf/pdflibplaceholder.min.js'; import { PDFDocument } from 'pdf-lib'; -import { saveFileUsage } from '../../../Utils.js'; +import { replaceMailVaribles, saveFileUsage } from '../../../Utils.js'; import GenerateCertificate from './GenerateCertificate.js'; const serverUrl = process.env.SERVER_URL, APPID = process.env.APP_ID, @@ -20,18 +20,18 @@ async function uploadFile(e, a) { } async function updateDoc(t, s, r, i, o, n) { try { - var d = { + var l = { UserPtr: { __type: 'Pointer', className: n, objectId: r }, SignedUrl: s, Activity: 'Signed', ipAddress: i, }; let e; - var l = (e = o.AuditTrail && 0 < o.AuditTrail.length ? [...o.AuditTrail, d] : [d]).filter( + var d = (e = o.AuditTrail && 0 < o.AuditTrail.length ? [...o.AuditTrail, l] : [l]).filter( e => 'Signed' === e.Activity ); let a = !1; - !((o.Signers && 0 < o.Signers.length && l.length !== o.Signers.length) || !(a = !0)); + !((o.Signers && 0 < o.Signers.length && d.length !== o.Signers.length) || !(a = !0)); var c = { SignedUrl: s, AuditTrail: e, IsCompleted: a }; await axios.put(serverUrl + '/classes/contracts_Document/' + t, c, { headers: { @@ -47,23 +47,62 @@ async function updateDoc(t, s, r, i, o, n) { } async function sendCompletedMail(e) { var a = e.url, - t = e.sender, - s = e.pdfName, - r = e.receiver, - e = { - extUserId: e.extUserId, - url: a, - from: 'OpenSign™', - recipient: r, - subject: `Document ${s} has been signed by all parties`, - pdfName: s, - html: - "

Document sign successfully

All parties have successfully signed the document" + - s + - '. Kindly download the document from the attachment.

This is an automated email from OpenSign™. For any queries regarding this email, please contact the sender ' + - t.Mail + - ' directly. If you think this email is inappropriate or spam, you may file a complaint with OpenSign™ here.

', - }; + t = e.doc, + s = e.doc.ExtUserPtr, + r = t.Name, + i = s.Email; + let o = `Document "${r}" has been signed by all parties`, + n = + "

Document signed successfully

All parties have successfully signed the document " + + `"${r}"` + + '. Kindly download the document from the attachment.

This is an automated email from OpenSign™. For any queries regarding this email, please contact the sender ' + + s.Email + + ' directly. If you think this email is inappropriate or spam, you may file a complaint with OpenSign™ here.

'; + if (e?.isCustomMail) + try { + var l, + d, + c, + p, + m, + g = new Parse.Query('partners_Tenant'); + g.equalTo('UserId', { __type: 'Pointer', className: '_User', objectId: s.UserId.objectId }); + const u = await g.first(); + u && + ((l = JSON.parse(JSON.stringify(u)))?.CompletionSubject && (o = l?.CompletionSubject), + l?.CompletionBody && (n = l?.CompletionBody), + (d = t.ExpiryDate.iso), + (c = new Date(d).toLocaleDateString('en-US', { + day: 'numeric', + month: 'long', + year: 'numeric', + })), + (p = { + document_title: r, + sender_name: s.Name, + sender_mail: s.Email, + sender_phone: s.Phone, + receiver_name: s.Name, + receiver_email: s.Email, + receiver_phone: s.Phone, + expiry_date: c, + company_name: s.Company, + }), + (m = replaceMailVaribles(o, n, p)), + (o = m.subject), + (n = m.body)); + } catch (e) { + console.log('error in fetch tenant in signpdf', e.message); + } + e = { + extUserId: s.objectId, + url: a, + from: 'OpenSign™', + recipient: i, + subject: o, + pdfName: r, + html: n, + }; await axios.post(serverUrl + '/functions/sendmailv3', e, { headers: { 'Content-Type': 'application/json', @@ -134,6 +173,7 @@ async function PDF(o) { try { var n = o.params.docId, e = o.params.userId, + l = o.params.isCustomCompletionMail, d = await axios.get( serverUrl + '/classes/contracts_Document/' + n + '?include=ExtUserPtr,Signers', { @@ -144,33 +184,33 @@ async function PDF(o) { }, } ), - l = await axios.get(serverUrl + '/users/me', { + c = await axios.get(serverUrl + '/users/me', { headers: { 'X-Parse-Application-Id': APPID, 'X-Parse-Session-Token': o.headers.sessiontoken, }, }); - if (!l.data || !l.data.objectId) return { status: 'error', message: 'This user not allowed!' }; + if (!c.data || !c.data.objectId) return { status: 'error', message: 'This user not allowed!' }; { var a, t, s, - c = JSON.stringify({ objectId: e }); + p = JSON.stringify({ objectId: e }); let r, i; i = e - ? (a = await axios.get(serverUrl + '/classes/contracts_Contactbook?where=' + c, { + ? (a = await axios.get(serverUrl + '/classes/contracts_Contactbook?where=' + p, { headers: { 'X-Parse-Application-Id': APPID, 'X-Parse-Session-Token': o.headers.sessiontoken, }, })).data && 0 < a.data.results.length ? ((r = a), 'contracts_Contactbook') - : ((r = await axios.get(serverUrl + '/classes/contracts_Users?where=' + c, { + : ((r = await axios.get(serverUrl + '/classes/contracts_Users?where=' + p, { headers: { 'X-Parse-Application-Id': APPID, 'X-Parse-Master-Key': masterKEY }, })), 'contracts_Users') : ((t = JSON.stringify({ - UserId: { __type: 'Pointer', className: '_User', objectId: l.data.objectId }, + UserId: { __type: 'Pointer', className: '_User', objectId: c.data.objectId }, })), (s = await axios.get(serverUrl + '/classes/contracts_Users?where=' + t, { headers: { 'X-Parse-Application-Id': APPID, 'X-Parse-Master-Key': masterKEY }, @@ -183,13 +223,13 @@ async function PDF(o) { }, })), 'contracts_Contactbook')); - var p = r.data.results[0].Name, - m = r.data.results[0].Email; + var m = r.data.results[0].Name, + g = r.data.results[0].Email; if (!o.params.pdfFile) return { status: 'error', message: 'Pdf file not present!' }; { let e = Buffer.from(o.params.pdfFile, 'base64'); - var g = process.env.PFX_BASE64, - u = Buffer.from(g, 'base64'), + var u = process.env.PFX_BASE64, + h = Buffer.from(u, 'base64'), f = { UserPtr: { __type: 'Pointer', className: i, objectId: r.data.results[0].objectId }, SignedUrl: '', @@ -197,104 +237,96 @@ async function PDF(o) { ipAddress: o.headers['x-real-ip'], }; let a; - var h = (a = + var P = (a = d.data.AuditTrail && 0 < d.data.AuditTrail.length ? [...d.data.AuditTrail, f] : [f]).filter(e => 'Signed' === e.Activity); let t = !1; !( - (d.data.Signers && 0 < d.data.Signers.length && h.length !== d.data.Signers.length) || + (d.data.Signers && 0 < d.data.Signers.length && P.length !== d.data.Signers.length) || !(t = !0) ); - var P, - y, + var y, + b, v, U, - b, I, - w = `exported_file_${Math.floor(5e3 * Math.random())}.pdf`, - A = './exports/' + w; + w, + D = `exported_file_${Math.floor(5e3 * Math.random())}.pdf`, + S = './exports/' + D; let s = e.length; s = ( t - ? ((P = d.data.Signers?.map(e => e.Name + ' <' + e.Email + '>')), + ? ((y = d.data.Signers?.map(e => e.Name + ' <' + e.Email + '>')), (e = - P && 0 < P.length - ? ((y = await PDFDocument.load(e)), + y && 0 < y.length + ? ((b = await PDFDocument.load(e)), pdflibAddPlaceholder({ - pdfDoc: y, - reason: 'Digitally signed by OpenSign for ' + P?.join(', '), + pdfDoc: b, + reason: 'Digitally signed by OpenSign for ' + y?.join(', '), location: 'n/a', signatureLength: 15e3, }), - (v = await y.save()), + (v = await b.save()), Buffer.from(v)) : ((U = await PDFDocument.load(e)), pdflibAddPlaceholder({ pdfDoc: U, - reason: 'Digitally signed by OpenSign for ' + p + ' <' + m + '>', + reason: 'Digitally signed by OpenSign for ' + m + ' <' + g + '>', location: 'n/a', signatureLength: 15e3, }), - (b = await U.save()), - Buffer.from(b))), - (I = await new SignPDF(e, u).signPDF()), - fs.writeFileSync(A, I), - I) - : (fs.writeFileSync(A, e), e) + (I = await U.save()), + Buffer.from(I))), + (w = await new SignPDF(e, h).signPDF()), + fs.writeFileSync(S, w), + w) + : (fs.writeFileSync(S, e), e) ).length; - var D, - S, + var _, + A, x, E, - _, j, k, F, + C, T, - N, - C = await uploadFile(w, A); - if (C && C.imageUrl) + N = await uploadFile(D, S); + if (N && N.imageUrl) return ( - (D = await updateDoc( + (_ = await updateDoc( o.params.docId, - C.imageUrl, + N.imageUrl, r.data.results[0].objectId, o.headers['x-real-ip'], d.data, i )), - sendDoctoWebhook(d, C.imageUrl, 'signed', r?.data.results?.[0]), - saveFileUsage(s, C.imageUrl, l.data.objectId), - D && - D.isCompleted && - ((S = { - url: C.imageUrl, - sender: { Mail: d.data.ExtUserPtr.Email, Name: 'OpenSign™' }, - pdfName: d.data.Name, - receiver: d.data.ExtUserPtr.Email, - extUserId: d.data.ExtUserPtr.objectId, - }), - (x = { ...d.data, AuditTrail: D.AuditTrail }), - (E = await GenerateCertificate(x)), - (_ = await PDFDocument.load(E)), + sendDoctoWebhook(d, N.imageUrl, 'signed', r?.data.results?.[0]), + saveFileUsage(s, N.imageUrl, c.data.objectId), + _ && + _.isCompleted && + ((A = { ...d.data, AuditTrail: _.AuditTrail }), + (x = await GenerateCertificate(A)), + (E = await PDFDocument.load(x)), pdflibAddPlaceholder({ - pdfDoc: _, + pdfDoc: E, reason: 'Digitally signed by OpenSign.', location: 'n/a', signatureLength: 15e3, }), - (j = await _.save()), + (j = await E.save()), (k = Buffer.from(j)), - (F = await new SignPDF(k, u).signPDF()), + (F = await new SignPDF(k, h).signPDF()), fs.writeFileSync('./exports/certificate.pdf', F), - (N = { - CertificateUrl: (T = await uploadFile( + (T = { + CertificateUrl: (C = await uploadFile( 'certificate.pdf', './exports/certificate.pdf' )).imageUrl, }), - await axios.put(serverUrl + '/classes/contracts_Document/' + n, N, { + await axios.put(serverUrl + '/classes/contracts_Document/' + n, T, { headers: { 'Content-Type': 'application/json', 'X-Parse-Application-Id': APPID, @@ -303,13 +335,13 @@ async function PDF(o) { }), d.data.IsSendMail && !1 === d.data.IsSendMail ? console.log("don't send mail") - : sendCompletedMail(S), - saveFileUsage(k.length, T.imageUrl, l.data.objectId), - sendDoctoWebhook(d, C.imageUrl, 'completed')), - fs.unlinkSync(A), - console.log('New Signed PDF created called: ' + A), - 'success' === D.message - ? { status: 'success', data: C.imageUrl } + : sendCompletedMail({ url: N.imageUrl, isCustomMail: l, doc: d.data }), + saveFileUsage(k.length, C.imageUrl, c.data.objectId), + sendDoctoWebhook(d, N.imageUrl, 'completed')), + fs.unlinkSync(S), + console.log('New Signed PDF created called: ' + S), + 'success' === _.message + ? { status: 'success', data: N.imageUrl } : { status: 'error', message: 'Please provide required parameters!' } ); }