Skip to content

Commit

Permalink
feat: introduce api-types package, refactoring (CDMD-3811) (codemod-c…
Browse files Browse the repository at this point in the history
  • Loading branch information
r4zendev authored Jul 17, 2024
1 parent 8ae8952 commit 284166b
Show file tree
Hide file tree
Showing 118 changed files with 724 additions and 987 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
elif [[ ${{ matrix.os }} == "macos-latest" ]]; then
pnpm test --filter=!@codemod-com/backend
else
pnpm --filter @codemod-com/database build && pnpm test
pnpm build --filter @codemod-com/auth && pnpm build --filter @codemod-com/database && pnpm test
fi
shell: bash
env:
Expand Down
4 changes: 3 additions & 1 deletion apps/auth-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@codemod-com/auth-service",
"version": "0.0.9",
"scripts": {
"build": "node esbuild.config.js",
"build": "tsc && node esbuild.config.js",
"start": "node build/index.js"
},
"author": "Codemod inc.",
Expand All @@ -11,6 +11,7 @@
"schema": "packages/database/generated/client/schema.prisma"
},
"devDependencies": {
"@codemod-com/api-types": "workspace:*",
"@codemod-com/tsconfig": "workspace:*",
"@types/node": "20.10.5",
"dotenv-cli": "catalog:",
Expand All @@ -22,6 +23,7 @@
"dependencies": {
"@clerk/backend": "catalog:",
"@clerk/fastify": "catalog:",
"@codemod-com/auth": "workspace:*",
"@codemod-com/database": "workspace:*",
"@codemod-com/utilities": "workspace:*",
"@fastify/busboy": "catalog:",
Expand Down
10 changes: 5 additions & 5 deletions apps/auth-service/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import "dotenv/config";

import { createClerkClient } from "@clerk/backend";
import { clerkPlugin, getAuth } from "@clerk/fastify";
import {
type GetScopedTokenResponse,
type RevokeScopedTokenResponse,
isNeitherNullNorUndefined,
} from "@codemod-com/utilities";
import type {
GetScopedTokenResponse,
RevokeScopedTokenResponse,
} from "@codemod-com/api-types";
import { isNeitherNullNorUndefined } from "@codemod-com/utilities";
import cors, { type FastifyCorsOptions } from "@fastify/cors";
import fastifyRateLimit from "@fastify/rate-limit";
import Fastify, { type FastifyPluginCallback } from "fastify";
Expand Down
8 changes: 7 additions & 1 deletion apps/auth-service/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"~/*": ["src/*"]
}
},
"include": ["./src"],
"exclude": ["./dist", "./node_modules"],
"extends": "@codemod-com/tsconfig/base.json"
"extends": "@codemod-com/tsconfig/backend.json"
}
1 change: 1 addition & 0 deletions apps/backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ PORT=
AWS_SECRET_ACCESS_KEY=
AWS_ACCESS_KEY_ID=

AUTH_SERVICE_URL=
DATABASE_URI=

