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

fix(billing): ensure billing deps are not included #303

Merged
merged 1 commit into from
Aug 13, 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions apps/api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { Hono } from "hono";
import { cors } from "hono/cors";
import { container } from "tsyringe";

import { AuthInterceptor } from "@src/auth/services/auth.interceptor";
import { config } from "@src/core/config";
import { getSentry, sentryOptions } from "@src/core/providers/sentry.provider";
import { HonoErrorHandlerService } from "@src/core/services/hono-error-handler/hono-error-handler.service";
import { HttpLoggerService } from "@src/core/services/http-logger/http-logger.service";
import { LoggerService } from "@src/core/services/logger/logger.service";
import { RequestContextInterceptor } from "@src/core/services/request-storage/request-context.interceptor";
import { HonoInterceptor } from "@src/core/types/hono-interceptor.type";
import packageJson from "../package.json";
import { chainDb, syncUserSchema, userDb } from "./db/dbConnection";
import { apiRouter } from "./routers/apiRouter";
Expand Down Expand Up @@ -49,7 +49,6 @@ const scheduler = new Scheduler({

appHono.use(container.resolve(HttpLoggerService).intercept());
appHono.use(container.resolve(RequestContextInterceptor).intercept());
appHono.use(container.resolve(AuthInterceptor).intercept());
appHono.use(
"*",
sentry({
Expand All @@ -70,6 +69,9 @@ appHono.route("/internal", internalRouter);

// TODO: remove condition once billing is in prod
if (BILLING_ENABLED === "true") {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { AuthInterceptor } = require("./auth/services/auth.interceptor");
appHono.use(container.resolve<HonoInterceptor>(AuthInterceptor).intercept());
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { createWalletRouter, getWalletListRouter, signAndBroadcastTxRouter } = require("./billing");
appHono.route("/", createWalletRouter);
Expand Down
9 changes: 7 additions & 2 deletions apps/api/src/routers/userRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import assert from "http-assert";
import { container } from "tsyringe";
import * as uuid from "uuid";

import { AuthTokenService } from "@src/auth/services/auth-token/auth-token.service";
import { getCurrentUserId, optionalUserMiddleware, requiredUserMiddleware } from "@src/middlewares/userMiddleware";
import {
addTemplateFavorite,
Expand Down Expand Up @@ -132,10 +131,16 @@ userRequiredRouter.post("/tokenInfo", async c => {
});

async function extractAnonymousUserId(c: Context) {
if (process.env.BILLING_ENABLED !== "true") {
return;
}
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { AuthTokenService } = require("@src/auth/services/auth-token/auth-token.service");

const anonymousBearer = c.req.header("x-anonymous-authorization");

if (anonymousBearer) {
const anonymousUserId = await container.resolve(AuthTokenService).getValidUserId(anonymousBearer);
const anonymousUserId = await container.resolve<any>(AuthTokenService).getValidUserId(anonymousBearer);
assert(anonymousUserId, 401, "Invalid anonymous user token");

return anonymousUserId;
Expand Down
Loading