@tremho/mist-lift 1.0.2-pre-release.4 → 1.0.2-pre-release.5

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.
Files changed (106) hide show
  1. package/build/commands/actions/initQuestions.js +24 -22
  2. package/build/commands/actions/initQuestions.js.map +1 -1
  3. package/build/commands/actions/setupPackageJson.js +4 -4
  4. package/build/commands/actions/setupPackageJson.js.map +1 -1
  5. package/build/commands/build.js +31 -25
  6. package/build/commands/build.js.map +1 -1
  7. package/build/commands/builtin/ApiDocMaker.js +60 -23
  8. package/build/commands/builtin/ApiDocMaker.js.map +1 -1
  9. package/build/commands/builtin/BuiltInHandler.js +6 -6
  10. package/build/commands/builtin/BuiltInHandler.js.map +1 -1
  11. package/build/commands/builtin/DeployBuiltInZip.js +4 -4
  12. package/build/commands/builtin/DeployBuiltInZip.js.map +1 -1
  13. package/build/commands/builtin/StageWebrootZip.js +1 -0
  14. package/build/commands/builtin/StageWebrootZip.js.map +1 -1
  15. package/build/commands/create.js +10 -11
  16. package/build/commands/create.js.map +1 -1
  17. package/build/commands/deploy.js +38 -42
  18. package/build/commands/deploy.js.map +1 -1
  19. package/build/commands/doctor.js +38 -37
  20. package/build/commands/doctor.js.map +1 -1
  21. package/build/commands/help.js +93 -93
  22. package/build/commands/help.js.map +1 -1
  23. package/build/commands/init.js +7 -7
  24. package/build/commands/init.js.map +1 -1
  25. package/build/commands/package.js +50 -51
  26. package/build/commands/package.js.map +1 -1
  27. package/build/commands/publish.js +98 -102
  28. package/build/commands/publish.js.map +1 -1
  29. package/build/commands/settings.js +19 -18
  30. package/build/commands/settings.js.map +1 -1
  31. package/build/commands/start.js +4 -4
  32. package/build/commands/start.js.map +1 -1
  33. package/build/commands/test.js +3 -3
  34. package/build/commands/test.js.map +1 -1
  35. package/build/commands/user.js +1 -1
  36. package/build/commands/user.js.map +1 -1
  37. package/build/expressRoutes/all.js +27 -26
  38. package/build/expressRoutes/all.js.map +1 -1
  39. package/build/expressRoutes/api.js +9 -7
  40. package/build/expressRoutes/api.js.map +1 -1
  41. package/build/expressRoutes/functionBinder.js +38 -36
  42. package/build/expressRoutes/functionBinder.js.map +1 -1
  43. package/build/lib/CaseUtils.js +2 -2
  44. package/build/lib/CaseUtils.js.map +1 -1
  45. package/build/lib/DirectoryUtils.js +4 -3
  46. package/build/lib/DirectoryUtils.js.map +1 -1
  47. package/build/lib/LiftConfig.js +18 -20
  48. package/build/lib/LiftConfig.js.map +1 -1
  49. package/build/lib/LiftVersion.js +17 -12
  50. package/build/lib/LiftVersion.js.map +1 -1
  51. package/build/lib/Tests/fileCompare.test.js +11 -10
  52. package/build/lib/Tests/fileCompare.test.js.map +1 -1
  53. package/build/lib/askQuestion.js +3 -2
  54. package/build/lib/askQuestion.js.map +1 -1
  55. package/build/lib/executeCommand.js +46 -33
  56. package/build/lib/executeCommand.js.map +1 -1
  57. package/build/lib/fileCompare.js +9 -8
  58. package/build/lib/fileCompare.js.map +1 -1
  59. package/build/lib/openAPI/ApiBuildCollector.js +9 -8
  60. package/build/lib/openAPI/ApiBuildCollector.js.map +1 -1
  61. package/build/lib/openAPI/WebrootFileSupport.js +4 -3
  62. package/build/lib/openAPI/WebrootFileSupport.js.map +1 -1
  63. package/build/lib/openAPI/openApiConstruction.js +62 -61
  64. package/build/lib/openAPI/openApiConstruction.js.map +1 -1
  65. package/build/lib/pathResolve.js +4 -4
  66. package/build/lib/pathResolve.js.map +1 -1
  67. package/build/lib/utils.js +5 -4
  68. package/build/lib/utils.js.map +1 -1
  69. package/build/lift.js +14 -15
  70. package/build/lift.js.map +1 -1
  71. package/package.json +2 -1
  72. package/src/commands/actions/initQuestions.ts +112 -112
  73. package/src/commands/actions/setupPackageJson.ts +21 -25
  74. package/src/commands/build.ts +143 -146
  75. package/src/commands/builtin/ApiDocMaker.ts +86 -54
  76. package/src/commands/builtin/BuiltInHandler.ts +31 -35
  77. package/src/commands/builtin/DeployBuiltInZip.ts +15 -17
  78. package/src/commands/builtin/StageWebrootZip.ts +29 -32
  79. package/src/commands/create.ts +40 -47
  80. package/src/commands/deploy.ts +139 -152
  81. package/src/commands/doctor.ts +86 -82
  82. package/src/commands/help.ts +152 -153
  83. package/src/commands/init.ts +37 -39
  84. package/src/commands/package.ts +201 -204
  85. package/src/commands/publish.ts +277 -312
  86. package/src/commands/settings.ts +67 -70
  87. package/src/commands/start.ts +32 -37
  88. package/src/commands/test.ts +15 -16
  89. package/src/commands/user.ts +1 -1
  90. package/src/expressRoutes/all.ts +73 -78
  91. package/src/expressRoutes/api.ts +14 -16
  92. package/src/expressRoutes/functionBinder.ts +144 -151
  93. package/src/lib/CaseUtils.ts +49 -54
  94. package/src/lib/DirectoryUtils.ts +25 -27
  95. package/src/lib/LiftConfig.ts +46 -54
  96. package/src/lib/LiftVersion.ts +69 -77
  97. package/src/lib/Tests/fileCompare.test.ts +27 -26
  98. package/src/lib/askQuestion.ts +12 -13
  99. package/src/lib/executeCommand.ts +40 -33
  100. package/src/lib/fileCompare.ts +46 -37
  101. package/src/lib/openAPI/ApiBuildCollector.ts +36 -36
  102. package/src/lib/openAPI/WebrootFileSupport.ts +15 -17
  103. package/src/lib/openAPI/openApiConstruction.ts +169 -175
  104. package/src/lib/pathResolve.ts +22 -28
  105. package/src/lib/utils.ts +31 -33
  106. package/src/lift.ts +68 -67
