-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP refactor(billing): rename files and improve logging
refs #247
1 parent
a18a906
commit dcf0644
Showing
43 changed files
with
402 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { env } from "./env"; | ||
import { USDC_IBC_DENOMS } from "./network"; | ||
import { envConfig } from "./env.config"; | ||
import { USDC_IBC_DENOMS } from "./network.config"; | ||
|
||
export const config = { | ||
...env, | ||
...envConfig, | ||
USDC_IBC_DENOMS | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from "./userWalletSchema"; | ||
export * from "./user-wallet/user-wallet.schema"; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from "./user-wallet/UserWalletModel"; | ||
export * from "./user-wallet/user-wallet.model"; |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import "./userWalletSchemaProvider"; | ||
import "./configProvider"; | ||
import "./user-wallet-schema.provider"; | ||
import "./config.provider"; | ||
|
||
export * from "./userWalletSchemaProvider"; | ||
export * from "./configProvider"; | ||
export * from "./user-wallet-schema.provider"; | ||
export * from "./config.provider"; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from "./user-wallet/UserWalletRepository"; | ||
export * from "./user-wallet/user-wallet.repository"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from "./wallet"; | ||
export * from "./wallet/wallet.router"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from "./wallet-manager/WalletManager"; | ||
export * from "./rpc-message-service/RpcMessageService"; | ||
export * from "./wallet-initializer/WalletInitializer"; | ||
export * from "@src/billing/services/wallet/wallet.service"; | ||
export * from "./rpc-message-service/rpc-message.service"; | ||
export * from "./wallet-initializer/wallet-initializer.service"; |
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
...s/wallet-initializer/WalletInitializer.ts → ...initializer/wallet-initializer.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import { env } from "./env"; | ||
import { envConfig } from "./env.config"; | ||
|
||
export const config = { | ||
...env | ||
...envConfig | ||
}; | ||
export type CoreConfig = typeof config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import "./providers"; | ||
export * from "./providers"; | ||
|
||
export * from "./services"; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from "./PostgresProvider"; | ||
export * from "./configProvider"; | ||
export * from "./postgres.provider"; | ||
export * from "./config.provider"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { DefaultLogger } from "drizzle-orm/logger"; | ||
import { drizzle } from "drizzle-orm/node-postgres"; | ||
import { Pool } from "pg"; | ||
import { container, inject } from "tsyringe"; | ||
|
||
import * as billingSchemas from "@src/billing/model-schemas"; | ||
import { config } from "@src/core/config"; | ||
import { PostgresLoggerService } from "@src/core/services/postgres-logger/postgres-logger.service"; | ||
|
||
const pool = new Pool({ | ||
connectionString: config.POSTGRES_DB_URI | ||
}); | ||
|
||
export const pgDatabase = drizzle(pool, { logger: new DefaultLogger({ writer: container.resolve(PostgresLoggerService) }), schema: billingSchemas }); | ||
|
||
export type ApiPgSchema = typeof billingSchemas; | ||
|
||
export const POSTGRES_DB = "POSTGRES_DB"; | ||
container.register(POSTGRES_DB, { useValue: pgDatabase }); | ||
|
||
export const InjectPg = () => inject(POSTGRES_DB); | ||
export type ApiPgDatabase = typeof pgDatabase; |
11 changes: 0 additions & 11 deletions
11
apps/api/src/core/services/contextual-logger/ContextualLogger.ts
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
apps/api/src/core/services/contextual-logger/contextual-logger.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Bindings } from "pino"; | ||
import { injectable } from "tsyringe"; | ||
|
||
import { LoggerService } from "@src/core/services/logger/logger.service"; | ||
import { RequestStorageService } from "@src/core/services/request-storage/request-storage.service"; | ||
|
||
@injectable() | ||
export class ContextualLoggerService extends LoggerService { | ||
constructor(private readonly requestStorage: RequestStorageService) { | ||
super(); | ||
} | ||
|
||
setContext(bindings: Bindings) { | ||
this.pino = this.pino.child(bindings); | ||
} | ||
|
||
protected toLoggableInput(message: any) { | ||
const { context } = this.requestStorage; | ||
const requestId = context?.get("requestId"); | ||
const loggableMessage = super.toLoggableInput(message); | ||
|
||
if (!requestId) { | ||
return loggableMessage; | ||
} | ||
|
||
if (typeof loggableMessage === "object" && !Array.isArray(loggableMessage)) { | ||
return { requestId, ...loggableMessage }; | ||
} | ||
|
||
return { requestId, msg: loggableMessage }; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
apps/api/src/core/services/http-logger/http-logger.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Context, Next } from "hono"; | ||
import { singleton } from "tsyringe"; | ||
|
||
import { ContextualLoggerService } from "@src/core/services"; | ||
import type { HonoInterceptor } from "@src/core/types/hono-interceptor.type"; | ||
|
||
@singleton() | ||
export class HttpLoggerService implements HonoInterceptor { | ||
constructor(private readonly logger: ContextualLoggerService) { | ||
logger.setContext({ context: "HTTP" }); | ||
} | ||
|
||
intercept() { | ||
return async (c: Context, next: Next) => { | ||
const timer = performance.now(); | ||
this.logger.info({ | ||
method: c.req.method, | ||
url: c.req.url | ||
}); | ||
|
||
await next(); | ||
|
||
this.logger.info({ | ||
status: c.res.status, | ||
duration: `${(performance.now() - timer).toFixed(3)}ms` | ||
}); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export * from "./tx-manager/TxManager"; | ||
export * from "./logger/Logger"; | ||
export * from "./contextual-logger/ContextualLogger"; | ||
export * from "./postgres/postgres"; | ||
export * from "./log-http-requests/logHttpRequests"; | ||
export * from "./request-storage/RequestStorage"; | ||
export * from "@src/core/services/tx/tx.service"; | ||
export * from "./logger/logger.service"; | ||
export * from "./contextual-logger/contextual-logger.service"; | ||
export * from "@src/core/services/http-logger/http-logger.service"; | ||
export * from "./request-storage/request-storage.service"; | ||
export * from "./postgres-migrator/postgres-migrator.service"; |
19 changes: 0 additions & 19 deletions
19
apps/api/src/core/services/log-http-requests/logHttpRequests.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import pino, { Bindings, LoggerOptions } from "pino"; | ||
|
||
import { config } from "@src/core/config"; | ||
|
||
export class LoggerService { | ||
protected pino: pino.Logger; | ||
|
||
readonly isPretty = config.LOG_FORMAT === "pretty"; | ||
|
||
constructor(bindings?: Bindings) { | ||
const options: LoggerOptions = { level: config.LOG_LEVEL }; | ||
|
||
if (this.isPretty) { | ||
options.transport = { | ||
target: "pino-pretty" | ||
}; | ||
} | ||
|
||
this.pino = pino(options); | ||
|
||
if (bindings) { | ||
this.pino = this.pino.child(bindings); | ||
} | ||
} | ||
|
||
info(message: any) { | ||
message = this.toLoggableInput(message); | ||
return this.pino.info(message); | ||
} | ||
|
||
error(message: any) { | ||
this.pino.error(this.toLoggableInput(message)); | ||
} | ||
|
||
warn(message: any) { | ||
return this.pino.warn(this.toLoggableInput(message)); | ||
} | ||
|
||
debug(message: any) { | ||
return this.pino.debug(this.toLoggableInput(message)); | ||
} | ||
|
||
protected toLoggableInput(message: any) { | ||
if (message instanceof Error) { | ||
return message.stack; | ||
} | ||
|
||
return message; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
import "reflect-metadata"; | ||
|
||
import { container } from "tsyringe"; | ||
|
||
import { initApp } from "@src/app"; | ||
import { migrateDb } from "@src/core/services/postgres/postgres"; | ||
import { PostgresMigratorService } from "@src/core"; | ||
|
||
migrateDb().then(() => initApp()); | ||
container | ||
.resolve(PostgresMigratorService) | ||
.migrate() | ||
.then(() => initApp()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import "reflect-metadata"; | ||
|
||
import dotenv from "dotenv"; | ||
import { container } from "tsyringe"; | ||
|
||
import { migrateDb } from "@src/core/services/postgres/postgres"; | ||
import { PostgresMigratorService } from "@src/core"; | ||
|
||
dotenv.config({ path: ".env.functional.test" }); | ||
|
||
beforeAll(async () => { | ||
await migrateDb(); | ||
await container.resolve(PostgresMigratorService).migrate(); | ||
}); |
Oops, something went wrong.