11import {
2+ checkExternalMembership ,
23 checkPaidMembershipFromEntra ,
34 checkPaidMembershipFromTable ,
45 setPaidMembershipInTable ,
@@ -14,7 +15,7 @@ import { getEntraIdToken } from "api/functions/entraId.js";
1415import { genericConfig , roleArns } from "common/config.js" ;
1516import { getRoleCredentials } from "api/functions/sts.js" ;
1617import { SecretsManagerClient } from "@aws-sdk/client-secrets-manager" ;
17- import { DynamoDBClient } from "@aws-sdk/client-dynamodb" ;
18+ import { DynamoDBClient , QueryCommand } from "@aws-sdk/client-dynamodb" ;
1819import rateLimiter from "api/plugins/rateLimiter.js" ;
1920import { createCheckoutSession } from "api/functions/stripe.js" ;
2021import { getSecretValue } from "api/plugins/auth.js" ;
@@ -70,9 +71,9 @@ const membershipPlugin: FastifyPluginAsync = async (fastify, _options) => {
7071 } ) ;
7172 fastify . get < {
7273 Body : undefined ;
73- Querystring : { netId : string } ;
74+ Params : { netId : string } ;
7475 } > ( "/checkout/:netId" , async ( request , reply ) => {
75- const netId = ( request . params as Record < string , string > ) . netId ;
76+ const netId = request . params . netId ;
7677 if ( ! validateNetId ( netId ) ) {
7778 throw new ValidationError ( {
7879 message : `${ netId } is not a valid Illinois NetID!` ,
@@ -143,26 +144,50 @@ const membershipPlugin: FastifyPluginAsync = async (fastify, _options) => {
143144 } ) ;
144145 fastify . get < {
145146 Body : undefined ;
146- Querystring : { netId : string } ;
147+ Querystring : { list ?: string } ;
148+ Params : { netId : string } ;
147149 } > ( "/:netId" , async ( request , reply ) => {
148- const netId = ( request . params as Record < string , string > ) . netId ;
150+ const netId = request . params . netId ;
151+ const list = request . query . list || "acmpaid" ;
149152 if ( ! validateNetId ( netId ) ) {
150153 throw new ValidationError ( {
151154 message : `${ netId } is not a valid Illinois NetID!` ,
152155 } ) ;
153156 }
154- if ( fastify . nodeCache . get ( `isMember_${ netId } ` ) !== undefined ) {
157+ if ( fastify . nodeCache . get ( `isMember_${ netId } _ ${ list } ` ) !== undefined ) {
155158 return reply . header ( "X-ACM-Data-Source" , "cache" ) . send ( {
156159 netId,
157- isPaidMember : fastify . nodeCache . get ( `isMember_${ netId } ` ) ,
160+ list : list === "acmpaid" ? undefined : list ,
161+ isPaidMember : fastify . nodeCache . get ( `isMember_${ netId } _${ list } ` ) ,
162+ } ) ;
163+ }
164+ if ( list !== "acmpaid" ) {
165+ const isMember = await checkExternalMembership (
166+ netId ,
167+ list ,
168+ fastify . dynamoClient ,
169+ ) ;
170+ fastify . nodeCache . set (
171+ `isMember_${ netId } _${ list } ` ,
172+ isMember ,
173+ MEMBER_CACHE_SECONDS ,
174+ ) ;
175+ return reply . header ( "X-ACM-Data-Source" , "dynamo" ) . send ( {
176+ netId,
177+ list,
178+ isPaidMember : isMember ,
158179 } ) ;
159180 }
160181 const isDynamoMember = await checkPaidMembershipFromTable (
161182 netId ,
162183 fastify . dynamoClient ,
163184 ) ;
164185 if ( isDynamoMember ) {
165- fastify . nodeCache . set ( `isMember_${ netId } ` , true , MEMBER_CACHE_SECONDS ) ;
186+ fastify . nodeCache . set (
187+ `isMember_${ netId } _${ list } ` ,
188+ true ,
189+ MEMBER_CACHE_SECONDS ,
190+ ) ;
166191 return reply
167192 . header ( "X-ACM-Data-Source" , "dynamo" )
168193 . send ( { netId, isPaidMember : true } ) ;
@@ -178,15 +203,19 @@ const membershipPlugin: FastifyPluginAsync = async (fastify, _options) => {
178203 paidMemberGroup ,
179204 ) ;
180205 if ( isAadMember ) {
181- fastify . nodeCache . set ( `isMember_${ netId } ` , true , MEMBER_CACHE_SECONDS ) ;
206+ fastify . nodeCache . set (
207+ `isMember_${ netId } _${ list } ` ,
208+ true ,
209+ MEMBER_CACHE_SECONDS ,
210+ ) ;
182211 reply
183212 . header ( "X-ACM-Data-Source" , "aad" )
184213 . send ( { netId, isPaidMember : true } ) ;
185214 await setPaidMembershipInTable ( netId , fastify . dynamoClient ) ;
186215 return ;
187216 }
188217 fastify . nodeCache . set (
189- `isMember_${ netId } ` ,
218+ `isMember_${ netId } _ ${ list } ` ,
190219 false ,
191220 NONMEMBER_CACHE_SECONDS ,
192221 ) ;
0 commit comments