Merged in release/2026-05-22 (pull request #3245)

Release/2026 05 22
This commit is contained in:
Dave Richer
2026-05-13 16:10:49 +00:00
63 changed files with 15881 additions and 184 deletions

5
.gitignore vendored
View File

@@ -149,3 +149,8 @@ docker_data
/COPILOT.md
/.github/copilot-instructions.md
/GEMINI.md
/_reference/select-component-test-plan.md
.terraform
terraform.tfvars

File diff suppressed because it is too large Load Diff

View File

@@ -16,6 +16,7 @@
"@dnd-kit/modifiers": "^9.0.0",
"@dnd-kit/sortable": "^10.0.0",
"@dnd-kit/utilities": "^3.2.2",
"@documenso/embed-react": "^0.5.1",
"@emotion/is-prop-valid": "^1.4.0",
"@fingerprintjs/fingerprintjs": "^5.1.0",
"@firebase/analytics": "^0.10.21",
@@ -2593,6 +2594,16 @@
"react": ">=16.8.0"
}
},
"node_modules/@documenso/embed-react": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/@documenso/embed-react/-/embed-react-0.5.1.tgz",
"integrity": "sha512-PlkZ3vrdZVBTc0J3xfG2wtPVGmxCxWgpQ/SsdR2oBMdTwsR+rDbj9k+CeTv+M9Xi5tKbLr5Y78bS9Sb8K+ltTQ==",
"license": "MIT",
"peerDependencies": {
"react": "^18.0.0 || ^19.0.0",
"react-dom": "^18.0.0 || ^19.0.0"
}
},
"node_modules/@dotenvx/dotenvx": {
"version": "1.59.1",
"resolved": "https://registry.npmjs.org/@dotenvx/dotenvx/-/dotenvx-1.59.1.tgz",

View File

@@ -15,6 +15,7 @@
"@dnd-kit/modifiers": "^9.0.0",
"@dnd-kit/sortable": "^10.0.0",
"@dnd-kit/utilities": "^3.2.2",
"@documenso/embed-react": "^0.5.1",
"@emotion/is-prop-valid": "^1.4.0",
"@fingerprintjs/fingerprintjs": "^5.1.0",
"@firebase/analytics": "^0.10.21",

View File

@@ -509,3 +509,10 @@
pointer-events: none !important;
}
}
.esignature-embed {
width: 100%;
height: 100%;
border-width: 0;
}

View File

@@ -4,6 +4,7 @@ import i18n from "i18next";
import { logImEXEvent } from "../../firebase/firebase.utils";
import { INSERT_NEW_DOCUMENT } from "../../graphql/documents.queries";
import { axiosAuthInterceptorId } from "../../utils/CleanAxios";
import { replaceAccents } from "../../utils/replaceAccents.js";
import client from "../../utils/GraphQLClient";
//Context: currentUserEmail, bodyshop, jobid, invoiceid
@@ -144,32 +145,3 @@ export const uploadToS3 = async (
if (onError) onError(JSON.stringify(error.message));
}
};
function replaceAccents(str) {
// Verifies if the String has accents and replace them
if (str.search(/[\xC0-\xFF]/g) > -1) {
str = str
.replace(/[\xC0-\xC5]/g, "A")
.replace(/[\xC6]/g, "AE")
.replace(/[\xC7]/g, "C")
.replace(/[\xC8-\xCB]/g, "E")
.replace(/[\xCC-\xCF]/g, "I")
.replace(/[\xD0]/g, "D")
.replace(/[\xD1]/g, "N")
.replace(/[\xD2-\xD6\xD8]/g, "O")
.replace(/[\xD9-\xDC]/g, "U")
.replace(/[\xDD]/g, "Y")
.replace(/[\xDE]/g, "P")
.replace(/[\xE0-\xE5]/g, "a")
.replace(/[\xE6]/g, "ae")
.replace(/[\xE7]/g, "c")
.replace(/[\xE8-\xEB]/g, "e")
.replace(/[\xEC-\xEF]/g, "i")
.replace(/[\xF1]/g, "n")
.replace(/[\xF2-\xF6\xF8]/g, "o")
.replace(/[\xF9-\xFC]/g, "u")
.replace(/[\xFE]/g, "p")
.replace(/[\xFD\xFF]/g, "y");
}
return str;
}

View File

@@ -0,0 +1,92 @@
import { UploadOutlined } from "@ant-design/icons";
import { Button, Upload } from "antd";
import axios from "axios";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { useNotification } from "../../contexts/Notifications/notificationContext.jsx";
import { setModalContext } from "../../redux/modals/modals.actions";
import { selectBodyshop } from "../../redux/user/user.selectors";
import { hasDocumensoApiKey } from "../../utils/esignature.js";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop
});
const mapDispatchToProps = (dispatch) => ({
setEsignatureContext: (context) =>
dispatch(
setModalContext({
context,
modal: "esignature"
})
)
});
export function EsignatureCustomDocument({ bodyshop, jobId, setEsignatureContext }) {
const [loading, setLoading] = useState(false);
const notification = useNotification();
const { t } = useTranslation();
if (!hasDocumensoApiKey(bodyshop)) {
return null;
}
const uploadCustomDocument = async ({ file, onError, onSuccess }) => {
const formData = new FormData();
formData.append("document", file);
formData.append("jobid", jobId);
formData.append("bodyshop", JSON.stringify(bodyshop));
setLoading(true);
try {
const {
data: { token, documentId, envelopeId }
} = await axios.post("/esign/new-custom", formData, {
headers: {
"Content-Type": "multipart/form-data"
}
});
setEsignatureContext({ context: { token, documentId, envelopeId, jobid: jobId } });
onSuccess?.({ token, documentId, envelopeId });
} catch (error) {
notification.error({
title: t("esignature.errors.upload_title"),
description: error?.response?.data?.error || error?.response?.data?.message || error.message
});
onError?.(error);
} finally {
setLoading(false);
}
};
return (
<Upload
accept="application/pdf,.pdf"
beforeUpload={(file) => {
if (file.type === "application/pdf" || file.name?.toLowerCase().endsWith(".pdf")) {
return true;
}
notification.error({
title: t("esignature.errors.upload_title"),
description: t("esignature.errors.pdf_only")
});
return Upload.LIST_IGNORE;
}}
customRequest={uploadCustomDocument}
maxCount={1}
showUploadList={false}
multiple={false}
>
<Button icon={<UploadOutlined />} loading={loading}>
{t("esignature.actions.upload_document")}
</Button>
</Upload>
);
}
export default connect(mapStateToProps, mapDispatchToProps)(EsignatureCustomDocument);

View File

@@ -0,0 +1,101 @@
import { EmbedUpdateDocumentV1 } from "@documenso/embed-react";
import { Modal, notification, Result } from "antd";
import axios from "axios";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { toggleModalVisible } from "../../redux/modals/modals.actions";
import { selectEsignature } from "../../redux/modals/modals.selectors";
import { selectBodyshop, selectCurrentUser } from "../../redux/user/user.selectors";
import { useState } from "react";
import InstanceRenderManager from "../../utils/instanceRenderMgr";
import { hasDocumensoApiKey } from "../../utils/esignature.js";
const mapStateToProps = createStructuredSelector({
esignatureModal: selectEsignature,
bodyshop: selectBodyshop,
currentUser: selectCurrentUser
});
const mapDispatchToProps = (dispatch) => ({
toggleModalVisible: () => dispatch(toggleModalVisible("esignature"))
});
export function EsignatureModalContainer({ esignatureModal, toggleModalVisible, bodyshop, currentUser }) {
const { t } = useTranslation();
const { open, context } = esignatureModal;
const { token, envelopeId, documentId, jobid } = context;
const [distributing, setDistributing] = useState(false);
if (!hasDocumensoApiKey(bodyshop)) {
return null;
}
return (
<Modal
open={open}
title={InstanceRenderManager({
imex: t("jobs.labels.esignature_imex"),
rome: t("jobs.labels.esignature_rome")
})}
onOk={async () => {
try {
setDistributing(true);
await axios.post("/esign/distribute", {
documentId,
envelopeId,
jobid,
bodyshopid: bodyshop.id
});
toggleModalVisible();
} catch (error) {
notification.error({
message: t("esignature.distribute_error"),
description: error?.response?.data?.message || error.message
});
}
setDistributing(false);
}}
onCancel={async () => {
try {
await axios.post("/esign/delete", {
documentId,
envelopeId,
bodyshopid: bodyshop.id
});
toggleModalVisible();
} catch (error) {
notification.error({
message: t("esignature.cancel_error"),
description: error?.response?.data?.message || error.message
});
}
}}
okButtonProps={{ loading: distributing }}
okText={t("esignature.actions.distribute")}
destroyOnHidden
width={"80%"}
>
<div style={{ height: "80vh", width: "100%" }}>
{token ? (
<EmbedUpdateDocumentV1
presignToken={token}
host="https://sign.imex.online"
documentId={documentId}
externalId={`${jobid}|${currentUser?.email}`}
className="esignature-embed"
onDocumentUpdated={(data) => {
console.log("Document updated:", data);
}}
/>
) : (
<Result status="warning" title={t("esignature.errors.no_token")} />
)}
</div>
</Modal>
);
}
export default connect(mapStateToProps, mapDispatchToProps)(EsignatureModalContainer);

View File

