-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style(Bun): Introduce Bun to email-function
- Loading branch information
1 parent
6feb3c5
commit fceaf4c
Showing
22 changed files
with
424 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Validate email-function | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
- develop | ||
paths: | ||
- .github/workflows/validate-email-function.yml | ||
- bun-packages/packages/email-function/** | ||
- bun-packages/biome.json | ||
|
||
jobs: | ||
prettier: | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- uses: actions/[email protected] | ||
|
||
- name: Set up Biome | ||
uses: biomejs/setup-biome@v2 | ||
with: | ||
version: 1.5.3 | ||
|
||
- name: Run Biome | ||
run: biome ci . | ||
working-directory: bun-packages/packages/email-function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"recommendations": [ | ||
"biomejs.biome" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"cSpell.words": [ | ||
"biomejs" | ||
], | ||
"[typescript]": { | ||
"editor.defaultFormatter": "biomejs.biome", | ||
"editor.formatOnSave": true, | ||
"editor.codeActionsOnSave": { | ||
"quickfix.biome": "explicit", | ||
"source.organizeImports.biome": "explicit" | ||
} | ||
}, | ||
"[json]": { | ||
"editor.defaultFormatter": "biomejs.biome", | ||
"editor.formatOnSave": true, | ||
"editor.codeActionsOnSave": { | ||
"quickfix.biome": "explicit" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json", | ||
"organizeImports": { | ||
"enabled": true | ||
}, | ||
"linter": { | ||
"enabled": true, | ||
"rules": { | ||
"recommended": true | ||
} | ||
}, | ||
"vcs": { | ||
"enabled": true, | ||
"clientKind": "git", | ||
"useIgnoreFile": true, | ||
"defaultBranch": "default" | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
{ | ||
"name": "bun-packages", | ||
"version": "0.1.0", | ||
"workspaces": [ | ||
"packages/*" | ||
] | ||
"name": "bun-packages", | ||
"version": "0.1.0", | ||
"workspaces": [ | ||
"packages/*" | ||
], | ||
"devDependencies": { | ||
"@biomejs/biome": "1.5.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
{ | ||
"name": "email-function", | ||
"version": "0.1.0", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"build:lambda": "rm -rf dist && esbuild src/lambda.ts --bundle --outfile=dist/lambda.js --platform=node --target=node18 --minify --metafile=meta.json", | ||
"build:node": "rm -rf dist && esbuild src/node.ts --bundle --outfile=dist/node.js --platform=node --target=node18 --format=esm --metafile=meta.json", | ||
"start:node": "npm run build:node && node dist/node.js", | ||
"lint": "tsc --project tsconfig.node.json" | ||
}, | ||
"devDependencies": { | ||
"esbuild": "0.20.0", | ||
"typescript": "5.3.3" | ||
}, | ||
"dependencies": { | ||
"@aws-sdk/client-dynamodb": "3.511.0", | ||
"@openpgp/web-stream-tools": "0.1.1", | ||
"@react-email/render": "0.0.12", | ||
"@types/aws-lambda": "8.10.133", | ||
"@types/node": "20.10.2", | ||
"dotenv": "16.4.2", | ||
"form-data": "4.0.0", | ||
"mailgun.js": "10.1.0", | ||
"openpgp": "5.11.0", | ||
"serialize-error": "11.0.3", | ||
"zod": "3.22.4" | ||
} | ||
"name": "email-function", | ||
"version": "0.1.0", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"build:lambda": "rm -rf dist && esbuild src/lambda.ts --bundle --outfile=dist/lambda.js --platform=node --target=node18 --minify --metafile=meta.json", | ||
"build:node": "rm -rf dist && esbuild src/node.ts --bundle --outfile=dist/node.js --platform=node --target=node18 --format=esm --metafile=meta.json", | ||
"start:node": "npm run build:node && node dist/node.js", | ||
"lint": "tsc --project tsconfig.node.json" | ||
}, | ||
"devDependencies": { | ||
"esbuild": "0.20.0", | ||
"typescript": "5.3.3" | ||
}, | ||
"dependencies": { | ||
"@aws-sdk/client-dynamodb": "3.511.0", | ||
"@openpgp/web-stream-tools": "0.1.1", | ||
"@react-email/render": "0.0.12", | ||
"@types/aws-lambda": "8.10.133", | ||
"@types/node": "20.10.2", | ||
"dotenv": "16.4.2", | ||
"form-data": "4.0.0", | ||
"mailgun.js": "10.1.0", | ||
"openpgp": "5.11.0", | ||
"serialize-error": "11.0.3", | ||
"zod": "3.22.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 42 additions & 42 deletions
84
bun-packages/packages/email-function/src/_lib/errorHandler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,50 @@ | ||
import { serializeError } from "serialize-error"; | ||
import { ZodError } from "zod"; | ||
import { log } from "./logging"; | ||
import { CustomError } from "./logging/CustomError"; | ||
import { serializeError } from "serialize-error"; | ||
|
||
export const errorHandler = (error: unknown) => { | ||
if (error instanceof ZodError) { | ||
return { | ||
statusCode: 400, | ||
body: JSON.stringify({ | ||
message: "Bad request", | ||
errors: error.errors, | ||
}), | ||
}; | ||
} else if (error instanceof Error && error.message === "Bad request") { | ||
return { | ||
statusCode: 400, | ||
body: JSON.stringify({ | ||
message: "Bad request", | ||
}), | ||
}; | ||
} else if (error instanceof Error && error.message === "Unauthorized") { | ||
return { | ||
statusCode: 401, | ||
body: JSON.stringify({ | ||
message: "Unauthorized", | ||
}), | ||
}; | ||
} else if (error instanceof CustomError) { | ||
log.error(error.message, serializeError(error.context)); | ||
if (error instanceof ZodError) { | ||
return { | ||
statusCode: 400, | ||
body: JSON.stringify({ | ||
message: "Bad request", | ||
errors: error.errors, | ||
}), | ||
}; | ||
} else if (error instanceof Error && error.message === "Bad request") { | ||
return { | ||
statusCode: 400, | ||
body: JSON.stringify({ | ||
message: "Bad request", | ||
}), | ||
}; | ||
} else if (error instanceof Error && error.message === "Unauthorized") { | ||
return { | ||
statusCode: 401, | ||
body: JSON.stringify({ | ||
message: "Unauthorized", | ||
}), | ||
}; | ||
} else if (error instanceof CustomError) { | ||
log.error(error.message, serializeError(error.context)); | ||
|
||
return { | ||
statusCode: 500, | ||
body: JSON.stringify({ | ||
message: "Internal server error", | ||
}), | ||
}; | ||
} | ||
return { | ||
statusCode: 500, | ||
body: JSON.stringify({ | ||
message: "Internal server error", | ||
}), | ||
}; | ||
} | ||
|
||
log.error("errorHandler", { | ||
error: serializeError(error), | ||
}); | ||
log.error("errorHandler", { | ||
error: serializeError(error), | ||
}); | ||
|
||
return { | ||
statusCode: 500, | ||
body: JSON.stringify({ | ||
message: "Internal server error", | ||
}), | ||
}; | ||
} | ||
return { | ||
statusCode: 500, | ||
body: JSON.stringify({ | ||
message: "Internal server error", | ||
}), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.