@gradientedge/cdk-utils 9.69.0 → 9.70.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -289,7 +289,7 @@ class AzureApiManagementManager {
289
289
  <!-- Store the response body in cache -->
290
290
  <choose>
291
291
  <when condition="@(context.Response.StatusCode == 200)">
292
- <cache-store-value key="@((string)context.Variables["customCacheKey"])" value="@(context.Response.Body.As<string>(preserveContent: true))" duration="${props.caching.ttl ?? 900}" />
292
+ <cache-store-value key="@((string)context.Variables["customCacheKey"])" value="@(context.Response.Body.As<string>(preserveContent: true))" duration="${props.caching.ttlInSecs ?? 900}" />
293
293
  <!-- Add cache status header -->
294
294
  <set-header name="X-Apim-Cache-Status" exists-action="override">
295
295
  <value>MISS</value>
@@ -335,9 +335,15 @@ class AzureApiManagementManager {
335
335
  </choose>`;
336
336
  }
337
337
  }
338
+ // Inject rate limiting policy (if configured)
339
+ let rateLimitPolicy = '';
340
+ if (props.rateLimit) {
341
+ rateLimitPolicy = `<rate-limit-by-key calls="${props.rateLimit.calls}" renewal-period="${props.rateLimit.renewalPeriodInSecs}"/>`;
342
+ }
338
343
  const policyXmlContent = `<policies>
339
344
  <inbound>
340
345
  <base />
346
+ ${rateLimitPolicy}
341
347
  ${cacheInboundPolicy}
342
348
  ${props.commonInboundPolicyXml ?? ''}
343
349
  </inbound>
@@ -17,6 +17,7 @@ export interface ApiManagementApiProps extends ApiManagementApiConfig {
17
17
  commonInboundPolicyXml: string;
18
18
  commonOutboundPolicyXml: string;
19
19
  caching?: ApiManagementApiCaching;
20
+ rateLimit?: ApiManagementApiRateLimit;
20
21
  }
21
22
  export interface ApiManagementV2Props extends ApiManagementConfig {
22
23
  body: any;
@@ -25,5 +26,9 @@ export interface ApiManagementApiOperationProps extends ApiManagementApiOperatio
25
26
  }
26
27
  export interface ApiManagementApiCaching {
27
28
  enabled: boolean;
28
- ttl?: number;
29
+ ttlInSecs?: number;
30
+ }
31
+ export interface ApiManagementApiRateLimit {
32
+ calls: number;
33
+ renewalPeriodInSecs: number;
29
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils",
3
- "version": "9.69.0",
3
+ "version": "9.70.0",
4
4
  "description": "Utilities for AWS CDK provisioning",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -352,7 +352,7 @@ export class AzureApiManagementManager {
352
352
  <!-- Store the response body in cache -->
353
353
  <choose>
354
354
  <when condition="@(context.Response.StatusCode == 200)">
355
- <cache-store-value key="@((string)context.Variables["customCacheKey"])" value="@(context.Response.Body.As<string>(preserveContent: true))" duration="${props.caching.ttl ?? 900}" />
355
+ <cache-store-value key="@((string)context.Variables["customCacheKey"])" value="@(context.Response.Body.As<string>(preserveContent: true))" duration="${props.caching.ttlInSecs ?? 900}" />
356
356
  <!-- Add cache status header -->
357
357
  <set-header name="X-Apim-Cache-Status" exists-action="override">
358
358
  <value>MISS</value>
@@ -400,9 +400,15 @@ export class AzureApiManagementManager {
400
400
  }
401
401
  }
402
402
 
403
+ // Inject rate limiting policy (if configured)
404
+ let rateLimitPolicy = ''
405
+ if (props.rateLimit) {
406
+ rateLimitPolicy = `<rate-limit-by-key calls="${props.rateLimit.calls}" renewal-period="${props.rateLimit.renewalPeriodInSecs}"/>`
407
+ }
403
408
  const policyXmlContent = `<policies>
404
409
  <inbound>
405
410
  <base />
411
+ ${rateLimitPolicy}
406
412
  ${cacheInboundPolicy}
407
413
  ${props.commonInboundPolicyXml ?? ''}
408
414
  </inbound>
@@ -19,6 +19,7 @@ export interface ApiManagementApiProps extends ApiManagementApiConfig {
19
19
  commonInboundPolicyXml: string
20
20
  commonOutboundPolicyXml: string
21
21
  caching?: ApiManagementApiCaching
22
+ rateLimit?: ApiManagementApiRateLimit
22
23
  }
23
24
 
24
25
  export interface ApiManagementV2Props extends ApiManagementConfig {
@@ -29,5 +30,10 @@ export interface ApiManagementApiOperationProps extends ApiManagementApiOperatio
29
30
 
30
31
  export interface ApiManagementApiCaching {
31
32
  enabled: boolean
32
- ttl?: number
33
+ ttlInSecs?: number
34
+ }
35
+
36
+ export interface ApiManagementApiRateLimit {
37
+ calls: number
38
+ renewalPeriodInSecs: number
33
39
  }