@gradientedge/cdk-utils 9.72.0 → 9.74.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.
@@ -5,7 +5,7 @@ import { ApiManagementApi } from '@cdktf/provider-azurerm/lib/api-management-api
5
5
  import { ApiManagementLoggerApplicationInsights } from '@cdktf/provider-azurerm/lib/api-management-logger';
6
6
  import { Resource } from '../../.gen/providers/azapi/resource';
7
7
  import { CommonAzureConstruct } from '../../common';
8
- import { ApiManagementProps, ApiManagementBackendProps, ApiManagementApiProps, ApiManagementV2Props, ApiManagementCustomDomainProps } from './types';
8
+ import { ApiManagementProps, ApiManagementBackendProps, ApiManagementApiProps, ApiManagementCustomDomainProps } from './types';
9
9
  /**
10
10
  * @classdesc Provides operations on Azure Api Management
11
11
  * - A new instance of this class is injected into {@link CommonAzureConstruct} constructor.
@@ -40,14 +40,6 @@ export declare class AzureApiManagementManager {
40
40
  * @see [CDKTF Api management Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/apiManagement.typescript.md}
41
41
  */
42
42
  resolveApiManagement(id: string, scope: CommonAzureConstruct, props: DataAzurermApiManagementConfig): DataAzurermApiManagement;
