@@ -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