Skip to content

Get into working state #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ module.exports = {
'import/no-extraneous-dependencies': 'off',
'no-extra-semi': 'off',
'dot-notation': 'off',
'max-len': [
'error',
150,
],
},
};
2,475 changes: 2,085 additions & 390 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"description": "Lambdas and DynamoDB",
"main": "serverless.ts",
"scripts": {
"deploy": "npx sls deploy",
"offline": "npx sls offline start",
"test": "echo \"Error: no test specified\" && exit 1"
},
"engines": {
Expand All @@ -14,15 +16,13 @@
"@middy/core": "^3.4.0",
"@middy/http-json-body-parser": "^3.4.0",
"@middy/validator": "^5.1.0",
"aws-lambda": "^1.0.7",
"aws-sdk": "^2.1522.0",
"serverless-auto-swagger": "^2.12.0",
"serverless-dynamodb": "^0.2.47",
"uuid": "^9.0.1"
},
"devDependencies": {
"@serverless/typescript": "^3.0.0",
"serverless-auto-swagger": "^2.12.0",
"serverless-dynamodb": "^0.2.47",
"@types/aws-lambda": "^8.10.71",
"@types/glob": "^8.1.0",
"@types/node": "^14.14.25",
"@typescript-eslint/eslint-plugin": "^6.15.0",
"@typescript-eslint/parser": "^6.15.0",
Expand All @@ -33,6 +33,7 @@
"eslint-plugin-import": "^2.29.1",
"json-schema-to-ts": "^1.5.0",
"serverless": "^3.0.0",
"serverless-dynamodb-local": "^0.2.40",
"serverless-esbuild": "^1.23.3",
"serverless-offline": "^13.3.2",
"ts-node": "^10.9.2",
Expand All @@ -44,4 +45,4 @@
"path": "./node_modules/cz-conventional-changelog"
}
}
}
}
262 changes: 143 additions & 119 deletions serverless.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { AWS } from '@serverless/typescript';
import scanFs from '@libs/fs-scanner';