@@ -1,6 +1,6 @@
import { SyncOutlined } from "@ant-design/icons";
import { useQuery } from "@apollo/client/react";
import { Button, Card, Col, Row, Tag } from "antd";
import { Button, Card, Checkbox, Col, Row, Space, Tag } from "antd";
import ResponsiveTable from "../responsive-table/responsive-table.component";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
@@ -12,6 +12,9 @@ import { DateTimeFormatter } from "../../utils/DateFormatter";
import BlurWrapperComponent from "../feature-wrapper/blur-wrapper.component";
import { HasFeatureAccess } from "../feature-wrapper/feature-wrapper.component";
import UpsellComponent, { upsellEnum } from "../upsell/upsell.component";
import axios from "axios";
import { useNotification } from "../../contexts/Notifications/notificationContext";
import { hasDocumensoApiKey } from "../../utils/esignature.js";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop
@@ -23,6 +26,8 @@ export default connect(mapStateToProps, mapDispatchToProps)(JobAuditTrail);
export function JobAuditTrail({ bodyshop, jobId }) {
const { t } = useTranslation();
const notification = useNotification();
const esignatureEnabled = hasDocumensoApiKey(bodyshop);
const { loading, data, refetch } = useQuery(QUERY_AUDIT_TRAIL, {
variables: { jobid: jobId },
skip: !jobId,
@@ -53,6 +58,145 @@ export function JobAuditTrail({ bodyshop, jobId }) {
)
}
];
const esigColumns = [
{
title: t("esignature.fields.created_at"),
dataIndex: "created_at",
key: "created_at",
render: (text) => <DateTimeFormatter>{text}</DateTimeFormatter>
},
{
title: t("esignature.fields.updated_at"),
dataIndex: "updated_at",
key: "updated_at",
render: (text) => <DateTimeFormatter>{text}</DateTimeFormatter>
},
{
title: t("esignature.fields.title"),
dataIndex: "title",
key: "title",
render: (text) => (
<BlurWrapperComponent featureName="audit" bypass>
<div>{text}</div>
</BlurWrapperComponent>
)
},
{
title: t("esignature.fields.external_document_id"),
dataIndex: "external_document_id",
key: "external_document_id",
render: (text) => (
<BlurWrapperComponent featureName="audit" bypass>
<div>{text}</div>
</BlurWrapperComponent>
)
},
{
title: t("esignature.fields.status"),
dataIndex: "status",
key: "status",
render: (text) => (
<BlurWrapperComponent featureName="audit" bypass>
<div>{text}</div>
</BlurWrapperComponent>
)
},
{
title: t("esignature.fields.opened"),
dataIndex: "opened",
key: "opened",
render: (text) => <Checkbox checked={text} disabled />
},
{
title: t("esignature.fields.rejected"),
dataIndex: "rejected",
key: "rejected",
render: (text) => <Checkbox checked={text} disabled />
},
{
title: t("esignature.fields.completed"),
dataIndex: "completed",
key: "completed",
render: (text) => <Checkbox checked={text} disabled />
},
{
title: t("esignature.fields.completed_at"),
dataIndex: "completed_at",
key: "completed_at",
render: (text) => <DateTimeFormatter>{text}</DateTimeFormatter>
},
{
title: t("general.labels.actions"),
dataIndex: "actions",
key: "actions",
render: (_text, record) => (
<Space wrap>
<Button
disabled={record.completed_at !== null || record.status === "REJECTED"}
onClick={async () => {
logImEXEvent("job_esig_delete", {});
try {
await axios.post("/esign/delete", {
documentId: record.external_document_id,
bodyshopid: bodyshop.id
});
refetch();
} catch (error) {
console.error("Error deleting document:", error?.response?.data || error.message);
notification.error({
message: t("esignature.delete_error"),
description: error?.response?.data?.error || error.message
});
}
}}
>
{t("esignature.actions.delete")}
</Button>
<Button
onClick={async () => {
logImEXEvent("job_esig_redistribute", {});
try {
await axios.post("/esign/redistribute", {
documentId: record.external_document_id,
bodyshopid: bodyshop.id
});
//Pop the success notification. Possible audit requery required.
} catch (error) {
console.error("Error viewing document:", error?.response?.data || error.message);
notification.error({
message: t("esignature.view_error"),
description: error?.response?.data?.message || error.message
});
}
}}
>
{t("esignature.actions.redistribute")}
</Button>
<Button
onClick={async () => {
logImEXEvent("job_esig_view", {});
try {
const response = await axios.post("/esign/view", {
documentId: record.external_document_id,
bodyshopid: bodyshop.id
});
window.open(response.data?.document?.downloadUrl, "_blank");
} catch (error) {
console.error("Error viewing document:", error?.response?.data || error.message);
notification.error({
message: t("esignature.view_error"),
description: error?.response?.data?.message || error.message
});
}
}}
>
{t("esignature.actions.view")}
</Button>
</Space>
)
}
];
const emailColumns = [
{
title: t("audit.fields.created"),
@@ -184,6 +328,20 @@ export function JobAuditTrail({ bodyshop, jobId }) {
/>
</Card>
</Col>
{esignatureEnabled && (
<Col span={24}>
<Card title={t("jobs.labels.esignatures")}>
<ResponsiveTable
loading={loading}
columns={esigColumns}
mobileColumnKeys={["title", "status"]}
rowKey="id"
scroll={{ x: true }}
dataSource={data ? data.esignature_documents : []}
/>
</Card>
</Col>
)}
</Row>
);
}

View File

@@ -1,4 +1,3 @@
import { notificationScenarios } from "../../utils/jobNotificationScenarios.js";
import { Checkbox, Form } from "antd";
import { useTranslation } from "react-i18next";
import PropTypes from "prop-types";
@@ -9,18 +8,18 @@ import PropTypes from "prop-types";
* @param form
* @param disabled
* @param onHeaderChange
* @param scenarioKeys
* @returns {JSX.Element}
* @constructor
*/
const ColumnHeaderCheckbox = ({ channel, form, disabled = false, onHeaderChange }) => {
const ColumnHeaderCheckbox = ({ channel, form, disabled = false, onHeaderChange, scenarioKeys }) => {
const { t } = useTranslation();
// Subscribe to all form values so that this component re-renders on changes.
const formValues = Form.useWatch([], form) || {};
// Determine if all scenarios for this channel are checked.
const allChecked =
notificationScenarios.length > 0 && notificationScenarios.every((scenario) => formValues[scenario]?.[channel]);
const allChecked = scenarioKeys.length > 0 && scenarioKeys.every((scenario) => formValues[scenario]?.[channel]);
const onChange = (e) => {
const checked = e.target.checked;
@@ -28,7 +27,7 @@ const ColumnHeaderCheckbox = ({ channel, form, disabled = false, onHeaderChange
const currentValues = form.getFieldsValue();
// Update each scenario for this channel.
const newValues = { ...currentValues };
notificationScenarios.forEach((scenario) => {
scenarioKeys.forEach((scenario) => {
newValues[scenario] = { ...newValues[scenario], [channel]: checked };
});
// Update form values.
@@ -50,7 +49,8 @@ ColumnHeaderCheckbox.propTypes = {
channel: PropTypes.oneOf(["app", "email", "fcm"]).isRequired,
form: PropTypes.object.isRequired,
disabled: PropTypes.bool,
onHeaderChange: PropTypes.func
onHeaderChange: PropTypes.func,
scenarioKeys: PropTypes.arrayOf(PropTypes.string).isRequired
};
export default ColumnHeaderCheckbox;

View File

@@ -12,12 +12,13 @@ import {
UPDATE_NOTIFICATION_SETTINGS,
UPDATE_NOTIFICATIONS_AUTOADD
} from "../../graphql/user.queries.js";
import { notificationScenarios } from "../../utils/jobNotificationScenarios.js";
import { getNotificationScenarios, notificationScenarioDefaults } from "../../utils/jobNotificationScenarios.js";
import LoadingSpinner from "../loading-spinner/loading-spinner.component.jsx";
import PropTypes from "prop-types";
import { useNotification } from "../../contexts/Notifications/notificationContext.jsx";
import ColumnHeaderCheckbox from "../notification-settings/column-header-checkbox.component.jsx";
import { useIsEmployee } from "../../utils/useIsEmployee.js";
import { hasDocumensoApiKey } from "../../utils/esignature.js";
/**
* Notifications Settings Form
@@ -35,6 +36,7 @@ const NotificationSettingsForm = ({ currentUser, bodyshop }) => {
const [initialAutoAdd, setInitialAutoAdd] = useState(false);
const notification = useNotification();
const isEmployee = useIsEmployee(bodyshop, currentUser);
const notificationScenarios = getNotificationScenarios({ includeEsign: hasDocumensoApiKey(bodyshop) });
// Fetch notification settings and notifications_autoadd
const { loading, error, data } = useQuery(QUERY_NOTIFICATION_SETTINGS, {
@@ -55,7 +57,8 @@ const NotificationSettingsForm = ({ currentUser, bodyshop }) => {
// Ensure each scenario has an object with { app, email, fcm }
const formattedValues = notificationScenarios.reduce((acc, scenario) => {
acc[scenario] = settings[scenario] ?? { app: false, email: false, fcm: false };
acc[scenario] = settings[scenario] ??
notificationScenarioDefaults[scenario] ?? { app: false, email: false, fcm: false };
return acc;
}, {});
@@ -65,7 +68,7 @@ const NotificationSettingsForm = ({ currentUser, bodyshop }) => {
setInitialAutoAdd(autoAdd);
setIsDirty(false); // Reset dirty state when new data loads
}
}, [data, form]);
}, [data, form, notificationScenarios]);
// Handle toggle of notifications_autoadd
const handleAutoAddToggle = async (checked) => {
@@ -136,7 +139,14 @@ const NotificationSettingsForm = ({ currentUser, bodyshop }) => {
width: "80%"
},
{
title: <ColumnHeaderCheckbox channel="app" form={form} onHeaderChange={() => setIsDirty(true)} />,
title: (
<ColumnHeaderCheckbox
channel="app"
form={form}
onHeaderChange={() => setIsDirty(true)}
scenarioKeys={notificationScenarios}
/>
),
dataIndex: "app",
key: "app",
align: "center",
@@ -147,7 +157,14 @@ const NotificationSettingsForm = ({ currentUser, bodyshop }) => {
)
},
{
title: <ColumnHeaderCheckbox channel="email" form={form} onHeaderChange={() => setIsDirty(true)} />,
title: (
<ColumnHeaderCheckbox
channel="email"
form={form}
onHeaderChange={() => setIsDirty(true)}
scenarioKeys={notificationScenarios}
/>
),
dataIndex: "email",
key: "email",
align: "center",
@@ -162,7 +179,14 @@ const NotificationSettingsForm = ({ currentUser, bodyshop }) => {
// Currently disabled for prod
if (!import.meta.env.PROD) {
columns.push({
title: <ColumnHeaderCheckbox channel="fcm" form={form} onHeaderChange={() => setIsDirty(true)} />,
title: (
<ColumnHeaderCheckbox
channel="fcm"
form={form}
onHeaderChange={() => setIsDirty(true)}
scenarioKeys={notificationScenarios}
/>
),
dataIndex: "fcm",
key: "fcm",
align: "center",

View File

@@ -1,4 +1,4 @@
import { MailOutlined, PrinterOutlined } from "@ant-design/icons";
import { MailOutlined, PrinterOutlined, SignatureFilled } from "@ant-design/icons";
import { Space, Spin } from "antd";
import { useState } from "react";
import { connect } from "react-redux";
@@ -10,6 +10,9 @@ import { GenerateDocument } from "../../utils/RenderTemplate";
import LockWrapperComponent from "../lock-wrapper/lock-wrapper.component";
import { HasFeatureAccess } from "./../feature-wrapper/feature-wrapper.component";
import { useNotification } from "../../contexts/Notifications/notificationContext.jsx";
import axios from "axios";
import { setModalContext } from "../../redux/modals/modals.actions.js";
import { hasDocumensoApiKey } from "../../utils/esignature.js";
const mapStateToProps = createStructuredSelector({
printCenterModal: selectPrintCenter,
@@ -17,12 +20,29 @@ const mapStateToProps = createStructuredSelector({
technician: selectTechnician
});
const mapDispatchToProps = () => ({});
const mapDispatchToProps = (dispatch) => ({
setEsignatureContext: (context) =>
dispatch(
setModalContext({
context: context,
modal: "esignature"
})
)
});
export function PrintCenterItemComponent({ printCenterModal, item, id, bodyshop, disabled, technician }) {
export function PrintCenterItemComponent({
printCenterModal,
setEsignatureContext,
item,
id,
bodyshop,
disabled,
technician
}) {
const [loading, setLoading] = useState(false);
const { context } = printCenterModal;
const notification = useNotification();
const esignatureEnabled = hasDocumensoApiKey(bodyshop);
const renderToNewWindow = async () => {
setLoading(true);
@@ -39,6 +59,30 @@ export function PrintCenterItemComponent({ printCenterModal, item, id, bodyshop,
setLoading(false);
};
const esignatureGenerate = async () => {
setLoading(true);
try {
const {
data: { token, documentId, envelopeId }
} = await axios.post("/esign/new", {
name: item.key,
jobid: id,
context,
bodyshop,
templateObject: {
name: item.key,
variables: { id: id }
}
});
setEsignatureContext({ context: { token, documentId, envelopeId, jobid: id } });
} catch (error) {
console.log(error);
} finally {
setLoading(false);
}
};
if (
disabled ||
(item.featureNameRestricted && !HasFeatureAccess({ featureName: item.featureNameRestricted, bodyshop }))
@@ -54,6 +98,7 @@ export function PrintCenterItemComponent({ printCenterModal, item, id, bodyshop,
<li>
<Space wrap>
{item.title}
{esignatureEnabled && <SignatureFilled onClick={esignatureGenerate} />}
<PrinterOutlined onClick={renderToNewWindow} />
{!technician ? (
<MailOutlined

View File

@@ -9,11 +9,13 @@ import { selectPrintCenter } from "../../redux/modals/modals.selectors";
import { selectBodyshop } from "../../redux/user/user.selectors";
import { TemplateList } from "../../utils/TemplateConstants";
import Jobd3RdPartyModal from "../job-3rd-party-modal/job-3rd-party-modal.component";
import EsignatureCustomDocument from "../esignature-custom-document/esignature-custom-document.component";
import PrintCenterItem from "../print-center-item/print-center-item.component";
import PrintCenterJobsLabels from "../print-center-jobs-labels/print-center-jobs-labels.component";
import PrintCenterSpeedPrint from "../print-center-speed-print/print-center-speed-print.component";
import { bodyshopHasDmsKey, DMS_MAP, getDmsMode } from "../../utils/dmsUtils";
import { selectTechnician } from "../../redux/tech/tech.selectors";
import { hasDocumensoApiKey } from "../../utils/esignature.js";
const mapStateToProps = createStructuredSelector({
printCenterModal: selectPrintCenter,
@@ -38,6 +40,7 @@ export function PrintCenterJobsComponent({ printCenterModal, bodyshop, technicia
const hasDMSKey = bodyshopHasDmsKey(bodyshop);
const dmsMode = getDmsMode(bodyshop, "off");
const isReynoldsMode = dmsMode === DMS_MAP.reynolds;
const esignatureEnabled = hasDocumensoApiKey(bodyshop);
const Templates = !hasDMSKey
? Object.keys(tempList)
@@ -64,7 +67,7 @@ export function PrintCenterJobsComponent({ printCenterModal, bodyshop, technicia
)
.filter((temp) => !isReynoldsMode || !temp.excludedDmsModes?.includes(dmsMode))
.filter((temp) => !technician || temp.group !== "financial");
const JobsReportsList =
Enhanced_Payroll.treatment === "on"
? Object.keys(Templates)
@@ -97,6 +100,7 @@ export function PrintCenterJobsComponent({ printCenterModal, bodyshop, technicia
extra={
<Space wrap>
<PrintCenterJobsLabels jobId={jobId} />
{esignatureEnabled && <EsignatureCustomDocument jobId={jobId} />}
<Jobd3RdPartyModal jobId={jobId} job={job} />
<Input.Search onChange={(e) => setSearch(e.target.value)} value={search} enterButton />
</Space>

View File

@@ -22,6 +22,23 @@ export const QUERY_AUDIT_TRAIL = gql`
useremail
status
}
esignature_documents(where: {jobid: {_eq: $jobid}}) {
id
created_at
updated_at
jobid
external_document_id
subject
message
title
status
recipients
completed_at
opened
completed
rejected
completed_at
}
}
`;

View File

@@ -53,6 +53,7 @@ export const QUERY_BODYSHOP = gql`
phone
federal_tax_id
id
documenso_api_key
insurance_vendor_id
logo_img_path
md_ro_statuses

View File

@@ -20,6 +20,7 @@ import { FaHardHat, FaRegStickyNote, FaShieldAlt, FaTasks } from "react-icons/fa
import { connect } from "react-redux";
import { useLocation, useNavigate } from "react-router-dom";
import { createStructuredSelector } from "reselect";
import EsignatureCustomDocument from "../../components/esignature-custom-document/esignature-custom-document.component.jsx";
import FormFieldsChanged from "../../components/form-fields-changed-alert/form-fields-changed-alert.component";
import JobAuditTrail from "../../components/job-audit-trail/job-audit-trail.component";
import JobsLinesContainer from "../../components/job-detail-lines/job-lines.container";
@@ -56,6 +57,7 @@ import { selectBodyshop } from "../../redux/user/user.selectors";
import AuditTrailMapping from "../../utils/AuditTrailMappings";
import { DateTimeFormat } from "../../utils/DateFormatter";
import dayjs from "../../utils/day";
import { hasDocumensoApiKey } from "../../utils/esignature.js";
import UndefinedToNull from "../../utils/undefinedtonull";
const mapStateToProps = createStructuredSelector({
@@ -104,6 +106,7 @@ export function JobsDetailPage({
});
const notification = useNotification();
const { scenarioNotificationsOn } = useSocket();
const esignatureEnabled = hasDocumensoApiKey(bodyshop);
useEffect(() => {
//form.setFieldsValue(transormJobToForm(job));
@@ -285,6 +288,7 @@ export function JobsDetailPage({
>
{t("general.labels.refresh")}
</Button>
{esignatureEnabled && <EsignatureCustomDocument jobId={job.id} />}
<JobsChangeStatus job={job} />
<JobSyncButton job={job} />
<Button

View File

@@ -30,6 +30,8 @@ import InstanceRenderManager from "../../utils/instanceRenderMgr.js";
import useAlertsNotifications from "../../hooks/useAlertsNotifications.jsx";
import { selectDarkMode } from "../../redux/application/application.selectors.js";
import { lazyDev } from "../../utils/lazyWithPreload.jsx";
import EsignatureModalContainer from "../../components/esignature-modal/esignature-modal.container.jsx";
import { hasDocumensoApiKey } from "../../utils/esignature.js";
const PrintCenterModalContainer = lazyDev(
() => import("../../components/print-center-modal/print-center-modal.container")
@@ -68,7 +70,9 @@ const FeatureRequestPage = lazyDev(() => import("../feature-request/feature-requ
const JobCostingModal = lazyDev(() => import("../../components/job-costing-modal/job-costing-modal.container"));
const ReportCenterModal = lazyDev(() => import("../../components/report-center-modal/report-center-modal.container"));
const BillEnterModalContainer = lazyDev(() => import("../../components/bill-enter-modal/bill-enter-modal.container"));
const TimeTicketModalContainer = lazyDev(() => import("../../components/time-ticket-modal/time-ticket-modal.container"));
const TimeTicketModalContainer = lazyDev(
() => import("../../components/time-ticket-modal/time-ticket-modal.container")
);
const TimeTicketModalTask = lazyDev(
() => import("../../components/time-ticket-task-modal/time-ticket-task-modal.container")
);
@@ -110,7 +114,9 @@ const TtApprovals = lazyDev(() => import("../tt-approvals/tt-approvals.page.cont
const MyTasksPage = lazyDev(() => import("../tasks/myTasksPageContainer.jsx"));
const AllTasksPage = lazyDev(() => import("../tasks/allTasksPageContainer.jsx"));
const TaskUpsertModalContainer = lazyDev(() => import("../../components/task-upsert-modal/task-upsert-modal.container"));
const TaskUpsertModalContainer = lazyDev(
() => import("../../components/task-upsert-modal/task-upsert-modal.container")
);
const { Content } = Layout;
const mapStateToProps = createStructuredSelector({
@@ -123,6 +129,7 @@ const mapStateToProps = createStructuredSelector({
export function Manage({ conflict, bodyshop, partsManagementOnly, isDarkMode, currentUser }) {
const { t } = useTranslation();
const esignatureEnabled = hasDocumensoApiKey(bodyshop);
const [chatVisible] = useState(false);
const didMount = useRef(false);
@@ -178,6 +185,7 @@ export function Manage({ conflict, bodyshop, partsManagementOnly, isDarkMode, cu
<TaskUpsertModalContainer />
<BreadCrumbs />
<BillEnterModalContainer />
{esignatureEnabled && <EsignatureModalContainer />}
<JobCostingModal />
<ReportCenterModal />
<EmailOverlayContainer />

View File

@@ -27,7 +27,8 @@ const INITIAL_STATE = {
contractFinder: { ...baseModal },
inventoryUpsert: { ...baseModal },
ca_bc_eftTableConvert: { ...baseModal },
cardPayment: { ...baseModal }
cardPayment: { ...baseModal },
esignature: { ...baseModal }
};
const modalsReducer = (state = INITIAL_STATE, action) => {

View File

@@ -36,3 +36,4 @@ export const selectInventoryUpsert = createSelector([selectModals], (modals) =>
export const selectCaBcEtfTableConvert = createSelector([selectModals], (modals) => modals.ca_bc_eftTableConvert);
export const selectCardPayment = createSelector([selectModals], (modals) => modals.cardPayment);
export const selectEsignature = createSelector([selectModals], (modals) => modals.esignature);

View File

@@ -323,14 +323,14 @@
"addtemplate": "Add Template",
"newlaborrate": "New Labor Rate",
"newsalestaxcode": "New Sales Tax Code",
"save_shop_information": "Save Shop Information",
"newstatus": "Add Status",
"save_shop_information": "Save Shop Information",
"testrender": "Test Render"
},
"errors": {
"creatingdefaultview": "Error creating default view.",
"duplicate_job_status": "Duplicate job status. Each job status must be unique.",
"duplicate_insurance_company": "Duplicate insurance company name. Each insurance company name must be unique",
"duplicate_job_status": "Duplicate job status. Each job status must be unique.",
"loading": "Unable to load shop details. Please call technical support.",
"saving": "Error encountered while saving. {{message}}",
"task_preset_allocation_exceeded": "{{laborType}} task preset total is {{total}}% and cannot exceed 100%."
@@ -427,35 +427,6 @@
"logo_img_path": "Shop Logo",
"logo_img_path_height": "Logo Image Height",
"logo_img_path_width": "Logo Image Width",
"scoreboard_setup": {
"daily_body_target": "Daily Body Target",
"daily_paint_target": "Daily Paint Target",
"ignore_blocked_days": "Ignore Blocked Days",
"last_number_working_days": "Last Number of Working Days",
"production_target_hours": "Production Target Hours"
},
"system_settings": {
"auto_email": {
"attach_pdf_to_email": "Attach PDF to Sent Emails?",
"from_emails": "Additional From Emails",
"parts_order_cc": "Parts Orders CC",
"parts_return_slip_cc": "Parts Returns CC"
},
"job_costing": {
"paint_hour_split": "Paint Hour Split",
"paint_materials_hourly_cost_rate": "Paint Materials Hourly Cost Rate",
"prep_hour_split": "Prep Hour Split",
"shop_materials_hourly_cost_rate": "Shop Materials Hourly Cost Rate",
"target_touch_time": "Target Touch Time",
"use_paint_scale_data": "Use Paint Scale Data"
},
"local_media_server": {
"enabled": "Enabled",
"http_path": "HTTP Path",
"network_path": "Network Path",
"token": "Token"
}
},
"md_categories": "Categories",
"md_ccc_rates": "Courtesy Car Contract Rate Presets",
"md_classes": "Classes",
@@ -712,6 +683,13 @@
},
"schedule_end_time": "Schedule Ending Time",
"schedule_start_time": "Schedule Starting Time",
"scoreboard_setup": {
"daily_body_target": "Daily Body Target",
"daily_paint_target": "Daily Paint Target",
"ignore_blocked_days": "Ignore Blocked Days",
"last_number_working_days": "Last Number of Working Days",
"production_target_hours": "Production Target Hours"
},
"shopname": "Shop Name",
"speedprint": {
"id": "Id",
@@ -758,6 +736,28 @@
"production_statuses": "Production Statuses",
"ready_statuses": "Ready Statuses"
},
"system_settings": {
"auto_email": {
"attach_pdf_to_email": "Attach PDF to Sent Emails?",
"from_emails": "Additional From Emails",
"parts_order_cc": "Parts Orders CC",
"parts_return_slip_cc": "Parts Returns CC"
},
"job_costing": {
"paint_hour_split": "Paint Hour Split",
"paint_materials_hourly_cost_rate": "Paint Materials Hourly Cost Rate",
"prep_hour_split": "Prep Hour Split",
"shop_materials_hourly_cost_rate": "Shop Materials Hourly Cost Rate",
"target_touch_time": "Target Touch Time",
"use_paint_scale_data": "Use Paint Scale Data"
},
"local_media_server": {
"enabled": "Enabled",
"http_path": "HTTP Path",
"network_path": "Network Path",
"token": "Token"
}
},
"target_touchtime": "Target Touch Time",
"timezone": "Timezone",
"tt_allow_post_to_invoiced": "Allow Time Tickets to be posted to Invoiced & Exported Jobs",
@@ -777,6 +777,7 @@
"alljobstatuses": "All Job Statuses",
"allopenjobstatuses": "All Open Job Statuses",
"apptcolors": "Appointment Colors",
"autoemail": "Auto Email",
"businessinformation": "Business Information",
"checklists": "Checklists",
"consent_settings": "Phone Number Opt-Out List",
@@ -784,7 +785,6 @@
"customtemplates": "Custom Templates",
"defaultcostsmapping": "Default Costs Mapping",
"defaultprofitsmapping": "Default Profits Mapping",
"dms_setup": "DMS Setup",
"deliverchecklist": "Delivery Checklist",
"dms": {
"cdk": {
@@ -799,10 +799,11 @@
"rr_dealerid": "Reynolds Store Number",
"title": "DMS"
},
"dms_setup": "DMS Setup",
"emaillater": "Email Later",
"employee_teams": "Employee Teams",
"employee_options": "Employee Options",
"employee_rates": "Employee Rates",
"employee_teams": "Employee Teams",
"employee_vacation": "Employee Vacation",
"employees": "Employees",
"estimators": "Estimators",
@@ -813,21 +814,22 @@
"intakechecklist": "Intake Checklist",
"intellipay_cash_discount": "Please ensure that cash discounting has been enabled on your merchant account. Reach out to IntelliPay Support if you need assistance. ",
"job_status_options": "Job Status Options",
"jobcosting": "Job Costing",
"jobstatuses": "Job Statuses",
"jump_to_section": "Jump to section",
"laborrates": "Labor Rates",
"licensing": "Licensing",
"localmediaserver": "Local Media Server",
"md_parts_scan": "Parts Scan Rules",
"md_ro_guard": "RO Guard",
"md_ro_guard_options": "RO Guard Options",
"md_tasks_presets": "Tasks Presets",
"task_preset_options": "Task Preset Options",
"md_to_emails": "Preset To Emails",
"md_to_emails_emails": "Emails",
"messagingpresets": "Messaging Presets",
"notification_options": "Notification Options",
"notemplatesavailable": "No templates available to add.",
"notespresets": "Notes Presets",
"jump_to_section": "Jump to section",
"notification_options": "Notification Options",
"notifications": {
"followers": "Notifications"
},
@@ -864,9 +866,6 @@
"roguard": {
"title": "RO Guard"
},
"autoemail": "Auto Email",
"jobcosting": "Job Costing",
"localmediaserver": "Local Media Server",
"romepay": "Rome Pay",
"scheduling": "SMART Scheduling",
"scoreboardsetup": "Scoreboard Setup",
@@ -878,6 +877,7 @@
"ssbuckets": "Job Size Definitions",
"systemsettings": "System Settings",
"task-presets": "Task Presets",
"task_preset_options": "Task Preset Options",
"workingdays": "Working Days"
},
"operations": {
@@ -1353,6 +1353,31 @@
"unique_employee_number": "You must enter a unique employee number."
}
},
"esignature": {
"actions": {
"delete": "Delete",
"distribute": "Distribute",
"redistribute": "Redistribute",
"upload_document": "Upload Document for E-Sign",
"view": "View"
},
"errors": {
"no_token": "Error connecting to signing server. No authorization token was provided.",
"pdf_only": "Only PDF documents can be uploaded for e-signature.",
"upload_title": "Unable to prepare document for e-signature"
},
"fields": {
"completed": "Completed?",
"completed_at": "Completed At",
"created_at": "Created At",
"external_document_id": "Ex. Document ID",
"opened": "Opened?",
"rejected": "Rejected?",
"status": "Status",
"title": "Title",
"updated_at": "Updated At"
}
},
"eula": {
"buttons": {
"accept": "Accept EULA"
@@ -1468,8 +1493,8 @@
"beta": "BETA",
"cancel": "Are you sure you want to cancel? Your changes will not be saved.",
"changelog": "Change Log",
"click_to_begin": "Click {{action}} to begin",
"clear": "Clear",
"click_to_begin": "Click {{action}} to begin",
"confirmpassword": "Confirm Password",
"created_at": "Created At",
"date": "Select Date",
@@ -2317,6 +2342,8 @@
"duplicateconfirm": "Are you sure you want to duplicate this Job? Some elements of this Job will not be duplicated.",
"emailaudit": "Email Audit Trail",
"employeeassignments": "Employee Assignments",
"esignature_imex": "ImEX Sign",
"esignature_rome": "Rome Sign",
"estimatelines": "Estimate Lines",
"estimator": "Estimator",
"existing_jobs": "Existing Jobs",
@@ -2756,6 +2783,9 @@
"alternate-transport-changed": "Alternate Transport Changed",
"bill-posted": "Bill Posted",
"critical-parts-status-changed": "Critical Parts Status Changed",
"esign-document-completed": "E-Sign Document Completed",
"esign-document-opened": "E-Sign Document Opened",
"esign-document-upload-failed": "E-Sign Document Upload Failed",
"intake-delivery-checklist-completed": "Intake or Delivery Checklist Completed",
"job-added-to-production": "Job Added to Production",
"job-assigned-to-me": "Job Assigned to Me",
@@ -3760,11 +3790,11 @@
"jobhours": "Job Related Time Tickets Summary",
"lunch": "Lunch",
"new": "New Time Ticket",
"payrollclaimedtasks": "These time tickets will be automatically entered to the system as a part of claiming this task. These numbers are calculated using the jobs assigned lines. If lines are unassigned, they will be excluded from created tickets.",
"payout_methods": {
"commission": "Commission",
"hourly": "Hourly"
},
"payrollclaimedtasks": "These time tickets will be automatically entered to the system as a part of claiming this task. These numbers are calculated using the jobs assigned lines. If lines are unassigned, they will be excluded from created tickets.",
"pmbreak": "PM Break",
"pmshift": "PM Shift",
"shift": "Shift",

View File

@@ -120,8 +120,9 @@
"appointmentinsert": "",
"assignedlinehours": "",
"billdeleted": "",
"billposted": "",
"billmarkforreexport": "",
"billposted": "",
"billupdated": "",
"failedpayment": "",
"jobassignmentchange": "",
"jobassignmentremoved": "",
@@ -136,6 +137,9 @@
"jobintake": "",
"jobinvoiced": "",
"jobioucreated": "",
"joblineupdate": "",
"jobmanualcreate": "",
"jobmanuallineinsert": "",
"jobmodifylbradj": "",
"jobnoteadded": "",
"jobnotedeleted": "",
@@ -151,7 +155,9 @@
"tasks_deleted": "",
"tasks_uncompleted": "",
"tasks_undeleted": "",
"tasks_updated": ""
"tasks_updated": "",
"timeticketcreated": "",
"timeticketupdated": ""
}
},
"billlines": {
@@ -317,14 +323,14 @@
"addtemplate": "",
"newlaborrate": "",
"newsalestaxcode": "",
"save_shop_information": "",
"newstatus": "",
"save_shop_information": "",
"testrender": ""
},
"errors": {
"creatingdefaultview": "",
"duplicate_job_status": "",
"duplicate_insurance_company": "",
"duplicate_job_status": "",
"loading": "No se pueden cargar los detalles de la tienda. Por favor llame al soporte técnico.",
"saving": "",
"task_preset_allocation_exceeded": ""
@@ -421,35 +427,6 @@
"logo_img_path": "",
"logo_img_path_height": "",
"logo_img_path_width": "",
"scoreboard_setup": {
"daily_body_target": "",
"daily_paint_target": "",
"ignore_blocked_days": "",
"last_number_working_days": "",
"production_target_hours": ""
},
"system_settings": {
"auto_email": {
"attach_pdf_to_email": "",
"from_emails": "",
"parts_order_cc": "",
"parts_return_slip_cc": ""
},
"job_costing": {
"paint_hour_split": "",
"paint_materials_hourly_cost_rate": "",
"prep_hour_split": "",
"shop_materials_hourly_cost_rate": "",
"target_touch_time": "",
"use_paint_scale_data": ""
},
"local_media_server": {
"enabled": "",
"http_path": "",
"network_path": "",
"token": ""
}
},
"md_categories": "",
"md_ccc_rates": "",
"md_classes": "",
@@ -706,6 +683,13 @@
},
"schedule_end_time": "",
"schedule_start_time": "",
"scoreboard_setup": {
"daily_body_target": "",
"daily_paint_target": "",
"ignore_blocked_days": "",
"last_number_working_days": "",
"production_target_hours": ""
},
"shopname": "",
"speedprint": {
"id": "",
@@ -752,6 +736,28 @@
"production_statuses": "",
"ready_statuses": ""
},
"system_settings": {
"auto_email": {
"attach_pdf_to_email": "",
"from_emails": "",
"parts_order_cc": "",
"parts_return_slip_cc": ""
},
"job_costing": {
"paint_hour_split": "",
"paint_materials_hourly_cost_rate": "",
"prep_hour_split": "",
"shop_materials_hourly_cost_rate": "",
"target_touch_time": "",
"use_paint_scale_data": ""
},
"local_media_server": {
"enabled": "",
"http_path": "",
"network_path": "",
"token": ""
}
},
"target_touchtime": "",
"timezone": "",
"tt_allow_post_to_invoiced": "",
@@ -771,6 +777,7 @@
"alljobstatuses": "",
"allopenjobstatuses": "",
"apptcolors": "",
"autoemail": "",
"businessinformation": "",
"checklists": "",
"consent_settings": "",
@@ -778,7 +785,6 @@
"customtemplates": "",
"defaultcostsmapping": "",
"defaultprofitsmapping": "",
"dms_setup": "",
"deliverchecklist": "",
"dms": {
"cdk": {
@@ -793,10 +799,11 @@
"rr_dealerid": "",
"title": ""
},
"dms_setup": "",
"emaillater": "",
"employee_teams": "",
"employee_options": "",
"employee_rates": "",
"employee_teams": "",
"employee_vacation": "",
"employees": "",
"estimators": "",
@@ -807,21 +814,22 @@
"intakechecklist": "",
"intellipay_cash_discount": "",
"job_status_options": "",
"jobcosting": "",
"jobstatuses": "",
"jump_to_section": "",
"laborrates": "",
"licensing": "",
"localmediaserver": "",
"md_parts_scan": "",
"md_ro_guard": "",
"md_ro_guard_options": "",
"md_tasks_presets": "",
"task_preset_options": "",
"md_to_emails": "",
"md_to_emails_emails": "",
"messagingpresets": "",
"notification_options": "",
"notemplatesavailable": "",
"notespresets": "",
"jump_to_section": "",
"notification_options": "",
"notifications": {
"followers": ""
},
@@ -858,9 +866,6 @@
"roguard": {
"title": ""
},
"autoemail": "",
"jobcosting": "",
"localmediaserver": "",
"romepay": "",
"scheduling": "",
"scoreboardsetup": "",
@@ -872,6 +877,7 @@
"ssbuckets": "",
"systemsettings": "",
"task-presets": "",
"task_preset_options": "",
"workingdays": ""
},
"operations": {
@@ -1347,6 +1353,31 @@
"unique_employee_number": ""
}
},
"esignature": {
"actions": {
"delete": "",
"distribute": "",
"redistribute": "",
"upload_document": "Upload Document for E-Sign",
"view": ""
},
"errors": {
"no_token": "",
"pdf_only": "Only PDF documents can be uploaded for e-signature.",
"upload_title": "Unable to prepare document for e-signature"
},
"fields": {
"completed": "",
"completed_at": "",
"created_at": "",
"external_document_id": "",
"opened": "",
"rejected": "",
"status": "",
"title": "",
"updated_at": ""
}
},
"eula": {
"buttons": {
"accept": "Accept EULA"
@@ -1462,8 +1493,8 @@
"beta": "",
"cancel": "",
"changelog": "",
"click_to_begin": "",
"clear": "",
"click_to_begin": "",
"confirmpassword": "",
"created_at": "",
"date": "",
@@ -2311,6 +2342,8 @@
"duplicateconfirm": "",
"emailaudit": "",
"employeeassignments": "",
"esignature_imex": "",
"esignature_rome": "",
"estimatelines": "",
"estimator": "",
"existing_jobs": "Empleos existentes",
@@ -2750,6 +2783,9 @@
"alternate-transport-changed": "",
"bill-posted": "",
"critical-parts-status-changed": "",
"esign-document-completed": "E-Sign Document Completed",
"esign-document-opened": "E-Sign Document Opened",
"esign-document-upload-failed": "E-Sign Document Upload Failed",
"intake-delivery-checklist-completed": "",
"job-added-to-production": "",
"job-assigned-to-me": "",
@@ -3754,11 +3790,11 @@
"jobhours": "",
"lunch": "",
"new": "",
"payrollclaimedtasks": "",
"payout_methods": {
"commission": "",
"hourly": ""
},
"payrollclaimedtasks": "",
"pmbreak": "",
"pmshift": "",
"shift": "",

View File

@@ -122,6 +122,7 @@
"billdeleted": "",
"billmarkforreexport": "",
"billposted": "",
"billupdated": "",
"failedpayment": "",
"jobassignmentchange": "",
"jobassignmentremoved": "",
@@ -136,6 +137,9 @@
"jobintake": "",
"jobinvoiced": "",
"jobioucreated": "",
"joblineupdate": "",
"jobmanualcreate": "",
"jobmanuallineinsert": "",
"jobmodifylbradj": "",
"jobnoteadded": "",
"jobnotedeleted": "",
@@ -151,7 +155,9 @@
"tasks_deleted": "",
"tasks_uncompleted": "",
"tasks_undeleted": "",
"tasks_updated": ""
"tasks_updated": "",
"timeticketcreated": "",
"timeticketupdated": ""
}
},
"billlines": {
@@ -317,14 +323,14 @@
"addtemplate": "",
"newlaborrate": "",
"newsalestaxcode": "",
"save_shop_information": "",
"newstatus": "",
"save_shop_information": "",
"testrender": ""
},
"errors": {
"creatingdefaultview": "",
"duplicate_job_status": "",
"duplicate_insurance_company": "",
"duplicate_job_status": "",
"loading": "Impossible de charger les détails de la boutique. Veuillez appeler le support technique.",
"saving": "",
"task_preset_allocation_exceeded": ""
@@ -421,35 +427,6 @@
"logo_img_path": "",
"logo_img_path_height": "",
"logo_img_path_width": "",
"scoreboard_setup": {
"daily_body_target": "",
"daily_paint_target": "",
"ignore_blocked_days": "",
"last_number_working_days": "",
"production_target_hours": ""
},
"system_settings": {
"auto_email": {
"attach_pdf_to_email": "",
"from_emails": "",
"parts_order_cc": "",
"parts_return_slip_cc": ""
},
"job_costing": {
"paint_hour_split": "",
"paint_materials_hourly_cost_rate": "",
"prep_hour_split": "",
"shop_materials_hourly_cost_rate": "",
"target_touch_time": "",
"use_paint_scale_data": ""
},
"local_media_server": {
"enabled": "",
"http_path": "",
"network_path": "",
"token": ""
}
},
"md_categories": "",
"md_ccc_rates": "",
"md_classes": "",
@@ -706,6 +683,13 @@
},
"schedule_end_time": "",
"schedule_start_time": "",
"scoreboard_setup": {
"daily_body_target": "",
"daily_paint_target": "",
"ignore_blocked_days": "",
"last_number_working_days": "",
"production_target_hours": ""
},
"shopname": "",
"speedprint": {
"id": "",
@@ -752,6 +736,28 @@
"production_statuses": "",
"ready_statuses": ""
},
"system_settings": {
"auto_email": {
"attach_pdf_to_email": "",
"from_emails": "",
"parts_order_cc": "",
"parts_return_slip_cc": ""
},
"job_costing": {
"paint_hour_split": "",
"paint_materials_hourly_cost_rate": "",
"prep_hour_split": "",
"shop_materials_hourly_cost_rate": "",
"target_touch_time": "",
"use_paint_scale_data": ""
},
"local_media_server": {
"enabled": "",
"http_path": "",
"network_path": "",
"token": ""
}
},
"target_touchtime": "",
"timezone": "",
"tt_allow_post_to_invoiced": "",
@@ -771,6 +777,7 @@
"alljobstatuses": "",
"allopenjobstatuses": "",
"apptcolors": "",
"autoemail": "",
"businessinformation": "",
"checklists": "",
"consent_settings": "",
@@ -778,7 +785,6 @@
"customtemplates": "",
"defaultcostsmapping": "",
"defaultprofitsmapping": "",
"dms_setup": "",
"deliverchecklist": "",
"dms": {
"cdk": {
@@ -793,10 +799,11 @@
"rr_dealerid": "",
"title": ""
},
"dms_setup": "",
"emaillater": "",
"employee_teams": "",
"employee_options": "",
"employee_rates": "",
"employee_teams": "",
"employee_vacation": "",
"employees": "",
"estimators": "",
@@ -807,21 +814,22 @@
"intakechecklist": "",
"intellipay_cash_discount": "",
"job_status_options": "",
"jobcosting": "",
"jobstatuses": "",
"jump_to_section": "",
"laborrates": "",
"licensing": "",
"localmediaserver": "",
"md_parts_scan": "",
"md_ro_guard": "",
"md_ro_guard_options": "",
"md_tasks_presets": "",
"task_preset_options": "",
"md_to_emails": "",
"md_to_emails_emails": "",
"messagingpresets": "",
"notification_options": "",
"notemplatesavailable": "",
"notespresets": "",
"jump_to_section": "",
"notification_options": "",
"notifications": {
"followers": ""
},
@@ -858,9 +866,6 @@
"roguard": {
"title": ""
},
"autoemail": "",
"jobcosting": "",
"localmediaserver": "",
"romepay": "",
"scheduling": "",
"scoreboardsetup": "",
@@ -872,6 +877,7 @@
"ssbuckets": "",
"systemsettings": "",
"task-presets": "",
"task_preset_options": "",
"workingdays": ""
},
"operations": {
@@ -1347,6 +1353,31 @@
"unique_employee_number": ""
}
},
"esignature": {
"actions": {
"delete": "",
"distribute": "",
"redistribute": "",
"upload_document": "Upload Document for E-Sign",
"view": ""
},
"errors": {
"no_token": "",
"pdf_only": "Only PDF documents can be uploaded for e-signature.",
"upload_title": "Unable to prepare document for e-signature"
},
"fields": {
"completed": "",
"completed_at": "",
"created_at": "",
"external_document_id": "",
"opened": "",
"rejected": "",
"status": "",
"title": "",
"updated_at": ""
}
},
"eula": {
"buttons": {
"accept": "Accept EULA"
@@ -1462,8 +1493,8 @@
"beta": "",
"cancel": "",
"changelog": "",
"click_to_begin": "",
"clear": "",
"click_to_begin": "",
"confirmpassword": "",
"created_at": "",
"date": "",
@@ -2311,6 +2342,8 @@
"duplicateconfirm": "",
"emailaudit": "",
"employeeassignments": "",
"esignature_imex": "",
"esignature_rome": "",
"estimatelines": "",
"estimator": "",
"existing_jobs": "Emplois existants",
@@ -2750,6 +2783,9 @@
"alternate-transport-changed": "",
"bill-posted": "",
"critical-parts-status-changed": "",
"esign-document-completed": "E-Sign Document Completed",
"esign-document-opened": "E-Sign Document Opened",
"esign-document-upload-failed": "E-Sign Document Upload Failed",
"intake-delivery-checklist-completed": "",
"job-added-to-production": "",
"job-assigned-to-me": "",
@@ -3754,11 +3790,11 @@
"jobhours": "",
"lunch": "",
"new": "",
"payrollclaimedtasks": "",
"payout_methods": {
"commission": "",
"hourly": ""
},
"payrollclaimedtasks": "",
"pmbreak": "",
"pmshift": "",
"shift": "",

View File

@@ -0,0 +1,7 @@
export const hasDocumensoApiKey = (bodyshop) => {
if (typeof bodyshop?.documenso_api_key === "string") {
return bodyshop.documenso_api_key.trim().length > 0;
}
return Boolean(bodyshop?.documenso_api_key);
};

View File

@@ -2,7 +2,7 @@
* @description This file contains the scenarios for job notifications.
* @type {string[]}
*/
const notificationScenarios = [
const baseNotificationScenarios = [
"job-assigned-to-me",
"bill-posted",
"critical-parts-status-changed",
@@ -20,4 +20,26 @@ const notificationScenarios = [
// "supplement-imported", // Disabled for now
];
export { notificationScenarios };
const esignNotificationScenarios = [
"esign-document-opened",
"esign-document-completed",
"esign-document-upload-failed"
];
const notificationScenarios = [...baseNotificationScenarios, ...esignNotificationScenarios];
const getNotificationScenarios = ({ includeEsign = true } = {}) =>
includeEsign ? notificationScenarios : baseNotificationScenarios;
/**
* Default channel preferences for e-sign document notifications. By default, all e-sign related notifications will be
* sent via the app, but not via email or FCM. These defaults can be overridden by user preferences.
* @type {{"esign-document-opened": {app: boolean, email: boolean, fcm: boolean}, "esign-document-completed": {app: boolean, email: boolean, fcm: boolean}, "esign-document-upload-failed": {app: boolean, email: boolean, fcm: boolean}}}
*/
const notificationScenarioDefaults = {
"esign-document-opened": { app: true, email: false, fcm: false },
"esign-document-completed": { app: true, email: false, fcm: false },
"esign-document-upload-failed": { app: true, email: false, fcm: false }
};
export { esignNotificationScenarios, getNotificationScenarios, notificationScenarios, notificationScenarioDefaults };

View File

@@ -0,0 +1,28 @@
export const replaceAccents = (str) => {
// Verifies if the String has accents and replace them
if (str.search(/[\xC0-\xFF]/g) > -1) {
str = str
.replace(/[\xC0-\xC5]/g, "A")
.replace(/[\xC6]/g, "AE")
.replace(/[\xC7]/g, "C")
.replace(/[\xC8-\xCB]/g, "E")
.replace(/[\xCC-\xCF]/g, "I")
.replace(/[\xD0]/g, "D")
.replace(/[\xD1]/g, "N")
.replace(/[\xD2-\xD6\xD8]/g, "O")
.replace(/[\xD9-\xDC]/g, "U")
.replace(/[\xDD]/g, "Y")
.replace(/[\xDE]/g, "P")
.replace(/[\xE0-\xE5]/g, "a")
.replace(/[\xE6]/g, "ae")
.replace(/[\xE7]/g, "c")
.replace(/[\xE8-\xEB]/g, "e")
.replace(/[\xEC-\xEF]/g, "i")
.replace(/[\xF1]/g, "n")
.replace(/[\xF2-\xF6\xF8]/g, "o")
.replace(/[\xF9-\xFC]/g, "u")
.replace(/[\xFE]/g, "p")
.replace(/[\xFD\xFF]/g, "y");
}
return str;
};

View File

@@ -0,0 +1,24 @@
-----BEGIN CERTIFICATE-----
MIID9zCCAt+gAwIBAgIUTB4OhIqfXvT0mBKHwYAwDPq79ygwDQYJKoZIhvcNAQEL
BQAwgYoxCzAJBgNVBAYTAkNBMQswCQYDVQQIDAJCQzESMBAGA1UEBwwJVmFuY291
dmVyMRowGAYDVQQKDBFJbUVYIFN5c3RlbXMgSW5jLjEXMBUGA1UEAwwOaW1leHN5
c3RlbXMuY2ExJTAjBgkqhkiG9w0BCQEWFmNvbnRhY3RAaW1leHN5c3RlbXMuY2Ew
HhcNMjYwNDEzMjAxMDIzWhcNMzYwNDEwMjAxMDIzWjCBijELMAkGA1UEBhMCQ0Ex
CzAJBgNVBAgMAkJDMRIwEAYDVQQHDAlWYW5jb3V2ZXIxGjAYBgNVBAoMEUltRVgg
U3lzdGVtcyBJbmMuMRcwFQYDVQQDDA5pbWV4c3lzdGVtcy5jYTElMCMGCSqGSIb3
DQEJARYWY29udGFjdEBpbWV4c3lzdGVtcy5jYTCCASIwDQYJKoZIhvcNAQEBBQAD
ggEPADCCAQoCggEBAPE+5bcnfYsMyLzJr50bzpHHP8I+cdSkvu7lwGysPZCCxi4Z
vkIDq4Q5xDa3ZZCeNZ9feELqm9ZjWpnaZj4CMbXMDpIucZHQJC9USCGavYhzNYu2
G3IU7D834jd8GkwGMQuXkGiuQmQssIZIKfX+MaZ0KKrh8gJbxXZOfCp3fdYOnFPq
BFCR0N/gTbeRboq36dG4vo1FanDLGroMS7FycGjyUTQv3CTWkGAOAPGQVrGZgvYM
DtFr+7M2J/KCbUMobK0uc1scAjLgetXknzVPU3qA66F3Hi7oWykoFX8m9oX/OJnK
/Gt8rIjRMOyQSK7dKT7qXCxgQVQnqHbyUCX4WUkCAwEAAaNTMFEwHQYDVR0OBBYE
FIRKLjeI+adC7yNg6cSDj72Kej11MB8GA1UdIwQYMBaAFIRKLjeI+adC7yNg6cSD
j72Kej11MA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAAHCSjlG
bo5miEfisKffPyfzufBIhOLLORasuFQ3gVKBU32JytuoflABfcqy3prgZxbFLMB2
fDcSImKuOtt79OMeMlA+ptfkWuOpFMqL2j6BilzjJ/MAlPAZlZmmuLh/fPj3lbMD
QQds/YhSmZcTdRX8seQslnYq1AT7629BDbpCjjL3pRkntnePR7u8tgb28Pm8Vl3S
uCnGS/mMxrS/7z+QnaDi1N/nyIwa2bQtGmsoMn+CzuUUjyMD4TYbdUJv+fca8/tR
zezNEHcpBCKGGgZRowhifJwEoel0M1iEo8UYy5eFPDF8CoRGRIH7QSaduCfnej06
KLtevL/vyhUpTMA=
-----END CERTIFICATE-----

Binary file not shown.

View File

@@ -0,0 +1,72 @@
name: documenso-production
services:
database:
image: postgres:15
environment:
- POSTGRES_USER=${POSTGRES_USER:?err}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:?err}
- POSTGRES_DB=${POSTGRES_DB:?err}
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U ${POSTGRES_USER}']
interval: 10s
timeout: 5s
retries: 5
volumes:
- database:/var/lib/postgresql/data
documenso:
image: documenso/documenso:latest
depends_on:
database:
condition: service_healthy
environment:
- PORT=${PORT:-3000}
- NEXTAUTH_SECRET=${NEXTAUTH_SECRET:?err}
- NEXT_PRIVATE_ENCRYPTION_KEY=${NEXT_PRIVATE_ENCRYPTION_KEY:?err}
- NEXT_PRIVATE_ENCRYPTION_SECONDARY_KEY=${NEXT_PRIVATE_ENCRYPTION_SECONDARY_KEY:?err}
- NEXT_PRIVATE_GOOGLE_CLIENT_ID=${NEXT_PRIVATE_GOOGLE_CLIENT_ID}
- NEXT_PRIVATE_GOOGLE_CLIENT_SECRET=${NEXT_PRIVATE_GOOGLE_CLIENT_SECRET}
- NEXT_PUBLIC_WEBAPP_URL=${NEXT_PUBLIC_WEBAPP_URL:?err}
- NEXT_PRIVATE_INTERNAL_WEBAPP_URL=${NEXT_PRIVATE_INTERNAL_WEBAPP_URL:-http://localhost:$PORT}
- NEXT_PRIVATE_DATABASE_URL=${NEXT_PRIVATE_DATABASE_URL:?err}
- NEXT_PRIVATE_DIRECT_DATABASE_URL=${NEXT_PRIVATE_DIRECT_DATABASE_URL:-${NEXT_PRIVATE_DATABASE_URL}}
- NEXT_PUBLIC_UPLOAD_TRANSPORT=${NEXT_PUBLIC_UPLOAD_TRANSPORT:-database}
- NEXT_PRIVATE_UPLOAD_ENDPOINT=${NEXT_PRIVATE_UPLOAD_ENDPOINT}
- NEXT_PRIVATE_UPLOAD_FORCE_PATH_STYLE=${NEXT_PRIVATE_UPLOAD_FORCE_PATH_STYLE}
- NEXT_PRIVATE_UPLOAD_REGION=${NEXT_PRIVATE_UPLOAD_REGION}
- NEXT_PRIVATE_UPLOAD_BUCKET=${NEXT_PRIVATE_UPLOAD_BUCKET}
- NEXT_PRIVATE_UPLOAD_ACCESS_KEY_ID=${NEXT_PRIVATE_UPLOAD_ACCESS_KEY_ID}
- NEXT_PRIVATE_UPLOAD_SECRET_ACCESS_KEY=${NEXT_PRIVATE_UPLOAD_SECRET_ACCESS_KEY}
- NEXT_PRIVATE_SMTP_TRANSPORT=${NEXT_PRIVATE_SMTP_TRANSPORT:?err}
- NEXT_PRIVATE_SMTP_HOST=${NEXT_PRIVATE_SMTP_HOST}
- NEXT_PRIVATE_SMTP_PORT=${NEXT_PRIVATE_SMTP_PORT}
- NEXT_PRIVATE_SMTP_USERNAME=${NEXT_PRIVATE_SMTP_USERNAME}
- NEXT_PRIVATE_SMTP_PASSWORD=${NEXT_PRIVATE_SMTP_PASSWORD}
- NEXT_PRIVATE_SMTP_APIKEY_USER=${NEXT_PRIVATE_SMTP_APIKEY_USER}
- NEXT_PRIVATE_SMTP_APIKEY=${NEXT_PRIVATE_SMTP_APIKEY}
- NEXT_PRIVATE_SMTP_SECURE=${NEXT_PRIVATE_SMTP_SECURE}
- NEXT_PRIVATE_SMTP_UNSAFE_IGNORE_TLS=${NEXT_PRIVATE_SMTP_UNSAFE_IGNORE_TLS}
- NEXT_PRIVATE_SMTP_FROM_NAME=${NEXT_PRIVATE_SMTP_FROM_NAME:?err}
- NEXT_PRIVATE_SMTP_FROM_ADDRESS=${NEXT_PRIVATE_SMTP_FROM_ADDRESS:?err}
- NEXT_PRIVATE_SMTP_SERVICE=${NEXT_PRIVATE_SMTP_SERVICE}
- NEXT_PRIVATE_RESEND_API_KEY=${NEXT_PRIVATE_RESEND_API_KEY}
- NEXT_PRIVATE_MAILCHANNELS_API_KEY=${NEXT_PRIVATE_MAILCHANNELS_API_KEY}
- NEXT_PRIVATE_MAILCHANNELS_ENDPOINT=${NEXT_PRIVATE_MAILCHANNELS_ENDPOINT}
- NEXT_PRIVATE_MAILCHANNELS_DKIM_DOMAIN=${NEXT_PRIVATE_MAILCHANNELS_DKIM_DOMAIN}
- NEXT_PRIVATE_MAILCHANNELS_DKIM_SELECTOR=${NEXT_PRIVATE_MAILCHANNELS_DKIM_SELECTOR}
- NEXT_PRIVATE_MAILCHANNELS_DKIM_PRIVATE_KEY=${NEXT_PRIVATE_MAILCHANNELS_DKIM_PRIVATE_KEY}
- NEXT_PUBLIC_DOCUMENT_SIZE_UPLOAD_LIMIT=${NEXT_PUBLIC_DOCUMENT_SIZE_UPLOAD_LIMIT}
- NEXT_PUBLIC_POSTHOG_KEY=${NEXT_PUBLIC_POSTHOG_KEY}
- NEXT_PUBLIC_DISABLE_SIGNUP=${NEXT_PUBLIC_DISABLE_SIGNUP}
- NEXT_PRIVATE_ALLOWED_SIGNUP_DOMAINS=${NEXT_PRIVATE_ALLOWED_SIGNUP_DOMAINS}
- NEXT_PRIVATE_SIGNING_LOCAL_FILE_PATH=${NEXT_PRIVATE_SIGNING_LOCAL_FILE_PATH:-/opt/documenso/cert.p12}
- NEXT_PRIVATE_SIGNING_PASSPHRASE=${NEXT_PRIVATE_SIGNING_PASSPHRASE}
- NEXT_PUBLIC_USE_INTERNAL_URL_BROWSERLESS=${NEXT_PUBLIC_USE_INTERNAL_URL_BROWSERLESS}
ports:
- ${PORT:-3000}:${PORT:-3000}
volumes:
- /opt/documenso/cert.p12:/opt/documenso/cert.p12:ro
volumes:
database:

45
documenso/terraform/.terraform.lock.hcl generated Normal file
View File

@@ -0,0 +1,45 @@
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/aws" {
version = "6.38.0"
constraints = "~> 6.0"
hashes = [
"h1:RDoKIzXmt7H1mNFcNIyRT+nA/gTJyO3+iW9QGN5I2eQ=",
"zh:143f118ae71059a7a7026c6b950da23fef04a06e2362ffa688bef75e43e869ed",
"zh:29ee220a017306effd877e1280f8b2934dc957e16e0e72ca0222e5514d0db522",
"zh:3a31baabf7aea7aa7669f5a3d76f3445e0e6cce5e9aea0279992765c0df12aee",
"zh:4c1908e62040dbc9901d4426ffb253f53e5dae9e3e1a9125311291ee265c8d8c",
"zh:550f4789f5f5b00e16118d4c17770be3ef4535d6b6928af1cf91ebd30f2c263b",
"zh:6537b7b70bf2c127771b0b84e4b726c834d10666b6104f017edae50c67ebae37",
"zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425",
"zh:af2f9cea0c8bdf5b2a2391f2d179a946c117196f7c829b919673cae3b71d2943",
"zh:c53ffa685381aa4e73158fd9f529239f95938dea330e7aca0b32e7b2a1210432",
"zh:d0995e1d64a7ec8bbc79fc3fbec3749f989e07f211a318705c37cd6a7c7d19e4",
"zh:d2348ffcffc1282983d7a5838dd5d61f372152fe6c0d10868cd6473352318750",
"zh:e449312efb73e4747165e689302a68a1df8ba5755e7f59097069acf82c94f011",
"zh:ec3a538d264ef79380e56fdf107ffb6c0446814f07fc5890c36855fe1e03196b",
"zh:f441e69699b22e32c96a8cdd3bbe694ed302c0dcfe867cd9bd683a16df362714",
"zh:f6f8eaa605ff902234d7e9bdab4fda977185fce14f8576f7b622c914c7d98008",
]
}
provider "registry.terraform.io/hashicorp/random" {
version = "3.8.1"
constraints = "~> 3.6"
hashes = [
"h1:u8AKlWVDTH5r9YLSeswoVEjiY72Rt4/ch7U+61ZDkiQ=",
"zh:08dd03b918c7b55713026037c5400c48af5b9f468f483463321bd18e17b907b4",
"zh:0eee654a5542dc1d41920bbf2419032d6f0d5625b03bd81339e5b33394a3e0ae",
"zh:229665ddf060aa0ed315597908483eee5b818a17d09b6417a0f52fd9405c4f57",
"zh:2469d2e48f28076254a2a3fc327f184914566d9e40c5780b8d96ebf7205f8bc0",
"zh:37d7eb334d9561f335e748280f5535a384a88675af9a9eac439d4cfd663bcb66",
"zh:741101426a2f2c52dee37122f0f4a2f2d6af6d852cb1db634480a86398fa3511",
"zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3",
"zh:a902473f08ef8df62cfe6116bd6c157070a93f66622384300de235a533e9d4a9",
"zh:b85c511a23e57a2147355932b3b6dce2a11e856b941165793a0c3d7578d94d05",
"zh:c5172226d18eaac95b1daac80172287b69d4ce32750c82ad77fa0768be4ea4b8",
"zh:dab4434dba34aad569b0bc243c2d3f3ff86dd7740def373f2a49816bd2ff819b",
"zh:f49fd62aa8c5525a5c17abd51e27ca5e213881d58882fd42fec4a545b53c9699",
]
}

View File

@@ -0,0 +1,60 @@
# Documenso on AWS
This Terraform stack deploys Documenso to AWS in `ca-central-1` using:
- ECS Fargate for the application tier
- RDS PostgreSQL for the database tier
- S3 for document uploads and signed PDFs
- Application Load Balancer with ACM-managed TLS
- Route53 DNS for `esignature.imex.online`
- Optional SES domain identity and DKIM management for outbound email
- Secrets Manager for generated application secrets, SMTP credentials, and the optional Documenso signing certificate
- AWS WAF with a basic managed rule set, rate limiting, and an allowlist for trusted IPv4 CIDRs
- CloudWatch alarms for ALB, ECS, and RDS health indicators
## Why this shape
This is the most practical fit for your Docker Compose workload if you want a balance of cost efficiency, managed operations, and scaling:
- Fargate gives you horizontal scaling without managing EC2 hosts.
- RDS PostgreSQL is simpler and cheaper than Aurora for a single Documenso workload.
- S3-backed uploads are better for production scale and keep document growth out of PostgreSQL.
- The database stays private; the ALB is public.
- The ECS tasks run in public subnets to avoid a NAT gateway charge. Inbound access is still restricted to the ALB security group.
- HTTPS is terminated by the ALB using ACM. The Documenso self-signed `.p12` certificate is separate and is used for document signing, not browser TLS.
## Files
- `main.tf`: core infrastructure
- `variables.tf`: configurable inputs
- `outputs.tf`: useful deployment outputs
- `terraform.tfvars.example`: example input values
## Assumptions built into this stack
1. Your DNS for `imex.online` is hosted in Route53.
2. You want Multi-AZ RDS enabled from the start for database availability.
3. You are comfortable starting with `documenso/documenso:latest`. For repeatable deployments, pin a version or digest after your first rollout.
4. You will provide SES SMTP credentials. Terraform does not derive SMTP passwords for you.
5. SES identity and DKIM might already be managed outside this stack. By default, this Terraform does not attempt to create them.
6. You will provide a base64-encoded PKCS#12 signing certificate and passphrase if you want document signing enabled immediately. This stack injects those values through Secrets Manager instead of mounting a host file.
7. You are comfortable with Terraform creating a dedicated IAM user and access key for Documenso S3 uploads because Documenso documents explicit S3 credentials for the upload backend.
8. You want Terraform destroy protection enabled for both the database and the uploads bucket.
## Deploy
1. Copy `terraform.tfvars.example` to `terraform.tfvars` and fill in the SMTP values.
2. If you want Documenso signing enabled, add `signing_certificate_base64` and `signing_certificate_passphrase`.
3. Optionally set `upload_bucket_name` if you want a specific S3 bucket name.
4. Set `manage_ses_resources = true` only if you want this stack to own SES identity verification and DKIM records.
5. Set `waf_bypass_ipv4_cidrs` with any public `/32` addresses that should bypass WAF inspection. The VPC CIDR is already allowlisted automatically.
6. Run `terraform init`.
7. Run `terraform plan`.
8. Run `terraform apply`.
## Recommended first production adjustments
1. Pin the Documenso image to a tested version or digest.
2. Wire `alarm_actions` to an SNS topic, PagerDuty bridge, or your on-call system so alarms notify someone.
3. Expand the WAF rule set if you need more aggressive filtering later.
4. Add CloudWatch alarms on ECS 5xx errors, ALB target health, and RDS CPU/storage.

1052
documenso/terraform/main.tf Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,44 @@
output "application_url" {
description = "Public URL for the Documenso deployment."
value = "https://${var.domain_name}"
}
output "load_balancer_dns_name" {
description = "DNS name assigned to the application load balancer."
value = aws_lb.this.dns_name
}
output "database_endpoint" {
description = "RDS PostgreSQL endpoint for the application."
value = aws_db_instance.postgres.address
}
output "postgres_engine_version" {
description = "Resolved PostgreSQL engine version deployed to RDS."
value = aws_db_instance.postgres.engine_version
}
output "ecs_cluster_name" {
description = "ECS cluster name running the Documenso service."
value = aws_ecs_cluster.this.name
}
output "secrets_manager_secret_name" {
description = "Secrets Manager secret that stores generated and supplied application secrets."
value = aws_secretsmanager_secret.app.name
}
output "ses_identity_domain" {
description = "SES domain used for outbound mail."
value = local.ses_domain
}
output "upload_bucket_name" {
description = "S3 bucket used for Documenso uploads."
value = aws_s3_bucket.uploads.bucket
}
output "waf_web_acl_arn" {
description = "ARN of the WAF web ACL attached to the ALB."
value = aws_wafv2_web_acl.this.arn
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,24 @@
aws_region = "ca-central-1"
domain_name = "esignature.imex.online"
hosted_zone_name = "imex.online"
documenso_image = "documenso/documenso:latest"
smtp_username = "AKIA2MRSPON3O6PRVUPE"
smtp_password = "pw"
smtp_from_address = "no-reply@imex.online"
manage_ses_resources = false
ses_identity_domain = "imex.online"
app_secret_name = "documenso/esignature-imex-online/app"
# signing_certificate_base64 = "MII...base64-encoded-p12..."
# signing_certificate_passphrase = "replace-with-your-p12-passphrase"
# upload_bucket_name = "esignature-imex-online-documenso"
# Optional tuning
# desired_count = 2
# max_count = 6
waf_bypass_ipv4_cidrs = ["203.0.113.10/32"]
db_instance_class = "db.t4g.micro"
db_publicly_accessible = true
db_allowed_cidrs = ["64.46.30.40/32"]
disable_signup = false
# allowed_signup_domains = "imex.online"
# alarm_actions = ["arn:aws:sns:ca-central-1:123456789012:ops-alerts"]

View File

@@ -0,0 +1,318 @@
variable "aws_region" {
description = "AWS region for the deployment."
type = string
default = "ca-central-1"
}
variable "project_name" {
description = "Logical name used to prefix created resources."
type = string
default = "documenso"
}
variable "domain_name" {
description = "Fully qualified domain name for the application."
type = string
default = "esignature.imex.online"
}
variable "hosted_zone_name" {
description = "Public Route53 hosted zone that contains the application hostname."
type = string
default = "imex.online"
}
variable "ses_identity_domain" {
description = "Domain used for SES. Defaults to the hosted zone when null. If manage_ses_resources is false, this is informational and used only for outputs/documentation."
type = string
default = null
}
variable "manage_ses_resources" {
description = "Whether this Terraform stack should create and manage the SES domain identity, verification record, and DKIM records. Disable this when SES is already configured elsewhere."
type = bool
default = false
}
variable "documenso_image" {
description = "Container image for Documenso. Default keeps you on the latest published image."
type = string
default = "documenso/documenso:latest"
}
variable "app_port" {
description = "Container port exposed by Documenso."
type = number
default = 3000
}
variable "upload_bucket_name" {
description = "Optional S3 bucket name for Documenso uploads. If null, Terraform generates a globally unique name based on account and region."
type = string
default = null
}
variable "s3_versioning_enabled" {
description = "Enable S3 object versioning for uploaded documents."
type = bool
default = true
}
variable "document_size_upload_limit_mb" {
description = "Upload size limit shown in the Documenso UI, in MB."
type = number
default = 10
}
variable "vpc_cidr" {
description = "CIDR block used for the VPC."
type = string
default = "10.42.0.0/16"
}
variable "fargate_cpu" {
description = "Fargate CPU units for the task."
type = number
default = 512
}
variable "fargate_memory" {
description = "Fargate memory in MiB for the task."
type = number
default = 1024
}
variable "desired_count" {
description = "Initial number of running Documenso tasks."
type = number
default = 1
}
variable "min_count" {
description = "Minimum number of tasks for autoscaling."
type = number
default = 1
}
variable "max_count" {
description = "Maximum number of tasks for autoscaling."
type = number
default = 4
}
variable "cpu_target_utilization" {
description = "Target average CPU utilization for ECS autoscaling."
type = number
default = 65
}
variable "memory_target_utilization" {
description = "Target average memory utilization for ECS autoscaling."
type = number
default = 75
}
variable "postgres_major_version" {
description = "Preferred PostgreSQL major version. Terraform resolves the latest matching minor release supported by AWS."
type = string
default = "17"
}
variable "db_name" {
description = "Initial PostgreSQL database name."
type = string
default = "documenso"
}
variable "db_username" {
description = "Master PostgreSQL username for the application."
type = string
default = "documenso"
}
variable "db_instance_class" {
description = "RDS instance class. Graviton classes are usually the best cost/performance option for Postgres."
type = string
default = "db.t4g.small"
}
variable "db_allocated_storage" {
description = "Initial allocated storage in GiB."
type = number
default = 20
}
variable "db_max_allocated_storage" {
description = "Maximum autoscaled storage in GiB."
type = number
default = 100
}
variable "db_backup_retention_days" {
description = "How many days of automated backups to retain."
type = number
default = 7
}
variable "db_multi_az" {
description = "Enable Multi-AZ for higher database availability at higher cost."
type = bool
default = true
}
variable "db_deletion_protection" {
description = "Protect the database from accidental deletion."
type = bool
default = true
}
variable "db_final_snapshot_on_destroy" {
description = "Create a final snapshot if the database is destroyed."
type = bool
default = true
}
variable "db_publicly_accessible" {
description = "Whether the RDS instance should have a public endpoint. Requires database subnets with a route to the internet gateway."
type = bool
default = false
}
variable "db_allowed_cidrs" {
description = "IPv4 CIDR blocks allowed to connect directly to PostgreSQL. Leave empty to disable direct public access."
type = list(string)
default = []
}
variable "disable_signup" {
description = "Disable public signup in Documenso."
type = bool
default = true
}
variable "allowed_signup_domains" {
description = "Optional comma-separated list of allowed email domains when signup is enabled."
type = string
default = ""
}
variable "smtp_port" {
description = "SES SMTP endpoint port."
type = number
default = 587
}
variable "smtp_secure" {
description = "Whether to use SMTPS. Keep false for SES on port 587 with STARTTLS."
type = bool
default = false
}
variable "smtp_unsafe_ignore_tls" {
description = "Whether the application should ignore TLS issues when sending mail."
type = bool
default = false
}
variable "smtp_username" {
description = "SES SMTP username."
type = string
sensitive = true
}
variable "smtp_password" {
description = "SES SMTP password."
type = string
sensitive = true
}
variable "smtp_from_name" {
description = "Display name used in outbound email."
type = string
default = "ImEX Sign"
}
variable "smtp_from_address" {
description = "Verified sender email address for SES."
type = string
}
variable "signing_certificate_base64" {
description = "Base64-encoded PKCS#12 signing certificate contents for Documenso. Leave empty to omit certificate injection."
type = string
default = ""
sensitive = true
}
variable "signing_certificate_passphrase" {
description = "Passphrase for the Documenso signing certificate. Leave empty to omit it."
type = string
default = ""
sensitive = true
}
variable "app_secret_name" {
description = "Secrets Manager secret name used for Documenso application secrets. Set this if a previous secret with the default name is pending deletion."
type = string
default = null
}
variable "tags" {
description = "Additional tags applied to all supported resources."
type = map(string)
default = {}
}
variable "waf_rate_limit" {
description = "Maximum requests per 5-minute window from a single IP before WAF blocks it."
type = number
default = 2000
}
variable "waf_bypass_ipv4_cidrs" {
description = "Additional IPv4 CIDR blocks that bypass the WAF. The VPC CIDR is always included automatically."
type = list(string)
default = []
}
variable "alarm_actions" {
description = "Optional list of SNS topic ARNs or other alarm actions to invoke when CloudWatch alarms fire."
type = list(string)
default = []
}
variable "alb_5xx_alarm_threshold" {
description = "Threshold for ALB 5xx count over a 5-minute period."
type = number
default = 10
}
variable "ecs_cpu_alarm_threshold" {
description = "Threshold for average ECS CPU utilization alarm."
type = number
default = 85
}
variable "ecs_memory_alarm_threshold" {
description = "Threshold for average ECS memory utilization alarm."
type = number
default = 85
}
variable "rds_cpu_alarm_threshold" {
description = "Threshold for average RDS CPU utilization alarm."
type = number
default = 80
}
variable "rds_free_storage_alarm_threshold_bytes" {
description = "Alarm threshold for low RDS free storage, in bytes."
type = number
default = 5368709120
}
variable "documenso_license_key" {
description = "Documenso license key. Not required for the free community edition, but required for enterprise features and support."
type = string
default = ""
}

View File

@@ -956,6 +956,7 @@
- created_at
- default_adjustment_rate
- deliverchecklist
- documenso_api_key
- email
- enforce_class
- enforce_conversion_category
@@ -1893,6 +1894,14 @@
- name: job
using:
foreign_key_constraint_on: jobid
array_relationships:
- name: esignature_documents
using:
foreign_key_constraint_on:
column: documentid
table:
name: esignature_documents
schema: public
insert_permissions:
- role: user
permission:
@@ -2568,6 +2577,101 @@
_eq: X-Hasura-User-Id
- active:
_eq: true
- table:
name: esignature_documents
schema: public
object_relationships:
- name: document
using:
foreign_key_constraint_on: documentid
- name: job
using:
foreign_key_constraint_on: jobid
insert_permissions:
- role: user
permission:
check:
job:
bodyshop:
associations:
_and:
- active:
_eq: true
- user:
authid:
_eq: X-Hasura-User-Id
columns:
- completed
- documentid
- external_document_id
- jobid
- message
- opened
- recipients
- rejected
- status
- subject
- title
comment: ""
select_permissions:
- role: user
permission:
columns:
- completed
- completed_at
- created_at
- documentid
- external_document_id
- id
- jobid
- message
- opened
- recipients
- rejected
- status
- subject
- title
- updated_at
filter:
job:
bodyshop:
associations:
_and:
- active:
_eq: true
- user:
authid:
_eq: X-Hasura-User-Id
comment: ""
update_permissions:
- role: user
permission:
columns:
- completed
- completed_at
- created_at
- documentid
- external_document_id
- message
- opened
- recipients
- rejected
- status
- subject
- title
- updated_at
filter:
job:
bodyshop:
associations:
_and:
- active:
_eq: true
- user:
authid:
_eq: X-Hasura-User-Id
check: null
comment: ""
- table:
name: eula_acceptances
schema: public
@@ -3466,6 +3570,13 @@
table:
name: email_audit_trail
schema: public
- name: esignature_documents
using:
foreign_key_constraint_on:
column: jobid
table:
name: esignature_documents
schema: public
- name: exportlogs
using:
foreign_key_constraint_on:

View File

@@ -0,0 +1 @@
DROP TABLE "public"."esignature_documents";

View File

@@ -0,0 +1,18 @@
CREATE TABLE "public"."esignature_documents" ("id" uuid NOT NULL DEFAULT gen_random_uuid(), "created_at" timestamptz NOT NULL DEFAULT now(), "updated_at" timestamptz NOT NULL DEFAULT now(), "external_document_id" text NOT NULL, "jobid" uuid NOT NULL, "status" text NOT NULL, "recipients" jsonb[] NOT NULL, "title" text NOT NULL, "subject" text NOT NULL, "message" text NOT NULL, "viewed" boolean NOT NULL DEFAULT false, "completed" boolean NOT NULL DEFAULT false, "documentid" uuid, "rejected" boolean NOT NULL DEFAULT false, "opened" boolean NOT NULL DEFAULT false, PRIMARY KEY ("id") , FOREIGN KEY ("jobid") REFERENCES "public"."jobs"("id") ON UPDATE restrict ON DELETE restrict);COMMENT ON TABLE "public"."esignature_documents" IS E'Tracking the lifecycle of esignature documents. ';
CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"()
RETURNS TRIGGER AS $$
DECLARE
_new record;
BEGIN
_new := NEW;
_new."updated_at" = NOW();
RETURN _new;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER "set_public_esignature_documents_updated_at"
BEFORE UPDATE ON "public"."esignature_documents"
FOR EACH ROW
EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"();
COMMENT ON TRIGGER "set_public_esignature_documents_updated_at" ON "public"."esignature_documents"
IS 'trigger to set value of column "updated_at" to current timestamp on row update';
CREATE EXTENSION IF NOT EXISTS pgcrypto;

View File

@@ -0,0 +1 @@
alter table "public"."esignature_documents" drop constraint "esignature_documents_documentid_fkey";

View File

@@ -0,0 +1,5 @@
alter table "public"."esignature_documents"
add constraint "esignature_documents_documentid_fkey"
foreign key ("documentid")
references "public"."documents"
("id") on update restrict on delete restrict;

View File

@@ -0,0 +1 @@
ALTER TABLE "public"."esignature_documents" ALTER COLUMN "recipients" TYPE ARRAY;

View File

@@ -0,0 +1 @@
ALTER TABLE "public"."esignature_documents" ALTER COLUMN "recipients" TYPE json[];

View File

@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."esignature_documents" add column "completed_at" timestamptz
-- null;

View File

@@ -0,0 +1,2 @@
alter table "public"."esignature_documents" add column "completed_at" timestamptz
null;

View File

@@ -0,0 +1,4 @@
comment on column "public"."esignature_documents"."viewed" is E'Tracking the lifecycle of esignature documents. ';
alter table "public"."esignature_documents" alter column "viewed" set default false;
alter table "public"."esignature_documents" alter column "viewed" drop not null;
alter table "public"."esignature_documents" add column "viewed" bool;

View File

@@ -0,0 +1 @@
alter table "public"."esignature_documents" drop column "viewed" cascade;

View File

@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."bodyshops" add column "documenso_api_key" text
-- null;

View File

@@ -0,0 +1,2 @@
alter table "public"."bodyshops" add column "documenso_api_key" text
null;

749
package-lock.json generated
View File

@@ -19,6 +19,8 @@
"@aws-sdk/credential-provider-node": "^3.972.28",
"@aws-sdk/lib-storage": "^3.1020.0",
"@aws-sdk/s3-request-presigner": "^3.1020.0",
"@documenso/sdk-typescript": "^0.8.0",
"@jsreport/nodejs-client": "^4.1.0",
"@opensearch-project/opensearch": "^2.13.0",
"@socket.io/admin-ui": "^0.5.1",
"@socket.io/redis-adapter": "^8.3.0",
@@ -54,6 +56,7 @@
"mustache": "^4.2.0",
"node-persist": "^4.0.4",
"nodemailer": "^6.10.0",
"normalize-url": "^9.0.0",
"pdf-lib": "^1.17.1",
"phone": "^3.1.71",
"query-string": "7.1.3",
@@ -1360,6 +1363,18 @@
"kuler": "^2.0.0"
}
},
"node_modules/@documenso/sdk-typescript": {
"version": "0.8.0",
"resolved": "https://registry.npmjs.org/@documenso/sdk-typescript/-/sdk-typescript-0.8.0.tgz",
"integrity": "sha512-Emzd5j+v8tA8gxtL+M/svVuzSOKMZw3/U4bS8zRoagvQEqkt+XNU2JraPEAJzxTjf3ww6EnlURXydbglBmR7AQ==",
"dependencies": {
"@modelcontextprotocol/sdk": "^1.26.0",
"zod": "^3.25.0 || ^4.0.0"
},
"bin": {
"mcp": "bin/mcp-server.js"
}
},
"node_modules/@esbuild/aix-ppc64": {
"version": "0.27.2",
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.27.2.tgz",
@@ -2196,6 +2211,18 @@
"node": ">=6"
}
},
"node_modules/@hono/node-server": {
"version": "1.19.9",
"resolved": "https://registry.npmjs.org/@hono/node-server/-/node-server-1.19.9.tgz",
"integrity": "sha512-vHL6w3ecZsky+8P5MD+eFfaGTyCeOHUIFYMGpQGbrBTSmNNoxv0if69rEZ5giu36weC5saFuznL411gRX7bJDw==",
"license": "MIT",
"engines": {
"node": ">=18.14.1"
},
"peerDependencies": {
"hono": "^4"
}
},
"node_modules/@humanfs/core": {
"version": "0.19.1",
"resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.1.tgz",
@@ -2303,12 +2330,370 @@
"url": "https://opencollective.com/js-sdsl"
}
},
"node_modules/@jsreport/nodejs-client": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/@jsreport/nodejs-client/-/nodejs-client-4.1.0.tgz",
"integrity": "sha512-QWupUQzMzxWFvY+AlSdUZGlinJv4cKhYmVE9rIe+he7rn4B24tezFmNdnrDcTSFv3hj4x7sTNqpeHT0fItfs5Q==",
"dependencies": {
"axios": "1.13.2",
"concat-stream": "2.0.0",
"mimic-response": "2.1.0"
},
"engines": {
"node": ">=22.18"
}
},
"node_modules/@jsreport/nodejs-client/node_modules/axios": {
"version": "1.13.2",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.13.2.tgz",
"integrity": "sha512-VPk9ebNqPcy5lRGuSlKx752IlDatOjT9paPlm8A7yOuW2Fbvp4X3JznJtT4f0GzGLLiWE9W8onz51SqLYwzGaA==",
"license": "MIT",
"dependencies": {
"follow-redirects": "^1.15.6",
"form-data": "^4.0.4",
"proxy-from-env": "^1.1.0"
}
},
"node_modules/@jsreport/nodejs-client/node_modules/proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==",
"license": "MIT"
},
"node_modules/@kurkle/color": {
"version": "0.3.4",
"resolved": "https://registry.npmjs.org/@kurkle/color/-/color-0.3.4.tgz",
"integrity": "sha512-M5UknZPHRu3DEDWoipU6sE8PdkZ6Z/S+v4dD+Ke8IaNlpdSQah50lz1KtcFBa2vsdOnwbbnxJwVM4wty6udA5w==",
"license": "MIT"
},
"node_modules/@modelcontextprotocol/sdk": {
"version": "1.27.1",
"resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.27.1.tgz",
"integrity": "sha512-sr6GbP+4edBwFndLbM60gf07z0FQ79gaExpnsjMGePXqFcSSb7t6iscpjk9DhFhwd+mTEQrzNafGP8/iGGFYaA==",
"license": "MIT",
"dependencies": {
"@hono/node-server": "^1.19.9",
"ajv": "^8.17.1",
"ajv-formats": "^3.0.1",
"content-type": "^1.0.5",
"cors": "^2.8.5",
"cross-spawn": "^7.0.5",
"eventsource": "^3.0.2",
"eventsource-parser": "^3.0.0",
"express": "^5.2.1",
"express-rate-limit": "^8.2.1",
"hono": "^4.11.4",
"jose": "^6.1.3",
"json-schema-typed": "^8.0.2",
"pkce-challenge": "^5.0.0",
"raw-body": "^3.0.0",
"zod": "^3.25 || ^4.0",
"zod-to-json-schema": "^3.25.1"
},
"engines": {
"node": ">=18"
},
"peerDependencies": {
"@cfworker/json-schema": "^4.1.1",
"zod": "^3.25 || ^4.0"
},
"peerDependenciesMeta": {
"@cfworker/json-schema": {
"optional": true
},
"zod": {
"optional": false
}
}
},
"node_modules/@modelcontextprotocol/sdk/node_modules/accepts": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz",
"integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==",
"license": "MIT",
"dependencies": {
"mime-types": "^3.0.0",
"negotiator": "^1.0.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/@modelcontextprotocol/sdk/node_modules/ajv": {
"version": "8.18.0",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-8.18.0.tgz",
"integrity": "sha512-PlXPeEWMXMZ7sPYOHqmDyCJzcfNrUr3fGNKtezX14ykXOEIvyK81d+qydx89KY5O71FKMPaQ2vBfBFI5NHR63A==",
"license": "MIT",
"dependencies": {
"fast-deep-equal": "^3.1.3",
"fast-uri": "^3.0.1",
"json-schema-traverse": "^1.0.0",
"require-from-string": "^2.0.2"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/epoberezkin"
}
},
"node_modules/@modelcontextprotocol/sdk/node_modules/content-disposition": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-1.0.1.tgz",
"integrity": "sha512-oIXISMynqSqm241k6kcQ5UwttDILMK4BiurCfGEREw6+X9jkkpEe5T9FZaApyLGGOnFuyMWZpdolTXMtvEJ08Q==",
"license": "MIT",
"engines": {
"node": ">=18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/@modelcontextprotocol/sdk/node_modules/cookie-signature": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz",
"integrity": "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==",
"license": "MIT",
"engines": {
"node": ">=6.6.0"
}
},
"node_modules/@modelcontextprotocol/sdk/node_modules/express": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/express/-/express-5.2.1.tgz",
"integrity": "sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==",
"license": "MIT",
"dependencies": {
"accepts": "^2.0.0",
"body-parser": "^2.2.1",
"content-disposition": "^1.0.0",
"content-type": "^1.0.5",
"cookie": "^0.7.1",
"cookie-signature": "^1.2.1",
"debug": "^4.4.0",
"depd": "^2.0.0",
"encodeurl": "^2.0.0",
"escape-html": "^1.0.3",
"etag": "^1.8.1",
"finalhandler": "^2.1.0",
"fresh": "^2.0.0",
"http-errors": "^2.0.0",
"merge-descriptors": "^2.0.0",
"mime-types": "^3.0.0",
"on-finished": "^2.4.1",
"once": "^1.4.0",
"parseurl": "^1.3.3",
"proxy-addr": "^2.0.7",
"qs": "^6.14.0",
"range-parser": "^1.2.1",
"router": "^2.2.0",
"send": "^1.1.0",
"serve-static": "^2.2.0",
"statuses": "^2.0.1",
"type-is": "^2.0.1",
"vary": "^1.1.2"
},
"engines": {
"node": ">= 18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/@modelcontextprotocol/sdk/node_modules/finalhandler": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.1.tgz",
"integrity": "sha512-S8KoZgRZN+a5rNwqTxlZZePjT/4cnm0ROV70LedRHZ0p8u9fRID0hJUZQpkKLzro8LfmC8sx23bY6tVNxv8pQA==",
"license": "MIT",
"dependencies": {
"debug": "^4.4.0",
"encodeurl": "^2.0.0",
"escape-html": "^1.0.3",
"on-finished": "^2.4.1",
"parseurl": "^1.3.3",
"statuses": "^2.0.1"
},
"engines": {
"node": ">= 18.0.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/@modelcontextprotocol/sdk/node_modules/fresh": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz",
"integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/@modelcontextprotocol/sdk/node_modules/http-errors": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz",
"integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==",
"license": "MIT",
"dependencies": {
"depd": "~2.0.0",
"inherits": "~2.0.4",
"setprototypeof": "~1.2.0",
"statuses": "~2.0.2",
"toidentifier": "~1.0.1"
},
"engines": {
"node": ">= 0.8"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/@modelcontextprotocol/sdk/node_modules/jose": {
"version": "6.1.3",
"resolved": "https://registry.npmjs.org/jose/-/jose-6.1.3.tgz",
"integrity": "sha512-0TpaTfihd4QMNwrz/ob2Bp7X04yuxJkjRGi4aKmOqwhov54i6u79oCv7T+C7lo70MKH6BesI3vscD1yb/yzKXQ==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/panva"
}
},
"node_modules/@modelcontextprotocol/sdk/node_modules/json-schema-traverse": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz",
"integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
"license": "MIT"
},
"node_modules/@modelcontextprotocol/sdk/node_modules/media-typer": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.0.tgz",
"integrity": "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/@modelcontextprotocol/sdk/node_modules/merge-descriptors": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz",
"integrity": "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g==",
"license": "MIT",
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/@modelcontextprotocol/sdk/node_modules/mime-types": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz",
"integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==",
"license": "MIT",
"dependencies": {
"mime-db": "^1.54.0"
},
"engines": {
"node": ">=18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/@modelcontextprotocol/sdk/node_modules/negotiator": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz",
"integrity": "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/@modelcontextprotocol/sdk/node_modules/qs": {
"version": "6.15.0",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.15.0.tgz",
"integrity": "sha512-mAZTtNCeetKMH+pSjrb76NAM8V9a05I9aBZOHztWy/UqcJdQYNsf59vrRKWnojAT9Y+GbIvoTBC++CPHqpDBhQ==",
"license": "BSD-3-Clause",
"dependencies": {
"side-channel": "^1.1.0"
},
"engines": {
"node": ">=0.6"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/@modelcontextprotocol/sdk/node_modules/send": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/send/-/send-1.2.1.tgz",
"integrity": "sha512-1gnZf7DFcoIcajTjTwjwuDjzuz4PPcY2StKPlsGAQ1+YH20IRVrBaXSWmdjowTJ6u8Rc01PoYOGHXfP1mYcZNQ==",
"license": "MIT",
"dependencies": {
"debug": "^4.4.3",
"encodeurl": "^2.0.0",
"escape-html": "^1.0.3",
"etag": "^1.8.1",
"fresh": "^2.0.0",
"http-errors": "^2.0.1",
"mime-types": "^3.0.2",
"ms": "^2.1.3",
"on-finished": "^2.4.1",
"range-parser": "^1.2.1",
"statuses": "^2.0.2"
},
"engines": {
"node": ">= 18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/@modelcontextprotocol/sdk/node_modules/serve-static": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.1.tgz",
"integrity": "sha512-xRXBn0pPqQTVQiC8wyQrKs2MOlX24zQ0POGaj0kultvoOCstBQM5yvOhAVSUwOMjQtTvsPWoNCHfPGwaaQJhTw==",
"license": "MIT",
"dependencies": {
"encodeurl": "^2.0.0",
"escape-html": "^1.0.3",
"parseurl": "^1.3.3",
"send": "^1.2.0"
},
"engines": {
"node": ">= 18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/@modelcontextprotocol/sdk/node_modules/statuses": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz",
"integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/@modelcontextprotocol/sdk/node_modules/type-is": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-2.0.1.tgz",
"integrity": "sha512-OZs6gsjF4vMp32qrCbiVSkrFmXtG/AZhY3t0iAMrMBiAZyV9oALtXO8hsrHbMXF9x6L3grlFuwW2oAz7cav+Gw==",
"license": "MIT",
"dependencies": {
"content-type": "^1.0.5",
"media-typer": "^1.1.0",
"mime-types": "^3.0.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/@msgpackr-extract/msgpackr-extract-darwin-arm64": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-darwin-arm64/-/msgpackr-extract-darwin-arm64-3.0.3.tgz",
@@ -4183,6 +4568,45 @@
"url": "https://github.com/sponsors/epoberezkin"
}
},
"node_modules/ajv-formats": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz",
"integrity": "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==",
"license": "MIT",
"dependencies": {
"ajv": "^8.0.0"
},
"peerDependencies": {
"ajv": "^8.0.0"
},
"peerDependenciesMeta": {
"ajv": {
"optional": true
}
}
},
"node_modules/ajv-formats/node_modules/ajv": {
"version": "8.18.0",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-8.18.0.tgz",
"integrity": "sha512-PlXPeEWMXMZ7sPYOHqmDyCJzcfNrUr3fGNKtezX14ykXOEIvyK81d+qydx89KY5O71FKMPaQ2vBfBFI5NHR63A==",
"license": "MIT",
"dependencies": {
"fast-deep-equal": "^3.1.3",
"fast-uri": "^3.0.1",
"json-schema-traverse": "^1.0.0",
"require-from-string": "^2.0.2"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/epoberezkin"
}
},
"node_modules/ajv-formats/node_modules/json-schema-traverse": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz",
"integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
"license": "MIT"
},
"node_modules/ansi-colors": {
"version": "4.1.3",
"resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz",
@@ -4641,6 +5065,100 @@
"node": "*"
}
},
"node_modules/body-parser": {
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.2.tgz",
"integrity": "sha512-oP5VkATKlNwcgvxi0vM0p/D3n2C3EReYVX+DNYs5TjZFn/oQt2j+4sVJtSMr18pdRr8wjTcBl6LoV+FUwzPmNA==",
"license": "MIT",
"dependencies": {
"bytes": "^3.1.2",
"content-type": "^1.0.5",
"debug": "^4.4.3",
"http-errors": "^2.0.0",
"iconv-lite": "^0.7.0",
"on-finished": "^2.4.1",
"qs": "^6.14.1",
"raw-body": "^3.0.1",
"type-is": "^2.0.1"
},
"engines": {
"node": ">=18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/body-parser/node_modules/iconv-lite": {
"version": "0.7.2",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.2.tgz",
"integrity": "sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw==",
"license": "MIT",
"dependencies": {
"safer-buffer": ">= 2.1.2 < 3.0.0"
},
"engines": {
"node": ">=0.10.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/body-parser/node_modules/media-typer": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.0.tgz",
"integrity": "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/body-parser/node_modules/mime-types": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz",
"integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==",
"license": "MIT",
"dependencies": {
"mime-db": "^1.54.0"
},
"engines": {
"node": ">=18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/body-parser/node_modules/qs": {
"version": "6.15.0",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.15.0.tgz",
"integrity": "sha512-mAZTtNCeetKMH+pSjrb76NAM8V9a05I9aBZOHztWy/UqcJdQYNsf59vrRKWnojAT9Y+GbIvoTBC++CPHqpDBhQ==",
"license": "BSD-3-Clause",
"dependencies": {
"side-channel": "^1.1.0"
},
"engines": {
"node": ">=0.6"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/body-parser/node_modules/type-is": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-2.0.1.tgz",
"integrity": "sha512-OZs6gsjF4vMp32qrCbiVSkrFmXtG/AZhY3t0iAMrMBiAZyV9oALtXO8hsrHbMXF9x6L3grlFuwW2oAz7cav+Gw==",
"license": "MIT",
"dependencies": {
"content-type": "^1.0.5",
"media-typer": "^1.1.0",
"mime-types": "^3.0.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/boolbase": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz",
@@ -6370,6 +6888,27 @@
"node": ">=0.8.x"
}
},
"node_modules/eventsource": {
"version": "3.0.7",
"resolved": "https://registry.npmjs.org/eventsource/-/eventsource-3.0.7.tgz",
"integrity": "sha512-CRT1WTyuQoD771GW56XEZFQ/ZoSfWid1alKGDYMmkt2yl8UXrVR4pspqWNEcqKvVIzg6PAltWjxcSSPrboA4iA==",
"license": "MIT",
"dependencies": {
"eventsource-parser": "^3.0.1"
},
"engines": {
"node": ">=18.0.0"
}
},
"node_modules/eventsource-parser": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/eventsource-parser/-/eventsource-parser-3.0.6.tgz",
"integrity": "sha512-Vo1ab+QXPzZ4tCa8SwIHJFaSzy4R6SHf7BY79rFBDf0idraZWAkYrDjDj8uWaSm3S2TK+hJ7/t1CEmZ7jXw+pg==",
"license": "MIT",
"engines": {
"node": ">=18.0.0"
}
},
"node_modules/expect-type": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.3.0.tgz",
@@ -6426,6 +6965,24 @@
"url": "https://opencollective.com/express"
}
},
"node_modules/express-rate-limit": {
"version": "8.2.1",
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-8.2.1.tgz",
"integrity": "sha512-PCZEIEIxqwhzw4KF0n7QF4QqruVTcF73O5kFKUnGOyjbCCgizBBiFaYpd/fnBLUMPw/BWw9OsiN7GgrNYr7j6g==",
"license": "MIT",
"dependencies": {
"ip-address": "10.0.1"
},
"engines": {
"node": ">= 16"
},
"funding": {
"url": "https://github.com/sponsors/express-rate-limit"
},
"peerDependencies": {
"express": ">= 4.11"
}
},
"node_modules/express/node_modules/body-parser": {
"version": "1.20.3",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.3.tgz",
@@ -6548,6 +7105,22 @@
"integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==",
"license": "MIT"
},
"node_modules/fast-uri": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.0.tgz",
"integrity": "sha512-iPeeDKJSWf4IEOasVVrknXpaBV0IApz/gp7S2bb7Z4Lljbl2MGJRqInZiUrQwV16cpzw/D3S5j5Julj/gT52AA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/fastify"
},
{
"type": "opencollective",
"url": "https://opencollective.com/fastify"
}
],
"license": "BSD-3-Clause"
},
"node_modules/fast-xml-builder": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/fast-xml-builder/-/fast-xml-builder-1.1.4.tgz",
@@ -7429,6 +8002,15 @@
"node": ">= 0.4"
}
},
"node_modules/hono": {
"version": "4.12.3",
"resolved": "https://registry.npmjs.org/hono/-/hono-4.12.3.tgz",
"integrity": "sha512-SFsVSjp8sj5UumXOOFlkZOG6XS9SJDKw0TbwFeV+AJ8xlST8kxK5Z/5EYa111UY8732lK2S/xB653ceuaoGwpg==",
"license": "MIT",
"engines": {
"node": ">=16.9.0"
}
},
"node_modules/hpagent": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/hpagent/-/hpagent-1.2.0.tgz",
@@ -7687,6 +8269,15 @@
"url": "https://opencollective.com/ioredis"
}
},
"node_modules/ip-address": {
"version": "10.0.1",
"resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.0.1.tgz",
"integrity": "sha512-NWv9YLW4PoW2B7xtzaS3NCot75m6nK7Icdv0o3lfMceJVRfSoQwqD4wEH5rLwoKJwUiZ/rfpiVBhnaF0FK4HoA==",
"license": "MIT",
"engines": {
"node": ">= 12"
}
},
"node_modules/ipaddr.js": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
@@ -7928,6 +8519,12 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/is-promise": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz",
"integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==",
"license": "MIT"
},
"node_modules/is-regex": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.2.1.tgz",
@@ -8201,6 +8798,12 @@
"dev": true,
"license": "MIT"
},
"node_modules/json-schema-typed": {
"version": "8.0.2",
"resolved": "https://registry.npmjs.org/json-schema-typed/-/json-schema-typed-8.0.2.tgz",
"integrity": "sha512-fQhoXdcvc3V28x7C7BMs4P5+kNlgUURe2jmUT1T//oBRMDrqy1QPelJimwZGo7Hg9VPV3EQV5Bnq4hbFy2vetA==",
"license": "BSD-2-Clause"
},
"node_modules/json-stable-stringify-without-jsonify": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz",
@@ -8700,6 +9303,18 @@
"node": ">= 0.6"
}
},
"node_modules/mimic-response": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-2.1.0.tgz",
"integrity": "sha512-wXqjST+SLt7R009ySCglWBCFpjUygmCIfD790/kVbiGmUgfYGuB14PiTd5DwVxSV4NcYHjzMkoj5LjQZwTQLEA==",
"license": "MIT",
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/minimalistic-assert": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz",
@@ -8989,6 +9604,18 @@
"node": ">=0.10.0"
}
},
"node_modules/normalize-url": {
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-9.0.0.tgz",
"integrity": "sha512-z9nC87iaZXXySbWWtTHfCFJyFvKaUAW6lODhikG7ILSbVgmwuFjUqkgnheHvAUcGedO29e2QGBRXMUD64aurqQ==",
"license": "MIT",
"engines": {
"node": ">=20"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/notepack.io": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/notepack.io/-/notepack.io-3.0.1.tgz",
@@ -9452,6 +10079,15 @@
"url": "https://github.com/sponsors/jonschlinkert"
}
},
"node_modules/pkce-challenge": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/pkce-challenge/-/pkce-challenge-5.0.1.tgz",
"integrity": "sha512-wQ0b/W4Fr01qtpHlqSqspcj3EhBvimsdh0KlHhH8HRZnMsEa0ea2fTULOXOS9ccQr3om+GcGRk4e+isrZWV8qQ==",
"license": "MIT",
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/possible-typed-array-names": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.1.0.tgz",
@@ -9687,6 +10323,66 @@
"node": ">= 0.6"
}
},
"node_modules/raw-body": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.2.tgz",
"integrity": "sha512-K5zQjDllxWkf7Z5xJdV0/B0WTNqx6vxG70zJE4N0kBs4LovmEYWJzQGxC9bS9RAKu3bgM40lrd5zoLJ12MQ5BA==",
"license": "MIT",
"dependencies": {
"bytes": "~3.1.2",
"http-errors": "~2.0.1",
"iconv-lite": "~0.7.0",
"unpipe": "~1.0.0"
},
"engines": {
"node": ">= 0.10"
}
},
"node_modules/raw-body/node_modules/http-errors": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz",
"integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==",
"license": "MIT",
"dependencies": {
"depd": "~2.0.0",
"inherits": "~2.0.4",
"setprototypeof": "~1.2.0",
"statuses": "~2.0.2",
"toidentifier": "~1.0.1"
},
"engines": {
"node": ">= 0.8"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/raw-body/node_modules/iconv-lite": {
"version": "0.7.2",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.2.tgz",
"integrity": "sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw==",
"license": "MIT",
"dependencies": {
"safer-buffer": ">= 2.1.2 < 3.0.0"
},
"engines": {
"node": ">=0.10.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/raw-body/node_modules/statuses": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz",
"integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/react-is": {
"version": "16.13.1",
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
@@ -9852,6 +10548,15 @@
"node": ">=0.10.0"
}
},
"node_modules/require-from-string": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz",
"integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==",
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/resolve": {
"version": "2.0.0-next.5",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-2.0.0-next.5.tgz",
@@ -10044,6 +10749,32 @@
"fsevents": "~2.3.2"
}
},
"node_modules/router": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz",
"integrity": "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==",
"license": "MIT",
"dependencies": {
"debug": "^4.4.0",
"depd": "^2.0.0",
"is-promise": "^4.0.0",
"parseurl": "^1.3.3",
"path-to-regexp": "^8.0.0"
},
"engines": {
"node": ">= 18"
}
},
"node_modules/router/node_modules/path-to-regexp": {
"version": "8.3.0",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.3.0.tgz",
"integrity": "sha512-7jdwVIRtsP8MYpdXSwOS0YdD0Du+qOoF/AEPIt88PcCFrZCzx41oxku1jD88hZBwbNUIEfpqvuhjFaMAqMTWnA==",
"license": "MIT",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/rsa-pem-from-mod-exp": {
"version": "0.8.6",
"resolved": "https://registry.npmjs.org/rsa-pem-from-mod-exp/-/rsa-pem-from-mod-exp-0.8.6.tgz",
@@ -12310,6 +13041,24 @@
"engines": {
"node": ">= 14"
}
},
"node_modules/zod": {
"version": "4.3.6",
"resolved": "https://registry.npmjs.org/zod/-/zod-4.3.6.tgz",
"integrity": "sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/colinhacks"
}
},
"node_modules/zod-to-json-schema": {
"version": "3.25.1",
"resolved": "https://registry.npmjs.org/zod-to-json-schema/-/zod-to-json-schema-3.25.1.tgz",
"integrity": "sha512-pM/SU9d3YAggzi6MtR4h7ruuQlqKtad8e9S0fmxcMi+ueAK5Korys/aWcV9LIIHTVbj01NdzxcnXSN+O74ZIVA==",
"license": "ISC",
"peerDependencies": {
"zod": "^3.25 || ^4"
}
}
}
}

