Finalize self hosted with self certificate, resolve webhook issues.
This commit is contained in:
@@ -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",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user