1
1
import {
2
+ checkExternalMembership ,
2
3
checkPaidMembershipFromEntra ,
3
4
checkPaidMembershipFromTable ,
4
5
setPaidMembershipInTable ,
@@ -14,7 +15,7 @@ import { getEntraIdToken } from "api/functions/entraId.js";
14
15
import { genericConfig , roleArns } from "common/config.js" ;
15
16
import { getRoleCredentials } from "api/functions/sts.js" ;
16
17
import { SecretsManagerClient } from "@aws-sdk/client-secrets-manager" ;
17
- import { DynamoDBClient } from "@aws-sdk/client-dynamodb" ;
18
+ import { DynamoDBClient , QueryCommand } from "@aws-sdk/client-dynamodb" ;
18
19
import rateLimiter from "api/plugins/rateLimiter.js" ;
19
20
import { createCheckoutSession } from "api/functions/stripe.js" ;
20
21
import { getSecretValue } from "api/plugins/auth.js" ;
@@ -70,9 +71,9 @@ const membershipPlugin: FastifyPluginAsync = async (fastify, _options) => {
70
71
} ) ;
71
72
fastify . get < {
72
73
Body : undefined ;
73
- Querystring : { netId : string } ;
74
+ Params : { netId : string } ;
74
75
} > ( "/checkout/:netId" , async ( request , reply ) => {
75
- const netId = ( request . params as Record < string , string > ) . netId ;
76
+ const netId = request . params . netId ;
76
77
if ( ! validateNetId ( netId ) ) {
77
78
throw new ValidationError ( {
78
79
message : `${ netId } is not a valid Illinois NetID!` ,
@@ -143,26 +144,50 @@ const membershipPlugin: FastifyPluginAsync = async (fastify, _options) => {
143
144
} ) ;
144
145
fastify . get < {
145
146
Body : undefined ;
146
- Querystring : { netId : string } ;
147
+ Querystring : { list ?: string } ;
148
+ Params : { netId : string } ;
147
149
} > ( "/: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" ;
149
152
if ( ! validateNetId ( netId ) ) {
150
153
throw new ValidationError ( {
151
154
message : `${ netId } is not a valid Illinois NetID!` ,
152
155
} ) ;
153
156
}
154
- if ( fastify . nodeCache . get ( `isMember_${ netId } ` ) !== undefined ) {
157
+ if ( fastify . nodeCache . get ( `isMember_${ netId } _ ${ list } ` ) !== undefined ) {
155
158
return reply . header ( "X-ACM-Data-Source" , "cache" ) . send ( {
156
159
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 ,
158
179
} ) ;
159
180
}
160
181
const isDynamoMember = await checkPaidMembershipFromTable (
161
182
netId ,
162
183
fastify . dynamoClient ,
163
184
) ;
164
185
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
+ ) ;
166
191
return reply
167
192
. header ( "X-ACM-Data-Source" , "dynamo" )
168
193
. send ( { netId, isPaidMember : true } ) ;
@@ -178,15 +203,19 @@ const membershipPlugin: FastifyPluginAsync = async (fastify, _options) => {
178
203
paidMemberGroup ,
179
204
) ;
180
205
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
+ ) ;
182
211
reply
183
212
. header ( "X-ACM-Data-Source" , "aad" )
184
213
. send ( { netId, isPaidMember : true } ) ;
185
214
await setPaidMembershipInTable ( netId , fastify . dynamoClient ) ;
186
215
return ;
187
216
}
188
217
fastify . nodeCache . set (
189
- `isMember_${ netId } ` ,
218
+ `isMember_${ netId } _ ${ list } ` ,
190
219
false ,
191
220
NONMEMBER_CACHE_SECONDS ,
192
221
) ;
0 commit comments