@@ -1,350 +1,315 @@
1
1
 
2
2
  import {
3
- LambdaClient,
4
- ListFunctionsCommand, ResourceNotFoundException,
5
- } from "@aws-sdk/client-lambda";
3
+ LambdaClient,
4
+ ListFunctionsCommand
5
+ } from '@aws-sdk/client-lambda'
6
6
  import {
7
- APIGatewayClient,
8
- ImportRestApiCommand,
9
- GetRestApisCommand,
10
- GetResourcesCommand,
11
- DeleteRestApiCommand,
12
- Resource,
13
- PutIntegrationRequest,
14
- PutIntegrationCommand,
15
- GetStageCommand,
16
- NotFoundException,
17
- CreateStageCommand, CreateDeploymentCommand, GetDeploymentsCommand, GetDeploymentCommand
18
- } from "@aws-sdk/client-api-gateway";
19
-
20
- import {getAWSCredentials, getSettings} from "../lib/LiftConfig";
21
-
22
- import {doDeployAsync} from "./deploy";
23
- import * as ac from "ansi-colors"
24
-
25
- import {executeCommand} from "../lib/executeCommand";
26
-
27
- import path from 'path';
28
- import fs, {mkdirSync} from 'fs';
29
- import {all} from "axios";
30
- import {resolvePaths} from "../lib/pathResolve";
31
- import {gatherFunctionDefinitions} from "../lib/openAPI/ApiBuildCollector";
32
- import {delay} from "../lib/utils";
33
- import {addBuiltInDefinitions, MakeBuiltinApiDoc, MakePublicApiDoc} from "./builtin/ApiDocMaker";
34
- import {DeployApiBuiltin, DeployRootFileserves, DeployWebrootBuiltIn} from "./builtin/BuiltInHandler";
35
- import {getProjectName, getProjectVersion} from "../lib/LiftVersion";
36
- import md5 from 'md5';
37
-
38
- let projectPaths:any;
39
-
40
- export async function doPublishAsync(stageName?:string): Promise<number>
41
- {
42
- // let retCode = await doDeployAsync([])
43
- // if(retCode) return retCode
44
- let retCode = 0;
45
-
46
- projectPaths = resolvePaths()
47
-
48
- await publishApi(stageName ?? "Dev")
49
-
50
- return retCode;
7
+ APIGatewayClient,
8
+ ImportRestApiCommand,
9
+ GetRestApisCommand,
10
+ GetResourcesCommand, GetResourcesCommandOutput,
11
+ DeleteRestApiCommand,
12
+ PutIntegrationRequest,
13
+ PutIntegrationCommand,
14
+ CreateDeploymentCommand
15
+ } from '@aws-sdk/client-api-gateway'
16
+
17
+ import { getAWSCredentials, getSettings } from '../lib/LiftConfig'
18
+
19
+ import * as ac from 'ansi-colors'
20
+
21
+ import path from 'path'
22
+ import fs, { mkdirSync } from 'fs'
23
+ import os from 'os'
24
+ import { resolvePaths } from '../lib/pathResolve'
25
+ import { gatherFunctionDefinitions } from '../lib/openAPI/ApiBuildCollector'
26
+ import { delay } from '../lib/utils'
27
+ import { addBuiltInDefinitions, MakeBuiltinApiDoc } from './builtin/ApiDocMaker'
28
+ import { DeployApiBuiltin, DeployRootFileserves, DeployWebrootBuiltIn } from './builtin/BuiltInHandler'
29
+ import { getProjectName, getProjectVersion } from '../lib/LiftVersion'
30
+ import md5 from 'md5'
31
+
32
+ let projectPaths: any
33
+
34
+ export async function doPublishAsync (stageName?: string): Promise<number> {
35
+ // let retCode = await doDeployAsync([])
36
+ // if(retCode) return retCode
37
+ const retCode = 0
38
+
39
+ projectPaths = resolvePaths()
40
+
41
+ await publishApi(stageName ?? 'Dev')
42
+
43
+ return retCode
51
44
  }
