@aws/nx-plugin 0.27.0 → 0.28.1
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.
- package/package.json +1 -1
- package/src/api-connection/generator.js +0 -2
- package/src/api-connection/generator.js.map +1 -1
- package/src/api-connection/schema.d.ts +0 -1
- package/src/api-connection/schema.json +0 -7
- package/src/cloudscape-website/app/generator.js +1 -0
- package/src/cloudscape-website/app/generator.js.map +1 -1
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +9 -0
- package/src/infra/app/generator.js +1 -0
- package/src/infra/app/generator.js.map +1 -1
- package/src/py/fast-api/__snapshots__/generator.spec.ts.snap +31 -30
- package/src/py/fast-api/generator.js +3 -0
- package/src/py/fast-api/generator.js.map +1 -1
- package/src/py/fast-api/react/__snapshots__/generator.spec.ts.snap +68 -1
- package/src/py/fast-api/react/files/website/components/__apiNameClassName__Provider.tsx.template +27 -1
- package/src/py/fast-api/react/generator.js +7 -17
- package/src/py/fast-api/react/generator.js.map +1 -1
- package/src/py/fast-api/react/schema.d.ts +0 -1
- package/src/py/fast-api/react/schema.json +0 -7
- package/src/py/fast-api/schema.d.ts +1 -0
- package/src/py/fast-api/schema.json +8 -0
- package/src/py/project/generator.js +1 -0
- package/src/py/project/generator.js.map +1 -1
- package/src/py/project/schema.json +7 -2
- package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +684 -82
- package/src/trpc/backend/files/backend/src/client/index.ts.template +22 -2
- package/src/trpc/backend/files/backend/src/local-server.ts.template +6 -0
- package/src/trpc/backend/files/backend/src/middleware/index.ts.template +2 -3
- package/src/trpc/backend/files/backend/src/router.ts.template +2 -3
- package/src/trpc/backend/generator.js +17 -1
- package/src/trpc/backend/generator.js.map +1 -1
- package/src/trpc/backend/schema.d.ts +1 -0
- package/src/trpc/backend/schema.json +8 -0
- package/src/trpc/react/__snapshots__/generator.spec.ts.snap +186 -73
- package/src/trpc/react/files/src/components/__apiNameClassName__ClientProvider.tsx.template +54 -0
- package/src/trpc/react/files/src/hooks/use__apiNameClassName__.tsx.template +2 -2
- package/src/trpc/react/generator.js +13 -69
- package/src/trpc/react/generator.js.map +1 -1
- package/src/trpc/react/schema.d.ts +0 -1
- package/src/trpc/react/schema.json +0 -7
- package/src/ts/lib/__snapshots__/generator.spec.ts.snap +9 -0
- package/src/ts/lib/generator.js +1 -0
- package/src/ts/lib/generator.js.map +1 -1
- package/src/ts/lib/schema.json +7 -2
- package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +3 -0
- package/src/ts/mcp-server/generator.js +1 -0
- package/src/ts/mcp-server/generator.js.map +1 -1
- package/src/ts/mcp-server/schema.json +5 -0
- package/src/utils/api-constructs/api-constructs.d.ts +1 -0
- package/src/utils/api-constructs/api-constructs.js.map +1 -1
- package/src/utils/api-constructs/files/app/apis/http/__apiNameKebabCase__.ts.template +53 -2
- package/src/utils/api-constructs/files/app/apis/rest/__apiNameKebabCase__.ts.template +57 -2
- package/src/utils/api-constructs/files/core/api/http/http-api.ts.template +1 -15
- package/src/utils/api-constructs/files/core/api/rest/rest-api.ts.template +0 -14
- package/src/utils/nx.d.ts +4 -0
- package/src/utils/nx.js +9 -1
- package/src/utils/nx.js.map +1 -1
- package/src/api-connection/README.md +0 -0
- package/src/cloudscape-website/app/README.md +0 -289
- package/src/cloudscape-website/cognito-auth/README.md +0 -193
- package/src/infra/app/README.md +0 -200
- package/src/license/README.md +0 -290
- package/src/trpc/backend/README.md +0 -571
- package/src/trpc/backend/files/backend/src/client/sigv4.ts.template +0 -9
- package/src/trpc/react/README.md +0 -330
- package/src/trpc/react/files/src/components/TrpcClients/TrpcApis.tsx.template +0 -1
- package/src/trpc/react/files/src/components/TrpcClients/TrpcClientProviders.tsx.template +0 -10
- package/src/trpc/react/files/src/components/TrpcClients/TrpcProvider.tsx.template +0 -55
- package/src/trpc/react/files/src/components/TrpcClients/index.tsx.template +0 -5
|
@@ -2,9 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
exports[`trpc backend generator > should generate backend and schema projects > apps/test-api/backend/src/client/index.ts 1`] = `
|
|
4
4
|
"import { createTRPCClient, httpLink, HTTPLinkOptions } from '@trpc/client';
|
|
5
|
-
|
|
5
|
+
import { AwsClient } from 'aws4fetch';
|
|
6
|
+
import { fromNodeProviderChain } from '@aws-sdk/credential-providers';
|
|
6
7
|
import { AppRouter } from '../router.js';
|
|
7
|
-
|
|
8
|
+
|
|
9
|
+
const credentialProvider = fromNodeProviderChain();
|
|
10
|
+
|
|
11
|
+
const sigv4Fetch = (async (...args) => {
|
|
12
|
+
const client = new AwsClient(await credentialProvider());
|
|
13
|
+
return client.fetch(...args);
|
|
14
|
+
}) satisfies AwsClient['fetch'];
|
|
8
15
|
|
|
9
16
|
export interface TestApiClientConfig {
|
|
10
17
|
readonly url: string;
|
|
@@ -22,19 +29,6 @@ export const createTestApiClient = (config: TestApiClientConfig) => {
|
|
|
22
29
|
"
|
|
23
30
|
`;
|
|
24
31
|
|
|
25
|
-
exports[`trpc backend generator > should generate backend and schema projects > apps/test-api/backend/src/client/sigv4.ts 1`] = `
|
|
26
|
-
"import { AwsClient } from 'aws4fetch';
|
|
27
|
-
import { fromNodeProviderChain } from '@aws-sdk/credential-providers';
|
|
28
|
-
|
|
29
|
-
const credentialProvider = fromNodeProviderChain();
|
|
30
|
-
|
|
31
|
-
export const sigv4Fetch = (async (...args) => {
|
|
32
|
-
const client = new AwsClient(await credentialProvider());
|
|
33
|
-
return client.fetch(...args);
|
|
34
|
-
}) satisfies AwsClient['fetch'];
|
|
35
|
-
"
|
|
36
|
-
`;
|
|
37
|
-
|
|
38
32
|
exports[`trpc backend generator > should generate backend and schema projects > apps/test-api/backend/src/index.ts 1`] = `
|
|
39
33
|
"export type { AppRouter } from './router.js';
|
|
40
34
|
export { appRouter } from './router.js';
|
|
@@ -83,6 +77,12 @@ createHTTPServer({
|
|
|
83
77
|
info: {} as any,
|
|
84
78
|
};
|
|
85
79
|
},
|
|
80
|
+
responseMeta: () => ({
|
|
81
|
+
headers: {
|
|
82
|
+
'Access-Control-Allow-Origin': '*',
|
|
83
|
+
'Access-Control-Allow-Methods': '*',
|
|
84
|
+
},
|
|
85
|
+
}),
|
|
86
86
|
}).listen(PORT);
|
|
87
87
|
|
|
88
88
|
console.log(\`Local TRPC server listening on port \${PORT}\`);
|
|
@@ -264,65 +264,665 @@ exports[`trpc backend generator > should generate backend and schema projects >
|
|
|
264
264
|
"import { publicProcedure } from '../init.js';
|
|
265
265
|
import { EchoInputSchema, EchoOutputSchema } from ':proj/test-api-schema';
|
|
266
266
|
|
|
267
|
-
export const echo = publicProcedure
|
|
268
|
-
.input(EchoInputSchema)
|
|
269
|
-
.output(EchoOutputSchema)
|
|
270
|
-
.query((opts) => ({ result: opts.input.message }));
|
|
267
|
+
export const echo = publicProcedure
|
|
268
|
+
.input(EchoInputSchema)
|
|
269
|
+
.output(EchoOutputSchema)
|
|
270
|
+
.query((opts) => ({ result: opts.input.message }));
|
|
271
|
+
"
|
|
272
|
+
`;
|
|
273
|
+
|
|
274
|
+
exports[`trpc backend generator > should generate backend and schema projects > apps/test-api/backend/src/router.ts 1`] = `
|
|
275
|
+
"import {
|
|
276
|
+
awsLambdaRequestHandler,
|
|
277
|
+
CreateAWSLambdaContextOptions,
|
|
278
|
+
} from '@trpc/server/adapters/aws-lambda';
|
|
279
|
+
import { echo } from './procedures/echo.js';
|
|
280
|
+
import { t } from './init.js';
|
|
281
|
+
import type { APIGatewayProxyEventV2WithIAMAuthorizer } from 'aws-lambda';
|
|
282
|
+
|
|
283
|
+
export const router = t.router;
|
|
284
|
+
|
|
285
|
+
export const appRouter = router({
|
|
286
|
+
echo,
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
export const handler = awsLambdaRequestHandler({
|
|
290
|
+
router: appRouter,
|
|
291
|
+
createContext: (
|
|
292
|
+
ctx: CreateAWSLambdaContextOptions<APIGatewayProxyEventV2WithIAMAuthorizer>,
|
|
293
|
+
) => ctx,
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
export type AppRouter = typeof appRouter;
|
|
297
|
+
"
|
|
298
|
+
`;
|
|
299
|
+
|
|
300
|
+
exports[`trpc backend generator > should generate backend and schema projects > apps/test-api/schema/src/index.ts 1`] = `
|
|
301
|
+
"export * from './procedures/echo.js';
|
|
302
|
+
"
|
|
303
|
+
`;
|
|
304
|
+
|
|
305
|
+
exports[`trpc backend generator > should generate backend and schema projects > apps/test-api/schema/src/procedures/echo.ts 1`] = `
|
|
306
|
+
"import { z } from 'zod';
|
|
307
|
+
|
|
308
|
+
export const EchoInputSchema = z.object({
|
|
309
|
+
message: z.string(),
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
export type IEchoInput = z.TypeOf<typeof EchoInputSchema>;
|
|
313
|
+
|
|
314
|
+
export const EchoOutputSchema = z.object({
|
|
315
|
+
result: z.string(),
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
export type IEchoOutput = z.TypeOf<typeof EchoOutputSchema>;
|
|
319
|
+
"
|
|
320
|
+
`;
|
|
321
|
+
|
|
322
|
+
exports[`trpc backend generator > should generate with cognito auth for a REST API > apps/test-api/backend/src/client/index.ts 1`] = `
|
|
323
|
+
"import { createTRPCClient, httpLink, HTTPLinkOptions } from '@trpc/client';
|
|
324
|
+
import { AppRouter } from '../router.js';
|
|
325
|
+
|
|
326
|
+
export interface TestApiClientConfig {
|
|
327
|
+
readonly url: string;
|
|
328
|
+
readonly token: string;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export const createTestApiClient = (config: TestApiClientConfig) => {
|
|
332
|
+
const linkOptions: HTTPLinkOptions<any> = {
|
|
333
|
+
url: config.url,
|
|
334
|
+
headers: {
|
|
335
|
+
Authorization: \`Bearer \${config.token}\`,
|
|
336
|
+
},
|
|
337
|
+
};
|
|
338
|
+
return createTRPCClient<AppRouter>({
|
|
339
|
+
links: [httpLink(linkOptions)],
|
|
340
|
+
});
|
|
341
|
+
};
|
|
342
|
+
"
|
|
343
|
+
`;
|
|
344
|
+
|
|
345
|
+
exports[`trpc backend generator > should generate with cognito auth for a REST API > packages/common/constructs/src/app/apis/index.ts 1`] = `
|
|
346
|
+
"export * from './test-api.js';
|
|
347
|
+
"
|
|
348
|
+
`;
|
|
349
|
+
|
|
350
|
+
exports[`trpc backend generator > should generate with cognito auth for a REST API > packages/common/constructs/src/app/apis/test-api.ts 1`] = `
|
|
351
|
+
"import { Construct } from 'constructs';
|
|
352
|
+
import * as url from 'url';
|
|
353
|
+
import {
|
|
354
|
+
Code,
|
|
355
|
+
Runtime,
|
|
356
|
+
Function,
|
|
357
|
+
FunctionProps,
|
|
358
|
+
Tracing,
|
|
359
|
+
} from 'aws-cdk-lib/aws-lambda';
|
|
360
|
+
import {
|
|
361
|
+
AuthorizationType,
|
|
362
|
+
Cors,
|
|
363
|
+
LambdaIntegration,
|
|
364
|
+
CognitoUserPoolsAuthorizer,
|
|
365
|
+
} from 'aws-cdk-lib/aws-apigateway';
|
|
366
|
+
import { Duration } from 'aws-cdk-lib';
|
|
367
|
+
import {
|
|
368
|
+
PolicyDocument,
|
|
369
|
+
PolicyStatement,
|
|
370
|
+
Effect,
|
|
371
|
+
AnyPrincipal,
|
|
372
|
+
} from 'aws-cdk-lib/aws-iam';
|
|
373
|
+
import { IUserPool } from 'aws-cdk-lib/aws-cognito';
|
|
374
|
+
import {
|
|
375
|
+
IntegrationBuilder,
|
|
376
|
+
RestApiIntegration,
|
|
377
|
+
} from '../../core/api/utils.js';
|
|
378
|
+
import { RestApi } from '../../core/api/rest-api.js';
|
|
379
|
+
import { Procedures, routerToOperations } from '../../core/api/trpc-utils.js';
|
|
380
|
+
import { AppRouter, appRouter } from ':proj/test-api';
|
|
381
|
+
|
|
382
|
+
// String union type for all API operation names
|
|
383
|
+
type Operations = Procedures<AppRouter>;
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Properties for creating a TestApi construct
|
|
387
|
+
*
|
|
388
|
+
* @template TIntegrations - Map of operation names to their integrations
|
|
389
|
+
*/
|
|
390
|
+
export interface TestApiProps<
|
|
391
|
+
TIntegrations extends Record<Operations, RestApiIntegration>,
|
|
392
|
+
> {
|
|
393
|
+
/**
|
|
394
|
+
* Map of operation names to their API Gateway integrations
|
|
395
|
+
*/
|
|
396
|
+
integrations: TIntegrations;
|
|
397
|
+
/**
|
|
398
|
+
* User pool for Cognito authentication
|
|
399
|
+
*/
|
|
400
|
+
userPool: IUserPool;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* A CDK construct that creates and configures an AWS API Gateway REST API
|
|
405
|
+
* specifically for TestApi.
|
|
406
|
+
* @template TIntegrations - Map of operation names to their integrations
|
|
407
|
+
*/
|
|
408
|
+
export class TestApi<
|
|
409
|
+
TIntegrations extends Record<Operations, RestApiIntegration>,
|
|
410
|
+
> extends RestApi<Operations, TIntegrations> {
|
|
411
|
+
/**
|
|
412
|
+
* Creates default integrations for all operations, which implement each operation as
|
|
413
|
+
* its own individual lambda function.
|
|
414
|
+
*
|
|
415
|
+
* @param scope - The CDK construct scope
|
|
416
|
+
* @returns An IntegrationBuilder with default lambda integrations
|
|
417
|
+
*/
|
|
418
|
+
public static defaultIntegrations = (scope: Construct) => {
|
|
419
|
+
return IntegrationBuilder.rest({
|
|
420
|
+
operations: routerToOperations(appRouter),
|
|
421
|
+
defaultIntegrationOptions: {
|
|
422
|
+
runtime: Runtime.NODEJS_LATEST,
|
|
423
|
+
handler: 'index.handler',
|
|
424
|
+
code: Code.fromAsset(
|
|
425
|
+
url.fileURLToPath(
|
|
426
|
+
new URL(
|
|
427
|
+
'../../../../../../dist/apps/test-api/backend/bundle',
|
|
428
|
+
import.meta.url,
|
|
429
|
+
),
|
|
430
|
+
),
|
|
431
|
+
),
|
|
432
|
+
timeout: Duration.seconds(30),
|
|
433
|
+
tracing: Tracing.ACTIVE,
|
|
434
|
+
environment: {
|
|
435
|
+
AWS_CONNECTION_REUSE_ENABLED: '1',
|
|
436
|
+
},
|
|
437
|
+
} satisfies FunctionProps,
|
|
438
|
+
buildDefaultIntegration: (op, props: FunctionProps) => {
|
|
439
|
+
const handler = new Function(scope, \`TestApi\${op}Handler\`, props);
|
|
440
|
+
return { handler, integration: new LambdaIntegration(handler) };
|
|
441
|
+
},
|
|
442
|
+
});
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
constructor(
|
|
446
|
+
scope: Construct,
|
|
447
|
+
id: string,
|
|
448
|
+
props: TestApiProps<TIntegrations>,
|
|
449
|
+
) {
|
|
450
|
+
super(scope, id, {
|
|
451
|
+
apiName: 'TestApi',
|
|
452
|
+
defaultMethodOptions: {
|
|
453
|
+
authorizationType: AuthorizationType.COGNITO,
|
|
454
|
+
authorizer: new CognitoUserPoolsAuthorizer(scope, 'TestApiAuthorizer', {
|
|
455
|
+
cognitoUserPools: [props.userPool],
|
|
456
|
+
}),
|
|
457
|
+
},
|
|
458
|
+
defaultCorsPreflightOptions: {
|
|
459
|
+
allowOrigins: Cors.ALL_ORIGINS,
|
|
460
|
+
allowMethods: Cors.ALL_METHODS,
|
|
461
|
+
},
|
|
462
|
+
policy: new PolicyDocument({
|
|
463
|
+
statements: [
|
|
464
|
+
// Allow all callers to invoke the API in the resource policy, since auth is handled by Cognito
|
|
465
|
+
new PolicyStatement({
|
|
466
|
+
effect: Effect.ALLOW,
|
|
467
|
+
principals: [new AnyPrincipal()],
|
|
468
|
+
actions: ['execute-api:Invoke'],
|
|
469
|
+
resources: ['execute-api:/*'],
|
|
470
|
+
}),
|
|
471
|
+
],
|
|
472
|
+
}),
|
|
473
|
+
operations: routerToOperations(appRouter),
|
|
474
|
+
...props,
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
"
|
|
479
|
+
`;
|
|
480
|
+
|
|
481
|
+
exports[`trpc backend generator > should generate with cognito auth for an HTTP API > apps/test-api/backend/src/client/index.ts 1`] = `
|
|
482
|
+
"import { createTRPCClient, httpLink, HTTPLinkOptions } from '@trpc/client';
|
|
483
|
+
import { AppRouter } from '../router.js';
|
|
484
|
+
|
|
485
|
+
export interface TestApiClientConfig {
|
|
486
|
+
readonly url: string;
|
|
487
|
+
readonly token: string;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
export const createTestApiClient = (config: TestApiClientConfig) => {
|
|
491
|
+
const linkOptions: HTTPLinkOptions<any> = {
|
|
492
|
+
url: config.url,
|
|
493
|
+
headers: {
|
|
494
|
+
Authorization: \`Bearer \${config.token}\`,
|
|
495
|
+
},
|
|
496
|
+
};
|
|
497
|
+
return createTRPCClient<AppRouter>({
|
|
498
|
+
links: [httpLink(linkOptions)],
|
|
499
|
+
});
|
|
500
|
+
};
|
|
501
|
+
"
|
|
502
|
+
`;
|
|
503
|
+
|
|
504
|
+
exports[`trpc backend generator > should generate with cognito auth for an HTTP API > packages/common/constructs/src/app/apis/index.ts 1`] = `
|
|
505
|
+
"export * from './test-api.js';
|
|
506
|
+
"
|
|
507
|
+
`;
|
|
508
|
+
|
|
509
|
+
exports[`trpc backend generator > should generate with cognito auth for an HTTP API > packages/common/constructs/src/app/apis/test-api.ts 1`] = `
|
|
510
|
+
"import { Construct } from 'constructs';
|
|
511
|
+
import * as url from 'url';
|
|
512
|
+
import {
|
|
513
|
+
Code,
|
|
514
|
+
Runtime,
|
|
515
|
+
Function,
|
|
516
|
+
FunctionProps,
|
|
517
|
+
Tracing,
|
|
518
|
+
} from 'aws-cdk-lib/aws-lambda';
|
|
519
|
+
import { Duration } from 'aws-cdk-lib';
|
|
520
|
+
import { CorsHttpMethod } from 'aws-cdk-lib/aws-apigatewayv2';
|
|
521
|
+
import { HttpUserPoolAuthorizer } from 'aws-cdk-lib/aws-apigatewayv2-authorizers';
|
|
522
|
+
import { HttpLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';
|
|
523
|
+
import { IUserPool, IUserPoolClient } from 'aws-cdk-lib/aws-cognito';
|
|
524
|
+
import {
|
|
525
|
+
HttpApiIntegration,
|
|
526
|
+
IntegrationBuilder,
|
|
527
|
+
} from '../../core/api/utils.js';
|
|
528
|
+
import { HttpApi } from '../../core/api/http-api.js';
|
|
529
|
+
import { Procedures, routerToOperations } from '../../core/api/trpc-utils.js';
|
|
530
|
+
import { AppRouter, appRouter } from ':proj/test-api';
|
|
531
|
+
|
|
532
|
+
// String union type for all API operation names
|
|
533
|
+
type Operations = Procedures<AppRouter>;
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Properties for creating a TestApi construct
|
|
537
|
+
*
|
|
538
|
+
* @template TIntegrations - Map of operation names to their integrations
|
|
539
|
+
*/
|
|
540
|
+
export interface TestApiProps<
|
|
541
|
+
TIntegrations extends Record<Operations, HttpApiIntegration>,
|
|
542
|
+
> {
|
|
543
|
+
/**
|
|
544
|
+
* Map of operation names to their API Gateway integrations
|
|
545
|
+
*/
|
|
546
|
+
integrations: TIntegrations;
|
|
547
|
+
/**
|
|
548
|
+
* Identity details for Cognito Authentication
|
|
549
|
+
*/
|
|
550
|
+
identity: {
|
|
551
|
+
userPool: IUserPool;
|
|
552
|
+
userPoolClient: IUserPoolClient;
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* A CDK construct that creates and configures an AWS API Gateway HTTP API
|
|
558
|
+
* specifically for TestApi.
|
|
559
|
+
* @template TIntegrations - Map of operation names to their integrations
|
|
560
|
+
*/
|
|
561
|
+
export class TestApi<
|
|
562
|
+
TIntegrations extends Record<Operations, HttpApiIntegration>,
|
|
563
|
+
> extends HttpApi<Operations, TIntegrations> {
|
|
564
|
+
/**
|
|
565
|
+
* Creates default integrations for all operations, which implement each operation as
|
|
566
|
+
* its own individual lambda function.
|
|
567
|
+
*
|
|
568
|
+
* @param scope - The CDK construct scope
|
|
569
|
+
* @returns An IntegrationBuilder with default lambda integrations
|
|
570
|
+
*/
|
|
571
|
+
public static defaultIntegrations = (scope: Construct) => {
|
|
572
|
+
return IntegrationBuilder.http({
|
|
573
|
+
operations: routerToOperations(appRouter),
|
|
574
|
+
defaultIntegrationOptions: {
|
|
575
|
+
runtime: Runtime.NODEJS_LATEST,
|
|
576
|
+
handler: 'index.handler',
|
|
577
|
+
code: Code.fromAsset(
|
|
578
|
+
url.fileURLToPath(
|
|
579
|
+
new URL(
|
|
580
|
+
'../../../../../../dist/apps/test-api/backend/bundle',
|
|
581
|
+
import.meta.url,
|
|
582
|
+
),
|
|
583
|
+
),
|
|
584
|
+
),
|
|
585
|
+
timeout: Duration.seconds(30),
|
|
586
|
+
tracing: Tracing.ACTIVE,
|
|
587
|
+
environment: {
|
|
588
|
+
AWS_CONNECTION_REUSE_ENABLED: '1',
|
|
589
|
+
},
|
|
590
|
+
} satisfies FunctionProps,
|
|
591
|
+
buildDefaultIntegration: (op, props: FunctionProps) => {
|
|
592
|
+
const handler = new Function(scope, \`TestApi\${op}Handler\`, props);
|
|
593
|
+
return {
|
|
594
|
+
handler,
|
|
595
|
+
integration: new HttpLambdaIntegration(
|
|
596
|
+
\`TestApi\${op}Integration\`,
|
|
597
|
+
handler,
|
|
598
|
+
),
|
|
599
|
+
};
|
|
600
|
+
},
|
|
601
|
+
});
|
|
602
|
+
};
|
|
603
|
+
|
|
604
|
+
constructor(
|
|
605
|
+
scope: Construct,
|
|
606
|
+
id: string,
|
|
607
|
+
props: TestApiProps<TIntegrations>,
|
|
608
|
+
) {
|
|
609
|
+
super(scope, id, {
|
|
610
|
+
apiName: 'TestApi',
|
|
611
|
+
corsPreflight: {
|
|
612
|
+
allowOrigins: ['*'],
|
|
613
|
+
allowMethods: [CorsHttpMethod.ANY],
|
|
614
|
+
allowHeaders: [
|
|
615
|
+
'authorization',
|
|
616
|
+
'content-type',
|
|
617
|
+
'x-amz-content-sha256',
|
|
618
|
+
'x-amz-date',
|
|
619
|
+
'x-amz-security-token',
|
|
620
|
+
],
|
|
621
|
+
},
|
|
622
|
+
defaultAuthorizer: new HttpUserPoolAuthorizer(
|
|
623
|
+
'TestApiAuthorizer',
|
|
624
|
+
props.identity.userPool,
|
|
625
|
+
{
|
|
626
|
+
userPoolClients: [props.identity.userPoolClient],
|
|
627
|
+
},
|
|
628
|
+
),
|
|
629
|
+
operations: routerToOperations(appRouter),
|
|
630
|
+
...props,
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
"
|
|
635
|
+
`;
|
|
636
|
+
|
|
637
|
+
exports[`trpc backend generator > should generate with no auth for a REST API > apps/test-api/backend/src/client/index.ts 1`] = `
|
|
638
|
+
"import { createTRPCClient, httpLink, HTTPLinkOptions } from '@trpc/client';
|
|
639
|
+
import { AppRouter } from '../router.js';
|
|
640
|
+
|
|
641
|
+
export interface TestApiClientConfig {
|
|
642
|
+
readonly url: string;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
export const createTestApiClient = (config: TestApiClientConfig) => {
|
|
646
|
+
const linkOptions: HTTPLinkOptions<any> = {
|
|
647
|
+
url: config.url,
|
|
648
|
+
};
|
|
649
|
+
return createTRPCClient<AppRouter>({
|
|
650
|
+
links: [httpLink(linkOptions)],
|
|
651
|
+
});
|
|
652
|
+
};
|
|
653
|
+
"
|
|
654
|
+
`;
|
|
655
|
+
|
|
656
|
+
exports[`trpc backend generator > should generate with no auth for a REST API > packages/common/constructs/src/app/apis/index.ts 1`] = `
|
|
657
|
+
"export * from './test-api.js';
|
|
658
|
+
"
|
|
659
|
+
`;
|
|
660
|
+
|
|
661
|
+
exports[`trpc backend generator > should generate with no auth for a REST API > packages/common/constructs/src/app/apis/test-api.ts 1`] = `
|
|
662
|
+
"import { Construct } from 'constructs';
|
|
663
|
+
import * as url from 'url';
|
|
664
|
+
import {
|
|
665
|
+
Code,
|
|
666
|
+
Runtime,
|
|
667
|
+
Function,
|
|
668
|
+
FunctionProps,
|
|
669
|
+
Tracing,
|
|
670
|
+
} from 'aws-cdk-lib/aws-lambda';
|
|
671
|
+
import {
|
|
672
|
+
AuthorizationType,
|
|
673
|
+
Cors,
|
|
674
|
+
LambdaIntegration,
|
|
675
|
+
} from 'aws-cdk-lib/aws-apigateway';
|
|
676
|
+
import { Duration } from 'aws-cdk-lib';
|
|
677
|
+
import {
|
|
678
|
+
PolicyDocument,
|
|
679
|
+
PolicyStatement,
|
|
680
|
+
Effect,
|
|
681
|
+
AnyPrincipal,
|
|
682
|
+
} from 'aws-cdk-lib/aws-iam';
|
|
683
|
+
import {
|
|
684
|
+
IntegrationBuilder,
|
|
685
|
+
RestApiIntegration,
|
|
686
|
+
} from '../../core/api/utils.js';
|
|
687
|
+
import { RestApi } from '../../core/api/rest-api.js';
|
|
688
|
+
import { Procedures, routerToOperations } from '../../core/api/trpc-utils.js';
|
|
689
|
+
import { AppRouter, appRouter } from ':proj/test-api';
|
|
690
|
+
|
|
691
|
+
// String union type for all API operation names
|
|
692
|
+
type Operations = Procedures<AppRouter>;
|
|
693
|
+
|
|
694
|
+
/**
|
|
695
|
+
* Properties for creating a TestApi construct
|
|
696
|
+
*
|
|
697
|
+
* @template TIntegrations - Map of operation names to their integrations
|
|
698
|
+
*/
|
|
699
|
+
export interface TestApiProps<
|
|
700
|
+
TIntegrations extends Record<Operations, RestApiIntegration>,
|
|
701
|
+
> {
|
|
702
|
+
/**
|
|
703
|
+
* Map of operation names to their API Gateway integrations
|
|
704
|
+
*/
|
|
705
|
+
integrations: TIntegrations;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* A CDK construct that creates and configures an AWS API Gateway REST API
|
|
710
|
+
* specifically for TestApi.
|
|
711
|
+
* @template TIntegrations - Map of operation names to their integrations
|
|
712
|
+
*/
|
|
713
|
+
export class TestApi<
|
|
714
|
+
TIntegrations extends Record<Operations, RestApiIntegration>,
|
|
715
|
+
> extends RestApi<Operations, TIntegrations> {
|
|
716
|
+
/**
|
|
717
|
+
* Creates default integrations for all operations, which implement each operation as
|
|
718
|
+
* its own individual lambda function.
|
|
719
|
+
*
|
|
720
|
+
* @param scope - The CDK construct scope
|
|
721
|
+
* @returns An IntegrationBuilder with default lambda integrations
|
|
722
|
+
*/
|
|
723
|
+
public static defaultIntegrations = (scope: Construct) => {
|
|
724
|
+
return IntegrationBuilder.rest({
|
|
725
|
+
operations: routerToOperations(appRouter),
|
|
726
|
+
defaultIntegrationOptions: {
|
|
727
|
+
runtime: Runtime.NODEJS_LATEST,
|
|
728
|
+
handler: 'index.handler',
|
|
729
|
+
code: Code.fromAsset(
|
|
730
|
+
url.fileURLToPath(
|
|
731
|
+
new URL(
|
|
732
|
+
'../../../../../../dist/apps/test-api/backend/bundle',
|
|
733
|
+
import.meta.url,
|
|
734
|
+
),
|
|
735
|
+
),
|
|
736
|
+
),
|
|
737
|
+
timeout: Duration.seconds(30),
|
|
738
|
+
tracing: Tracing.ACTIVE,
|
|
739
|
+
environment: {
|
|
740
|
+
AWS_CONNECTION_REUSE_ENABLED: '1',
|
|
741
|
+
},
|
|
742
|
+
} satisfies FunctionProps,
|
|
743
|
+
buildDefaultIntegration: (op, props: FunctionProps) => {
|
|
744
|
+
const handler = new Function(scope, \`TestApi\${op}Handler\`, props);
|
|
745
|
+
return { handler, integration: new LambdaIntegration(handler) };
|
|
746
|
+
},
|
|
747
|
+
});
|
|
748
|
+
};
|
|
749
|
+
|
|
750
|
+
constructor(
|
|
751
|
+
scope: Construct,
|
|
752
|
+
id: string,
|
|
753
|
+
props: TestApiProps<TIntegrations>,
|
|
754
|
+
) {
|
|
755
|
+
super(scope, id, {
|
|
756
|
+
apiName: 'TestApi',
|
|
757
|
+
defaultMethodOptions: {
|
|
758
|
+
authorizationType: AuthorizationType.NONE,
|
|
759
|
+
},
|
|
760
|
+
defaultCorsPreflightOptions: {
|
|
761
|
+
allowOrigins: Cors.ALL_ORIGINS,
|
|
762
|
+
allowMethods: Cors.ALL_METHODS,
|
|
763
|
+
},
|
|
764
|
+
policy: new PolicyDocument({
|
|
765
|
+
statements: [
|
|
766
|
+
// Allow all callers to invoke the API in the resource policy
|
|
767
|
+
new PolicyStatement({
|
|
768
|
+
effect: Effect.ALLOW,
|
|
769
|
+
principals: [new AnyPrincipal()],
|
|
770
|
+
actions: ['execute-api:Invoke'],
|
|
771
|
+
resources: ['execute-api:/*'],
|
|
772
|
+
}),
|
|
773
|
+
],
|
|
774
|
+
}),
|
|
775
|
+
operations: routerToOperations(appRouter),
|
|
776
|
+
...props,
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
}
|
|
271
780
|
"
|
|
272
781
|
`;
|
|
273
782
|
|
|
274
|
-
exports[`trpc backend generator > should generate
|
|
275
|
-
"import {
|
|
276
|
-
|
|
277
|
-
CreateAWSLambdaContextOptions,
|
|
278
|
-
} from '@trpc/server/adapters/aws-lambda';
|
|
279
|
-
import { echo } from './procedures/echo.js';
|
|
280
|
-
import { t } from './init.js';
|
|
281
|
-
import type { APIGatewayProxyEventV2WithIAMAuthorizer } from 'aws-lambda';
|
|
282
|
-
|
|
283
|
-
export const router = t.router;
|
|
284
|
-
|
|
285
|
-
export const appRouter = router({
|
|
286
|
-
echo,
|
|
287
|
-
});
|
|
783
|
+
exports[`trpc backend generator > should generate with no auth for an HTTP API > apps/test-api/backend/src/client/index.ts 1`] = `
|
|
784
|
+
"import { createTRPCClient, httpLink, HTTPLinkOptions } from '@trpc/client';
|
|
785
|
+
import { AppRouter } from '../router.js';
|
|
288
786
|
|
|
289
|
-
export
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
ctx: CreateAWSLambdaContextOptions<APIGatewayProxyEventV2WithIAMAuthorizer>,
|
|
293
|
-
) => ctx,
|
|
294
|
-
});
|
|
787
|
+
export interface TestApiClientConfig {
|
|
788
|
+
readonly url: string;
|
|
789
|
+
}
|
|
295
790
|
|
|
296
|
-
export
|
|
791
|
+
export const createTestApiClient = (config: TestApiClientConfig) => {
|
|
792
|
+
const linkOptions: HTTPLinkOptions<any> = {
|
|
793
|
+
url: config.url,
|
|
794
|
+
};
|
|
795
|
+
return createTRPCClient<AppRouter>({
|
|
796
|
+
links: [httpLink(linkOptions)],
|
|
797
|
+
});
|
|
798
|
+
};
|
|
297
799
|
"
|
|
298
800
|
`;
|
|
299
801
|
|
|
300
|
-
exports[`trpc backend generator > should generate
|
|
301
|
-
"export * from './
|
|
802
|
+
exports[`trpc backend generator > should generate with no auth for an HTTP API > packages/common/constructs/src/app/apis/index.ts 1`] = `
|
|
803
|
+
"export * from './test-api.js';
|
|
302
804
|
"
|
|
303
805
|
`;
|
|
304
806
|
|
|
305
|
-
exports[`trpc backend generator > should generate
|
|
306
|
-
"import {
|
|
807
|
+
exports[`trpc backend generator > should generate with no auth for an HTTP API > packages/common/constructs/src/app/apis/test-api.ts 1`] = `
|
|
808
|
+
"import { Construct } from 'constructs';
|
|
809
|
+
import * as url from 'url';
|
|
810
|
+
import {
|
|
811
|
+
Code,
|
|
812
|
+
Runtime,
|
|
813
|
+
Function,
|
|
814
|
+
FunctionProps,
|
|
815
|
+
Tracing,
|
|
816
|
+
} from 'aws-cdk-lib/aws-lambda';
|
|
817
|
+
import { Duration } from 'aws-cdk-lib';
|
|
818
|
+
import {
|
|
819
|
+
CorsHttpMethod,
|
|
820
|
+
HttpNoneAuthorizer,
|
|
821
|
+
} from 'aws-cdk-lib/aws-apigatewayv2';
|
|
822
|
+
import { HttpLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';
|
|
823
|
+
import {
|
|
824
|
+
HttpApiIntegration,
|
|
825
|
+
IntegrationBuilder,
|
|
826
|
+
} from '../../core/api/utils.js';
|
|
827
|
+
import { HttpApi } from '../../core/api/http-api.js';
|
|
828
|
+
import { Procedures, routerToOperations } from '../../core/api/trpc-utils.js';
|
|
829
|
+
import { AppRouter, appRouter } from ':proj/test-api';
|
|
307
830
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
});
|
|
831
|
+
// String union type for all API operation names
|
|
832
|
+
type Operations = Procedures<AppRouter>;
|
|
311
833
|
|
|
312
|
-
|
|
834
|
+
/**
|
|
835
|
+
* Properties for creating a TestApi construct
|
|
836
|
+
*
|
|
837
|
+
* @template TIntegrations - Map of operation names to their integrations
|
|
838
|
+
*/
|
|
839
|
+
export interface TestApiProps<
|
|
840
|
+
TIntegrations extends Record<Operations, HttpApiIntegration>,
|
|
841
|
+
> {
|
|
842
|
+
/**
|
|
843
|
+
* Map of operation names to their API Gateway integrations
|
|
844
|
+
*/
|
|
845
|
+
integrations: TIntegrations;
|
|
846
|
+
}
|
|
313
847
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
848
|
+
/**
|
|
849
|
+
* A CDK construct that creates and configures an AWS API Gateway HTTP API
|
|
850
|
+
* specifically for TestApi.
|
|
851
|
+
* @template TIntegrations - Map of operation names to their integrations
|
|
852
|
+
*/
|
|
853
|
+
export class TestApi<
|
|
854
|
+
TIntegrations extends Record<Operations, HttpApiIntegration>,
|
|
855
|
+
> extends HttpApi<Operations, TIntegrations> {
|
|
856
|
+
/**
|
|
857
|
+
* Creates default integrations for all operations, which implement each operation as
|
|
858
|
+
* its own individual lambda function.
|
|
859
|
+
*
|
|
860
|
+
* @param scope - The CDK construct scope
|
|
861
|
+
* @returns An IntegrationBuilder with default lambda integrations
|
|
862
|
+
*/
|
|
863
|
+
public static defaultIntegrations = (scope: Construct) => {
|
|
864
|
+
return IntegrationBuilder.http({
|
|
865
|
+
operations: routerToOperations(appRouter),
|
|
866
|
+
defaultIntegrationOptions: {
|
|
867
|
+
runtime: Runtime.NODEJS_LATEST,
|
|
868
|
+
handler: 'index.handler',
|
|
869
|
+
code: Code.fromAsset(
|
|
870
|
+
url.fileURLToPath(
|
|
871
|
+
new URL(
|
|
872
|
+
'../../../../../../dist/apps/test-api/backend/bundle',
|
|
873
|
+
import.meta.url,
|
|
874
|
+
),
|
|
875
|
+
),
|
|
876
|
+
),
|
|
877
|
+
timeout: Duration.seconds(30),
|
|
878
|
+
tracing: Tracing.ACTIVE,
|
|
879
|
+
environment: {
|
|
880
|
+
AWS_CONNECTION_REUSE_ENABLED: '1',
|
|
881
|
+
},
|
|
882
|
+
} satisfies FunctionProps,
|
|
883
|
+
buildDefaultIntegration: (op, props: FunctionProps) => {
|
|
884
|
+
const handler = new Function(scope, \`TestApi\${op}Handler\`, props);
|
|
885
|
+
return {
|
|
886
|
+
handler,
|
|
887
|
+
integration: new HttpLambdaIntegration(
|
|
888
|
+
\`TestApi\${op}Integration\`,
|
|
889
|
+
handler,
|
|
890
|
+
),
|
|
891
|
+
};
|
|
892
|
+
},
|
|
893
|
+
});
|
|
894
|
+
};
|
|
317
895
|
|
|
318
|
-
|
|
896
|
+
constructor(
|
|
897
|
+
scope: Construct,
|
|
898
|
+
id: string,
|
|
899
|
+
props: TestApiProps<TIntegrations>,
|
|
900
|
+
) {
|
|
901
|
+
super(scope, id, {
|
|
902
|
+
apiName: 'TestApi',
|
|
903
|
+
corsPreflight: {
|
|
904
|
+
allowOrigins: ['*'],
|
|
905
|
+
allowMethods: [CorsHttpMethod.ANY],
|
|
906
|
+
allowHeaders: [
|
|
907
|
+
'authorization',
|
|
908
|
+
'content-type',
|
|
909
|
+
'x-amz-content-sha256',
|
|
910
|
+
'x-amz-date',
|
|
911
|
+
'x-amz-security-token',
|
|
912
|
+
],
|
|
913
|
+
},
|
|
914
|
+
defaultAuthorizer: new HttpNoneAuthorizer(),
|
|
915
|
+
operations: routerToOperations(appRouter),
|
|
916
|
+
...props,
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
}
|
|
319
920
|
"
|
|
320
921
|
`;
|
|
321
922
|
|
|
322
923
|
exports[`trpc backend generator > should set up shared constructs for http > http-api.ts 1`] = `
|
|
323
924
|
"import { Construct } from 'constructs';
|
|
324
925
|
import { RuntimeConfig } from '../runtime-config.js';
|
|
325
|
-
import { Grant, IGrantable } from 'aws-cdk-lib/aws-iam';
|
|
326
926
|
import { HttpApiIntegration, OperationDetails } from './utils.js';
|
|
327
927
|
import { CfnOutput } from 'aws-cdk-lib';
|
|
328
928
|
import {
|
|
@@ -389,7 +989,7 @@ export class HttpApi<
|
|
|
389
989
|
super(scope, id);
|
|
390
990
|
this.integrations = integrations;
|
|
391
991
|
|
|
392
|
-
// Create the API Gateway REST API
|
|
992
|
+
// Create the API Gateway REST API
|
|
393
993
|
this.api = new _HttpApi(this, 'Api', {
|
|
394
994
|
...props,
|
|
395
995
|
});
|
|
@@ -418,19 +1018,6 @@ export class HttpApi<
|
|
|
418
1018
|
[apiName]: this.api.url!,
|
|
419
1019
|
};
|
|
420
1020
|
}
|
|
421
|
-
|
|
422
|
-
/**
|
|
423
|
-
* Grants IAM permissions to invoke any method on this API.
|
|
424
|
-
*
|
|
425
|
-
* @param grantee - The IAM principal to grant permissions to
|
|
426
|
-
*/
|
|
427
|
-
public grantInvokeAccess(grantee: IGrantable) {
|
|
428
|
-
Grant.addToPrincipal({
|
|
429
|
-
grantee,
|
|
430
|
-
actions: ['execute-api:Invoke'],
|
|
431
|
-
resourceArns: [this.api.arnForExecuteApi('*', '/*', '*')],
|
|
432
|
-
});
|
|
433
|
-
}
|
|
434
1021
|
}
|
|
435
1022
|
"
|
|
436
1023
|
`;
|
|
@@ -449,6 +1036,7 @@ import { Duration } from 'aws-cdk-lib';
|
|
|
449
1036
|
import { CorsHttpMethod } from 'aws-cdk-lib/aws-apigatewayv2';
|
|
450
1037
|
import { HttpIamAuthorizer } from 'aws-cdk-lib/aws-apigatewayv2-authorizers';
|
|
451
1038
|
import { HttpLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';
|
|
1039
|
+
import { Grant, IGrantable } from 'aws-cdk-lib/aws-iam';
|
|
452
1040
|
import {
|
|
453
1041
|
HttpApiIntegration,
|
|
454
1042
|
IntegrationBuilder,
|
|
@@ -545,6 +1133,19 @@ export class TestApi<
|
|
|
545
1133
|
...props,
|
|
546
1134
|
});
|
|
547
1135
|
}
|
|
1136
|
+
|
|
1137
|
+
/**
|
|
1138
|
+
* Grants IAM permissions to invoke any method on this API.
|
|
1139
|
+
*
|
|
1140
|
+
* @param grantee - The IAM principal to grant permissions to
|
|
1141
|
+
*/
|
|
1142
|
+
public grantInvokeAccess(grantee: IGrantable) {
|
|
1143
|
+
Grant.addToPrincipal({
|
|
1144
|
+
grantee,
|
|
1145
|
+
actions: ['execute-api:Invoke'],
|
|
1146
|
+
resourceArns: [this.api.arnForExecuteApi('*', '/*', '*')],
|
|
1147
|
+
});
|
|
1148
|
+
}
|
|
548
1149
|
}
|
|
549
1150
|
"
|
|
550
1151
|
`;
|
|
@@ -858,7 +1459,6 @@ import {
|
|
|
858
1459
|
IResource,
|
|
859
1460
|
} from 'aws-cdk-lib/aws-apigateway';
|
|
860
1461
|
import { RuntimeConfig } from '../runtime-config.js';
|
|
861
|
-
import { Grant, IGrantable } from 'aws-cdk-lib/aws-iam';
|
|
862
1462
|
import { OperationDetails, RestApiIntegration } from './utils.js';
|
|
863
1463
|
|
|
864
1464
|
/**
|
|
@@ -965,19 +1565,6 @@ export class RestApi<
|
|
|
965
1565
|
resource.getResource(nextPathPart) ?? resource.addResource(nextPathPart);
|
|
966
1566
|
return this.getOrCreateResource(childResource, pathParts);
|
|
967
1567
|
}
|
|
968
|
-
|
|
969
|
-
/**
|
|
970
|
-
* Grants IAM permissions to invoke any method on this API.
|
|
971
|
-
*
|
|
972
|
-
* @param grantee - The IAM principal to grant permissions to
|
|
973
|
-
*/
|
|
974
|
-
public grantInvokeAccess(grantee: IGrantable) {
|
|
975
|
-
Grant.addToPrincipal({
|
|
976
|
-
grantee,
|
|
977
|
-
actions: ['execute-api:Invoke'],
|
|
978
|
-
resourceArns: [this.api.arnForExecuteApi('*', '/*', '*')],
|
|
979
|
-
});
|
|
980
|
-
}
|
|
981
1568
|
}
|
|
982
1569
|
"
|
|
983
1570
|
`;
|
|
@@ -1002,8 +1589,10 @@ import {
|
|
|
1002
1589
|
PolicyDocument,
|
|
1003
1590
|
PolicyStatement,
|
|
1004
1591
|
Effect,
|
|
1005
|
-
AccountPrincipal,
|
|
1006
1592
|
AnyPrincipal,
|
|
1593
|
+
AccountPrincipal,
|
|
1594
|
+
IGrantable,
|
|
1595
|
+
Grant,
|
|
1007
1596
|
} from 'aws-cdk-lib/aws-iam';
|
|
1008
1597
|
import {
|
|
1009
1598
|
IntegrationBuilder,
|
|
@@ -1110,6 +1699,19 @@ export class TestApi<
|
|
|
1110
1699
|
...props,
|
|
1111
1700
|
});
|
|
1112
1701
|
}
|
|
1702
|
+
|
|
1703
|
+
/**
|
|
1704
|
+
* Grants IAM permissions to invoke any method on this API.
|
|
1705
|
+
*
|
|
1706
|
+
* @param grantee - The IAM principal to grant permissions to
|
|
1707
|
+
*/
|
|
1708
|
+
public grantInvokeAccess(grantee: IGrantable) {
|
|
1709
|
+
Grant.addToPrincipal({
|
|
1710
|
+
grantee,
|
|
1711
|
+
actions: ['execute-api:Invoke'],
|
|
1712
|
+
resourceArns: [this.api.arnForExecuteApi('*', '/*', '*')],
|
|
1713
|
+
});
|
|
1714
|
+
}
|
|
1113
1715
|
}
|
|
1114
1716
|
"
|
|
1115
1717
|
`;
|