@aws/nx-plugin 0.49.1 → 0.51.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.
- package/generators.json +22 -1
- package/package.json +1 -1
- package/sdk/ts.d.ts +2 -0
- package/sdk/ts.js +6 -3
- package/sdk/ts.js.map +1 -1
- package/src/api-connection/generator.d.ts +2 -2
- package/src/api-connection/generator.js +20 -0
- package/src/api-connection/generator.js.map +1 -1
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +128 -18
- package/src/infra/app/files/app/README.md.template +5 -5
- package/src/infra/app/files/app/checkov.yml.template +12 -0
- package/src/infra/app/files/app/src/main.ts.template +2 -4
- package/src/infra/app/generator.js +13 -8
- package/src/infra/app/generator.js.map +1 -1
- package/src/infra/app/schema.d.ts +0 -8
- package/src/infra/app/schema.json +0 -16
- package/src/license/config.js +3 -3
- package/src/license/config.js.map +1 -1
- package/src/open-api/ts-hooks/__snapshots__/generator.spec.tsx.snap +114 -0
- package/src/open-api/ts-hooks/generator.spec.tsx +176 -0
- package/src/open-api/utils/codegen-data.js +42 -5
- package/src/open-api/utils/codegen-data.js.map +1 -1
- package/src/preset/__snapshots__/generator.spec.ts.snap +2 -0
- package/src/py/fast-api/__snapshots__/generator.spec.ts.snap +55 -2
- package/src/py/fast-api/generator.js +8 -55
- package/src/py/fast-api/generator.js.map +1 -1
- package/src/py/fast-api/react/generator.js +9 -111
- package/src/py/fast-api/react/generator.js.map +1 -1
- package/src/py/lambda-function/generator.js +1 -1
- package/src/py/lambda-function/generator.js.map +1 -1
- package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +18 -74
- package/src/py/mcp-server/generator.js +1 -1
- package/src/py/mcp-server/generator.js.map +1 -1
- package/src/py/strands-agent/__snapshots__/generator.spec.ts.snap +18 -74
- package/src/py/strands-agent/generator.js +1 -1
- package/src/py/strands-agent/generator.js.map +1 -1
- package/src/smithy/project/__snapshots__/generator.spec.ts.snap +576 -0
- package/src/smithy/project/files/build.Dockerfile.template +97 -0
- package/src/smithy/project/files/smithy-build.json.template +25 -0
- package/src/smithy/project/files/src/main.smithy.template +19 -0
- package/src/smithy/project/files/src/operations/echo.smithy.template +18 -0
- package/src/smithy/project/generator.d.ts +10 -0
- package/src/smithy/project/generator.js +70 -0
- package/src/smithy/project/generator.js.map +1 -0
- package/src/smithy/project/schema.d.ts +11 -0
- package/src/smithy/project/schema.json +42 -0
- package/src/smithy/react-connection/__snapshots__/generator.spec.ts.snap +270 -0
- package/src/smithy/react-connection/files/model/extensions.smithy.template +33 -0
- package/src/smithy/react-connection/generator.d.ts +10 -0
- package/src/smithy/react-connection/generator.js +100 -0
- package/src/smithy/react-connection/generator.js.map +1 -0
- package/src/smithy/react-connection/schema.d.ts +8 -0
- package/src/smithy/react-connection/schema.json +26 -0
- package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +3023 -0
- package/src/smithy/ts/api/files/context.ts.template +12 -0
- package/src/smithy/ts/api/files/handler.ts.template +50 -0
- package/src/smithy/ts/api/files/index.ts.template +0 -0
- package/src/smithy/ts/api/files/local-server.ts.template +41 -0
- package/src/smithy/ts/api/files/operations/echo.ts.template +7 -0
- package/src/smithy/ts/api/files/service.ts.template +8 -0
- package/src/smithy/ts/api/generator.d.ts +10 -0
- package/src/smithy/ts/api/generator.js +154 -0
- package/src/smithy/ts/api/generator.js.map +1 -0
- package/src/smithy/ts/api/schema.d.ts +14 -0
- package/src/smithy/ts/api/schema.json +56 -0
- package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +61 -2
- package/src/trpc/backend/generator.js +6 -20
- package/src/trpc/backend/generator.js.map +1 -1
- package/src/trpc/backend/schema.d.ts +2 -1
- package/src/ts/lambda-function/__snapshots__/generator.spec.ts.snap +3 -3
- package/src/ts/lambda-function/generator.js +10 -10
- package/src/ts/lambda-function/generator.js.map +1 -1
- package/src/ts/lib/eslint.d.ts +7 -0
- package/src/ts/lib/eslint.js +37 -29
- package/src/ts/lib/eslint.js.map +1 -1
- package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +18 -74
- package/src/ts/mcp-server/files/Dockerfile.template +1 -1
- package/src/ts/mcp-server/generator.js +20 -14
- package/src/ts/mcp-server/generator.js.map +1 -1
- package/src/ts/nx-generator/__snapshots__/generator.spec.ts.snap +6 -6
- package/src/ts/nx-generator/generator.js +3 -2
- package/src/ts/nx-generator/generator.js.map +1 -1
- package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +267 -6
- package/src/ts/react-website/cognito-auth/__snapshots__/generator.spec.ts.snap +10 -0
- package/src/utils/__snapshots__/shared-constructs.spec.ts.snap +49 -0
- package/src/utils/agent-core-constructs/agent-core-constructs.js +0 -3
- package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
- package/src/utils/agent-core-constructs/files/cdk/app/agent-core/__nameKebabCase__/__nameKebabCase__.ts.template +1 -1
- package/src/utils/agent-core-constructs/files/cdk/core/agent-core/runtime.ts.template +15 -72
- package/src/utils/agent-core-constructs/files/terraform/core/agent-core/runtime.tf.template +1 -1
- package/src/utils/api-connection/open-api/react.d.ts +43 -0
- package/src/utils/api-connection/open-api/react.js +132 -0
- package/src/utils/api-connection/open-api/react.js.map +1 -0
- package/src/utils/api-constructs/api-constructs.d.ts +6 -2
- package/src/utils/api-constructs/api-constructs.js.map +1 -1
- package/src/utils/api-constructs/files/cdk/app/apis/http/__apiNameKebabCase__.ts.template +4 -4
- package/src/utils/api-constructs/files/cdk/app/apis/rest/__apiNameKebabCase__.ts.template +7 -4
- package/src/utils/api-constructs/files/cdk/core/api/http/http-api.ts.template +37 -2
- package/src/utils/api-constructs/files/cdk/core/api/rest/rest-api.ts.template +15 -0
- package/src/utils/api-constructs/files/terraform/app/apis/http/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +1 -1
- package/src/utils/api-constructs/files/terraform/app/apis/rest/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +1 -1
- package/src/utils/api-constructs/open-api-metadata.d.ts +17 -0
- package/src/utils/api-constructs/open-api-metadata.js +68 -0
- package/src/utils/api-constructs/open-api-metadata.js.map +1 -0
- package/src/utils/bundle/bundle.d.ts +35 -0
- package/src/utils/bundle/bundle.js +107 -0
- package/src/utils/bundle/bundle.js.map +1 -0
- package/src/utils/bundle/files/ts/rolldown.config.ts.template +3 -0
- package/src/utils/files/common/constructs/src/core/checkov.ts.template +44 -0
- package/src/utils/files/common/constructs/src/core/index.ts.template +1 -0
- package/src/utils/fs.d.ts +16 -0
- package/src/utils/fs.js +32 -0
- package/src/utils/fs.js.map +1 -0
- package/src/utils/identity-constructs/files/cdk/core/user-identity.ts.template +8 -0
- package/src/utils/nx.d.ts +10 -3
- package/src/utils/nx.js +18 -3
- package/src/utils/nx.js.map +1 -1
- package/src/utils/versions.d.ts +8 -5
- package/src/utils/versions.js +7 -4
- package/src/utils/versions.js.map +1 -1
- package/src/utils/website-constructs/files/cdk/core/static-website.ts.template +56 -2
- package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/aws-prototyping.guard +0 -1282
- package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/cfn-nag.guard +0 -6839
- package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/hipaa-security.guard +0 -2807
- package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/nist-csf.guard +0 -2585
- package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/pci-dss-3-2-1.guard +0 -2236
- package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/wa-reliability-pillar.guard +0 -885
- package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/wa-security-pillar.guard +0 -2205
- package/src/infra/app/files/common/constructs/src/core/cfn-guard.ts.template +0 -67
- package/src/utils/bundle.d.ts +0 -16
- package/src/utils/bundle.js +0 -48
- package/src/utils/bundle.js.map +0 -1
- package/src/utils/esbuild.d.ts +0 -15
- package/src/utils/esbuild.js +0 -46
- package/src/utils/esbuild.js.map +0 -1
- /package/src/{py/fast-api/react/files/website → utils/api-connection/open-api/files}/components/__apiNameClassName__Provider.tsx.template +0 -0
- /package/src/{py/fast-api/react/files/website → utils/api-connection/open-api/files}/hooks/use__apiNameClassName__.tsx.template +0 -0
- /package/src/{py/fast-api/react/files/website → utils/api-connection/open-api/files}/hooks/use__apiNameClassName__Client.tsx.template +0 -0
|
@@ -8,15 +8,9 @@ import {
|
|
|
8
8
|
Grant,
|
|
9
9
|
IPrincipal,
|
|
10
10
|
} from 'aws-cdk-lib/aws-iam';
|
|
11
|
-
import {
|
|
12
|
-
AwsCustomResource,
|
|
13
|
-
AwsCustomResourcePolicy,
|
|
14
|
-
PhysicalResourceId,
|
|
15
|
-
PhysicalResourceIdReference,
|
|
16
|
-
} from 'aws-cdk-lib/custom-resources';
|
|
17
11
|
import { Construct } from 'constructs';
|
|
18
|
-
import type { AuthorizerConfiguration } from '@aws-sdk/client-bedrock-agentcore-control';
|
|
19
12
|
import { Stack } from 'aws-cdk-lib';
|
|
13
|
+
import { CfnRuntime } from 'aws-cdk-lib/aws-bedrockagentcore';
|
|
20
14
|
|
|
21
15
|
/**
|
|
22
16
|
* Options for the AgentCoreRuntime construct
|
|
@@ -27,7 +21,7 @@ export interface AgentCoreRuntimeProps {
|
|
|
27
21
|
containerUri: string;
|
|
28
22
|
serverProtocol: 'MCP' | 'HTTP';
|
|
29
23
|
environment?: Record<string, string>;
|
|
30
|
-
authorizerConfiguration?:
|
|
24
|
+
authorizerConfiguration?: CfnRuntime.AuthorizerConfigurationProperty;
|
|
31
25
|
}
|
|
32
26
|
|
|
33
27
|
/**
|
|
@@ -132,75 +126,24 @@ export class AgentCoreRuntime extends Construct implements IGrantable {
|
|
|
132
126
|
});
|
|
133
127
|
this.grantPrincipal = this.role.grantPrincipal;
|
|
134
128
|
|
|
135
|
-
const agentRuntime = new
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
agentRuntimeName: props.runtimeName,
|
|
141
|
-
agentRuntimeArtifact: {
|
|
142
|
-
containerConfiguration: {
|
|
143
|
-
containerUri: props.containerUri,
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
description: props.description,
|
|
147
|
-
environmentVariables: props.environment,
|
|
148
|
-
networkConfiguration: {
|
|
149
|
-
networkMode: 'PUBLIC',
|
|
150
|
-
},
|
|
151
|
-
protocolConfiguration: {
|
|
152
|
-
serverProtocol: props.serverProtocol,
|
|
153
|
-
},
|
|
154
|
-
roleArn: this.role.roleArn,
|
|
155
|
-
authorizerConfiguration: props.authorizerConfiguration,
|
|
156
|
-
},
|
|
157
|
-
physicalResourceId: PhysicalResourceId.fromResponse('agentRuntimeId'),
|
|
158
|
-
},
|
|
159
|
-
onUpdate: {
|
|
160
|
-
service: 'bedrock-agentcore-control',
|
|
161
|
-
action: 'UpdateAgentRuntime',
|
|
162
|
-
parameters: {
|
|
163
|
-
agentRuntimeId: new PhysicalResourceIdReference(),
|
|
164
|
-
agentRuntimeName: props.runtimeName,
|
|
165
|
-
agentRuntimeArtifact: {
|
|
166
|
-
containerConfiguration: {
|
|
167
|
-
containerUri: props.containerUri,
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
description: props.description,
|
|
171
|
-
environmentVariables: props.environment,
|
|
172
|
-
networkConfiguration: {
|
|
173
|
-
networkMode: 'PUBLIC',
|
|
174
|
-
},
|
|
175
|
-
protocolConfiguration: {
|
|
176
|
-
serverProtocol: props.serverProtocol,
|
|
177
|
-
},
|
|
178
|
-
roleArn: this.role.roleArn,
|
|
179
|
-
authorizerConfiguration: props.authorizerConfiguration,
|
|
129
|
+
const agentRuntime = new CfnRuntime(this, 'MCPServerRuntime', {
|
|
130
|
+
agentRuntimeName: props.runtimeName,
|
|
131
|
+
agentRuntimeArtifact: {
|
|
132
|
+
containerConfiguration: {
|
|
133
|
+
containerUri: props.containerUri,
|
|
180
134
|
},
|
|
181
|
-
physicalResourceId: PhysicalResourceId.fromResponse('agentRuntimeId'),
|
|
182
135
|
},
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
agentRuntimeId: new PhysicalResourceIdReference(),
|
|
188
|
-
},
|
|
136
|
+
description: props.description,
|
|
137
|
+
environmentVariables: props.environment,
|
|
138
|
+
networkConfiguration: {
|
|
139
|
+
networkMode: 'PUBLIC',
|
|
189
140
|
},
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
resources: ['*'],
|
|
194
|
-
}),
|
|
195
|
-
new PolicyStatement({
|
|
196
|
-
actions: ['iam:PassRole'],
|
|
197
|
-
resources: [this.role.roleArn],
|
|
198
|
-
}),
|
|
199
|
-
]),
|
|
200
|
-
installLatestAwsSdk: true,
|
|
141
|
+
protocolConfiguration: props.serverProtocol,
|
|
142
|
+
roleArn: this.role.roleArn,
|
|
143
|
+
authorizerConfiguration: props.authorizerConfiguration,
|
|
201
144
|
});
|
|
202
145
|
|
|
203
|
-
this.arn = agentRuntime.
|
|
146
|
+
this.arn = agentRuntime.attrAgentRuntimeArn;
|
|
204
147
|
}
|
|
205
148
|
|
|
206
149
|
/**
|
|
@@ -278,7 +278,7 @@ resource "aws_iam_role_policy_attachment" "agent_core_policy" {
|
|
|
278
278
|
}
|
|
279
279
|
|
|
280
280
|
data "external" "docker_digest" {
|
|
281
|
-
program = ["sh", "-c", "echo '{\"digest\":\"'$(docker inspect ${var.docker_image_tag} --format '{{.
|
|
281
|
+
program = ["sh", "-c", "echo '{\"digest\":\"'$(docker inspect ${var.docker_image_tag} --format '{{.Id}}')'\"}' "]
|
|
282
282
|
}
|
|
283
283
|
|
|
284
284
|
# Null resource for Docker publish
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { ProjectConfiguration, Tree } from '@nx/devkit';
|
|
6
|
+
export interface AddOpenApiReactClientOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The react project to add the openapi client and build targets to
|
|
9
|
+
*/
|
|
10
|
+
frontendProjectConfig: ProjectConfiguration;
|
|
11
|
+
/**
|
|
12
|
+
* The backend project which serves the api
|
|
13
|
+
*/
|
|
14
|
+
backendProjectConfig: ProjectConfiguration;
|
|
15
|
+
/**
|
|
16
|
+
* The project which builds/generates the openapi spec
|
|
17
|
+
*/
|
|
18
|
+
specBuildProject: ProjectConfiguration;
|
|
19
|
+
/**
|
|
20
|
+
* Name of the api
|
|
21
|
+
*/
|
|
22
|
+
apiName: string;
|
|
23
|
+
/**
|
|
24
|
+
* Path to the openapi spec from the workspace root
|
|
25
|
+
*/
|
|
26
|
+
specPath: string;
|
|
27
|
+
/**
|
|
28
|
+
* Fully qualified target name for the target that builds/generates the openapi spec
|
|
29
|
+
*/
|
|
30
|
+
specBuildTargetName: string;
|
|
31
|
+
/**
|
|
32
|
+
* Authentication method
|
|
33
|
+
*/
|
|
34
|
+
auth: 'IAM' | 'Cognito' | 'None';
|
|
35
|
+
/**
|
|
36
|
+
* Port on which the backend project's local server listens
|
|
37
|
+
*/
|
|
38
|
+
port: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Adds an OpenAPI React client to the frontend project along with supporting build targets
|
|
42
|
+
*/
|
|
43
|
+
export declare const addOpenApiReactClient: (tree: Tree, { apiName, frontendProjectConfig, backendProjectConfig, specBuildProject, specPath, specBuildTargetName, auth, port, }: AddOpenApiReactClientOptions) => Promise<void>;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addOpenApiReactClient = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
/**
|
|
6
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
7
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
8
|
+
*/
|
|
9
|
+
const devkit_1 = require("@nx/devkit");
|
|
10
|
+
const names_1 = require("../../names");
|
|
11
|
+
const object_1 = require("../../object");
|
|
12
|
+
const git_1 = require("../../git");
|
|
13
|
+
const generator_1 = tslib_1.__importDefault(require("../../../ts/react-website/runtime-config/generator"));
|
|
14
|
+
const ast_1 = require("../../ast");
|
|
15
|
+
const serve_local_1 = require("../../../api-connection/serve-local");
|
|
16
|
+
const ast_2 = require("../../ast");
|
|
17
|
+
const versions_1 = require("../../versions");
|
|
18
|
+
/**
|
|
19
|
+
* Adds an OpenAPI React client to the frontend project along with supporting build targets
|
|
20
|
+
*/
|
|
21
|
+
const addOpenApiReactClient = (tree_1, _a) => tslib_1.__awaiter(void 0, [tree_1, _a], void 0, function* (tree, { apiName, frontendProjectConfig, backendProjectConfig, specBuildProject, specPath, specBuildTargetName, auth, port, }) {
|
|
22
|
+
const clientGenTarget = `generate:${(0, names_1.kebabCase)(apiName)}-client`;
|
|
23
|
+
const clientGenWatchTarget = `watch-${clientGenTarget}`;
|
|
24
|
+
const generatedClientDir = (0, devkit_1.joinPathFragments)('generated', (0, names_1.kebabCase)(apiName));
|
|
25
|
+
const generatedClientDirFromRoot = (0, devkit_1.joinPathFragments)(frontendProjectConfig.sourceRoot, generatedClientDir);
|
|
26
|
+
// Add TypeScript client generation to Frontend project.json
|
|
27
|
+
(0, devkit_1.updateProjectConfiguration)(tree, frontendProjectConfig.name, Object.assign(Object.assign({}, frontendProjectConfig), { targets: (0, object_1.sortObjectKeys)(Object.assign(Object.assign(Object.assign({}, frontendProjectConfig.targets), Object.fromEntries(['compile', 'bundle'].map((target) => {
|
|
28
|
+
var _a, _b, _c, _d;
|
|
29
|
+
return [
|
|
30
|
+
target,
|
|
31
|
+
Object.assign(Object.assign({}, (_a = frontendProjectConfig.targets) === null || _a === void 0 ? void 0 : _a[target]), { dependsOn: [
|
|
32
|
+
...((_d = (_c = (_b = frontendProjectConfig.targets) === null || _b === void 0 ? void 0 : _b[target]) === null || _c === void 0 ? void 0 : _c.dependsOn) !== null && _d !== void 0 ? _d : []).filter((t) => t !== clientGenTarget),
|
|
33
|
+
clientGenTarget,
|
|
34
|
+
] }),
|
|
35
|
+
];
|
|
36
|
+
}))), { [clientGenTarget]: {
|
|
37
|
+
cache: true,
|
|
38
|
+
executor: 'nx:run-commands',
|
|
39
|
+
inputs: [
|
|
40
|
+
{
|
|
41
|
+
dependentTasksOutputFiles: '**/*.json',
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
outputs: [
|
|
45
|
+
(0, devkit_1.joinPathFragments)('{workspaceRoot}', generatedClientDirFromRoot),
|
|
46
|
+
],
|
|
47
|
+
options: {
|
|
48
|
+
commands: [
|
|
49
|
+
`nx g @aws/nx-plugin:open-api#ts-hooks --openApiSpecPath="${specPath}" --outputPath="${generatedClientDirFromRoot}" --no-interactive`,
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
dependsOn: [specBuildTargetName],
|
|
53
|
+
},
|
|
54
|
+
// Watch target for regenerating the client
|
|
55
|
+
[clientGenWatchTarget]: {
|
|
56
|
+
executor: 'nx:run-commands',
|
|
57
|
+
options: {
|
|
58
|
+
commands: [
|
|
59
|
+
`nx watch --projects=${specBuildProject.name} --includeDependentProjects -- nx run ${frontendProjectConfig.name}:"${clientGenTarget}"`,
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
continuous: true,
|
|
63
|
+
} })) }));
|
|
64
|
+
const relativeSrcDir = frontendProjectConfig.sourceRoot.slice(frontendProjectConfig.root.length + 1);
|
|
65
|
+
// Ignore the generated client by default
|
|
66
|
+
// Users can safely remove the entry from the .gitignore if they prefer to check it in
|
|
67
|
+
(0, git_1.updateGitIgnore)(tree, frontendProjectConfig.root, (patterns) => [
|
|
68
|
+
...patterns,
|
|
69
|
+
(0, devkit_1.joinPathFragments)(relativeSrcDir, generatedClientDir),
|
|
70
|
+
]);
|
|
71
|
+
// Ensure that the frontend has runtime config as we'll use the url for creating the client
|
|
72
|
+
yield (0, generator_1.default)(tree, {
|
|
73
|
+
project: frontendProjectConfig.name,
|
|
74
|
+
});
|
|
75
|
+
// Add sigv4 fetch
|
|
76
|
+
if (auth === 'IAM') {
|
|
77
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, '../../files/website/hooks/sigv4'), (0, devkit_1.joinPathFragments)(frontendProjectConfig.sourceRoot, 'hooks'), {});
|
|
78
|
+
}
|
|
79
|
+
// Generate the tanstack query provider if it does not exist already
|
|
80
|
+
if (!tree.exists((0, devkit_1.joinPathFragments)(frontendProjectConfig.sourceRoot, 'components', 'QueryClientProvider.tsx'))) {
|
|
81
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, '../../files/website/components/tanstack-query'), (0, devkit_1.joinPathFragments)(frontendProjectConfig.sourceRoot, 'components'), {});
|
|
82
|
+
}
|
|
83
|
+
const apiNameClassName = (0, names_1.toClassName)(apiName);
|
|
84
|
+
// Add a hook to instantiate the client
|
|
85
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files'), frontendProjectConfig.sourceRoot, {
|
|
86
|
+
auth,
|
|
87
|
+
apiName,
|
|
88
|
+
apiNameClassName,
|
|
89
|
+
generatedClientDir,
|
|
90
|
+
});
|
|
91
|
+
// Update main.tsx to add required providers
|
|
92
|
+
const mainTsxPath = (0, devkit_1.joinPathFragments)(frontendProjectConfig.sourceRoot, 'main.tsx');
|
|
93
|
+
// Add the query client provider if it doesn't exist already
|
|
94
|
+
const hasQueryClientProvider = (0, ast_1.query)(tree, mainTsxPath, 'JsxOpeningElement[tagName.name="QueryClientProvider"]').length > 0;
|
|
95
|
+
if (!hasQueryClientProvider) {
|
|
96
|
+
(0, ast_2.addSingleImport)(tree, mainTsxPath, 'QueryClientProvider', './components/QueryClientProvider');
|
|
97
|
+
(0, ast_1.replace)(tree, mainTsxPath, 'JsxSelfClosingElement[tagName.name="App"]', (node) => (0, ast_2.createJsxElementFromIdentifier)('QueryClientProvider', [node]));
|
|
98
|
+
}
|
|
99
|
+
// Add the api provider if it does not exist
|
|
100
|
+
const providerName = `${apiNameClassName}Provider`;
|
|
101
|
+
const hasProvider = (0, ast_1.query)(tree, mainTsxPath, `JsxOpeningElement[tagName.name="${providerName}"]`).length > 0;
|
|
102
|
+
if (!hasProvider) {
|
|
103
|
+
(0, ast_2.addSingleImport)(tree, mainTsxPath, providerName, `./components/${providerName}`);
|
|
104
|
+
(0, ast_1.replace)(tree, mainTsxPath, 'JsxSelfClosingElement[tagName.name="App"]', (node) => (0, ast_2.createJsxElementFromIdentifier)(providerName, [node]));
|
|
105
|
+
}
|
|
106
|
+
// Update serve-local on the website to use our local server
|
|
107
|
+
(0, serve_local_1.addTargetToServeLocal)(tree, frontendProjectConfig.name, backendProjectConfig.name, {
|
|
108
|
+
url: `http://localhost:${port}/`,
|
|
109
|
+
apiName,
|
|
110
|
+
// Additionally add a dependency on the generate watch command to ensure that local
|
|
111
|
+
// API changes that affect the client are also reloaded.
|
|
112
|
+
// We include a dependency on the generate target as watch ONLY triggers on a change,
|
|
113
|
+
// and we need to ensure the client is generated the first time if not already present.
|
|
114
|
+
additionalDependencyTargets: [clientGenTarget, clientGenWatchTarget],
|
|
115
|
+
});
|
|
116
|
+
(0, devkit_1.addDependenciesToPackageJson)(tree, (0, versions_1.withVersions)([
|
|
117
|
+
...(auth === 'IAM'
|
|
118
|
+
? [
|
|
119
|
+
'oidc-client-ts',
|
|
120
|
+
'react-oidc-context',
|
|
121
|
+
'@aws-sdk/client-cognito-identity',
|
|
122
|
+
'@aws-sdk/credential-provider-cognito-identity',
|
|
123
|
+
'aws4fetch',
|
|
124
|
+
]
|
|
125
|
+
: []),
|
|
126
|
+
...(auth === 'Cognito' ? ['react-oidc-context'] : []),
|
|
127
|
+
'@tanstack/react-query',
|
|
128
|
+
'@tanstack/react-query-devtools',
|
|
129
|
+
]), (0, versions_1.withVersions)(['@smithy/types']));
|
|
130
|
+
});
|
|
131
|
+
exports.addOpenApiReactClient = addOpenApiReactClient;
|
|
132
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../../../../../../../packages/nx-plugin/src/utils/api-connection/open-api/react.ts"],"names":[],"mappings":";;;;AAAA;;;GAGG;AACH,uCAOoB;AACpB,uCAAqD;AACrD,yCAA8C;AAC9C,mCAA4C;AAC5C,2GAAwF;AACxF,mCAA2C;AAC3C,qEAA4E;AAE5E,mCAA4E;AAC5E,6CAA8C;AAqC9C;;GAEG;AACI,MAAM,qBAAqB,GAAG,aAYnC,EAAE,4DAXF,IAAU,EACV,EACE,OAAO,EACP,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EAChB,QAAQ,EACR,mBAAmB,EACnB,IAAI,EACJ,IAAI,GACyB;IAE/B,MAAM,eAAe,GAAG,YAAY,IAAA,iBAAS,EAAC,OAAO,CAAC,SAAS,CAAC;IAChE,MAAM,oBAAoB,GAAG,SAAS,eAAe,EAAE,CAAC;IAExD,MAAM,kBAAkB,GAAG,IAAA,0BAAiB,EAAC,WAAW,EAAE,IAAA,iBAAS,EAAC,OAAO,CAAC,CAAC,CAAC;IAC9E,MAAM,0BAA0B,GAAG,IAAA,0BAAiB,EAClD,qBAAqB,CAAC,UAAU,EAChC,kBAAkB,CACnB,CAAC;IAEF,4DAA4D;IAC5D,IAAA,mCAA0B,EAAC,IAAI,EAAE,qBAAqB,CAAC,IAAI,kCACtD,qBAAqB,KACxB,OAAO,EAAE,IAAA,uBAAc,gDAClB,qBAAqB,CAAC,OAAO,GAE7B,MAAM,CAAC,WAAW,CACnB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;;YAAC,OAAA;gBACpC,MAAM;gDAED,MAAA,qBAAqB,CAAC,OAAO,0CAAG,MAAM,CAAC,KAC1C,SAAS,EAAE;wBACT,GAAG,CACD,MAAA,MAAA,MAAA,qBAAqB,CAAC,OAAO,0CAAG,M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AAuB;QACvB,gCAAgC;KACjC,CAAC,EACF,IAAA,uBAAY,EAAC,CAAC,eAAe,CAAC,CAAC,CAChC,CAAC;AACJ,CAAC,CAAA,CAAC;AA/NW,QAAA,qBAAqB,yBA+NhC"}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { Tree } from '@nx/devkit';
|
|
6
6
|
import { IacProvider } from '../iac';
|
|
7
7
|
interface BackendOptions {
|
|
8
|
-
type: 'trpc' | 'fastapi';
|
|
8
|
+
type: 'trpc' | 'fastapi' | 'smithy';
|
|
9
9
|
}
|
|
10
10
|
export interface TrpcBackendOptions extends BackendOptions {
|
|
11
11
|
type: 'trpc';
|
|
@@ -17,12 +17,16 @@ export interface FastApiBackendOptions extends BackendOptions {
|
|
|
17
17
|
moduleName: string;
|
|
18
18
|
dir: string;
|
|
19
19
|
}
|
|
20
|
+
export interface SmithyBackendOptions extends BackendOptions {
|
|
21
|
+
type: 'smithy';
|
|
22
|
+
dir: string;
|
|
23
|
+
}
|
|
20
24
|
export interface AddApiGatewayConstructOptions {
|
|
21
25
|
apiProjectName: string;
|
|
22
26
|
apiNameClassName: string;
|
|
23
27
|
apiNameKebabCase: string;
|
|
24
28
|
constructType: 'http' | 'rest';
|
|
25
|
-
backend: TrpcBackendOptions | FastApiBackendOptions;
|
|
29
|
+
backend: TrpcBackendOptions | FastApiBackendOptions | SmithyBackendOptions;
|
|
26
30
|
auth: 'IAM' | 'Cognito' | 'None';
|
|
27
31
|
}
|
|
28
32
|
export declare const addApiGatewayInfra: (tree: Tree, options: AddApiGatewayConstructOptions & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-constructs.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/utils/api-constructs/api-constructs.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCAOoB;AACpB,gFAIwC;AACxC,gCAAuC;
|
|
1
|
+
{"version":3,"file":"api-constructs.js","sourceRoot":"","sources":["../../../../../../packages/nx-pl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AAU,CACX,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,6BAA6B,GAAG,CACpC,IAAU,EACV,OAAsC,EACtC,EAAE;IACF,iCAAiC;IACjC,IAAA,sBAAa,EACX,IAAI,EACJ,IAAA,0BAAiB,EACf,SAAS,EACT,OAAO,EACP,WAAW,EACX,MAAM,EACN,KAAK,EACL,OAAO,CAAC,aAAa,CACtB,EACD,IAAA,0BAAiB,EAAC,0CAAY,EAAE,kDAAoB,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAC3E,EAAE,EACF;QACE,iBAAiB,EAAE,0BAAiB,CAAC,YAAY;KAClD,CACF,CAAC;IAEF,yCAAyC;IACzC,IAAA,sBAAa,EACX,IAAI,EACJ,IAAA,0BAAiB,EACf,SAAS,EACT,OAAO,EACP,WAAW,EACX,KAAK,EACL,MAAM,EACN,OAAO,CAAC,aAAa,CACtB,EACD,IAAA,0BAAiB,EAAC,0CAAY,EAAE,kDAAoB,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,EAC3E,OAAO,EACP;QACE,iBAAiB,EAAE,0BAAiB,CAAC,YAAY;KAClD,CACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -41,7 +41,7 @@ import { AppRouter, appRouter } from '<%= backend.projectAlias %>';
|
|
|
41
41
|
|
|
42
42
|
// String union type for all API operation names
|
|
43
43
|
type Operations = Procedures<AppRouter>;
|
|
44
|
-
<%_ } else
|
|
44
|
+
<%_ } else { _%>
|
|
45
45
|
import {
|
|
46
46
|
OPERATION_DETAILS,
|
|
47
47
|
Operations,
|
|
@@ -90,11 +90,11 @@ export class <%= apiNameClassName %><
|
|
|
90
90
|
return IntegrationBuilder.http({
|
|
91
91
|
<%_ if (backend.type === 'trpc') { _%>
|
|
92
92
|
operations: routerToOperations(appRouter),
|
|
93
|
-
<%_ } else
|
|
93
|
+
<%_ } else { _%>
|
|
94
94
|
operations: OPERATION_DETAILS,
|
|
95
95
|
<%_ } _%>
|
|
96
96
|
defaultIntegrationOptions: {
|
|
97
|
-
<%_ if (backend.type
|
|
97
|
+
<%_ if (['trpc', 'smithy'].includes(backend.type)) { _%>
|
|
98
98
|
runtime: Runtime.NODEJS_LATEST,
|
|
99
99
|
handler: 'index.handler',
|
|
100
100
|
code: Code.fromAsset(
|
|
@@ -162,7 +162,7 @@ export class <%= apiNameClassName %><
|
|
|
162
162
|
<%_ } _%>
|
|
163
163
|
<%_ if (backend.type === 'trpc') { _%>
|
|
164
164
|
operations: routerToOperations(appRouter),
|
|
165
|
-
<%_ } else
|
|
165
|
+
<%_ } else { _%>
|
|
166
166
|
operations: OPERATION_DETAILS,
|
|
167
167
|
<%_ } _%>
|
|
168
168
|
...props,
|
|
@@ -46,7 +46,7 @@ import { AppRouter, appRouter } from '<%= backend.projectAlias %>';
|
|
|
46
46
|
|
|
47
47
|
// String union type for all API operation names
|
|
48
48
|
type Operations = Procedures<AppRouter>;
|
|
49
|
-
<%_ } else
|
|
49
|
+
<%_ } else { _%>
|
|
50
50
|
import {
|
|
51
51
|
OPERATION_DETAILS,
|
|
52
52
|
Operations,
|
|
@@ -94,11 +94,11 @@ export class <%= apiNameClassName %><
|
|
|
94
94
|
return IntegrationBuilder.rest({
|
|
95
95
|
<%_ if (backend.type === 'trpc') { _%>
|
|
96
96
|
operations: routerToOperations(appRouter),
|
|
97
|
-
<%_ } else
|
|
97
|
+
<%_ } else { _%>
|
|
98
98
|
operations: OPERATION_DETAILS,
|
|
99
99
|
<%_ } _%>
|
|
100
100
|
defaultIntegrationOptions: {
|
|
101
|
-
<%_ if (backend.type
|
|
101
|
+
<%_ if (['trpc', 'smithy'].includes(backend.type)) { _%>
|
|
102
102
|
runtime: Runtime.NODEJS_LATEST,
|
|
103
103
|
handler: 'index.handler',
|
|
104
104
|
code: Code.fromAsset(
|
|
@@ -157,6 +157,9 @@ export class <%= apiNameClassName %><
|
|
|
157
157
|
allowOrigins: Cors.ALL_ORIGINS,
|
|
158
158
|
allowMethods: Cors.ALL_METHODS,
|
|
159
159
|
},
|
|
160
|
+
deployOptions: {
|
|
161
|
+
tracingEnabled: true,
|
|
162
|
+
},
|
|
160
163
|
policy: new PolicyDocument({
|
|
161
164
|
statements: [
|
|
162
165
|
<%_ if (auth === 'IAM') { _%>
|
|
@@ -189,7 +192,7 @@ export class <%= apiNameClassName %><
|
|
|
189
192
|
}),
|
|
190
193
|
<%_ if (backend.type === 'trpc') { _%>
|
|
191
194
|
operations: routerToOperations(appRouter),
|
|
192
|
-
<%_ } else
|
|
195
|
+
<%_ } else { _%>
|
|
193
196
|
operations: OPERATION_DETAILS,
|
|
194
197
|
<%_ } _%>
|
|
195
198
|
...props,
|
|
@@ -6,7 +6,11 @@ import {
|
|
|
6
6
|
HttpApi as _HttpApi,
|
|
7
7
|
HttpApiProps as _HttpApiProps,
|
|
8
8
|
HttpMethod,
|
|
9
|
+
HttpStage,
|
|
10
|
+
LogGroupLogDestination,
|
|
9
11
|
} from 'aws-cdk-lib/aws-apigatewayv2';
|
|
12
|
+
import { LogGroup } from 'aws-cdk-lib/aws-logs';
|
|
13
|
+
import { suppressRules } from '../checkov.js';
|
|
10
14
|
|
|
11
15
|
/**
|
|
12
16
|
* Properties for creating an HttpApi construct.
|
|
@@ -50,6 +54,9 @@ export class HttpApi<
|
|
|
50
54
|
/** The underlying CDK HttpApi instance */
|
|
51
55
|
public readonly api: _HttpApi;
|
|
52
56
|
|
|
57
|
+
/** Default auto-deployed stage */
|
|
58
|
+
public readonly defaultStage: HttpStage;
|
|
59
|
+
|
|
53
60
|
/** Map of operation names to their API Gateway integrations */
|
|
54
61
|
public readonly integrations: TIntegrations;
|
|
55
62
|
|
|
@@ -68,9 +75,30 @@ export class HttpApi<
|
|
|
68
75
|
|
|
69
76
|
// Create the API Gateway REST API
|
|
70
77
|
this.api = new _HttpApi(this, 'Api', {
|
|
78
|
+
createDefaultStage: false,
|
|
71
79
|
...props,
|
|
72
80
|
});
|
|
73
81
|
|
|
82
|
+
const accessLogGroup = new LogGroup(this, 'AccessLogs');
|
|
83
|
+
suppressRules(
|
|
84
|
+
accessLogGroup,
|
|
85
|
+
['CKV_AWS_158'],
|
|
86
|
+
'Using default CloudWatch log encryption',
|
|
87
|
+
);
|
|
88
|
+
suppressRules(
|
|
89
|
+
accessLogGroup,
|
|
90
|
+
['CKV_AWS_66', 'CKV_AWS_338'],
|
|
91
|
+
'Logs are retained forever',
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
this.defaultStage = new HttpStage(this, 'DefaultStage', {
|
|
95
|
+
httpApi: this.api,
|
|
96
|
+
autoDeploy: true,
|
|
97
|
+
accessLogSettings: {
|
|
98
|
+
destination: new LogGroupLogDestination(accessLogGroup),
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
|
|
74
102
|
// Create API resources and methods for each operation
|
|
75
103
|
(Object.entries(operations) as [TOperation, OperationDetails][]).map(
|
|
76
104
|
([op, details]) => {
|
|
@@ -86,13 +114,20 @@ export class HttpApi<
|
|
|
86
114
|
);
|
|
87
115
|
|
|
88
116
|
new CfnOutput(this, `${apiName}Url`, {
|
|
89
|
-
value: this.
|
|
117
|
+
value: this.defaultStage.url!,
|
|
90
118
|
});
|
|
91
119
|
|
|
92
120
|
// Register the API URL in runtime configuration for client discovery
|
|
93
121
|
RuntimeConfig.ensure(this).config.apis = {
|
|
94
122
|
...RuntimeConfig.ensure(this).config.apis!,
|
|
95
|
-
[apiName]: this.
|
|
123
|
+
[apiName]: this.defaultStage.url!,
|
|
96
124
|
};
|
|
97
125
|
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Return the API url
|
|
129
|
+
*/
|
|
130
|
+
public get url() {
|
|
131
|
+
return this.defaultStage.url;
|
|
132
|
+
}
|
|
98
133
|
}
|
|
@@ -3,9 +3,11 @@ import {
|
|
|
3
3
|
RestApi as _RestApi,
|
|
4
4
|
RestApiProps as _RestApiProps,
|
|
5
5
|
IResource,
|
|
6
|
+
Stage,
|
|
6
7
|
} from 'aws-cdk-lib/aws-apigateway';
|
|
7
8
|
import { RuntimeConfig } from '../runtime-config.js';
|
|
8
9
|
import { OperationDetails, RestApiIntegration } from './utils.js';
|
|
10
|
+
import { suppressRules } from '../checkov.js';
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* Properties for creating a RestApi construct.
|
|
@@ -68,6 +70,19 @@ export class RestApi<
|
|
|
68
70
|
// Create the API Gateway REST API
|
|
69
71
|
this.api = new _RestApi(this, 'Api', props);
|
|
70
72
|
|
|
73
|
+
suppressRules(
|
|
74
|
+
this.api,
|
|
75
|
+
['CKV_AWS_120'],
|
|
76
|
+
'Caching not required for this use case',
|
|
77
|
+
(c) => c instanceof Stage,
|
|
78
|
+
);
|
|
79
|
+
suppressRules(
|
|
80
|
+
this.api,
|
|
81
|
+
['CKV_AWS_76'],
|
|
82
|
+
'API Gateway access logging disabled due to account-level CloudWatch Logs role ARN requirement',
|
|
83
|
+
(c) => c instanceof Stage,
|
|
84
|
+
);
|
|
85
|
+
|
|
71
86
|
// Create API resources and methods for each operation
|
|
72
87
|
(Object.entries(operations) as [TOperation, OperationDetails][]).map(
|
|
73
88
|
([op, details]) => {
|
|
@@ -128,7 +128,7 @@ resource "aws_lambda_function" "api_lambda" {
|
|
|
128
128
|
filename = data.archive_file.lambda_zip.output_path
|
|
129
129
|
function_name = "<%- apiNameClassName %>Handler"
|
|
130
130
|
role = aws_iam_role.lambda_execution_role.arn
|
|
131
|
-
<%_ if (backend.type
|
|
131
|
+
<%_ if (['trpc', 'smithy'].includes(backend.type)) { _%>
|
|
132
132
|
handler = "index.handler"
|
|
133
133
|
runtime = "nodejs22.x"
|
|
134
134
|
<%_ } else if (backend.type === 'fastapi') { _%>
|
|
@@ -106,7 +106,7 @@ resource "aws_lambda_function" "api_lambda" {
|
|
|
106
106
|
filename = data.archive_file.lambda_zip.output_path
|
|
107
107
|
function_name = "<%- apiNameClassName %>Handler"
|
|
108
108
|
role = aws_iam_role.lambda_execution_role.arn
|
|
109
|
-
<%_ if (backend.type
|
|
109
|
+
<%_ if (['trpc', 'smithy'].includes(backend.type)) { _%>
|
|
110
110
|
handler = "index.handler"
|
|
111
111
|
runtime = "nodejs22.x"
|
|
112
112
|
<%_ } else if (backend.type === 'fastapi') { _%>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { Tree } from '@nx/devkit';
|
|
6
|
+
import { IacProvider } from '../iac';
|
|
7
|
+
export interface AddOpenApiMetadataGenerateTargetOptions {
|
|
8
|
+
iacProvider: IacProvider;
|
|
9
|
+
apiNameKebabCase: string;
|
|
10
|
+
specPath: string;
|
|
11
|
+
specBuildTargetName: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Adds a generate:<api-name>-metadata target to shared constructs (CDK only)
|
|
15
|
+
* This allows for API CDK constructs to have type-safety for integrations based on an OpenAPI Specification
|
|
16
|
+
*/
|
|
17
|
+
export declare const addSharedConstructsOpenApiMetadataGenerateTarget: (tree: Tree, { iacProvider, apiNameKebabCase, specPath, specBuildTargetName, }: AddOpenApiMetadataGenerateTargetOptions) => void;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addSharedConstructsOpenApiMetadataGenerateTarget = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
const devkit_1 = require("@nx/devkit");
|
|
9
|
+
const git_1 = require("../git");
|
|
10
|
+
const shared_constructs_constants_1 = require("../shared-constructs-constants");
|
|
11
|
+
/**
|
|
12
|
+
* Adds a generate:<api-name>-metadata target to shared constructs (CDK only)
|
|
13
|
+
* This allows for API CDK constructs to have type-safety for integrations based on an OpenAPI Specification
|
|
14
|
+
*/
|
|
15
|
+
const addSharedConstructsOpenApiMetadataGenerateTarget = (tree, { iacProvider, apiNameKebabCase, specPath, specBuildTargetName, }) => {
|
|
16
|
+
if (iacProvider !== 'CDK') {
|
|
17
|
+
// For Terraform, we do not support type-safe integration builders, rather only the single lambda
|
|
18
|
+
// router pattern, and therefore do not need to add depenencies on metadata generation.
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const generatedMetadataDir = (0, devkit_1.joinPathFragments)('generated', apiNameKebabCase);
|
|
22
|
+
const generatedMetadataDirFromRoot = (0, devkit_1.joinPathFragments)((0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, shared_constructs_constants_1.SHARED_CONSTRUCTS_DIR), 'src', generatedMetadataDir);
|
|
23
|
+
(0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, shared_constructs_constants_1.SHARED_CONSTRUCTS_DIR, 'project.json'), (config) => {
|
|
24
|
+
var _a;
|
|
25
|
+
if (!config.targets) {
|
|
26
|
+
config.targets = {};
|
|
27
|
+
}
|
|
28
|
+
if (!config.targets.build) {
|
|
29
|
+
config.targets.build = {};
|
|
30
|
+
}
|
|
31
|
+
// If not already defined, add a target to generate metadata from the OpenAPI spec, used
|
|
32
|
+
// for providing a type-safe CDK construct
|
|
33
|
+
const metadataTargetName = `generate:${apiNameKebabCase}-metadata`;
|
|
34
|
+
if (!config.targets[metadataTargetName]) {
|
|
35
|
+
config.targets[metadataTargetName] = {
|
|
36
|
+
cache: true,
|
|
37
|
+
executor: 'nx:run-commands',
|
|
38
|
+
inputs: [
|
|
39
|
+
{
|
|
40
|
+
dependentTasksOutputFiles: '**/*.json',
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
outputs: [
|
|
44
|
+
(0, devkit_1.joinPathFragments)('{workspaceRoot}', generatedMetadataDirFromRoot),
|
|
45
|
+
],
|
|
46
|
+
options: {
|
|
47
|
+
commands: [
|
|
48
|
+
`nx g @aws/nx-plugin:open-api#ts-metadata --openApiSpecPath="${specPath}" --outputPath="${generatedMetadataDirFromRoot}" --no-interactive`,
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
dependsOn: [specBuildTargetName],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
if (!config.targets.compile) {
|
|
55
|
+
config.targets.compile = {};
|
|
56
|
+
}
|
|
57
|
+
config.targets.compile.dependsOn = [
|
|
58
|
+
...((_a = config.targets.compile.dependsOn) !== null && _a !== void 0 ? _a : []),
|
|
59
|
+
metadataTargetName,
|
|
60
|
+
];
|
|
61
|
+
return config;
|
|
62
|
+
});
|
|
63
|
+
// Ignore the generated metadata by default
|
|
64
|
+
// Users can safely remove the entry from the .gitignore if they prefer to check it in
|
|
65
|
+
(0, git_1.updateGitIgnore)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, shared_constructs_constants_1.SHARED_CONSTRUCTS_DIR), (patterns) => [...patterns, (0, devkit_1.joinPathFragments)('src', generatedMetadataDir)]);
|
|
66
|
+
};
|
|
67
|
+
exports.addSharedConstructsOpenApiMetadataGenerateTarget = addSharedConstructsOpenApiMetadataGenerateTarget;
|
|
68
|
+
//# sourceMappingURL=open-api-metadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-api-metadata.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/utils/api-constructs/open-api-metadata.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCAKoB;AAEpB,gCAAyC;AACzC,gFAGwC;AASxC;;;GAGG;AACI,MAAM,gDAAgD,GAAG,CAC9D,IAAU,EACV,EACE,WAAW,EACX,gBAAgB,EAChB,QAAQ,EACR,mBAAmB,GACqB,EAC1C,EAAE;IACF,IAAI,WAAW,KAAK,KAAK,EAAE,CAAC;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