Skip to content

Commit bc599ad

Browse files
authored
fix: access available features from product plans (#5358)
This will let us to configure available features for each plan.
1 parent a7a019f commit bc599ad

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

apps/builder/app/shared/db/user-plan-features.server.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const getUserPlanFeatures = async (
2121

2222
const productsResult = await postgrest.client
2323
.from("Product")
24-
.select("name")
24+
.select("name, meta")
2525
.in(
2626
"id",
2727
userProducts.map(({ productId }) => productId ?? "")
@@ -34,19 +34,34 @@ export const getUserPlanFeatures = async (
3434

3535
const products = productsResult.data;
3636

37-
// This is fast and dirty implementation
38-
// @todo: implement this using products meta, custom table with aggregated transaction info
3937
if (userProducts.length > 0) {
4038
const hasSubscription = userProducts.some(
4139
(log) => log.subscriptionId !== null
4240
);
43-
41+
const productMetas = products.map((product) => {
42+
return {
43+
allowShareAdminLinks: true,
44+
allowDynamicData: true,
45+
maxContactEmails: 5,
46+
maxDomainsAllowedPerUser: Number.MAX_SAFE_INTEGER,
47+
maxPublishesAllowedPerUser: Number.MAX_SAFE_INTEGER,
48+
...(product.meta as Partial<UserPlanFeatures>),
49+
};
50+
});
4451
return {
45-
allowShareAdminLinks: true,
46-
allowDynamicData: true,
47-
maxContactEmails: 5,
48-
maxDomainsAllowedPerUser: Number.MAX_SAFE_INTEGER,
49-
maxPublishesAllowedPerUser: Number.MAX_SAFE_INTEGER,
52+
allowShareAdminLinks: productMetas.some(
53+
(item) => item.allowShareAdminLinks
54+
),
55+
allowDynamicData: productMetas.some((item) => item.allowDynamicData),
56+
maxContactEmails: Math.max(
57+
...productMetas.map((item) => item.maxContactEmails)
58+
),
59+
maxDomainsAllowedPerUser: Math.max(
60+
...productMetas.map((item) => item.maxDomainsAllowedPerUser)
61+
),
62+
maxPublishesAllowedPerUser: Math.max(
63+
...productMetas.map((item) => item.maxPublishesAllowedPerUser)
64+
),
5065
hasSubscription,
5166
hasProPlan: true,
5267
planName: products[0].name,

0 commit comments

Comments
 (0)