@@ -21,7 +21,7 @@ export const getUserPlanFeatures = async (
21
21
22
22
const productsResult = await postgrest . client
23
23
. from ( "Product" )
24
- . select ( "name" )
24
+ . select ( "name, meta " )
25
25
. in (
26
26
"id" ,
27
27
userProducts . map ( ( { productId } ) => productId ?? "" )
@@ -34,19 +34,34 @@ export const getUserPlanFeatures = async (
34
34
35
35
const products = productsResult . data ;
36
36
37
- // This is fast and dirty implementation
38
- // @todo : implement this using products meta, custom table with aggregated transaction info
39
37
if ( userProducts . length > 0 ) {
40
38
const hasSubscription = userProducts . some (
41
39
( log ) => log . subscriptionId !== null
42
40
) ;
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
+ } ) ;
44
51
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
+ ) ,
50
65
hasSubscription,
51
66
hasProPlan : true ,
52
67
planName : products [ 0 ] . name ,
0 commit comments