View File

@@ -28,6 +28,8 @@
"@aws-sdk/credential-provider-node": "^3.972.28",
"@aws-sdk/lib-storage": "^3.1020.0",
"@aws-sdk/s3-request-presigner": "^3.1020.0",
"@documenso/sdk-typescript": "^0.8.0",
"@jsreport/nodejs-client": "^4.1.0",
"@opensearch-project/opensearch": "^2.13.0",
"@socket.io/admin-ui": "^0.5.1",
"@socket.io/redis-adapter": "^8.3.0",
@@ -63,6 +65,7 @@
"mustache": "^4.2.0",
"node-persist": "^4.0.4",
"nodemailer": "^6.10.0",
"normalize-url": "^9.0.0",
"pdf-lib": "^1.17.1",
"phone": "^3.1.71",
"query-string": "7.1.3",

View File

@@ -130,6 +130,7 @@ const applyRoutes = ({ app }) => {
app.use("/ai", require("./server/routes/aiRoutes"));
app.use("/chatter", require("./server/routes/chatterRoutes"));
app.use("/esign", require("./server/routes/esignRoutes"));
// Default route for forbidden access
app.get("/", (req, res) => {

488
server/esign/esign-new.js Normal file
View File

@@ -0,0 +1,488 @@
const { Documenso } = require("@documenso/sdk-typescript");
const axios = require("axios");
const { jsrAuthString } = require("../utils/utils");
const logger = require("../utils/logger");
//Need to pull the key dynamically to send documents.
const JSR_SERVER = process.env.JSR_URL || "https://reports.imex.online";
const jsreport = require("@jsreport/nodejs-client");
const { QUERY_JOB_FOR_SIGNATURE, INSERT_ESIGNATURE_DOCUMENT, DISTRIBUTE_ESIGNATURE_DOCUMENT, QUERY_ESIGNATURE_BY_EXTERNAL_ID, UPDATE_ESIGNATURE_DOCUMENT, QUERY_DOCUMENSO_KEY, INSERT_ESIG_AUDIT_TRAIL } = require("../graphql-client/queries");
const _ = require("lodash");
function parseJsonField(value, fallback = null) {
if (value === undefined || value === null) {
return fallback;
}
if (typeof value !== "string") {
return value;
}
try {
return JSON.parse(value);
} catch {
return fallback;
}
}
function getDefaultEsignData({ esigData, bodyshop, fileName }) {
const fallbackTitle = fileName || `Esign request from ${bodyshop.shopname}`;
return {
...esigData,
title: esigData?.title || fallbackTitle,
subject: esigData?.subject || `Esign request from ${bodyshop.shopname}`,
message: esigData?.message || `Please review and sign the document from ${bodyshop.shopname}.`
};
}
function createClientError(message, statusCode = 400) {
const error = new Error(message);
error.statusCode = statusCode;
return error;
}
function isValidEmail(email) {
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
}
function getJobOwnerName(jobData, email) {
const ownerName = [jobData?.ownr_fn, jobData?.ownr_ln].filter(Boolean).join(" ").trim();
return ownerName || jobData?.ownr_co_nm || email;
}
function getJobOwnerRecipients(jobData) {
const ownerEmail = jobData?.ownr_ea?.trim();
if (!ownerEmail) {
throw createClientError("Job owner email is required before sending an e-signature request.");
}
if (!isValidEmail(ownerEmail)) {
throw createClientError(`Job owner email "${ownerEmail}" is not valid.`);
}
return [
{
email: ownerEmail,
name: getJobOwnerName(jobData, ownerEmail),
role: "SIGNER"
}
];
}
async function getDocumensoClient({ bodyshopid, req }) {
const client = req.userGraphQLClient;
const { bodyshops_by_pk: { documenso_api_key } } = await client.request(QUERY_DOCUMENSO_KEY, { bodyshopid });
return new Documenso({
apiKey: documenso_api_key,//Done on a by team basis,
serverURL: "https://sign.imex.online/api/v2",
});
}
async function createEsignDocumentFromPdf({ req, bodyshop, pdfBuffer, esigData, fileName }) {
const resolvedEsigData = getDefaultEsignData({ esigData, bodyshop, fileName });
const fileBlob = new Blob([pdfBuffer], { type: "application/pdf" });
const jobid = req.body.jobid;
const client = req.userGraphQLClient;
const { jobs_by_pk: jobData } = await client.request(QUERY_JOB_FOR_SIGNATURE, { jobid });
const recipients = getJobOwnerRecipients(jobData);
const documenso = await getDocumensoClient({ bodyshopid: bodyshop.id, req })
const createDocumentResponse = await documenso.documents.create({
payload: {
title: resolvedEsigData.title,
externalId: `${jobid}|${req.user?.email}`,
recipients,
meta: {
timezone: bodyshop.timezone,
dateFormat: "MM/dd/yyyy hh:mm a",
language: "en",
subject: resolvedEsigData.subject,
message: resolvedEsigData.message,
}
},
file: fileBlob
});
const documentResult = await documenso.documents.get({
documentId: createDocumentResponse.id,
});
if (resolvedEsigData?.fields && resolvedEsigData.fields.length > 0) {
try {
await documenso.envelopes.fields.createMany({
envelopeId: createDocumentResponse.envelopeId,
data: resolvedEsigData.fields.map(sigField => ({ ...sigField, recipientId: documentResult.recipients[0].id, }))
});
} catch (error) {
logger.log(`esig-new-fields-error`, "ERROR", "esig", "api", {
message: error.message, stack: error.stack,
body: req.body
});
}
}
const presignToken = await documenso.embedding.embeddingPresignCreateEmbeddingPresignToken({});
await client.request(INSERT_ESIGNATURE_DOCUMENT, {
audit: {
jobid,
bodyshopid: bodyshop.id,
operation: `Esignature document created. Subject: ${resolvedEsigData.subject || "No subject"}, Message: ${resolvedEsigData.message || "No message"}. Document ID: ${createDocumentResponse.id} Envlope ID: ${createDocumentResponse.envelopeId}`,
useremail: req.user?.email,
type: 'esig-create'
},
esig: {
jobid,
external_document_id: createDocumentResponse.id.toString(),
subject: resolvedEsigData.subject || "No subject",
message: resolvedEsigData.message || "No message",
title: resolvedEsigData.title || "No title",
status: "DRAFT",
recipients: recipients,
}
});
return {
token: presignToken.token,
documentId: createDocumentResponse.id,
envelopeId: createDocumentResponse.envelopeId
};
}
async function distributeDocument(req, res) {
try {
const client = req.userGraphQLClient;
const { documentId, bodyshopid } = req.body;
const documenso = await getDocumensoClient({ bodyshopid, req })
const distributeResult = await documenso.documents.distribute({
documentId,
});
await client.request(DISTRIBUTE_ESIGNATURE_DOCUMENT, {
external_document_id: documentId.toString(),
esig_update: {
status: "SENT"
},
audit: {
jobid: req.body.jobid,
bodyshopid: req.body.bodyshopid,
operation: `Esignature document with title ${distributeResult.title} (ID: ${documentId}) distributed to recipients.`,
useremail: req.user?.email,
type: 'esig-distribute'
}
})
res.json({ success: true, distributeResult });
} catch (error) {
logger.log(`esig-distribute-error`, "ERROR", "esig", "api", {
message: error.message, stack: error.stack,
body: req.body
});
res.status(500).json({ error: "An error occurred while distributing the document.", message: error.message });
}
}
async function redistributeDocument(req, res) {
try {
const client = req.userGraphQLClient;
const { documentId, bodyshopid } = req.body;
const documenso = await getDocumensoClient({ bodyshopid, req })
const document = await documenso.documents.get({
documentId: parseInt(documentId)
});
const distributeResult = await documenso.documents.redistribute({
documentId: parseInt(documentId),
recipients: document.recipients.filter(r => r.signingStatus === "NOT_SIGNED").map(r => r.id)
});
await client.request(INSERT_ESIG_AUDIT_TRAIL, {
obj: {
jobid: req.body.jobid,
bodyshopid: req.body.bodyshopid,
operation: `Esignature document with title ${distributeResult.title} (ID: ${documentId}) redistributed to recipients.`,
useremail: req.user?.email,
type: 'esig-redistribute'
}
})
res.json({ success: true, distributeResult });
} catch (error) {
logger.log(`esig-redistribute-error`, "ERROR", "esig", "api", {
message: error.message, stack: error.stack,
body: req.body
});
res.status(500).json({ error: "An error occurred while redistributing the document.", message: error.message });
}
}
async function deleteDocument(req, res) {
try {
const client = req.userGraphQLClient;
const { documentId, bodyshopid } = req.body;
const { esignature_documents } = await client.request(QUERY_ESIGNATURE_BY_EXTERNAL_ID, { external_document_id: documentId.toString() });
if (!esignature_documents || esignature_documents.length === 0) {
//return res.status(404).json({ error: "Document not found" });
}
const documenso = await getDocumensoClient({ bodyshopid, req })
const deleteResult = await documenso.documents.delete({
documentId: (documentId)
});
await client.request(UPDATE_ESIGNATURE_DOCUMENT, {
external_document_id: documentId.toString(),
esig_update: {
status: "DELETED"
}
})
res.json({ success: true, deleteResult });
} catch (error) {
logger.log(`esig-delete-error`, "ERROR", "esig", "api", {
message: error.message, stack: error.stack,
body: req.body
});
res.status(500).json({ error: "An error occurred while deleting the document." });
}
}
async function viewDocument(req, res) {
try {
const { documentId, bodyshopid } = req.body;
const documenso = await getDocumensoClient({ bodyshopid, req })
const document = await documenso.document.documentDownload({
documentId: parseInt(documentId)
});
res.json({ success: true, document });
} catch (error) {
logger.log(`esig-view-error`, "ERROR", "esig", "api", {
message: error.message, stack: error.stack,
body: req.body
});
res.status(500).json({ error: "An error occurred while retrieving the document.", message: error.message });
}
}
async function newEsignDocument(req, res) {
try {
const client = req.userGraphQLClient;
const { bodyshop } = req.body;
const { pdf: fileBuffer, esigData } = await RenderTemplate({ client, req });
const result = await createEsignDocumentFromPdf({
req,
bodyshop,
pdfBuffer: fileBuffer,
esigData
});
res.json(result);
}
catch (error) {
logger.log(`esig-new-error`, "ERROR", "esig", "api", {
message: error.message, stack: error.stack,
body: _.omit(req.body, ["bodyshop"]) // bodyshop can be large, so we omit it from the logs
});
res.status(error.statusCode || 500).json({ error: "An error occurred while creating the e-sign document.", message: error.message });
}
}
async function newCustomEsignDocument(req, res) {
try {
const bodyshop = parseJsonField(req.body.bodyshop, req.body.bodyshop);
const esigData = parseJsonField(req.body.esigData, {});
const uploadedDocument = req.file;
if (!uploadedDocument?.buffer) {
return res.status(400).json({ error: "A PDF document is required." });
}
if (uploadedDocument.mimetype !== "application/pdf") {
return res.status(400).json({ error: "Only PDF documents can be used for e-signature." });
}
req.body.bodyshop = bodyshop;
const fileName = uploadedDocument.originalname?.replace(/\.[^.]+$/, "") || undefined;
const result = await createEsignDocumentFromPdf({
req,
bodyshop,
pdfBuffer: uploadedDocument.buffer,
esigData,
fileName
});
res.json(result);
}
catch (error) {
logger.log(`esig-new-custom-error`, "ERROR", "esig", "api", {
message: error.message, stack: error.stack,
body: _.omit(req.body, ["bodyshop"]) // bodyshop can be large, so we omit it from the logs
});
res.status(error.statusCode || 500).json({ error: "An error occurred while creating the custom e-sign document.", message: error.message });
}
}
async function RenderTemplate({ req }) {
const jsrAuth = jsrAuthString()
const jsreportClient = new jsreport(JSR_SERVER, process.env.JSR_USER, process.env.JSR_PASSWORD);
const { templateObject, bodyshop } = req.body;
let { contextData, useShopSpecificTemplate, shopSpecificFolder, esigData } = await fetchContextData({ templateObject, jsrAuth, req });
const { ignoreCustomMargins } = { ignoreCustomMargins: false }// Templates[templateObject.name];
let reportRequest = {
template: {
name: useShopSpecificTemplate ? `/${bodyshop.imexshopid}/${templateObject.name}` : `/${templateObject.name}`,
recipe: "chrome-pdf",
...(!ignoreCustomMargins && {
chrome: {
marginTop:
bodyshop.logo_img_path &&
bodyshop.logo_img_path.headerMargin &&
bodyshop.logo_img_path.headerMargin > 36
? bodyshop.logo_img_path.headerMargin
: "36px",
marginBottom:
bodyshop.logo_img_path &&
bodyshop.logo_img_path.footerMargin &&
bodyshop.logo_img_path.footerMargin > 50
? bodyshop.logo_img_path.footerMargin
: "50px"
}
}),
},
data: {
...contextData,
...templateObject.variables,
...templateObject.context,
headerpath: shopSpecificFolder ? `/${bodyshop.imexshopid}/header.html` : `/GENERIC/header.html`,
footerpath: shopSpecificFolder ? `/${bodyshop.imexshopid}/footer.html` : `/GENERIC/footer.html`,
bodyshop: bodyshop,
esignature: true,
filters: templateObject?.filters,
sorters: templateObject?.sorters,
offset: bodyshop.timezone, //dayjs().utcOffset(),
defaultSorters: templateObject?.defaultSorters
}
};
const render = await jsreportClient.render(reportRequest);
//Check render object and download. It should be the PDF?
const pdfBuffer = await render.body()
return { pdf: pdfBuffer, esigData }
}
const fetchContextData = async ({ templateObject, jsrAuth, req, }) => {
const { bodyshop } = req.body
const folders = await axios.get(`${JSR_SERVER}/odata/folders`, {
headers: { Authorization: jsrAuth }
});
const shopSpecificFolder = folders.data.value.find((f) => f.name === bodyshop.imexshopid);
const jsReportQueries = await axios.get(
`${JSR_SERVER}/odata/assets?$filter=name eq '${templateObject.name}.query'`,
{ headers: { Authorization: jsrAuth } }
);
const jsReportEsig = await axios.get(
`${JSR_SERVER}/odata/assets?$filter=name eq '${templateObject.name}.esig'`,
{ headers: { Authorization: jsrAuth } }
);
let templateQueryToExecute;
let esigData;
let useShopSpecificTemplate = false;
// let shopSpecificTemplate;
if (shopSpecificFolder) {
let shopSpecificTemplate = jsReportQueries.data.value.find(
(f) => f?.folder?.shortid === shopSpecificFolder.shortid
);
if (shopSpecificTemplate) {
useShopSpecificTemplate = true;
templateQueryToExecute = atob(shopSpecificTemplate.content);
}
let shopSpecificEsig = jsReportEsig.data.value.find(
(f) => f?.folder?.shortid === shopSpecificFolder.shortid
);
if (shopSpecificEsig) {
esigData = (atob(shopSpecificEsig.content));
}
}
if (!templateQueryToExecute) {
const generalTemplate = jsReportQueries.data.value.find((f) => !f.folder);
useShopSpecificTemplate = false;
templateQueryToExecute = atob(generalTemplate.content);
}
if (!esigData) {
const generalTemplate = jsReportEsig.data.value.find((f) => !f.folder);
useShopSpecificTemplate = false;
if (generalTemplate && generalTemplate.content) {
esigData = atob(generalTemplate?.content);
}
}
const client = req.userGraphQLClient;
// In the print center, we will never have sorters or filters.
// We have no template filters or sorters, so we can just execute the query and return the data
// if (!hasFilters && !hasSorters && !hasDefaultSorters) {
let contextData = {};
if (templateQueryToExecute) {
const data = await client.request(
templateQueryToExecute,
templateObject.variables,
);
contextData = data;
}
let parsedEsigData
try {
parsedEsigData = esigData ? JSON.parse(esigData) : null;
} catch (error) {
logger.log(`esig-data-parse-error`, "ERROR", "esig", "api", {
message: error.message, stack: error.stack,
esigData,
body: req.body
});
parsedEsigData = {}
}
return {
contextData,
useShopSpecificTemplate,
shopSpecificFolder,
esigData: parsedEsigData
};
// }
// return await generateTemplate(templateQueryToExecute, templateObject, useShopSpecificTemplate, shopSpecificFolder);
};
module.exports = {
newEsignDocument,
newCustomEsignDocument,
distributeDocument,
redistributeDocument,
deleteDocument,
viewDocument,
getDocumensoClient
}

337
server/esign/webhook.js Normal file
View File

@@ -0,0 +1,337 @@
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,
GET_DOCUMENSO_KEY_BY_JOBID
} = require("../graphql-client/queries");
const replaceAccents = require("../utils/replaceAccents");
const { uploadFileBuffer } = require("../media/imgproxy-media");
const {
dispatchEsignDocumentOpenedNotification,
dispatchEsignDocumentCompletedNotification,
dispatchEsignDocumentUploadFailedNotification
} = require("../notifications/esignNotifications");
const axios = require("axios");
const normalizeUrl = require("normalize-url");
const client = require("../graphql-client/graphql-client").client;
/**
* Enumeration of webhook event types received from the e-signature service. These events represent different stages in
* the document signing process, such as when a document is created, sent, opened, signed, completed, rejected,
* cancelled, or when a reminder is sent. This enumeration is used to handle incoming webhook events and trigger
* appropriate actions based on the event type.
* @type {{DOCUMENT_CREATED: string, DOCUMENT_SENT: string, DOCUMENT_COMPLETED: string, DOCUMENT_REJECTED: string, DOCUMENT_CANCELLED: string, DOCUMENT_OPENED: string, DOCUMENT_SIGNED: string, DOCUMENT_REMINDER_SENT: string}}
*/
const webhookTypeEnums = {
DOCUMENT_CREATED: "DOCUMENT_CREATED",
DOCUMENT_SENT: "DOCUMENT_SENT",
DOCUMENT_COMPLETED: "DOCUMENT_COMPLETED",
DOCUMENT_REJECTED: "DOCUMENT_REJECTED",
DOCUMENT_CANCELLED: "DOCUMENT_CANCELLED",
DOCUMENT_OPENED: "DOCUMENT_OPENED",
DOCUMENT_SIGNED: "DOCUMENT_SIGNED",
DOCUMENT_REMINDER_SENT: "DOCUMENT_REMINDER_SENT"
};
/**
* Safely dispatches e-sign notifications by catching and logging any errors that occur during the dispatch process.
* This ensures that failures in notification dispatch do not affect the main flow of processing webhook events.
* The function takes an object containing the promise returned by the notification dispatch function, the event name,
* job ID, and document ID for logging purposes.
* @param param0
* @param param0.promise
* @param param0.eventName
* @param param0.jobid
* @param param0.documentId
*/
function dispatchEsignNotificationSafely({ promise, eventName, jobid, documentId }) {
promise.catch((error) => {
logger.log("esig-notification-dispatch-error", "ERROR", "notifications", "api", {
eventName,
jobid,
documentId,
message: error.message,
stack: error.stack
});
});
}
/**
* Handles incoming webhook events from the e-signature service. It processes different event types such as document
* opened, completed, rejected, etc., updates the document status in the database accordingly, and dispatches
* notifications to users. The function also includes error handling to log any issues that occur during processing and
* ensure a proper response is sent back to the webhook sender.
* @param req
* @param res
* @returns {Promise<void>}
*/
async function esignWebhook(req, res) {
try {
const message = req.body;
const documentPayload = message.payload || message.payload?.payload || {};
const externalId = documentPayload.externalId || documentPayload.payload?.externalId || "";
const [jobid, uploadedBy] = externalId.split("|");
logger.log(`esig-webhook-received`, "DEBUG", "redis", "api", {
event: message.event,
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_REMINDER_SENT:
break;
case webhookTypeEnums.DOCUMENT_OPENED:
await client.request(UPDATE_ESIGNATURE_DOCUMENT, {
external_document_id: documentId,
esig_update: {
status: "OPENED",
opened: true
}
});
dispatchEsignNotificationSafely({
promise: dispatchEsignDocumentOpenedNotification({
jobId: jobid,
documentId,
title: documentPayload.title,
uploadedBy,
logger
}),
eventName: webhookTypeEnums.DOCUMENT_OPENED,
jobid,
documentId
});
break;
case webhookTypeEnums.DOCUMENT_REJECTED:
await client.request(UPDATE_ESIGNATURE_DOCUMENT, {
external_document_id: documentId,
esig_update: {
status: "REJECTED",
rejected: true
}
});
break;
case webhookTypeEnums.DOCUMENT_CREATED:
//This is largely a throwaway event we know it was created.
break;
case webhookTypeEnums.DOCUMENT_COMPLETED:
await handleDocumentCompleted(message.payload);
break;
case webhookTypeEnums.DOCUMENT_SIGNED:
await client.request(UPDATE_ESIGNATURE_DOCUMENT, {
external_document_id: documentId,
esig_update: {
status: "SIGNED"
}
});
break;
default:
res.status(200).json({ message: "Unsupported event type." });
logger.log(`esig-webhook-received-unknown`, "ERROR", "redis", "api", {
event: message.event,
body: message
});
return;
}
logger.log(`esig-webhook-processed`, "INFO", "redis", "api", {
event: message.event,
documentId: message.payload?.payload?.id,
jobid: message.payload?.payload?.externalId?.split("|")[0] || null
});
res.sendStatus(200);
} catch (error) {
logger.log(`esig-webhook-error`, "ERROR", "redis", "api", {
message: error.message,
stack: error.stack,
body: req.body
});
res.status(500).json({ message: "Error processing webhook event.", error: error.message });
}
}
/**
* Handles the processing of a document completion event. This includes downloading the completed document from the
* e-signature service, uploading it to either a local media server or S3 depending on the bodyshop configuration,
* updating the document record in the database, and dispatching a notification about the document completion.
* The function also includes error handling to log any issues that occur during processing.
* @param payload
* @returns {Promise<void>}
*/
async function handleDocumentCompleted(payload) {
try {
//Split the external id to get the uploaded user.
const [jobid, uploaded_by] = payload.externalId.split("|");
if (!jobid || !uploaded_by) {
throw new Error(`Invalid externalId format. Expected "jobid|uploaded_by", got "${payload.externalId}"`);
}
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
});
const response = await fetch(document.downloadUrl);
const arrayBuffer = await response.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);
let key = `${jobs_by_pk.bodyshop.id}/${jobs_by_pk.id}/${replaceAccents(document.filename).replace(/[^A-Z0-9]+/gi, "_")}-${new Date().getTime()}.pdf`;
const notifyUploadFailure = () =>
dispatchEsignNotificationSafely({
promise: dispatchEsignDocumentUploadFailedNotification({
jobId: jobs_by_pk.id,
documentId: payload.id.toString(),
title: payload.title,
uploadedBy: uploaded_by,
logger
}),
eventName: "DOCUMENT_UPLOAD_FAILED",
jobid,
documentId: payload.id.toString()
});
if (jobs_by_pk?.bodyshop?.uselocalmediaserver) {
const {
bodyshop: { localmediaserverhttp, localmediatoken }
} = jobs_by_pk;
const options = {
headers: {
"X-Requested-With": "XMLHttpRequest",
ims_token: localmediatoken
}
};
const formData = new FormData();
const fileName = document.filename?.toLowerCase().endsWith(".pdf")
? document.filename
: `${document.filename || `esignature-document-${payload.id}`}.pdf`;
const pdfBlob = new Blob([buffer], { type: "application/pdf" });
formData.append("jobid", jobid);
formData.append("file", pdfBlob, fileName);
try {
const imexMediaServerResponse = await axios.post(
normalizeUrl(`${localmediaserverhttp}/jobs/upload`),
formData,
options
);
if (imexMediaServerResponse.status === 200) {
//Succesful upload - we don't really need to do anything here.
} else {
throw new Error(
`Local media server upload failed with status ${imexMediaServerResponse.status}: ${imexMediaServerResponse.statusText}`
);
}
} catch (error) {
logger.log(`esig-webhook-lms-upload-error`, "ERROR", "redis", "api", {
message: error.message,
stack: error.stack,
jobid,
documentId: payload.id
});
notifyUploadFailure();
throw error;
}
} else {
try {
const uploadResult = await uploadFileBuffer({ key, buffer, contentType: "application/pdf" });
if (uploadResult.success) {
logger.log(`esig-webhook-s3-upload-success`, "INFO", "redis", "api", {
jobid: jobid,
documentId: payload.id,
s3Key: key,
bucket: uploadResult.bucket
});
//insert the document record with the s3 key and bucket info.
await client.request(INSERT_ESIGNATURE_COMPLETED_DOCOUMENT, {
docInput: {
jobid: jobs_by_pk.id,
uploaded_by: uploaded_by,
key,
type: "application/pdf",
extension: "pdf",
bodyshopid: jobs_by_pk.bodyshop.id,
size: buffer.length,
takenat: new Date().toISOString()
}
});
} else {
const uploadError = new Error(uploadResult.message || "S3 upload failed");
uploadError.stack = uploadResult.stack || uploadError.stack;
throw uploadError;
}
} catch (error) {
logger.log(`esig-webhook-s3-upload-error`, "ERROR", "redis", "api", {
message: error.message,
stack: error.stack,
jobid: jobid,
documentId: payload.id
});
notifyUploadFailure();
throw error;
}
}
//Update the audit trail and records to mark the document as completed.
await client.request(DISTRIBUTE_ESIGNATURE_DOCUMENT, {
external_document_id: payload.id.toString(),
esig_update: {
status: "COMPLETED",
completed: true,
completed_at: new Date().toISOString()
},
audit: {
jobid: jobs_by_pk.id,
bodyshopid: jobs_by_pk.bodyshop.id,
operation: `Esignature document with title ${payload.title} (ID: ${payload.documentMeta.id}) has been completed.`,
useremail: uploaded_by,
type: "esig-complete"
}
});
dispatchEsignNotificationSafely({
promise: dispatchEsignDocumentCompletedNotification({
jobId: jobs_by_pk.id,
documentId: payload.id.toString(),
title: payload.title,
uploadedBy: uploaded_by,
logger
}),
eventName: webhookTypeEnums.DOCUMENT_COMPLETED,
jobid,
documentId: payload.id.toString()
});
} catch (error) {
logger.log(`esig-webhook-event-completed-error`, "ERROR", "redis", "api", {
message: error.message,
stack: error.stack,
payload
});
throw error;
}
}
module.exports = {
esignWebhook
};

