diff --git a/apps/api/src/app.ts b/apps/api/src/app.ts index b1eab8539..bc18e1afb 100644 --- a/apps/api/src/app.ts +++ b/apps/api/src/app.ts @@ -73,8 +73,8 @@ if (BILLING_ENABLED === "true") { const { AuthInterceptor } = require("./auth/services/auth.interceptor"); appHono.use(container.resolve(AuthInterceptor).intercept()); // eslint-disable-next-line @typescript-eslint/no-var-requires - const { createWalletRouter, getWalletListRouter, signAndBroadcastTxRouter, checkoutRouter, stripeWebhook } = require("./billing"); - appHono.route("/", createWalletRouter); + const { startTrialRouter, getWalletListRouter, signAndBroadcastTxRouter, checkoutRouter, stripeWebhook } = require("./billing"); + appHono.route("/", startTrialRouter); appHono.route("/", getWalletListRouter); appHono.route("/", signAndBroadcastTxRouter); appHono.route("/", checkoutRouter); diff --git a/apps/api/src/billing/controllers/wallet/wallet.controller.ts b/apps/api/src/billing/controllers/wallet/wallet.controller.ts index bda758a39..d4b1864b2 100644 --- a/apps/api/src/billing/controllers/wallet/wallet.controller.ts +++ b/apps/api/src/billing/controllers/wallet/wallet.controller.ts @@ -3,7 +3,7 @@ import { Lifecycle, scoped } from "tsyringe"; import { Protected } from "@src/auth/services/auth.service"; import type { WalletListOutputResponse, WalletOutputResponse } from "@src/billing/http-schemas/wallet.schema"; -import type { CreateWalletRequestInput, SignTxRequestInput, SignTxResponseOutput } from "@src/billing/routes"; +import type { SignTxRequestInput, SignTxResponseOutput, StartTrialRequestInput } from "@src/billing/routes"; import { GetWalletQuery } from "@src/billing/routes/get-wallet-list/get-wallet-list.router"; import { WalletInitializerService } from "@src/billing/services"; import { RefillService } from "@src/billing/services/refill/refill.service"; @@ -22,7 +22,7 @@ export class WalletController { @WithTransaction() @Protected([{ action: "create", subject: "UserWallet" }]) - async create({ data: { userId } }: CreateWalletRequestInput): Promise { + async create({ data: { userId } }: StartTrialRequestInput): Promise { return { data: await this.walletInitializer.initializeAndGrantTrialLimits(userId) }; diff --git a/apps/api/src/billing/routes/checkout/checkout.router.ts b/apps/api/src/billing/routes/checkout/checkout.router.ts index f4e15d229..ad5a1d773 100644 --- a/apps/api/src/billing/routes/checkout/checkout.router.ts +++ b/apps/api/src/billing/routes/checkout/checkout.router.ts @@ -8,7 +8,7 @@ const route = createRoute({ method: "get", path: "/v1/checkout", summary: "Creates a stripe checkout session and redirects to checkout", - tags: ["Wallets"], + tags: ["Wallet"], request: {}, responses: { 301: { diff --git a/apps/api/src/billing/routes/get-wallet-list/get-wallet-list.router.ts b/apps/api/src/billing/routes/get-wallet-list/get-wallet-list.router.ts index 6276460b3..bf04c4333 100644 --- a/apps/api/src/billing/routes/get-wallet-list/get-wallet-list.router.ts +++ b/apps/api/src/billing/routes/get-wallet-list/get-wallet-list.router.ts @@ -16,7 +16,7 @@ const route = createRoute({ method: "get", path: "/v1/wallets", summary: "Get a list of wallets", - tags: ["Wallets"], + tags: ["Wallet"], request: { query: GetWalletRequestQuerySchema }, diff --git a/apps/api/src/billing/routes/index.ts b/apps/api/src/billing/routes/index.ts index 79da4eed4..428aa73e4 100644 --- a/apps/api/src/billing/routes/index.ts +++ b/apps/api/src/billing/routes/index.ts @@ -1,4 +1,4 @@ -export * from "@src/billing/routes/create-wallet/create-wallet.router"; +export * from "@src/billing/routes/start-trial/start-trial.router"; export * from "@src/billing/routes/get-wallet-list/get-wallet-list.router"; export * from "@src/billing/routes/checkout/checkout.router"; export * from "@src/billing/routes/sign-and-broadcast-tx/sign-and-broadcast-tx.router"; diff --git a/apps/api/src/billing/routes/sign-and-broadcast-tx/sign-and-broadcast-tx.router.ts b/apps/api/src/billing/routes/sign-and-broadcast-tx/sign-and-broadcast-tx.router.ts index 1a0d20d17..bdd814a1b 100644 --- a/apps/api/src/billing/routes/sign-and-broadcast-tx/sign-and-broadcast-tx.router.ts +++ b/apps/api/src/billing/routes/sign-and-broadcast-tx/sign-and-broadcast-tx.router.ts @@ -41,7 +41,7 @@ const route = createRoute({ method: "post", path: "/v1/tx", summary: "Signs a transaction via a user managed wallet", - tags: ["Wallets"], + tags: ["Wallet"], request: { body: { content: { diff --git a/apps/api/src/billing/routes/create-wallet/create-wallet.router.ts b/apps/api/src/billing/routes/start-trial/start-trial.router.ts similarity index 71% rename from apps/api/src/billing/routes/create-wallet/create-wallet.router.ts rename to apps/api/src/billing/routes/start-trial/start-trial.router.ts index 050f628c3..65d656cfa 100644 --- a/apps/api/src/billing/routes/create-wallet/create-wallet.router.ts +++ b/apps/api/src/billing/routes/start-trial/start-trial.router.ts @@ -6,24 +6,24 @@ import { WalletController } from "@src/billing/controllers/wallet/wallet.control import { WalletResponseOutputSchema } from "@src/billing/http-schemas/wallet.schema"; import { OpenApiHonoHandled } from "@src/core/services/open-api-hono-handled/open-api-hono-handled"; -export const CreateWalletRequestInputSchema = z.object({ +export const StartTrialRequestInputSchema = z.object({ data: z.object({ userId: z.string().openapi({}) }) }); -export type CreateWalletRequestInput = z.infer; +export type StartTrialRequestInput = z.infer; const route = createRoute({ method: "post", - path: "/v1/wallets", + path: "/v1/start-trial", summary: "Creates a managed wallet for a user", - tags: ["Wallets"], + tags: ["Wallet"], request: { body: { content: { "application/json": { - schema: CreateWalletRequestInputSchema + schema: StartTrialRequestInputSchema } } } @@ -39,8 +39,8 @@ const route = createRoute({ } } }); -export const createWalletRouter = new OpenApiHonoHandled(); +export const startTrialRouter = new OpenApiHonoHandled(); -createWalletRouter.openapi(route, async function routeCreateWallet(c) { +startTrialRouter.openapi(route, async function routeStartTrial(c) { return c.json(await container.resolve(WalletController).create(c.req.valid("json")), 200); }); diff --git a/apps/api/test/functional/create-wallet.spec.ts b/apps/api/test/functional/start-trial.spec.ts similarity index 95% rename from apps/api/test/functional/create-wallet.spec.ts rename to apps/api/test/functional/start-trial.spec.ts index 24ae07e42..468eb4c8a 100644 --- a/apps/api/test/functional/create-wallet.spec.ts +++ b/apps/api/test/functional/start-trial.spec.ts @@ -10,7 +10,7 @@ import { ApiPgDatabase, POSTGRES_DB, resolveTable } from "@src/core"; jest.setTimeout(20000); -describe("wallets", () => { +describe("start trial", () => { const userWalletsTable = resolveTable("UserWallets"); const config = container.resolve(BILLING_CONFIG); const db = container.resolve(POSTGRES_DB); @@ -22,7 +22,7 @@ describe("wallets", () => { await dbService.cleanAll(); }); - describe("POST /v1/wallets", () => { + describe("POST /v1/start-trial", () => { it("should create a wallet for a user", async () => { const userResponse = await app.request("/v1/anonymous-users", { method: "POST", @@ -33,7 +33,7 @@ describe("wallets", () => { token } = await userResponse.json(); const headers = new Headers({ "Content-Type": "application/json", authorization: `Bearer ${token}` }); - const createWalletResponse = await app.request("/v1/wallets", { + const createWalletResponse = await app.request("/v1/start-trial", { method: "POST", body: JSON.stringify({ data: { userId } }), headers @@ -102,7 +102,7 @@ describe("wallets", () => { }); it("should throw 401 provided no auth header ", async () => { - const createWalletResponse = await app.request("/v1/wallets", { + const createWalletResponse = await app.request("/v1/start-trial", { method: "POST", body: JSON.stringify({ data: { userId: faker.string.uuid() } }), headers: new Headers({ "Content-Type": "application/json" }) diff --git a/apps/api/test/services/wallet-testing.service.ts b/apps/api/test/services/wallet-testing.service.ts index c738750c3..960d2a2b9 100644 --- a/apps/api/test/services/wallet-testing.service.ts +++ b/apps/api/test/services/wallet-testing.service.ts @@ -5,7 +5,7 @@ export class WalletTestingService { async createUserAndWallet() { const { user, token } = await this.createUser(); - const walletResponse = await this.app.request("/v1/wallets", { + const walletResponse = await this.app.request("/v1/start-trial", { method: "POST", body: JSON.stringify({ data: { userId: user.id } diff --git a/packages/http-sdk/src/managed-wallet-http/managed-wallet-http.service.ts b/packages/http-sdk/src/managed-wallet-http/managed-wallet-http.service.ts index 69d7502fa..fb566a688 100644 --- a/packages/http-sdk/src/managed-wallet-http/managed-wallet-http.service.ts +++ b/packages/http-sdk/src/managed-wallet-http/managed-wallet-http.service.ts @@ -10,7 +10,7 @@ export interface ApiWalletOutput { export class ManagedWalletHttpService extends ApiHttpService { async createWallet(userId: string) { - return this.addWalletEssentials(this.extractApiData(await this.post("v1/wallets", { data: { userId } }))); + return this.addWalletEssentials(this.extractApiData(await this.post("v1/start-trial", { data: { userId } }))); } async getWallet(userId: string) {