@goldstack/template-lambda-api 0.3.73

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 (55) hide show
  1. package/README.md +3 -0
  2. package/bin/template +12 -0
  3. package/bin/template.ts +6 -0
  4. package/dist/src/generateLambdaConfig.d.ts +8 -0
  5. package/dist/src/generateLambdaConfig.d.ts.map +1 -0
  6. package/dist/src/generateLambdaConfig.js +51 -0
  7. package/dist/src/generateLambdaConfig.js.map +1 -0
  8. package/dist/src/generateLambdaConfig.spec.d.ts +2 -0
  9. package/dist/src/generateLambdaConfig.spec.d.ts.map +1 -0
  10. package/dist/src/generateLambdaConfig.spec.js +65 -0
  11. package/dist/src/generateLambdaConfig.spec.js.map +1 -0
  12. package/dist/src/templateLambdaApi.d.ts +3 -0
  13. package/dist/src/templateLambdaApi.d.ts.map +1 -0
  14. package/dist/src/templateLambdaApi.js +79 -0
  15. package/dist/src/templateLambdaApi.js.map +1 -0
  16. package/dist/src/templateLambdaApiBuild.d.ts +5 -0
  17. package/dist/src/templateLambdaApiBuild.d.ts.map +1 -0
  18. package/dist/src/templateLambdaApiBuild.js +36 -0
  19. package/dist/src/templateLambdaApiBuild.js.map +1 -0
  20. package/dist/src/templateLambdaApiDeploy.d.ts +10 -0
  21. package/dist/src/templateLambdaApiDeploy.d.ts.map +1 -0
  22. package/dist/src/templateLambdaApiDeploy.js +38 -0
  23. package/dist/src/templateLambdaApiDeploy.js.map +1 -0
  24. package/dist/src/templateLambdaConsts.d.ts +2 -0
  25. package/dist/src/templateLambdaConsts.d.ts.map +1 -0
  26. package/dist/src/templateLambdaConsts.js +5 -0
  27. package/dist/src/templateLambdaConsts.js.map +1 -0
  28. package/dist/src/types/LambdaApiPackage.d.ts +75 -0
  29. package/dist/src/types/LambdaApiPackage.d.ts.map +1 -0
  30. package/dist/src/types/LambdaApiPackage.js +3 -0
  31. package/dist/src/types/LambdaApiPackage.js.map +1 -0
  32. package/dist/tsconfig.tsbuildinfo +1 -0
  33. package/jest.config.js +11 -0
  34. package/package.json +84 -0
  35. package/schemas/deployment-configuration.schema.json +70 -0
  36. package/schemas/deployment.schema.json +156 -0
  37. package/schemas/package-configuration.schema.json +16 -0
  38. package/schemas/package.schema.json +224 -0
  39. package/scripts/generateSchemas.ts +3 -0
  40. package/src/generateLambdaConfig.spec.ts +74 -0
  41. package/src/generateLambdaConfig.ts +61 -0
  42. package/src/templateLambdaApi.ts +82 -0
  43. package/src/templateLambdaApiBuild.ts +33 -0
  44. package/src/templateLambdaApiDeploy.ts +48 -0
  45. package/src/templateLambdaConsts.ts +1 -0
  46. package/src/types/LambdaApiPackage.ts +89 -0
  47. package/testData/$default.ts +0 -0
  48. package/testData/folder/nested.ts +0 -0
  49. package/testData/folder/{pathparam}.ts +0 -0
  50. package/testData/health/$index.ts +0 -0
  51. package/testData/index.ts +0 -0
  52. package/testData/resource/{path}/object.ts +0 -0
  53. package/testData/resource.ts +0 -0
  54. package/tsconfig.generate.json +12 -0
  55. package/tsconfig.json +64 -0
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$ref": "#/definitions/ThisPackageConfiguration",
4
+ "definitions": {
5
+ "ThisPackageConfiguration": {
6
+ "$ref": "#/definitions/PackageConfiguration",
7
+ "description": "Configures this lambda.",
8
+ "title": "Lambda Configuration"
9
+ },
10
+ "PackageConfiguration": {
11
+ "type": "object",
12
+ "description": "Configuration of this package",
13
+ "title": "Configuration"
14
+ }
15
+ }
16
+ }
@@ -0,0 +1,224 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$ref": "#/definitions/ThisPackage",
4
+ "definitions": {
5
+ "ThisPackage": {
6
+ "type": "object",
7
+ "properties": {
8
+ "template": {
9
+ "$ref": "#/definitions/Template"
10
+ },
11
+ "templateVersion": {
12
+ "$ref": "#/definitions/TemplateVersion"
13
+ },
14
+ "name": {
15
+ "$ref": "#/definitions/Name"
16
+ },
17
+ "configuration": {
18
+ "$ref": "#/definitions/ThisPackageConfiguration"
19
+ },
20
+ "deployments": {
21
+ "$ref": "#/definitions/LambdaApiDeployments"
22
+ },
23
+ "$schema": {
24
+ "type": "string"
25
+ }
26
+ },
27
+ "required": [
28
+ "$schema",
29
+ "configuration",
30
+ "deployments",
31
+ "name",
32
+ "template",
33
+ "templateVersion"
34
+ ],
35
+ "additionalProperties": false,
36
+ "description": "A deployment for a lambda API.",
37
+ "title": "Lambda API Package"
38
+ },
39
+ "Template": {
40
+ "type": "string",
41
+ "description": "Name of the template used for creating this package.",
42
+ "title": "Template",
43
+ "pattern": "^[^\\s]*$"
44
+ },
45
+ "TemplateVersion": {
46
+ "type": "string",
47
+ "description": "Latest template version that was applied to this package.",
48
+ "title": "Template Version"
49
+ },
50
+ "Name": {
51
+ "type": "string",
52
+ "description": "Name of this package.",
53
+ "title": "Package Name"
54
+ },
55
+ "ThisPackageConfiguration": {
56
+ "$ref": "#/definitions/PackageConfiguration",
57
+ "description": "Configures this lambda.",
58
+ "title": "Lambda Configuration"
59
+ },
60
+ "PackageConfiguration": {
61
+ "type": "object",
62
+ "description": "Configuration of this package",
63
+ "title": "Configuration"
64
+ },
65
+ "LambdaApiDeployments": {
66
+ "type": "array",
67
+ "items": {
68
+ "$ref": "#/definitions/ThisDeployment"
69
+ },
70
+ "description": "Places where the lambda should be deployed to.",
71
+ "title": "Deployments"
72
+ },
73
+ "ThisDeployment": {
74
+ "type": "object",
75
+ "properties": {
76
+ "name": {
77
+ "$ref": "#/definitions/DeploymentName"
78
+ },
79
+ "configuration": {
80
+ "$ref": "#/definitions/ThisDeploymentConfiguration"
81
+ },
82
+ "terraformVariables": {
83
+ "$ref": "#/definitions/TerraformVariables"
84
+ },
85
+ "tfStateKey": {
86
+ "$ref": "#/definitions/TerraformStateKey"
87
+ },
88
+ "awsRegion": {
89
+ "$ref": "#/definitions/AWSDeploymentRegion"
90
+ },
91
+ "awsUser": {
92
+ "$ref": "#/definitions/AWSUserName"
93
+ }
94
+ },
95
+ "required": [
96
+ "awsRegion",
97
+ "awsUser",
98
+ "configuration",
99
+ "name"
100
+ ]
101
+ },
102
+ "DeploymentName": {
103
+ "type": "string",
104
+ "description": "Identifier for this deployment. No spaces allowed in name.",
105
+ "title": "Deployment Name",
106
+ "pattern": "^[^\\s]*$"
107
+ },
108
+ "ThisDeploymentConfiguration": {
109
+ "type": "object",
110
+ "properties": {
111
+ "lambdaNamePrefix": {
112
+ "type": "string",
113
+ "description": "The prefix to be used for names of the generated lambdas for the API endpoints.",
114
+ "title": "Lambda Name Prefix",
115
+ "pattern": "^[A-Za-z0-9-_]*$"
116
+ },
117
+ "apiDomain": {
118
+ "$ref": "#/definitions/APIDomain"
119
+ },
120
+ "hostedZoneDomain": {
121
+ "$ref": "#/definitions/HostedZoneDomain"
122
+ },
123
+ "cors": {
124
+ "$ref": "#/definitions/CorsHeader"
125
+ },
126
+ "lambdas": {
127
+ "$ref": "#/definitions/LambdaRoutesConfig"
128
+ }
129
+ },
130
+ "required": [
131
+ "apiDomain",
132
+ "hostedZoneDomain",
133
+ "lambdas"
134
+ ]
135
+ },
136
+ "APIDomain": {
137
+ "type": "string",
138
+ "description": "The domain name that the API should be deployed to (e.g. api.mysite.com)",
139
+ "title": "API Domain",
140
+ "pattern": "^[^\\s]*"
141
+ },
142
+ "HostedZoneDomain": {
143
+ "type": "string",
144
+ "description": "The domain name of the Route 53 hosted zone that the domain for this API should be added to.",
145
+ "title": "Hosted Zone Domain",
146
+ "pattern": "^[^\\s]*"
147
+ },
148
+ "CorsHeader": {
149
+ "type": "string",
150
+ "description": "Optional URL for an UI that should be allowed to access this server.",
151
+ "title": "CORS Header",
152
+ "pattern": "^[^\\s]*"
153
+ },
154
+ "LambdaRoutesConfig": {
155
+ "type": "object",
156
+ "additionalProperties": {
157
+ "$ref": "#/definitions/LambdaRouteConfig"
158
+ }
159
+ },
160
+ "LambdaRouteConfig": {
161
+ "type": "object",
162
+ "properties": {
163
+ "function_name": {
164
+ "type": "string"
165
+ }
166
+ },
167
+ "required": [
168
+ "function_name"
169
+ ],
170
+ "additionalProperties": false
171
+ },
172
+ "TerraformVariables": {
173
+ "type": "array",
174
+ "items": {
175
+ "$ref": "#/definitions/TerraformVariable"
176
+ },
177
+ "description": "Define which of the deployment variables will be made available for terraform.",
178
+ "title": "Terraform Variables"
179
+ },
180
+ "TerraformVariable": {
181
+ "type": "string",
182
+ "description": "Name of the property that should be converted into a Terraform variable.",
183
+ "title": "Terraform Variable"
184
+ },
185
+ "TerraformStateKey": {
186
+ "type": "string",
187
+ "description": "Key used for Terraform state persisted in Terraform state bucket.\n\nWill be auto-generated upon first deployment if not provided.",
188
+ "title": "Terraform State Key"
189
+ },
190
+ "AWSDeploymentRegion": {
191
+ "type": "string",
192
+ "enum": [
193
+ "us-east-1",
194
+ "us-east-2",
195
+ "us-west-1",
196
+ "us-west-2",
197
+ "af-south-1",
198
+ "ap-east-1",
199
+ "ap-south-1",
200
+ "ap-northeast-3",
201
+ "ap-northeast-2",
202
+ "ap-southeast-1",
203
+ "ap-southeast-2",
204
+ "ap-northeast-1",
205
+ "ca-central-1",
206
+ "eu-central-1",
207
+ "eu-west-1",
208
+ "eu-west-2",
209
+ "eu-south-1",
210
+ "eu-west-3",
211
+ "eu-north-1",
212
+ "me-south-1",
213
+ "sa-east-1"
214
+ ],
215
+ "description": "AWS region that infrastructure should be deployed to.",
216
+ "title": "AWS Deployment Region"
217
+ },
218
+ "AWSUserName": {
219
+ "type": "string",
220
+ "description": "Name of the AWS user that is used to perform the deployment.",
221
+ "title": "AWS User Name"
222
+ }
223
+ }
224
+ }
@@ -0,0 +1,3 @@
1
+ import { run } from '@goldstack/utils-package-config-generate';
2
+
3
+ run(process.argv);
@@ -0,0 +1,74 @@
1
+ import { readLambdaConfig } from '@goldstack/utils-aws-lambda';
2
+ import assert from 'assert';
3
+ import {
4
+ generateFunctionName,
5
+ generateLambdaConfig,
6
+ } from './generateLambdaConfig';
7
+ import { LambdaApiDeployment } from './templateLambdaApi';
8
+ import { getOutDirForLambda } from './templateLambdaApiBuild';
9
+
10
+ const dummyDeployment: LambdaApiDeployment = {
11
+ awsRegion: 'ap-east-1',
12
+ awsUser: 'dummy',
13
+ configuration: {
14
+ lambdaNamePrefix: 'test-lambdas',
15
+ apiDomain: 'domain',
16
+ hostedZoneDomain: 'domain',
17
+ lambdas: {},
18
+ },
19
+ name: 'test',
20
+ };
21
+
22
+ describe('Generate Lambda config', () => {
23
+ const routesConfig = readLambdaConfig('./testData');
24
+ const config = generateLambdaConfig(dummyDeployment, routesConfig);
25
+ test('Should render config for Terraform', () => {
26
+ assert(config['$default'].function_name);
27
+ assert(
28
+ config['ANY /folder/nested'].function_name.indexOf(
29
+ dummyDeployment.configuration.lambdaNamePrefix || 'fail'
30
+ ) !== -1
31
+ );
32
+ });
33
+ test('Should determine correct output dirs for dist', () => {
34
+ const nestedRoute = routesConfig.find((e) => e.path === '/folder/nested');
35
+ assert(nestedRoute);
36
+ const dir = getOutDirForLambda(nestedRoute);
37
+ assert(dir === './distLambda/folder/nested');
38
+ });
39
+ test('Should determine path parametmers for file names', () => {
40
+ const nestedRoute = routesConfig.find(
41
+ (e) => e.path === '/folder/{pathparam}'
42
+ );
43
+ assert(nestedRoute);
44
+ const functionName = generateFunctionName(dummyDeployment, nestedRoute);
45
+ assert(functionName.indexOf('folder') !== -1);
46
+ assert(functionName.indexOf('{') === -1);
47
+ assert(functionName.indexOf('}') === -1);
48
+ });
49
+ test('Should determine path parametmers for folder names', () => {
50
+ const nestedRoute = routesConfig.find(
51
+ (e) => e.path === '/resource/{path}/object'
52
+ );
53
+ assert(nestedRoute);
54
+ const functionName = generateFunctionName(dummyDeployment, nestedRoute);
55
+ assert(functionName.indexOf('object') !== -1);
56
+ assert(functionName.indexOf('resource') !== -1);
57
+ assert(functionName.indexOf('{') === -1);
58
+ assert(functionName.indexOf('}') === -1);
59
+ });
60
+ test('Should provide a correct path for a nested index file', () => {
61
+ const nestedRoute = routesConfig.find((e) => e.path === '/health');
62
+ assert(nestedRoute);
63
+
64
+ const functionName = generateFunctionName(dummyDeployment, nestedRoute);
65
+ assert(functionName.indexOf('health') !== -1);
66
+ });
67
+ test('Should provide a correct path for a file in the API root', () => {
68
+ const nestedRoute = routesConfig.find((e) => e.path === '/resource');
69
+ assert(nestedRoute);
70
+
71
+ const functionName = generateFunctionName(dummyDeployment, nestedRoute);
72
+ assert(functionName.match(/resource/g)?.length === 1);
73
+ });
74
+ });
@@ -0,0 +1,61 @@
1
+ import { LambdaConfig } from '@goldstack/utils-aws-lambda';
2
+ import {
3
+ LambdaRoutesConfig,
4
+ LambdaApiDeployment,
5
+ } from './types/LambdaApiPackage';
6
+
7
+ const santiseFunctionName = (input: string): string => {
8
+ return input
9
+ .replace(/\//g, '-')
10
+ .replace(/\$/g, '_')
11
+ .replace(/\{/g, '_')
12
+ .replace(/\}/g, '_')
13
+ .replace(/\+/g, '_')
14
+ .replace(/[^\w\-_]/gi, '_');
15
+ };
16
+
17
+ /**
18
+ * Generates a valid function name for a route
19
+ */
20
+ export const generateFunctionName = (
21
+ deployment: LambdaApiDeployment,
22
+ config: LambdaConfig
23
+ ): string => {
24
+ let name = config.name;
25
+ if (name === '$default') {
26
+ // '$' is not a valid character in a lambda function name
27
+ name = 'default_gateway_lambda_2281';
28
+ }
29
+ if (name === '$index') {
30
+ name = 'index_root_lambda_4423';
31
+ }
32
+ name = santiseFunctionName(name);
33
+
34
+ let pathPrefix = '';
35
+ const segments = config.path.split('/');
36
+ if (segments.length === 2 && name === 'index_root_lambda_4423') {
37
+ pathPrefix = `${segments[1]}-`;
38
+ }
39
+ if (segments.length > 2) {
40
+ segments.shift(); // remove first element since path starts with '/' and thus the first element is always ''
41
+ segments.pop(); // remove the last element since that is the name of the function in the route
42
+ pathPrefix = santiseFunctionName(segments.join('-'));
43
+ pathPrefix = `${pathPrefix}-`;
44
+ }
45
+
46
+ name = `${pathPrefix}${name}`;
47
+ name = (`${deployment.configuration.lambdaNamePrefix}-` || '') + name;
48
+ return name;
49
+ };
50
+
51
+ export const generateLambdaConfig = (
52
+ deployment: LambdaApiDeployment,
53
+ config: LambdaConfig[]
54
+ ): LambdaRoutesConfig => {
55
+ return config.reduce((last, curr) => {
56
+ last[curr.route] = {
57
+ function_name: generateFunctionName(deployment, curr),
58
+ };
59
+ return last;
60
+ }, {});
61
+ };
@@ -0,0 +1,82 @@
1
+ import { buildCli, buildDeployCommands } from '@goldstack/utils-package';
2
+ import { wrapCli } from '@goldstack/utils-cli';
3
+ import { infraCommands } from '@goldstack/utils-terraform';
4
+ import { deployCli } from './templateLambdaApiDeploy';
5
+ import { terraformAwsCli } from '@goldstack/utils-terraform-aws';
6
+ import { PackageConfig } from '@goldstack/utils-package-config';
7
+ import { writePackageConfig } from '@goldstack/utils-package';
8
+ export * from './types/LambdaApiPackage';
9
+ import yargs from 'yargs';
10
+ import fs from 'fs';
11
+ import {
12
+ LambdaApiPackage,
13
+ LambdaApiDeployment,
14
+ } from './types/LambdaApiPackage';
15
+ import { readLambdaConfig } from '@goldstack/utils-aws-lambda';
16
+ import { generateLambdaConfig } from './generateLambdaConfig';
17
+ import { defaultRoutesPath } from './templateLambdaConsts';
18
+ import { buildLambdas } from './templateLambdaApiBuild';
19
+
20
+ export const run = async (args: string[]): Promise<void> => {
21
+ await wrapCli(async () => {
22
+ const argv = buildCli({
23
+ yargs,
24
+ deployCommands: buildDeployCommands(),
25
+ infraCommands: infraCommands(),
26
+ })
27
+ .command('build [deployment]', 'Build all lambdas', () => {
28
+ return yargs.positional('deployment', {
29
+ type: 'string',
30
+ describe: 'Name of the deployment this command should be applied to',
31
+ default: '',
32
+ });
33
+ })
34
+ .help().argv;
35
+
36
+ const packageConfig = new PackageConfig<
37
+ LambdaApiPackage,
38
+ LambdaApiDeployment
39
+ >({
40
+ packagePath: './',
41
+ });
42
+
43
+ const config = packageConfig.getConfig();
44
+
45
+ // update routes
46
+ if (!fs.existsSync('./src/routes')) {
47
+ throw new Error(
48
+ 'Please specify lambda function handlers in ./src/routes so that API Gateway route configuration can be generated.'
49
+ );
50
+ }
51
+ const lambdaRoutes = readLambdaConfig(defaultRoutesPath);
52
+ config.deployments = config.deployments.map((e) => {
53
+ const lambdasConfigs = generateLambdaConfig(e, lambdaRoutes);
54
+ e.configuration.lambdas = lambdasConfigs;
55
+ return e;
56
+ });
57
+ writePackageConfig(config);
58
+
59
+ const command = argv._[0];
60
+ const [, , , ...opArgs] = args;
61
+
62
+ if (command === 'infra') {
63
+ await terraformAwsCli(opArgs);
64
+ return;
65
+ }
66
+
67
+ if (command === 'build') {
68
+ await buildLambdas(lambdaRoutes);
69
+ return;
70
+ }
71
+
72
+ if (command === 'deploy') {
73
+ await deployCli(
74
+ packageConfig.getDeployment(config, opArgs[0]),
75
+ lambdaRoutes
76
+ );
77
+ return;
78
+ }
79
+
80
+ throw new Error('Unknown command: ' + command);
81
+ });
82
+ };
@@ -0,0 +1,33 @@
1
+ import { build } from 'esbuild';
2
+ import { pnpPlugin } from '@yarnpkg/esbuild-plugin-pnp';
3
+ import { LambdaConfig } from '@goldstack/utils-aws-lambda';
4
+ import { mkdir } from '@goldstack/utils-sh';
5
+ import { defaultRoutesPath } from './templateLambdaConsts';
6
+
7
+ export const getOutDirForLambda = (config: LambdaConfig): string => {
8
+ if (config.path === '$default') {
9
+ return `./distLambda/${config.path}`;
10
+ }
11
+ return `./distLambda${config.path}`;
12
+ };
13
+
14
+ export const getOutFileForLambda = (config: LambdaConfig): string => {
15
+ return `${getOutDirForLambda(config)}/lambda.js`;
16
+ };
17
+
18
+ export const buildLambdas = async (configs: LambdaConfig[]): Promise<void> => {
19
+ for await (const config of configs) {
20
+ mkdir('-p', getOutDirForLambda(config));
21
+ await build({
22
+ plugins: [pnpPlugin()],
23
+ bundle: true,
24
+ entryPoints: [`${defaultRoutesPath}/${config.relativeFilePath}`],
25
+ external: ['aws-sdk'],
26
+ minify: true,
27
+ format: 'cjs',
28
+ target: 'node12.0',
29
+ sourcemap: true,
30
+ outfile: getOutFileForLambda(config),
31
+ });
32
+ }
33
+ };
@@ -0,0 +1,48 @@
1
+ import { LambdaApiDeployment } from './types/LambdaApiPackage';
2
+ import { getAWSUser } from '@goldstack/infra-aws';
3
+ import { deployFunction, LambdaConfig } from '@goldstack/utils-aws-lambda';
4
+
5
+ import { readLambdaConfig } from '@goldstack/utils-aws-lambda';
6
+ import { defaultRoutesPath } from './templateLambdaConsts';
7
+
8
+ import { mkdir } from '@goldstack/utils-sh';
9
+ import { generateFunctionName } from './generateLambdaConfig';
10
+ import { getOutDirForLambda } from './templateLambdaApiBuild';
11
+
12
+ interface DeployLambdaParams {
13
+ deployment: LambdaApiDeployment;
14
+ config: LambdaConfig[];
15
+ }
16
+
17
+ export const deployLambdas = async (
18
+ params: DeployLambdaParams
19
+ ): Promise<void> => {
20
+ const lambdaConfig = readLambdaConfig(defaultRoutesPath);
21
+
22
+ const operations = lambdaConfig.map(async (config) => {
23
+ const functionName = generateFunctionName(params.deployment, config);
24
+ console.log(`[${functionName}]: Starting deployment`);
25
+ const functionDir = getOutDirForLambda(config);
26
+ mkdir('-p', functionDir);
27
+ const targetArchive = `${functionDir}/${config.name}.zip`;
28
+ await deployFunction({
29
+ targetArchiveName: targetArchive,
30
+ lambdaPackageDir: functionDir,
31
+ awsCredentials: await getAWSUser(params.deployment.awsUser),
32
+ region: params.deployment.awsRegion,
33
+ functionName,
34
+ });
35
+ console.log(`[${functionName}]: Deployment completed`);
36
+ });
37
+ await Promise.all(operations);
38
+ };
39
+
40
+ export const deployCli = async (
41
+ deployment: LambdaApiDeployment,
42
+ config: LambdaConfig[]
43
+ ): Promise<void> => {
44
+ await deployLambdas({
45
+ deployment,
46
+ config,
47
+ });
48
+ };
@@ -0,0 +1 @@
1
+ export const defaultRoutesPath = './src/routes';
@@ -0,0 +1,89 @@
1
+ import { AWSDeployment } from '@goldstack/infra-aws';
2
+ import { TerraformDeployment } from '@goldstack/utils-terraform';
3
+ import { Deployment, DeploymentConfiguration } from '@goldstack/infra';
4
+ import { Package, Configuration } from '@goldstack/utils-package';
5
+
6
+ /**
7
+ * The prefix to be used for names of the generated lambdas for the API endpoints.
8
+ *
9
+ * @title Lambda Name Prefix
10
+ * @pattern ^[A-Za-z0-9-_]*$
11
+ */
12
+ type LambdaNamePrefix = string;
13
+
14
+ /**
15
+ * The domain name that the API should be deployed to (e.g. api.mysite.com)
16
+ *
17
+ * @title API Domain
18
+ * @pattern ^[^\s]*
19
+ */
20
+ export type APIDomain = string;
21
+
22
+ /**
23
+ * The domain name of the Route 53 hosted zone that the domain for this API should be added to.
24
+ *
25
+ * @title Hosted Zone Domain
26
+ * @pattern ^[^\s]*
27
+ */
28
+ export type HostedZoneDomain = string;
29
+
30
+ /**
31
+ * Optional URL for an UI that should be allowed to access this server.
32
+ *
33
+ * @title CORS Header
34
+ * @pattern ^[^\s]*
35
+ */
36
+ export type CorsHeader = string;
37
+
38
+ export interface LambdaRouteConfig {
39
+ function_name: string;
40
+ }
41
+
42
+ export type LambdaRoutesConfig = {
43
+ [key: string]: LambdaRouteConfig;
44
+ };
45
+
46
+ export interface ThisDeploymentConfiguration extends DeploymentConfiguration {
47
+ lambdaNamePrefix?: LambdaNamePrefix;
48
+ apiDomain: APIDomain;
49
+ hostedZoneDomain: HostedZoneDomain;
50
+ cors?: CorsHeader;
51
+ lambdas: LambdaRoutesConfig;
52
+ }
53
+
54
+ export interface ThisDeployment
55
+ extends Deployment,
56
+ AWSDeployment,
57
+ TerraformDeployment {
58
+ configuration: ThisDeploymentConfiguration;
59
+ }
60
+
61
+ /**
62
+ * Places where the lambda should be deployed to.
63
+ *
64
+ * @title Deployments
65
+ */
66
+ export type LambdaApiDeployments = ThisDeployment[];
67
+
68
+ /**
69
+ * Configures this lambda.
70
+ *
71
+ * @title Lambda Configuration
72
+ *
73
+ */
74
+ export type ThisPackageConfiguration = Configuration;
75
+
76
+ /**
77
+ * A deployment for a lambda API.
78
+ *
79
+ * @title Lambda API Package
80
+ */
81
+ export interface ThisPackage extends Package {
82
+ configuration: ThisPackageConfiguration;
83
+ deployments: LambdaApiDeployments;
84
+ }
85
+
86
+ export { ThisDeploymentConfiguration as LambdaApiDeploymentConfiguration };
87
+ export { ThisDeployment as LambdaApiDeployment };
88
+ export { ThisPackageConfiguration as LambdaApiConfiguration };
89
+ export { ThisPackage as LambdaApiPackage };
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "include": [
4
+ "./src/**/*"
5
+ ],
6
+ "compilerOptions": {
7
+ "incremental": false,
8
+ "declarationMap": false,
9
+ "outDir": "dist",
10
+ "baseUrl": "."
11
+ }
12
+ }