Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Simplify folder organization in the repo #796

Merged
merged 5 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
17 changes: 0 additions & 17 deletions .vscode/settings.json

This file was deleted.

7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import "./polyfill";
import "./tracer";

import { initServer } from "./server";
import { env } from "./utils/env";
import { logger } from "./utils/logger";
import "./utils/tracer";
import { env } from "./shared/utils/env";
import { logger } from "./shared/utils/logger";
import { initWorker } from "./worker";
import { CancelRecycledNoncesQueue } from "./worker/queues/cancelRecycledNoncesQueue";
import { MineTransactionQueue } from "./worker/queues/mineTransactionQueue";
Expand Down
2 changes: 1 addition & 1 deletion src/polyfill.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as crypto from "crypto";
import * as crypto from "node:crypto";

if (typeof globalThis.crypto === "undefined") {
(globalThis as any).crypto = crypto;
Expand Down
10 changes: 7 additions & 3 deletions src/scripts/apply-migrations.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { logger } from "../utils/logger";
import { acquireLock, releaseLock, waitForLock } from "../utils/redis/lock";
import { redis } from "../utils/redis/redis";
import { logger } from "../shared/utils/logger";
import {
acquireLock,
releaseLock,
waitForLock,
} from "../shared/utils/redis/lock";
import { redis } from "../shared/utils/redis/redis";

const MIGRATION_LOCK_TTL_SECONDS = 60;

Expand Down
8 changes: 4 additions & 4 deletions src/scripts/setup-db.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { execSync } from "child_process";
import { prisma } from "../db/client";
import { execSync } from "node:child_process";
import { prisma } from "../shared/db/client";

const main = async () => {
const [{ exists: hasWalletsTable }]: [{ exists: boolean }] =
Expand All @@ -14,8 +14,8 @@ const main = async () => {

const schema =
process.env.NODE_ENV === "production"
? `./dist/prisma/schema.prisma`
: `./src/prisma/schema.prisma`;
? "./dist/prisma/schema.prisma"
: "./src/prisma/schema.prisma";

if (hasWalletsTable) {
execSync(`yarn prisma migrate reset --force --schema ${schema}`, {
Expand Down
10 changes: 5 additions & 5 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import fastify, { type FastifyInstance } from "fastify";
import * as fs from "node:fs";
import path from "node:path";
import { URL } from "node:url";
import { clearCacheCron } from "../utils/cron/clearCacheCron";
import { env } from "../utils/env";
import { logger } from "../utils/logger";
import { metricsServer } from "../utils/prometheus";
import { withServerUsageReporting } from "../utils/usage";
import { clearCacheCron } from "../shared/utils/cron/clearCacheCron";
import { env } from "../shared/utils/env";
import { logger } from "../shared/utils/logger";
import { metricsServer } from "../shared/utils/prometheus";
import { withServerUsageReporting } from "../shared/utils/usage";
import { updateTxListener } from "./listeners/updateTxListener";
import { withAdminRoutes } from "./middleware/adminRoutes";
import { withAuth } from "./middleware/auth";
Expand Down
6 changes: 3 additions & 3 deletions src/server/listeners/updateTxListener.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { knex } from "../../db/client";
import { TransactionDB } from "../../db/transactions/db";
import { logger } from "../../utils/logger";
import { knex } from "../../shared/db/client";
import { TransactionDB } from "../../shared/db/transactions/db";
import { logger } from "../../shared/utils/logger";
import { toTransactionSchema } from "../schemas/transaction";
import { subscriptionsData } from "../schemas/websocket";
import {
Expand Down
2 changes: 1 addition & 1 deletion src/server/middleware/adminRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Queue } from "bullmq";
import type { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import { timingSafeEqual } from "node:crypto";
import { env } from "../../utils/env";
import { env } from "../../shared/utils/env";
import { CancelRecycledNoncesQueue } from "../../worker/queues/cancelRecycledNoncesQueue";
import { MineTransactionQueue } from "../../worker/queues/mineTransactionQueue";
import { NonceHealthCheckQueue } from "../../worker/queues/nonceHealthCheckQueue";
Expand Down
30 changes: 15 additions & 15 deletions src/server/middleware/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ import {
type ThirdwebAuthUser,
} from "@thirdweb-dev/auth/fastify";
import { AsyncWallet } from "@thirdweb-dev/wallets/evm/wallets/async";
import { createHash } from "crypto";
import { createHash } from "node:crypto";
import type { FastifyInstance } from "fastify";
import type { FastifyRequest } from "fastify/types/request";
import jsonwebtoken, { type JwtPayload } from "jsonwebtoken";
import { validate as uuidValidate } from "uuid";
import { getPermissions } from "../../db/permissions/getPermissions";
import { createToken } from "../../db/tokens/createToken";
import { revokeToken } from "../../db/tokens/revokeToken";
import { WebhooksEventTypes } from "../../schema/webhooks";
import { THIRDWEB_DASHBOARD_ISSUER, handleSiwe } from "../../utils/auth";
import { getAccessToken } from "../../utils/cache/accessToken";
import { getAuthWallet } from "../../utils/cache/authWallet";
import { getConfig } from "../../utils/cache/getConfig";
import { getWebhooksByEventType } from "../../utils/cache/getWebhook";
import { getKeypair } from "../../utils/cache/keypair";
import { env } from "../../utils/env";
import { logger } from "../../utils/logger";
import { sendWebhookRequest } from "../../utils/webhook";
import { Permission } from "../schemas/auth";
import { getPermissions } from "../../shared/db/permissions/getPermissions";
import { createToken } from "../../shared/db/tokens/createToken";
import { revokeToken } from "../../shared/db/tokens/revokeToken";
import { WebhooksEventTypes } from "../../shared/schemas/webhooks";
import { THIRDWEB_DASHBOARD_ISSUER, handleSiwe } from "../../shared/utils/auth";
import { getAccessToken } from "../../shared/utils/cache/accessToken";
import { getAuthWallet } from "../../shared/utils/cache/authWallet";
import { getConfig } from "../../shared/utils/cache/getConfig";
import { getWebhooksByEventType } from "../../shared/utils/cache/getWebhook";
import { getKeypair } from "../../shared/utils/cache/keypair";
import { env } from "../../shared/utils/env";
import { logger } from "../../shared/utils/logger";
import { sendWebhookRequest } from "../../shared/utils/webhook";
import { Permission } from "../../shared/schemas/auth";
import { ADMIN_QUEUES_BASEPATH } from "./adminRoutes";
import { OPENAPI_ROUTES } from "./openApi";

Expand Down
2 changes: 1 addition & 1 deletion src/server/middleware/cors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FastifyInstance } from "fastify";
import { getConfig } from "../../utils/cache/getConfig";
import { getConfig } from "../../shared/utils/cache/getConfig";
import { ADMIN_QUEUES_BASEPATH } from "./adminRoutes";

const STANDARD_METHODS = "GET,POST,DELETE,PUT,PATCH,HEAD,PUT,PATCH,POST,DELETE";
Expand Down
2 changes: 1 addition & 1 deletion src/server/middleware/engineMode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FastifyInstance } from "fastify";
import { env } from "../../utils/env";
import { env } from "../../shared/utils/env";

export function withEnforceEngineMode(server: FastifyInstance) {
if (env.ENGINE_MODE === "sandbox") {
Expand Down
4 changes: 2 additions & 2 deletions src/server/middleware/error.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { FastifyInstance } from "fastify";
import { ReasonPhrases, StatusCodes } from "http-status-codes";
import { ZodError } from "zod";
import { env } from "../../utils/env";
import { parseEthersError } from "../../utils/ethers";
import { env } from "../../shared/utils/env";
import { parseEthersError } from "../../shared/utils/ethers";

export type CustomError = {
message: string;
Expand Down
2 changes: 1 addition & 1 deletion src/server/middleware/logs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { FastifyInstance } from "fastify";
import { stringify } from "thirdweb/utils";
import { logger } from "../../utils/logger";
import { logger } from "../../shared/utils/logger";
import { ADMIN_QUEUES_BASEPATH } from "./adminRoutes";
import { OPENAPI_ROUTES } from "./openApi";

Expand Down
4 changes: 2 additions & 2 deletions src/server/middleware/prometheus.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
import { env } from "../../utils/env";
import { recordMetrics } from "../../utils/prometheus";
import { env } from "../../shared/utils/env";
import { recordMetrics } from "../../shared/utils/prometheus";

export function withPrometheus(server: FastifyInstance) {
if (!env.METRICS_ENABLED) {
Expand Down
4 changes: 2 additions & 2 deletions src/server/middleware/rateLimit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import { env } from "../../utils/env";
import { redis } from "../../utils/redis/redis";
import { env } from "../../shared/utils/env";
import { redis } from "../../shared/utils/redis/redis";
import { createCustomError } from "./error";
import { OPENAPI_ROUTES } from "./openApi";

Expand Down
2 changes: 1 addition & 1 deletion src/server/middleware/websocket.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import WebSocketPlugin from "@fastify/websocket";
import type { FastifyInstance } from "fastify";
import { logger } from "../../utils/logger";
import { logger } from "../../shared/utils/logger";

export async function withWebSocket(server: FastifyInstance) {
await server.register(WebSocketPlugin, {
Expand Down
14 changes: 7 additions & 7 deletions src/server/routes/admin/nonces.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Static, Type } from "@sinclair/typebox";
import { FastifyInstance } from "fastify";
import { type Static, Type } from "@sinclair/typebox";
import type { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import {
Address,
type Address,
eth_getTransactionCount,
getAddress,
getRpcClient,
Expand All @@ -12,10 +12,10 @@ import {
lastUsedNonceKey,
recycledNoncesKey,
sentNoncesKey,
} from "../../../db/wallets/walletNonce";
import { getChain } from "../../../utils/chain";
import { redis } from "../../../utils/redis/redis";
import { thirdwebClient } from "../../../utils/sdk";
} from "../../../shared/db/wallets/walletNonce";
import { getChain } from "../../../shared/utils/chain";
import { redis } from "../../../shared/utils/redis/redis";
import { thirdwebClient } from "../../../shared/utils/sdk";
import { AddressSchema } from "../../schemas/address";
import { standardResponseSchema } from "../../schemas/sharedApiSchemas";
import { walletWithAddressParamSchema } from "../../schemas/wallet";
Expand Down
14 changes: 7 additions & 7 deletions src/server/routes/admin/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Static, Type } from "@sinclair/typebox";
import { Queue } from "bullmq";
import { FastifyInstance } from "fastify";
import { type Static, Type } from "@sinclair/typebox";
import type { Queue } from "bullmq";
import type { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import { stringify } from "thirdweb/utils";
import { TransactionDB } from "../../../db/transactions/db";
import { getConfig } from "../../../utils/cache/getConfig";
import { maybeDate } from "../../../utils/primitiveTypes";
import { redis } from "../../../utils/redis/redis";
import { TransactionDB } from "../../../shared/db/transactions/db";
import { getConfig } from "../../../shared/utils/cache/getConfig";
import { maybeDate } from "../../../shared/utils/primitiveTypes";
import { redis } from "../../../shared/utils/redis/redis";
import { MineTransactionQueue } from "../../../worker/queues/mineTransactionQueue";
import { SendTransactionQueue } from "../../../worker/queues/sendTransactionQueue";
import { createCustomError } from "../../middleware/error";
Expand Down
10 changes: 5 additions & 5 deletions src/server/routes/auth/access-tokens/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { buildJWT } from "@thirdweb-dev/auth";
import { LocalWallet } from "@thirdweb-dev/wallets";
import type { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import { updateConfiguration } from "../../../../db/configuration/updateConfiguration";
import { createToken } from "../../../../db/tokens/createToken";
import { accessTokenCache } from "../../../../utils/cache/accessToken";
import { getConfig } from "../../../../utils/cache/getConfig";
import { env } from "../../../../utils/env";
import { updateConfiguration } from "../../../../shared/db/configuration/updateConfiguration";
import { createToken } from "../../../../shared/db/tokens/createToken";
import { accessTokenCache } from "../../../../shared/utils/cache/accessToken";
import { getConfig } from "../../../../shared/utils/cache/getConfig";
import { env } from "../../../../shared/utils/env";
import { standardResponseSchema } from "../../../schemas/sharedApiSchemas";
import { AccessTokenSchema } from "./getAll";

Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/auth/access-tokens/getAll.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Type, type Static } from "@sinclair/typebox";
import type { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import { getAccessTokens } from "../../../../db/tokens/getAccessTokens";
import { getAccessTokens } from "../../../../shared/db/tokens/getAccessTokens";
import { AddressSchema } from "../../../schemas/address";
import { standardResponseSchema } from "../../../schemas/sharedApiSchemas";

Expand Down
4 changes: 2 additions & 2 deletions src/server/routes/auth/access-tokens/revoke.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Type, type Static } from "@sinclair/typebox";
import type { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import { revokeToken } from "../../../../db/tokens/revokeToken";
import { accessTokenCache } from "../../../../utils/cache/accessToken";
import { revokeToken } from "../../../../shared/db/tokens/revokeToken";
import { accessTokenCache } from "../../../../shared/utils/cache/accessToken";
import { standardResponseSchema } from "../../../schemas/sharedApiSchemas";

const requestBodySchema = Type.Object({
Expand Down
4 changes: 2 additions & 2 deletions src/server/routes/auth/access-tokens/update.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Type, type Static } from "@sinclair/typebox";
import type { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import { updateToken } from "../../../../db/tokens/updateToken";
import { accessTokenCache } from "../../../../utils/cache/accessToken";
import { updateToken } from "../../../../shared/db/tokens/updateToken";
import { accessTokenCache } from "../../../../shared/utils/cache/accessToken";
import { standardResponseSchema } from "../../../schemas/sharedApiSchemas";

const requestBodySchema = Type.Object({
Expand Down
12 changes: 6 additions & 6 deletions src/server/routes/auth/keypair/add.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Keypairs, Prisma } from "@prisma/client";
import { Static, Type } from "@sinclair/typebox";
import { FastifyInstance } from "fastify";
import { type Keypairs, Prisma } from "@prisma/client";
import { type Static, Type } from "@sinclair/typebox";
import type { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import { insertKeypair } from "../../../../db/keypair/insert";
import { isWellFormedPublicKey } from "../../../../utils/crypto";
import { insertKeypair } from "../../../../shared/db/keypair/insert";
import { isWellFormedPublicKey } from "../../../../shared/utils/crypto";
import { createCustomError } from "../../../middleware/error";
import {
KeypairAlgorithmSchema,
KeypairSchema,
toKeypairSchema,
} from "../../../schemas/keypairs";
} from "../../../../shared/schemas/keypair";
import { standardResponseSchema } from "../../../schemas/sharedApiSchemas";

const requestBodySchema = Type.Object({
Expand Down
11 changes: 7 additions & 4 deletions src/server/routes/auth/keypair/list.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Static, Type } from "@sinclair/typebox";
import { FastifyInstance } from "fastify";
import { type Static, Type } from "@sinclair/typebox";
import type { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import { listKeypairs } from "../../../../db/keypair/list";
import { KeypairSchema, toKeypairSchema } from "../../../schemas/keypairs";
import { listKeypairs } from "../../../../shared/db/keypair/list";
import {
KeypairSchema,
toKeypairSchema,
} from "../../../../shared/schemas/keypair";
import { standardResponseSchema } from "../../../schemas/sharedApiSchemas";

const responseBodySchema = Type.Object({
Expand Down
8 changes: 4 additions & 4 deletions src/server/routes/auth/keypair/remove.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Static, Type } from "@sinclair/typebox";
import { FastifyInstance } from "fastify";
import { type Static, Type } from "@sinclair/typebox";
import type { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import { deleteKeypair } from "../../../../db/keypair/delete";
import { keypairCache } from "../../../../utils/cache/keypair";
import { deleteKeypair } from "../../../../shared/db/keypair/delete";
import { keypairCache } from "../../../../shared/utils/cache/keypair";
import { standardResponseSchema } from "../../../schemas/sharedApiSchemas";

const requestBodySchema = Type.Object({
Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/auth/permissions/getAll.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Type, type Static } from "@sinclair/typebox";
import type { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import { prisma } from "../../../../db/client";
import { prisma } from "../../../../shared/db/client";
import { AddressSchema } from "../../../schemas/address";
import { standardResponseSchema } from "../../../schemas/sharedApiSchemas";

Expand Down
4 changes: 2 additions & 2 deletions src/server/routes/auth/permissions/grant.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Type, type Static } from "@sinclair/typebox";
import type { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import { updatePermissions } from "../../../../db/permissions/updatePermissions";
import { updatePermissions } from "../../../../shared/db/permissions/updatePermissions";
import { AddressSchema } from "../../../schemas/address";
import { permissionsSchema } from "../../../schemas/auth";
import { permissionsSchema } from "../../../../shared/schemas/auth";
import { standardResponseSchema } from "../../../schemas/sharedApiSchemas";

const requestBodySchema = Type.Object({
Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/auth/permissions/revoke.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Type, type Static } from "@sinclair/typebox";
import type { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import { deletePermissions } from "../../../../db/permissions/deletePermissions";
import { deletePermissions } from "../../../../shared/db/permissions/deletePermissions";
import { AddressSchema } from "../../../schemas/address";
import { standardResponseSchema } from "../../../schemas/sharedApiSchemas";

Expand Down
6 changes: 3 additions & 3 deletions src/server/routes/backend-wallet/cancel-nonces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import type { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import { eth_getTransactionCount, getRpcClient } from "thirdweb";
import { checksumAddress } from "thirdweb/utils";
import { getChain } from "../../../utils/chain";
import { thirdwebClient } from "../../../utils/sdk";
import { sendCancellationTransaction } from "../../../utils/transaction/cancelTransaction";
import { getChain } from "../../../shared/utils/chain";
import { thirdwebClient } from "../../../shared/utils/sdk";
import { sendCancellationTransaction } from "../../../shared/utils/transaction/cancelTransaction";
import {
requestQuerystringSchema,
standardResponseSchema,
Expand Down
Loading
Loading