REDIS_HOST=
Expand Down
4 changes: 3 additions & 1 deletion apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@codemod-com/backend",
"version": "0.0.133",
"scripts": {
"build": "node esbuild.config.js",
"build": "tsc && node esbuild.config.js",
"start": "node build/index.js",
"test": "vitest --run"
},
Expand All @@ -12,6 +12,7 @@
"author": "Codemod inc.",
"private": true,
"devDependencies": {
"@codemod-com/api-types": "workspace:*",
"@codemod-com/telemetry": "workspace:*",
"@codemod-com/tsconfig": "workspace:*",
"@faker-js/faker": "catalog:",
Expand All @@ -34,6 +35,7 @@
"dependencies": {
"@aws-sdk/client-s3": "catalog:",
"@aws-sdk/s3-request-presigner": "catalog:",
"@codemod-com/auth": "workspace:*",
"@codemod-com/database": "workspace:*",
"@codemod-com/utilities": "workspace:*",
"@fastify/busboy": "catalog:",
Expand Down
4 changes: 2 additions & 2 deletions apps/backend/src/handlers/getCodemodDownloadLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
import type {
ApiResponse,
CodemodDownloadLinkResponse,
} from "@codemod-com/utilities";
} from "@codemod-com/api-types";
import type { UserDataPopulatedRequest } from "@codemod-com/auth";
import type { FastifyReply, RouteHandler } from "fastify";
import { processHandlerError } from "~/types/errors.js";
import type { UserDataPopulatedRequest } from "../plugins/authPlugin.js";
import { parseGetCodemodLatestVersionQuery } from "../schemata/schema.js";
import { codemodService } from "../services/CodemodService.js";
import { environment } from "../util.js";
Expand Down
6 changes: 3 additions & 3 deletions apps/backend/src/handlers/getCodemodHandler.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { GetCodemodResponse } from "@codemod-com/utilities";
import type { ApiResponse, GetCodemodResponse } from "@codemod-com/api-types";
import type { UserDataPopulatedRequest } from "@codemod-com/auth";
import type { RouteHandler } from "fastify";
import type { UserDataPopulatedRequest } from "~/plugins/authPlugin.js";
import { processHandlerError } from "~/types/errors.js";
import { parseGetCodemodBySlugParams } from "../schemata/schema.js";
import { codemodService } from "../services/CodemodService.js";

export const getCodemodHandler: RouteHandler<{
Reply: GetCodemodResponse;
Reply: ApiResponse<GetCodemodResponse>;
}> = async (request: UserDataPopulatedRequest, reply) => {
const { criteria } = parseGetCodemodBySlugParams(request.params);

Expand Down
4 changes: 2 additions & 2 deletions apps/backend/src/handlers/getCodemodsHandler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ApiResponse } from "@codemod-com/api-types";
import type { UserDataPopulatedRequest } from "@codemod-com/auth";
import type { Codemod } from "@codemod-com/database";
import type { ApiResponse } from "@codemod-com/utilities";
import type { RouteHandler } from "fastify";
import type { UserDataPopulatedRequest } from "~/plugins/authPlugin.js";
import { parseGetCodemodsQuery } from "../schemata/schema.js";
import { codemodService } from "../services/CodemodService.js";

Expand Down
4 changes: 2 additions & 2 deletions apps/backend/src/handlers/getCodemodsListHandler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { randomBytes } from "node:crypto";
import type { CodemodListResponse } from "@codemod-com/utilities";
import type { CodemodListResponse } from "@codemod-com/api-types";
import type { UserDataPopulatedRequest } from "@codemod-com/auth";
import type { RouteHandler } from "fastify";
import type { UserDataPopulatedRequest } from "../plugins/authPlugin.js";
import {
parseClientIdentifierSchema,
parseListCodemodsQuery,
Expand Down
128 changes: 0 additions & 128 deletions apps/backend/src/plugins/authPlugin.ts

This file was deleted.

4 changes: 2 additions & 2 deletions apps/backend/src/publishHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { createHash } from "node:crypto";
import {
CODEMOD_NAME_TAKEN,
CODEMOD_VERSION_EXISTS,
type CodemodConfigInput,
INTERNAL_SERVER_ERROR,
NO_MAIN_FILE_FOUND,
UNAUTHORIZED,
} from "@codemod-com/utilities";
} from "@codemod-com/api-types";
import type { CodemodConfigInput } from "@codemod-com/utilities";
import supertest from "supertest";
import { afterAll, afterEach, describe, expect, it, vi } from "vitest";
import { runServer } from "./server.js";
Expand Down
10 changes: 6 additions & 4 deletions apps/backend/src/publishHandler.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { createHash, randomBytes } from "node:crypto";
import * as fs from "node:fs";
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
import { prisma } from "@codemod-com/database";
import {
type ApiResponse,
CODEMOD_CONFIG_INVALID,
CODEMOD_NAME_TAKEN,
CODEMOD_VERSION_EXISTS,
type CodemodConfig,
INTERNAL_SERVER_ERROR,
NO_CONFIG_FILE_FOUND,
NO_MAIN_FILE_FOUND,
type PublishResponse,
TarService,
UNAUTHORIZED,
} from "@codemod-com/api-types";
import type { UserDataPopulatedRequest } from "@codemod-com/auth";
import { prisma } from "@codemod-com/database";
import {
type CodemodConfig,
TarService,
buildCodemodSlug,
codemodNameRegex,
isNeitherNullNorUndefined,
Expand All @@ -22,7 +25,6 @@ import {
import axios from "axios";
import type { RouteHandler } from "fastify";
import * as semver from "semver";
import type { UserDataPopulatedRequest } from "./plugins/authPlugin";
import { buildRevalidateHelper } from "./revalidate";
import { environment } from "./util";

Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/schemata/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const environmentSchema = object({
SLACK_TOKEN: string(),
SLACK_CHANNEL: string(),
BACKEND_API_URL: optional(string()),
AUTH_SERVICE_URL: optional(string()),
AUTH_SERVICE_URL: string(),
MODGPT_SERVICE_URL: optional(string()),
CODEMOD_AI_SERVICE_URL: optional(string()),
RUN_SERVICE_URL: optional(string()),
Expand Down
13 changes: 6 additions & 7 deletions apps/backend/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { randomBytes } from "node:crypto";
import type { CodemodListResponse } from "@codemod-com/api-types";
import { getAuthPlugin } from "@codemod-com/auth";
import { prisma } from "@codemod-com/database";
import {
type CodemodListResponse,
decryptWithIv,
encryptWithIv,
} from "@codemod-com/utilities";
import { decryptWithIv, encryptWithIv } from "@codemod-com/utilities";
import cors, { type FastifyCorsOptions } from "@fastify/cors";
import fastifyMultipart from "@fastify/multipart";
import fastifyRateLimit from "@fastify/rate-limit";
Expand All @@ -22,7 +20,6 @@ import {
getCodemodsHandler,
} from "./handlers/getCodemodsHandler.js";
import { getCodemodsListHandler } from "./handlers/getCodemodsListHandler.js";
import authPlugin from "./plugins/authPlugin.js";
import {
type PublishHandlerResponse,
publishHandler,
Expand Down Expand Up @@ -138,9 +135,11 @@ export const initApp = async (toRegister: FastifyPluginCallback[]) => {
timeWindow: 60 * 1000, // 1 minute
});

await fastify.register(fastifyMultipart);
const authPlugin = await getAuthPlugin(environment.AUTH_SERVICE_URL);
await fastify.register(authPlugin);

await fastify.register(fastifyMultipart);

for (const plugin of toRegister) {
await fastify.register(plugin);
}
Expand Down
3 changes: 1 addition & 2 deletions apps/backend/src/services/CodemodService.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { CodemodListResponse } from "@codemod-com/api-types";
import {
type Codemod,
type CodemodVersion,
Expand All @@ -6,10 +7,8 @@ import {
type Tag,
prisma,
} from "@codemod-com/database";

import {
type AllEngines,
type CodemodListResponse,
isNeitherNullNorUndefined,
} from "@codemod-com/utilities";

Expand Down
Loading

0 comments on commit 284166b

Please sign in to comment.