Skip to content
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

build: Bun #63

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d17ca9c
replace `bcrypt` with bun's password hashing
bnussman Sep 26, 2023
5bd2bdf
fix ws import
bnussman Sep 26, 2023
02beb1a
Merge branch 'main' into 62-use-bun-for-the-api
bnussman Oct 1, 2023
056c1cd
Merge branch 'main' into 62-use-bun-for-the-api
Oct 4, 2023
44552bb
fix deps
Oct 4, 2023
aafc18f
Merge branch 'main' into 62-use-bun-for-the-api
bnussman Oct 5, 2023
5c304ff
Merge branch 'main' into 62-use-bun-for-the-api
bnussman Oct 15, 2023
415ddd2
try to fix CI
bnussman Oct 17, 2023
699fdb2
Merge branch 'main' into 62-use-bun-for-the-api
bnussman Oct 31, 2023
8f880e8
Merge branch 'main' into 62-use-bun-for-the-api
bnussman Oct 31, 2023
15785af
Merge branch 'main' into 62-use-bun-for-the-api
bnussman Oct 31, 2023
1f755fb
use bun in api dockerfile
bnussman Oct 31, 2023
5921d67
add bun to github actions e2e
bnussman Oct 31, 2023
ee334bf
Merge branch 'main' into 62-use-bun-for-the-api
bnussman Nov 15, 2023
5138c80
fix tsc error
bnussman Nov 15, 2023
c0fe633
Merge branch 'main' into 62-use-bun-for-the-api
bnussman Nov 18, 2023
d468957
fix api type
bnussman Nov 18, 2023
74da240
Merge branch 'main' into 62-use-bun-for-the-api
bnussman Nov 19, 2023
902f6f0
Merge branch 'main' into 62-use-bun-for-the-api
bnussman Nov 27, 2023
6c14457
Merge branch 'main' into 62-use-bun-for-the-api
bnussman Dec 2, 2023
8695c7b
Merge branch 'main' into 62-use-bun-for-the-api
bnussman Dec 3, 2023
b9f8f26
Merge branch 'main' into 62-use-bun-for-the-api
bnussman Dec 7, 2023
fe7ed47
Merge branch 'main' into 62-use-bun-for-the-api
bnussman Dec 14, 2023
4a15a94
Merge branch 'main' into 62-use-bun-for-the-api
bnussman Dec 22, 2023
825b75d
Merge branch 'main' into 62-use-bun-for-the-api
bnussman Jan 3, 2024
c319685
Merge branch 'main' into 62-use-bun-for-the-api
bnussman Jan 13, 2024
105e830
Merge branch 'main' into 62-use-bun-for-the-api
bnussman Jan 16, 2024
b95f1a0
Merge branch 'main' into 62-use-bun-for-the-api
bnussman Jan 19, 2024
037f362
fix fetch type issue
bnussman Jan 19, 2024
12c091d
Merge branch 'main' into 62-use-bun-for-the-api
bnussman Jan 21, 2024
c720908
Merge branch 'main' into 62-use-bun-for-the-api
bnussman Feb 4, 2024
b83de8f
use `@types/bun` package
bnussman Feb 4, 2024
996e870
Merge branch 'main' into 62-use-bun-for-the-api
bnussman Feb 23, 2024
07c0dd4
Merge branch 'main' into 62-use-bun-for-the-api
bnussman Mar 9, 2024
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
3 changes: 3 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: 16
- uses: oven-sh/setup-bun@v1
with:
bun-version: canary
- uses: pnpm/[email protected]
name: Install pnpm
id: pnpm-install
Expand Down
11 changes: 4 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
FROM node:current-alpine
# FROM mcr.microsoft.com/playwright:focal
FROM oven/bun:canary

WORKDIR /usr/api

COPY api/package.json ./

RUN npm install -g pnpm

RUN pnpm install
RUN bun install

COPY api/ .

RUN npx tsc
RUN bun tsc

EXPOSE 3000

CMD [ "node", "build/index.js" ]
CMD [ "bun", "run", "build/index.js" ]
4 changes: 2 additions & 2 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"scripts": {
"build": "tsc",
"start": "node build/index.js",
"dev": "concurrently --raw \"tsc -w --preserveWatchOutput\" \"node --watch build/index.js\"",
"dev": "concurrently --raw \"tsc -w --preserveWatchOutput\" \"bun --watch build/index.js\"",
"db:create": "mikro-orm schema:create --run",
"db:update": "mikro-orm schema:update --run",
"db:drop": "mikro-orm schema:drop --run",
Expand All @@ -30,7 +30,6 @@
"@sentry/integrations": "7.77.0",
"@sentry/node": "7.77.0",
"aws-sdk": "^2.1563.0",
"bcrypt": "^5.1.1",
"body-parser": "^1.20.2",
"car-info": "^0.1.6",
"class-validator": "^0.14.1",
Expand Down Expand Up @@ -63,6 +62,7 @@
"@types/uuid": "^9.0.8",
"@types/ws": "^8.5.10",
"concurrently": "^8.2.2",
"@types/bun": "latest",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
},
Expand Down
8 changes: 4 additions & 4 deletions api/src/auth/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Token } from '../entities/Token';
import { Context } from '../utils/context';
import { s3 } from '../utils/s3';
import { FileUpload } from 'graphql-upload-minimal';
import { compare, hash } from 'bcrypt';
import { password as bunPassword } from 'bun';
import { isDevelopment } from '../utils/constants';