View File

@@ -0,0 +1,95 @@
export type WebhookEventType =
| "DOCUMENT_CREATED"
| "DOCUMENT_SENT"
| "DOCUMENT_COMPLETED"
| "DOCUMENT_REJECTED"
| "DOCUMENT_CANCELLED"
| "DOCUMENT_OPENED"
| "DOCUMENT_SIGNED";
export interface AuthOptions {
accessAuth: unknown[];
actionAuth: unknown[];
}
export interface Recipient {
id: number;
name: string;
role: string;
email: string;
token?: string | null;
signedAt?: string | null;
expiresAt?: string | null;
documentId?: number;
readStatus?: string | null;
sendStatus?: string | null;
templateId?: number | null;
authOptions?: AuthOptions;
signingOrder?: number | null;
signingStatus?: string | null;
rejectionReason?: string | null;
documentDeletedAt?: string | null;
expirationNotifiedAt?: string | null;
}
export interface EmailSettings {
documentDeleted: boolean;
documentPending: boolean;
recipientSigned: boolean;
recipientRemoved: boolean;
documentCompleted: boolean;
ownerDocumentCompleted: boolean;
recipientSigningRequest: boolean;
}
export interface DocumentMeta {
id: string;
message?: string | null;
subject?: string | null;
language?: string | null;
timezone?: string | null;
dateFormat?: string | null;
redirectUrl?: string | null;
signingOrder?: string | null;
emailSettings?: EmailSettings;
distributionMethod?: string | null;
drawSignatureEnabled?: boolean;
typedSignatureEnabled?: boolean;
allowDictateNextSigner?: boolean;
uploadSignatureEnabled?: boolean;
}
export interface DocumentAuthOptions {
globalAccessAuth: unknown[];
globalActionAuth: unknown[];
}
export interface DocumentPayload {
id: number;
title?: string | null;
source?: string | null;
status?: string | null;
teamId?: number | null;
userId?: number | null;
Recipient?: Recipient[];
recipients?: Recipient[];
createdAt?: string | null;
deletedAt?: string | null;
updatedAt?: string | null;
externalId?: string | null;
formValues?: unknown | null;
templateId?: number | null;
visibility?: string | null;
authOptions?: DocumentAuthOptions;
completedAt?: string | null;
documentMeta?: DocumentMeta | null;
}
export interface WebhookEventPayload {
event: WebhookEventType;
payload: DocumentPayload;
createdAt?: string | null;
webhookEndpoint?: string | null;
}
export default WebhookEventPayload;

