diff --git a/Dockerfile b/Dockerfile index c60927f..039751c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,9 +14,12 @@ COPY --from=BUILDER ./package.json ./package.json COPY --from=BUILDER ./package-lock.json ./package-lock.json # Client Files COPY --from=BUILDER ./clients ./clients +# Sites Files +COPY --from=BUILDER ./sites ./sites # Service Files COPY --from=BUILDER ./services/liquid-auth-api-js/ ./services/liquid-auth-api-js/ + RUN npm ci --production # Expose the port on which the app will run diff --git a/Vite.Dockerfile b/Vite.Dockerfile deleted file mode 100644 index f64ba7f..0000000 --- a/Vite.Dockerfile +++ /dev/null @@ -1,12 +0,0 @@ -FROM node:20.12-alpine - -ADD . . - -RUN npm install - -RUN npm run build - - -EXPOSE 5173 - -CMD ["npm", "run", "dev:ui"] diff --git a/docker-compose.yml b/docker-compose.yml index d1b6ebe..999cfe0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3.4' +version: '3.5' services: liquid-auth: @@ -11,20 +11,7 @@ services: depends_on: - redis - mongo - - ngrok - liquid-demo: - restart: no - build: - context: . - dockerfile: Vite.Dockerfile - ports: - - "5173:5173" - environment: - - PROXY_URL=http://liquid-auth:3000 - - WSS_PROXY_SERVER=ws://liquid-auth:3000 - depends_on: - - liquid-auth - - ngrok + command: ["npm", "run", "start:ssr"] ngrok: image: ngrok/ngrok:latest restart: no diff --git a/package-lock.json b/package-lock.json index 612bf4f..b4ea6cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5366,6 +5366,7 @@ "os": [ "darwin" ], + "peer": true, "engines": { "node": ">=10" } @@ -5382,6 +5383,7 @@ "os": [ "darwin" ], + "peer": true, "engines": { "node": ">=10" } @@ -5398,6 +5400,7 @@ "os": [ "linux" ], + "peer": true, "engines": { "node": ">=10" } @@ -5414,6 +5417,7 @@ "os": [ "linux" ], + "peer": true, "engines": { "node": ">=10" } @@ -5430,6 +5434,7 @@ "os": [ "linux" ], + "peer": true, "engines": { "node": ">=10" } @@ -5446,6 +5451,7 @@ "os": [ "linux" ], + "peer": true, "engines": { "node": ">=10" } @@ -5462,6 +5468,7 @@ "os": [ "linux" ], + "peer": true, "engines": { "node": ">=10" } @@ -5478,6 +5485,7 @@ "os": [ "win32" ], + "peer": true, "engines": { "node": ">=10" } @@ -5494,6 +5502,7 @@ "os": [ "win32" ], + "peer": true, "engines": { "node": ">=10" } @@ -5510,6 +5519,7 @@ "os": [ "win32" ], + "peer": true, "engines": { "node": ">=10" } @@ -8456,8 +8466,9 @@ }, "node_modules/cross-env": { "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", "dev": true, - "license": "MIT", "dependencies": { "cross-spawn": "^7.0.1" }, @@ -9723,6 +9734,10 @@ "node": ">= 0.10.0" } }, + "node_modules/express-dapp": { + "resolved": "sites/express-dapp", + "link": true + }, "node_modules/express-session": { "version": "1.17.3", "license": "MIT", @@ -17478,7 +17493,7 @@ "typescript": "^5.3.3" }, "engines": { - "node": ">=18.0.0 <21.0.0" + "node": ">=18.0.0" } }, "sites/dapp-ui": { @@ -17535,6 +17550,41 @@ "funding": { "url": "https://github.com/sponsors/isaacs" } + }, + "sites/express-dapp": { + "version": "0.0.1", + "license": "AGPL-3.0", + "dependencies": { + "@liquid/auth-api": "*", + "@nestjs/common": "^10.0.0", + "@nestjs/core": "^10.0.0", + "@nestjs/platform-express": "^10.0.0", + "reflect-metadata": "^0.1.13", + "rxjs": "^7.8.1" + }, + "devDependencies": { + "@nestjs/cli": "^10.0.0", + "@nestjs/schematics": "^10.0.0", + "@nestjs/testing": "^10.0.0", + "@types/express": "^4.17.17", + "@types/jest": "^29.5.2", + "@types/node": "^20.3.1", + "@types/supertest": "^2.0.12", + "@typescript-eslint/eslint-plugin": "^6.0.0", + "@typescript-eslint/parser": "^6.0.0", + "eslint": "^8.42.0", + "eslint-config-prettier": "^9.0.0", + "eslint-plugin-prettier": "^5.0.0", + "jest": "^29.5.0", + "prettier": "^3.0.0", + "source-map-support": "^0.5.21", + "supertest": "^6.3.3", + "ts-jest": "^29.1.0", + "ts-loader": "^9.4.3", + "ts-node": "^10.9.1", + "tsconfig-paths": "^4.2.0", + "typescript": "^5.1.3" + } } } } diff --git a/package.json b/package.json index 79fb660..23cc77b 100644 --- a/package.json +++ b/package.json @@ -7,11 +7,12 @@ "dev:core": "npm run dev --if-present --workspace @liquid/core", "dev:sdk": "npm run dev --if-present --workspace @liquid/auth-client", "dev:ui": "npm run dev --if-present --workspace dapp-ui", - "build": "npm run build --workspace @liquid/core && npm run build --workspace @liquid/auth-client && npm run build --workspace @liquid/auth-api && npm run build --workspace dapp-ui", + "build": "npm run build --workspace @liquid/core && npm run build --workspace @liquid/auth-client && npm run build --workspace @liquid/auth-api && npm run build --workspace dapp-ui && npm run build --workspace express-dapp", "lint": "npm run lint --if-present --ws", "test": "npm run test --if-present --ws", "test:cov": "npm run test:cov --if-present --ws", - "start": "npm run start:prod --workspace @liquid/auth-api" + "start": "npm run start:prod --workspace @liquid/auth-api", + "start:ssr": "npm run start:prod --workspace express-dapp" }, "workspaces": [ "clients/**", diff --git a/services/liquid-auth-api-js/package.json b/services/liquid-auth-api-js/package.json index eb97b12..495121b 100644 --- a/services/liquid-auth-api-js/package.json +++ b/services/liquid-auth-api-js/package.json @@ -9,6 +9,14 @@ "files": [ "./src/**/*.md" ], + "main": "dist/src/index.js", + "types": "dist/src/index.d.ts", + "exports": { + ".": { + "default": "./dist/src/index.js", + "types": "./dist/src/index.d.ts" + } + }, "scripts": { "build": "nest build", "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", diff --git a/services/liquid-auth-api-js/src/assertion/assertion.controller.ts b/services/liquid-auth-api-js/src/assertion/assertion.controller.ts index c4865b1..854e6be 100644 --- a/services/liquid-auth-api-js/src/assertion/assertion.controller.ts +++ b/services/liquid-auth-api-js/src/assertion/assertion.controller.ts @@ -18,8 +18,6 @@ import { AuthService } from '../auth/auth.service.js'; import { AssertionService } from './assertion.service.js'; import { ClientProxy } from '@nestjs/microservices'; -import { readFileSync } from 'node:fs'; -import { join } from 'node:path'; import { ApiBody, ApiForbiddenResponse, @@ -30,14 +28,9 @@ import { ApiUnauthorizedResponse, } from '@nestjs/swagger'; import { User } from '../auth/auth.schema.js'; -// TODO: Make doc loader utility -const filePath = join(process.cwd(), './src/assertion'); -const requestDescription = readFileSync( - join(filePath, 'assertion.controller.post.request.md'), -).toString(); -const responseDescription = readFileSync( - join(filePath, 'assertion.controller.post.response.md'), -).toString(); +// TODO: make a loader for descriptions +const requestDescription = ''; +const responseDescription = ''; /** * Assertion Controller diff --git a/services/liquid-auth-api-js/src/auth/index.ts b/services/liquid-auth-api-js/src/auth/index.ts new file mode 100644 index 0000000..53a24c7 --- /dev/null +++ b/services/liquid-auth-api-js/src/auth/index.ts @@ -0,0 +1,6 @@ +export * from './auth.controller.js'; +export * from './auth.guard.js'; +export * from './auth.module.js'; +export * from './auth.schema.js'; +export * from './auth.service.js'; +export * from './session.schema.js'; diff --git a/services/liquid-auth-api-js/src/index.ts b/services/liquid-auth-api-js/src/index.ts new file mode 100644 index 0000000..2de8035 --- /dev/null +++ b/services/liquid-auth-api-js/src/index.ts @@ -0,0 +1,5 @@ +export * from './auth/index.js'; +export * from './app.module.js'; +export * from './app.service.js'; +export * from './sentry.filter.js'; +export * from './adapters/redis-io.adapter.js'; diff --git a/sites/express-dapp/.eslintrc.cjs b/sites/express-dapp/.eslintrc.cjs new file mode 100644 index 0000000..fd79ed8 --- /dev/null +++ b/sites/express-dapp/.eslintrc.cjs @@ -0,0 +1,25 @@ +module.exports = { + parser: '@typescript-eslint/parser', + parserOptions: { + project: 'tsconfig.json', + tsconfigRootDir: __dirname, + sourceType: 'module', + }, + plugins: ['@typescript-eslint/eslint-plugin'], + extends: [ + 'plugin:@typescript-eslint/recommended', + 'plugin:prettier/recommended', + ], + root: true, + env: { + node: true, + jest: true, + }, + ignorePatterns: ['.eslintrc.cjs'], + rules: { + '@typescript-eslint/interface-name-prefix': 'off', + '@typescript-eslint/explicit-function-return-type': 'off', + '@typescript-eslint/explicit-module-boundary-types': 'off', + '@typescript-eslint/no-explicit-any': 'off', + }, +}; diff --git a/sites/express-dapp/.gitignore b/sites/express-dapp/.gitignore new file mode 100644 index 0000000..22f55ad --- /dev/null +++ b/sites/express-dapp/.gitignore @@ -0,0 +1,35 @@ +# compiled output +/dist +/node_modules + +# Logs +logs +*.log +npm-debug.log* +pnpm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# OS +.DS_Store + +# Tests +/coverage +/.nyc_output + +# IDEs and editors +/.idea +.project +.classpath +.c9/ +*.launch +.settings/ +*.sublime-workspace + +# IDE - VSCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json \ No newline at end of file diff --git a/sites/express-dapp/.prettierrc b/sites/express-dapp/.prettierrc new file mode 100644 index 0000000..dcb7279 --- /dev/null +++ b/sites/express-dapp/.prettierrc @@ -0,0 +1,4 @@ +{ + "singleQuote": true, + "trailingComma": "all" +} \ No newline at end of file diff --git a/sites/express-dapp/README.md b/sites/express-dapp/README.md new file mode 100644 index 0000000..00a13b1 --- /dev/null +++ b/sites/express-dapp/README.md @@ -0,0 +1,73 @@ +
+ +[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456 +[circleci-url]: https://circleci.com/gh/nestjs/nest + +A progressive Node.js framework for building efficient and scalable server-side applications.
+ + + +## Description + +[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. + +## Installation + +```bash +$ npm install +``` + +## Running the app + +```bash +# development +$ npm run start + +# watch mode +$ npm run start:dev + +# production mode +$ npm run start:prod +``` + +## Test + +```bash +# unit tests +$ npm run test + +# e2e tests +$ npm run test:e2e + +# test coverage +$ npm run test:cov +``` + +## Support + +Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support). + +## Stay in touch + +- Author - [Kamil MyĆliwiec](https://kamilmysliwiec.com) +- Website - [https://nestjs.com](https://nestjs.com/) +- Twitter - [@nestframework](https://twitter.com/nestframework) + +## License + +Nest is [MIT licensed](LICENSE). diff --git a/sites/express-dapp/nest-cli.json b/sites/express-dapp/nest-cli.json new file mode 100644 index 0000000..f9aa683 --- /dev/null +++ b/sites/express-dapp/nest-cli.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://json.schemastore.org/nest-cli", + "collection": "@nestjs/schematics", + "sourceRoot": "src", + "compilerOptions": { + "deleteOutDir": true + } +} diff --git a/sites/express-dapp/package.json b/sites/express-dapp/package.json new file mode 100644 index 0000000..43a9551 --- /dev/null +++ b/sites/express-dapp/package.json @@ -0,0 +1,60 @@ +{ + "name": "express-dapp", + "version": "0.0.1", + "description": "Example Express Application using Liquid Auth App", + "author": "Algorand Foundation", + "private": true, + "type": "module", + "license": "AGPL-3.0", + "scripts": { + "build": "nest build", + "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", + "start": "nest start", + "start:dev": "nest start --watch", + "start:debug": "nest start --debug --watch", + "start:prod": "node dist/main", + "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix" + }, + "dependencies": { + "@liquid/auth-api": "*", + "@nestjs/common": "^10.0.0", + "@nestjs/core": "^10.0.0", + "@nestjs/platform-express": "^10.0.0", + "reflect-metadata": "^0.1.13", + "rxjs": "^7.8.1" + }, + "devDependencies": { + "@nestjs/cli": "^10.0.0", + "@nestjs/schematics": "^10.0.0", + "@types/express": "^4.17.17", + "@types/node": "^20.3.1", + "@typescript-eslint/eslint-plugin": "^6.0.0", + "@typescript-eslint/parser": "^6.0.0", + "eslint": "^8.42.0", + "eslint-config-prettier": "^9.0.0", + "eslint-plugin-prettier": "^5.0.0", + "prettier": "^3.0.0", + "source-map-support": "^0.5.21", + "ts-loader": "^9.4.3", + "ts-node": "^10.9.1", + "tsconfig-paths": "^4.2.0", + "typescript": "^5.1.3" + }, + "jest": { + "moduleFileExtensions": [ + "js", + "json", + "ts" + ], + "rootDir": "src", + "testRegex": ".*\\.spec\\.ts$", + "transform": { + "^.+\\.(t|j)s$": "ts-jest" + }, + "collectCoverageFrom": [ + "**/*.(t|j)s" + ], + "coverageDirectory": "../coverage", + "testEnvironment": "node" + } +} diff --git a/sites/express-dapp/src/app.controller.ts b/sites/express-dapp/src/app.controller.ts new file mode 100644 index 0000000..83caa17 --- /dev/null +++ b/sites/express-dapp/src/app.controller.ts @@ -0,0 +1,17 @@ +import { Controller, Get, Render, UseGuards } from '@nestjs/common'; +import { AuthGuard } from '@liquid/auth-api'; + +@Controller() +export class AppController { + constructor() {} + + @Get('protected') + @UseGuards(AuthGuard) + getProtected() { + return 'Protected route'; + } + + @Get() + @Render('index') + getIndex() {} +} diff --git a/sites/express-dapp/src/app.module.ts b/sites/express-dapp/src/app.module.ts new file mode 100644 index 0000000..4e79341 --- /dev/null +++ b/sites/express-dapp/src/app.module.ts @@ -0,0 +1,9 @@ +import { Module } from '@nestjs/common'; +import { AppController } from './app.controller.js'; + +@Module({ + imports: [], + controllers: [AppController], + providers: [], +}) +export class AppModule {} diff --git a/sites/express-dapp/src/main.ts b/sites/express-dapp/src/main.ts new file mode 100644 index 0000000..0914091 --- /dev/null +++ b/sites/express-dapp/src/main.ts @@ -0,0 +1,68 @@ +import 'dotenv/config'; +import { NestFactory } from '@nestjs/core'; +import type { NestExpressApplication } from '@nestjs/platform-express'; +import { ConfigService } from '@nestjs/config'; + +// Application +import { AppModule, RedisIoAdapter } from '@liquid/auth-api'; + +// Session +import session from 'express-session'; +import MongoStore from 'connect-mongo'; + +import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; +import { dirname, join } from 'path'; +import { fileURLToPath } from 'url'; + +const __dirname = dirname(fileURLToPath(import.meta.url)); + +async function bootstrap() { + const app = await NestFactory.create