@ObjectType()
Expand All @@ -35,7 +35,7 @@ export class AuthResolver {
isPasswordCorrect = sha256(password) === user.password;
break;
case (PasswordType.BCRYPT):
isPasswordCorrect = await compare(password, user.password);
isPasswordCorrect = await bunPassword.verify(password, user.password, "bcrypt");
break;
default:
throw new Error(`Unknown password type ${user.passwordType}`);
Expand Down Expand Up @@ -77,7 +77,7 @@ export class AuthResolver {
throw new Error("No result from AWS");
}

const password = await hash(input.password, 10);
const password = await bunPassword.hash(input.password, "bcrypt");

wrap(user).assign({
username: input.username,
Expand Down Expand Up @@ -185,7 +185,7 @@ export class AuthResolver {
throw new Error("Your reset token has expired. You must re-request to reset your password.");
}

entry.user.password = await hash(input.password, 10);
entry.user.password = await bunPassword.hash(input.password, "bcrypt");
entry.user.passwordType = PasswordType.BCRYPT;

await ctx.em.nativeDelete(Token, { user: entry.user });
Expand Down
2 changes: 1 addition & 1 deletion api/src/directions/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ export class DirectionsResolver {

return `${etaMinutes} min`;
}
}
}
4 changes: 2 additions & 2 deletions api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import "dotenv/config";
import Redis from 'ioredis';
import express from "express";
import config from './mikro-orm.config';
import ws from 'ws';
import { WebSocketServer } from 'ws';
import cors from 'cors';
import * as Sentry from "./utils/sentry";
import * as RealSentry from "@sentry/node";
Expand Down Expand Up @@ -99,7 +99,7 @@ async function start() {
plugins,
});

const wsServer = new ws.Server({
const wsServer = new WebSocketServer({
server: httpServer,
path: '/subscriptions',
});
Expand Down
2 changes: 1 addition & 1 deletion api/src/payments/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export async function syncUserPayments(em: EntityManager, userId: string): Promi

const request = await fetch(`https://api.revenuecat.com/v1/subscribers/${userId}`, options);

const response: SubscriberResponse = await request.json();
const response = await request.json() as SubscriberResponse;

const user = await em.findOneOrFail(User, userId, { populate: ['payments.id'] });

Expand Down
13 changes: 6 additions & 7 deletions api/src/users/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { S3 } from 'aws-sdk';
import { getOlderObjectsToDelete, getAllObjects, getUserFromObjectKey, deleteObject, s3 } from '../utils/s3';
import { ChangePasswordInput, EditUserInput, NotificationArgs } from './args';
import { createVerifyEmailEntryAndSendEmail } from '../auth/helpers';
import { hash } from 'bcrypt';
import { password as bunPassword } from 'bun';
import { VerifyEmail } from '../entities/VerifyEmail';
import { GraphQLUpload } from 'graphql-upload-minimal';
import { setContext } from "@sentry/node";
Expand Down Expand Up @@ -109,7 +109,7 @@ export class UserResolver {
@Mutation(() => Boolean)
@Authorized('No Verification')
public async changePassword(@Ctx() ctx: Context, @Arg('input') input: ChangePasswordInput): Promise<boolean> {
ctx.user.password = await hash(input.password, 10);
ctx.user.password = await bunPassword.hash(input.password, "bcrypt");
ctx.user.passwordType = PasswordType.BCRYPT;

await ctx.em.flush();
Expand Down Expand Up @@ -164,15 +164,14 @@ export class UserResolver {

@Mutation(() => User)
@Authorized('No Verification')
public async addProfilePicture(@Ctx() ctx: Context, @Arg("picture", () => GraphQLUpload) { createReadStream, filename }: Upload, @PubSub() pubSub: PubSubEngine): Promise<User> {

public async addProfilePicture(@Ctx() ctx: Context, @Arg("picture", () => GraphQLUpload) picture: Upload, @PubSub() pubSub: PubSubEngine): Promise<User> {
const { createReadStream, filename } = await picture;

const extention = filename.substring(filename.lastIndexOf("."), filename.length);

filename = ctx.user.id + "-" + Date.now() + extention;

const uploadParams = {
Body: createReadStream(),
Key: "images/" + filename,
Key: "images/" + ctx.user.id + "-" + Date.now() + extention,
Bucket: "beep",
ACL: "public-read"
};
Expand Down
5 changes: 4 additions & 1 deletion api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"forceConsistentCasingInFileNames": true
"forceConsistentCasingInFileNames": true,
"types": [
"@types/bun" // add Bun global
]
},
"compileOnSave": true,
"include": [
Expand Down
Loading
Loading