Fetch documenso key dynamically and clean up. Update to 2.9.1 in terraform.
This commit is contained in:
@@ -414,5 +414,6 @@ module.exports = {
|
||||
newCustomEsignDocument,
|
||||
distributeDocument,
|
||||
deleteDocument,
|
||||
viewDocument
|
||||
viewDocument,
|
||||
getDocumensoClient
|
||||
}
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
|
||||
const { Documenso } = require("@documenso/sdk-typescript");
|
||||
const logger = require("../utils/logger");
|
||||
const { QUERY_META_FOR_ESIG_COMPLETION, INSERT_ESIGNATURE_COMPLETED_DOCOUMENT, UPDATE_ESIGNATURE_DOCUMENT, DISTRIBUTE_ESIGNATURE_DOCUMENT } = require("../graphql-client/queries");
|
||||
const { QUERY_META_FOR_ESIG_COMPLETION, INSERT_ESIGNATURE_COMPLETED_DOCOUMENT, UPDATE_ESIGNATURE_DOCUMENT, DISTRIBUTE_ESIGNATURE_DOCUMENT, QUERY_DOCUMENSO_KEY, GET_DOCUMENSO_KEY_BY_JOBID } = require("../graphql-client/queries");
|
||||
const { uploadFileBuffer } = require("../media/imgproxy-media");
|
||||
|
||||
const client = require('../graphql-client/graphql-client').client;
|
||||
const documenso = new Documenso({
|
||||
apiKey: "api_io2lssosg9v4p2mb",// Centralize key and pull dynamically.
|
||||
serverURL: "https://sign.imex.online/api/v2",
|
||||
});
|
||||
|
||||
const webhookTypeEnums = {
|
||||
DOCUMENT_CREATED: "DOCUMENT_CREATED",
|
||||
@@ -32,6 +28,7 @@ async function esignWebhook(req, res) {
|
||||
//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:
|
||||
//TODO: DR: Add notification for document opened.
|
||||
await client.request(UPDATE_ESIGNATURE_DOCUMENT, {
|
||||
external_document_id: documentId,
|
||||
esig_update: {
|
||||
@@ -51,16 +48,14 @@ 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:", 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:", documentId);
|
||||
//TODO: DR: Add notification for document completed.
|
||||
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:", 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: documentId,
|
||||
@@ -98,6 +93,17 @@ async function handleDocumentCompleted(payload) {
|
||||
const { jobs_by_pk } = await client.request(QUERY_META_FOR_ESIG_COMPLETION, {
|
||||
jobid
|
||||
});
|
||||
|
||||
//Have to use globally authed cleint since this a webhook.
|
||||
const { jobs_by_pk: { bodyshop: { documenso_api_key } } } = await client.request(GET_DOCUMENSO_KEY_BY_JOBID, {
|
||||
jobid,
|
||||
|
||||
})
|
||||
const documenso = new Documenso({
|
||||
apiKey: documenso_api_key,
|
||||
serverURL: "https://sign.imex.online/api/v2",
|
||||
});
|
||||
|
||||
const document = await documenso.document.documentDownload({
|
||||
documentId: payload.id,
|
||||
});
|
||||
|
||||
@@ -3345,4 +3345,14 @@ exports.QUERY_DOCUMENSO_KEY = `query QUERY_DOCUMENTS_KEY($bodyshopid: uuid!) {
|
||||
documenso_api_key
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
exports.GET_DOCUMENSO_KEY_BY_JOBID = `query GET_DOCUMENSO_KEY_BY_JOBID($jobid: uuid!) {
|
||||
jobs_by_pk(id: $jobid) {
|
||||
id
|
||||
bodyshop {
|
||||
documenso_api_key
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
Reference in New Issue
Block a user