@@ -200,6 +200,79 @@ module.exports = {
200200 }
201201 } ,
202202
203+ /**
204+ * Update project rate limits settings
205+ *
206+ * @param {ResolverObj } _obj
207+ * @param {string } id - project id
208+ * @param {Object | null } rateLimitSettings - rate limit settings (null to remove)
209+ * @param {UserInContext } user - current authorized user {@see ../index.js}
210+ * @param {ContextFactories } factories - factories for working with models
211+ *
212+ * @returns {Project }
213+ */
214+ async updateProjectRateLimits ( _obj , { id, rateLimitSettings } , { user, factories } ) {
215+ const project = await factories . projectsFactory . findById ( id ) ;
216+
217+ if ( ! project ) {
218+ throw new ApolloError ( 'There is no project with that id' ) ;
219+ }
220+
221+ if ( project . workspaceId . toString ( ) === '6213b6a01e6281087467cc7a' ) {
222+ throw new ApolloError ( 'Unable to update demo project' ) ;
223+ }
224+
225+ // Validate rate limit settings if provided
226+ if ( rateLimitSettings ) {
227+ const { N, T } = rateLimitSettings ;
228+
229+ // Validate that N and T exist
230+ if ( ! N || ! T ) {
231+ throw new UserInputError (
232+ 'Rate limit settings must contain both N (threshold) and T (period) fields.'
233+ ) ;
234+ }
235+
236+ // Validate N (threshold) - must be positive integer > 0
237+ if ( typeof N !== 'number' || ! Number . isInteger ( N ) || N <= 0 ) {
238+ throw new UserInputError (
239+ 'Invalid rate limit threshold. Must be a positive integer greater than 0.'
240+ ) ;
241+ }
242+
243+ // Validate T (period) - must be positive integer >= 60 (1 minute)
244+ if ( typeof T !== 'number' || ! Number . isInteger ( T ) || T < 60 ) {
245+ throw new UserInputError (
246+ 'Invalid rate limit period. Must be a positive integer greater than or equal to 60 seconds.'
247+ ) ;
248+ }
249+
250+ // Validate reasonable maximums (prevent extremely large values)
251+ const MAX_THRESHOLD = 1000000000 ; // 1 billion
252+ const MAX_PERIOD = 60 * 60 * 24 * 31 ; // 1 month in seconds
253+
254+ if ( N > MAX_THRESHOLD ) {
255+ throw new UserInputError (
256+ `Rate limit threshold cannot exceed ${ MAX_THRESHOLD . toLocaleString ( ) } .`
257+ ) ;
258+ }
259+
260+ if ( T > MAX_PERIOD ) {
261+ throw new UserInputError (
262+ `Rate limit period cannot exceed ${ MAX_PERIOD . toLocaleString ( ) } seconds (1 month).`
263+ ) ;
264+ }
265+ }
266+
267+ try {
268+ return project . updateProject ( {
269+ rateLimitSettings : rateLimitSettings || null ,
270+ } ) ;
271+ } catch ( err ) {
272+ throw new ApolloError ( 'Failed to update project rate limit settings' , { originalError : err } ) ;
273+ }
274+ } ,
275+
203276 /**
204277 * Generates new project integration token by id
205278 *
0 commit comments