The Open Source DocuSign Alternative.
TypeScript digital-signaturedocument-signingdocusign-alternativee-signatureesignesignaturenext-authnextjsopen-sourcepades-standardpdfpdf-signpdf-signaturepostgresqlprismaself-hostedsigningtypescript
move document upload to feature
Timur Ercana5c6f657b8f5
diff --git a/apps/web/next.config.js b/apps/web/next.config.jsindex 498512c82..2c0429327 100644--- a/apps/web/next.config.js+++ b/apps/web/next.config.js@@ -10,6 +10,7 @@ const withTM = require("next-transpile-modules")(["@documenso/prisma","@documenso/lib","@documenso/ui",+ "@documenso/features",]);const plugins = [];plugins.push(withTM);diff --git a/apps/web/pages/api/documents/index.ts b/apps/web/pages/api/documents/index.tsindex fc14bb89e..7e8f7a655 100644--- a/apps/web/pages/api/documents/index.ts+++ b/apps/web/pages/api/documents/index.ts@@ -20,7 +20,8 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) {form.parse(req, async (err, fields, files) => {if (err) throw err;- let uploadedDocument: any = files["document"];+ const uploadedDocument: any = files["document"];+ const title = uploadedDocument[0].originalFilename;const path = uploadedDocument[0].filepath;const fs = require("fs");const buffer = fs.readFileSync(path);@@ -29,6 +30,7 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) {.$transaction([prisma.document.create({data: {+ title: title,userId: user?.id,document: documentAsBase64EncodedString,},@@ -49,8 +51,13 @@ async function getHandler(req: NextApiRequest, res: NextApiResponse) {return res.status(200).json(await prisma.document.findMany({- where: { userId: user?.id },- select: { id: true },+ where: {+ userId: user?.id,+ },+ select: {+ id: true,+ title: true,+ },}));}diff --git a/apps/web/pages/dashboard.tsx b/apps/web/pages/dashboard.tsxindex ee40f2e38..1af901976 100644--- a/apps/web/pages/dashboard.tsx+++ b/apps/web/pages/dashboard.tsx@@ -17,6 +17,7 @@ import { FormProvider, useForm } from "react-hook-form";import Router from "next/router";import { NEXT_PUBLIC_WEBAPP_URL } from "@documenso/lib";import toast from "react-hot-toast";+import { uploadDocument } from "@documenso/features";type FormValues = {document: File;@@ -62,33 +63,6 @@ const DashboardPage: NextPageWithLayout = () => {},];- const uploadToServer = async (event: any) => {- if (event.target.files && event.target.files[0]) {- const body = new FormData();- const document = event.target.files[0];- body.append("document", document || "");- const response: any = await toast- .promise(- fetch("/api/documents", {- method: "POST",- body,- }),- {- loading: "Uploading document...",- success: "Document uploaded successfully.",- error: "Could not upload document :/",- }- )- .then((response: Response) => {- response.json().then((createdDocumentIdFromBody) => {- Router.push(- `${NEXT_PUBLIC_WEBAPP_URL}/documents/${createdDocumentIdFromBody}`- );- });- });- }- };-return (<><Head>@@ -123,7 +97,7 @@ const DashboardPage: NextPageWithLayout = () => {id="fileUploadHelper"type="file"onChange={(event: any) => {- uploadToServer(event);+ uploadDocument(event);}}hidden/>diff --git a/apps/web/pages/documents.tsx b/apps/web/pages/documents.tsxindex 13a96a5ba..f5352dec1 100644--- a/apps/web/pages/documents.tsx+++ b/apps/web/pages/documents.tsx@@ -4,12 +4,9 @@ import Layout from "../components/layout";import type { NextPageWithLayout } from "./_app";import Head from "next/head";import { PlusIcon, TrashIcon } from "@heroicons/react/24/outline";-import { Document as PrismaDocument } from "@prisma/client";-import { getUserFromToken } from "@documenso/lib/server";import Link from "next/link";import { useRouter } from "next/router";-import { NEXT_PUBLIC_WEBAPP_URL } from "@documenso/lib/constants";-import toast from "react-hot-toast";+import { uploadDocument } from "@documenso/features";const DocumentsPage: NextPageWithLayout = (req, res) => {const router = useRouter();@@ -38,33 +35,6 @@ const DocumentsPage: NextPageWithLayout = (req, res) => {router.push("/documents/" + documentId);}- const uploadToServer = async (event: any) => {- if (event.target.files && event.target.files[0]) {- const body = new FormData();- const document = event.target.files[0];- body.append("document", document || "");- const response: any = await toast- .promise(- fetch("/api/documents", {- method: "POST",- body,- }),- {- loading: "Uploading document...",- success: "Document uploaded successfully.",- error: "Could not upload document :/",- }- )- .then((response: Response) => {- response.json().then((createdDocumentIdFromBody) => {- router.push(- `${NEXT_PUBLIC_WEBAPP_URL}/documents/${createdDocumentIdFromBody}`- );- });- });- }- };-return (<><Head>@@ -237,7 +207,7 @@ const DocumentsPage: NextPageWithLayout = (req, res) => {id="fileUploadHelper"type="file"onChange={(event: any) => {- uploadToServer(event);+ uploadDocument(event);}}hidden/>diff --git a/package-lock.json b/package-lock.jsonindex 85eb632da..83f69d35f 100644--- a/package-lock.json+++ b/package-lock.json@@ -40,7 +40,6 @@}},"apps/web": {- "name": "@documenso/web","version": "0.1.0","dependencies": {"@documenso/prisma": "*",@@ -104,9 +103,9 @@}},"node_modules/@babel/runtime": {- "version": "7.20.7",- "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.20.7.tgz",- "integrity": "sha512-UF0tvkUtxwAgZ5W/KrkHf0Rn0fdnLDU9ScxBrEVNUprE/MzirjK4MJUX1/BVDv00Sv8cljtukVK1aky++X1SjQ==",+ "version": "7.20.13",+ "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.20.13.tgz",+ "integrity": "sha512-gt3PKXs0DBoL9xCvOIIZ2NEqAGZqHjAnmVbfQtB620V0uReIQutpel14KcneZuer7UioY8ALKZ7iocavvzTNFA==","dependencies": {"regenerator-runtime": "^0.13.11"},@@ -126,6 +125,10 @@"node": ">=12"}},+ "node_modules/@documenso/features": {+ "resolved": "packages/features",+ "link": true+ },"node_modules/@documenso/lib": {"resolved": "packages/lib","link": true@@ -706,13 +709,13 @@"integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew=="},"node_modules/@typescript-eslint/parser": {- "version": "5.48.2",- "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.48.2.tgz",- "integrity": "sha512-38zMsKsG2sIuM5Oi/olurGwYJXzmtdsHhn5mI/pQogP+BjYVkK5iRazCQ8RGS0V+YLk282uWElN70zAAUmaYHw==",+ "version": "5.49.0",+ "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.49.0.tgz",+ "integrity": "sha512-veDlZN9mUhGqU31Qiv2qEp+XrJj5fgZpJ8PW30sHU+j/8/e5ruAhLaVDAeznS7A7i4ucb/s8IozpDtt9NqCkZg==","dependencies": {- "@typescript-eslint/scope-manager": "5.48.2",- "@typescript-eslint/types": "5.48.2",- "@typescript-eslint/typescript-estree": "5.48.2",+ "@typescript-eslint/scope-manager": "5.49.0",+ "@typescript-eslint/types": "5.49.0",+ "@typescript-eslint/typescript-estree": "5.49.0","debug": "^4.3.4"},"engines": {@@ -732,12 +735,12 @@}},"node_modules/@typescript-eslint/scope-manager": {- "version": "5.48.2",- "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.48.2.tgz",- "integrity": "sha512-zEUFfonQid5KRDKoI3O+uP1GnrFd4tIHlvs+sTJXiWuypUWMuDaottkJuR612wQfOkjYbsaskSIURV9xo4f+Fw==",+ "version": "5.49.0",+ "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.49.0.tgz",+ "integrity": "sha512-clpROBOiMIzpbWNxCe1xDK14uPZh35u4QaZO1GddilEzoCLAEz4szb51rBpdgurs5k2YzPtJeTEN3qVbG+LRUQ==","dependencies": {- "@typescript-eslint/types": "5.48.2",- "@typescript-eslint/visitor-keys": "5.48.2"+ "@typescript-eslint/types": "5.49.0",+ "@typescript-eslint/visitor-keys": "5.49.0"},"engines": {"node": "^12.22.0 || ^14.17.0 || >=16.0.0"@@ -748,9 +751,9 @@}},"node_modules/@typescript-eslint/types": {- "version": "5.48.2",- "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.48.2.tgz",- "integrity": "sha512-hE7dA77xxu7ByBc6KCzikgfRyBCTst6dZQpwaTy25iMYOnbNljDT4hjhrGEJJ0QoMjrfqrx+j1l1B9/LtKeuqA==",+ "version": "5.49.0",+ "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.49.0.tgz",+ "integrity": "sha512-7If46kusG+sSnEpu0yOz2xFv5nRz158nzEXnJFCGVEHWnuzolXKwrH5Bsf9zsNlOQkyZuk0BZKKoJQI+1JPBBg==","engines": {"node": "^12.22.0 || ^14.17.0 || >=16.0.0"},@@ -760,12 +763,12 @@}},"node_modules/@typescript-eslint/typescript-estree": {- "version": "5.48.2",- "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.48.2.tgz",- "integrity": "sha512-bibvD3z6ilnoVxUBFEgkO0k0aFvUc4Cttt0dAreEr+nrAHhWzkO83PEVVuieK3DqcgL6VAK5dkzK8XUVja5Zcg==",+ "version": "5.49.0",+ "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.49.0.tgz",+ "integrity": "sha512-PBdx+V7deZT/3GjNYPVQv1Nc0U46dAHbIuOG8AZ3on3vuEKiPDwFE/lG1snN2eUB9IhF7EyF7K1hmTcLztNIsA==","dependencies": {- "@typescript-eslint/types": "5.48.2",- "@typescript-eslint/visitor-keys": "5.48.2",+ "@typescript-eslint/types": "5.49.0",+ "@typescript-eslint/visitor-keys": "5.49.0","debug": "^4.3.4","globby": "^11.1.0","is-glob": "^4.0.3",@@ -786,11 +789,11 @@}},"node_modules/@typescript-eslint/visitor-keys": {- "version": "5.48.2",- "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.48.2.tgz",- "integrity": "sha512-z9njZLSkwmjFWUelGEwEbdf4NwKvfHxvGC0OcGN1Hp/XNDIcJ7D5DpPNPv6x6/mFvc1tQHsaWmpD/a4gOvvCJQ==",+ "version": "5.49.0",+ "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.49.0.tgz",+ "integrity": "sha512-v9jBMjpNWyn8B6k/Mjt6VbUS4J1GvUlR4x3Y+ibnP1z7y7V4n0WRz+50DY6+Myj0UaXVSuUlHohO+eZ8IJEnkg==","dependencies": {- "@typescript-eslint/types": "5.48.2",+ "@typescript-eslint/types": "5.49.0","eslint-visitor-keys": "^3.3.0"},"engines": {@@ -960,9 +963,9 @@"peer": true},"node_modules/acorn": {- "version": "8.8.1",- "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.1.tgz",- "integrity": "sha512-7zFpHzhnqYKrkYdUjF1HI1bzd0VygEGX8lFk4k5zVMqHEoES+P+7TKI+EvLO9WVMJ8eekdO0aDEK044xTXwPPA==",+ "version": "8.8.2",+ "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz",+ "integrity": "sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==","bin": {"acorn": "bin/acorn"},@@ -1227,9 +1230,9 @@}},"node_modules/axe-core": {- "version": "4.6.2",- "resolved": "https://registry.npmjs.org/axe-core/-/axe-core-4.6.2.tgz",- "integrity": "sha512-b1WlTV8+XKLj9gZy2DZXgQiyDp9xkkoe2a6U6UbYccScq2wgH/YwCeI2/Jq2mgo0HzQxqJOjWZBLeA/mqsk5Mg==",+ "version": "4.6.3",+ "resolved": "https://registry.npmjs.org/axe-core/-/axe-core-4.6.3.tgz",+ "integrity": "sha512-/BQzOX780JhsxDnPpH4ZiyrJAzcd8AfzFPkv+89veFSr1rcMjuq2JDCwypKaPeB6ljHp9KjXhPpjgCvQlWYuqg==","engines": {"node": ">=4"}@@ -1350,9 +1353,9 @@}},"node_modules/caniuse-lite": {- "version": "1.0.30001446",- "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001446.tgz",- "integrity": "sha512-fEoga4PrImGcwUUGEol/PoFCSBnSkA9drgdkxXkJLsUBOnJ8rs3zDv6ApqYXGQFOyMPsjh79naWhF4DAxbF8rw==",+ "version": "1.0.30001448",+ "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001448.tgz",+ "integrity": "sha512-tq2YI+MJnooG96XpbTRYkBxLxklZPOdLmNIOdIhvf7SNJan6u5vCKum8iT7ZfCt70m1GPkuC7P3TtX6UuhupuA==","funding": [{"type": "opencollective",@@ -2464,9 +2467,9 @@}},"node_modules/get-intrinsic": {- "version": "1.1.3",- "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.3.tgz",- "integrity": "sha512-QJVz1Tj7MS099PevUG5jvnt9tSkXN8K14dxQlikJuPt4uD9hHAHjLyLBiLR5zELelBdD9QNRAXZzsJx0WaDL9A==",+ "version": "1.2.0",+ "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.0.tgz",+ "integrity": "sha512-L049y6nFOuom5wGyRc3/gdTLO94dySVKRACj1RmJZBQXlbTMhtNIgkWkUHq+jYmZvKf14EW1EoJnnjbmoHij0Q==","dependencies": {"function-bind": "^1.1.1","has": "^1.0.3",@@ -3095,9 +3098,9 @@}},"node_modules/js-sdsl": {- "version": "4.2.0",- "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.2.0.tgz",- "integrity": "sha512-dyBIzQBDkCqCu+0upx25Y2jGdbTGxE9fshMsCdK0ViOongpV+n5tXRcZY9v7CaVQ79AGS9KA1KHtojxiM7aXSQ==",+ "version": "4.3.0",+ "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.3.0.tgz",+ "integrity": "sha512-mifzlm2+5nZ+lEcLJMoBK0/IH/bDg8XnJfd/Wq6IP+xoCjLZsTOnV2QpxlVbX9bMnkl5PdEjNtBJ9Cj1NjifhQ==","funding": {"type": "opencollective","url": "https://opencollective.com/js-sdsl"@@ -3122,8 +3125,7 @@"node_modules/json-parse-even-better-errors": {"version": "2.3.1","resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz",- "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==",- "peer": true+ "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w=="},"node_modules/json-schema-traverse": {"version": "0.4.1",@@ -3456,9 +3458,9 @@}},"node_modules/next-auth": {- "version": "4.18.8",- "resolved": "https://registry.npmjs.org/next-auth/-/next-auth-4.18.8.tgz",- "integrity": "sha512-USP8ihmvB7iCGtkS0+toe2QPrzdbZfkydQZX56JOI9Ft5n/BardOXh3D4wQ2An+vpq/jDKojGlgfv21wVElW7A==",+ "version": "4.18.10",+ "resolved": "https://registry.npmjs.org/next-auth/-/next-auth-4.18.10.tgz",+ "integrity": "sha512-j2JVyH7byZ2eqXlOqNLpOO7gOlAkTzblxLZNeZihKCeIabYFHNdAJgUvVahhnHs3pZ4xaa3ZqGQHgi1uE97L9Q==","dependencies": {"@babel/runtime": "^7.16.3","@panva/hkdf": "^1.0.1",@@ -3470,9 +3472,6 @@"preact-render-to-string": "^5.1.19","uuid": "^8.3.2"},- "engines": {- "node": "^12.19.0 || ^14.15.0 || ^16.13.0 || ^18.12.0"- },"peerDependencies": {"next": "^12.2.5 || ^13","nodemailer": "^6.6.5",@@ -6295,9 +6294,9 @@}},"node_modules/openid-client": {- "version": "5.3.1",- "resolved": "https://registry.npmjs.org/openid-client/-/openid-client-5.3.1.tgz",- "integrity": "sha512-RLfehQiHch9N6tRWNx68cicf3b1WR0x74bJWHRc25uYIbSRwjxYcTFaRnzbbpls5jroLAaB/bFIodTgA5LJMvw==",+ "version": "5.3.2",+ "resolved": "https://registry.npmjs.org/openid-client/-/openid-client-5.3.2.tgz",+ "integrity": "sha512-nXXt+cna0XHOw+WqjMZOmuXw/YZEMwfWD2lD7tCsFtsBjMQGVXA+NZABA3upYBET1suhIsmfd7GnxG4jCAnvYQ==","dependencies": {"jose": "^4.10.0","lru-cache": "^6.0.0",@@ -7805,15 +7804,16 @@"url": "https://github.com/sponsors/sindresorhus"}},+ "packages/features": {+ "version": "0.0.0"+ },"packages/lib": {- "name": "@documenso/lib","version": "0.0.0","dependencies": {"bcryptjs": "^2.4.3"}},"packages/prisma": {- "name": "@documenso/prisma","version": "0.0.0","dependencies": {"@prisma/client": "^4.8.1",@@ -7832,16 +7832,15 @@"dev": true},"packages/ui": {- "name": "@documenso/ui","version": "0.0.0","devDependencies": {}}},"dependencies": {"@babel/runtime": {- "version": "7.20.7",- "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.20.7.tgz",- "integrity": "sha512-UF0tvkUtxwAgZ5W/KrkHf0Rn0fdnLDU9ScxBrEVNUprE/MzirjK4MJUX1/BVDv00Sv8cljtukVK1aky++X1SjQ==",+ "version": "7.20.13",+ "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.20.13.tgz",+ "integrity": "sha512-gt3PKXs0DBoL9xCvOIIZ2NEqAGZqHjAnmVbfQtB620V0uReIQutpel14KcneZuer7UioY8ALKZ7iocavvzTNFA==","requires": {"regenerator-runtime": "^0.13.11"}@@ -7855,6 +7854,9 @@"@jridgewell/trace-mapping": "0.3.9"}},+ "@documenso/features": {+ "version": "file:packages/features"+ },"@documenso/lib": {"version": "file:packages/lib","requires": {@@ -8317,37 +8319,37 @@"integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew=="},"@typescript-eslint/parser": {- "version": "5.48.2",- "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.48.2.tgz",- "integrity": "sha512-38zMsKsG2sIuM5Oi/olurGwYJXzmtdsHhn5mI/pQogP+BjYVkK5iRazCQ8RGS0V+YLk282uWElN70zAAUmaYHw==",+ "version": "5.49.0",+ "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.49.0.tgz",+ "integrity": "sha512-veDlZN9mUhGqU31Qiv2qEp+XrJj5fgZpJ8PW30sHU+j/8/e5ruAhLaVDAeznS7A7i4ucb/s8IozpDtt9NqCkZg==","requires": {- "@typescript-eslint/scope-manager": "5.48.2",- "@typescript-eslint/types": "5.48.2",- "@typescript-eslint/typescript-estree": "5.48.2",+ "@typescript-eslint/scope-manager": "5.49.0",+ "@typescript-eslint/types": "5.49.0",+ "@typescript-eslint/typescript-estree": "5.49.0","debug": "^4.3.4"}},"@typescript-eslint/scope-manager": {- "version": "5.48.2",- "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.48.2.tgz",- "integrity": "sha512-zEUFfonQid5KRDKoI3O+uP1GnrFd4tIHlvs+sTJXiWuypUWMuDaottkJuR612wQfOkjYbsaskSIURV9xo4f+Fw==",+ "version": "5.49.0",+ "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.49.0.tgz",+ "integrity": "sha512-clpROBOiMIzpbWNxCe1xDK14uPZh35u4QaZO1GddilEzoCLAEz4szb51rBpdgurs5k2YzPtJeTEN3qVbG+LRUQ==","requires": {- "@typescript-eslint/types": "5.48.2",- "@typescript-eslint/visitor-keys": "5.48.2"+ "@typescript-eslint/types": "5.49.0",+ "@typescript-eslint/visitor-keys": "5.49.0"}},"@typescript-eslint/types": {- "version": "5.48.2",- "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.48.2.tgz",- "integrity": "sha512-hE7dA77xxu7ByBc6KCzikgfRyBCTst6dZQpwaTy25iMYOnbNljDT4hjhrGEJJ0QoMjrfqrx+j1l1B9/LtKeuqA=="+ "version": "5.49.0",+ "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.49.0.tgz",+ "integrity": "sha512-7If46kusG+sSnEpu0yOz2xFv5nRz158nzEXnJFCGVEHWnuzolXKwrH5Bsf9zsNlOQkyZuk0BZKKoJQI+1JPBBg=="},"@typescript-eslint/typescript-estree": {- "version": "5.48.2",- "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.48.2.tgz",- "integrity": "sha512-bibvD3z6ilnoVxUBFEgkO0k0aFvUc4Cttt0dAreEr+nrAHhWzkO83PEVVuieK3DqcgL6VAK5dkzK8XUVja5Zcg==",+ "version": "5.49.0",+ "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.49.0.tgz",+ "integrity": "sha512-PBdx+V7deZT/3GjNYPVQv1Nc0U46dAHbIuOG8AZ3on3vuEKiPDwFE/lG1snN2eUB9IhF7EyF7K1hmTcLztNIsA==","requires": {- "@typescript-eslint/types": "5.48.2",- "@typescript-eslint/visitor-keys": "5.48.2",+ "@typescript-eslint/types": "5.49.0",+ "@typescript-eslint/visitor-keys": "5.49.0","debug": "^4.3.4","globby": "^11.1.0","is-glob": "^4.0.3",@@ -8356,11 +8358,11 @@}},"@typescript-eslint/visitor-keys": {- "version": "5.48.2",- "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.48.2.tgz",- "integrity": "sha512-z9njZLSkwmjFWUelGEwEbdf4NwKvfHxvGC0OcGN1Hp/XNDIcJ7D5DpPNPv6x6/mFvc1tQHsaWmpD/a4gOvvCJQ==",+ "version": "5.49.0",+ "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.49.0.tgz",+ "integrity": "sha512-v9jBMjpNWyn8B6k/Mjt6VbUS4J1GvUlR4x3Y+ibnP1z7y7V4n0WRz+50DY6+Myj0UaXVSuUlHohO+eZ8IJEnkg==","requires": {- "@typescript-eslint/types": "5.48.2",+ "@typescript-eslint/types": "5.49.0","eslint-visitor-keys": "^3.3.0"}},@@ -8523,9 +8525,9 @@"peer": true},"acorn": {- "version": "8.8.1",- "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.1.tgz",- "integrity": "sha512-7zFpHzhnqYKrkYdUjF1HI1bzd0VygEGX8lFk4k5zVMqHEoES+P+7TKI+EvLO9WVMJ8eekdO0aDEK044xTXwPPA=="+ "version": "8.8.2",+ "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz",+ "integrity": "sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw=="},"acorn-import-assertions": {"version": "1.8.0",@@ -8709,9 +8711,9 @@}},"axe-core": {- "version": "4.6.2",- "resolved": "https://registry.npmjs.org/axe-core/-/axe-core-4.6.2.tgz",- "integrity": "sha512-b1WlTV8+XKLj9gZy2DZXgQiyDp9xkkoe2a6U6UbYccScq2wgH/YwCeI2/Jq2mgo0HzQxqJOjWZBLeA/mqsk5Mg=="+ "version": "4.6.3",+ "resolved": "https://registry.npmjs.org/axe-core/-/axe-core-4.6.3.tgz",+ "integrity": "sha512-/BQzOX780JhsxDnPpH4ZiyrJAzcd8AfzFPkv+89veFSr1rcMjuq2JDCwypKaPeB6ljHp9KjXhPpjgCvQlWYuqg=="},"axobject-query": {"version": "3.1.1",@@ -8795,9 +8797,9 @@"integrity": "sha512-QOSvevhslijgYwRx6Rv7zKdMF8lbRmx+uQGx2+vDc+KI/eBnsy9kit5aj23AgGu3pa4t9AgwbnXWqS+iOY+2aA=="},"caniuse-lite": {- "version": "1.0.30001446",- "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001446.tgz",- "integrity": "sha512-fEoga4PrImGcwUUGEol/PoFCSBnSkA9drgdkxXkJLsUBOnJ8rs3zDv6ApqYXGQFOyMPsjh79naWhF4DAxbF8rw=="+ "version": "1.0.30001448",+ "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001448.tgz",+ "integrity": "sha512-tq2YI+MJnooG96XpbTRYkBxLxklZPOdLmNIOdIhvf7SNJan6u5vCKum8iT7ZfCt70m1GPkuC7P3TtX6UuhupuA=="},"chalk": {"version": "4.1.2",@@ -9626,9 +9628,9 @@"integrity": "sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ=="},"get-intrinsic": {- "version": "1.1.3",- "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.3.tgz",- "integrity": "sha512-QJVz1Tj7MS099PevUG5jvnt9tSkXN8K14dxQlikJuPt4uD9hHAHjLyLBiLR5zELelBdD9QNRAXZzsJx0WaDL9A==",+ "version": "1.2.0",+ "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.0.tgz",+ "integrity": "sha512-L049y6nFOuom5wGyRc3/gdTLO94dySVKRACj1RmJZBQXlbTMhtNIgkWkUHq+jYmZvKf14EW1EoJnnjbmoHij0Q==","requires": {"function-bind": "^1.1.1","has": "^1.0.3",@@ -10047,9 +10049,9 @@"integrity": "sha512-njj0VL2TsIxCtgzhO+9RRobBvws4oYyCM8TpvoUQwl/MbIM3NFJRR9+e6x0sS5xXaP1t6OCBkaBME98OV9zU5A=="},"js-sdsl": {- "version": "4.2.0",- "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.2.0.tgz",- "integrity": "sha512-dyBIzQBDkCqCu+0upx25Y2jGdbTGxE9fshMsCdK0ViOongpV+n5tXRcZY9v7CaVQ79AGS9KA1KHtojxiM7aXSQ=="+ "version": "4.3.0",+ "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.3.0.tgz",+ "integrity": "sha512-mifzlm2+5nZ+lEcLJMoBK0/IH/bDg8XnJfd/Wq6IP+xoCjLZsTOnV2QpxlVbX9bMnkl5PdEjNtBJ9Cj1NjifhQ=="},"js-tokens": {"version": "4.0.0",@@ -10067,8 +10069,7 @@"json-parse-even-better-errors": {"version": "2.3.1","resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz",- "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==",- "peer": true+ "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w=="},"json-schema-traverse": {"version": "0.4.1",@@ -10306,9 +10307,9 @@}},"next-auth": {- "version": "4.18.8",- "resolved": "https://registry.npmjs.org/next-auth/-/next-auth-4.18.8.tgz",- "integrity": "sha512-USP8ihmvB7iCGtkS0+toe2QPrzdbZfkydQZX56JOI9Ft5n/BardOXh3D4wQ2An+vpq/jDKojGlgfv21wVElW7A==",+ "version": "4.18.10",+ "resolved": "https://registry.npmjs.org/next-auth/-/next-auth-4.18.10.tgz",+ "integrity": "sha512-j2JVyH7byZ2eqXlOqNLpOO7gOlAkTzblxLZNeZihKCeIabYFHNdAJgUvVahhnHs3pZ4xaa3ZqGQHgi1uE97L9Q==","requires": {"@babel/runtime": "^7.16.3","@panva/hkdf": "^1.0.1",@@ -12182,9 +12183,9 @@}},"openid-client": {- "version": "5.3.1",- "resolved": "https://registry.npmjs.org/openid-client/-/openid-client-5.3.1.tgz",- "integrity": "sha512-RLfehQiHch9N6tRWNx68cicf3b1WR0x74bJWHRc25uYIbSRwjxYcTFaRnzbbpls5jroLAaB/bFIodTgA5LJMvw==",+ "version": "5.3.2",+ "resolved": "https://registry.npmjs.org/openid-client/-/openid-client-5.3.2.tgz",+ "integrity": "sha512-nXXt+cna0XHOw+WqjMZOmuXw/YZEMwfWD2lD7tCsFtsBjMQGVXA+NZABA3upYBET1suhIsmfd7GnxG4jCAnvYQ==","requires": {"jose": "^4.10.0","lru-cache": "^6.0.0",diff --git a/packages/features/index.ts b/packages/features/index.tsnew file mode 100644index 000000000..721342dd1--- /dev/null+++ b/packages/features/index.ts@@ -0,0 +1 @@+export { uploadDocument } from "./uploadDocument";diff --git a/packages/features/package.json b/packages/features/package.jsonnew file mode 100644index 000000000..36ed5449b--- /dev/null+++ b/packages/features/package.json@@ -0,0 +1,8 @@+{+ "name": "@documenso/features",+ "description": "Main features of documenso in one neat package.",+ "version": "0.0.0",+ "private": true,+ "main": "index.ts",+ "dependencies": {}+}diff --git a/packages/features/uploadDocument.ts b/packages/features/uploadDocument.tsnew file mode 100644index 000000000..5cf5c7a1b--- /dev/null+++ b/packages/features/uploadDocument.ts@@ -0,0 +1,31 @@+import router from "next/router";+import toast from "react-hot-toast";+import { NEXT_PUBLIC_WEBAPP_URL } from "../lib/constants";++export const uploadDocument = async (event: any) => {+ if (event.target.files && event.target.files[0]) {+ const body = new FormData();+ const document = event.target.files[0];+ const fileName = event.target.files[0].name;+ body.append("document", document || "");+ const response: any = await toast+ .promise(+ fetch("/api/documents", {+ method: "POST",+ body,+ }),+ {+ loading: "Uploading document...",+ success: `${fileName} uploaded successfully.`,+ error: "Could not upload document :/",+ }+ )+ .then((response: Response) => {+ response.json().then((createdDocumentIdFromBody) => {+ router.push(+ `${NEXT_PUBLIC_WEBAPP_URL}/documents/${createdDocumentIdFromBody}`+ );+ });+ });+ }+};