Skip to content

Commit 22e2940

Browse files
fix
1 parent 8d5bfbb commit 22e2940

File tree

2 files changed

+8
-35
lines changed

2 files changed

+8
-35
lines changed

packages/web/src/features/entitlements/constants.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
const planLabels = {
44
oss: "OSS",
55
"cloud:team": "Team",
6+
"cloud:demo": "Demo",
67
"self-hosted:enterprise": "Enterprise (Self-Hosted)",
78
"self-hosted:enterprise-unlimited": "Enterprise (Self-Hosted) Unlimited",
8-
"self-hosted:enterprise-custom": "Enterprise (Self-Hosted) Custom",
99
} as const;
1010
export type Plan = keyof typeof planLabels;
1111

@@ -21,14 +21,11 @@ const entitlements = [
2121
] as const;
2222
export type Entitlement = (typeof entitlements)[number];
2323

24-
export const isValidEntitlement = (entitlement: string): entitlement is Entitlement => {
25-
return entitlements.includes(entitlement as Entitlement);
26-
}
27-
2824
export const entitlementsByPlan: Record<Plan, Entitlement[]> = {
2925
oss: [],
3026
"cloud:team": ["billing", "multi-tenancy", "sso", "code-nav"],
3127
"self-hosted:enterprise": ["search-contexts", "sso", "code-nav"],
3228
"self-hosted:enterprise-unlimited": ["search-contexts", "public-access", "sso", "code-nav"],
33-
"self-hosted:enterprise-custom": [],
29+
// Special entitlement for https://demo.sourcebot.dev
30+
"cloud:demo": ["public-access", "code-nav", "search-contexts"],
3431
} as const;

packages/web/src/features/entitlements/server.ts

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { env } from "@/env.mjs"
2-
import { Entitlement, entitlementsByPlan, Plan, isValidEntitlement } from "./constants"
2+
import { Entitlement, entitlementsByPlan, Plan } from "./constants"
33
import { base64Decode } from "@/lib/utils";
44
import { z } from "zod";
55
import { SOURCEBOT_SUPPORT_EMAIL } from "@/lib/constants";
@@ -12,7 +12,6 @@ const eeLicenseKeyPayloadSchema = z.object({
1212
seats: z.number(),
1313
// ISO 8601 date string
1414
expiryDate: z.string().datetime(),
15-
customEntitlements: z.array(z.string()).optional()
1615
});
1716

1817
type LicenseKeyPayload = z.infer<typeof eeLicenseKeyPayloadSchema>;
@@ -39,6 +38,10 @@ export const getLicenseKey = (): LicenseKeyPayload | null => {
3938

4039
export const getPlan = (): Plan => {
4140
if (env.NEXT_PUBLIC_SOURCEBOT_CLOUD_ENVIRONMENT) {
41+
if (env.NEXT_PUBLIC_SOURCEBOT_CLOUD_ENVIRONMENT === "demo") {
42+
return "cloud:demo";
43+
}
44+
4245
return "cloud:team";
4346
}
4447

@@ -50,9 +53,6 @@ export const getPlan = (): Plan => {
5053
process.exit(1);
5154
}
5255

53-
if (licenseKey.customEntitlements) {
54-
return "self-hosted:enterprise-custom";
55-
}
5656
return licenseKey.seats === SOURCEBOT_UNLIMITED_SEATS ? "self-hosted:enterprise-unlimited" : "self-hosted:enterprise";
5757
} else {
5858
console.info(`No valid license key found. Falling back to oss plan.`);
@@ -71,30 +71,6 @@ export const hasEntitlement = (entitlement: Entitlement) => {
7171
}
7272

7373
export const getEntitlements = (): Entitlement[] => {
74-
const licenseKey = getLicenseKey();
75-
if (!licenseKey) {
76-
return entitlementsByPlan["oss"];
77-
}
78-
7974
const plan = getPlan();
80-
if (plan === "self-hosted:enterprise-custom") {
81-
const customEntitlements = licenseKey.customEntitlements;
82-
if (!customEntitlements) {
83-
console.error(`The provided license key is under the self-hosted:enterprise-custom plan but has no custom entitlements. Returning oss entitlements.`);
84-
return entitlementsByPlan["oss"];
85-
}
86-
87-
const validCustomEntitlements: Entitlement[] = [];
88-
for (const entitlement of customEntitlements) {
89-
if (!isValidEntitlement(entitlement)) {
90-
console.error(`Invalid custom entitlement "${entitlement}" provided in license key. Skipping.`);
91-
continue;
92-
}
93-
validCustomEntitlements.push(entitlement as Entitlement);
94-
}
95-
96-
return validCustomEntitlements;
97-
}
98-
9975
return entitlementsByPlan[plan];
10076
}

0 commit comments

Comments
 (0)