Skip to content

Commit

Permalink
merge with main; fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
nishkohli96 committed Jan 27, 2025
2 parents 33d587c + 48ce4e1 commit 590ecaa
Show file tree
Hide file tree
Showing 29 changed files with 1,319 additions and 615 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
- name: Build @csl/react-express, @csl/shared-fe, @csl/mongo-models
run: yarn lib

- name: Build express-server
run: yarn workspace express-server build
# - name: Build express-server
# run: yarn workspace express-server build

- name: Build nestjs-server
run: yarn workspace nestjs-server build
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/docker-img.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ jobs:
id: date
run: echo "::set-output name=date::$(date +'%Y_%m_%d_%H_%m')"

- name: Build Express Server Image
run: docker build -f ./apps/express-server/Dockerfile -t ${{secrets.DOCKER_HUB_USERNAME}}/csl-express-server:${{ steps.date.outputs.date }} .
# - name: Build Express Server Image
# run: docker build -f ./apps/express-server/Dockerfile -t ${{secrets.DOCKER_HUB_USERNAME}}/csl-express-server:${{ steps.date.outputs.date }} .

- name: Build NestJS Server Image
run: docker build -f ./apps/nestjs-server/Dockerfile -t ${{secrets.DOCKER_HUB_USERNAME}}/csl-nestjs-server:${{ steps.date.outputs.date }} .
Expand All @@ -45,8 +45,8 @@ jobs:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}

- name: Push Express Server Image to Docker Hub
run: docker push ${{ secrets.DOCKER_HUB_USERNAME }}/csl-express-server:${{ steps.date.outputs.date }}
# - name: Push Express Server Image to Docker Hub
# run: docker push ${{ secrets.DOCKER_HUB_USERNAME }}/csl-express-server:${{ steps.date.outputs.date }}

- name: Push NestJS Server Image to Docker Hub
run: docker push ${{ secrets.DOCKER_HUB_USERNAME }}/csl-nestjs-server:${{ steps.date.outputs.date }}
Expand Down
13 changes: 12 additions & 1 deletion apps/express-server/.env_sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
NODE_ENV=
PORT=
DOMAIN=

# MongoDB
DB_URL=
DB_NAME=
POSTGRES_URL=

# Postgres
POSTGRES_URL=

