Skip to content

refactor: api types#1810

Merged
stalniy merged 1 commit intomainfrom
refactor/api-import-types-fix
Aug 15, 2025
Merged

refactor: api types#1810
stalniy merged 1 commit intomainfrom
refactor/api-import-types-fix

Conversation

@stalniy
Copy link
Contributor

@stalniy stalniy commented Aug 14, 2025

Why

This is needed for tsup to compile our app. Basically every type should be imported as type

Summary by CodeRabbit

  • Refactor
    • Consolidated and reduced runtime dependencies by converting several compile-time-only imports to type-only usage across backend services, repositories, and controllers.
  • Chores
    • Code hygiene and import consistency improvements to reduce bundle/runtime surface without altering behavior or APIs.

No user-facing changes in this release.

@stalniy stalniy requested a review from a team as a code owner August 14, 2025 05:41
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 14, 2025

Walkthrough

Refactors numerous import statements across API modules to use TypeScript type-only imports. Changes are limited to import declarations (types vs. value imports); runtime behavior, control flow, and public APIs are unchanged.

Changes

Cohort / File(s) Summary of changes
Repository type-only PG/Ability imports
apps/api/src/auth/repositories/api-key/api-key.repository.ts, apps/api/src/billing/repositories/checkout-session/checkout-session.repository.ts, apps/api/src/billing/repositories/payment-method/payment-method.repository.ts, apps/api/src/billing/repositories/user-wallet/user-wallet.repository.ts, apps/api/src/deployment/repositories/deployment-setting/deployment-setting.repository.ts, apps/api/src/user/repositories/user/user.repository.ts
Convert ApiPgDatabase, ApiPgTables, and AbilityParams to type-only imports; keep InjectPg, InjectPgTable, and BaseRepository as value imports.
Billing services/controllers: type-only BillingConfig and related types
apps/api/src/billing/controllers/checkout/checkout.controller.ts, apps/api/src/billing/services/balances/balances.service.ts, apps/api/src/billing/services/financial-stats/financial-stats.service.ts, apps/api/src/billing/services/managed-user-wallet/managed-user-wallet.service.ts, apps/api/src/billing/services/provider-cleanup/provider-cleanup.service.ts, apps/api/src/billing/services/refill/refill.service.ts, apps/api/src/deployment/services/sdl/sdl.service.ts, apps/api/src/provider/services/provider/provider.service.ts
Import BillingConfig as type-only; also convert UserWalletInput/UserWalletOutput and ProviderCleanupParams to type-only where applicable. Runtime DI tokens (e.g., InjectBillingConfig) remain value imports.
Deployment controllers: type-only schema imports
apps/api/src/deployment/controllers/deployment-setting/deployment-setting.controller.ts, apps/api/src/deployment/controllers/lease/lease.controller.ts
Switch HTTP schema DTO types (Create/Update/Find*, GetDeploymentResponse, CreateLeaseRequest) to type-only imports; method signatures remain the same.
Core services: type-only dependencies
apps/api/src/core/services/analytics/analytics.service.ts, apps/api/src/core/services/tx/tx.service.ts, apps/api/src/healthz/services/healthz/healthz.service.ts
Make Amplitude/Hasher, ApiPgDatabase/ApiPgTables, and ApiPgDatabase type-only imports respectively; keep runtime injection tokens as value imports.
GPU service: type-only type imports
apps/api/src/gpu/services/gpu.service.ts
Convert GpuVendor and GpuBreakdownQuery to type-only imports; runtime behavior unchanged.
Provider graph data service: type-only stats types
apps/api/src/provider/services/provider-graph-data/provider-graph-data.service.ts
Convert ProviderStats and ProviderStatsKey to type-only imports; used only in type positions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • ygrishajev
  • baktun14

Poem

I nibble lines of code with care,
Making imports light as air.
Types stay neat, no runtime fuss,
Carrots saved for future us.
Hop—build passes, tidy and fair. 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/api-import-types-fix

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🔭 Outside diff range comments (9)
apps/api/src/user/repositories/user/user.repository.ts (1)

2-3: Convert Drizzle types to type-only imports for full consistency with PR goal

Both SQL and PgUpdateSetSource are types and should be imported via import type to avoid pulling runtime code.

Apply:

-import { and, desc, eq, isNull, lt, lte, SQL, sql } from "drizzle-orm";
+import { and, desc, eq, isNull, lt, lte, sql } from "drizzle-orm";
+import type { SQL } from "drizzle-orm";
-import { PgUpdateSetSource } from "drizzle-orm/pg-core";
+import type { PgUpdateSetSource } from "drizzle-orm/pg-core";
apps/api/src/provider/services/provider/provider.service.ts (1)

