vls-openapi-generator 1.6.1 → 1.8.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.
@@ -41,6 +41,7 @@ require("module-alias/register.js");
41
41
  const path = __importStar(require("path"));
42
42
  const util_1 = require("util");
43
43
  const zod_1 = require("zod");
44
+ const client_cloudformation_1 = require("@aws-sdk/client-cloudformation");
44
45
  const OPENAPI_FILE = path.join(process.cwd(), 'openapi.json');
45
46
  const HANDLERS_DIR = path.join(process.cwd(), 'dist', 'src', 'handlers');
46
47
  const SCHEMAS_DIR = path.join(process.cwd(), 'dist', 'src', 'schemas');
@@ -49,9 +50,20 @@ const generateOpenAPI = async () => {
49
50
  console.info('Generating Open API documentation...');
50
51
  const args = process.argv;
51
52
  const params = {};
52
- for (let i = 2; i < args.length; i += 2) {
53
+ for (let i = 2; i < args.length;) {
53
54
  const key = args[i].replace('--', '');
54
55
  params[key] = args[i + 1];
56
+ if (!params[key]) {
57
+ i++;
58
+ continue;
59
+ }
60
+ if (params[key].startsWith('--')) {
61
+ i++;
62
+ delete params[key];
63
+ }
64
+ else {
65
+ i += 2;
66
+ }
55
67
  }
56
68
  await (0, util_1.promisify)(child_process_1.exec)('rm -rf ./dist');
57
69
  await (0, util_1.promisify)(child_process_1.exec)('npx tsc');
@@ -121,7 +133,43 @@ const generateOpenAPI = async () => {
121
133
  }
122
134
  };
123
135
  }
136
+ const partnerName = params['partner-name'];
137
+ if (partnerName) {
138
+ const developmentURLIndex = existingOpenAPIFile.servers.findIndex((x) => x.url.includes('development'));
139
+ const fetchedDevelopmentURL = await getStackURL(partnerName, 'development');
140
+ if (fetchedDevelopmentURL) {
141
+ existingOpenAPIFile.servers[developmentURLIndex].url = fetchedDevelopmentURL;
142
+ }
143
+ const productionURLIndex = existingOpenAPIFile.servers.findIndex((x) => x.url.includes('production'));
144
+ const fetchedProductionURL = await getStackURL(partnerName, 'production');
145
+ if (fetchedProductionURL) {
146
+ existingOpenAPIFile.servers[productionURLIndex].url = fetchedProductionURL;
147
+ }
148
+ }
124
149
  await fs_1.promises.writeFile(OUTPUT_FILE, JSON.stringify(existingOpenAPIFile, undefined, 4));
125
150
  console.info('Open API documentation generated successfully');
126
151
  };
127
152
  exports.generateOpenAPI = generateOpenAPI;
153
+ async function getStackURL(partnerName, environment) {
154
+ const cloudFormationClient = new client_cloudformation_1.CloudFormationClient();
155
+ const describeStacksCommand = new client_cloudformation_1.DescribeStacksCommand({
156
+ StackName: `${partnerName}-development`
157
+ });
158
+ const result = await cloudFormationClient.send(describeStacksCommand);
159
+ if (!result.Stacks) {
160
+ console.warn(`Base URL was not found with the given environment. Environment will not be updated. Given environment: ${environment}`);
161
+ return;
162
+ }
163
+ for (const cloudFormationStack of result.Stacks) {
164
+ if (!cloudFormationStack.Outputs) {
165
+ console.warn(`Output was not found within the given stack. Environment will not be updated. Given environment: ${environment}`);
166
+ return;
167
+ }
168
+ for (const output of cloudFormationStack.Outputs) {
169
+ if (output.OutputKey !== 'WebEndpoint' || !output.OutputValue) {
170
+ continue;
171
+ }
172
+ return output.OutputValue;
173
+ }
174
+ }
175
+ }
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- export * from './lambda-type';
2
+ export { OpenAPIConfig } from './lambda-type';
package/dist/index.js CHANGED
@@ -1,23 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
- };
17
3
  Object.defineProperty(exports, "__esModule", { value: true });
18
4
  const generate_openapi_1 = require("./generate-openapi");
19
5
  const upload_openapi_js_1 = require("./upload-openapi.js");
20
- __exportStar(require("./lambda-type"), exports);
21
6
  (async () => {
22
7
  try {
23
8
  await (0, generate_openapi_1.generateOpenAPI)();
@@ -2,12 +2,6 @@ export type OpenAPIConfig = {
2
2
  tags: string[];
3
3
  };
4
4
  export type LambdaConfig = {
5
- cron?: {
6
- schedule: string;
7
- input?: Record<string, unknown>;
8
- };
9
- timeout?: number;
10
- memorySize?: number;
11
5
  api?: {
12
6
  method?: 'GET' | 'POST';
13
7
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vls-openapi-generator",
3
- "version": "1.6.1",
3
+ "version": "1.8.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
@@ -16,6 +16,7 @@
16
16
  "description": "VLS Open API Generator",
17
17
  "dependencies": {
18
18
  "@anatine/zod-openapi": "^2.2.7",
19
+ "@aws-sdk/client-cloudformation": "^3.817.0",
19
20
  "axios": "^1.7.9",
20
21
  "module-alias": "^2.2.3",
21
22
  "openapi-to-postmanv2": "^4.25.0"
@@ -7,6 +7,7 @@ import { promisify } from 'util';
7
7
  import { z } from 'zod';
8
8
  import { LambdaConfig, OpenAPIConfig } from './lambda-type';
9
9
  import { OpenAPI } from './openapi-type';
10
+ import { CloudFormationClient, DescribeStacksCommand } from '@aws-sdk/client-cloudformation';
10
11
 
11
12
  const OPENAPI_FILE = path.join(process.cwd(), 'openapi.json');
12
13
  const HANDLERS_DIR = path.join(process.cwd(), 'dist', 'src', 'handlers');
@@ -19,9 +20,21 @@ export const generateOpenAPI = async (): Promise<void> => {
19
20
  const args = process.argv;
20
21
  const params: Record<string, string> = {};
21
22
 
22
- for (let i = 2; i < args.length; i += 2) {
23
+ for (let i = 2; i < args.length; ) {
23
24
  const key = args[i].replace('--', '');
24
25
  params[key] = args[i + 1];
26
+
27
+ if (!params[key]) {
28
+ i++;
29
+ continue;
30
+ }
31
+
32
+ if (params[key].startsWith('--')) {
33
+ i++;
34
+ delete params[key];
35
+ } else {
36
+ i += 2;
37
+ }
25
38
  }
26
39
 
27
40
  await promisify(exec)('rm -rf ./dist');
@@ -123,6 +136,62 @@ export const generateOpenAPI = async (): Promise<void> => {
123
136
  };
124
137
  }
125
138
 
139
+ const partnerName = params['partner-name'];
140
+
141
+ if (partnerName) {
142
+ const developmentURLIndex = existingOpenAPIFile.servers.findIndex((x) => x.url.includes('development'));
143
+
144
+ const fetchedDevelopmentURL = await getStackURL(partnerName, 'development');
145
+
146
+ if (fetchedDevelopmentURL) {
147
+ existingOpenAPIFile.servers[developmentURLIndex].url = fetchedDevelopmentURL;
148
+ }
149
+
150
+ const productionURLIndex = existingOpenAPIFile.servers.findIndex((x) => x.url.includes('production'));
151
+
152
+ const fetchedProductionURL = await getStackURL(partnerName, 'production');
153
+
154
+ if (fetchedProductionURL) {
155
+ existingOpenAPIFile.servers[productionURLIndex].url = fetchedProductionURL;
156
+ }
157
+ }
158
+
126
159
  await fs.writeFile(OUTPUT_FILE, JSON.stringify(existingOpenAPIFile, undefined, 4));
127
160
  console.info('Open API documentation generated successfully');
128
161
  };
162
+
163
+ async function getStackURL(partnerName: string, environment: 'development' | 'production') {
164
+ const cloudFormationClient = new CloudFormationClient();
165
+
166
+ const describeStacksCommand = new DescribeStacksCommand({
167
+ StackName: `${partnerName}-development`
168
+ });
169
+
170
+ const result = await cloudFormationClient.send(describeStacksCommand);
171
+
172
+ if (!result.Stacks) {
173
+ console.warn(
174
+ `Base URL was not found with the given environment. Environment will not be updated. Given environment: ${environment}`
175
+ );
176
+
177
+ return;
178
+ }
179
+
180
+ for (const cloudFormationStack of result.Stacks) {
181
+ if (!cloudFormationStack.Outputs) {
182
+ console.warn(
183
+ `Output was not found within the given stack. Environment will not be updated. Given environment: ${environment}`
184
+ );
185
+
186
+ return;
187
+ }
188
+
189
+ for (const output of cloudFormationStack.Outputs) {
190
+ if (output.OutputKey !== 'WebEndpoint' || !output.OutputValue) {
191
+ continue;
192
+ }
193
+
194
+ return output.OutputValue;
195
+ }
196
+ }
197
+ }
package/src/index.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  import { generateOpenAPI } from './generate-openapi';
4
4
  import { uploadOpenAPI } from './upload-openapi.js';
5
5
 
6
- export * from './lambda-type';
6
+ export { OpenAPIConfig } from './lambda-type';
7
7
 
8
8
  (async () => {
9
9
  try {
@@ -3,12 +3,6 @@ export type OpenAPIConfig = {
3
3
  };
4
4
 
5
5
  export type LambdaConfig = {
6
- cron?: {
7
- schedule: string;
8
- input?: Record<string, unknown>;
9
- };
10
- timeout?: number;
11
- memorySize?: number;
12
6
  api?: {
13
7
  method?: 'GET' | 'POST';
14
8
  };