Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat(ee): add team limits

Marc Seitz4750b3c632d3
diff --git a/ee/LICENSE b/ee/LICENSE
new file mode 100644
index 00000000..c1917dad
--- /dev/null
+++ b/ee/LICENSE
@@ -0,0 +1,40 @@
+The Papermark Commercial License (the “Commercial License”)
+Copyright (c) 2024-present Papermark, Inc
+
+With regard to the Papermark Software:
+
+This software and associated documentation files (the "Software") may only be
+used in production, if you (and any entity that you represent) have agreed to,
+and are in compliance with, an agreement governing
+the use of the Software, as mutually agreed by you and Papermark, Inc ("Papermark"),
+and otherwise have a valid Papermark Enterprise Edition subscription ("Commercial Subscription").
+Subject to the foregoing sentence, you are free to modify this Software and publish patches to the Software.
+You agree that Papermark and/or its licensors (as applicable) retain all right, title and interest in
+and to all such modifications and/or patches, and all such modifications and/or
+patches may only be used, copied, modified, displayed, distributed, or otherwise
+exploited with a valid Commercial Subscription for the correct number of hosts.
+Notwithstanding the foregoing, you may copy and modify the Software for development
+and testing purposes, without requiring a subscription. You agree that Papermark and/or
+its licensors (as applicable) retain all right, title and interest in and to all such
+modifications. You are not granted any other rights beyond what is expressly stated herein.
+Subject to the foregoing, it is forbidden to copy, merge, publish, distribute, sublicense,
+and/or sell the Software.
+
+This Commercial License applies only to the part of this Software that is not distributed under
+the AGPLv3 license. Any part of this Software distributed under the MIT license or which
+is served client-side as an image, font, cascading stylesheet (CSS), file which produces
+or is compiled, arranged, augmented, or combined into client-side JavaScript, in whole or
+in part, is copyrighted under the AGPLv3 license. The full text of this Commercial License shall
+be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+For all third party components incorporated into the Papermark Software, those
+components are licensed under the original license provided by the owner of the
+applicable component.
diff --git a/ee/limits/server.ts b/ee/limits/server.ts
new file mode 100644
index 00000000..321c617b
--- /dev/null
+++ b/ee/limits/server.ts
@@ -0,0 +1,49 @@
+import prisma from "@/lib/prisma";
+import { z } from "zod";
+
+export async function getLimits({
+ teamId,
+ userId,
+}: {
+ teamId: string;
+ userId: string;
+}) {
+ const team = await prisma.team.findUnique({
+ where: {
+ id: teamId,
+ users: {
+ some: {
+ userId: userId,
+ },
+ },
+ },
+ select: {
+ plan: true,
+ limits: true,
+ },
+ });
+
+ if (!team) {
+ throw new Error("Team not found");
+ }
+
+ // parse the limits json with zod and return the limits
+ // {datarooms: 1, users: 1, domains: 1, customDomainOnPro: boolean, customDomainInDataroom: boolean}
+
+ const configSchema = z.object({
+ datarooms: z.number(),
+ users: z.number(),
+ domains: z.number(),
+ customDomainOnPro: z.boolean(),
+ customDomainInDataroom: z.boolean(),
+ });
+
+ try {
+ const parsedData = configSchema.parse(team.limits);
+
+ return parsedData;
+ } catch (error) {
+ // if no limits set, then return null and don't block the team
+ return null;
+ }
+}
diff --git a/prisma/migrations/20240511000000_add_team_limits/migration.sql b/prisma/migrations/20240511000000_add_team_limits/migration.sql
new file mode 100644
index 00000000..1f6ac6f0
--- /dev/null
+++ b/prisma/migrations/20240511000000_add_team_limits/migration.sql
@@ -0,0 +1,3 @@
+-- AlterTable
+ALTER TABLE "Team" ADD COLUMN "limits" JSONB;
+
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index c2b87405..b12c59e7 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -70,11 +70,13 @@ model Team {
datarooms Dataroom[]
plan String @default("free")
- stripeId String? @unique // Stripe subscription / customer ID
+ stripeId String? @unique // Stripe customer ID
subscriptionId String? @unique // Stripe subscription ID
startsAt DateTime? // Stripe subscription start date
endsAt DateTime? // Stripe subscription end date
+ limits Json? // Plan limits // {datarooms: 1, users: 1, domains: 1, customDomainOnPro: boolean, customDomainInDataroom: boolean}
+
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}