52
45
 
53
-
54
- async function publishApi(stageName:string)
55
- {
56
- if(!stageName) stageName = "Dev"
57
- console.log(ac.green.bold(`Publishing Api to ${stageName}`));
58
-
59
- // do the built-in deploys
60
- await DeployWebrootBuiltIn();
61
- await DeployRootFileserves();
62
- await DeployApiBuiltin();
63
-
64
- const projectPaths = resolvePaths();
65
-
66
- // make a private api
67
- const fs = require('fs');
68
- const os = require('os');
69
- const path = require('path');
70
-
71
- let tmpDir;
72
- let apiBytes;
73
- const appPrefix = 'MistLift';
46
+ async function publishApi (
47
+ stageName?: string
48
+ ): Promise<void> {
49
+ if (stageName === undefined) stageName = 'Dev'
50
+ console.log(ac.green.bold(`Publishing Api to ${stageName}`))
51
+
52
+ // do the built-in deploys
53
+ await DeployWebrootBuiltIn()
54
+ await DeployRootFileserves()
55
+ await DeployApiBuiltin()
56
+
57
+ // make a private api
58
+ // const fs = require('fs')
59
+ // const os = require('os')
60
+ // const path = require('path')
61
+
62
+ let tmpDir
63
+ let apiBytes
64
+ const appPrefix = 'MistLift'
65
+ try {
66
+ tmpDir = path.join(os.tmpdir(), appPrefix)
67
+ // console.log("making "+tmpDir)
68
+ mkdirSync(tmpDir, { recursive: true })
69
+
70
+ const yamlFile = path.join(tmpDir, 'papi.yaml')
71
+ await MakeBuiltinApiDoc(yamlFile)
72
+ // console.log("reading "+yamlFile)
73
+ apiBytes = fs.readFileSync(yamlFile)
74
+ } catch (e: any) {
75
+ console.error(ac.red.bold('Error creating temp staging folder ') + (e.message as string))
76
+ throw Error()
77
+ } finally {
74
78
  try {
75
- tmpDir = path.join(os.tmpdir(), appPrefix);
76
- // console.log("making "+tmpDir)
77
- mkdirSync(tmpDir, {recursive:true});
78
-
79
- const yamlFile = path.join(tmpDir, 'papi.yaml')
80
- await MakeBuiltinApiDoc(yamlFile);
81
- // console.log("reading "+yamlFile)
82
- apiBytes = fs.readFileSync(yamlFile)
83
- }
84
- catch (e:any) {
85
- console.error(ac.red.bold("Error creating temp staging folder ")+e.message);
86
- throw Error();
79
+ if (tmpDir !== undefined) {
80
+ fs.rmSync(tmpDir, { recursive: true })
81
+ }
82
+ } catch (e: any) {
83
+ console.error(`An error has occurred while removing the temp folder at ${tmpDir ?? ''}. Please remove it manually. Error: ${(e.message as string)}`)
87
84
  }
88
- finally {
89
- try {
90
- if (tmpDir) {
91
- // console.log("Removing "+tmpDir)
92
- fs.rmSync(tmpDir, { recursive: true });
93
- }
94
- }
95
- catch (e) {
96
- console.error(`An error has occurred while removing the temp folder at ${tmpDir}. Please remove it manually. Error: ${e}`);
97
- }
98
- }
99
-
100
- const client = new APIGatewayClient(getAWSCredentials());
101
-
102
- await RemoveExistingVersions(client)
103
-
104
- const command = new ImportRestApiCommand({
105
- failOnWarnings: false,
106
- body: apiBytes
107
- })
108
- let apiId;
109
- try {
110
- const response = await client.send(command)
111
- const {name, id, rootResourceId, version, warnings} = response
112
- console.log(ac.grey(`\n\nAPI ${name} version ${version} [${id}] schema created`))
113
- apiId = id;
114
- if (warnings?.length) {
115
- console.log(ac.magenta(` with ${warnings.length} warnings`))
116
- for (let warning of warnings) {
117
- console.log(ac.grey.italic(` ${warning}`))
118
- }
85
+ }
86
+
87
+ const client = new APIGatewayClient(getAWSCredentials())
88
+
89
+ await RemoveExistingVersions(client)
90
+
91
+ const command = new ImportRestApiCommand({
92
+ failOnWarnings: false,
93
+ body: apiBytes
94
+ })
95
+ let apiId
96
+ try {
97
+ const response = await client.send(command)
98
+ const { name, id, version, warnings } = response
99
+ console.log(ac.grey(`\n\nAPI ${name ?? ''} version ${version ?? ''} [${id ?? ''}] schema created`))
100
+ apiId = id ?? ''
101
+ if (warnings?.length !== 0) {
102
+ console.log(ac.magenta(` with ${warnings?.length ?? 0} warnings`))
103
+ if (warnings !== undefined) {
104
+ for (const warning of warnings) {
105
+ console.log(ac.grey.italic(` ${warning}`))
119
106
  }
107
+ }
120
108
  }
121
- catch(e:any) {
122
- console.error(ac.bold.red(e.message));
123
- }
124
- var apidoc = new TextDecoder().decode(apiBytes);
125
- // console.log(apidoc)
126
- if(!apiId) return;
127
-
128
- console.log(ac.grey("Continuing with binding..."))
129
- const prereq = await PrequisiteValues(apiId);
130
- const intRequests = prereq.MakeRequests();
131
- await PutIntegrations(intRequests);
132
- await DeployApi(apiId, stageName);
133
- const region = getSettings().awsPreferredRegion;
134
- console.log(ac.green.bold(`\n Successfully deployed to https://${apiId}.execute-api.${region}.amazonaws.com/${stageName}`));
109
+ } catch (e: any) {
110
+ console.error(ac.bold.red(e.message))
111
+ }
112
+ // const apidoc = new TextDecoder().decode(apiBytes)
113
+ // console.log(apidoc)
114
+ if (apiId === '') return
115
+
116
+ console.log(ac.grey('Continuing with binding...'))
117
+ const prereq = await PrequisiteValues(apiId ?? '')
118
+ const intRequests = prereq.MakeRequests()
119
+ await PutIntegrations(intRequests)
120
+ await DeployApi(apiId ?? '', stageName)
121
+ const region = getSettings()?.awsPreferredRegion ?? ''
122
+ console.log(ac.green.bold(`\n Successfully deployed to https://${apiId ?? ''}.execute-api.${region}.amazonaws.com/${stageName}`))
135
123
  }
136
- function findApiName()
137
- {
138
- const infoFile = path.join(projectPaths.functionPath, "apiService.info.json")
139
- const pkgFile = projectPaths.packagePath;
140
- let pkg:any = {};
141
- if(fs.existsSync(pkgFile)) { pkg = JSON.parse(fs.readFileSync(pkgFile).toString()) }
142
- let info:any = {};
143
- if(fs.existsSync(infoFile)) { info = JSON.parse(fs.readFileSync(infoFile).toString()) }
144
-
145
- return info.title ?? pkg.name ?? "API";
124
+ function findApiName (): string {
125
+ const infoFile = path.join(projectPaths.functionPath, 'apiService.info.json')
126
+ const pkgFile = projectPaths.packagePath
127
+ let pkg: any = {}
128
+ if (fs.existsSync(pkgFile)) { pkg = JSON.parse(fs.readFileSync(pkgFile).toString()) }
129
+ let info: any = {}
130
+ if (fs.existsSync(infoFile)) { info = JSON.parse(fs.readFileSync(infoFile).toString()) }
131
+
132
+ return info.title ?? pkg.name ?? 'API'
146
133
  }
147
134
 
148
- function RemoveExistingVersions(client:APIGatewayClient)
149
- {
150
- return new Promise(resolve => {
151
- const ourName = findApiName();
152
- // ClogDebug("looking for name "+ ourName)
153
- const listCommand = new GetRestApisCommand({})
154
- const all:any = [];
155
- client.send(listCommand).then((response:any) => {
156
- // ClogInfo(`There are ${response.items.length} other APIs`)
157
-
158
-
159
- const DeleteMatchingApis = (i: number = 0):Promise<any> => {
160
- if (i >= response.items.length) {
161
- resolve(undefined);
162
- return Promise.resolve(undefined);
163
- }
164
- const item = response.items[i];
165
- if (item.name === ourName) {
166
- // ClogInfo(`Found previous ${ourName}, [${item.id}] -- deleting...`)
167
- const deleteCommand = new DeleteRestApiCommand({
168
- restApiId: item.id
169
- })
170
- return client.send(deleteCommand).then(() => {
171
- delay(5000).then(() => {
172
- console.log(ac.magenta.bold(`Removed previous id ${item.id}`));
173
- return DeleteMatchingApis(++i);
174
- })
175
- })
176
- } else {
177
- return DeleteMatchingApis(++i);
178
- }
179
- }
180
- DeleteMatchingApis();
181
- });
182
- })
135
+ async function RemoveExistingVersions (client: APIGatewayClient): Promise<void> {
136
+ await new Promise(resolve => {
137
+ const ourName = findApiName()
138
+ // ClogDebug("looking for name "+ ourName)
139
+ const listCommand = new GetRestApisCommand({})
140
+ client.send(listCommand).then((response: any) => {
141
+ // ClogInfo(`There are ${response.items.length} other APIs`)
142
+
143
+ const DeleteMatchingApis = async (i: number = 0): Promise<any> => {
144
+ if (i >= response.items.length) {
145
+ resolve(undefined)
146
+ return await Promise.resolve(undefined)
147
+ }
148
+ const item: { name: string, id: string } = response.items[i]
149
+ if (item.name === ourName) {
150
+ // ClogInfo(`Found previous ${ourName}, [${item.id}] -- deleting...`)
151
+ const deleteCommand = new DeleteRestApiCommand({
152
+ restApiId: item.id
153
+ })
154
+ return await client.send(deleteCommand).then(() => {
155
+ delay(5000).then(async () => {
156
+ console.log(ac.magenta.bold(`Removed previous id ${item.id}`))
157
+ return await DeleteMatchingApis(++i)
158
+ }).catch<any>((reason: any) => undefined)
159
+ }).catch<any>((reason: any) => undefined)
160
+ } else {
161
+ return await DeleteMatchingApis(++i)
162
+ }
163
+ }
164
+ DeleteMatchingApis().catch<any>((reason: any) => undefined)
165
+ }).catch<any>((reason: any) => undefined)
166
+ }).catch<any>((reason: any) => undefined)
183
167
  }
184
168
 
185
-
186
169
  class FunctionInfo {
187
- name: string = ""
188
- arn: string = ""
189
- }
190
- class APIInfo {
191
- id: string = ""
192
- parentId: string = ""
193
- path:string = ""
194
- pathPart: string = "";
195
- resourceMethods: object = {}
170
+ name: string = ''
171
+ arn: string = ''
196
172
  }
197
173
 
198
-
199
174
  class PrereqInfo {
200
- requestApiId:string = ""
201
- functions: FunctionInfo[] = []
202
- apis: any[] = [] // Resource + method
203
- defs: any[] = []
204
-
205
- public constructor() {
206
- this.functions = []
207
- this.apis = []
208
- this.defs = []
209
- }
210
-
211
-
212
- public findApi(pathMap:string, allowedMethods:string):any
213
- {
214
- // find the pathmap in the apis list
215
- // console.log("findApi "+pathMap, allowedMethods)
216
- // see that this method exists in method map
217
- for(let api of this.apis) {
218
- if (api?.path === pathMap) {
219
- // console.log("resourceMethods", api.resourceMethods)
220
- const methodList = Object.getOwnPropertyNames(api.resourceMethods);
221
- // ClogTrace("methodList", methodList)
222
- for(let meth of allowedMethods.toUpperCase().split(',')) {
223
- // console.log("meth", meth)
224
- if(methodList.indexOf(meth) !== -1) {
225
- (api as any).method = meth
226
- return api;
227
- }
228
- }
229
- }
175
+ requestApiId: string = ''
176
+ functions: FunctionInfo[] = []
177
+ apis: any[] = [] // Resource + method
178
+ defs: any[] = []
179
+
180
+ public constructor () {
181
+ this.functions = []
182
+ this.apis = []
183
+ this.defs = []
184
+ }
185
+
186
+ public findApi (pathMap: string, allowedMethods: string): any {
187
+ // find the pathmap in the apis list
188
+ // console.log("findApi "+pathMap, allowedMethods)
189
+ // see that this method exists in method map
190
+ for (const api of this.apis) {
191
+ if (api?.path === pathMap) {
192
+ // console.log("resourceMethods", api.resourceMethods)
193
+ const methodList = Object.getOwnPropertyNames(api.resourceMethods)
194
+ // ClogTrace("methodList", methodList)
195
+ for (const meth of allowedMethods.toUpperCase().split(',')) {
196
+ // console.log("meth", meth)
197
+ if (methodList.includes(meth)) {
198
+ (api).method = meth
199
+ return api
200
+ }
230
201
  }
231
- return null;
202
+ }
232
203
  }
233
-
234
- public findARN(name:string):string
235
- {
236
- for(let f of this.functions ?? []) {
237
- let lastus = f.name.lastIndexOf('_');
238
- const fname = f.name.substring(0, lastus);
239
- if(fname.toLowerCase() === name.toLowerCase()) return f.arn;
240
- }
241
- console.log("$$$ Couldn't find "+name+" in ", this.functions)
242
- return "";
204
+ return null
205
+ }
206
+
207
+ public findARN (name: string): string {
208
+ for (const f of this.functions ?? []) {
209
+ const lastus = f.name.lastIndexOf('_')
210
+ const fname = f.name.substring(0, lastus)
211
+ if (fname.toLowerCase() === name.toLowerCase()) return f.arn
243
212
  }
244
-
245
- public MakeRequests():PutIntegrationRequest[]
246
- {
247
- const region = getSettings().awsPreferredRegion;
248
- const out:PutIntegrationRequest[] = [];
249
- for(let d of this.defs) {
250
- const def = (d as any);
251
- const api = this.findApi(def.pathMap, def.allowedMethods)
252
- const arn = this.findARN(def.name)
253
- if(!arn) {
254
- console.log(`>>> No ARN for ${def.name} ${def.pathMap}, ${api.id}`)
255
- }
256
- if(api) {
257
- out.push({
258
- restApiId: this.requestApiId,
259
- resourceId: api.id, // api.parentId
260
- httpMethod: api.method,
261
- integrationHttpMethod: 'POST', // api.method,
262
- type: "AWS_PROXY",
263
- uri: `arn:aws:apigateway:${region}:lambda:path/2015-03-31/functions/${arn}/invocations`,
264
- credentials: "arn:aws:iam::545650260286:role/TBDLambdaExecution2"
265
- })
266
- }
267
-
268
- }
269
- return out;
213
+ console.log("$$$ Couldn't find " + name + ' in ', this.functions)
214
+ return ''
215
+ }
216
+
217
+ public MakeRequests (): PutIntegrationRequest[] {
218
+ const region = getSettings()?.awsPreferredRegion ?? ''
219
+ const out: PutIntegrationRequest[] = []
220
+ for (const d of this.defs) {
221
+ const def = (d)
222
+ const api = this.findApi(def.pathMap, def.allowedMethods)
223
+ const arn = this.findARN(def.name) ?? ''
224
+ if (arn === '') {
225
+ console.log(`>>> No ARN for ${(def.name as string)} ${(def.pathMap as string)}, ${(api.id as string)}`)
226
+ }
227
+ if (api !== undefined) {
228
+ out.push({
229
+ restApiId: this.requestApiId,
230
+ resourceId: api.id, // api.parentId
231
+ httpMethod: api.method,
232
+ integrationHttpMethod: 'POST', // api.method,
233
+ type: 'AWS_PROXY',
234
+ uri: `arn:aws:apigateway:${region}:lambda:path/2015-03-31/functions/${arn}/invocations`,
235
+ credentials: 'arn:aws:iam::545650260286:role/TBDLambdaExecution2'
236
+ })
237
+ }
270
238
  }
239
+ return out
240
+ }
271
241
  }
272
242
 
243
+ async function PrequisiteValues (id: string): Promise<PrereqInfo> {
244
+ const pri = new PrereqInfo()
245
+ const out = await GetFunctionInfo(pri)
246
+ out.defs = gatherFunctionDefinitions()
247
+ addBuiltInDefinitions(out.defs)
248
+ out.requestApiId = id
249
+ await GetMethodResources(id, out)
273
250
 
274
- async function PrequisiteValues(id:string):Promise<PrereqInfo>
275
- {
276
- const pri = new PrereqInfo()
277
- const out = await GetFunctionInfo(pri)
278
- out.defs = gatherFunctionDefinitions()
279
- addBuiltInDefinitions(out.defs)
280
- out.requestApiId = id;
281
- await GetMethodResources(id, out);
282
-
283
- return out;
251
+ return out
284
252
  }
285
253
 
286
- async function GetFunctionInfo(info:PrereqInfo):Promise<PrereqInfo>
287
- {
288
- const client = new LambdaClient(getAWSCredentials());
289
- const listCommand:any = new ListFunctionsCommand({})
290
- const response:any = await client.send(listCommand);
254
+ async function GetFunctionInfo (info: PrereqInfo): Promise<PrereqInfo> {
255
+ const client = new LambdaClient(getAWSCredentials())
256
+ const listCommand: any = new ListFunctionsCommand({})
257
+ const response: any = await client.send(listCommand)
291
258
 
292
- const sfx = "_"+md5((getProjectName()??"")+(getProjectVersion()??""))
259
+ const sfx = '_' + md5((getProjectName() ?? '') + (getProjectVersion()?.toString() ?? ''))
293
260
 
294
- for(let func of response.Functions ?? []) {
295
- if(func.FunctionName.endsWith(sfx)) {
296
- info.functions.push({
297
- name: func.FunctionName ?? "",
298
- arn: func.FunctionArn ?? ""
299
- })
300
- }
261
+ for (const func of response.Functions ?? []) {
262
+ const fName: string = func?.FunctionName ?? ''
263
+ if (fName.endsWith(sfx)) {
264
+ info.functions.push({
265
+ name: func.FunctionName ?? '',
266
+ arn: func.FunctionArn ?? ''
267
+ })
301
268
  }
302
- return info;
303
-
269
+ }
270
+ return info
304
271
  }
305
272
 
306
- async function GetMethodResources(id:string, info:PrereqInfo)
307
- {
308
- const client = new APIGatewayClient(getAWSCredentials())
309
- const listCommand = new GetResourcesCommand({
310
- restApiId: id
311
- });
312
- const response:any|null = await client.send(listCommand);
313
- // ClogInfo("Resources response", response)
314
- if(response?.items) info.apis = response.items;
315
-
316
- return info;
273
+ async function GetMethodResources (
274
+ id: string,
275
+ info: PrereqInfo
276
+ ): Promise<PrereqInfo> {
277
+ const client = new APIGatewayClient(getAWSCredentials())
278
+ const listCommand = new GetResourcesCommand({
279
+ restApiId: id
280
+ })
281
+ const response: GetResourcesCommandOutput = await client.send(listCommand)
282
+ // ClogInfo("Resources response", response)
283
+ if ((response?.items) != null) info.apis = response.items
284
+
285
+ return info
317
286
  }
318
287
 
319
- async function PutIntegrations(integrations:PutIntegrationRequest[])
320
- {
321
- const client = new APIGatewayClient(getAWSCredentials())
322
- for(let input of integrations) {
323
-
324
- try {
325
- const command = new PutIntegrationCommand(input);
326
- const intResp = await client.send(command);
327
- // ClogDebug("integration response", intResp);
328
- await delay(5000);
329
- } catch(e:any) {
330
- console.error("Problem with integration for "+input.uri, {input});
331
- throw e
332
- }
288
+ async function PutIntegrations (integrations: PutIntegrationRequest[]): Promise<void> {
289
+ const client = new APIGatewayClient(getAWSCredentials())
290
+ for (const input of integrations) {
291
+ try {
292
+ const command = new PutIntegrationCommand(input)
293
+ /* const intResp = */ await client.send(command)
294
+ // ClogDebug("integration response", intResp);
295
+ await delay(5000)
296
+ } catch (e: any) {
297
+ console.error('Problem with integration for ' + (input.uri as string), { input })
298
+ throw e
333
299
  }
300
+ }
334
301
  }
335
302
 
336
- async function DeployApi(restApiId:string, stageName:string)
337
- {
338
- try {
339
- const client = new APIGatewayClient(getAWSCredentials())
340
- const command = new CreateDeploymentCommand({
341
- restApiId,
342
- stageName
343
- })
344
- const resp = await client.send(command);
345
- }
346
- catch(e:any) {
347
- console.error(ac.red.bold("Error with deployApi: "+e.message));
348
- throw e;
349
- }
303
+ async function DeployApi (restApiId: string, stageName: string): Promise<void> {
304
+ try {
305
+ const client = new APIGatewayClient(getAWSCredentials())
306
+ const command = new CreateDeploymentCommand({
307
+ restApiId,
308
+ stageName
309
+ })
310
+ await client.send(command)
311
+ } catch (e: any) {
312
+ console.error(ac.red.bold(`Error with deployApi: ${e.message as string}`))
313
+ throw e
314
+ }
350
315
  }