Finalize self hosted with self certificate, resolve webhook issues.

This commit is contained in:
Patrick Fic
2026-04-20 09:49:48 -07:00
parent 969dd8be8d
commit cc48448a07
12 changed files with 236 additions and 44 deletions

View File

@@ -3,10 +3,11 @@ const { Documenso } = require("@documenso/sdk-typescript");
const axios = require("axios");
const { jsrAuthString } = require("../utils/utils");
const logger = require("../utils/logger");
const DOCUMENSO_API_KEY = "api_asojim0czruv13ud";//Done on a by team basis,
//Need to pull the key dynamically to send documents.
const DOCUMENSO_API_KEY = "api_io2lssosg9v4p2mb";//Done on a by team basis,
const documenso = new Documenso({
apiKey: DOCUMENSO_API_KEY,//Done on a by team basis,
serverURL: "https://stg-app.documenso.com/api/v2",
serverURL: "https://sign.imex.online/api/v2",
});
const JSR_SERVER = "https://reports.test.imex.online";
const jsreport = require("@jsreport/nodejs-client");
@@ -216,9 +217,9 @@ async function newEsignDocument(req, res) {
catch (error) {
logger.log(`esig-new-error`, "ERROR", "esig", "api", {
message: error.message, stack: error.stack,
body: req.body
body: _.omit(req.body, ["bodyshop"]) // bodyshop can be large, so we omit it from the logs
});
res.status(500).json({ error: "An error occurred while creating the e-sign document." });
res.status(500).json({ error: "An error occurred while creating the e-sign document.", message: error.message });
}
}

View File

@@ -7,8 +7,8 @@ const { log } = require("node-persist");
const client = require('../graphql-client/graphql-client').client;
const documenso = new Documenso({
apiKey: "api_asojim0czruv13ud",//Done on a by team basis,
serverURL: "https://stg-app.documenso.com/api/v2",
apiKey: "api_io2lssosg9v4p2mb",// Centralize key and pull dynamically.
serverURL: "https://sign.imex.online/api/v2",
});
const webhookTypeEnums = {
@@ -22,7 +22,6 @@ const webhookTypeEnums = {
}
async function esignWebhook(req, res) {
console.log("Esign Webhook Received:", req.body);
try {
const message = req.body
logger.log(`esig-webhook-received`, "DEBUG", "redis", "api", {
@@ -30,11 +29,12 @@ async function esignWebhook(req, res) {
body: message
});
const documentId = (message.payload?.id || message.payload?.payload?.id)?.toString()
//TODO: Implement checks to prevent this from going backwards in status? If a request fails, it retries, which could cause a document marked as completed to be marked as rejected if the rejection event is processed after the completion event.
switch (message.event) {
case webhookTypeEnums.DOCUMENT_OPENED:
await client.request(UPDATE_ESIGNATURE_DOCUMENT, {
external_document_id: message.payload?.payload?.id?.toString(),
external_document_id: documentId,
esig_update: {
status: "OPENED",
opened: true,
@@ -43,7 +43,7 @@ async function esignWebhook(req, res) {
break;
case webhookTypeEnums.DOCUMENT_REJECTED:
await client.request(UPDATE_ESIGNATURE_DOCUMENT, {
external_document_id: message.payload?.payload?.id?.toString(),
external_document_id: documentId,
esig_update: {
status: "REJECTED",
rejected: true,
@@ -52,19 +52,19 @@ async function esignWebhook(req, res) {
break;
case webhookTypeEnums.DOCUMENT_CREATED:
//This is largely a throwaway event we know it was created.
console.log("Document created event received. Document ID:", message.payload?.payload?.documentId);
console.log("Document created event received. Document ID:", documentId);
// Here you can add any additional processing you want to do when a document is created
break;
case webhookTypeEnums.DOCUMENT_COMPLETED:
console.log("Document completed event received. Document ID:", message.payload?.payload?.documentId);
console.log("Document completed event received. Document ID:", documentId);
await handleDocumentCompleted(message.payload);
// Here you can add any additional processing you want to do when a document is completed
break;
case webhookTypeEnums.DOCUMENT_SIGNED:
console.log("Document signed event received. Document ID:", message.payload?.payload?.documentId);
console.log("Document signed event received. Document ID:", documentId);
// Here you can add any additional processing you want to do when a document is signed
await client.request(UPDATE_ESIGNATURE_DOCUMENT, {
external_document_id: message.payload?.payload?.id?.toString(),
external_document_id: documentId,
esig_update: {
status: "SIGNED",
}