diff --git a/.env.local_dev b/.env.local_dev index cf19e847c..807d61ec0 100644 --- a/.env.local_dev +++ b/.env.local_dev @@ -44,10 +44,16 @@ DO_REGION=us-west # local storage USE_LOCAL=FALSE -# Email mailgun config (The app will not initialize if any of these 3 variables are not set) ********************************************************************************************************************* -MAILGUN_API_KEY=XXXXX +# Email using Mailgun or SMTP if set enable config (The app will not initialize if any of these variables are not set) ********************************************************************************************************************* +MAILGUN_API_KEY= MAILGUN_DOMAIN=mail.yourdomain.com MAILGUN_SENDER=postmaster@mail.yourdomain.com +SMTP_ENABLE= +SMTP_HOST= +SMTP_PORT= +SMTP_USER_EMAIL= +SMTP_PASS= + # Base64 encoded PFX or p12 document signing certificate file ********************************************************************************************************************* PFX_BASE64='MIIKLwIBAzCCCeUGCSqGSIb3DQEHAaCCCdYEggnSMIIJzjCCBEIGCSqGSIb3DQEH diff --git a/.gitignore b/.gitignore index 8e62b9ce7..b6dcebdf3 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,5 @@ npm-debug.log* yarn-debug.log* yarn-error.log* apps/OpenSign/public/mfbuild/* -microfrontends/SignDocuments/build/* \ No newline at end of file +microfrontends/SignDocuments/build/* +apps/OpenSignServer/files/files/* \ No newline at end of file diff --git a/.husky/pre-commit b/.husky/pre-commit index 1999e3518..21170d497 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,5 +1,4 @@ -#!/bin/sh -. "$(dirname "$0")/_/husky.sh" +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" -npx eslint '**/*.{js,jsx}' -npx pretty-quick --staged '**/*.{js,jsx}' \ No newline at end of file +npm run lint-staged-changes diff --git a/.lintstagedrc.json b/.lintstagedrc.json new file mode 100644 index 000000000..5478c3ce3 --- /dev/null +++ b/.lintstagedrc.json @@ -0,0 +1,3 @@ +{ + "*.js": "prettier --write" +} diff --git a/INSTALLATION.md b/INSTALLATION.md index a489eb8fe..86a9fb8e6 100644 --- a/INSTALLATION.md +++ b/INSTALLATION.md @@ -127,7 +127,24 @@ openssl pkcs12 -inkey ./cert/local_dev.key -in ./cert/local_dev.crt -export -out openssl base64 -in ./cert/local_dev.pfx -out ./cert/base64_pfx ``` -#Build Local Environment +# CORS Configuration -Below are the steps to follow - +As document storage is delegated to S3-compatible services that reside in a different host than the OpenSign one, document operations (loading, storing, deleting) are subject to [Cross-Origin Resource Sharing](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) restriction policies; as a consequence, OpenSign app may fail with (browser console) errors like the following: +``` +Access to fetch at 'https://foo.nyc3.digitaloceanspaces.com/exported_file_4627_0000-00-00T00%3A45%3A43.344Z.pdf' +from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header +is present on the requested resource. If an opaque response serves your needs, set the request's mode to +'no-cors' to fetch the resource with CORS disabled. +``` + +In order to address this, your document storage system must be instructed to accept requests from other hosts; below the relevant documentation links: +- [How to Configure CORS on DigitalOcean Spaces](https://docs.digitalocean.com/products/spaces/how-to/configure-cors/) +- [Configuring cross-origin resource sharing on AWS S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/enabling-cors-examples.html) + +# Build Local Environment + +Command to build project - - Execute `make build` + +Command to run project - +- Execute `make run` \ No newline at end of file diff --git a/Makefile b/Makefile index 35fa55901..d44c064b7 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,9 @@ build: + cp .env.local_dev .env + rm -rf apps/OpenSign/public/mfbuild + cd microfrontends/SignDocuments && npm install && npm run build + docker compose up --build --force-recreate + +run: cp .env.local_dev .env docker compose up -d \ No newline at end of file diff --git a/README.md b/README.md index 200487ed5..7a4d986c7 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,7 @@ -
Hello!
This is a html checking mail
" @@ -46,14 +62,60 @@ async function sendmail(req) { const from = req.params.from || ''; const messageParams = { - from: from + ' <' + process.env.MAILGUN_SENDER + '>', + from: + from + ' <' + process.env.SMTP_ENABLE + ? process.env.SMTP_USER_EMAIL + : process.env.MAILGUN_SENDER + '>', to: req.params.recipient, subject: req.params.subject, text: req.params.text || 'mail', html: req.params.html || '', - attachment: file, + attachments: process.env.SMTP_ENABLE ? [file] : undefined, + attachment: process.env.SMTP_ENABLE ? undefined : file, }; + if (transporterSMTP) { + const res = await transporterSMTP.sendMail(messageParams); + + console.log('Res ', res); + if (!res.err) { + return { + status: 'success', + }; + } + } else { + const res = await mailgunClient.messages.create(mailgunDomain, messageParams); + console.log('Res ', res); + if (res.status === 200) { + return { + status: 'success', + }; + } + } + } + } else { + const from = req.params.from || ''; + const messageParams = { + from: + from + ' <' + process.env.SMTP_ENABLE + ? process.env.SMTP_USER_EMAIL + : process.env.MAILGUN_SENDER + '>', + to: req.params.recipient, + subject: req.params.subject, + text: req.params.text || 'mail', + html: req.params.html || '', + }; + + if (transporterSMTP) { + const res = await transporterSMTP.sendMail(messageParams); + + console.log('Res ', res); + if (!res.err) { + return { + status: 'success', + }; + } + } else { const res = await mailgunClient.messages.create(mailgunDomain, messageParams); console.log('Res ', res); if (res.status === 200) { @@ -62,23 +124,6 @@ async function sendmail(req) { }; } } - } else { - const from = req.params.from || ''; - const messageParams = { - from: from + ' <' + process.env.MAILGUN_SENDER + '>', - to: req.params.recipient, - subject: req.params.subject, - text: req.params.text || 'mail', - html: req.params.html || '', - }; - - const res = await mailgunClient.messages.create(mailgunDomain, messageParams); - console.log('Res ', res); - if (res.status === 200) { - return { - status: 'success', - }; - } } } catch (err) { console.log('err ', err); diff --git a/apps/OpenSignServer/index.js b/apps/OpenSignServer/index.js index b60238cf7..14ca95558 100644 --- a/apps/OpenSignServer/index.js +++ b/apps/OpenSignServer/index.js @@ -21,7 +21,7 @@ import { exec } from 'child_process'; const spacesEndpoint = new AWS.Endpoint(process.env.DO_ENDPOINT); // console.log("configuration ", configuration); -if (process.env.USE_LOCAL !== 'TRUE') { +if (process.env.USE_LOCAL !== "TRUE") { const s3Options = { bucket: process.env.DO_SPACE, // globalConfig.S3FilesAdapter.bucket, baseUrl: process.env.DO_BASEURL, @@ -41,14 +41,27 @@ if (process.env.USE_LOCAL !== 'TRUE') { }); } +let transporterMail; let mailgunClient; let mailgunDomain; -if (process.env.MAILGUN_API_KEY) { + +if (process.env.SMTP_ENABLE) { + transporterMail = createTransport({ + host: process.env.SMTP_HOST, + port: process.env.SMTP_PORT || 465, + secure: process.env.SMTP_SECURE || true, + auth: { + user: process.env.SMTP_USER_EMAIL, + pass: process.env.SMTP_PASS, + }, + }); +} else if (process.env.MAILGUN_API_KEY) { const mailgun = new Mailgun(formData); mailgunClient = mailgun.client({ username: 'api', key: process.env.MAILGUN_API_KEY, }); + mailgunDomain = process.env.MAILGUN_DOMAIN; } @@ -65,36 +78,39 @@ export const config = { // Your apps name. This will appear in the subject and body of the emails that are sent. appName: 'Open Sign', allowClientClassCreation: false, - emailAdapter: process.env.MAILGUN_API_KEY - ? { - module: 'parse-server-api-mail-adapter', - options: { - // The email address from which emails are sent. - sender: process.env.MAILGUN_SENDER, - // The email templates. - templates: { - // The template used by Parse Server to send an email for password - // reset; this is a reserved template name. - passwordResetEmail: { - subjectPath: './files/password_reset_email_subject.txt', - textPath: './files/password_reset_email.txt', - htmlPath: './files/password_reset_email.html', + emailAdapter: + process.env.SMTP_ENABLE || process.env.MAILGUN_API_KEY + ? { + module: 'parse-server-api-mail-adapter', + options: { + // The email address from which emails are sent. + sender: process.env.SMTP_ENABLE ? process.env.SMTP_USER_EMAIL : process.env.MAILGUN_SENDER, + // The email templates. + templates: { + // The template used by Parse Server to send an email for password + // reset; this is a reserved template name. + passwordResetEmail: { + subjectPath: './files/password_reset_email_subject.txt', + textPath: './files/password_reset_email.txt', + htmlPath: './files/password_reset_email.html', + }, + // The template used by Parse Server to send an email for email + // address verification; this is a reserved template name. + verificationEmail: { + subjectPath: './files/verification_email_subject.txt', + textPath: './files/verification_email.txt', + htmlPath: './files/verification_email.html', + }, }, - // The template used by Parse Server to send an email for email - // address verification; this is a reserved template name. - verificationEmail: { - subjectPath: './files/verification_email_subject.txt', - textPath: './files/verification_email.txt', - htmlPath: './files/verification_email.html', + apiCallback: async ({ payload, locale }) => { + if (mailgunClient) { + const mailgunPayload = ApiPayloadConverter.mailgun(payload); + await mailgunClient.messages.create(mailgunDomain, mailgunPayload); + } else if (transporterMail) await transporterMail.sendMail(payload); }, }, - apiCallback: async ({ payload, locale }) => { - const mailgunPayload = ApiPayloadConverter.mailgun(payload); - await mailgunClient.messages.create(mailgunDomain, mailgunPayload); - }, - }, - } - : null, + } + : null, filesAdapter: fsAdapter, auth: { google: { diff --git a/apps/OpenSignServer/package-lock.json b/apps/OpenSignServer/package-lock.json index aadbb80b1..f7626012e 100644 --- a/apps/OpenSignServer/package-lock.json +++ b/apps/OpenSignServer/package-lock.json @@ -18,12 +18,13 @@ "express-sse": "^0.5.3", "form-data": "^4.0.0", "jsonschema": "^1.4.1", - "mailgun.js": "^9.0.1", + "mailgun.js": "^9.3.0", "mongoose": "^7.2.1", "multer": "^1.4.5-lts.1", "multer-s3": "^2.10.0", "node-forge": "^1.3.1", "node-signpdf": "^1.5.1", + "nodemailer": "^6.9.7", "openai": "^4.8.0", "parse": "4.1.0", "parse-server": "6.3.1", @@ -6017,9 +6018,9 @@ } }, "node_modules/mailgun.js": { - "version": "9.0.1", - "resolved": "https://registry.npmjs.org/mailgun.js/-/mailgun.js-9.0.1.tgz", - "integrity": "sha512-bVZ1zGh5UfQcChqIwIAil99hzoTeB3aHqAUbqmIBLMLcKfx+FF2qvhbc00WtwrFhe5dBQqQw6zPj0QBlqV4nXg==", + "version": "9.3.0", + "resolved": "https://registry.npmjs.org/mailgun.js/-/mailgun.js-9.3.0.tgz", + "integrity": "sha512-iRqCglCdi+Q5anFpeRKHiytT/i34E14p/WtTE57VSeq5bATK+zQ8UnpFgPRaqGGTJqyGjqcO9m5YDRRB4/qirw==", "dependencies": { "axios": "^1.3.3", "base-64": "^1.0.0", @@ -6800,6 +6801,14 @@ "node-forge": "^1.2.1" } }, + "node_modules/nodemailer": { + "version": "6.9.7", + "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.7.tgz", + "integrity": "sha512-rUtR77ksqex/eZRLmQ21LKVH5nAAsVicAtAYudK7JgwenEDZ0UIQ1adUGqErz7sMkWYxWTTU1aeP2Jga6WQyJw==", + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/nodemon": { "version": "2.0.22", "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.22.tgz", diff --git a/apps/OpenSignServer/package.json b/apps/OpenSignServer/package.json index 50292ad43..5049e7188 100644 --- a/apps/OpenSignServer/package.json +++ b/apps/OpenSignServer/package.json @@ -27,18 +27,19 @@ "express-sse": "^0.5.3", "form-data": "^4.0.0", "jsonschema": "^1.4.1", - "mailgun.js": "^9.0.1", + "mailgun.js": "^9.3.0", "mongoose": "^7.2.1", "multer": "^1.4.5-lts.1", "multer-s3": "^2.10.0", "node-forge": "^1.3.1", "node-signpdf": "^1.5.1", + "nodemailer": "^6.9.7", "openai": "^4.8.0", "parse": "4.1.0", "parse-server": "6.3.1", "parse-server-api-mail-adapter": "^3.0.0", - "parse-server-s3-adapter": "^1.2.0", "parse-server-fs-adapter": "1.0.1", + "parse-server-s3-adapter": "^1.2.0", "pdf-lib": "^1.16.0", "pdfkit": "^0.13.0", "razorpay": "^2.8.6", diff --git a/microfrontends/SignDocuments/src/Component/Certificate/Certificate.js b/microfrontends/SignDocuments/src/Component/Certificate/Certificate.js index 5df07d5f5..37eee4fc3 100644 --- a/microfrontends/SignDocuments/src/Component/Certificate/Certificate.js +++ b/microfrontends/SignDocuments/src/Component/Certificate/Certificate.js @@ -1,7 +1,15 @@ import React, { useEffect, useState } from "react"; import "./certificate.css"; +import opensignLogo from "../../assests/open-sign-logo.png"; -import { Page, Text, View, Document, StyleSheet } from "@react-pdf/renderer"; +import { + Page, + Text, + View, + Document, + StyleSheet, + Image +} from "@react-pdf/renderer"; function Certificate({ pdfData }) { const [isMultiSigners, setIsMultiSigners] = useState(); @@ -49,70 +57,34 @@ function Certificate({ pdfData }) { fontSize: "11px", marginBottom: "10px", color: "gray" + }, + image: { + width: "71px", + height: "17px" } }); const generatedDate = () => { const newDate = new Date(); - const localExpireDate = newDate.toLocaleDateString("en-US", { - day: "numeric", - month: "long", - year: "numeric" - }); - - var currentOffset = newDate.getTimezoneOffset(); - - var ISTOffset = 330; // IST offset UTC +5:30 - - var ISTTime = new Date( - newDate.getTime() + (ISTOffset + currentOffset) * 60000 - ); - - // ISTTime now represents the time in IST coordinates - - var hoursIST = ISTTime.getHours(); - var minutesIST = ISTTime.getMinutes(); + const utcTime = newDate.toUTCString(); return (