@aws/nx-plugin 0.20.0 → 0.22.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/LICENSE-THIRD-PARTY +531 -21
- package/README.md +3 -9
- package/generators.json +14 -0
- package/package.json +7 -7
- package/src/cloudscape-website/cognito-auth/__snapshots__/generator.spec.ts.snap +1 -0
- package/src/cloudscape-website/cognito-auth/files/common/constructs/src/core/user-identity.ts.template +1 -0
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +54 -12
- package/src/infra/app/generator.js +14 -0
- package/src/infra/app/generator.js.map +1 -1
- package/src/open-api/ts-metadata/__snapshots__/generator.spec.ts.snap +49 -0
- package/src/open-api/ts-metadata/files/metadata.gen.ts.template +17 -0
- package/src/open-api/ts-metadata/generator.d.ts +16 -0
- package/src/open-api/ts-metadata/generator.js +32 -0
- package/src/open-api/ts-metadata/generator.js.map +1 -0
- package/src/{utils/http-api.d.ts → open-api/ts-metadata/schema.d.ts} +5 -2
- package/src/open-api/ts-metadata/schema.json +20 -0
- package/src/open-api/utils/codegen-data.js +3 -0
- package/src/open-api/utils/codegen-data.js.map +1 -1
- package/src/open-api/utils/normalise.js +6 -0
- package/src/open-api/utils/normalise.js.map +1 -1
- package/src/preset/__snapshots__/generator.spec.ts.snap +199 -0
- package/src/preset/files/README.md +107 -0
- package/src/preset/generator.d.ts +10 -0
- package/src/preset/generator.js +63 -0
- package/src/preset/generator.js.map +1 -0
- package/src/preset/schema.d.ts +7 -0
- package/src/preset/schema.json +14 -0
- package/src/py/fast-api/__snapshots__/generator.spec.ts.snap +972 -0
- package/src/py/fast-api/files/app/__name__/init.py.template +8 -0
- package/src/py/fast-api/generator.js +53 -15
- package/src/py/fast-api/generator.js.map +1 -1
- package/src/py/fast-api/react/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/py/fast-api/react/files/website/components/__apiNameClassName__Provider.tsx.template +1 -1
- package/src/py/fast-api/react/generator.js +6 -23
- package/src/py/fast-api/react/generator.js.map +1 -1
- package/src/py/fast-api/react/open-api.d.ts +14 -0
- package/src/py/fast-api/react/open-api.js +53 -0
- package/src/py/fast-api/react/open-api.js.map +1 -0
- package/src/py/fast-api/schema.d.ts +3 -0
- package/src/py/fast-api/schema.json +8 -0
- package/src/setup-tests.d.ts +2 -0
- package/src/setup-tests.js +14 -0
- package/src/setup-tests.js.map +1 -0
- package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +1061 -88
- package/src/trpc/backend/files/backend/src/client/index.ts.template +2 -13
- package/src/trpc/backend/files/backend/src/index.ts.template +1 -0
- package/src/trpc/backend/files/backend/src/init.ts.template +4 -4
- package/src/trpc/backend/files/backend/src/middleware/index.ts.template +3 -2
- package/src/trpc/backend/files/backend/src/router.ts.template +11 -2
- package/src/trpc/backend/generator.js +12 -10
- package/src/trpc/backend/generator.js.map +1 -1
- package/src/trpc/backend/schema.d.ts +1 -1
- package/src/trpc/backend/schema.json +8 -0
- package/src/trpc/react/__snapshots__/generator.spec.ts.snap +4 -19
- package/src/trpc/react/files/src/components/TrpcClients/TrpcProvider.tsx.template +2 -13
- package/src/trpc/react/generator.js +1 -1
- package/src/trpc/react/generator.js.map +1 -1
- package/src/ts/lib/__snapshots__/generator.spec.ts.snap +26 -9
- package/src/ts/lib/generator.js +9 -0
- package/src/ts/lib/generator.js.map +1 -1
- package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +1 -4
- package/src/ts/nx-generator/generator.js +4 -3
- package/src/ts/nx-generator/generator.js.map +1 -1
- package/src/utils/api-constructs/api-constructs.d.ts +29 -0
- package/src/utils/api-constructs/api-constructs.js +65 -0
- package/src/utils/api-constructs/api-constructs.js.map +1 -0
- package/src/utils/api-constructs/files/app/apis/http/__apiNameKebabCase__.ts.template +135 -0
- package/src/utils/api-constructs/files/app/apis/rest/__apiNameKebabCase__.ts.template +156 -0
- package/src/utils/api-constructs/files/core/api/http/http-api.ts.template +112 -0
- package/src/utils/api-constructs/files/core/api/rest/rest-api.ts.template +137 -0
- package/src/utils/api-constructs/files/core/api/trpc/trpc-utils.ts.template +67 -0
- package/src/utils/api-constructs/files/core/api/utils/utils.ts.template +223 -0
- package/src/utils/versions.d.ts +3 -3
- package/src/utils/versions.js +2 -2
- package/src/py/fast-api/files/common/constructs/src/app/http-apis/__apiNameKebabCase__.ts.template +0 -22
- package/src/trpc/backend/files/common/constructs/src/app/http-apis/__apiNameKebabCase__.ts.template +0 -22
- package/src/utils/files/http-api/common/constructs/src/core/http-api.ts.template +0 -87
- package/src/utils/http-api.js +0 -51
- package/src/utils/http-api.js.map +0 -1
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { Integration, MethodOptions } from 'aws-cdk-lib/aws-apigateway';
|
|
2
|
+
import { HttpRouteIntegration, AddRoutesOptions } from 'aws-cdk-lib/aws-apigatewayv2';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Type representing applicable HTTP Methods in API Gateway
|
|
6
|
+
*/
|
|
7
|
+
export type HttpMethod =
|
|
8
|
+
| 'ANY'
|
|
9
|
+
| 'DELETE'
|
|
10
|
+
| 'GET'
|
|
11
|
+
| 'HEAD'
|
|
12
|
+
| 'OPTIONS'
|
|
13
|
+
| 'PATCH'
|
|
14
|
+
| 'POST'
|
|
15
|
+
| 'PUT';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Defines the details of an API operation.
|
|
19
|
+
*/
|
|
20
|
+
export interface OperationDetails {
|
|
21
|
+
/**
|
|
22
|
+
* The URL path for the operation
|
|
23
|
+
*/
|
|
24
|
+
path: string;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The HTTP method for the operation
|
|
28
|
+
*/
|
|
29
|
+
method: HttpMethod;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Represents an API Gateway REST API integration that can be attached to API methods.
|
|
34
|
+
*/
|
|
35
|
+
export interface RestApiIntegration {
|
|
36
|
+
integration: Integration;
|
|
37
|
+
options?: MethodOptions;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Represents an API Gateway HTTP API that can be attached to API methods.
|
|
42
|
+
*/
|
|
43
|
+
export interface HttpApiIntegration {
|
|
44
|
+
integration: HttpRouteIntegration;
|
|
45
|
+
options?: Omit<AddRoutesOptions, 'path' | 'methods' | 'integration'>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Options for constructing an IntegrationBuilder
|
|
50
|
+
*/
|
|
51
|
+
export interface IntegrationBuilderProps<
|
|
52
|
+
TOperation extends string,
|
|
53
|
+
TBaseIntegration,
|
|
54
|
+
TDefaultIntegrationProps extends object,
|
|
55
|
+
TDefaultIntegration extends TBaseIntegration,
|
|
56
|
+
> {
|
|
57
|
+
/** Map of operation names to their API path and HTTP method details */
|
|
58
|
+
operations: Record<TOperation, OperationDetails>;
|
|
59
|
+
|
|
60
|
+
/** Default configuration options for integrations */
|
|
61
|
+
defaultIntegrationOptions: TDefaultIntegrationProps;
|
|
62
|
+
|
|
63
|
+
/** Function to create a default integration for an operation */
|
|
64
|
+
buildDefaultIntegration: (
|
|
65
|
+
op: TOperation,
|
|
66
|
+
props: TDefaultIntegrationProps,
|
|
67
|
+
) => TDefaultIntegration;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A builder class for creating API integrations with flexible configuration options.
|
|
72
|
+
*
|
|
73
|
+
* This class implements the builder pattern to create a set of API integrations
|
|
74
|
+
* with support for default configurations and selective overrides.
|
|
75
|
+
*
|
|
76
|
+
* @template TOperation - String literal type representing operation names
|
|
77
|
+
* @template TBaseIntegration - Base type for all integrations
|
|
78
|
+
* @template TIntegrations - Record mapping operation names to their integrations
|
|
79
|
+
* @template TDefaultIntegrationProps - Type for default integration properties
|
|
80
|
+
* @template TDefaultIntegration - Type for default integration implementation
|
|
81
|
+
*/
|
|
82
|
+
export class IntegrationBuilder<
|
|
83
|
+
TOperation extends string,
|
|
84
|
+
TBaseIntegration,
|
|
85
|
+
TIntegrations extends Record<TOperation, TBaseIntegration>,
|
|
86
|
+
TDefaultIntegrationProps extends object,
|
|
87
|
+
TDefaultIntegration extends TBaseIntegration,
|
|
88
|
+
> {
|
|
89
|
+
/** Options for the integration builder */
|
|
90
|
+
private options: IntegrationBuilderProps<
|
|
91
|
+
TOperation,
|
|
92
|
+
TBaseIntegration,
|
|
93
|
+
TDefaultIntegrationProps,
|
|
94
|
+
TDefaultIntegration
|
|
95
|
+
>;
|
|
96
|
+
|
|
97
|
+
/** Map of operation names to their custom integrations */
|
|
98
|
+
private integrations: Partial<TIntegrations> = {};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Create an Integration Builder for an HTTP API
|
|
102
|
+
*/
|
|
103
|
+
public static http = <
|
|
104
|
+
TOperation extends string,
|
|
105
|
+
TIntegrations extends Record<TOperation, TDefaultIntegration>,
|
|
106
|
+
TDefaultIntegrationProps extends object,
|
|
107
|
+
TDefaultIntegration extends HttpApiIntegration,
|
|
108
|
+
>(
|
|
109
|
+
options: IntegrationBuilderProps<
|
|
110
|
+
TOperation,
|
|
111
|
+
HttpApiIntegration,
|
|
112
|
+
TDefaultIntegrationProps,
|
|
113
|
+
TDefaultIntegration
|
|
114
|
+
>,
|
|
115
|
+
) => {
|
|
116
|
+
return new IntegrationBuilder<
|
|
117
|
+
TOperation,
|
|
118
|
+
HttpApiIntegration,
|
|
119
|
+
TIntegrations,
|
|
120
|
+
TDefaultIntegrationProps,
|
|
121
|
+
TDefaultIntegration
|
|
122
|
+
>(options);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Create an Integration Builder for a REST API
|
|
127
|
+
*/
|
|
128
|
+
public static rest = <
|
|
129
|
+
TOperation extends string,
|
|
130
|
+
TIntegrations extends Record<TOperation, TDefaultIntegration>,
|
|
131
|
+
TDefaultIntegrationProps extends object,
|
|
132
|
+
TDefaultIntegration extends RestApiIntegration,
|
|
133
|
+
>(
|
|
134
|
+
options: IntegrationBuilderProps<
|
|
135
|
+
TOperation,
|
|
136
|
+
RestApiIntegration,
|
|
137
|
+
TDefaultIntegrationProps,
|
|
138
|
+
TDefaultIntegration
|
|
139
|
+
>,
|
|
140
|
+
) => {
|
|
141
|
+
return new IntegrationBuilder<
|
|
142
|
+
TOperation,
|
|
143
|
+
RestApiIntegration,
|
|
144
|
+
TIntegrations,
|
|
145
|
+
TDefaultIntegrationProps,
|
|
146
|
+
TDefaultIntegration
|
|
147
|
+
>(options);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
private constructor(
|
|
151
|
+
options: IntegrationBuilderProps<
|
|
152
|
+
TOperation,
|
|
153
|
+
TBaseIntegration,
|
|
154
|
+
TDefaultIntegrationProps,
|
|
155
|
+
TDefaultIntegration
|
|
156
|
+
>,
|
|
157
|
+
) {
|
|
158
|
+
this.options = options;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Overrides default integrations with custom implementations for specific operations.
|
|
163
|
+
*
|
|
164
|
+
* @param overrides - Map of operation names to their custom integration implementations
|
|
165
|
+
* @returns The builder instance with updated type information reflecting the overrides
|
|
166
|
+
*/
|
|
167
|
+
public withOverrides<
|
|
168
|
+
TOverrideIntegrations extends Partial<Record<TOperation, TBaseIntegration>>,
|
|
169
|
+
>(overrides: TOverrideIntegrations) {
|
|
170
|
+
this.integrations = { ...this.integrations, ...overrides };
|
|
171
|
+
// Re-type to include the overridden integration types
|
|
172
|
+
return this as unknown as IntegrationBuilder<
|
|
173
|
+
TOperation,
|
|
174
|
+
TBaseIntegration,
|
|
175
|
+
Omit<TIntegrations, keyof TOverrideIntegrations> & TOverrideIntegrations,
|
|
176
|
+
TDefaultIntegrationProps,
|
|
177
|
+
TDefaultIntegration
|
|
178
|
+
>;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Updates the default integration options that will be used for operations
|
|
183
|
+
* without custom overrides.
|
|
184
|
+
*
|
|
185
|
+
* @param options - Partial default integration options to merge with existing defaults
|
|
186
|
+
* @returns The builder instance
|
|
187
|
+
*/
|
|
188
|
+
public withDefaultOptions(options: Partial<TDefaultIntegrationProps>) {
|
|
189
|
+
this.options.defaultIntegrationOptions = {
|
|
190
|
+
...this.options.defaultIntegrationOptions,
|
|
191
|
+
...options,
|
|
192
|
+
};
|
|
193
|
+
return this;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Builds and returns the complete set of integrations.
|
|
198
|
+
*
|
|
199
|
+
* This method creates the final integration map by:
|
|
200
|
+
* 1. Including all custom overrides provided via withOverrides()
|
|
201
|
+
* 2. Creating default integrations for any operations without custom overrides
|
|
202
|
+
*
|
|
203
|
+
* @returns A complete map of operation names to their integrations
|
|
204
|
+
*/
|
|
205
|
+
public build(): TIntegrations {
|
|
206
|
+
return {
|
|
207
|
+
...this.integrations,
|
|
208
|
+
...Object.fromEntries(
|
|
209
|
+
(Object.keys(this.options.operations) as TOperation[])
|
|
210
|
+
.filter(
|
|
211
|
+
(op) => !this.integrations[op as keyof typeof this.integrations],
|
|
212
|
+
)
|
|
213
|
+
.map((op) => [
|
|
214
|
+
op,
|
|
215
|
+
this.options.buildDefaultIntegration(
|
|
216
|
+
op,
|
|
217
|
+
this.options.defaultIntegrationOptions,
|
|
218
|
+
),
|
|
219
|
+
]),
|
|
220
|
+
),
|
|
221
|
+
} as unknown as TIntegrations;
|
|
222
|
+
}
|
|
223
|
+
}
|
package/src/utils/versions.d.ts
CHANGED
|
@@ -11,8 +11,8 @@ export declare const VERSIONS: {
|
|
|
11
11
|
readonly '@aws-lambda-powertools/logger': "^2.17.0";
|
|
12
12
|
readonly '@aws-lambda-powertools/metrics': "^2.17.0";
|
|
13
13
|
readonly '@aws-lambda-powertools/tracer': "^2.17.0";
|
|
14
|
-
readonly '@nxlv/python': "^20.
|
|
15
|
-
readonly '@nx/devkit': "~
|
|
14
|
+
readonly '@nxlv/python': "^20.15.0";
|
|
15
|
+
readonly '@nx/devkit': "~21.0.3";
|
|
16
16
|
readonly '@modelcontextprotocol/sdk': "^1.10.2";
|
|
17
17
|
readonly '@tanstack/react-router': "^1.114.27";
|
|
18
18
|
readonly '@tanstack/router-plugin': "^1.114.27";
|
|
@@ -46,5 +46,5 @@ export declare const VERSIONS: {
|
|
|
46
46
|
* Add versions to the given dependencies
|
|
47
47
|
*/
|
|
48
48
|
export declare const withVersions: (deps: (keyof typeof VERSIONS)[]) => {
|
|
49
|
-
[k: string]: "^0.0.60" | "^2.185.0-alpha.0" | "^3.775.0" | "^2.17.0" | "^20.
|
|
49
|
+
[k: string]: "^0.0.60" | "^2.185.0-alpha.0" | "^3.775.0" | "^2.17.0" | "^20.15.0" | "~21.0.3" | "^1.10.2" | "^1.114.27" | "^3.0.94" | "^3.0.928" | "^1.0.38" | "^5.74.3" | "11.0.0" | "^22.13.13" | "^8.10.148" | "^4.2.0" | "^1.0.20" | "^2.1006.0" | "^2.185.0" | "^3.10.3" | "^10.4.2" | "^0.25.1" | "^5.2.5" | "^2.4.0" | "^3.2.0" | "^3.5.3" | "^0.5.21" | "^4.19.3" | "^5.1.4" | "^3.24.2";
|
|
50
50
|
};
|
package/src/utils/versions.js
CHANGED
|
@@ -14,8 +14,8 @@ exports.VERSIONS = {
|
|
|
14
14
|
'@aws-lambda-powertools/logger': '^2.17.0',
|
|
15
15
|
'@aws-lambda-powertools/metrics': '^2.17.0',
|
|
16
16
|
'@aws-lambda-powertools/tracer': '^2.17.0',
|
|
17
|
-
'@nxlv/python': '^20.
|
|
18
|
-
'@nx/devkit': '~
|
|
17
|
+
'@nxlv/python': '^20.15.0',
|
|
18
|
+
'@nx/devkit': '~21.0.3',
|
|
19
19
|
'@modelcontextprotocol/sdk': '^1.10.2',
|
|
20
20
|
'@tanstack/react-router': '^1.114.27',
|
|
21
21
|
'@tanstack/router-plugin': '^1.114.27',
|
package/src/py/fast-api/files/common/constructs/src/app/http-apis/__apiNameKebabCase__.ts.template
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Construct } from 'constructs';
|
|
2
|
-
import * as url from 'url';
|
|
3
|
-
import { HttpApi } from '../../core/http-api.js';
|
|
4
|
-
import { HttpIamAuthorizer } from 'aws-cdk-lib/aws-apigatewayv2-authorizers';
|
|
5
|
-
import { Runtime } from 'aws-cdk-lib/aws-lambda';
|
|
6
|
-
|
|
7
|
-
export class <%= apiNameClassName %> extends HttpApi {
|
|
8
|
-
constructor(scope: Construct, id: string) {
|
|
9
|
-
super(scope, id, {
|
|
10
|
-
defaultAuthorizer: new HttpIamAuthorizer(),
|
|
11
|
-
apiName: '<%= apiNameClassName %>',
|
|
12
|
-
runtime: Runtime.PYTHON_3_12,
|
|
13
|
-
handler: '<%= apiNameSnakeCase %>.main.handler',
|
|
14
|
-
handlerFilePath: url.fileURLToPath(
|
|
15
|
-
new URL(
|
|
16
|
-
'../../../../../../dist/<%= dir %>/bundle',
|
|
17
|
-
import.meta.url
|
|
18
|
-
)
|
|
19
|
-
)
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
package/src/trpc/backend/files/common/constructs/src/app/http-apis/__apiNameKebabCase__.ts.template
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Construct } from 'constructs';
|
|
2
|
-
import * as url from 'url';
|
|
3
|
-
import { HttpApi } from '../../core/http-api.js';
|
|
4
|
-
import { HttpIamAuthorizer } from 'aws-cdk-lib/aws-apigatewayv2-authorizers';
|
|
5
|
-
import { Runtime } from 'aws-cdk-lib/aws-lambda';
|
|
6
|
-
|
|
7
|
-
export class <%= apiNameClassName %> extends HttpApi {
|
|
8
|
-
constructor(scope: Construct, id: string) {
|
|
9
|
-
super(scope, id, {
|
|
10
|
-
defaultAuthorizer: new HttpIamAuthorizer(),
|
|
11
|
-
apiName: '<%= apiNameClassName %>',
|
|
12
|
-
runtime: Runtime.NODEJS_LATEST,
|
|
13
|
-
handler: 'index.handler',
|
|
14
|
-
handlerFilePath: url.fileURLToPath(
|
|
15
|
-
new URL(
|
|
16
|
-
'../../../../../../dist/<%= backendRoot %>/bundle',
|
|
17
|
-
import.meta.url
|
|
18
|
-
)
|
|
19
|
-
)
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { Construct } from 'constructs';
|
|
2
|
-
import { CfnOutput, Duration } from 'aws-cdk-lib';
|
|
3
|
-
import {
|
|
4
|
-
CorsHttpMethod,
|
|
5
|
-
HttpApi as _HttpApi,
|
|
6
|
-
HttpMethod,
|
|
7
|
-
IHttpRouteAuthorizer,
|
|
8
|
-
} from 'aws-cdk-lib/aws-apigatewayv2';
|
|
9
|
-
import { HttpLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';
|
|
10
|
-
import { Code, Function, Runtime, Tracing } from 'aws-cdk-lib/aws-lambda';
|
|
11
|
-
import { Grant, IGrantable } from 'aws-cdk-lib/aws-iam';
|
|
12
|
-
import { RuntimeConfig } from './runtime-config.js';
|
|
13
|
-
|
|
14
|
-
export interface HttpApiProps {
|
|
15
|
-
readonly apiName: string;
|
|
16
|
-
readonly handler: string;
|
|
17
|
-
readonly handlerFilePath: string;
|
|
18
|
-
readonly runtime: Runtime;
|
|
19
|
-
readonly defaultAuthorizer: IHttpRouteAuthorizer;
|
|
20
|
-
readonly allowedOrigins?: string[];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export class HttpApi extends Construct {
|
|
24
|
-
public readonly api: _HttpApi;
|
|
25
|
-
public readonly routerFunction: Function;
|
|
26
|
-
|
|
27
|
-
constructor(scope: Construct, id: string, props: HttpApiProps) {
|
|
28
|
-
super(scope, id);
|
|
29
|
-
|
|
30
|
-
this.routerFunction = new Function(this, `${id}Handler`, {
|
|
31
|
-
timeout: Duration.seconds(30),
|
|
32
|
-
runtime: props.runtime,
|
|
33
|
-
handler: props.handler,
|
|
34
|
-
code: Code.fromAsset(props.handlerFilePath),
|
|
35
|
-
tracing: Tracing.ACTIVE,
|
|
36
|
-
environment: {
|
|
37
|
-
AWS_CONNECTION_REUSE_ENABLED: '1',
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
this.api = new _HttpApi(this, id, {
|
|
42
|
-
corsPreflight: {
|
|
43
|
-
allowOrigins: props.allowedOrigins ?? ['*'],
|
|
44
|
-
allowMethods: [CorsHttpMethod.ANY],
|
|
45
|
-
allowHeaders: [
|
|
46
|
-
'authorization',
|
|
47
|
-
'content-type',
|
|
48
|
-
'x-amz-content-sha256',
|
|
49
|
-
'x-amz-date',
|
|
50
|
-
'x-amz-security-token',
|
|
51
|
-
],
|
|
52
|
-
},
|
|
53
|
-
defaultAuthorizer: props.defaultAuthorizer,
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
this.api.addRoutes({
|
|
57
|
-
path: '/{proxy+}',
|
|
58
|
-
methods: [
|
|
59
|
-
HttpMethod.GET,
|
|
60
|
-
HttpMethod.DELETE,
|
|
61
|
-
HttpMethod.POST,
|
|
62
|
-
HttpMethod.PUT,
|
|
63
|
-
HttpMethod.PATCH,
|
|
64
|
-
HttpMethod.HEAD,
|
|
65
|
-
],
|
|
66
|
-
integration: new HttpLambdaIntegration(
|
|
67
|
-
'RouterIntegration',
|
|
68
|
-
this.routerFunction,
|
|
69
|
-
),
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
new CfnOutput(this, `${props.apiName}Url`, { value: this.api.url! });
|
|
73
|
-
|
|
74
|
-
RuntimeConfig.ensure(this).config.httpApis = {
|
|
75
|
-
...RuntimeConfig.ensure(this).config.httpApis!,
|
|
76
|
-
[props.apiName]: this.api.url!,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public grantInvokeAccess(grantee: IGrantable) {
|
|
81
|
-
Grant.addToPrincipal({
|
|
82
|
-
grantee,
|
|
83
|
-
actions: ['execute-api:Invoke'],
|
|
84
|
-
resourceArns: [this.api.arnForExecuteApi('*', '/*', '*')],
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}
|
package/src/utils/http-api.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addHttpApi = 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 typescript_1 = require("typescript");
|
|
10
|
-
const shared_constructs_constants_1 = require("./shared-constructs-constants");
|
|
11
|
-
const ast_1 = require("./ast");
|
|
12
|
-
const addHttpApi = (tree, apiNameClassName) => {
|
|
13
|
-
const shouldGenerateCoreFastApiConstruct = !tree.exists((0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, shared_constructs_constants_1.SHARED_CONSTRUCTS_DIR, 'src', 'core', 'http-api.ts'));
|
|
14
|
-
if (shouldGenerateCoreFastApiConstruct) {
|
|
15
|
-
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', 'http-api', shared_constructs_constants_1.SHARED_CONSTRUCTS_DIR, 'src', 'core'), (0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, shared_constructs_constants_1.SHARED_CONSTRUCTS_DIR, 'src', 'core'), {}, {
|
|
16
|
-
overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting,
|
|
17
|
-
});
|
|
18
|
-
(0, ast_1.addStarExport)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, shared_constructs_constants_1.SHARED_CONSTRUCTS_DIR, 'src', 'core', 'index.ts'), './http-api.js');
|
|
19
|
-
}
|
|
20
|
-
// Update runtime-config.ts with ApiUrl type and httpApis property
|
|
21
|
-
const runtimeConfigPath = (0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, shared_constructs_constants_1.TYPE_DEFINITIONS_DIR, 'src', 'runtime-config.ts');
|
|
22
|
-
// Check if ApiUrl type exists
|
|
23
|
-
const existingApiUrl = (0, ast_1.query)(tree, runtimeConfigPath, 'TypeAliasDeclaration[name.text="ApiUrl"]');
|
|
24
|
-
// Check if httpApis property exists in IRuntimeConfig
|
|
25
|
-
const existinghttpApis = (0, ast_1.query)(tree, runtimeConfigPath, 'InterfaceDeclaration[name.text="IRuntimeConfig"] PropertySignature[name.text="httpApis"]');
|
|
26
|
-
// Add ApiUrl type if it doesn't exist
|
|
27
|
-
if (existingApiUrl.length === 0) {
|
|
28
|
-
const apiUrlType = typescript_1.factory.createTypeAliasDeclaration([typescript_1.factory.createModifier(typescript_1.SyntaxKind.ExportKeyword)], typescript_1.factory.createIdentifier('ApiUrl'), undefined, typescript_1.factory.createKeywordTypeNode(typescript_1.SyntaxKind.StringKeyword));
|
|
29
|
-
(0, ast_1.prependStatements)(tree, runtimeConfigPath, [apiUrlType]);
|
|
30
|
-
}
|
|
31
|
-
// Add empty httpApis to IRuntimeConfig if it doesn't exist
|
|
32
|
-
if (existinghttpApis.length === 0) {
|
|
33
|
-
(0, ast_1.replace)(tree, runtimeConfigPath, 'InterfaceDeclaration[name.text="IRuntimeConfig"]', (node) => {
|
|
34
|
-
const httpApisProperty = typescript_1.factory.createPropertySignature(undefined, typescript_1.factory.createIdentifier('httpApis'), undefined, typescript_1.factory.createTypeLiteralNode([]));
|
|
35
|
-
return typescript_1.factory.updateInterfaceDeclaration(node, node.modifiers, node.name, node.typeParameters, node.heritageClauses, [...node.members, httpApisProperty]);
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
// Check if apiNameClassName property exists in httpApis
|
|
39
|
-
const existingApiNameProperty = (0, ast_1.query)(tree, runtimeConfigPath, `InterfaceDeclaration[name.text="IRuntimeConfig"] PropertySignature[name.text="httpApis"] TypeLiteral PropertySignature[name.text="${apiNameClassName}"]`);
|
|
40
|
-
// Add apiNameClassName property to httpApis if it doesn't exist
|
|
41
|
-
if (existingApiNameProperty.length === 0) {
|
|
42
|
-
(0, ast_1.replace)(tree, runtimeConfigPath, 'InterfaceDeclaration[name.text="IRuntimeConfig"] PropertySignature[name.text="httpApis"] TypeLiteral', (node) => {
|
|
43
|
-
return typescript_1.factory.createTypeLiteralNode([
|
|
44
|
-
...node.members,
|
|
45
|
-
typescript_1.factory.createPropertySignature(undefined, typescript_1.factory.createIdentifier(apiNameClassName), undefined, typescript_1.factory.createTypeReferenceNode('ApiUrl', undefined)),
|
|
46
|
-
]);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
exports.addHttpApi = addHttpApi;
|
|
51
|
-
//# sourceMappingURL=http-api.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http-api.js","sourceRoot":"","sources":["../../../../../packages/nx-plugin/src/utils/http-api.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCAKoB;AACpB,2CAKoB;AACpB,+EAIuC;AACvC,+BAAyE;AAElE,MAAM,UAAU,GAAG,CAAC,IAAU,EAAE,gBAAwB,EAAE,EAAE;IACjE,MAAM,kCAAkC,GAAG,CAAC,IAAI,CAAC,MAAM,CACrD,IAAA,0BAAiB,EACf,0CAAY,EACZ,mDAAqB,EACrB,KAAK,EACL,MAAM,EACN,aAAa,CACd,CACF,CAAC;IACF,IAAI,kCAAkC,EAAE,CAAC;QACvC,IAAA,sBAAa,EACX,IAAI,EACJ,IAAA,0BAAiB,EACf,SAAS,EACT,OAAO,EACP,UAAU,EACV,mDAAqB,EACrB,KAAK,EACL,MAAM,CACP,EACD,IAAA,0BAAiB,EAAC,0CAAY,EAAE,mDAAqB,EAAE,KAAK,EAAE,MAAM,CAAC,EACrE,EAAE,EACF;YACE,iBAAiB,EAAE,0BAAiB,CAAC,YAAY;SAClD,CACF,CAAC;QACF,IAAA,mBAAa,EACX,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