Delete apps/OpenSignServer/package-lock.json

This commit is contained in:
prafull-opensignlabs
2026-02-06 12:45:57 +00:00
parent f1278d32a8
commit 336cfb3482
59 changed files with 3201 additions and 33098 deletions
@@ -1,7 +1,6 @@
import express from 'express';
import cors from 'cors';
import dotenv from 'dotenv';
import uploadFile from './uploadFile.js';
import docxtopdf, { upload as docxUpload } from './docxtopdf.js';
import decryptpdf, { upload as decryptUpload } from './decryptpdf.js';
@@ -16,7 +15,6 @@ app.use(cors());
app.use(express.json({ limit: '100mb' }));
app.use(express.urlencoded({ limit: '100mb', extended: true }));
app.post('/file_upload', uploadFile);
app.post('/docxtopdf', docxUpload.single('file'), docxtopdf);
app.post('/decryptpdf', decryptUpload.single('file'), decryptpdf);
app.get('/delete-account/:userId', deleteUserGet);
@@ -1,8 +1,31 @@
import axios from 'axios';
import multer from 'multer';
import libre from 'libreoffice-convert';
import { exec } from 'child_process';
import { promisify } from 'util';
import { cloudServerUrl, getSecureUrl, serverAppId } from '../../Utils.js';
const execAsync = promisify(exec);
// -------------------- Process Management --------------------
/**
* Kill stuck LibreOffice processes
*/
async function killStuckProcesses() {
try {
// Kill soffice processes older than 2 minutes
if (process.platform === 'linux' || process.platform === 'darwin') {
await execAsync("pkill -9 -f 'soffice.*--headless' || true");
console.log('[DOCX2PDF] Cleaned up stuck processes');
} else if (process.platform === 'win32') {
await execAsync('taskkill /F /IM soffice.bin /T || exit 0');
console.log('[DOCX2PDF] Cleaned up stuck processes (Windows)');
}
} catch (err) {
console.error('[DOCX2PDF] Error killing processes:', err.message);
}
}
/** @returns {Promise<Buffer>} */
async function convertLibre(input, ext, opts) {
return await new Promise((resolve, reject) => {
@@ -14,7 +37,7 @@ async function convertLibre(input, ext, opts) {
});
}
// -------------------- Concurrency limiter --------------------
// -------------------- Concurrency limiter with queue limits --------------------
// CRITICAL FIX: Reduced to 1 for CPU-intensive LibreOffice conversions
const MAX_CONCURRENCY = Number(process.env.DOCX2PDF_CONCURRENCY || 1);
let active = 0;
@@ -22,22 +45,27 @@ const queue = [];
function runWithLimit(task) {
return new Promise((resolve, reject) => {
const run = () => {
const run = async () => {
active++;
Promise.resolve()
.then(task)
.then(resolve, reject)
.finally(() => {
active--;
if (queue.length) queue.shift()();
});
try {
const result = await task();
resolve(result);
} catch (error) {
reject(error);
} finally {
active--;
if (queue.length) {
const next = queue.shift();
next();
}
}
};
if (active < MAX_CONCURRENCY) run();
else queue.push(run);
});
}
// -------------------- Timeout helper --------------------
// -------------------- Timeout helper with cleanup --------------------
/**
* @template T
* @param {Promise<T>} promise
@@ -49,7 +77,11 @@ export async function withTimeout(promise, ms, label = 'operation') {
let timer;
try {
const timeout = new Promise((_, reject) => {
timer = setTimeout(() => reject(new Error(`${label} timed out after ${ms}ms`)), ms);
timer = setTimeout(async () => {
// Kill stuck processes on timeout
await killStuckProcesses();
reject(new Error(`${label} timed out after ${ms}ms`));
}, ms);
});
return await Promise.race([promise, timeout]);
} finally {
@@ -116,22 +148,29 @@ export default async function docxtopdf(req, res) {
// ---- DOCX -> PDF conversion with concurrency control and timeout ----
const fileName = `${generatePdfName(16)}.pdf`;
// FIX: Increased timeout to 90s for large files, added nice priority
// Adjust timeout based on file size
const timeoutMs = uploadedSizeBytes > 10 * 1024 * 1024 ? 120_000 : 90_000;
// FIX: Increased timeout for large files, added nice priority
const pdfBuffer = await runWithLimit(async () => {
// Log for monitoring
console.log(`[DOCX2PDF] Starting conversion, active: ${active}, queued: ${queue.length}`);
console.log(
`[DOCX2PDF] Starting conversion, size: ${(uploadedSizeBytes / 1024 / 1024).toFixed(2)}MB, active: ${active}, queued: ${queue.length}`
);
const startTime = Date.now();
try {
const result = await withTimeout(
convertLibre(req.file.buffer, '.pdf', undefined),
90_000, // Increased from 60s to 90s
timeoutMs,
'DOCX->PDF'
);
console.log(`[DOCX2PDF] Completed in ${Date.now() - startTime}ms`);
return result;
} catch (error) {
console.error(`[DOCX2PDF] Failed after ${Date.now() - startTime}ms:`, error.message);
// Clean up on error
await killStuckProcesses();
throw error;
}
});
@@ -1,168 +0,0 @@
// npm packages
import multer from 'multer';
import multerS3 from 'multer-s3';
import aws from 'aws-sdk';
import dotenv from 'dotenv';
import { cloudServerUrl, serverAppId, useLocal } from '../../Utils.js';
dotenv.config({ quiet: true });
function sanitizeFileName(fileName) {
// Remove spaces and invalid characters
return fileName.replace(/[^a-zA-Z0-9._-]/g, '');
}
async function uploadFile(req, res) {
try {
//--size extended to 100 mb
const size = 100 * 1024 * 1024;
//console.log(size);
const accepted_extensions = [
'jpg',
'png',
'gif',
'mp4',
'mp3',
'pdf',
'jpeg',
'dwg',
'dxf',
'zip',
'rar',
'txt',
'doc',
'docx',
'pptx',
'ppt',
'xlsx',
'xlsm',
'xlsb',
'xltx',
'xml',
'xls',
'xla',
'xlx',
];
const DO_ENDPOINT = process.env.DO_ENDPOINT;
const DO_ACCESS_KEY_ID = process.env.DO_ACCESS_KEY_ID;
const DO_SECRET_ACCESS_KEY = process.env.DO_SECRET_ACCESS_KEY;
const DO_SPACE = process.env.DO_SPACE;
const parseBaseUrl = cloudServerUrl; //process.env.SERVER_URL;
const parseAppId = serverAppId;
let fileStorage;
if (useLocal === 'true') {
fileStorage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, 'files/files');
},
metadata: function (req, file, cb) {
cb(null, { fieldName: 'OPENSIGN_METADATA' });
},
filename: function (req, file, cb) {
let filename = file.originalname;
let newFileName = filename.split('.')[0];
let extension = filename.split('.')[1];
newFileName = sanitizeFileName(
newFileName + '_' + new Date().toISOString() + '.' + extension
);
// console.log(newFileName);
cb(null, newFileName);
},
});
} else {
try {
const spacesEndpoint = new aws.Endpoint(DO_ENDPOINT);
const s3 = new aws.S3({
endpoint: spacesEndpoint,
accessKeyId: DO_ACCESS_KEY_ID,
secretAccessKey: DO_SECRET_ACCESS_KEY,
signatureVersion: 'v4',
region: process.env.DO_REGION,
});
fileStorage = multerS3({
acl: 'public-read',
s3,
bucket: DO_SPACE,
metadata: function (req, file, cb) {
cb(null, { fieldName: 'OPENSIGN_METADATA' });
},
key: function (req, file, cb) {
//console.log(file);
let filename = file.originalname;
let newFileName = filename.split('.')[0];
let extension = filename.split('.')[1];
newFileName = sanitizeFileName(
newFileName + '_' + new Date().toISOString() + '.' + extension
);
// console.log(newFileName);
cb(null, newFileName);
},
});
} catch (err) {
fileStorage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, 'files/files');
},
metadata: function (req, file, cb) {
cb(null, { fieldName: 'OPENSIGN_METADATA' });
},
filename: function (req, file, cb) {
let filename = file.originalname;
let newFileName = filename.split('.')[0];
let extension = filename.split('.')[1];
newFileName = sanitizeFileName(
newFileName + '_' + new Date().toISOString() + '.' + extension
);
// console.log(newFileName);
cb(null, newFileName);
},
});
}
}
// const s3 = new aws.S3();
const upload = multer({
fileFilter: function (req, file, cb) {
if (accepted_extensions.some(ext => file.originalname.toLowerCase().endsWith('.' + ext))) {
return cb(null, true);
}
// otherwise, return error
return cb('Only ' + accepted_extensions.join(', ') + ' files are allowed!');
},
storage: fileStorage,
limits: { fileSize: size },
}).single('file');
//--call upload function--
upload(req, res, function (err, some) {
if (err) {
console.log(err);
const status = 'Error';
const message = err;
const returnCode = 1029;
return res.send({ status, returnCode, message });
}
const status = 'Success';
//res.header("Access-Control-Allow-Headers", "Content-Type");
//res.setHeader("Access-Control-Allow-Origin", "*");
if (useLocal === 'true') {
// console.log(req.file);
var fileUrl = `${parseBaseUrl}/files/${parseAppId}/${req.file.filename}`;
} else {
var fileUrl = req.file.location;
}
return res.json({ status, imageUrl: fileUrl });
});
} catch (err) {
console.log('Exeption in query ' + err.stack);
const status = 'Error';
const returnCode = 1021;
const message = 'Some error occurred';
return res.send({ status, returnCode, message });
}
}
export default uploadFile;
@@ -25,7 +25,7 @@ async function sendMail(document, publicUrl) {
month: 'long',
year: 'numeric',
});
let signerMail = document.Placeholders;
let signerMail = document.Placeholders?.filter(x => x?.Role !== 'prefill');
const senderName = document.ExtUserPtr.Name;
const senderEmail = document.ExtUserPtr.Email;
@@ -109,9 +109,12 @@ async function batchQuery(userId, Documents, Ip, parseConfig, type, publicUrl) {
try {
const requests = Documents.map(x => {
const Signers = x.Signers;
const allSigner = x?.Placeholders?.map(
item => Signers?.find(e => item?.signerPtr?.objectId === e?.objectId) || item?.signerPtr
).filter(signer => Object.keys(signer).length > 0);
const placeholders = x?.Placeholders?.filter(p => p?.Role !== 'prefill');
const allSigner = placeholders
?.map(
item => Signers?.find(e => item?.signerPtr?.objectId === e?.objectId) || item?.signerPtr
)
.filter(signer => Object.keys(signer).length > 0);
const date = new Date();
const isoDate = date.toISOString();
let Acl = { [x.CreatedBy.objectId]: { read: true, write: true } };
@@ -140,7 +143,7 @@ async function batchQuery(userId, Documents, Ip, parseConfig, type, publicUrl) {
className: x.ExtUserPtr.className,
objectId: x.ExtUserPtr?.objectId,
},
Placeholders: x.Placeholders.map(y =>
Placeholders: placeholders.map(y =>
y?.signerPtr?.objectId
? {
...y,
@@ -2,7 +2,6 @@ import { SignPdf } from '@signpdf/signpdf';
import { P12Signer } from '@signpdf/signer-p12';
import { pdflibAddPlaceholder } from '@signpdf/placeholder-pdf-lib';
import { PDFDocument } from 'pdf-lib';
import Parse from 'parse/node.js';
import fs from 'node:fs';
import dotenv from 'dotenv';
import GenerateCertificate from './pdf/GenerateCertificate.js';
@@ -2,6 +2,7 @@ import AWS from 'aws-sdk';
import { useLocal } from '../../Utils.js';
import jwt from 'jsonwebtoken';
import dotenv from 'dotenv';
import { isAuthenticated } from '../../utils/AuthUtils.js';
dotenv.config({ quiet: true });
export default function getPresignedUrl(url) {
@@ -42,6 +43,7 @@ export async function getSignedUrl(request) {
const docId = request.params.docId || '';
const templateId = request.params.templateId || '';
const url = request.params.url;
if (docId || templateId) {
try {
if (url?.includes('files')) {
@@ -56,8 +58,14 @@ export async function getSignedUrl(request) {
const _resDoc = res?.toJSON();
// Ensure user is authenticated if OTP is required
if (_resDoc?.IsEnableOTP && !request?.user) {
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'User is not authenticated.');
if (_resDoc?.IsEnableOTP) {
const isAuth = await isAuthenticated(request?.user);
if (!isAuth) {
throw new Parse.Error(
Parse.Error.INVALID_SESSION_TOKEN,
'User is not authenticated.'
);
}
}
const presignedUrl = getPresignedUrl(url);
@@ -70,7 +78,8 @@ export async function getSignedUrl(request) {
throw err;
}
} else {
if (!request?.user) {
const isAuth = await isAuthenticated(request?.user);
if (!isAuth) {
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'User is not authenticated.');
} else {
if (url?.includes('files')) {
@@ -56,6 +56,7 @@ export default async function saveAsTemplate(request) {
pos: pageItem.pos.map(p => ({
...p,
type: p.type === 'text' ? 'text input' : p.type,
signatureType: '',
options: {
...p.options,
status: 'required',
@@ -92,6 +93,7 @@ export default async function saveAsTemplate(request) {
if (widget.options && widget.options.defaultValue !== undefined) {
return {
...widget,
signatureType: '',
options: {
...widget.options,
defaultValue: '',
-14803
View File
File diff suppressed because it is too large Load Diff
+17 -17
View File
@@ -18,55 +18,55 @@
"watch": "nodemon index.js"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.958.0",
"@aws-sdk/s3-request-presigner": "^3.958.0",
"@aws-sdk/client-s3": "^3.978.0",
"@aws-sdk/s3-request-presigner": "^3.978.0",
"@parse/fs-files-adapter": "^3.0.0",
"@parse/push-adapter": "^8.1.0",
"@parse/push-adapter": "^8.2.0",
"@parse/s3-files-adapter": "^4.2.0",
"@pdf-lib/fontkit": "^1.1.1",
"@signpdf/placeholder-pdf-lib": "^3.3.0",
"@signpdf/signer-p12": "^3.3.0",
"@signpdf/signpdf": "^3.3.0",
"aws-sdk": "^2.1693.0",
"axios": "^1.13.2",
"axios": "^1.13.4",
"coherentpdf": "^2.5.5",
"cors": "^2.8.5",
"cors": "^2.8.6",
"date-fns-tz": "^3.2.0",
"dotenv": "^17.2.3",
"express": "^5.2.1",
"form-data": "^4.0.5",
"generate-api-key": "^1.0.2",
"googleapis": "^169.0.0",
"libreoffice-convert": "^1.7.0",
"mailgun.js": "^12.4.1",
"googleapis": "^170.1.0",
"libreoffice-convert": "^1.8.1",
"mailgun.js": "^12.7.0",
"moment": "^2.30.1",
"mongodb": "^7.0.0",
"multer": "^2.0.2",
"multer-s3": "^3.0.1",
"node-forge": "^1.3.3",
"nodemailer": "^7.0.12",
"nodemailer": "^7.0.13",
"p-limit": "^7.2.0",
"parse": "^8.0.0",
"parse": "^8.0.3",
"parse-dbtool": "^1.2.0",
"parse-server": "^8.6.2",
"parse-server-api-mail-adapter": "^5.0.2",
"parse-server-api-mail-adapter": "^5.0.4",
"pdf-lib": "^1.17.1",
"posthog-node": "^5.18.1",
"posthog-node": "^5.21.2",
"qrcode": "^1.5.4",
"rate-limiter-flexible": "^9.0.1",
"sharp": "^0.34.5",
"speakeasy": "^2.0.0",
"ws": "^8.18.3"
"ws": "^8.19.0"
},
"type": "module",
"devDependencies": {
"@babel/eslint-parser": "^7.28.5",
"@babel/eslint-parser": "^7.28.6",
"eslint": "^9.39.2",
"jasmine": "^5.12.0",
"mongodb-runner": "^6.5.2",
"jasmine": "^6.0.0",
"mongodb-runner": "^6.5.4",
"nodemon": "^3.1.11",
"nyc": "^17.1.0",
"prettier": "^3.7.4"
"prettier": "^3.8.1"
},
"overrides": {
"ws": "$ws",
+8
View File
@@ -0,0 +1,8 @@
export const isAuthenticated = async sessionUser => {
try {
return sessionUser ? true : false;
} catch (err) {
console.log(`authentication error ${err?.message}`);
return false;
}
};
+214
View File
@@ -0,0 +1,214 @@
export function getPattern(option) {
const validateType = option?.validation?.type;
let regexValidation;
switch (validateType) {
case 'email':
regexValidation = '/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/';
return regexValidation;
case 'number':
regexValidation = /^[0-9\s]*$/;
return regexValidation;
case 'ssn':
regexValidation = /^(?!000|666|9\d{2})\d{3}-(?!00)\d{2}-(?!0000)\d{4}$/;
return regexValidation;
default:
regexValidation = option?.validation?.pattern;
return regexValidation;
}
}
//function used in getTemplate API to update placeholders options field
export function getWidgetOptions(option, type, role) {
const isPrefill = role === 'prefill';
const status = option?.status === 'required' ? true : false;
const widgetname = option?.name;
const defaultValue = option?.defaultValue || option?.response || '';
switch (type) {
case 'stamp':
return { required: status, name: widgetname };
case 'initials':
return { required: status, name: widgetname };
case 'image':
return {
required: status,
name: widgetname,
...(isPrefill &&
option?.response && {
response: option.response,
}),
};
case 'email':
return {
required: status,
name: widgetname,
color: option?.fontColor || 'black',
fontSize: option?.fontSize || 12,
hide_text_with_asterisks: option?.isHideText || false,
};
case 'name':
return {
required: status,
name: widgetname,
color: option?.fontColor || 'black',
fontSize: option?.fontSize || 12,
hide_text_with_asterisks: option?.isHideText || false,
};
case 'job title':
return {
required: status,
name: widgetname,
color: option?.fontColor || 'black',
fontSize: option?.fontSize || 12,
hide_text_with_asterisks: option?.isHideText || false,
};
case 'company':
return {
required: status,
name: widgetname,
color: option?.fontColor || 'black',
fontSize: option?.fontSize || 12,
hide_text_with_asterisks: option?.isHideText || false,
};
case 'date': {
const format = option?.validation?.format;
return {
required: status,
name: widgetname,
color: option?.fontColor || 'black',
fontSize: option?.fontSize || 12,
format: format || 'mm-dd-yyyy',
...(!isPrefill && {
...{ min_date: option?.minDate || '' },
...{ max_date: option?.maxDate || '' },
...(defaultValue !== 'today' && { default: defaultValue }),
...(defaultValue === 'today' && { signing_date: true }),
...{ readonly: option?.isReadOnly || false },
}),
...(isPrefill &&
option?.response && {
response: option.response,
}),
};
}
case 'text input':
case 'text':
return {
required: status,
name: widgetname,
color: option?.fontColor || 'black',
fontSize: option?.fontSize || 12,
...(!isPrefill && {
...{ hint: option?.hint || '' },
...{ hide_text_with_asterisks: option?.isHideText || false },
...(defaultValue && { default: defaultValue }),
...{ regularexpression: getPattern(option) },
...{ readonly: option?.isReadOnly || false },
}),
...(isPrefill &&
option?.response && {
response: option.response,
}),
};
case 'checkbox': {
const optionsArr = option?.values || [];
// defaultValue = index numbers e.g. [0, 1]
let selectedvalues =
Array.isArray(defaultValue) && defaultValue.length > 0 ? defaultValue : [];
// convert index numbers back to actual values
let getSelectedValue = [];
if (selectedvalues.length > 0) {
for (const index of selectedvalues) {
if (optionsArr[index] !== undefined) {
getSelectedValue.push(optionsArr[index]);
}
}
}
return {
required: status,
name: widgetname,
values: optionsArr,
...(!isPrefill && {
...(getSelectedValue && { selectedvalues: getSelectedValue || [] }),
...{
validation: {
minselections: option?.validation?.minRequiredCount || 0,
maxselections: option?.validation?.maxRequiredCount || 0,
},
},
...{ readonly: option?.isReadOnly || false },
}),
hidelabel: option?.isHideLabel || false,
color: option?.fontColor || 'black',
fontSize: option?.fontSize || 12,
layout: option?.layout || 'vertical',
...(isPrefill &&
getSelectedValue && {
response: getSelectedValue,
}),
};
}
case 'radio button': {
return {
required: status,
name: widgetname,
color: option?.fontColor || 'black',
fontSize: option?.fontSize || 12,
layout: option?.layout || 'vertical',
values: option?.values || [],
...(!isPrefill && {
...{ default: defaultValue || '' },
...{ readonly: option?.isReadOnly || false },
}),
...(isPrefill && {
...{ response: defaultValue },
}),
};
}
case 'dropdown':
return {
required: status,
name: widgetname,
color: option?.fontColor || 'black',
fontSize: option?.fontSize || 12,
...(!isPrefill && {
...{ default: defaultValue || '' },
...{ readonly: option?.isReadOnly || false },
}),
values: option?.values || [],
...(isPrefill &&
defaultValue && {
response: defaultValue,
}),
};
case 'number':
return {
required: status,
name: widgetname,
color: option?.fontColor || 'black',
fontSize: option?.fontSize || 12,
readonly: option?.isReadOnly || false,
default: defaultValue || '',
hint: option?.hint || '',
formula: option?.formula || '',
decimalplaces: option?.decimalPlaces || 0,
hide_text_with_asterisks: option?.isHideText || false,
};
case 'cells':
return {
required: status,
name: widgetname,
color: option?.fontColor || 'black',
fontSize: option?.fontSize || 12,
hide_text_with_asterisks: option?.isHideText || false,
readonly: option?.isReadOnly || false,
default: defaultValue || '',
hint: option?.hint || '',
cell_count: option?.cellCount || 0,
regularexpression: getPattern(option),
};
default:
break;
}
}