# Stytch
STYTCH_PROJECT_ID=
STYTCH_ORG_ID=
STYTCH_SECRET=
STYTCH_TEST_EMAIL=
4 changes: 3 additions & 1 deletion apps/express-server/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module.exports = {
extends: ['@nish1896/eslint-config/js']
extends: [
'@nish1896/eslint-config/js'
]
};
3 changes: 2 additions & 1 deletion apps/express-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ $ yarn run start:prod
- delete file and folder
- People API
- CRUD operations
- Advanced filtering using operators from [Mui Datagrid](https://mui.com/x/react-data-grid/)
- Advanced filtering using operators from [Mui Datagrid](https://mui.com/x/react-data-grid/)
- [Stytch](https://stytch.com/) authentication methods
14 changes: 7 additions & 7 deletions apps/express-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
"@csl/react-express": "*",
"cors": "^2.8.5",
"dotenv": "^16.4.4",
"express": "^4.18.2",
"express": "^4.21.2",
"fluent-ffmpeg": "^2.1.3",
"moment": "^2.30.1",
"multer": "^1.4.5-lts.1",
"pg": "^8.11.5",
"pg": "^8.13.1",
"pg-hstore": "^2.3.4",
"sequelize": "^6.37.3",
"sequelize": "^6.37.5",
"stytch": "^11.11.0",
"winston": "3.11.0"
},
"devDependencies": {
"@nish1896/eslint-config": "^2.1.2",
"@nish1896/eslint-config": "^2.1.3",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/express-serve-static-core": "^4.19.5",
"@types/express": "4.17.21",
"@types/fluent-ffmpeg": "^2.1.24",
"@types/multer": "^1.4.11",
"@types/multer": "1.4.12",
"@types/node": "^20.11.17",
"env-cmd": "^10.1.0",
"eslint": "^8.57.0",
Expand Down
9 changes: 8 additions & 1 deletion apps/express-server/src/app-constants/env_vars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ const env = process.env;
export const ENV_VARS = Object.freeze({
env: env.NODE_ENV ?? 'development',
port: env.PORT ?? 8000,
domain: env.DOMAIN ?? 'http://localhost:8000',
mongoDB: {
url: process.env.DB_URL ?? 'mongodb://localhost:27017',
dbName: process.env.DB_NAME ?? 'SeederDB'
},
postgresUrl: env.POSTGRES_URL ?? ''
postgresUrl: env.POSTGRES_URL ?? '',
stytch: {
projectId: env.STYTCH_PROJECT_ID ?? '',
orgId: env.STYTCH_ORG_ID ?? '',
secret: env.STYTCH_SECRET ?? '',
testEmail: env.STYTCH_TEST_EMAIL ?? '[email protected]'
}
});

export const isProductionEnv = ENV_VARS.env === 'production';
7 changes: 4 additions & 3 deletions apps/express-server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path';
import { ExpressServerEndpoints } from '@csl/react-express';
import { ENV_VARS, ServerConfig } from '@/app-constants';
import { requestLogger } from '@/middleware';
import * as Routes from '@/routes';
import { routesArray } from '@/routes';

const app: Express = express();

Expand Down Expand Up @@ -47,8 +47,9 @@ app.get('/', (_: Request, response: Response) => {
});
});

app.use(generatePath(ExpressServerEndpoints.files.rootPath), Routes.fileRouter);
app.use(generatePath(ExpressServerEndpoints.people.rootPath), Routes.personRouter);
/* Require App to use all routes from the routesArray. */
routesArray.forEach(route =>
app.use(generatePath(route.rootPath), route.router));

/* 404 Handler */
app.get('*', (req: Request, response: Response) => {
Expand Down
3 changes: 3 additions & 0 deletions apps/express-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ async function bootstrap() {
try {
await connectToDB();
await connect(dbConnectionString);
winstonLogger.info(
`[ ⚡️ ${hostName} ⚡️ ] - Connected to MongoDB`
);
const server = createServer(app);
server.listen(port, () => {
winstonLogger.info(
Expand Down
1 change: 1 addition & 0 deletions apps/express-server/src/routes/file/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class FileService {
return res.send('File Uploaded');
} catch (err) {
console.log('Error in uploading file ', err);
return res.send(err);
}
}

Expand Down
2 changes: 1 addition & 1 deletion apps/express-server/src/routes/file/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Request } from 'express';

/* File Upload */
export interface UploadMediaBody {
media: File
media: Express.Multer.File
}
export type UploadMediaRequest = Request<object, object, UploadMediaBody>

Expand Down
20 changes: 16 additions & 4 deletions apps/express-server/src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import { ExpressServerEndpoints } from '@csl/react-express';
import { fileRouter } from './file/controller';
import { personRouter } from './person/controller';
import { stytchRouter } from './stytch/controller';

export {
fileRouter,
personRouter
};
export const routesArray = [
{
rootPath: ExpressServerEndpoints.files.rootPath,
router: fileRouter
},
{
rootPath: ExpressServerEndpoints.people.rootPath,
router: personRouter
},
{
rootPath: ExpressServerEndpoints.stytch.rootPath,
router: stytchRouter
}
];
166 changes: 166 additions & 0 deletions apps/express-server/src/routes/stytch/controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import { Request, Response, Router } from 'express';
import { ExpressServerEndpoints } from '@csl/react-express';
import { ENV_VARS } from '@/app-constants';
import stytchService from './service';
import * as StytchTypes from './types';

const stytchRouter = Router();
const subRoutes = ExpressServerEndpoints.stytch.subRoutes;

/* POST: /stytch/add-member */
stytchRouter.post(
`/${subRoutes.addMember}`,
async (req: Request<object, object, StytchTypes.CreateMemberBody>, res: Response) => {
return await stytchService.addMember(res, req.body);
}
);

/* GET: /stytch/get-member */
stytchRouter.get(
`/${subRoutes.getMember}/:memberId`,
async (req: Request<StytchTypes.GetMember>, res: Response) => {
return await stytchService.getMember(res, req.params.memberId);
}
);

/* PATCH: /stytch/update-member */
stytchRouter.patch(
`/${subRoutes.updateMember}/:memberId`,
async (req: Request<StytchTypes.GetMember, object, StytchTypes.CreateMemberBody>, res: Response) => {
return await stytchService.updateMember(res, req.params.memberId, req.body);
}
);

/* DELETE: /stytch/unlink-email */
stytchRouter.delete(
`/${subRoutes.unlinkEmail}/:memberId`,
async (req: Request<StytchTypes.GetMember, object, StytchTypes.EmailPayload>, res: Response) => {
return await stytchService.unlinkEmail(res, req.params.memberId, req.body);
}
);

/* DELETE: /stytch/delete-member */
stytchRouter.delete(
`/${subRoutes.deleteMember}/:memberId`,
async (req: Request<StytchTypes.GetMember>, res: Response) => {
return await stytchService.deleteMember(res, req.params.memberId);
}
);

/* POST: /stytch/migrate-password */
stytchRouter.post(
`/${subRoutes.migratePassword}`,
async (req: Request<object, object, StytchTypes.SetPassword>, res: Response) => {
return await stytchService.migratePassword(res, req.body);
}
);

/* POST: /stytch/org-signin */
stytchRouter.post(
`/${subRoutes.orgSignIn}`,
async (req: Request, res: Response) => {
return await stytchService.sendSignInEmail(res);
}
);

/* POST: /stytch/magic-link */
stytchRouter.post(
`/${subRoutes.magicLinkEmail}`,
async (req: Request, res: Response) => {
const redirectURL = `${ENV_VARS.domain}${ExpressServerEndpoints.apiPrefix}${ExpressServerEndpoints.stytch.rootPath}/${subRoutes.magicLinkRedirect}`;
return await stytchService.sendDiscoveryEmail(res, redirectURL);
}
);

/* GET: /stytch/discovery-redirect */
stytchRouter.get(
`/${subRoutes.magicLinkRedirect}`,
(req: Request, res: Response) => {
return stytchService.magicLinkRedirect(res);
}
);

/* GET: /stytch/sms-otp */
stytchRouter.get(
`/${subRoutes.smsOTP}/:memberId`,
async (req: Request<StytchTypes.GetMember>, res: Response) => {
return await stytchService.sendSMSOtp(res, req.params.memberId);
}
);

/* POST: /stytch/verify-sms-otp */
stytchRouter.post(
`/${subRoutes.verifySMSOTP}`,
async (req: Request<object, object, StytchTypes.VerifyCode>, res: Response) => {
return await stytchService.verifySMSOtp(res, req.body);
}
);

/* POST: /stytch/email-otp */
stytchRouter.post(
`/${subRoutes.emailOTP}`,
async (req: Request, res: Response) => {
return await stytchService.sendOtp(res);
}
);

/* POST: /stytch/reset-password */
stytchRouter.post(
`/${subRoutes.resetPassword}`,
async (
req: Request<object, object, StytchTypes.EmailPayload>,
res: Response
) => {
const reqBody = req.body;
return await stytchService.resetPassword(res, reqBody);
}
);

/* POST: /stytch/authenticate/with-password */
stytchRouter.post(
`/${subRoutes.authenticatePassword}`,
async (
req: Request<object, object, StytchTypes.UserLogin>,
res: Response
) => {
const reqBody = req.body;
return await stytchService.loginWithPassword(res, reqBody);
}
);

/* POST: /stytch/password-strength */
stytchRouter.post(
`/${subRoutes.passwordStrength}`,
async (
req: Request<object, object, StytchTypes.PasswordStrengthBody>,
res: Response
) => {
const reqBody = req.body;
return await stytchService.checkPasswordStrength(res, reqBody);
}
);

/* POST: /stytch/authenticate-email-otp */
stytchRouter.post(
`/${subRoutes.authenticateEmailOTP}`,
async (
req: Request<object, object, { code: string }>,
res: Response
) => {
const otpCode = req.body.code;
return await stytchService.verifyOtp(res, otpCode);
}
);

/* GET: /stytch/get-recovery-codes */
stytchRouter.get(
`/${subRoutes.getRecoveryCodes}/:memberId`,
async (
req: Request<StytchTypes.GetMember>,
res: Response
) => {
return await stytchService.getRecoveryCodes(res, req.params.memberId);
}
);

export { stytchRouter };
Loading

0 comments on commit 590ecaa

Please sign in to comment.