View File

@@ -2253,18 +2253,16 @@ exports.UPDATE_OLD_TRANSITION = `mutation UPDATE_OLD_TRANSITION($jobid: uuid!, $
exports.INSERT_NEW_TRANSITION = (
includeOldTransition
) => `mutation INSERT_NEW_TRANSITION($newTransition: transitions_insert_input!, ${
includeOldTransition ? `$oldTransitionId: uuid!, $duration: numeric` : ""
) => `mutation INSERT_NEW_TRANSITION($newTransition: transitions_insert_input!, ${includeOldTransition ? `$oldTransitionId: uuid!, $duration: numeric` : ""
}) {
insert_transitions_one(object: $newTransition) {
id
}
${
includeOldTransition
? `update_transitions(where: {id: {_eq: $oldTransitionId}}, _set: {duration: $duration}) {
${includeOldTransition
? `update_transitions(where: {id: {_eq: $oldTransitionId}}, _set: {duration: $duration}) {
affected_rows
}`
: ""
: ""
}
}`;
@@ -3260,3 +3258,102 @@ exports.SET_JOB_DMS_ID = `mutation SetJobDmsId($id: uuid!, $dms_id: String!, $dm
kmin
}
}`;
exports.QUERY_JOB_FOR_SIGNATURE = `query QUERY_JOB_FOR_SIGNATURE($jobid: uuid!) {
jobs_by_pk(id: $jobid) {
id
ownr_fn
ownr_ln
ownr_co_nm
ownr_ea
ownr_ph1
}
}
`
exports.INSERT_ESIGNATURE_DOCUMENT = `mutation INSERT_ESIGNATURE_DOCUMENT($audit: audit_trail_insert_input!, $esig: esignature_documents_insert_input!) {
insert_audit_trail_one(object: $audit) {
id
}
insert_esignature_documents_one(object: $esig){
id
}
}`
exports.QUERY_ESIGNATURE_BY_EXTERNAL_ID = `query QUERY_ESIGNATURE_BY_EXTERNAL_ID($external_document_id: String!) {
esignature_documents(where: {external_document_id: {_eq: $external_document_id}}) {
id
jobid
external_document_id
}
}`
exports.DISTRIBUTE_ESIGNATURE_DOCUMENT = `mutation DISTRIBUTE_ESIGNATURE_DOCUMENT($external_document_id: String!, $esig_update: esignature_documents_set_input!, $audit: audit_trail_insert_input!) {
insert_audit_trail_one(object: $audit) {
id
}
update_esignature_documents(where: {external_document_id: {_eq: $external_document_id}}, _set: $esig_update) {
affected_rows
returning {
id
}
}
}
`
exports.UPDATE_ESIGNATURE_DOCUMENT = `mutation UPDATE_ESIGNATURE_DOCUMENT($external_document_id: String!, $esig_update: esignature_documents_set_input!) {
update_esignature_documents(where: {external_document_id: {_eq: $external_document_id}}, _set: $esig_update) {
affected_rows
returning {
id
}
}
}
`
exports.INSERT_ESIG_AUDIT_TRAIL = `mutation INSERT_ESIG_AUDIT_TRAIL($obj: audit_trail_insert_input!) {
insert_audit_trail_one(object: $obj) {
id
}
}
`
exports.QUERY_META_FOR_ESIG_COMPLETION = `query QUERY_META_FOR_ESIG_COMPLETION($jobid: uuid!) {
jobs_by_pk(id: $jobid) {
id
ro_number
bodyshop {
id
uselocalmediaserver
localmediatoken
localmediaserverhttp
localmediaservernetwork
}
}
}`
exports.INSERT_ESIGNATURE_COMPLETED_DOCOUMENT = `mutation INSERT_ESIGNATURE_COMPLETED_DOCOUMENT($docInput: documents_insert_input!) {
insert_documents_one(object: $docInput) {
id
name
key
}
}
`
exports.QUERY_DOCUMENSO_KEY = `query QUERY_DOCUMENTS_KEY($bodyshopid: uuid!) {
bodyshops_by_pk(id: $bodyshopid) {
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
}
}
}
`

View File

@@ -94,6 +94,47 @@ const generateSignedUploadUrls = async (req, res) => {
}
};
/**
* Upload a file buffer directly to S3.
* Accepts either `req.file.buffer` (e.g. from multer) or `req.body.buffer` (base64 string).
*/
const uploadFileBuffer = async ({ key, contentType, buffer }) => {
try {
if (!key) {
throw new Error("key is required");
}
if (!buffer) {
throw new Error("buffer is required");
}
const isPdf = key.toLowerCase().endsWith(".pdf");
const client = new S3Client({ region: InstanceRegion() });
const putParams = {
Bucket: imgproxyDestinationBucket,
Key: key,
Body: buffer,
StorageClass: "INTELLIGENT_TIERING"
};
if (contentType) {
putParams.ContentType = contentType;
} else if (isPdf) {
putParams.ContentType = "application/pdf";
}
await client.send(new PutObjectCommand(putParams));
return ({ success: true, key, bucket: imgproxyDestinationBucket });
} catch (error) {
return { success: false, message: error.message, stack: error.stack };
}
};
/**
* Get Thumbnail URLS
* @param req
@@ -500,6 +541,7 @@ const keyStandardize = (doc) => {
module.exports = {
generateSignedUploadUrls,
uploadFileBuffer,
getThumbnailUrls,
getOriginalImageByDocumentId,
downloadFiles,

View File

@@ -0,0 +1,268 @@
const { client: gqlClient } = require("../graphql-client/graphql-client");
const { GET_JOB_WATCHERS, GET_NOTIFICATION_ASSOCIATIONS } = require("../graphql-client/queries");
const { dispatchEmailsToQueue } = require("./queues/emailQueue");
const { dispatchAppsToQueue } = require("./queues/appQueue");
const { dispatchFcmsToQueue } = require("./queues/fcmQueue");
/**
* Default channel preferences to fall back on if a recipient doesn't have specific preferences set for a scenario.
* @type {Readonly<{app: boolean, email: boolean, fcm: boolean}>}
*/
const DEFAULT_CHANNEL_PREFERENCES = Object.freeze({
app: false,
email: false,
fcm: false
});
/**
* Normalizes channel preferences for a recipient based on their specific preferences for a scenario, falling back to
* default preferences if not set.
* @param preferences
* @param fallbackPreferences
* @returns {{app, email, fcm}}
*/
const normalizeChannelPreferences = (preferences, fallbackPreferences = DEFAULT_CHANNEL_PREFERENCES) => ({
app: preferences?.app ?? fallbackPreferences.app ?? false,
email: preferences?.email ?? fallbackPreferences.email ?? false,
fcm: preferences?.fcm ?? fallbackPreferences.fcm ?? false
});
/**
* Builds notification payloads for app, email, and FCM channels based on the provided parameters and recipient
* preferences.
* @param param0
* @param param0.jobId
* @param param0.jobRoNumber
* @param param0.bodyShopId
* @param param0.bodyShopName
* @param param0.bodyShopTimezone
* @param param0.scenarioKey
* @param param0.scenarioTable
* @param param0.key
* @param param0.body
* @param param0.variables
* @param param0.recipients
* @returns {{app: {jobId: *, jobRoNumber: *, bodyShopId: *, scenarioKey: *, scenarioTable: *, key: *, body: *, variables: *, recipients: *}, email: {jobId: *, jobRoNumber: *, bodyShopName: *, bodyShopTimezone: *, body: *, recipients: *}, fcm: {jobId: *, jobRoNumber: *, bodyShopId: *, bodyShopName: *, bodyShopTimezone: *, scenarioKey: *, scenarioTable: *, key: *, body: *, variables: *, recipients: *}}}
*/
const buildNotificationPayloads = ({
jobId,
jobRoNumber,
bodyShopId,
bodyShopName,
bodyShopTimezone,
scenarioKey,
scenarioTable,
key,
body,
variables,
recipients
}) => ({
app: {
jobId,
jobRoNumber,
bodyShopId,
scenarioKey,
scenarioTable,
key,
body,
variables,
recipients: recipients
.filter((recipient) => recipient.app)
.map(({ user, employeeId, associationId }) => ({
user,
bodyShopId,
employeeId,
associationId
}))
},
email: {
jobId,
jobRoNumber,
bodyShopName,
bodyShopTimezone,
body,
recipients: recipients
.filter((recipient) => recipient.email)
.map(({ user, firstName, lastName }) => ({ user, firstName, lastName }))
},
fcm: {
jobId,
jobRoNumber,
bodyShopId,
bodyShopName,
bodyShopTimezone,
scenarioKey,
scenarioTable,
key,
body,
variables,
recipients: recipients
.filter((recipient) => recipient.fcm)
.map(({ user, employeeId, associationId }) => ({
user,
bodyShopId,
employeeId,
associationId
}))
}
});
/**
* Dispatches notifications to job watchers based on their preferences for a given scenario. It retrieves the watchers
* of a job, determines their notification preferences, builds the appropriate payloads for each channel, and dispatches
* the notifications to the respective queues.
* @param param0
* @param param0.jobId
* @param param0.scenarioKey
* @param param0.key
* @param param0.body
* @param param0.variables
* @param param0.scenarioTable
* @param param0.extraRecipientEmails
* @param param0.defaultChannelPreferences
* @param param0.logger
* @returns {Promise<boolean>}
*/
async function dispatchJobWatcherNotification({
jobId,
scenarioKey,
key,
body,
variables = {},
scenarioTable = "esignature_documents",
extraRecipientEmails = [],
defaultChannelPreferences = DEFAULT_CHANNEL_PREFERENCES,
logger
}) {
if (!jobId || !scenarioKey || !key || !body) {
return false;
}
const watcherData = await gqlClient.request(GET_JOB_WATCHERS, { jobid: jobId });
const bodyShopId = watcherData?.job?.bodyshop?.id;
const bodyShopName = watcherData?.job?.bodyshop?.shopname;
const bodyShopTimezone = watcherData?.job?.bodyshop?.timezone;
const jobRoNumber = watcherData?.job?.ro_number;
if (!bodyShopId || !bodyShopName) {
logger?.log?.("dispatch-job-watcher-notification-missing-job-meta", "WARN", "notifications", "api", {
jobId,
scenarioKey
});
return false;
}
const recipientsByEmail = new Map();
for (const watcher of watcherData?.job_watchers || []) {
if (!watcher?.user_email) continue;
recipientsByEmail.set(watcher.user_email, {
email: watcher.user_email,
firstName: watcher?.user?.employee?.first_name || null,
lastName: watcher?.user?.employee?.last_name || null,
employeeId: watcher?.user?.employee?.id || null
});
}
for (const recipientEmail of extraRecipientEmails) {
if (!recipientEmail || recipientsByEmail.has(recipientEmail)) continue;
recipientsByEmail.set(recipientEmail, {
email: recipientEmail,
firstName: null,
lastName: null,
employeeId: null
});
}
const recipientEmails = [...recipientsByEmail.keys()];
if (!recipientEmails.length) {
logger?.log?.("dispatch-job-watcher-notification-no-recipients", "INFO", "notifications", "api", {
jobId,
scenarioKey
});
return false;
}
const associationsData = await gqlClient.request(GET_NOTIFICATION_ASSOCIATIONS, {
emails: recipientEmails,
shopid: bodyShopId
});
const eligibleRecipients = (associationsData?.associations || [])
.map((association) => {
const preferences = normalizeChannelPreferences(
association?.notification_settings?.[scenarioKey],
defaultChannelPreferences
);
if (!preferences.app && !preferences.email && !preferences.fcm) {
return null;
}
const watcher = recipientsByEmail.get(association.useremail);
return {
user: association.useremail,
app: preferences.app,
email: preferences.email,
fcm: preferences.fcm,
firstName: watcher?.firstName || null,
lastName: watcher?.lastName || null,
employeeId: watcher?.employeeId || null,
associationId: association.id
};
})
.filter(Boolean);
if (!eligibleRecipients.length) {
logger?.log?.("dispatch-job-watcher-notification-no-eligible-recipients", "INFO", "notifications", "api", {
jobId,
scenarioKey,
bodyShopId
});
return false;
}
const payloads = buildNotificationPayloads({
jobId,
jobRoNumber,
bodyShopId,
bodyShopName,
bodyShopTimezone,
scenarioKey,
scenarioTable,
key,
body,
variables,
recipients: eligibleRecipients
});
const dispatches = [];
if (payloads.email.recipients.length) {
dispatches.push(dispatchEmailsToQueue({ emailsToDispatch: [payloads.email], logger }));
}
if (payloads.app.recipients.length) {
dispatches.push(dispatchAppsToQueue({ appsToDispatch: [payloads.app], logger }));
}
if (payloads.fcm.recipients.length) {
dispatches.push(dispatchFcmsToQueue({ fcmsToDispatch: [payloads.fcm], logger }));
}
if (!dispatches.length) {
return false;
}
await Promise.all(dispatches);
return true;
}
module.exports = {
DEFAULT_CHANNEL_PREFERENCES,
dispatchJobWatcherNotification
};

View File

@@ -0,0 +1,231 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
const mock = require("mock-require");
const graphClientModuleId = require.resolve("../graphql-client/graphql-client");
const queriesModuleId = require.resolve("../graphql-client/queries");
const emailQueueModuleId = require.resolve("./queues/emailQueue");
const appQueueModuleId = require.resolve("./queues/appQueue");
const fcmQueueModuleId = require.resolve("./queues/fcmQueue");
const dispatcherModuleId = require.resolve("./dispatchJobWatcherNotification");
const dispatchEmailsToQueueMock = vi.fn();
const dispatchAppsToQueueMock = vi.fn();
const dispatchFcmsToQueueMock = vi.fn();
const loadDispatcher = ({ requestMock }) => {
mock.stopAll();
dispatchEmailsToQueueMock.mockReset();
dispatchAppsToQueueMock.mockReset();
dispatchFcmsToQueueMock.mockReset();
mock(graphClientModuleId, { client: { request: requestMock } });
mock(queriesModuleId, {
GET_JOB_WATCHERS: "GET_JOB_WATCHERS",
GET_NOTIFICATION_ASSOCIATIONS: "GET_NOTIFICATION_ASSOCIATIONS"
});
mock(emailQueueModuleId, { dispatchEmailsToQueue: dispatchEmailsToQueueMock });
mock(appQueueModuleId, { dispatchAppsToQueue: dispatchAppsToQueueMock });
mock(fcmQueueModuleId, { dispatchFcmsToQueue: dispatchFcmsToQueueMock });
delete require.cache[dispatcherModuleId];
return require(dispatcherModuleId);
};
afterEach(() => {
mock.stopAll();
delete require.cache[dispatcherModuleId];
});
describe("dispatchJobWatcherNotification", () => {
it("dispatches queue payloads using watcher settings plus fallback defaults for extra recipients", async () => {
const requestMock = vi.fn(async (query) => {
if (query === "GET_JOB_WATCHERS") {
return {
job_watchers: [
{
user_email: "watcher@example.com",
user: {
employee: {
id: "emp-1",
first_name: "Pat",
last_name: "Lee"
}
}
}
],
job: {
ro_number: "RO-123",
bodyshop: {
id: "shop-1",
shopname: "ImEX",
timezone: "America/Toronto"
}
}
};
}
if (query === "GET_NOTIFICATION_ASSOCIATIONS") {
return {
associations: [
{
id: "assoc-1",
useremail: "watcher@example.com",
notification_settings: {
"esign-document-opened": {
app: true,
email: false,
fcm: true
}
}
},
{
id: "assoc-2",
useremail: "creator@example.com",
notification_settings: {}
}
]
};
}
return {};
});
const { dispatchJobWatcherNotification } = loadDispatcher({ requestMock });
const logger = { log: vi.fn() };
const result = await dispatchJobWatcherNotification({
jobId: "job-1",
scenarioKey: "esign-document-opened",
key: "notifications.job.esignDocumentOpened",
body: '"Repair Authorization" has been opened.',
variables: { documentId: "123" },
extraRecipientEmails: ["creator@example.com"],
defaultChannelPreferences: {
app: true,
email: false,
fcm: false
},
logger
});
expect(result).toBe(true);
expect(requestMock).toHaveBeenCalledTimes(2);
expect(dispatchEmailsToQueueMock).not.toHaveBeenCalled();
expect(dispatchAppsToQueueMock).toHaveBeenCalledTimes(1);
expect(dispatchAppsToQueueMock.mock.calls[0][0]).toEqual({
appsToDispatch: [
expect.objectContaining({
jobId: "job-1",
jobRoNumber: "RO-123",
bodyShopId: "shop-1",
scenarioKey: "esign-document-opened",
key: "notifications.job.esignDocumentOpened",
recipients: [
{
user: "watcher@example.com",
bodyShopId: "shop-1",
employeeId: "emp-1",
associationId: "assoc-1"
},
{
user: "creator@example.com",
bodyShopId: "shop-1",
employeeId: null,
associationId: "assoc-2"
}
]
})
],
logger
});
expect(dispatchFcmsToQueueMock).toHaveBeenCalledTimes(1);
expect(dispatchFcmsToQueueMock.mock.calls[0][0]).toEqual({
fcmsToDispatch: [
expect.objectContaining({
jobId: "job-1",
scenarioKey: "esign-document-opened",
recipients: [
{
user: "watcher@example.com",
bodyShopId: "shop-1",
employeeId: "emp-1",
associationId: "assoc-1"
}
]
})
],
logger
});
});
it("returns false when no recipients have any enabled channels", async () => {
const requestMock = vi.fn(async (query) => {
if (query === "GET_JOB_WATCHERS") {
return {
job_watchers: [
{
user_email: "watcher@example.com",
user: {
employee: {
id: "emp-1",
first_name: "Pat",
last_name: "Lee"
}
}
}
],
job: {
ro_number: "RO-123",
bodyshop: {
id: "shop-1",
shopname: "ImEX",
timezone: "America/Toronto"
}
}
};
}
if (query === "GET_NOTIFICATION_ASSOCIATIONS") {
return {
associations: [
{
id: "assoc-1",
useremail: "watcher@example.com",
notification_settings: {
"esign-document-opened": {
app: false,
email: false,
fcm: false
}
}
}
]
};
}
return {};
});
const { dispatchJobWatcherNotification } = loadDispatcher({ requestMock });
const result = await dispatchJobWatcherNotification({
jobId: "job-1",
scenarioKey: "esign-document-opened",
key: "notifications.job.esignDocumentOpened",
body: '"Repair Authorization" has been opened.',
logger: { log: vi.fn() }
});
expect(result).toBe(false);
expect(dispatchEmailsToQueueMock).not.toHaveBeenCalled();
expect(dispatchAppsToQueueMock).not.toHaveBeenCalled();
expect(dispatchFcmsToQueueMock).not.toHaveBeenCalled();
});
});

View File

@@ -0,0 +1,136 @@
const { dispatchJobWatcherNotification } = require("./dispatchJobWatcherNotification");
/**
* Default notification channel preferences for e-sign document events. By default, users will receive in-app
* notifications for e-sign events, but not email or FCM notifications. These defaults can be overridden by user
* preferences or specific notification dispatch calls.
* @type {Readonly<{app: boolean, email: boolean, fcm: boolean}>}
*/
const DEFAULT_ESIGN_CHANNEL_PREFERENCES = Object.freeze({
app: true,
email: false,
fcm: false
});
/**
* Notification scenarios for e-sign document events. Each scenario includes a unique scenario key and a localization
* key for the notification message.
* @type {Readonly<{documentOpened: {scenarioKey: string, key: string}, documentCompleted: {scenarioKey: string, key: string}, documentUploadFailed: {scenarioKey: string, key: string}}>}
*/
const ESIGN_NOTIFICATION_SCENARIOS = Object.freeze({
documentOpened: {
scenarioKey: "esign-document-opened",
key: "notifications.job.esignDocumentOpened"
},
documentCompleted: {
scenarioKey: "esign-document-completed",
key: "notifications.job.esignDocumentCompleted"
},
documentUploadFailed: {
scenarioKey: "esign-document-upload-failed",
key: "notifications.job.esignDocumentUploadFailed"
}
});
/**
* Formats the document title for use in notification messages. If a title is provided, it will be wrapped in quotes;
* if not, a generic description will be used.
* @param title
* @returns {string|string}
*/
const formatDocumentTitle = (title) => (title ? `"${title}"` : "An e-sign document");
/**
* Dispatches a notification when an e-sign document is opened. The notification will include the document title and
* will be sent to the user who uploaded the document (if available) with default channel preferences for e-sign events.
* @param param0
* @param param0.jobId
* @param param0.documentId
* @param param0.title
* @param param0.uploadedBy
* @param param0.logger
* @returns {Promise<boolean>}
*/
async function dispatchEsignDocumentOpenedNotification({ jobId, documentId, title, uploadedBy, logger }) {
return dispatchJobWatcherNotification({
jobId,
scenarioKey: ESIGN_NOTIFICATION_SCENARIOS.documentOpened.scenarioKey,
key: ESIGN_NOTIFICATION_SCENARIOS.documentOpened.key,
body: `${formatDocumentTitle(title)} has been opened.`,
variables: {
documentId,
title: title || null,
uploadedBy: uploadedBy || null,
status: "OPENED"
},
extraRecipientEmails: uploadedBy ? [uploadedBy] : [],
defaultChannelPreferences: DEFAULT_ESIGN_CHANNEL_PREFERENCES,
logger
});
}
/**
* Dispatches a notification when an e-sign document is completed. The notification will include the document title and
* will be sent to the user who uploaded the document (if available) with default channel preferences for e-sign events.
* @param param0
* @param param0.jobId
* @param param0.documentId
* @param param0.title
* @param param0.uploadedBy
* @param param0.logger
* @returns {Promise<boolean>}
*/
async function dispatchEsignDocumentCompletedNotification({ jobId, documentId, title, uploadedBy, logger }) {
return dispatchJobWatcherNotification({
jobId,
scenarioKey: ESIGN_NOTIFICATION_SCENARIOS.documentCompleted.scenarioKey,
key: ESIGN_NOTIFICATION_SCENARIOS.documentCompleted.key,
body: `${formatDocumentTitle(title)} has been completed.`,
variables: {
documentId,
title: title || null,
uploadedBy: uploadedBy || null,
status: "COMPLETED"
},
extraRecipientEmails: uploadedBy ? [uploadedBy] : [],
defaultChannelPreferences: DEFAULT_ESIGN_CHANNEL_PREFERENCES,
logger
});
}
/**
* Dispatches a notification when an e-sign document upload fails. The notification will include the document title and
* will be sent to the user who uploaded the document (if available) with default channel preferences for e-sign events.
* @param param0
* @param param0.jobId
* @param param0.documentId
* @param param0.title
* @param param0.uploadedBy
* @param param0.logger
* @returns {Promise<boolean>}
*/
async function dispatchEsignDocumentUploadFailedNotification({ jobId, documentId, title, uploadedBy, logger }) {
return dispatchJobWatcherNotification({
jobId,
scenarioKey: ESIGN_NOTIFICATION_SCENARIOS.documentUploadFailed.scenarioKey,
key: ESIGN_NOTIFICATION_SCENARIOS.documentUploadFailed.key,
body: `${formatDocumentTitle(title)} was completed, but the signed PDF failed to upload to the job documents.`,
variables: {
documentId,
title: title || null,
uploadedBy: uploadedBy || null,
status: "UPLOAD_FAILED"
},
extraRecipientEmails: uploadedBy ? [uploadedBy] : [],
defaultChannelPreferences: DEFAULT_ESIGN_CHANNEL_PREFERENCES,
logger
});
}
module.exports = {
DEFAULT_ESIGN_CHANNEL_PREFERENCES,
ESIGN_NOTIFICATION_SCENARIOS,
dispatchEsignDocumentOpenedNotification,
dispatchEsignDocumentCompletedNotification,
dispatchEsignDocumentUploadFailedNotification
};

View File

@@ -0,0 +1,25 @@
const express = require("express");
const router = express.Router();
const multer = require("multer");
const validateFirebaseIdTokenMiddleware = require("../middleware/validateFirebaseIdTokenMiddleware");
const withUserGraphQLClientMiddleware = require("../middleware/withUserGraphQLClientMiddleware");
const { newEsignDocument, newCustomEsignDocument, distributeDocument, redistributeDocument, viewDocument, deleteDocument } = require("../esign/esign-new");
const { esignWebhook } = require("../esign/webhook");
const upload = multer({
limits: {
fileSize: 20 * 1024 * 1024
}
});
router.post("/new", validateFirebaseIdTokenMiddleware, withUserGraphQLClientMiddleware, newEsignDocument);
router.post("/new-custom", validateFirebaseIdTokenMiddleware, withUserGraphQLClientMiddleware, upload.single("document"), newCustomEsignDocument);
router.post("/distribute", validateFirebaseIdTokenMiddleware, withUserGraphQLClientMiddleware, distributeDocument);
router.post("/redistribute", validateFirebaseIdTokenMiddleware, withUserGraphQLClientMiddleware, redistributeDocument);
router.post("/delete", validateFirebaseIdTokenMiddleware, withUserGraphQLClientMiddleware, deleteDocument);
router.post("/view", validateFirebaseIdTokenMiddleware, withUserGraphQLClientMiddleware, viewDocument);
router.post("/webhook", esignWebhook);
module.exports = router;

View File

@@ -0,0 +1,30 @@
const replaceAccents = (str) => {
// Verifies if the String has accents and replace them
if (str.search(/[\xC0-\xFF]/g) > -1) {
str = str
.replace(/[\xC0-\xC5]/g, "A")
.replace(/[\xC6]/g, "AE")
.replace(/[\xC7]/g, "C")
.replace(/[\xC8-\xCB]/g, "E")
.replace(/[\xCC-\xCF]/g, "I")
.replace(/[\xD0]/g, "D")
.replace(/[\xD1]/g, "N")
.replace(/[\xD2-\xD6\xD8]/g, "O")
.replace(/[\xD9-\xDC]/g, "U")
.replace(/[\xDD]/g, "Y")
.replace(/[\xDE]/g, "P")
.replace(/[\xE0-\xE5]/g, "a")
.replace(/[\xE6]/g, "ae")
.replace(/[\xE7]/g, "c")
.replace(/[\xE8-\xEB]/g, "e")
.replace(/[\xEC-\xEF]/g, "i")
.replace(/[\xF1]/g, "n")
.replace(/[\xF2-\xF6\xF8]/g, "o")
.replace(/[\xF9-\xFC]/g, "u")
.replace(/[\xFE]/g, "p")
.replace(/[\xFD\xFF]/g, "y");
}
return str;
};
module.exports = replaceAccents;

View File

@@ -2,6 +2,9 @@ exports.servertime = (req, res) => {
res.status(200).send(new Date());
};
exports.jsrAuthString =() => {
return "Basic " + Buffer.from(`${process.env.JSR_USER}:${process.env.JSR_PASSWORD}`).toString("base64")
}
exports.jsrAuth = async (req, res) => {
res.send("Basic " + Buffer.from(`${process.env.JSR_USER}:${process.env.JSR_PASSWORD}`).toString("base64"));
res.send(exports.jsrAuthString());
};