From 39d658188dc4e213cbe9c8e1e462cbf95f2661df Mon Sep 17 00:00:00 2001 From: hxtree Date: Thu, 22 Feb 2024 03:44:34 +0000 Subject: [PATCH 1/3] feat: change authentication service to user service Signed-off-by: hxtree --- .../src/components/SignupForm.tsx | 89 +++-- common/config/rush/pnpm-lock.yaml | 344 +++++++++--------- common/config/rush/repo-state.json | 2 +- middleware/api/.env.dist | 3 +- .../api/src/modules/router/router.service.ts | 33 +- .../__snapshots__/main.stack.test.ts.snap | 3 +- middleware/api/stacks/main.stack.ts | 2 +- rush.json | 4 +- .../.env.dist | 0 .../.eslintrc.js | 0 .../CHANGELOG.json | 0 .../CHANGELOG.md | 0 .../README.md | 0 .../bin/app.ts | 0 .../cdk.json | 0 .../jest-mongodb-config.js | 0 .../jest.config.json | 0 .../openapi-spec.json | 0 .../package.json | 6 +- .../src/app.module.ts | 0 .../src/index.ts | 0 .../src/main.ts | 0 .../src/models/user.repository.ts | 0 .../src/models/user.schema.ts | 0 .../src/modules/auth/auth.controller.ts | 0 .../src/modules/auth/auth.e2e-spec.ts | 0 .../src/modules/auth/auth.module.ts | 0 .../src/modules/auth/auth.service.ts | 0 .../src/modules/auth/cognito.service.ts | 0 .../src/modules/auth/confirm-sign-up.dto.ts | 0 .../src/modules/auth/constants.ts | 0 .../src/modules/auth/forgot-password.dto.ts | 0 .../src/modules/auth/jwt-auth.guard.ts | 0 .../src/modules/auth/jwt.strategy.ts | 0 .../src/modules/auth/login.dto.ts | 0 .../src/modules/auth/reset-password.dto.ts | 0 .../src/modules/auth/sign-up.dto.ts | 0 .../src/modules/health/health.controller.ts | 0 .../src/modules/health/health.e2e-spec.ts | 0 .../src/modules/health/health.module.ts | 0 .../src/modules/user/create-user.dto.ts | 0 .../src/modules/user/query-user.dto.ts | 0 .../src/modules/user/user.controller.ts | 0 .../src/modules/user/user.e2e-spec.ts | 0 .../src/modules/user/user.module.ts | 0 .../src/modules/user/user.service.ts | 0 .../auth-service.stack.test.ts.snap | 128 +++---- .../stacks/auth-service.stack.test.ts | 0 .../stacks/auth-service.stack.ts | 14 +- .../stacks/cognito-pool.ts | 0 .../tsconfig.json | 0 51 files changed, 347 insertions(+), 281 deletions(-) rename services/{authentication-service => user-service}/.env.dist (100%) rename services/{authentication-service => user-service}/.eslintrc.js (100%) rename services/{authentication-service => user-service}/CHANGELOG.json (100%) rename services/{authentication-service => user-service}/CHANGELOG.md (100%) rename services/{authentication-service => user-service}/README.md (100%) rename services/{authentication-service => user-service}/bin/app.ts (100%) rename services/{authentication-service => user-service}/cdk.json (100%) rename services/{authentication-service => user-service}/jest-mongodb-config.js (100%) rename services/{authentication-service => user-service}/jest.config.json (100%) rename services/{authentication-service => user-service}/openapi-spec.json (100%) rename services/{authentication-service => user-service}/package.json (94%) rename services/{authentication-service => user-service}/src/app.module.ts (100%) rename services/{authentication-service => user-service}/src/index.ts (100%) rename services/{authentication-service => user-service}/src/main.ts (100%) rename services/{authentication-service => user-service}/src/models/user.repository.ts (100%) rename services/{authentication-service => user-service}/src/models/user.schema.ts (100%) rename services/{authentication-service => user-service}/src/modules/auth/auth.controller.ts (100%) rename services/{authentication-service => user-service}/src/modules/auth/auth.e2e-spec.ts (100%) rename services/{authentication-service => user-service}/src/modules/auth/auth.module.ts (100%) rename services/{authentication-service => user-service}/src/modules/auth/auth.service.ts (100%) rename services/{authentication-service => user-service}/src/modules/auth/cognito.service.ts (100%) rename services/{authentication-service => user-service}/src/modules/auth/confirm-sign-up.dto.ts (100%) rename services/{authentication-service => user-service}/src/modules/auth/constants.ts (100%) rename services/{authentication-service => user-service}/src/modules/auth/forgot-password.dto.ts (100%) rename services/{authentication-service => user-service}/src/modules/auth/jwt-auth.guard.ts (100%) rename services/{authentication-service => user-service}/src/modules/auth/jwt.strategy.ts (100%) rename services/{authentication-service => user-service}/src/modules/auth/login.dto.ts (100%) rename services/{authentication-service => user-service}/src/modules/auth/reset-password.dto.ts (100%) rename services/{authentication-service => user-service}/src/modules/auth/sign-up.dto.ts (100%) rename services/{authentication-service => user-service}/src/modules/health/health.controller.ts (100%) rename services/{authentication-service => user-service}/src/modules/health/health.e2e-spec.ts (100%) rename services/{authentication-service => user-service}/src/modules/health/health.module.ts (100%) rename services/{authentication-service => user-service}/src/modules/user/create-user.dto.ts (100%) rename services/{authentication-service => user-service}/src/modules/user/query-user.dto.ts (100%) rename services/{authentication-service => user-service}/src/modules/user/user.controller.ts (100%) rename services/{authentication-service => user-service}/src/modules/user/user.e2e-spec.ts (100%) rename services/{authentication-service => user-service}/src/modules/user/user.module.ts (100%) rename services/{authentication-service => user-service}/src/modules/user/user.service.ts (100%) rename services/{authentication-service => user-service}/stacks/__snapshots__/auth-service.stack.test.ts.snap (94%) rename services/{authentication-service => user-service}/stacks/auth-service.stack.test.ts (100%) rename services/{authentication-service => user-service}/stacks/auth-service.stack.ts (90%) rename services/{authentication-service => user-service}/stacks/cognito-pool.ts (100%) rename services/{authentication-service => user-service}/tsconfig.json (100%) diff --git a/clients/admin-client/src/components/SignupForm.tsx b/clients/admin-client/src/components/SignupForm.tsx index 099e4cd9c..9ca32266e 100644 --- a/clients/admin-client/src/components/SignupForm.tsx +++ b/clients/admin-client/src/components/SignupForm.tsx @@ -1,45 +1,92 @@ import { FC, useState } from "react"; import { FontAwesomeIcon, faArrowRight, TextField, Button } from '@cats-cradle/design-system/dist/main'; import React from 'react'; +import axios from 'axios'; -type TSignupForm = { +type TSignupFormProps = { title?: string; }; -export const SignupForm: FC = ({ title }) => { +enum TSignupFormType { + SignUp, + Verify +} + +export const SignupForm: FC = ({ title }) => { const [isLoading, setIsLoading] = useState(false); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); + const [securityCode, setSecurityCode] = useState(''); + const [currentForm, setCurrentForm] = useState(TSignupFormType.SignUp); + + const parentDomainName = import.meta.env.VITE_PARENT_DOMAIN_NAME ?? 'sandbox.nekosgate.com'; async function createUser() { - // Now use the email and password states here - console.log("Email:", email); - console.log("Password:", password); - // await axios.post() - // set isLoading + try { + setIsLoading(true); + const response = await axios.post( + `https://api.${parentDomainName}/user/auth/sign-up`, + { email: email, password: password } + ); + console.log("User created successfully:", response.data); + setCurrentForm(TSignupFormType.Verify); + } catch (error) { + console.error("Error creating user:", error); + } finally { + setIsLoading(false); + } + } + + async function verifyAccount() { + try { + setIsLoading(true); + const response = await axios.post( + `https://api.${parentDomainName}/user/auth/confirm-sign-up`, + { email: email, code: securityCode } + ); + console.log("Account verified successfully:", response.data); + } catch (error) { + console.error("Error verifying account:", error); + } finally { + setIsLoading(false); + } } function onClickHandler(event: React.MouseEvent) { - setIsLoading(true); - createUser(); // Call createUser when the button is clicked - console.log(event); - return; + if (currentForm === TSignupFormType.SignUp) { + createUser(); + } else { + verifyAccount(); + } } return (
-

Create an account

-
- {/* Bind the value and onChange to the email state */} - setEmail(e.target.value)} /> -
-
- {/* Bind the value and onChange to the password state */} - setPassword(e.target.value)} /> -
+ {currentForm === TSignupFormType.SignUp && ( +
+

Create an account

+
+ setEmail(e.target.value)} /> +
+
+ setPassword(e.target.value)} /> +
+
+ )} + + {currentForm === TSignupFormType.Verify && ( +
+

Verify Your Account

+

Check your email for the verification code.

+
+ setSecurityCode(e.target.value)} /> +
+
+ )} +
diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 46ac35e7c..cc25e751a 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -1784,178 +1784,6 @@ importers: specifier: 5.3.3 version: 5.3.3 - ../../services/authentication-service: - dependencies: - '@aws-sdk/client-cognito-identity-provider': - specifier: 3.10.0 - version: 3.10.0(react-native@0.72.7) - '@aws-sdk/client-ssm': - specifier: 3.10.0 - version: 3.10.0(react-native@0.72.7) - '@aws-sdk/types': - specifier: 3.10.0 - version: 3.10.0 - '@cats-cradle/base-nodejs': - specifier: workspace:* - version: link:../../platform/rigs/base-nodejs - '@cats-cradle/constructs': - specifier: workspace:* - version: link:../../platform/constructs - '@cats-cradle/nestjs-modules': - specifier: workspace:* - version: link:../../libraries/nestjs-modules - '@cats-cradle/validation-schemas': - specifier: workspace:* - version: link:../../libraries/validation-schemas - '@nestjs/common': - specifier: 9.4.0 - version: 9.4.0(class-transformer@0.5.1)(class-validator@0.13.2)(reflect-metadata@0.1.13)(rxjs@7.8.1) - '@nestjs/config': - specifier: 2.2.0 - version: 2.2.0(@nestjs/common@9.4.0)(reflect-metadata@0.1.13)(rxjs@7.8.1) - '@nestjs/core': - specifier: 9.2.1 - version: 9.2.1(@nestjs/common@9.4.0)(@nestjs/platform-express@9.3.9)(reflect-metadata@0.1.13)(rxjs@7.8.1) - '@nestjs/jwt': - specifier: ~10.1.1 - version: 10.1.1(@nestjs/common@9.4.0) - '@nestjs/mongoose': - specifier: 9.2.1 - version: 9.2.1(@nestjs/common@9.4.0)(@nestjs/core@9.2.1)(mongoose@6.11.3)(reflect-metadata@0.1.13)(rxjs@7.8.1) - '@nestjs/passport': - specifier: 9.0.0 - version: 9.0.0(@nestjs/common@9.4.0)(passport@0.6.0) - '@nestjs/platform-express': - specifier: 9.3.9 - version: 9.3.9(@nestjs/common@9.4.0)(@nestjs/core@9.2.1) - '@nestjs/swagger': - specifier: ~7.1.17 - version: 7.1.17(@fastify/static@6.9.0)(@nestjs/common@9.4.0)(@nestjs/core@9.2.1)(class-transformer@0.5.1)(class-validator@0.13.2)(reflect-metadata@0.1.13) - '@nestjs/terminus': - specifier: 9.1.1 - version: 9.1.1(@nestjs/common@9.4.0)(@nestjs/core@9.2.1)(reflect-metadata@0.1.13)(rxjs@7.8.1) - '@types/passport-jwt': - specifier: ~3.0.10 - version: 3.0.10 - '@vendia/serverless-express': - specifier: 4.12.6 - version: 4.12.6 - aws-lambda: - specifier: 1.0.7 - version: 1.0.7 - aws-serverless-express: - specifier: ~3.4.0 - version: 3.4.0 - class-transformer: - specifier: 0.5.1 - version: 0.5.1 - class-validator: - specifier: 0.13.2 - version: 0.13.2 - express: - specifier: 4.18.2 - version: 4.18.2 - mongoose: - specifier: 6.11.3 - version: 6.11.3 - node-cache: - specifier: 5.1.2 - version: 5.1.2 - passport: - specifier: ~0.6.0 - version: 0.6.0 - passport-jwt: - specifier: ~4.0.1 - version: 4.0.1 - reflect-metadata: - specifier: 0.1.13 - version: 0.1.13 - rxjs: - specifier: 7.8.1 - version: 7.8.1 - source-map-support: - specifier: ~0.5.21 - version: 0.5.21 - uuid: - specifier: ~9.0.1 - version: 9.0.1 - devDependencies: - '@cats-cradle/create-artifact': - specifier: 2.0.6 - version: 2.0.6(@yarnpkg/core@4.0.0-rc.51)(typanion@3.14.0) - '@cats-cradle/create-bundle': - specifier: 1.0.12 - version: 1.0.12(@babel/core@7.23.5)(@types/node@20.10.5)(ts-node@10.9.2)(typescript@5.3.3) - '@cats-cradle/eslint-config': - specifier: 1.0.11 - version: 1.0.11 - '@cats-cradle/faker-factory': - specifier: workspace:* - version: link:../../libraries/faker-factory - '@microsoft/tsdoc': - specifier: ~0.13.2 - version: 0.13.2 - '@nestjs/testing': - specifier: 9.2.1 - version: 9.2.1(@nestjs/common@9.4.0)(@nestjs/core@9.2.1)(@nestjs/platform-express@9.3.9) - '@shelf/jest-mongodb': - specifier: ~4.1.7 - version: 4.1.7(jest-environment-node@29.7.0)(mongodb@5.9.0) - '@types/aws-lambda': - specifier: ~8.10.130 - version: 8.10.130 - '@types/express': - specifier: ~4.17.21 - version: 4.17.21 - '@types/jest': - specifier: 29.5.11 - version: 29.5.11 - '@types/node': - specifier: 20.10.5 - version: 20.10.5 - '@types/passport': - specifier: ~1.0.13 - version: 1.0.13 - '@types/supertest': - specifier: ~2.0.16 - version: 2.0.16 - '@types/uuid': - specifier: ~9.0.7 - version: 9.0.7 - aws-cdk-lib: - specifier: 2.95.0 - version: 2.95.0(constructs@10.2.70) - constructs: - specifier: ^10.2.70 - version: 10.2.70 - esbuild: - specifier: ~0.17.5 - version: 0.17.5 - eslint: - specifier: 8.56.0 - version: 8.56.0 - fs: - specifier: ~0.0.1-security - version: 0.0.1-security - jest: - specifier: 29.7.0 - version: 29.7.0(@types/node@20.10.5)(ts-node@10.9.2) - path: - specifier: ~0.12.7 - version: 0.12.7 - supertest: - specifier: ~6.3.3 - version: 6.3.3 - ts-jest: - specifier: 29.1.1 - version: 29.1.1(@babel/core@7.23.5)(esbuild@0.17.5)(jest@29.7.0)(typescript@5.3.3) - ts-node: - specifier: 10.9.2 - version: 10.9.2(@types/node@20.10.5)(typescript@5.3.3) - typescript: - specifier: 5.3.3 - version: 5.3.3 - ../../services/billing-system: dependencies: '@cats-cradle/base-nodejs': @@ -2987,6 +2815,178 @@ importers: specifier: 5.3.3 version: 5.3.3 + ../../services/user-service: + dependencies: + '@aws-sdk/client-cognito-identity-provider': + specifier: 3.10.0 + version: 3.10.0(react-native@0.72.7) + '@aws-sdk/client-ssm': + specifier: 3.10.0 + version: 3.10.0(react-native@0.72.7) + '@aws-sdk/types': + specifier: 3.10.0 + version: 3.10.0 + '@cats-cradle/base-nodejs': + specifier: workspace:* + version: link:../../platform/rigs/base-nodejs + '@cats-cradle/constructs': + specifier: workspace:* + version: link:../../platform/constructs + '@cats-cradle/nestjs-modules': + specifier: workspace:* + version: link:../../libraries/nestjs-modules + '@cats-cradle/validation-schemas': + specifier: workspace:* + version: link:../../libraries/validation-schemas + '@nestjs/common': + specifier: 9.4.0 + version: 9.4.0(class-transformer@0.5.1)(class-validator@0.13.2)(reflect-metadata@0.1.13)(rxjs@7.8.1) + '@nestjs/config': + specifier: 2.2.0 + version: 2.2.0(@nestjs/common@9.4.0)(reflect-metadata@0.1.13)(rxjs@7.8.1) + '@nestjs/core': + specifier: 9.2.1 + version: 9.2.1(@nestjs/common@9.4.0)(@nestjs/platform-express@9.3.9)(reflect-metadata@0.1.13)(rxjs@7.8.1) + '@nestjs/jwt': + specifier: ~10.1.1 + version: 10.1.1(@nestjs/common@9.4.0) + '@nestjs/mongoose': + specifier: 9.2.1 + version: 9.2.1(@nestjs/common@9.4.0)(@nestjs/core@9.2.1)(mongoose@6.11.3)(reflect-metadata@0.1.13)(rxjs@7.8.1) + '@nestjs/passport': + specifier: 9.0.0 + version: 9.0.0(@nestjs/common@9.4.0)(passport@0.6.0) + '@nestjs/platform-express': + specifier: 9.3.9 + version: 9.3.9(@nestjs/common@9.4.0)(@nestjs/core@9.2.1) + '@nestjs/swagger': + specifier: ~7.1.17 + version: 7.1.17(@fastify/static@6.9.0)(@nestjs/common@9.4.0)(@nestjs/core@9.2.1)(class-transformer@0.5.1)(class-validator@0.13.2)(reflect-metadata@0.1.13) + '@nestjs/terminus': + specifier: 9.1.1 + version: 9.1.1(@nestjs/common@9.4.0)(@nestjs/core@9.2.1)(reflect-metadata@0.1.13)(rxjs@7.8.1) + '@types/passport-jwt': + specifier: ~3.0.10 + version: 3.0.10 + '@vendia/serverless-express': + specifier: 4.12.6 + version: 4.12.6 + aws-lambda: + specifier: 1.0.7 + version: 1.0.7 + aws-serverless-express: + specifier: ~3.4.0 + version: 3.4.0 + class-transformer: + specifier: 0.5.1 + version: 0.5.1 + class-validator: + specifier: 0.13.2 + version: 0.13.2 + express: + specifier: 4.18.2 + version: 4.18.2 + mongoose: + specifier: 6.11.3 + version: 6.11.3 + node-cache: + specifier: 5.1.2 + version: 5.1.2 + passport: + specifier: ~0.6.0 + version: 0.6.0 + passport-jwt: + specifier: ~4.0.1 + version: 4.0.1 + reflect-metadata: + specifier: 0.1.13 + version: 0.1.13 + rxjs: + specifier: 7.8.1 + version: 7.8.1 + source-map-support: + specifier: ~0.5.21 + version: 0.5.21 + uuid: + specifier: ~9.0.1 + version: 9.0.1 + devDependencies: + '@cats-cradle/create-artifact': + specifier: 2.0.6 + version: 2.0.6(@yarnpkg/core@4.0.0-rc.51)(typanion@3.14.0) + '@cats-cradle/create-bundle': + specifier: 1.0.12 + version: 1.0.12(@babel/core@7.23.5)(@types/node@20.10.5)(ts-node@10.9.2)(typescript@5.3.3) + '@cats-cradle/eslint-config': + specifier: 1.0.11 + version: 1.0.11 + '@cats-cradle/faker-factory': + specifier: workspace:* + version: link:../../libraries/faker-factory + '@microsoft/tsdoc': + specifier: ~0.13.2 + version: 0.13.2 + '@nestjs/testing': + specifier: 9.2.1 + version: 9.2.1(@nestjs/common@9.4.0)(@nestjs/core@9.2.1)(@nestjs/platform-express@9.3.9) + '@shelf/jest-mongodb': + specifier: ~4.1.7 + version: 4.1.7(jest-environment-node@29.7.0)(mongodb@5.9.0) + '@types/aws-lambda': + specifier: ~8.10.130 + version: 8.10.130 + '@types/express': + specifier: ~4.17.21 + version: 4.17.21 + '@types/jest': + specifier: 29.5.11 + version: 29.5.11 + '@types/node': + specifier: 20.10.5 + version: 20.10.5 + '@types/passport': + specifier: ~1.0.13 + version: 1.0.13 + '@types/supertest': + specifier: ~2.0.16 + version: 2.0.16 + '@types/uuid': + specifier: ~9.0.7 + version: 9.0.7 + aws-cdk-lib: + specifier: 2.95.0 + version: 2.95.0(constructs@10.2.70) + constructs: + specifier: ^10.2.70 + version: 10.2.70 + esbuild: + specifier: ~0.17.5 + version: 0.17.5 + eslint: + specifier: 8.56.0 + version: 8.56.0 + fs: + specifier: ~0.0.1-security + version: 0.0.1-security + jest: + specifier: 29.7.0 + version: 29.7.0(@types/node@20.10.5)(ts-node@10.9.2) + path: + specifier: ~0.12.7 + version: 0.12.7 + supertest: + specifier: ~6.3.3 + version: 6.3.3 + ts-jest: + specifier: 29.1.1 + version: 29.1.1(@babel/core@7.23.5)(esbuild@0.17.5)(jest@29.7.0)(typescript@5.3.3) + ts-node: + specifier: 10.9.2 + version: 10.9.2(@types/node@20.10.5)(typescript@5.3.3) + typescript: + specifier: 5.3.3 + version: 5.3.3 + ../../services/weather-control: dependencies: '@cats-cradle/base-nodejs': diff --git a/common/config/rush/repo-state.json b/common/config/rush/repo-state.json index 80413789c..410e4bbad 100644 --- a/common/config/rush/repo-state.json +++ b/common/config/rush/repo-state.json @@ -1,5 +1,5 @@ // DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush. { - "pnpmShrinkwrapHash": "e736b55283186590bffc8945d9dc6f5923fb2009", + "pnpmShrinkwrapHash": "8e49bea46048448dd545ab40be0a9b738d0a6549", "preferredVersionsHash": "a48003cf229dd47d077bcf6301ac15a6f90e1c34" } diff --git a/middleware/api/.env.dist b/middleware/api/.env.dist index af0ef7637..3995326b2 100644 --- a/middleware/api/.env.dist +++ b/middleware/api/.env.dist @@ -3,4 +3,5 @@ EMAIL_SERVICE_SVC_DOMAIN_NAME = email-message.sandbox.nekosgate.com HTML_TO_PDF_SVC_DOMAIN_NAME = html-to-pdf.sandbox.nekosgate.com INSTANCES_SVC_DOMAIN_NAME = instances.sandbox.nekosgate.com LUCK_BY_DICE_SVC_DOMAIN_NAME = luck-by-dice.sandbox.nekosgate.com -PLAYER_ACHIEVEMENTS_SVC_DOMAIN_NAME = player-achievements.sandbox.nekosgate.com \ No newline at end of file +PLAYER_ACHIEVEMENTS_SVC_DOMAIN_NAME = player-achievements.sandbox.nekosgate.com +USER_SVC_DOMAIN_NAME = user.sandbox.nekosgate.com \ No newline at end of file diff --git a/middleware/api/src/modules/router/router.service.ts b/middleware/api/src/modules/router/router.service.ts index 29567e3d9..b6b505930 100644 --- a/middleware/api/src/modules/router/router.service.ts +++ b/middleware/api/src/modules/router/router.service.ts @@ -3,31 +3,47 @@ import { Injectable } from '@nestjs/common'; import axios, { AxiosResponse } from 'axios'; import { v4 as uuidv4 } from 'uuid'; +type TRoute = { + path: string; + name: string; + endpoint: string; +}; + @Injectable() export class RouterService { - private readonly routes: { path: string; endpoint: string }[] = [ + private readonly routes: TRoute[] = [ { - path: '/auth', - endpoint: process.env.AUTH_SVC_DOMAIN_NAME || '', + name: 'users_url', + path: '/user', + endpoint: process.env.USER_SVC_DOMAIN_NAME || '', }, { + name: 'character_sheets_url', path: '/character-sheets', endpoint: process.env.CHARACTER_SHEETS_SVC_DOMAIN_NAME || '', }, { + name: 'email_messages_url', path: '/email-message', endpoint: process.env.EMAIL_MESSAGE_SVC_DOMAIN_NAME || '', }, { + name: 'html_to_pdf_url', path: '/html-to-pdf', endpoint: process.env.HTML_TO_PDF_SVC_DOMAIN_NAME || '', }, { + name: 'instances_url', path: '/instances', endpoint: process.env.INSTANCES_SVC_DOMAIN_NAME || '', }, - { path: '/dice', endpoint: process.env.LUCK_BY_DICE_SVC_DOMAIN_NAME || '' }, { + name: 'dice_url', + path: '/dice', + endpoint: process.env.LUCK_BY_DICE_SVC_DOMAIN_NAME || '', + }, + { + name: 'player_achievements_url', path: '/player-achievements', endpoint: process.env.PLAYER_ACHIEVEMENTS_SVC_DOMAIN_NAME || '', }, @@ -95,8 +111,13 @@ export class RouterService { return response.data; } - getRoutes(): { path: string; endpoint: string }[] { - return this.routes; + // TODO remove endpoint + getRoutes(): { [key: string]: { path: string; endpoint: string } } { + const urls: { [key: string]: { path: string; endpoint: string } } = {}; + this.routes.forEach((route: TRoute) => { + urls[route.name] = { path: route.path, endpoint: route.endpoint }; + }); + return urls; } private getRouteForPath( diff --git a/middleware/api/stacks/__snapshots__/main.stack.test.ts.snap b/middleware/api/stacks/__snapshots__/main.stack.test.ts.snap index 655f2949e..7412ab4e2 100644 --- a/middleware/api/stacks/__snapshots__/main.stack.test.ts.snap +++ b/middleware/api/stacks/__snapshots__/main.stack.test.ts.snap @@ -627,7 +627,7 @@ exports[`MainStack should match snapshot test 1`] = ` S3Bucket: { Fn::Sub: cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}, }, - S3Key: 8b09b3678df3d161862dbb5019405aac57973c5acd68cb442e19b9b7a1669e4f.zip, + S3Key: 84733bfcc0860a158020056aeea6de14f9009718cf2a83659cde3585250b04a6.zip, }, Environment: { Variables: { @@ -650,6 +650,7 @@ exports[`MainStack should match snapshot test 1`] = ` }, PLAYER_ACHIEVEMENTS_SVC_DOMAIN_NAME: {{resolve:ssm:/PLAYER_ACHIEVEMENTS_SVC_DOMAIN_NAME}}, STAGE_NAME: default, + USER_SVC_DOMAIN_NAME: {{resolve:ssm:/USER_SVC_DOMAIN_NAME}}, }, }, Handler: index.handler, diff --git a/middleware/api/stacks/main.stack.ts b/middleware/api/stacks/main.stack.ts index 17e0fffca..2f1cdcf44 100644 --- a/middleware/api/stacks/main.stack.ts +++ b/middleware/api/stacks/main.stack.ts @@ -11,7 +11,7 @@ interface Secret { export class MainStack extends cdk.Stack { secrets: Secret[] = [ - { key: 'AUTH_SVC_DOMAIN_NAME' }, + { key: 'USER_SVC_DOMAIN_NAME' }, { key: 'CHARACTER_SHEETS_SVC_DOMAIN_NAME' }, { key: 'EMAIL_SERVICE_SVC_DOMAIN_NAME' }, { key: 'HTML_TO_PDF_SVC_DOMAIN_NAME' }, diff --git a/rush.json b/rush.json index 42266c234..6b0dcf5a2 100644 --- a/rush.json +++ b/rush.json @@ -224,8 +224,8 @@ "tags": ["middleware", "cimongo"] }, { - "packageName": "@cats-cradle/authentication-service", - "projectFolder": "services/authentication-service", + "packageName": "@cats-cradle/user-service", + "projectFolder": "services/user-service", "reviewCategory": "apis", "decoupledLocalDependencies": [ "@cats-cradle/validation-schemas", diff --git a/services/authentication-service/.env.dist b/services/user-service/.env.dist similarity index 100% rename from services/authentication-service/.env.dist rename to services/user-service/.env.dist diff --git a/services/authentication-service/.eslintrc.js b/services/user-service/.eslintrc.js similarity index 100% rename from services/authentication-service/.eslintrc.js rename to services/user-service/.eslintrc.js diff --git a/services/authentication-service/CHANGELOG.json b/services/user-service/CHANGELOG.json similarity index 100% rename from services/authentication-service/CHANGELOG.json rename to services/user-service/CHANGELOG.json diff --git a/services/authentication-service/CHANGELOG.md b/services/user-service/CHANGELOG.md similarity index 100% rename from services/authentication-service/CHANGELOG.md rename to services/user-service/CHANGELOG.md diff --git a/services/authentication-service/README.md b/services/user-service/README.md similarity index 100% rename from services/authentication-service/README.md rename to services/user-service/README.md diff --git a/services/authentication-service/bin/app.ts b/services/user-service/bin/app.ts similarity index 100% rename from services/authentication-service/bin/app.ts rename to services/user-service/bin/app.ts diff --git a/services/authentication-service/cdk.json b/services/user-service/cdk.json similarity index 100% rename from services/authentication-service/cdk.json rename to services/user-service/cdk.json diff --git a/services/authentication-service/jest-mongodb-config.js b/services/user-service/jest-mongodb-config.js similarity index 100% rename from services/authentication-service/jest-mongodb-config.js rename to services/user-service/jest-mongodb-config.js diff --git a/services/authentication-service/jest.config.json b/services/user-service/jest.config.json similarity index 100% rename from services/authentication-service/jest.config.json rename to services/user-service/jest.config.json diff --git a/services/authentication-service/openapi-spec.json b/services/user-service/openapi-spec.json similarity index 100% rename from services/authentication-service/openapi-spec.json rename to services/user-service/openapi-spec.json diff --git a/services/authentication-service/package.json b/services/user-service/package.json similarity index 94% rename from services/authentication-service/package.json rename to services/user-service/package.json index 2881ffb57..adcbda995 100644 --- a/services/authentication-service/package.json +++ b/services/user-service/package.json @@ -1,13 +1,13 @@ { - "name": "@cats-cradle/authentication-service", + "name": "@cats-cradle/user-service", "module": "commonjs", - "description": "authentication service", + "description": "user service", "version": "1.1.4", "scripts": { "dev": "nest start --debug --watch", "build": "tsc", "build:all": "rush build -t .", - "artifact": "create-artifact @cats-cradle/authentication-service", + "artifact": "create-artifact @cats-cradle/user-service", "watch": "tsc -w", "test": "jest --runInBand", "test:cov": "jest --coverage --runInBand", diff --git a/services/authentication-service/src/app.module.ts b/services/user-service/src/app.module.ts similarity index 100% rename from services/authentication-service/src/app.module.ts rename to services/user-service/src/app.module.ts diff --git a/services/authentication-service/src/index.ts b/services/user-service/src/index.ts similarity index 100% rename from services/authentication-service/src/index.ts rename to services/user-service/src/index.ts diff --git a/services/authentication-service/src/main.ts b/services/user-service/src/main.ts similarity index 100% rename from services/authentication-service/src/main.ts rename to services/user-service/src/main.ts diff --git a/services/authentication-service/src/models/user.repository.ts b/services/user-service/src/models/user.repository.ts similarity index 100% rename from services/authentication-service/src/models/user.repository.ts rename to services/user-service/src/models/user.repository.ts diff --git a/services/authentication-service/src/models/user.schema.ts b/services/user-service/src/models/user.schema.ts similarity index 100% rename from services/authentication-service/src/models/user.schema.ts rename to services/user-service/src/models/user.schema.ts diff --git a/services/authentication-service/src/modules/auth/auth.controller.ts b/services/user-service/src/modules/auth/auth.controller.ts similarity index 100% rename from services/authentication-service/src/modules/auth/auth.controller.ts rename to services/user-service/src/modules/auth/auth.controller.ts diff --git a/services/authentication-service/src/modules/auth/auth.e2e-spec.ts b/services/user-service/src/modules/auth/auth.e2e-spec.ts similarity index 100% rename from services/authentication-service/src/modules/auth/auth.e2e-spec.ts rename to services/user-service/src/modules/auth/auth.e2e-spec.ts diff --git a/services/authentication-service/src/modules/auth/auth.module.ts b/services/user-service/src/modules/auth/auth.module.ts similarity index 100% rename from services/authentication-service/src/modules/auth/auth.module.ts rename to services/user-service/src/modules/auth/auth.module.ts diff --git a/services/authentication-service/src/modules/auth/auth.service.ts b/services/user-service/src/modules/auth/auth.service.ts similarity index 100% rename from services/authentication-service/src/modules/auth/auth.service.ts rename to services/user-service/src/modules/auth/auth.service.ts diff --git a/services/authentication-service/src/modules/auth/cognito.service.ts b/services/user-service/src/modules/auth/cognito.service.ts similarity index 100% rename from services/authentication-service/src/modules/auth/cognito.service.ts rename to services/user-service/src/modules/auth/cognito.service.ts diff --git a/services/authentication-service/src/modules/auth/confirm-sign-up.dto.ts b/services/user-service/src/modules/auth/confirm-sign-up.dto.ts similarity index 100% rename from services/authentication-service/src/modules/auth/confirm-sign-up.dto.ts rename to services/user-service/src/modules/auth/confirm-sign-up.dto.ts diff --git a/services/authentication-service/src/modules/auth/constants.ts b/services/user-service/src/modules/auth/constants.ts similarity index 100% rename from services/authentication-service/src/modules/auth/constants.ts rename to services/user-service/src/modules/auth/constants.ts diff --git a/services/authentication-service/src/modules/auth/forgot-password.dto.ts b/services/user-service/src/modules/auth/forgot-password.dto.ts similarity index 100% rename from services/authentication-service/src/modules/auth/forgot-password.dto.ts rename to services/user-service/src/modules/auth/forgot-password.dto.ts diff --git a/services/authentication-service/src/modules/auth/jwt-auth.guard.ts b/services/user-service/src/modules/auth/jwt-auth.guard.ts similarity index 100% rename from services/authentication-service/src/modules/auth/jwt-auth.guard.ts rename to services/user-service/src/modules/auth/jwt-auth.guard.ts diff --git a/services/authentication-service/src/modules/auth/jwt.strategy.ts b/services/user-service/src/modules/auth/jwt.strategy.ts similarity index 100% rename from services/authentication-service/src/modules/auth/jwt.strategy.ts rename to services/user-service/src/modules/auth/jwt.strategy.ts diff --git a/services/authentication-service/src/modules/auth/login.dto.ts b/services/user-service/src/modules/auth/login.dto.ts similarity index 100% rename from services/authentication-service/src/modules/auth/login.dto.ts rename to services/user-service/src/modules/auth/login.dto.ts diff --git a/services/authentication-service/src/modules/auth/reset-password.dto.ts b/services/user-service/src/modules/auth/reset-password.dto.ts similarity index 100% rename from services/authentication-service/src/modules/auth/reset-password.dto.ts rename to services/user-service/src/modules/auth/reset-password.dto.ts diff --git a/services/authentication-service/src/modules/auth/sign-up.dto.ts b/services/user-service/src/modules/auth/sign-up.dto.ts similarity index 100% rename from services/authentication-service/src/modules/auth/sign-up.dto.ts rename to services/user-service/src/modules/auth/sign-up.dto.ts diff --git a/services/authentication-service/src/modules/health/health.controller.ts b/services/user-service/src/modules/health/health.controller.ts similarity index 100% rename from services/authentication-service/src/modules/health/health.controller.ts rename to services/user-service/src/modules/health/health.controller.ts diff --git a/services/authentication-service/src/modules/health/health.e2e-spec.ts b/services/user-service/src/modules/health/health.e2e-spec.ts similarity index 100% rename from services/authentication-service/src/modules/health/health.e2e-spec.ts rename to services/user-service/src/modules/health/health.e2e-spec.ts diff --git a/services/authentication-service/src/modules/health/health.module.ts b/services/user-service/src/modules/health/health.module.ts similarity index 100% rename from services/authentication-service/src/modules/health/health.module.ts rename to services/user-service/src/modules/health/health.module.ts diff --git a/services/authentication-service/src/modules/user/create-user.dto.ts b/services/user-service/src/modules/user/create-user.dto.ts similarity index 100% rename from services/authentication-service/src/modules/user/create-user.dto.ts rename to services/user-service/src/modules/user/create-user.dto.ts diff --git a/services/authentication-service/src/modules/user/query-user.dto.ts b/services/user-service/src/modules/user/query-user.dto.ts similarity index 100% rename from services/authentication-service/src/modules/user/query-user.dto.ts rename to services/user-service/src/modules/user/query-user.dto.ts diff --git a/services/authentication-service/src/modules/user/user.controller.ts b/services/user-service/src/modules/user/user.controller.ts similarity index 100% rename from services/authentication-service/src/modules/user/user.controller.ts rename to services/user-service/src/modules/user/user.controller.ts diff --git a/services/authentication-service/src/modules/user/user.e2e-spec.ts b/services/user-service/src/modules/user/user.e2e-spec.ts similarity index 100% rename from services/authentication-service/src/modules/user/user.e2e-spec.ts rename to services/user-service/src/modules/user/user.e2e-spec.ts diff --git a/services/authentication-service/src/modules/user/user.module.ts b/services/user-service/src/modules/user/user.module.ts similarity index 100% rename from services/authentication-service/src/modules/user/user.module.ts rename to services/user-service/src/modules/user/user.module.ts diff --git a/services/authentication-service/src/modules/user/user.service.ts b/services/user-service/src/modules/user/user.service.ts similarity index 100% rename from services/authentication-service/src/modules/user/user.service.ts rename to services/user-service/src/modules/user/user.service.ts diff --git a/services/authentication-service/stacks/__snapshots__/auth-service.stack.test.ts.snap b/services/user-service/stacks/__snapshots__/auth-service.stack.test.ts.snap similarity index 94% rename from services/authentication-service/stacks/__snapshots__/auth-service.stack.test.ts.snap rename to services/user-service/stacks/__snapshots__/auth-service.stack.test.ts.snap index aa60589c4..c77a0f7ae 100644 --- a/services/authentication-service/stacks/__snapshots__/auth-service.stack.test.ts.snap +++ b/services/user-service/stacks/__snapshots__/auth-service.stack.test.ts.snap @@ -192,7 +192,7 @@ exports[`AuthServiceStack should match snapshot test 1`] = ` Fn::Join: [ , [ - auth., + user., { Ref: MyTestStackapiendpointMyTestStackapiendpointssmdomainnameParameter7CDF0FAA, }, @@ -219,24 +219,13 @@ exports[`AuthServiceStack should match snapshot test 1`] = ` }, Type: AWS::ApiGateway::Stage, }, - MyTestStackapiendpointMyTestStackapiendpointauthsvcdomainname9BBC596F: { - Properties: { - Description: auth service domain name, - Name: AUTH_SVC_DOMAIN_NAME, - Type: String, - Value: { - Ref: MyTestStackapiendpointMyTestStackapiendpointcustomdomain02611C53, - }, - }, - Type: AWS::SSM::Parameter, - }, MyTestStackapiendpointMyTestStackapiendpointcustomdomain02611C53: { Properties: { DomainName: { Fn::Join: [ , [ - auth., + user., { Ref: MyTestStackapiendpointMyTestStackapiendpointssmdomainnameParameter7CDF0FAA, }, @@ -283,8 +272,8 @@ exports[`AuthServiceStack should match snapshot test 1`] = ` }, MyTestStackapiendpointMyTestStackapiendpointrestapi9524CD35: { Properties: { - Description: auth Service API Gateway, - Name: auth RestAPI, + Description: user Service API Gateway, + Name: user RestAPI, }, Type: AWS::ApiGateway::RestApi, }, @@ -310,7 +299,7 @@ exports[`AuthServiceStack should match snapshot test 1`] = ` :lambda:path/2015-03-31/functions/, { Fn::GetAtt: [ - authenticationservicestacknestjsNodeJsLambdaC49C5643, + userservicestacknestjsNodeJsLambda13B2A918, Arn, ], }, @@ -336,7 +325,7 @@ exports[`AuthServiceStack should match snapshot test 1`] = ` Action: lambda:InvokeFunction, FunctionName: { Fn::GetAtt: [ - authenticationservicestacknestjsNodeJsLambdaC49C5643, + userservicestacknestjsNodeJsLambda13B2A918, Arn, ], }, @@ -377,7 +366,7 @@ exports[`AuthServiceStack should match snapshot test 1`] = ` Action: lambda:InvokeFunction, FunctionName: { Fn::GetAtt: [ - authenticationservicestacknestjsNodeJsLambdaC49C5643, + userservicestacknestjsNodeJsLambda13B2A918, Arn, ], }, @@ -458,14 +447,14 @@ exports[`AuthServiceStack should match snapshot test 1`] = ` Type: AWS::IAM::Role, UpdateReplacePolicy: Retain, }, - MyTestStackapiendpointMyTestStackapiendpointrestapiDeploymentAD663FBD8d3facdd370d544c040a541e88e8bbe2: { + MyTestStackapiendpointMyTestStackapiendpointrestapiDeploymentAD663FBDe90f25a847143f3df42f873e2e4640eb: { DependsOn: [ MyTestStackapiendpointMyTestStackapiendpointrestapiproxyANY26E2BF11, MyTestStackapiendpointMyTestStackapiendpointrestapiproxyF101F298, MyTestStackapiendpointMyTestStackapiendpointrestapiANY9ADB99C9, ], Properties: { - Description: auth Service API Gateway, + Description: user Service API Gateway, RestApiId: { Ref: MyTestStackapiendpointMyTestStackapiendpointrestapi9524CD35, }, @@ -478,7 +467,7 @@ exports[`AuthServiceStack should match snapshot test 1`] = ` ], Properties: { DeploymentId: { - Ref: MyTestStackapiendpointMyTestStackapiendpointrestapiDeploymentAD663FBD8d3facdd370d544c040a541e88e8bbe2, + Ref: MyTestStackapiendpointMyTestStackapiendpointrestapiDeploymentAD663FBDe90f25a847143f3df42f873e2e4640eb, }, MethodSettings: [ { @@ -518,7 +507,7 @@ exports[`AuthServiceStack should match snapshot test 1`] = ` :lambda:path/2015-03-31/functions/, { Fn::GetAtt: [ - authenticationservicestacknestjsNodeJsLambdaC49C5643, + userservicestacknestjsNodeJsLambda13B2A918, Arn, ], }, @@ -541,7 +530,7 @@ exports[`AuthServiceStack should match snapshot test 1`] = ` Action: lambda:InvokeFunction, FunctionName: { Fn::GetAtt: [ - authenticationservicestacknestjsNodeJsLambdaC49C5643, + userservicestacknestjsNodeJsLambda13B2A918, Arn, ], }, @@ -582,7 +571,7 @@ exports[`AuthServiceStack should match snapshot test 1`] = ` Action: lambda:InvokeFunction, FunctionName: { Fn::GetAtt: [ - authenticationservicestacknestjsNodeJsLambdaC49C5643, + userservicestacknestjsNodeJsLambda13B2A918, Arn, ], }, @@ -629,6 +618,17 @@ exports[`AuthServiceStack should match snapshot test 1`] = ` }, Type: AWS::ApiGateway::Resource, }, + MyTestStackapiendpointMyTestStackapiendpointusersvcdomainname2C8902B4: { + Properties: { + Description: user service domain name, + Name: USER_SVC_DOMAIN_NAME, + Type: String, + Value: { + Ref: MyTestStackapiendpointMyTestStackapiendpointcustomdomain02611C53, + }, + }, + Type: AWS::SSM::Parameter, + }, MyTestStackusercognitopoolCognitoPool8A729BFB: { DeletionPolicy: Delete, Properties: { @@ -747,10 +747,10 @@ exports[`AuthServiceStack should match snapshot test 1`] = ` }, Type: AWS::SSM::Parameter, }, - authenticationservicestacknestjsNodeJsLambdaC49C5643: { + userservicestacknestjsNodeJsLambda13B2A918: { DependsOn: [ - authenticationservicestacknestjsNodeJsLambdaServiceRoleDefaultPolicy52727D7B, - authenticationservicestacknestjsNodeJsLambdaServiceRole0E28D4E1, + userservicestacknestjsNodeJsLambdaServiceRoleDefaultPolicyCC145D01, + userservicestacknestjsNodeJsLambdaServiceRoleF3A12BEB, ], Properties: { Code: { @@ -791,7 +791,7 @@ exports[`AuthServiceStack should match snapshot test 1`] = ` MemorySize: 1024, Role: { Fn::GetAtt: [ - authenticationservicestacknestjsNodeJsLambdaServiceRole0E28D4E1, + userservicestacknestjsNodeJsLambdaServiceRoleF3A12BEB, Arn, ], }, @@ -800,7 +800,7 @@ exports[`AuthServiceStack should match snapshot test 1`] = ` }, Type: AWS::Lambda::Function, }, - authenticationservicestacknestjsNodeJsLambdaLogRetention1F9A7FDE: { + userservicestacknestjsNodeJsLambdaLogRetentionE0424A97: { Properties: { LogGroupName: { Fn::Join: [ @@ -808,7 +808,7 @@ exports[`AuthServiceStack should match snapshot test 1`] = ` [ /aws/lambda/, { - Ref: authenticationservicestacknestjsNodeJsLambdaC49C5643, + Ref: userservicestacknestjsNodeJsLambda13B2A918, }, ], ], @@ -823,38 +823,7 @@ exports[`AuthServiceStack should match snapshot test 1`] = ` }, Type: Custom::LogRetention, }, - authenticationservicestacknestjsNodeJsLambdaServiceRole0E28D4E1: { - Properties: { - AssumeRolePolicyDocument: { - Statement: [ - { - Action: sts:AssumeRole, - Effect: Allow, - Principal: { - Service: lambda.amazonaws.com, - }, - }, - ], - Version: 2012-10-17, - }, - ManagedPolicyArns: [ - { - Fn::Join: [ - , - [ - arn:, - { - Ref: AWS::Partition, - }, - :iam::aws:policy/service-role/AWSLambdaBasicExecutionRole, - ], - ], - }, - ], - }, - Type: AWS::IAM::Role, - }, - authenticationservicestacknestjsNodeJsLambdaServiceRoleDefaultPolicy52727D7B: { + userservicestacknestjsNodeJsLambdaServiceRoleDefaultPolicyCC145D01: { Properties: { PolicyDocument: { Statement: [ @@ -925,15 +894,46 @@ exports[`AuthServiceStack should match snapshot test 1`] = ` ], Version: 2012-10-17, }, - PolicyName: authenticationservicestacknestjsNodeJsLambdaServiceRoleDefaultPolicy52727D7B, + PolicyName: userservicestacknestjsNodeJsLambdaServiceRoleDefaultPolicyCC145D01, Roles: [ { - Ref: authenticationservicestacknestjsNodeJsLambdaServiceRole0E28D4E1, + Ref: userservicestacknestjsNodeJsLambdaServiceRoleF3A12BEB, }, ], }, Type: AWS::IAM::Policy, }, + userservicestacknestjsNodeJsLambdaServiceRoleF3A12BEB: { + Properties: { + AssumeRolePolicyDocument: { + Statement: [ + { + Action: sts:AssumeRole, + Effect: Allow, + Principal: { + Service: lambda.amazonaws.com, + }, + }, + ], + Version: 2012-10-17, + }, + ManagedPolicyArns: [ + { + Fn::Join: [ + , + [ + arn:, + { + Ref: AWS::Partition, + }, + :iam::aws:policy/service-role/AWSLambdaBasicExecutionRole, + ], + ], + }, + ], + }, + Type: AWS::IAM::Role, + }, }, Rules: { CheckBootstrapVersion: { diff --git a/services/authentication-service/stacks/auth-service.stack.test.ts b/services/user-service/stacks/auth-service.stack.test.ts similarity index 100% rename from services/authentication-service/stacks/auth-service.stack.test.ts rename to services/user-service/stacks/auth-service.stack.test.ts diff --git a/services/authentication-service/stacks/auth-service.stack.ts b/services/user-service/stacks/auth-service.stack.ts similarity index 90% rename from services/authentication-service/stacks/auth-service.stack.ts rename to services/user-service/stacks/auth-service.stack.ts index 3611e83c6..ba72d1c4d 100644 --- a/services/authentication-service/stacks/auth-service.stack.ts +++ b/services/user-service/stacks/auth-service.stack.ts @@ -40,14 +40,10 @@ export class AuthServiceStack extends cdk.Stack { environment.USER_POOL_ID = cognitoPool.cognitoPool.userPoolId; environment.USER_POOL_CLIENT_ID = cognitoPool.client.userPoolClientId; - const microservice = new Microservice( - this, - 'authentication-service-stack', - { - projectRoot: path.join(__dirname, '..'), - environment, - }, - ); + const microservice = new Microservice(this, 'user-service-stack', { + projectRoot: path.join(__dirname, '..'), + environment, + }); userPoolId.grantRead(microservice.getNodeJsFunction()); userPoolClientId.grantRead(microservice.getNodeJsFunction()); @@ -56,7 +52,7 @@ export class AuthServiceStack extends cdk.Stack { const apiEndpoint = new LambdaDomainName(this, `${id}-api-endpoint`, { stageName, - subdomainName: 'auth', + subdomainName: 'user', proxyLambda: microservice.getNodeJsFunction(), }); diff --git a/services/authentication-service/stacks/cognito-pool.ts b/services/user-service/stacks/cognito-pool.ts similarity index 100% rename from services/authentication-service/stacks/cognito-pool.ts rename to services/user-service/stacks/cognito-pool.ts diff --git a/services/authentication-service/tsconfig.json b/services/user-service/tsconfig.json similarity index 100% rename from services/authentication-service/tsconfig.json rename to services/user-service/tsconfig.json From f3a1e793be88af1a63d27439f540913968224d94 Mon Sep 17 00:00:00 2001 From: hxtree Date: Thu, 22 Feb 2024 03:54:35 +0000 Subject: [PATCH 2/3] fix: type on route return Signed-off-by: hxtree --- middleware/api/src/modules/router/router.controller.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middleware/api/src/modules/router/router.controller.ts b/middleware/api/src/modules/router/router.controller.ts index db4bdf766..f6d62af8c 100644 --- a/middleware/api/src/modules/router/router.controller.ts +++ b/middleware/api/src/modules/router/router.controller.ts @@ -17,7 +17,7 @@ export class RouterController { constructor(private readonly routerService: RouterService) {} @Get('routes') - getRoutes(): { path: string; endpoint: string }[] { + getRoutes(): { [key: string]: { path: string; endpoint: string } } { return this.routerService.getRoutes(); } From 57534cb8329a8ed92eeb69e53327c44164d8dc0b Mon Sep 17 00:00:00 2001 From: hxtree Date: Thu, 22 Feb 2024 04:52:38 +0000 Subject: [PATCH 3/3] feat: show url routes by default on api Signed-off-by: hxtree --- middleware/api/.env.dist | 1 + middleware/api/openapi-spec.json | 9 ++- .../api/src/modules/router/route-url.dto.ts | 31 ++++++++++ .../src/modules/router/router.controller.ts | 10 ++- .../api/src/modules/router/router.service.ts | 62 ++++--------------- .../api/src/modules/router/routes.config.ts | 44 +++++++++++++ .../__snapshots__/main.stack.test.ts.snap | 3 +- middleware/api/stacks/main.stack.ts | 27 ++++---- 8 files changed, 119 insertions(+), 68 deletions(-) create mode 100644 middleware/api/src/modules/router/route-url.dto.ts create mode 100644 middleware/api/src/modules/router/routes.config.ts diff --git a/middleware/api/.env.dist b/middleware/api/.env.dist index 3995326b2..2dafd44ef 100644 --- a/middleware/api/.env.dist +++ b/middleware/api/.env.dist @@ -1,3 +1,4 @@ +API_SVC_DOMAIN_NAME = api.sandbox.nekosgate.com CHARACTER_SHEETS_SVC_DOMAIN_NAME = character-sheets.sandbox.nekosgate.com EMAIL_SERVICE_SVC_DOMAIN_NAME = email-message.sandbox.nekosgate.com HTML_TO_PDF_SVC_DOMAIN_NAME = html-to-pdf.sandbox.nekosgate.com diff --git a/middleware/api/openapi-spec.json b/middleware/api/openapi-spec.json index 6c8554afe..8ed4ed345 100644 --- a/middleware/api/openapi-spec.json +++ b/middleware/api/openapi-spec.json @@ -1,13 +1,20 @@ { "openapi": "3.0.0", "paths": { - "/routes": { + "/": { "get": { "operationId": "RouterController_getRoutes", "parameters": [], "responses": { "200": { "description": "" } } } }, + "/debug": { + "get": { + "operationId": "RouterController_getConfig", + "parameters": [], + "responses": { "200": { "description": "" } } + } + }, "/*": { "get": { "operationId": "RouterController_getRoute", diff --git a/middleware/api/src/modules/router/route-url.dto.ts b/middleware/api/src/modules/router/route-url.dto.ts new file mode 100644 index 000000000..a3a040aa2 --- /dev/null +++ b/middleware/api/src/modules/router/route-url.dto.ts @@ -0,0 +1,31 @@ +import { IsString, IsUrl } from '@cats-cradle/validation-schemas'; + +export class RouteUrlsDto { + @IsString() + @IsUrl() + users_url: string; + + @IsString() + @IsUrl() + character_sheets_url: string; + + @IsString() + @IsUrl() + email_messages_url: string; + + @IsString() + @IsUrl() + html_to_pdf_url: string; + + @IsString() + @IsUrl() + instances_url: string; + + @IsString() + @IsUrl() + dice_url: string; + + @IsString() + @IsUrl() + player_achievements_url: string; +} diff --git a/middleware/api/src/modules/router/router.controller.ts b/middleware/api/src/modules/router/router.controller.ts index f6d62af8c..81af1e18a 100644 --- a/middleware/api/src/modules/router/router.controller.ts +++ b/middleware/api/src/modules/router/router.controller.ts @@ -11,16 +11,22 @@ import { VERSION_NEUTRAL, } from '@nestjs/common'; import { RouterService } from './router.service'; +import { RouteUrlsDto } from './route-url.dto'; @Controller({ path: '', version: ['1', VERSION_NEUTRAL] }) export class RouterController { constructor(private readonly routerService: RouterService) {} - @Get('routes') - getRoutes(): { [key: string]: { path: string; endpoint: string } } { + @Get('') + getRoutes(): RouteUrlsDto { return this.routerService.getRoutes(); } + @Get('debug') + getConfig(): { [key: string]: { path: string; endpoint: string } } { + return this.routerService.getConfig(); + } + @Get('*') async getRoute(@Req() req: any): Promise { const { path, query } = req; diff --git a/middleware/api/src/modules/router/router.service.ts b/middleware/api/src/modules/router/router.service.ts index b6b505930..78ea67da0 100644 --- a/middleware/api/src/modules/router/router.service.ts +++ b/middleware/api/src/modules/router/router.service.ts @@ -2,54 +2,11 @@ import { Injectable } from '@nestjs/common'; import axios, { AxiosResponse } from 'axios'; import { v4 as uuidv4 } from 'uuid'; - -type TRoute = { - path: string; - name: string; - endpoint: string; -}; +import { RouteUrlsDto } from './route-url.dto'; +import { routes, RouteDefinition } from './routes.config'; @Injectable() export class RouterService { - private readonly routes: TRoute[] = [ - { - name: 'users_url', - path: '/user', - endpoint: process.env.USER_SVC_DOMAIN_NAME || '', - }, - { - name: 'character_sheets_url', - path: '/character-sheets', - endpoint: process.env.CHARACTER_SHEETS_SVC_DOMAIN_NAME || '', - }, - { - name: 'email_messages_url', - path: '/email-message', - endpoint: process.env.EMAIL_MESSAGE_SVC_DOMAIN_NAME || '', - }, - { - name: 'html_to_pdf_url', - path: '/html-to-pdf', - endpoint: process.env.HTML_TO_PDF_SVC_DOMAIN_NAME || '', - }, - { - name: 'instances_url', - path: '/instances', - endpoint: process.env.INSTANCES_SVC_DOMAIN_NAME || '', - }, - { - name: 'dice_url', - path: '/dice', - endpoint: process.env.LUCK_BY_DICE_SVC_DOMAIN_NAME || '', - }, - { - name: 'player_achievements_url', - path: '/player-achievements', - endpoint: process.env.PLAYER_ACHIEVEMENTS_SVC_DOMAIN_NAME || '', - }, - // Add more routes as needed - ]; - async routeRequest(path: string, body: any, method: string): Promise { const route = this.getRouteForPath(path); // Find the route for the provided path if (!route) { @@ -111,10 +68,17 @@ export class RouterService { return response.data; } - // TODO remove endpoint - getRoutes(): { [key: string]: { path: string; endpoint: string } } { + getRoutes(): RouteUrlsDto { + const urls: { [key: string]: string } = {}; + routes.forEach((route: RouteDefinition) => { + urls[route.name] = `https://${process.env.API_SVC_DOMAIN_NAME}${route.path}`; + }); + return urls as any as RouteUrlsDto; + } + + getConfig(): { [key: string]: { path: string; endpoint: string } } { const urls: { [key: string]: { path: string; endpoint: string } } = {}; - this.routes.forEach((route: TRoute) => { + routes.forEach((route: RouteDefinition) => { urls[route.name] = { path: route.path, endpoint: route.endpoint }; }); return urls; @@ -123,7 +87,7 @@ export class RouterService { private getRouteForPath( path: string, ): { path: string; endpoint: string } | undefined { - return this.routes.find((route) => path.startsWith(route.path)); + return routes.find((route) => path.startsWith(route.path)); } private constructUrl(endpoint: string, path: string): string { diff --git a/middleware/api/src/modules/router/routes.config.ts b/middleware/api/src/modules/router/routes.config.ts new file mode 100644 index 000000000..5a2841de0 --- /dev/null +++ b/middleware/api/src/modules/router/routes.config.ts @@ -0,0 +1,44 @@ +export type RouteDefinition = { + path: string; + name: string; + endpoint: string; +}; + +export const routes: RouteDefinition[] = [ + { + name: 'users_url', + path: '/user', + endpoint: process.env.USER_SVC_DOMAIN_NAME || '', + }, + { + name: 'character_sheets_url', + path: '/character-sheets', + endpoint: process.env.CHARACTER_SHEETS_SVC_DOMAIN_NAME || '', + }, + { + name: 'email_messages_url', + path: '/email-message', + endpoint: process.env.EMAIL_MESSAGE_SVC_DOMAIN_NAME || '', + }, + { + name: 'html_to_pdf_url', + path: '/html-to-pdf', + endpoint: process.env.HTML_TO_PDF_SVC_DOMAIN_NAME || '', + }, + { + name: 'instances_url', + path: '/instances', + endpoint: process.env.INSTANCES_SVC_DOMAIN_NAME || '', + }, + { + name: 'dice_url', + path: '/dice', + endpoint: process.env.LUCK_BY_DICE_SVC_DOMAIN_NAME || '', + }, + { + name: 'player_achievements_url', + path: '/player-achievements', + endpoint: process.env.PLAYER_ACHIEVEMENTS_SVC_DOMAIN_NAME || '', + }, + // Add more routes as needed +]; diff --git a/middleware/api/stacks/__snapshots__/main.stack.test.ts.snap b/middleware/api/stacks/__snapshots__/main.stack.test.ts.snap index 7412ab4e2..b141d0884 100644 --- a/middleware/api/stacks/__snapshots__/main.stack.test.ts.snap +++ b/middleware/api/stacks/__snapshots__/main.stack.test.ts.snap @@ -627,10 +627,11 @@ exports[`MainStack should match snapshot test 1`] = ` S3Bucket: { Fn::Sub: cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}, }, - S3Key: 84733bfcc0860a158020056aeea6de14f9009718cf2a83659cde3585250b04a6.zip, + S3Key: 696402484aadd93c03efb231f3a270bfd8656a85eed0051095cb57022377084a.zip, }, Environment: { Variables: { + API_SVC_DOMAIN_NAME: {{resolve:ssm:/API_SVC_DOMAIN_NAME}}, AWS_ACCOUNT_ID: { Ref: AWS::AccountId, }, diff --git a/middleware/api/stacks/main.stack.ts b/middleware/api/stacks/main.stack.ts index 2f1cdcf44..8e86ca76a 100644 --- a/middleware/api/stacks/main.stack.ts +++ b/middleware/api/stacks/main.stack.ts @@ -11,6 +11,7 @@ interface Secret { export class MainStack extends cdk.Stack { secrets: Secret[] = [ + { key: 'API_SVC_DOMAIN_NAME' }, { key: 'USER_SVC_DOMAIN_NAME' }, { key: 'CHARACTER_SHEETS_SVC_DOMAIN_NAME' }, { key: 'EMAIL_SERVICE_SVC_DOMAIN_NAME' }, @@ -23,20 +24,6 @@ export class MainStack extends cdk.Stack { constructor(scope: Construct, id: string, props?: cdk.StackProps) { super(scope, id, props); - const healthCheckLambda = this.setupLambda(`${id}-health-check-lambda`); - - const lambdaDomainName = new LambdaDomainName(this, `${id}-dns-domain`, { - subdomainName: 'api', - proxyLambda: healthCheckLambda, - stageName: 'default', - }); - - new cdk.CfnOutput(this, 'Endpoint', { - value: lambdaDomainName.getBaseUrl(), - }); - } - - setupLambda(lambdaId: string): lambda.Function { const environment: { [key: string]: string } = {}; for (const secret of this.secrets) { @@ -49,6 +36,16 @@ export class MainStack extends cdk.Stack { environment: environment, }); - return lambdaFunction.getNodeJsFunction(); + const lambdaDomainName = new LambdaDomainName(this, `${id}-dns-domain`, { + subdomainName: 'api', + proxyLambda: lambdaFunction.getNodeJsFunction(), + stageName: 'default', + }); + + lambdaDomainName.domainName; + + new cdk.CfnOutput(this, 'Endpoint', { + value: lambdaDomainName.getBaseUrl(), + }); } }