43
- /**
44
- * @summary Method to create a new api management
45
- * @param id scoped id of the resource
46
- * @param scope scope in which this resource is defined
47
- * @param props api management properties
48
- * @see [CDKTF Api management Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/apiManagement.typescript.md}
49
- */
50
- createApiManagementv2(id: string, scope: CommonAzureConstruct, props: ApiManagementV2Props, applicationInsightsKey?: ApiManagementLoggerApplicationInsights['instrumentationKey']): Resource;
51
43
  /**
52
44
  * @summary Method to create a new api management backend
53
45
  * @param id scoped id of the resource
@@ -99,67 +99,6 @@ class AzureApiManagementManager {
99
99
  });
100
100
  return apiManagement;
101
101
  }
102
- /**
103
- * @summary Method to create a new api management
104
- * @param id scoped id of the resource
105
- * @param scope scope in which this resource is defined
106
- * @param props api management properties
107
- * @see [CDKTF Api management Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/apiManagement.typescript.md}
108
- */
109
- createApiManagementv2(id, scope, props, applicationInsightsKey) {
110
- if (!props)
111
- throw `Props undefined for ${id}`;
112
- const resourceGroup = new data_azurerm_resource_group_1.DataAzurermResourceGroup(scope, `${id}-am-rg`, {
113
- name: scope.props.resourceGroupName
114
- ? scope.resourceNameFormatter.format(scope.props.resourceGroupName)
115
- : `${props.resourceGroupName}`,
116
- });
117
- if (!resourceGroup)
118
- throw `Resource group undefined for ${id}`;
119
- const apiManagement = new resource_1.Resource(scope, `${id}-am`, {
120
- type: 'Microsoft.ApiManagement/service@2024-05-01',
121
- name: scope.resourceNameFormatter.format(props.name, scope.props.resourceNameOptions?.apiManagement),
122
- location: resourceGroup.location,
123
- parentId: resourceGroup.id,
124
- body: {
125
- properties: {
126
- apiVersionConstraint: {
127
- minApiVersion: '2019-12-01',
128
- },
129
- publisherName: props.publisherName,
130
- publisherEmail: props.publisherEmail,
131
- },
132
- sku: {
133
- capacity: 1,
134
- name: props.skuName,
135
- },
136
- },
137
- responseExportValues: ['*'],
138
- identity: [
139
- {
140
- type: 'SystemAssigned',
141
- },
142
- ],
143
- ignoreMissingProperty: true,
144
- ignoreCasing: true,
145
- schemaValidationEnabled: false,
146
- lifecycle: props.lifecycle,
147
- });
148
- if (applicationInsightsKey) {
149
- new api_management_logger_1.ApiManagementLogger(scope, `${id}-am-logger`, {
150
- name: scope.resourceNameFormatter.format(props.name, scope.props.resourceNameOptions?.apiManagementLogger),
151
- resourceGroupName: resourceGroup.name,
152
- apiManagementName: apiManagement.name,
153
- applicationInsights: {
154
- instrumentationKey: applicationInsightsKey,
155
- },
156
- });
157
- }
158
- (0, utils_1.createAzureTfOutput)(`${id}-apiManagementName`, scope, apiManagement.name);
159
- (0, utils_1.createAzureTfOutput)(`${id}-apiManagementFriendlyUniqueId`, scope, apiManagement.friendlyUniqueId);
160
- (0, utils_1.createAzureTfOutput)(`${id}-apiManagementId`, scope, apiManagement.id);
161
- return apiManagement;
162
- }
163
102
  /**
164
103
  * @summary Method to create a new api management backend
165
104
  * @param id scoped id of the resource
@@ -239,11 +178,12 @@ class AzureApiManagementManager {
239
178
  (0, utils_1.createAzureTfOutput)(`${id}-${operation.displayName}-${operation.method}-apimOperationFriendlyUniqueId`, scope, apimOperation.friendlyUniqueId);
240
179
  (0, utils_1.createAzureTfOutput)(`${id}-${operation.displayName}-${operation.method}-apimOperationId`, scope, apimOperation.id);
241
180
  // Define Caching Policy if enabled
242
- let cacheInboundPolicy = '';
243
- let cacheOutboundPolicy = '';
244
- if (props.caching?.enabled === true) {
245
- if (operation.method === 'get') {
246
- cacheInboundPolicy = `<!-- Generate a comprehensive custom cache key (without query params or Accept header) -->
181
+ let cacheSetVariablePolicy = '';
182
+ let cacheInvalidateInboundPolicy = '';
183
+ let cacheSetInboundPolicy = '';
184
+ let cacheSetOutboundPolicy = '';
185
+ if (operation.caching) {
186
+ cacheSetVariablePolicy = `<!-- Generate a comprehensive custom cache key (without query params or Accept header) -->
247
187
  <set-variable name="customCacheKey" value="@{
248
188
  // Instance identification
249
189
 
@@ -253,13 +193,15 @@ class AzureApiManagementManager {
253
193
 
254
194
  // Full path construction (without query parameters)
255
195
  string fullPath = context.Request.Url.Path.ToLower();
256
-
257
- // Construct final cache key (no Accept header needed for JSON-only APIs)
258
- return $"{apiName}:{apiVersion}:{fullPath}";
259
- }" />
260
- <set-variable name="bypassCache" value="@(context.Request.Headers.GetValueOrDefault("X-Bypass-Cache", "false").ToLower())" />
261
196
 
262
- <choose>
197
+ // Query parameters
198
+ string query = context.Request.Url.Query.ToLower();
199
+
200
+ // Construct final cache key (no Accept header needed for JSON-only APIs)
201
+ return $"{apiName}:{apiVersion}:{fullPath}:{query}";
202
+ }" />`;
203
+ if (operation.caching.enableCacheSet) {
204
+ cacheSetInboundPolicy = `<choose>
263
205
  <when condition="@((string)context.Variables["bypassCache"] != "true")">
264
206
  <!-- Attempt to retrieve cached response -->
265
207
  <cache-lookup-value key="@((string)context.Variables["customCacheKey"])" variable-name="cachedResponse" />
@@ -284,12 +226,12 @@ class AzureApiManagementManager {
284
226
  </choose>
285
227
  </when>
286
228
  </choose>`;
287
- cacheOutboundPolicy = `<choose>
229
+ cacheSetOutboundPolicy = `<choose>
288
230
  <when condition="@((string)context.Variables["bypassCache"] != "true")">
289
231
  <!-- Store the response body in cache -->
290
232
  <choose>
291
233
  <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.ttlInSecs ?? 900}" />
234
+ <cache-store-value key="@((string)context.Variables["customCacheKey"])" value="@(context.Response.Body.As<string>(preserveContent: true))" duration="${operation.caching.ttlInSecs ?? 900}" />
293
235
  <!-- Add cache status header -->
294
236
  <set-header name="X-Apim-Cache-Status" exists-action="override">
295
237
  <value>MISS</value>
@@ -306,23 +248,8 @@ class AzureApiManagementManager {
306
248
  </when>
307
249
  </choose>`;
308
250
  }
309
- if (operation.method === 'post') {
310
- cacheInboundPolicy = `<!-- Generate a comprehensive custom cache key (without query params or Accept header) -->
311
- <set-variable name="customCacheKey" value="@{
312
- // Instance identification
313
-
314
- // API identification
315
- string apiName = context.Api.Name.Replace(" ", "").ToLower();
316
- string apiVersion = context.Api.Version ?? "v1";
317
-
318
- // Full path construction (without query parameters)
319
- string fullPath = context.Request.Url.Path.ToLower();
320
-
321
- // Construct final cache key (no Accept header needed for JSON-only APIs)
322
- return $"{apiName}:{apiVersion}:{fullPath}";
323
- }" />
324
- <set-variable name="clearCache" value="@(context.Request.Headers.GetValueOrDefault("X-Apim-Clear-Cache", "false").ToLower())" />
325
-
251
+ if (operation.caching.enableCacheInvalidation) {
252
+ cacheInvalidateInboundPolicy = `<set-variable name="clearCache" value="@(context.Request.Headers.GetValueOrDefault("X-Apim-Clear-Cache", "false").ToLower())" />
326
253
  <!-- Allow admin to clear specific cache entries -->
327
254
  <choose>
328
255
  <when condition="@((string)context.Variables["clearCache"] == "true")">
@@ -344,7 +271,9 @@ class AzureApiManagementManager {
344
271
  <inbound>
345
272
  <base />
346
273
  ${rateLimitPolicy}
347
- ${cacheInboundPolicy}
274
+ ${cacheSetVariablePolicy}
275
+ ${cacheInvalidateInboundPolicy}
276
+ ${cacheSetInboundPolicy}
348
277
  ${props.commonInboundPolicyXml ?? ''}
349
278
  </inbound>
350
279
  <backend>
@@ -352,7 +281,7 @@ class AzureApiManagementManager {
352
281
  </backend>
353
282
  <outbound>
354
283
  <base />
355
- ${cacheOutboundPolicy ?? ''}
284
+ ${cacheSetOutboundPolicy}
356
285
  ${props.commonOutboundPolicyXml ?? ''}
357
286
  </outbound>
358
287
  <on-error>
@@ -16,16 +16,14 @@ export interface ApiManagementApiProps extends ApiManagementApiConfig {
16
16
  operations: ApiManagementApiOperationProps[];
17
17
  commonInboundPolicyXml: string;
18
18
  commonOutboundPolicyXml: string;
19
- caching?: ApiManagementApiCaching;
20
19
  rateLimit?: ApiManagementApiRateLimit;
21
20
  }
22
- export interface ApiManagementV2Props extends ApiManagementConfig {
23
- body: any;
24
- }
25
21
  export interface ApiManagementApiOperationProps extends ApiManagementApiOperationConfig {
22
+ caching?: ApiManagementApiCaching;
26
23
  }
27
24
  export interface ApiManagementApiCaching {
28
- enabled: boolean;
25
+ enableCacheSet?: boolean;
26
+ enableCacheInvalidation?: boolean;
29
27
  ttlInSecs?: number;
30
28
  }
31
29
  export interface ApiManagementApiRateLimit {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils",
3
- "version": "9.72.0",
3
+ "version": "9.74.0",
4
4
  "description": "Utilities for AWS CDK provisioning",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -4,7 +4,6 @@ import {
4
4
  DataAzurermApiManagementConfig,
5
5
  } from '@cdktf/provider-azurerm/lib/data-azurerm-api-management'
6
6
  import { ApiManagementCustomDomain } from '@cdktf/provider-azurerm/lib/api-management-custom-domain'
7
- import { ApiManagementBackend } from '@cdktf/provider-azurerm/lib/api-management-backend'
8
7
  import { ApiManagement } from '@cdktf/provider-azurerm/lib/api-management'
9
8
  import { ApiManagementApi } from '@cdktf/provider-azurerm/lib/api-management-api'
10
9
  import { ApiManagementApiOperation } from '@cdktf/provider-azurerm/lib/api-management-api-operation'
@@ -20,7 +19,6 @@ import {
20
19
  ApiManagementProps,
21
20
  ApiManagementBackendProps,
22
21
  ApiManagementApiProps,
23
- ApiManagementV2Props,
24
22
  ApiManagementCustomDomainProps,
25
23
  } from './types'
26
24
  import _ from 'lodash'
@@ -122,82 +120,6 @@ export class AzureApiManagementManager {
122
120
  return apiManagement
123
121
  }
124
122
 
125
- /**
126
- * @summary Method to create a new api management
127
- * @param id scoped id of the resource
128
- * @param scope scope in which this resource is defined
129
- * @param props api management properties
130
- * @see [CDKTF Api management Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/apiManagement.typescript.md}
131
- */
132
- public createApiManagementv2(
133
- id: string,
134
- scope: CommonAzureConstruct,
135
- props: ApiManagementV2Props,
136
- applicationInsightsKey?: ApiManagementLoggerApplicationInsights['instrumentationKey']
137
- ) {
138
- if (!props) throw `Props undefined for ${id}`
139
-
140
- const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-am-rg`, {
141
- name: scope.props.resourceGroupName
142
- ? scope.resourceNameFormatter.format(scope.props.resourceGroupName)
143
- : `${props.resourceGroupName}`,
144
- })
145
-
146
- if (!resourceGroup) throw `Resource group undefined for ${id}`
147
-
148
- const apiManagement = new Resource(scope, `${id}-am`, {
149
- type: 'Microsoft.ApiManagement/service@2024-05-01',
150
- name: scope.resourceNameFormatter.format(props.name, scope.props.resourceNameOptions?.apiManagement),
151
- location: resourceGroup.location,
152
- parentId: resourceGroup.id,
153
-
154
- body: {
155
- properties: {
156
- apiVersionConstraint: {
157
- minApiVersion: '2019-12-01',
158
- },
159
- publisherName: props.publisherName,
160
- publisherEmail: props.publisherEmail,
161
- },
162
- sku: {
163
- capacity: 1,
164
- name: props.skuName,
165
- },
166
- },
167
-
168
- responseExportValues: ['*'],
169
-
170
- identity: [
171
- {
172
- type: 'SystemAssigned',
173
- },
174
- ],
175
-
176
- ignoreMissingProperty: true,
177
- ignoreCasing: true,
178
- schemaValidationEnabled: false,
179
-
180
- lifecycle: props.lifecycle,
181
- })
182
-
183
- if (applicationInsightsKey) {
184
- new ApiManagementLogger(scope, `${id}-am-logger`, {
185
- name: scope.resourceNameFormatter.format(props.name, scope.props.resourceNameOptions?.apiManagementLogger),
186
- resourceGroupName: resourceGroup.name,
187
- apiManagementName: apiManagement.name,
188
- applicationInsights: {
189
- instrumentationKey: applicationInsightsKey,
190
- },
191
- })
192
- }
193
-
194
- createAzureTfOutput(`${id}-apiManagementName`, scope, apiManagement.name)
195
- createAzureTfOutput(`${id}-apiManagementFriendlyUniqueId`, scope, apiManagement.friendlyUniqueId)
196
- createAzureTfOutput(`${id}-apiManagementId`, scope, apiManagement.id)
197
-
198
- return apiManagement
199
- }
200
-
201
123
  /**
202
124
  * @summary Method to create a new api management backend
203
125
  * @param id scoped id of the resource
@@ -301,12 +223,13 @@ export class AzureApiManagementManager {
301
223
  createAzureTfOutput(`${id}-${operation.displayName}-${operation.method}-apimOperationId`, scope, apimOperation.id)
302
224
 
303
225
  // Define Caching Policy if enabled
304
- let cacheInboundPolicy = ''
305
- let cacheOutboundPolicy = ''
226
+ let cacheSetVariablePolicy = ''
227
+ let cacheInvalidateInboundPolicy = ''
228
+ let cacheSetInboundPolicy = ''
229
+ let cacheSetOutboundPolicy = ''
306
230
 
307
- if (props.caching?.enabled === true) {
308
- if (operation.method === 'get') {
309
- cacheInboundPolicy = `<!-- Generate a comprehensive custom cache key (without query params or Accept header) -->
231
+ if (operation.caching) {
232
+ cacheSetVariablePolicy = `<!-- Generate a comprehensive custom cache key (without query params or Accept header) -->
310
233
  <set-variable name="customCacheKey" value="@{
311
234
  // Instance identification
312
235
 
@@ -316,13 +239,16 @@ export class AzureApiManagementManager {
316
239
 
317
240
  // Full path construction (without query parameters)
318
241
  string fullPath = context.Request.Url.Path.ToLower();
319
-
242
+
243
+ // Query parameters
244
+ string query = context.Request.Url.Query.ToLower();
245
+
320
246
  // Construct final cache key (no Accept header needed for JSON-only APIs)
321
- return $"{apiName}:{apiVersion}:{fullPath}";
322
- }" />
323
- <set-variable name="bypassCache" value="@(context.Request.Headers.GetValueOrDefault("X-Bypass-Cache", "false").ToLower())" />
247
+ return $"{apiName}:{apiVersion}:{fullPath}:{query}";
248
+ }" />`
324
249
 
325
- <choose>
250
+ if (operation.caching.enableCacheSet) {
251
+ cacheSetInboundPolicy = `<choose>
326
252
  <when condition="@((string)context.Variables["bypassCache"] != "true")">
327
253
  <!-- Attempt to retrieve cached response -->
328
254
  <cache-lookup-value key="@((string)context.Variables["customCacheKey"])" variable-name="cachedResponse" />
@@ -347,12 +273,12 @@ export class AzureApiManagementManager {
347
273
  </choose>
348
274
  </when>
349
275
  </choose>`
350
- cacheOutboundPolicy = `<choose>
276
+ cacheSetOutboundPolicy = `<choose>
351
277
  <when condition="@((string)context.Variables["bypassCache"] != "true")">
352
278
  <!-- Store the response body in cache -->
353
279
  <choose>
354
280
  <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.ttlInSecs ?? 900}" />
281
+ <cache-store-value key="@((string)context.Variables["customCacheKey"])" value="@(context.Response.Body.As<string>(preserveContent: true))" duration="${operation.caching.ttlInSecs ?? 900}" />
356
282
  <!-- Add cache status header -->
357
283
  <set-header name="X-Apim-Cache-Status" exists-action="override">
358
284
  <value>MISS</value>
@@ -370,23 +296,8 @@ export class AzureApiManagementManager {
370
296
  </choose>`
371
297
  }
372
298
 
373
- if (operation.method === 'post') {
374
- cacheInboundPolicy = `<!-- Generate a comprehensive custom cache key (without query params or Accept header) -->
375
- <set-variable name="customCacheKey" value="@{
376
- // Instance identification
377
-
378
- // API identification
379
- string apiName = context.Api.Name.Replace(" ", "").ToLower();
380
- string apiVersion = context.Api.Version ?? "v1";
381
-
382
- // Full path construction (without query parameters)
383
- string fullPath = context.Request.Url.Path.ToLower();
384
-
385
- // Construct final cache key (no Accept header needed for JSON-only APIs)
386
- return $"{apiName}:{apiVersion}:{fullPath}";
387
- }" />
388
- <set-variable name="clearCache" value="@(context.Request.Headers.GetValueOrDefault("X-Apim-Clear-Cache", "false").ToLower())" />
389
-
299
+ if (operation.caching.enableCacheInvalidation) {
300
+ cacheInvalidateInboundPolicy = `<set-variable name="clearCache" value="@(context.Request.Headers.GetValueOrDefault("X-Apim-Clear-Cache", "false").ToLower())" />
390
301
  <!-- Allow admin to clear specific cache entries -->
391
302
  <choose>
392
303
  <when condition="@((string)context.Variables["clearCache"] == "true")">
@@ -405,11 +316,14 @@ export class AzureApiManagementManager {
405
316
  if (props.rateLimit && scope.props.subscriptionId) {
406
317
  rateLimitPolicy = `<rate-limit-by-key calls="${props.rateLimit.calls}" renewal-period="${props.rateLimit.renewalPeriodInSecs}" counter-key="${scope.props.subscriptionId}-${apimOperation.operationId}"/>`
407
318
  }
319
+
408
320
  const policyXmlContent = `<policies>
409
321
  <inbound>
410
322
  <base />
411
323
  ${rateLimitPolicy}
412
- ${cacheInboundPolicy}
324
+ ${cacheSetVariablePolicy}
325
+ ${cacheInvalidateInboundPolicy}
326
+ ${cacheSetInboundPolicy}
413
327
  ${props.commonInboundPolicyXml ?? ''}
414
328
  </inbound>
415
329
  <backend>
@@ -417,7 +331,7 @@ export class AzureApiManagementManager {
417
331
  </backend>
418
332
  <outbound>
419
333
  <base />
420
- ${cacheOutboundPolicy ?? ''}
334
+ ${cacheSetOutboundPolicy}
421
335
  ${props.commonOutboundPolicyXml ?? ''}
422
336
  </outbound>
423
337
  <on-error>
@@ -18,18 +18,16 @@ export interface ApiManagementApiProps extends ApiManagementApiConfig {
18
18
  operations: ApiManagementApiOperationProps[]
19
19
  commonInboundPolicyXml: string
20
20
  commonOutboundPolicyXml: string
21
- caching?: ApiManagementApiCaching
22
21
  rateLimit?: ApiManagementApiRateLimit
23
22
  }
24
23
 
25
- export interface ApiManagementV2Props extends ApiManagementConfig {
26
- body: any
24
+ export interface ApiManagementApiOperationProps extends ApiManagementApiOperationConfig {
25
+ caching?: ApiManagementApiCaching
27
26
  }
28
27
 
29
- export interface ApiManagementApiOperationProps extends ApiManagementApiOperationConfig {}
30
-
31
28
  export interface ApiManagementApiCaching {
32
- enabled: boolean
29
+ enableCacheSet?: boolean
30
+ enableCacheInvalidation?: boolean
33
31
  ttlInSecs?: number
34
32
  }
35
33