Skip to content

Commit

Permalink
feat(api-client): Added API Client package (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdip-b authored Jul 10, 2024
1 parent bc15ead commit 8dc0da9
Show file tree
Hide file tree
Showing 27 changed files with 965 additions and 222 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ PLATFORM_OAUTH_FAILURE_REDIRECT_PATH=/oauth/failure
DOMAIN=localhost
FEEDBACK_FORWARD_EMAIL=

NEXT_PUBLIC_BACKEND_URL=http://localhost:4200
BACKEND_URL=http://localhost:4200
62 changes: 62 additions & 0 deletions .github/workflows/validate-api-client.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
on:
push:
branches:
- '!develop'
- '!main'
paths:
['packages/api-client/**', '.github/workflows/validate-api-client.yaml']
pull_request:
paths:
['packages/api-client/**', '.github/workflows/validate-api-client.yaml']

jobs:
validate:
runs-on: ubuntu-latest
name: Validate API Client

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9.2.0
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install packages
run: |
pnpm i
- name: Lint
run: |
pnpm run lint:api-client
- name: Test
run: |
pnpm run test:api-client
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
flags: api-client
3 changes: 0 additions & 3 deletions .github/workflows/validate-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ jobs:
- name: E2E tests
env:
GITHUB_CLIENT_ID: dummy
GITHUB_CLIENT_SECRET: dummy
GITHUB_CALLBACK_URL: dummy
REDIS_URL: redis://localhost:6379
JWT_SECRET: secret
run: pnpm run e2e:api
Expand Down
14 changes: 12 additions & 2 deletions .github/workflows/validate-web.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@ on:
branches:
- '!develop'
- '!main'
paths: ['apps/web/**', '.github/workflows/web.yaml']
paths:
[
'apps/web/**',
'.github/workflows/validate-web.yaml',
'.github/workflows/deploy-web.yaml'
]
pull_request:
paths: ['apps/web/**', '.github/workflows/web.yaml']
paths:
[
'apps/web/**',
'.github/workflows/deploy-web.yaml',
'.github/workflows/validate-web.yaml'
]

jobs:
validate:
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpm lint && pnpm format && pnpm test:api
pnpm lint && pnpm format && pnpm test:api && pnpm test:api-client
9 changes: 0 additions & 9 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,11 @@
"@types/cookie-parser": "^1.4.7",
"@types/eccrypto": "^1.1.6",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/multer": "^1.4.11",
"@types/node": "^20.3.1",
"@types/supertest": "^6.0.0",
"@types/uuid": "^9.0.8",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"ajv": "^7",
"dotenv-cli": "^7.4.2",
"eslint": "^8.42.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.5.0",
"jest-mock-extended": "^3.0.5",
"prettier": "^3.0.0",
Expand All @@ -79,7 +71,6 @@
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.3",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.1.3"
},
"jest": {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/feedback/feedback.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Feedback Controller (E2E)', () => {
beforeEach(async () => {
user = await prisma.user.create({
data: {
email: 'john@keyshade.xyz',
email: 'johndoe@keyshade.xyz',
name: 'John',
isActive: true,
isAdmin: false,
Expand Down
19 changes: 19 additions & 0 deletions apps/api/src/user/service/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class UserService {

async onApplicationBootstrap() {
await this.checkIfAdminExistsOrCreate()
await this.createDummyUser()
}

async getSelf(user: User) {
Expand Down Expand Up @@ -294,6 +295,24 @@ export class UserService {
return userWithWorkspace
}

private async createDummyUser() {
// @ts-expect-error - This is a test environment
if (process.env.NODE_ENV === 'test' || process.env.NODE_ENV === 'e2e') {
this.log.log('Creating dummy user')

const user = await this.prisma.user.create({
data: {
email: '[email protected]',
name: 'John Doe',
isActive: true,
isOnboardingFinished: true
}
})

this.log.log('Created dummy user: ', user)
}
}

private async checkIfAdminExistsOrCreate() {
const parsedEnv = EnvSchema.safeParse(process.env)
let nodeEnv
Expand Down
9 changes: 4 additions & 5 deletions apps/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"main": "index.js",
"type": "commonjs",
"scripts": {
"build": "npx tsc",
"watch": "npx tsc -w",
"build": "tsc",
"watch": "tsc -w",
"start": "node dist/index.js"
},
"keywords": [],
Expand All @@ -16,13 +16,12 @@
"@clack/core": "^0.3.4",
"@clack/prompts": "^0.7.0",
"@types/figlet": "^1.5.8",
"@types/node": "^20.14.8",
"commander": "^12.1.0",
"figlet": "^1.7.0",
"fs": "0.0.1-security",
"nodemon": "^3.1.4",
"socket.io-client": "^4.7.5",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.5.2"
}
},
"devDependencies": {}
}
127 changes: 63 additions & 64 deletions apps/platform/package.json
Original file line number Diff line number Diff line change
@@ -1,65 +1,64 @@
{
"name": "platform",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "env-cmd -f ../../.env --silent next dev -p 3025",
"build": "next build",
"start": "next start",
"lint": "next lint --fix"
},
"dependencies": {
"@radix-ui/react-accordion": "^1.2.0",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-context-menu": "^2.1.5",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-direction": "^1.0.1",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-menubar": "^1.0.4",
"@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-scroll-area": "^1.0.5",
"@radix-ui/react-separator": "^1.0.3",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-tooltip": "^1.1.2",
"@tanstack/react-table": "^8.16.0",
"avvvatars-react": "^0.4.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"cmdk": "^1.0.0",
"dayjs": "^1.11.11",
"env-cmd": "^10.1.0",
"framer-motion": "^11.1.7",
"geist": "^1.2.2",
"input-otp": "^1.2.4",
"jotai": "^2.8.0",
"js-cookie": "^3.0.5",
"lucide-react": "^0.340.0",
"next": "^13.5.6",
"next-themes": "^0.3.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"sonner": "^1.4.41",
"tailwind-merge": "^2.2.2",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.23.8"
},
"devDependencies": {
"@next/eslint-plugin-next": "^13.5.6",
"@svgr/webpack": "^8.1.0",
"@tailwindcss/forms": "^0.5.7",
"@types/js-cookie": "^3.0.6",
"@types/node": "^17.0.45",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.0",
"autoprefixer": "^10.4.16",
"eslint-config-custom": "workspace:*",
"postcss": "^8.4.31",
"tailwindcss": "^3.3.3",
"tsconfig": "workspace:*",
"typescript": "^4.5.3"
}
}
"name": "platform",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "env-cmd -f ../../.env --silent next dev -p 3025",
"build": "next build",
"start": "next start",
"lint": "next lint --fix"
},
"dependencies": {
"@radix-ui/react-accordion": "^1.2.0",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-context-menu": "^2.1.5",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-direction": "^1.0.1",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-menubar": "^1.0.4",
"@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-scroll-area": "^1.0.5",
"@radix-ui/react-separator": "^1.0.3",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-tooltip": "^1.1.2",
"@tanstack/react-table": "^8.16.0",
"avvvatars-react": "^0.4.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"cmdk": "^1.0.0",
"dayjs": "^1.11.11",
"env-cmd": "^10.1.0",
"framer-motion": "^11.1.7",
"geist": "^1.2.2",
"input-otp": "^1.2.4",
"jotai": "^2.8.0",
"js-cookie": "^3.0.5",
"lucide-react": "^0.340.0",
"next": "^13.5.6",
"next-themes": "^0.3.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"sonner": "^1.4.41",
"tailwind-merge": "^2.2.2",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.23.8"
},
"devDependencies": {
"@next/eslint-plugin-next": "^13.5.6",
"@svgr/webpack": "^8.1.0",
"@tailwindcss/forms": "^0.5.7",
"@types/js-cookie": "^3.0.6",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.0",
"autoprefixer": "^10.4.16",
"eslint-config-custom": "workspace:*",
"postcss": "^8.4.31",
"tailwindcss": "^3.3.3",
"tsconfig": "workspace:*",
"typescript": "^4.5.3"
}
}
2 changes: 1 addition & 1 deletion apps/platform/src/lib/api-functions/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function getProjectsbyWorkspaceID(

const zProjectWithoutKeysArray = z.array(zProjectWithoutKeys)
const { success, data } = zProjectWithoutKeysArray.safeParse(projectData)

if (!success) {
throw new Error('Invalid data')
}
Expand Down
2 changes: 1 addition & 1 deletion apps/platform/src/lib/api-functions/secrets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from 'zod'
import { apiClient } from '../api-client'
import { zSecret, type Secret } from '@/types'
import { apiClient } from '../api-client'

async function getAllSecretbyProjectId(
projectId: string
Expand Down
2 changes: 0 additions & 2 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
"@next/eslint-plugin-next": "^13.4.19",
"@svgr/webpack": "^8.1.0",
"@tailwindcss/forms": "^0.5.7",
"@types/jest": "^29.5.2",
"@types/node": "^17.0.12",
"@types/react": "^18.0.22",
"@types/react-dom": "^18.0.7",
"autoprefixer": "^10.4.16",
Expand Down
Loading

0 comments on commit 8dc0da9

Please sign in to comment.