// User
import {
Expand All @@ -20,145 +21,168 @@ import {
sendMail,
} from '@functions/mail/routes';

const serverlessConfiguration: AWS = {
service: 'NodeTeam',
frameworkVersion: '3',
plugins: ['serverless-esbuild', 'serverless-dynamodb', 'serverless-auto-swagger', 'serverless-offline'],
provider: {
name: 'aws',
runtime: 'nodejs18.x',
apiGateway: {
minimumCompressionSize: 1024,
shouldStartNameWithService: true,
},
environment: {
AWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',
},
},
functions: {
usersGetAll,
usersCreate,
usersGetById,
usersGetByEmail,
setVerifiedUser,
shopsCreate,
shopsGetById,
sendMail,
},
package: { individually: true },
custom: {
esbuild: {
bundle: true,
minify: false,
sourcemap: true,
exclude: ['aws-sdk'],
target: 'node18',
define: { 'require.resolve': undefined },
platform: 'node',
concurrency: 10,
const TYPE_FILE_PATTERN = './src/**/*.d.ts';

const getConfiguration = async (): Promise<AWS> => {
const typeFileNames = await scanFs(TYPE_FILE_PATTERN);

return {
service: 'NodeTeam',
frameworkVersion: '3',
plugins: [
'serverless-auto-swagger',
'serverless-esbuild',
'serverless-dynamodb',
'serverless-offline',
],
provider: {
name: 'aws',
runtime: 'nodejs18.x',
apiGateway: {
minimumCompressionSize: 1024,
shouldStartNameWithService: true,
},
environment: {
AWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',
},
},
autoswagger: {
title: 'NodeTeam',
basePath: '/dev',
functions: {
usersGetAll,
usersCreate,
usersGetById,
usersGetByEmail,
setVerifiedUser,
shopsCreate,
shopsGetById,
sendMail,
},
'serverless-dynamodb': {
start: {
port: 8000,
docker: false,
migrate: true,
inMemory: false,
dbPath: '../.dynamodb',
package: { individually: true },
custom: {
esbuild: {
bundle: true,
minify: false,
sourcemap: true,
exclude: [],
target: 'node18',
define: { 'require.resolve': undefined },
platform: 'node',
concurrency: 10,
},
autoswagger: {
title: 'NodeTeam',
basePath: '/dev',
typefiles: typeFileNames,
apiType: 'http',
},
'serverless-dynamodb': {
start: {
port: 8000,
docker: false,
migrate: true,
inMemory: false,
dbPath: '../.dynamodb',
},
},
},
},
resources: {
Resources: {
UsersTable: {
Type: 'AWS::DynamoDB::Table',
Properties: {
TableName: 'UsersTable',
AttributeDefinitions: [{
AttributeName: 'userId',
AttributeType: 'S',
}, {
AttributeName: 'email',
AttributeType: 'S',
}],
KeySchema: [{
AttributeName: 'userId',
KeyType: 'HASH',
}],
GlobalSecondaryIndexes: [{
IndexName: 'email-index',
resources: {
Resources: {
UsersTable: {
Type: 'AWS::DynamoDB::Table',
Properties: {
TableName: 'UsersTable',
AttributeDefinitions: [
{
AttributeName: 'userId',
AttributeType: 'S',
},
{
AttributeName: 'email',
AttributeType: 'S',
},
],
KeySchema: [{
AttributeName: 'email',
KeyType: 'HASH',
}, {
AttributeName: 'userId',
KeyType: 'RANGE',
}],
AttributeDefinitions: [{
AttributeName: 'email',
AttributeType: 'S',
KeyType: 'HASH',
}],
Projection: {
ProjectionType: 'ALL',
},
GlobalSecondaryIndexes: [
{
IndexName: 'email-index',
KeySchema: [
{
AttributeName: 'email',
KeyType: 'HASH',
},
{
AttributeName: 'userId',
KeyType: 'RANGE',
},
],
Projection: {
ProjectionType: 'ALL',
},
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1,
},
},
],
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1,
},
}],
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1,
},
},
},
ShopsTable: {
Type: 'AWS::DynamoDB::Table',
Properties: {
TableName: 'ShopsTable',
AttributeDefinitions: [{
AttributeName: 'shopId',
AttributeType: 'S',
}, {
AttributeName: 'name',
AttributeType: 'S',
}],
KeySchema: [{
AttributeName: 'shopId',
KeyType: 'HASH',
}],
GlobalSecondaryIndexes: [{
IndexName: 'name-index',
KeySchema: [{
AttributeName: 'name',
KeyType: 'HASH',
}, {
AttributeName: 'shopId',
KeyType: 'RANGE',
}],
AttributeDefinitions: [{
AttributeName: 'name',
AttributeType: 'S',
}],
Projection: {
ProjectionType: 'ALL',
},
ShopsTable: {
Type: 'AWS::DynamoDB::Table',
Properties: {
TableName: 'ShopsTable',
AttributeDefinitions: [
{
AttributeName: 'shopId',
AttributeType: 'S',
},
{
AttributeName: 'name',
AttributeType: 'S',
},
],
KeySchema: [
{
AttributeName: 'shopId',
KeyType: 'HASH',
},
],
GlobalSecondaryIndexes: [
{
IndexName: 'name-index',
KeySchema: [
{
AttributeName: 'name',
KeyType: 'HASH',
},
{
AttributeName: 'shopId',
KeyType: 'RANGE',
},
],
Projection: {
ProjectionType: 'ALL',
},
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1,
},
},
],
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1,
},
}],
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1,
},
},
},
},
},
};
};

module.exports = serverlessConfiguration;
module.exports = getConfiguration();
23 changes: 23 additions & 0 deletions src/constants/http-method.constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export const CONNECT = 'CONNECT';
export const DELETE = 'DELETE';
export const GET = 'GET';
export const HEAD = 'HEAD';
export const OPTIONS = 'OPTIONS';
export const PATCH = 'PATCH';
export const POST = 'POST';
export const PUT = 'PUT';
export const TRACE = 'TRACE';

const HTTP_METHODS = {
CONNECT,
DELETE,
GET,
HEAD,
OPTIONS,
PATCH,
POST,
PUT,
TRACE,
} as const;

export default HTTP_METHODS;
4 changes: 2 additions & 2 deletions src/functions/mail/handler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SESClient, SendEmailCommand } from '@aws-sdk/client-ses';
import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
import { formatJSONResponse } from '@libs/api-gateway';
import { middyfy } from '@libs/lambda';
import { middify } from '@libs/lambda';

const ses = new SESClient({
region: 'us-west-2',
Expand All @@ -18,7 +18,7 @@ type APIGatewayProxyEventWithBody<TBody> = Omit<APIGatewayProxyEvent, 'body'> &
* @description: Send Mail
* @example: curl -X POST http://localhost:3000/dev/mail -d '{"to": "test@test"}'
*/
const sendMail = middyfy(
const sendMail = middify(
{
type: 'object',
required: ['body'],
Expand Down
Loading