69-75: Avoid any in catch; use unknown and narrow safely

Guideline: never use any. Replace with unknown and narrow via instanceof/property checks.

Apply:

-      } catch (err: any) {
-        if (err.message?.includes("no lease for deployment") && i < this.MANIFEST_SEND_MAX_RETRIES) {
+      } catch (err: unknown) {
+        if (err instanceof Error && err.message.includes("no lease for deployment") && i < this.MANIFEST_SEND_MAX_RETRIES) {
           await delay(this.MANIFEST_SEND_RETRY_DELAY);
           continue;
         }
-        throw new Error(err?.response?.data || err);
+        const responseData =
+          typeof err === "object" &&
+          err !== null &&
+          "response" in err &&
+          typeof (err as { response?: { data?: unknown } }).response === "object" &&
+          (err as { response?: { data?: unknown } }).response !== null
+            ? (err as { response?: { data?: unknown } }).response?.data
+            : undefined;
+        const message =
+          typeof responseData === "string" ? responseData : err instanceof Error ? err.message : String(err);
+        throw new Error(message);
       }
apps/api/src/core/services/tx/tx.service.ts (1)

3-3: Make PostgresJsQueryResultHKT a type-only import

It’s a type parameter only; avoid pulling any runtime from drizzle.

Apply:

-import { PostgresJsQueryResultHKT } from "drizzle-orm/postgres-js/session";
+import type { PostgresJsQueryResultHKT } from "drizzle-orm/postgres-js/session";
apps/api/src/core/services/analytics/analytics.service.ts (1)

21-21: Avoid using any in public method signature

Per our TS guidelines, replace Record<string, any> with a safer alternative.

Apply this diff:

-  track(userId: string, eventName: AnalyticsEvent, eventProperties: Record<string, any> = {}) {
+  track(userId: string, eventName: AnalyticsEvent, eventProperties: Record<string, unknown> = {}) {

If you can define a stricter schema (e.g., string | number | boolean | null), even better:

type AnalyticsProps = Record<string, string | number | boolean | null>;
apps/api/src/billing/repositories/checkout-session/checkout-session.repository.ts (1)

41-46: Don’t use any in catch; narrow from unknown

Replace catch (error: any) with unknown and narrow to Error to satisfy our TS guideline.

Apply this diff:

-    } catch (error: any) {
-      if (error.message === "Session is still active") {
+    } catch (error: unknown) {
+      if (error instanceof Error && error.message === "Session is still active") {
         this.logger.warn({ event: "SESSION_STILL_ACTIVE", sessionId });
         return;
       }
     }
apps/api/src/deployment/repositories/deployment-setting/deployment-setting.repository.ts (1)

64-69: LEFT JOIN allows null walletId; remove unsafe cast or strengthen JOINs

walletId can be null due to LEFT JOINs, yet results are cast to AutoTopUpDeployment[] (which requires a non-null walletId). This is unsound and can lead to runtime issues downstream.

Recommended fix: use INNER JOINs to guarantee presence of Users and UserWallets rows.

Apply this diff:

-        .leftJoin(Users, eq(this.table.userId, Users.id))
-        .leftJoin(UserWallets, eq(Users.id, UserWallets.userId))
+        .innerJoin(Users, eq(this.table.userId, Users.id))
+        .innerJoin(UserWallets, eq(Users.id, UserWallets.userId))

Alternative if LEFT JOINs are required by business logic: filter out nulls before yielding and drop the unsafe cast.

-      if (items.length) {
-        // BUGALERT: walletId may be null because of LEFT JOIN. should be INNER JOIN?
-        yield items as AutoTopUpDeployment[];
-      }
+      if (items.length) {
+        const safeItems = items.filter((i): i is AutoTopUpDeployment => i.walletId != null);
+        if (safeItems.length) {
+          yield safeItems;
+        }
+      }
apps/api/src/billing/controllers/checkout/checkout.controller.ts (1)

37-45: Avoid any in catch blocks; use unknown and narrow

The coding guidelines prohibit any. Use unknown and narrow to Error to read message safely.

-    } catch (error: any) {
-      if (error.message === "Price invalid") {
-        return c.redirect(`${redirectUrl}?invalid-price=true`);
-      }
-
-      this.logger.error(error);
-
-      return c.redirect(`${redirectUrl}?unknown-error=true`);
-    }
+    } catch (error: unknown) {
+      const message = error instanceof Error ? error.message : String(error);
+      if (message === "Price invalid") {
+        return c.redirect(`${redirectUrl}?invalid-price=true`);
+      }
+      this.logger.error(error instanceof Error ? error : new Error(message));
+      return c.redirect(`${redirectUrl}?unknown-error=true`);
+    }
apps/api/src/billing/services/managed-user-wallet/managed-user-wallet.service.ts (1)

108-111: Replace any with the proper options type

The guidelines disallow any. This function expects the full SpendingAuthorizationMsgOptions (includes denom and limit).

-  private async authorizeDeploymentSpending(options: any) {
+  private async authorizeDeploymentSpending(options: SpendingAuthorizationMsgOptions) {
     const deploymentAllowanceMsg = this.rpcMessageService.getDepositDeploymentGrantMsg(options);
     return await this.managedSignerService.executeRootTx([deploymentAllowanceMsg]);
   }
apps/api/src/billing/services/provider-cleanup/provider-cleanup.service.ts (1)

62-76: Replace any in catch with unknown and narrow the error

Coding guidelines disallow any. Narrow the error safely before accessing .message.

Apply this diff:

-      } catch (error: any) {
-        if (error.message.includes("not allowed to pay fees")) {
+      } catch (error: unknown) {
+        if (error instanceof Error && error.message.includes("not allowed to pay fees")) {
           if (!options.dryRun) {
             await this.managedUserWalletService.authorizeSpending({
               address: wallet.address!,
               limits: {
                 fees: this.config.FEE_ALLOWANCE_REFILL_AMOUNT
               }
             });
             await this.managedSignerService.executeManagedTx(wallet.id, [message]);
             this.logger.info({ event: "PROVIDER_CLEAN_UP_SUCCESS" });
           }
         } else {
           throw error;
         }
🧹 Nitpick comments (7)
apps/api/src/provider/services/provider/provider.service.ts (1)

15-15: Import ProviderIdentity as a type-only import

Used strictly for typing local constants; no runtime usage.

Apply:

-import { ProviderIdentity } from "@src/provider/services/provider/provider-proxy.service";
+import type { ProviderIdentity } from "@src/provider/services/provider/provider-proxy.service";
apps/api/src/billing/repositories/payment-method/payment-method.repository.ts (1)

41-43: Minor: remove redundant await

deleteBy presumably returns a Promise; returning it directly avoids an unnecessary await.

-  async deleteByFingerprint(fingerprint: string, paymentMethodId: string, userId: string) {
-    return await this.deleteBy({ fingerprint, paymentMethodId, userId });
-  }
+  async deleteByFingerprint(fingerprint: string, paymentMethodId: string, userId: string) {
+    return this.deleteBy({ fingerprint, paymentMethodId, userId });
+  }
apps/api/src/billing/services/balances/balances.service.ts (2)

1-1: Import DeploymentInfo as a type-only import

DeploymentInfo is only used in type positions (reduce callback). Make it a type-only import to match the PR’s goal.

-import { AuthzHttpService, DeploymentHttpService, DeploymentInfo } from "@akashnetwork/http-sdk";
+import { AuthzHttpService, DeploymentHttpService, type DeploymentInfo } from "@akashnetwork/http-sdk";

4-4: Also import Wallet as a type-only import

Wallet is used purely as a type annotation in the constructor parameter. Importing it as type reduces runtime imports and aligns with the PR changes. The injection relies on the @InjectWallet token, not the type.

-import { Wallet } from "@src/billing/lib/wallet/wallet";
+import { type Wallet } from "@src/billing/lib/wallet/wallet";
apps/api/src/billing/services/managed-user-wallet/managed-user-wallet.service.ts (2)

4-4: Make EncodeObject a type-only import

EncodeObject is used only as a type (messages arrays). Import it as a type.

-import { DirectSecp256k1HdWallet, EncodeObject } from "@cosmjs/proto-signing";
+import { DirectSecp256k1HdWallet, type EncodeObject } from "@cosmjs/proto-signing";

13-13: Import SpendingAuthorizationMsgOptions as a type-only import

It’s used purely in type positions; keep it out of runtime bundles.

-import { RpcMessageService, SpendingAuthorizationMsgOptions } from "../rpc-message-service/rpc-message.service";
+import { RpcMessageService, type SpendingAuthorizationMsgOptions } from "../rpc-message-service/rpc-message.service";
apps/api/src/provider/services/provider-graph-data/provider-graph-data.service.ts (1)

106-112: Fix typo in variable name for readability

Rename isFirstFifteenMinuesOfDay to isFirstFifteenMinutesOfDay. Keeps code clear and avoids future confusion.

-    const isFirstFifteenMinuesOfDay = now.getHours() === 0 && now.getMinutes() <= 15;
+    const isFirstFifteenMinutesOfDay = now.getHours() === 0 && now.getMinutes() <= 15;
     const lastItem = stats.length > 0 ? stats[stats.length - 1] : null;
 
     const lastItemIsForToday = lastItem && isSameDay(lastItem.date, now);
-    if (isFirstFifteenMinuesOfDay && lastItemIsForToday) {
+    if (isFirstFifteenMinutesOfDay && lastItemIsForToday) {
       return stats.slice(0, stats.length - 1);
     }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b16573b and c40eb58.

📒 Files selected for processing (21)
  • apps/api/src/auth/repositories/api-key/api-key.repository.ts (1 hunks)
  • apps/api/src/billing/controllers/checkout/checkout.controller.ts (1 hunks)
  • apps/api/src/billing/repositories/checkout-session/checkout-session.repository.ts (1 hunks)
  • apps/api/src/billing/repositories/payment-method/payment-method.repository.ts (1 hunks)
  • apps/api/src/billing/repositories/user-wallet/user-wallet.repository.ts (1 hunks)
  • apps/api/src/billing/services/balances/balances.service.ts (1 hunks)
  • apps/api/src/billing/services/financial-stats/financial-stats.service.ts (1 hunks)
  • apps/api/src/billing/services/managed-user-wallet/managed-user-wallet.service.ts (1 hunks)
  • apps/api/src/billing/services/provider-cleanup/provider-cleanup.service.ts (1 hunks)
  • apps/api/src/billing/services/refill/refill.service.ts (1 hunks)
  • apps/api/src/core/services/analytics/analytics.service.ts (1 hunks)
  • apps/api/src/core/services/tx/tx.service.ts (1 hunks)
  • apps/api/src/deployment/controllers/deployment-setting/deployment-setting.controller.ts (1 hunks)
  • apps/api/src/deployment/controllers/lease/lease.controller.ts (1 hunks)
  • apps/api/src/deployment/repositories/deployment-setting/deployment-setting.repository.ts (1 hunks)
  • apps/api/src/deployment/services/sdl/sdl.service.ts (1 hunks)
  • apps/api/src/gpu/services/gpu.service.ts (1 hunks)
  • apps/api/src/healthz/services/healthz/healthz.service.ts (1 hunks)
  • apps/api/src/provider/services/provider-graph-data/provider-graph-data.service.ts (1 hunks)
  • apps/api/src/provider/services/provider/provider.service.ts (1 hunks)
  • apps/api/src/user/repositories/user/user.repository.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/general.mdc)

Never use type any or cast to type any. Always define the proper TypeScript types.

Files:

  • apps/api/src/billing/services/balances/balances.service.ts
  • apps/api/src/gpu/services/gpu.service.ts
  • apps/api/src/healthz/services/healthz/healthz.service.ts
  • apps/api/src/billing/services/financial-stats/financial-stats.service.ts
  • apps/api/src/billing/services/refill/refill.service.ts
  • apps/api/src/billing/repositories/payment-method/payment-method.repository.ts
  • apps/api/src/deployment/services/sdl/sdl.service.ts
  • apps/api/src/provider/services/provider/provider.service.ts
  • apps/api/src/provider/services/provider-graph-data/provider-graph-data.service.ts
  • apps/api/src/billing/controllers/checkout/checkout.controller.ts
  • apps/api/src/core/services/analytics/analytics.service.ts
  • apps/api/src/user/repositories/user/user.repository.ts
  • apps/api/src/deployment/repositories/deployment-setting/deployment-setting.repository.ts
  • apps/api/src/deployment/controllers/lease/lease.controller.ts
  • apps/api/src/billing/services/managed-user-wallet/managed-user-wallet.service.ts
  • apps/api/src/billing/repositories/checkout-session/checkout-session.repository.ts
  • apps/api/src/auth/repositories/api-key/api-key.repository.ts
  • apps/api/src/core/services/tx/tx.service.ts
  • apps/api/src/deployment/controllers/deployment-setting/deployment-setting.controller.ts
  • apps/api/src/billing/services/provider-cleanup/provider-cleanup.service.ts
  • apps/api/src/billing/repositories/user-wallet/user-wallet.repository.ts
**/*.{js,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/general.mdc)

**/*.{js,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code

Files:

  • apps/api/src/billing/services/balances/balances.service.ts
  • apps/api/src/gpu/services/gpu.service.ts
  • apps/api/src/healthz/services/healthz/healthz.service.ts
  • apps/api/src/billing/services/financial-stats/financial-stats.service.ts
  • apps/api/src/billing/services/refill/refill.service.ts
  • apps/api/src/billing/repositories/payment-method/payment-method.repository.ts
  • apps/api/src/deployment/services/sdl/sdl.service.ts
  • apps/api/src/provider/services/provider/provider.service.ts
  • apps/api/src/provider/services/provider-graph-data/provider-graph-data.service.ts
  • apps/api/src/billing/controllers/checkout/checkout.controller.ts
  • apps/api/src/core/services/analytics/analytics.service.ts
  • apps/api/src/user/repositories/user/user.repository.ts
  • apps/api/src/deployment/repositories/deployment-setting/deployment-setting.repository.ts
  • apps/api/src/deployment/controllers/lease/lease.controller.ts
  • apps/api/src/billing/services/managed-user-wallet/managed-user-wallet.service.ts
  • apps/api/src/billing/repositories/checkout-session/checkout-session.repository.ts
  • apps/api/src/auth/repositories/api-key/api-key.repository.ts
  • apps/api/src/core/services/tx/tx.service.ts
  • apps/api/src/deployment/controllers/deployment-setting/deployment-setting.controller.ts
  • apps/api/src/billing/services/provider-cleanup/provider-cleanup.service.ts
  • apps/api/src/billing/repositories/user-wallet/user-wallet.repository.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
🔇 Additional comments (23)
apps/api/src/user/repositories/user/user.repository.ts (1)

6-7: Good: converted DB/table/ability imports to type-only while keeping decorators as value imports

This aligns with tsup-friendly type elision and preserves runtime decorators.

apps/api/src/healthz/services/healthz/healthz.service.ts (1)

7-7: LGTM: ApiPgDatabase switched to type-only import

Constructor param is injected via @InjectPg, so no runtime reliance on the type value. Matches the PR’s objective.

apps/api/src/provider/services/provider/provider.service.ts (1)

10-10: LGTM: BillingConfig is now a type-only import, decorator remains a value import

@InJECTBillingConfig supplies the runtime token; the type is only used for annotation, so this change is safe and compliant.

apps/api/src/core/services/tx/tx.service.ts (1)

7-7: LGTM: ApiPgDatabase/ApiPgTables as type-only, InjectPg as value import

Matches tsup-friendly pattern; only annotations depend on the types.

apps/api/src/core/services/analytics/analytics.service.ts (1)

3-4: Type-only imports for DI types: correct and safe

Switching Amplitude and Hasher to type-only imports while keeping AMPLITUDE and HASHER as value tokens is correct and keeps DI working. This also helps tsup by removing unused runtime imports.

apps/api/src/billing/repositories/checkout-session/checkout-session.repository.ts (1)

5-6: Type-only imports applied correctly

Converting ApiPgDatabase, ApiPgTables, and AbilityParams to type-only while keeping InjectPg/InjectPgTable and BaseRepository as value imports is correct. All usages are in type positions.

apps/api/src/billing/services/financial-stats/financial-stats.service.ts (1)

9-9: Type-only import for BillingConfig: correct

Keeping InjectBillingConfig as a value import and BillingConfig as a type-only import aligns with the PR goal and maintains runtime behavior.

apps/api/src/billing/repositories/user-wallet/user-wallet.repository.ts (1)

4-5: Type-only imports for DB types and AbilityParams: correct

ApiPgDatabase, ApiPgTables, and AbilityParams are only used in type positions; keeping InjectPg/InjectPgTable and BaseRepository as value imports is correct.

apps/api/src/billing/services/refill/refill.service.ts (1)

5-6: Type-only imports for BillingConfig and UserWalletOutput: correct

This cleanly separates type and value imports and should help tsup with tree-shaking. Runtime behavior remains unchanged.

apps/api/src/deployment/controllers/lease/lease.controller.ts (1)

6-7: Type-only schema imports are correct and reduce runtime deps

These are used purely in type positions (method signature/return), so switching to import type is safe and aligns with the PR goal.

If CreateLeaseRequest follows the common { data: ... } shape used elsewhere, consider verifying whether the parameter should be CreateLeaseRequest["data"] for consistency. If its schema differs, keep as-is.

apps/api/src/deployment/repositories/deployment-setting/deployment-setting.repository.ts (1)

6-8: Type-only DB and ability imports: ✅

ApiPgDatabase, ApiPgTables, and AbilityParams are used only in type positions, so import type is appropriate. Decorator-based injections (@InjectPg, @InjectPgTable) remain unaffected at runtime.

apps/api/src/deployment/services/sdl/sdl.service.ts (2)

6-6: Type-only BillingConfig import is safe with explicit injector

Using import type for BillingConfig is correct here; runtime resolution is handled via @InjectBillingConfig(), so no reflection on the type is required.


31-35: Potential double-stringify of manifest when asString = true

If sdl.manifest(true) already returns a string (common in such APIs), JSON.stringify will produce an extra quoted string. Verify and simplify accordingly.

Apply this diff if manifest(true) returns a string:

-    const manifest = sdl.manifest(asString);
-    return asString ? (JSON.stringify(manifest) as string) : manifest;
+    const manifest = sdl.manifest(asString);
+    return asString ? (manifest as string) : manifest;
apps/api/src/deployment/controllers/deployment-setting/deployment-setting.controller.ts (1)

6-10: Type-only schema imports are correct and consistent

All four imports are used purely for typing in method signatures; converting them to import type is correct and matches the PR’s objective.

apps/api/src/billing/repositories/payment-method/payment-method.repository.ts (1)

4-5: Type-only DB and ability imports: ✅

ApiPgDatabase, ApiPgTables, and AbilityParams are used only for typing; import type reduces bundled runtime deps without behavior changes. Decorator-based injections remain intact.

apps/api/src/billing/services/balances/balances.service.ts (1)

5-5: Type-only imports applied correctly

Switching BillingConfig, UserWalletInput, and UserWalletOutput to type-only imports is correct and keeps runtime bundles clean. No runtime references to these identifiers in this file.

Also applies to: 7-7

apps/api/src/billing/controllers/checkout/checkout.controller.ts (1)

6-6: Type-only BillingConfig import is correct

Good change. Keeps DI token InjectBillingConfig as a runtime import and BillingConfig as type-only.

apps/api/src/billing/services/managed-user-wallet/managed-user-wallet.service.ts (1)

9-9: Type-only BillingConfig import is correct

Matches the PR aim and keeps runtime import surface minimal.

apps/api/src/provider/services/provider-graph-data/provider-graph-data.service.ts (1)

8-8: Type-only imports for ProviderStats/ProviderStatsKey are correct

These are used exclusively in type positions; good change.

apps/api/src/auth/repositories/api-key/api-key.repository.ts (1)

5-6: Type-only imports look good

ApiPgDatabase, ApiPgTables, and AbilityParams are now type-only, while DI tokens remain value imports. This matches the PR objective without affecting runtime.

apps/api/src/billing/services/provider-cleanup/provider-cleanup.service.ts (3)

4-4: Type-only import for BillingConfig is correct and safe here

BillingConfig is used purely as a type annotation for this.config, and InjectBillingConfig remains a value import for DI. This aligns with tsup’s requirements and won’t affect runtime.


5-5: Good separation of type vs value for repository layer

Using import type for UserWalletOutput while keeping UserWalletRepository as a value import is appropriate and preserves runtime behavior.


8-8: Type-only import for ProviderCleanupParams is appropriate

ProviderCleanupParams is used only in method signatures; making it a type-only import eliminates unnecessary runtime imports.

Comment on lines +6 to 8
import { type GpuVendor, ProviderConfigGpusType } from "@src/types/gpu";
import { type GpuBreakdownQuery } from "../http-schemas/gpu.schema";
import { GpuRepository } from "../repositories/gpu.repository";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Also import ProviderConfigGpusType as a type-only import

ProviderConfigGpusType is used only in type positions (axios generic). Importing it as a value keeps an unnecessary runtime dependency.

Apply:

-import { type GpuVendor, ProviderConfigGpusType } from "@src/types/gpu";
+import type { GpuVendor, ProviderConfigGpusType } from "@src/types/gpu";
 import { type GpuBreakdownQuery } from "../http-schemas/gpu.schema";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { type GpuVendor, ProviderConfigGpusType } from "@src/types/gpu";
import { type GpuBreakdownQuery } from "../http-schemas/gpu.schema";
import { GpuRepository } from "../repositories/gpu.repository";
import type { GpuVendor, ProviderConfigGpusType } from "@src/types/gpu";
import { type GpuBreakdownQuery } from "../http-schemas/gpu.schema";
import { GpuRepository } from "../repositories/gpu.repository";
🤖 Prompt for AI Agents
In apps/api/src/gpu/services/gpu.service.ts around lines 6 to 8,
ProviderConfigGpusType is only used as a type so change its import to a
type-only import to avoid a runtime dependency; update the import statement to
use the TypeScript "import type" form for ProviderConfigGpusType while keeping
the other imports unchanged.

import { BillingConfig, InjectBillingConfig } from "@src/billing/providers";
import { type BillingConfig, InjectBillingConfig } from "@src/billing/providers";
import { AUDITOR, TRIAL_ATTRIBUTE } from "@src/deployment/config/provider.config";
import { LeaseStatusResponse } from "@src/deployment/http-schemas/lease.schema";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Import LeaseStatusResponse as a type-only import

It’s only used for typing (return type and generics). Switching prevents unnecessary runtime import.

Apply:

-import { LeaseStatusResponse } from "@src/deployment/http-schemas/lease.schema";
+import type { LeaseStatusResponse } from "@src/deployment/http-schemas/lease.schema";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { LeaseStatusResponse } from "@src/deployment/http-schemas/lease.schema";
import type { LeaseStatusResponse } from "@src/deployment/http-schemas/lease.schema";
🤖 Prompt for AI Agents
In apps/api/src/provider/services/provider/provider.service.ts around line 12,
the LeaseStatusResponse symbol is only used for typing, so change the runtime
import to a type-only import: replace the current import with a TypeScript
"import type { LeaseStatusResponse } from
'@src/deployment/http-schemas/lease.schema';" so the compiler erases the import
at runtime and avoids unnecessary module loading.

@codecov
Copy link

codecov bot commented Aug 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 42.49%. Comparing base (ffe2356) to head (beed109).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1810      +/-   ##
==========================================
- Coverage   42.78%   42.49%   -0.30%     
==========================================
  Files         940      935       -5     
  Lines       26476    26299     -177     
  Branches     6958     6943      -15     
==========================================
- Hits        11329    11176     -153     
+ Misses      13989    13965      -24     
  Partials     1158     1158              
Flag Coverage Δ *Carryforward flag
api 81.22% <100.00%> (-0.05%) ⬇️
deploy-web 20.93% <ø> (ø) Carriedforward from ffe2356
log-collector ?
notifications 87.67% <ø> (ø) Carriedforward from ffe2356
provider-console 81.48% <ø> (ø) Carriedforward from ffe2356
provider-proxy 84.75% <ø> (ø) Carriedforward from ffe2356

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
...rc/auth/repositories/api-key/api-key.repository.ts 100.00% <100.00%> (ø)
...illing/controllers/checkout/checkout.controller.ts 53.84% <100.00%> (ø)
...es/checkout-session/checkout-session.repository.ts 50.00% <100.00%> (ø)
...tories/payment-method/payment-method.repository.ts 52.63% <100.00%> (ø)
...repositories/user-wallet/user-wallet.repository.ts 93.33% <100.00%> (ø)
.../src/billing/services/balances/balances.service.ts 96.29% <100.00%> (ø)
...ervices/financial-stats/financial-stats.service.ts 32.43% <100.00%> (ø)
...managed-user-wallet/managed-user-wallet.service.ts 98.46% <100.00%> (ø)
...vices/provider-cleanup/provider-cleanup.service.ts 40.90% <100.00%> (ø)
.../api/src/billing/services/refill/refill.service.ts 97.56% <100.00%> (ø)
... and 11 more

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@stalniy stalniy force-pushed the refactor/api-import-types-fix branch from c40eb58 to 131b157 Compare August 15, 2025 03:37
@stalniy stalniy force-pushed the refactor/api-import-types-fix branch from 131b157 to beed109 Compare August 15, 2025 03:38
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
apps/api/src/billing/services/balances/balances.service.ts (4)

1-1: Make DeploymentInfo a type-only import; keep services as value imports

DeploymentInfo is only used in type positions. Convert it to a type-only import while keeping AuthzHttpService and DeploymentHttpService as value imports to preserve DI metadata.

-import { AuthzHttpService, DeploymentHttpService, DeploymentInfo } from "@akashnetwork/http-sdk";
+import { AuthzHttpService, DeploymentHttpService } from "@akashnetwork/http-sdk";
+import type { DeploymentInfo } from "@akashnetwork/http-sdk";

4-4: Optionally import Wallet as type-only (DI uses InjectWallet token)

Wallet is only used for typing the injected param and DI uses @InjectWallet("MANAGED"). You can avoid a runtime import by switching to a type-only import.

-import { Wallet } from "@src/billing/lib/wallet/wallet";
+import type { Wallet } from "@src/billing/lib/wallet/wallet";

Please confirm this doesn’t affect tsyringe resolution in your setup (it shouldn’t, since the token decorator is used).


61-61: Specify radix for parseInt to avoid implicit base

Explicitly pass radix 10 for clarity and to avoid edge cases.

-    return feeAllowance.allowance.spend_limit.reduce((acc, { denom, amount }) => (denom === "uakt" ? acc + parseInt(amount) : acc), 0);
+    return feeAllowance.allowance.spend_limit.reduce(
+      (acc, { denom, amount }) => (denom === "uakt" ? acc + Number.parseInt(amount, 10) : acc),
+      0
+    );

72-72: Specify radix for parseInt here as well

Same rationale as above.

-    return parseInt(depositDeploymentGrant.authorization.spend_limit.amount);
+    return Number.parseInt(depositDeploymentGrant.authorization.spend_limit.amount, 10);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between c40eb58 and beed109.

📒 Files selected for processing (21)
  • apps/api/src/auth/repositories/api-key/api-key.repository.ts (1 hunks)
  • apps/api/src/billing/controllers/checkout/checkout.controller.ts (1 hunks)
  • apps/api/src/billing/repositories/checkout-session/checkout-session.repository.ts (1 hunks)
  • apps/api/src/billing/repositories/payment-method/payment-method.repository.ts (1 hunks)
  • apps/api/src/billing/repositories/user-wallet/user-wallet.repository.ts (1 hunks)
  • apps/api/src/billing/services/balances/balances.service.ts (1 hunks)
  • apps/api/src/billing/services/financial-stats/financial-stats.service.ts (1 hunks)
  • apps/api/src/billing/services/managed-user-wallet/managed-user-wallet.service.ts (1 hunks)
  • apps/api/src/billing/services/provider-cleanup/provider-cleanup.service.ts (1 hunks)
  • apps/api/src/billing/services/refill/refill.service.ts (1 hunks)
  • apps/api/src/core/services/analytics/analytics.service.ts (1 hunks)
  • apps/api/src/core/services/tx/tx.service.ts (1 hunks)
  • apps/api/src/deployment/controllers/deployment-setting/deployment-setting.controller.ts (1 hunks)
  • apps/api/src/deployment/controllers/lease/lease.controller.ts (1 hunks)
  • apps/api/src/deployment/repositories/deployment-setting/deployment-setting.repository.ts (1 hunks)
  • apps/api/src/deployment/services/sdl/sdl.service.ts (1 hunks)
  • apps/api/src/gpu/services/gpu.service.ts (1 hunks)
  • apps/api/src/healthz/services/healthz/healthz.service.ts (1 hunks)
  • apps/api/src/provider/services/provider-graph-data/provider-graph-data.service.ts (1 hunks)
  • apps/api/src/provider/services/provider/provider.service.ts (1 hunks)
  • apps/api/src/user/repositories/user/user.repository.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/api/src/gpu/services/gpu.service.ts
🚧 Files skipped from review as they are similar to previous changes (19)
  • apps/api/src/core/services/tx/tx.service.ts
  • apps/api/src/billing/repositories/payment-method/payment-method.repository.ts
  • apps/api/src/billing/services/managed-user-wallet/managed-user-wallet.service.ts
  • apps/api/src/provider/services/provider-graph-data/provider-graph-data.service.ts
  • apps/api/src/deployment/services/sdl/sdl.service.ts
  • apps/api/src/billing/controllers/checkout/checkout.controller.ts
  • apps/api/src/deployment/repositories/deployment-setting/deployment-setting.repository.ts
  • apps/api/src/core/services/analytics/analytics.service.ts
  • apps/api/src/billing/services/financial-stats/financial-stats.service.ts
  • apps/api/src/billing/repositories/user-wallet/user-wallet.repository.ts
  • apps/api/src/billing/services/refill/refill.service.ts
  • apps/api/src/billing/repositories/checkout-session/checkout-session.repository.ts
  • apps/api/src/healthz/services/healthz/healthz.service.ts
  • apps/api/src/deployment/controllers/deployment-setting/deployment-setting.controller.ts
  • apps/api/src/deployment/controllers/lease/lease.controller.ts
  • apps/api/src/billing/services/provider-cleanup/provider-cleanup.service.ts
  • apps/api/src/provider/services/provider/provider.service.ts
  • apps/api/src/user/repositories/user/user.repository.ts
  • apps/api/src/auth/repositories/api-key/api-key.repository.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/general.mdc)

Never use type any or cast to type any. Always define the proper TypeScript types.

Files:

  • apps/api/src/billing/services/balances/balances.service.ts
**/*.{js,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/general.mdc)

**/*.{js,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code

Files:

  • apps/api/src/billing/services/balances/balances.service.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
🔇 Additional comments (2)
apps/api/src/billing/services/balances/balances.service.ts (2)

5-5: Good: Type-only import for BillingConfig matches DI usage

Using import type for BillingConfig is correct here since @InjectBillingConfig() provides the runtime token and no runtime reference to BillingConfig is needed.


7-7: Good: DTOs as type-only, repository as value import

UserWalletInput/UserWalletOutput are correctly imported as types while keeping UserWalletRepository as a runtime import for DI. This aligns with the PR goal without affecting behavior.

@stalniy stalniy merged commit 12fa6b5 into main Aug 15, 2025
62 checks passed
@stalniy stalniy deleted the refactor/api-import-types-fix branch August 15, 2025 19:14
stalniy added a commit that referenced this pull request Nov 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments