diff --git a/.vscode/settings.json b/.vscode/settings.json index d464c1e..b5c6cfc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "eslint.workingDirectories": [ "./services/api1", + "./services/api2", ] -} \ No newline at end of file +} diff --git a/README.md b/README.md index 5690e3e..d7707cd 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Each package is 100% [TypeScript](https://www.typescriptlang.org/). ### Services - `api1`: serverless service to say hello. Run `pnpm dev` to run the offline in offline mode. +- `api2`: serverless service to say ciao. Run `pnpm dev` to run the offline in offline mode. ### Utilities diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 91744b0..bf9a2f6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,8 +9,8 @@ importers: turbo: latest devDependencies: eslint-config-custom: link:packages/eslint-config-custom - prettier: 2.6.2 - turbo: 1.2.16 + prettier: 2.8.3 + turbo: 1.7.0 packages/eslint-config-custom: specifiers: @@ -88,6 +88,41 @@ importers: tsconfig-paths: 4.0.0 typescript: 4.7.3 + services/api2: + specifiers: + '@serverless/typescript': ^3.18.0 + '@types/aws-lambda': ^8.10.98 + '@types/node': ^17.0.40 + aws-lambda: ^1.0.7 + esbuild: ^0.14.42 + eslint: ^8.14.0 + helpers: workspace:* + jest: ^28.0.3 + serverless: ^3.19.0 + serverless-esbuild: ^1.30.0 + serverless-offline: ^8.8.0 + ts-node: ^10.8.1 + tsconfig: workspace:* + tsconfig-paths: ^4.0.0 + typescript: ^4.7.3 + dependencies: + aws-lambda: 1.0.7 + helpers: link:../../packages/helpers + devDependencies: + '@serverless/typescript': 3.18.0 + '@types/aws-lambda': 8.10.98 + '@types/node': 17.0.40 + esbuild: 0.14.42 + eslint: 8.14.0 + jest: 28.1.0_2cdaztp7eenh32anyybg24itfi + serverless: 3.19.0 + serverless-esbuild: 1.30.0_esbuild@0.14.42 + serverless-offline: 8.8.0_serverless@3.19.0 + ts-node: 10.8.1_fvkldoeufjjq5mlpfdkzhuqzdy + tsconfig: link:../../packages/tsconfig + tsconfig-paths: 4.0.0 + typescript: 4.7.3 + packages: /2-thenable/1.0.0: @@ -736,14 +771,14 @@ packages: '@jest/test-result': 28.1.0 '@jest/transform': 28.1.0 '@jest/types': 28.1.0 - '@types/node': 17.0.30 + '@types/node': 17.0.40 ansi-escapes: 4.3.2 chalk: 4.1.2 ci-info: 3.3.0 exit: 0.1.2 graceful-fs: 4.2.10 jest-changed-files: 28.0.2 - jest-config: 28.1.0_ddoydpugwy6bqvanrmveqeliw4 + jest-config: 28.1.0_2cdaztp7eenh32anyybg24itfi jest-haste-map: 28.1.0 jest-message-util: 28.1.0 jest-regex-util: 28.0.2 @@ -1273,10 +1308,6 @@ packages: resolution: {integrity: sha512-/THyiqyQAP9AfARo4pF+aCGcyiQ94tX/Is2I7HofNRqoYLgN1PBoOWu2/zTA5zMxzP5EFutMtWtGAFRKUe961Q==} dev: true - /@types/node/17.0.30: - resolution: {integrity: sha512-oNBIZjIqyHYP8VCNAV9uEytXVeXG2oR0w9lgAXro20eugRQfY002qr3CUl6BAe+Yf/z3CRjPdz27Pu6WWtuSRw==} - dev: true - /@types/node/17.0.40: resolution: {integrity: sha512-UXdBxNGqTMtm7hCwh9HtncFVLrXoqA3oJW30j6XWp5BH/wu3mVeaxo7cq5benFdBw34HB3XDT2TRPI7rXZ+mDg==} dev: true @@ -4089,46 +4120,6 @@ packages: - supports-color dev: true - /jest-config/28.1.0_ddoydpugwy6bqvanrmveqeliw4: - resolution: {integrity: sha512-aOV80E9LeWrmflp7hfZNn/zGA4QKv/xsn2w8QCBP0t0+YqObuCWTSgNbHJ0j9YsTuCO08ZR/wsvlxqqHX20iUA==} - engines: {node: ^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0} - peerDependencies: - '@types/node': '*' - ts-node: '>=9.0.0' - peerDependenciesMeta: - '@types/node': - optional: true - ts-node: - optional: true - dependencies: - '@babel/core': 7.18.2 - '@jest/test-sequencer': 28.1.0 - '@jest/types': 28.1.0 - '@types/node': 17.0.30 - babel-jest: 28.1.0_@babel+core@7.18.2 - chalk: 4.1.2 - ci-info: 3.3.0 - deepmerge: 4.2.2 - glob: 7.2.0 - graceful-fs: 4.2.10 - jest-circus: 28.1.0 - jest-environment-node: 28.1.0 - jest-get-type: 28.0.2 - jest-regex-util: 28.0.2 - jest-resolve: 28.1.0 - jest-runner: 28.1.0 - jest-util: 28.1.0 - jest-validate: 28.1.0 - micromatch: 4.0.5 - parse-json: 5.2.0 - pretty-format: 28.1.0 - slash: 3.0.0 - strip-json-comments: 3.1.1 - ts-node: 10.8.1_fvkldoeufjjq5mlpfdkzhuqzdy - transitivePeerDependencies: - - supports-color - dev: true - /jest-diff/28.1.0: resolution: {integrity: sha512-8eFd3U3OkIKRtlasXfiAQfbovgFgRDb0Ngcs2E+FMeBZ4rUezqIaGjuyggJBp+llosQXNEWofk/Sz4Hr5gMUhA==} engines: {node: ^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0} @@ -5341,8 +5332,8 @@ packages: engines: {node: '>=4'} dev: true - /prettier/2.6.2: - resolution: {integrity: sha512-PkUpF+qoXTqhOeWL9fu7As8LXsIUZ1WYaJiY/a7McAQzxjk82OF0tibkFXVCDImZtWxbvojFjerkiLb0/q8mew==} + /prettier/2.8.3: + resolution: {integrity: sha512-tJ/oJ4amDihPoufT5sM0Z1SKEuKay8LfVAMlbbhnnkvt6BUserZylqo2PN+p9KeljLr0OHa2rXHU1T8reeoTrw==} engines: {node: '>=10.13.0'} hasBin: true dev: true @@ -6294,128 +6285,65 @@ packages: typescript: 4.7.3 dev: true - /turbo-darwin-64/1.2.16: - resolution: {integrity: sha512-dyitLQJdH3uLVdlH9jAkP4LqEO/K+wOXjUqOzjTciRLjQPzmsNY60/bmFHODADK4eBBl1nxbtn7tmmoT4vS1qA==} + /turbo-darwin-64/1.7.0: + resolution: {integrity: sha512-hSGAueSf5Ko8J67mpqjpt9FsP6ePn1nMcl7IVPoJq5dHsgX3anCP/BPlexJ502bNK+87DDyhQhJ/LPSJXKrSYQ==} cpu: [x64] os: [darwin] requiresBuild: true dev: true optional: true - /turbo-darwin-arm64/1.2.16: - resolution: {integrity: sha512-Ex6uM4HU7rGXdhvJMpzNpp6qxglJ98nWeIi5qR/lBXHLjK3UCvSW8BEALArUJYJTXS9FZBq1a5LowFqXYsfDcA==} + /turbo-darwin-arm64/1.7.0: + resolution: {integrity: sha512-BLLOW5W6VZxk5+0ZOj5AO1qjM0P5isIgjbEuyAl8lHZ4s9antUbY4CtFrspT32XxPTYoDl4UjviPMcSsbcl3WQ==} cpu: [arm64] os: [darwin] requiresBuild: true dev: true optional: true - /turbo-freebsd-64/1.2.16: - resolution: {integrity: sha512-onRGKMvog8B3XDssSBIAg+FrEq9pcBoAybP7bpi/uYIH1L/WQ7YMmLn88X9JX19ehYuVOVZrjap4jWH2GIkU8A==} + /turbo-linux-64/1.7.0: + resolution: {integrity: sha512-aw2qxmfZa+kT87SB3GNUoFimqEPzTlzlRqhPgHuAAT6Uf0JHnmebPt4K+ZPtDNl5yfVmtB05bhHPqw+5QV97Yg==} cpu: [x64] - os: [freebsd] - requiresBuild: true - dev: true - optional: true - - /turbo-freebsd-arm64/1.2.16: - resolution: {integrity: sha512-S0EqPqxwnJuVNNXRgcHB0r8ai8LSrpHdihVJKRM7WYmIR7isccBEf/G9agrt73sCXwjvenxFs4HDR7cSvGt14Q==} - cpu: [arm64] - os: [freebsd] - requiresBuild: true - dev: true - optional: true - - /turbo-linux-32/1.2.16: - resolution: {integrity: sha512-ecbqmGOxgTWePGrowtwyvZGfvwaLxFWmPK21cU0PS+fzoZBaVmzYmniTdd/2EkGCw7TOPhtiT22v96fWcnRycA==} - cpu: [ia32] os: [linux] requiresBuild: true dev: true optional: true - /turbo-linux-64/1.2.16: - resolution: {integrity: sha512-q6gtdMWCzM0Sktkd73zcaQjNoeM1MjtrbwQBctWN/Sgj0eiPBPnzpIvokvx98x7RLf4qyI99/mlme0Dn5fx21A==} - cpu: [x64] - os: [linux] - requiresBuild: true - dev: true - optional: true - - /turbo-linux-arm/1.2.16: - resolution: {integrity: sha512-du7uvExELNb89V3g7iM0XP21fR1Yl3EoHRcOfQz32oUqnS7idCKvbEowM9LtiluQl1dKcOIJjn1nlvvsqzkhOg==} - cpu: [arm] - os: [linux] - requiresBuild: true - dev: true - optional: true - - /turbo-linux-arm64/1.2.16: - resolution: {integrity: sha512-gUf67tYJ/N09WAZTTmtUWYrqm381tZxiulnRGAIM+iRsaTrweyUKZaYXwJvlPpI/cQOw25wCG9/IyvxLeagL8A==} + /turbo-linux-arm64/1.7.0: + resolution: {integrity: sha512-AJEx2jX+zO5fQtJpO3r6uhTabj4oSA5ZhB7zTs/rwu/XqoydsvStA4X8NDW4poTbOjF7DcSHizqwi04tSMzpJw==} cpu: [arm64] os: [linux] requiresBuild: true dev: true optional: true - /turbo-linux-mips64le/1.2.16: - resolution: {integrity: sha512-U5BM+Ql3z13uRtwMmKH/8eL+9DdTgyijC2gaX4xP0RTlcN7WfAstg8Fg/Tn2Vw9vtpVDdxwpw7dvX4kw2ghhpA==} - cpu: [mips64el] - os: [linux] - requiresBuild: true - dev: true - optional: true - - /turbo-linux-ppc64le/1.2.16: - resolution: {integrity: sha512-HQWSCmVZyc5chw7Ie2ZcfZPfmM06mbEEu0Wl11Y5QWh1ZzhPNQHs/TsF4I9r146wHi62XgcrKFjkw4ARZiWsLA==} - cpu: [ppc64] - os: [linux] - requiresBuild: true - dev: true - optional: true - - /turbo-windows-32/1.2.16: - resolution: {integrity: sha512-0ZtPz5FK2qZjznMG4vvRyaabrhO8BgbN+tBx1wjXSuoICTAjYi5TwRVVRh59c3x7qQmR21Cv33CrhLBPRfeAlg==} - cpu: [ia32] - os: [win32] - requiresBuild: true - dev: true - optional: true - - /turbo-windows-64/1.2.16: - resolution: {integrity: sha512-j8iAIixq/rGfBpHNbYOosxMasZrGuMzLILEuQGDxZgKNpYgobJ15QFHQlGR9sit1b8qPU5zZX4CtByRtkgH1Bw==} + /turbo-windows-64/1.7.0: + resolution: {integrity: sha512-ewj7PPv2uxqv0r31hgnBa3E5qwUu7eyVRP5M1gB/TJXfSHduU79gbxpKCyxIZv2fL/N2/3U7EPOQPSZxBAoljA==} cpu: [x64] os: [win32] requiresBuild: true dev: true optional: true - /turbo-windows-arm64/1.2.16: - resolution: {integrity: sha512-4GpcJG3B8R9WDhwfT8fu6ZmOOfseCg6Q1cy/G8/zpJQk769yYcSnD8MgQhYgHB58aVFxZcMxBvLL6UA0UrpgWA==} + /turbo-windows-arm64/1.7.0: + resolution: {integrity: sha512-LzjOUzveWkvTD0jP8DBMYiAnYemmydsvqxdSmsUapHHJkl6wKZIOQNSO7pxsy+9XM/1/+0f9Y9F9ZNl5lePTEA==} cpu: [arm64] os: [win32] requiresBuild: true dev: true optional: true - /turbo/1.2.16: - resolution: {integrity: sha512-PPUa2COKgFkyb6N3uF9AnIY3l9FZkF15QQ3U1K2wpI01D3gyGKQO0Q3DUQ4ipmciP0teBfL7H+l/QTrUA9IVvQ==} + /turbo/1.7.0: + resolution: {integrity: sha512-cwympNwQNnQZ/TffBd8yT0i0O10Cf/hlxccCYgUcwhcGEb9rDjE5thDbHoHw1hlJQUF/5ua7ERJe7Zr0lNE/ww==} hasBin: true requiresBuild: true optionalDependencies: - turbo-darwin-64: 1.2.16 - turbo-darwin-arm64: 1.2.16 - turbo-freebsd-64: 1.2.16 - turbo-freebsd-arm64: 1.2.16 - turbo-linux-32: 1.2.16 - turbo-linux-64: 1.2.16 - turbo-linux-arm: 1.2.16 - turbo-linux-arm64: 1.2.16 - turbo-linux-mips64le: 1.2.16 - turbo-linux-ppc64le: 1.2.16 - turbo-windows-32: 1.2.16 - turbo-windows-64: 1.2.16 - turbo-windows-arm64: 1.2.16 + turbo-darwin-64: 1.7.0 + turbo-darwin-arm64: 1.7.0 + turbo-linux-64: 1.7.0 + turbo-linux-arm64: 1.7.0 + turbo-windows-64: 1.7.0 + turbo-windows-arm64: 1.7.0 dev: true /type-check/0.4.0: diff --git a/services/api2/.eslintrc.json b/services/api2/.eslintrc.json new file mode 100644 index 0000000..df83cc2 --- /dev/null +++ b/services/api2/.eslintrc.json @@ -0,0 +1,6 @@ +{ + "parser": "@typescript-eslint/parser", + "parserOptions": { + "project": "./tsconfig.json" + } +} diff --git a/services/api2/README.md b/services/api2/README.md new file mode 100644 index 0000000..e65bd27 --- /dev/null +++ b/services/api2/README.md @@ -0,0 +1,3 @@ +# API 2 + +Backend service using [serverless framework](https://www.serverless.com/). diff --git a/services/api2/package.json b/services/api2/package.json new file mode 100644 index 0000000..2b47ee4 --- /dev/null +++ b/services/api2/package.json @@ -0,0 +1,34 @@ +{ + "name": "api2", + "version": "0.0.0", + "private": true, + "scripts": { + "dev": "serverless offline start", + "deploy:staging": "serverless deploy --aws-profile personal --stage staging", + "deploy:production": "serverless deploy --aws-profile personal --stage production", + "test": "jest --passWithNoTests", + "test:watch": "jest --watch --coverage", + "lint": "eslint '**/*.ts'", + "lint:fix": "eslint '**/*.ts' --fix", + "package": "serverless package" + }, + "devDependencies": { + "@serverless/typescript": "^3.18.0", + "@types/aws-lambda": "^8.10.98", + "@types/node": "^17.0.40", + "esbuild": "^0.14.42", + "eslint": "^8.14.0", + "jest": "^28.0.3", + "serverless": "^3.19.0", + "serverless-esbuild": "^1.30.0", + "serverless-offline": "^8.8.0", + "ts-node": "^10.8.1", + "tsconfig": "workspace:*", + "tsconfig-paths": "^4.0.0", + "typescript": "^4.7.3" + }, + "dependencies": { + "aws-lambda": "^1.0.7", + "helpers": "workspace:*" + } +} diff --git a/services/api2/serverless.ts b/services/api2/serverless.ts new file mode 100644 index 0000000..9be6c9a --- /dev/null +++ b/services/api2/serverless.ts @@ -0,0 +1,35 @@ +import type { AWS } from "@serverless/typescript"; + +import { functions as ciao } from "@functions/index"; + +const serverlessConfiguration: AWS = { + service: "api2", + frameworkVersion: "3.19", + plugins: ["serverless-esbuild", "serverless-offline"], + provider: { + name: "aws", + runtime: "nodejs16.x", + stage: "dev", + region: "eu-central-1", + environment: { + AWS_NODEJS_CONNECTION_REUSE_ENABLED: "1", + NODE_OPTIONS: "--enable-source-maps --stack-trace-limit=1000", + }, + }, + functions: { ...ciao }, + package: { individually: true }, + custom: { + esbuild: { + bundle: true, + minify: false, + sourcemap: true, + exclude: ["aws-sdk"], + target: "node16", + define: { "require.resolve": undefined }, + platform: "node", + concurrency: 10, + }, + }, +}; + +module.exports = serverlessConfiguration; diff --git a/services/api2/src/functions/ciao/handler.ts b/services/api2/src/functions/ciao/handler.ts new file mode 100644 index 0000000..f994f8d --- /dev/null +++ b/services/api2/src/functions/ciao/handler.ts @@ -0,0 +1,17 @@ +import type { APIGatewayProxyResult } from "aws-lambda"; +import type { ValidatedAPIGatewayProxyEvent } from "helpers"; +import { middyfy, formatJSONResponse } from "helpers"; + +import schema from "./schema"; + +const ciao = async ( + event: ValidatedAPIGatewayProxyEvent +): Promise => { + await new Promise((res) => setTimeout(res, 500)); + + return formatJSONResponse({ + message: `Ciao ${event.body.name} !`, + }); +}; + +export const main = middyfy(ciao); diff --git a/services/api2/src/functions/ciao/schema.ts b/services/api2/src/functions/ciao/schema.ts new file mode 100644 index 0000000..fd65d70 --- /dev/null +++ b/services/api2/src/functions/ciao/schema.ts @@ -0,0 +1,7 @@ +export default { + type: "object", + properties: { + name: { type: "string" }, + }, + required: ["name"], +} as const; diff --git a/services/api2/src/functions/index.ts b/services/api2/src/functions/index.ts new file mode 100644 index 0000000..855fdf3 --- /dev/null +++ b/services/api2/src/functions/index.ts @@ -0,0 +1,25 @@ +import type { AWS } from "@serverless/typescript"; + +import schema from "./ciao/schema"; + +export const functions: AWS["functions"] = { + ciao: { + handler: "src/functions/ciao/handler.main", + description: "Lambda function to say ciao", + memorySize: 256, + events: [ + { + http: { + method: "post", + path: "ciao", + cors: true, + request: { + schemas: { + "application/json": schema, + }, + }, + }, + }, + ], + }, +}; diff --git a/services/api2/tsconfig.json b/services/api2/tsconfig.json new file mode 100644 index 0000000..f2b9e5e --- /dev/null +++ b/services/api2/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "tsconfig/base.json", + "compilerOptions": { + "baseUrl": ".", + "paths": { + "@functions/*": ["src/functions/*"], + } + }, + "include": ["src/**/*.ts", "serverless.ts"], + "exclude": ["node_modules"] +}