Skip to content

refactor(web): move server helpers out of lib/utils - #6915

Merged
chrarnoldus merged 2 commits into
mainfrom
refactor/utils-server-helpers
Sep 29, 2026
Merged

chrarnoldus merged 2 commits into
mainfrom
refactor/utils-server-helpers

Conversation

@chrarnoldus

Copy link
Copy Markdown
Contributor

Summary

lib/utils mixes the UI class-name and formatting helpers with helpers that gateway and billing code use, so server code loaded clsx, tailwind-merge and the Stripe payment-method types. The server helpers move unchanged:

  • getFraudDetectionHeaders and its types → lib/fraud-detection-headers
  • normalizeEmail and getLowerDomainFromEmail → lib/email-address
  • toMicrodollars → lib/microdollars
  • stripRequiredPrefix → into llm-proxy, its only caller

Importers of fromMicrodollars now use @kilocode/app-shared/utils, which lib/utils only re-exported.

Verification

Tests are left to CI. No manual checks are listed.

Visual Changes

N/A

Reviewer Notes

Split out of #6894, which prepares #6806 (the ai-gateway app and the web-shared package). The move is verbatim; use git show --color-moved to confirm it.

lib/utils mixes the UI class-name and formatting helpers with helpers the
gateway and billing code use, so server code loaded clsx, tailwind-merge
and the Stripe payment-method types. The server helpers move unchanged:

- getFraudDetectionHeaders and its types to lib/fraud-detection-headers
- normalizeEmail and getLowerDomainFromEmail to lib/email-address
- toMicrodollars to lib/microdollars
- stripRequiredPrefix into llm-proxy, its only caller

fromMicrodollars importers use @kilocode/app-shared/utils, which
lib/utils only re-exported.
@kilo-code-bot

kilo-code-bot Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

Verified the verbatim move of toMicrodollars, normalizeEmail/getLowerDomainFromEmail, getFraudDetectionHeaders/EmptyFraudDetectionHeaders, and stripRequiredPrefix out of lib/utils; every prior importer was updated and no stale references to the removed exports remain.

Verification Notes

  • Repo-wide search confirms no remaining imports of the moved symbols from @/lib/utils, ./utils, or ../utils (including multi-line imports).
  • All fromMicrodollars importers now use @kilocode/app-shared/utils, which exports it (packages/app-shared/src/utils.ts:28) and is exposed via the ./utils subpath export.
  • New modules lib/email-address.ts, lib/fraud-detection-headers.ts, and lib/microdollars.ts contain the moved code verbatim with no new imports; utils.ts retains the still-used exports (formatCents, formatDollars, toNonNullish, etc.).
  • stripRequiredPrefix was inlined into llm-proxy.ts (its only caller) and is not referenced anywhere else.
  • No client-only access was broken: the new modules carry no server-only marker, so client components such as InviteMemberDialog.tsx still resolve getLowerDomainFromEmail. No new module-level mutable state or timers are introduced, so no memory-leak risk from this change.
Files Reviewed (62 files)
  • apps/web/src/app/(app)/organizations/[id]/sub-organizations/distribute-funds/parseDollarInput.ts
  • apps/web/src/app/admin/api/backfills/normalized-email/route.ts
  • apps/web/src/app/admin/api/organizations/[id]/consume-credits/route.ts
  • apps/web/src/app/admin/users/[id]/page.tsx
  • apps/web/src/app/api/dev/consume-credits/route.ts
  • apps/web/src/app/api/sso/organizations/route.ts
  • apps/web/src/app/payments/topup/success/page.tsx
  • apps/web/src/components/organizations/OrganizationInfoCard.tsx
  • apps/web/src/components/organizations/OrganizationPaymentDetails.tsx
  • apps/web/src/components/organizations/members/InviteMemberDialog.tsx
  • apps/web/src/components/profile/ProfileExpiringCredits.tsx
  • apps/web/src/components/subscriptions/org-kilo-pass/mappers.ts
  • apps/web/src/components/usage-analytics/format.ts
  • apps/web/src/lib/ai-gateway/handlers/llm-proxy.ts
  • apps/web/src/lib/ai-gateway/llm-proxy-helpers.ts
  • apps/web/src/lib/ai-gateway/openai-chatgpt/routing.test.ts
  • apps/web/src/lib/ai-gateway/processUsage.shared.ts
  • apps/web/src/lib/ai-gateway/processUsage.test.ts
  • apps/web/src/lib/ai-gateway/processUsage.ts
  • apps/web/src/lib/ai-gateway/processUsage.types.ts
  • apps/web/src/lib/ai-gateway/providers/apply-provider-specific-logic.test.ts
  • apps/web/src/lib/ai-gateway/providers/apply-provider-specific-logic.ts
  • apps/web/src/lib/ai-gateway/providers/build-direct-provider.test.ts
  • apps/web/src/lib/ai-gateway/providers/direct-byok/opencode-go.test.ts
  • apps/web/src/lib/ai-gateway/providers/types.ts
  • apps/web/src/lib/ai-gateway/providers/upstream-attempt.ts
  • apps/web/src/lib/ai-gateway/typesafe/handler.test.ts
  • apps/web/src/lib/ai-gateway/typesafe/handler.ts
  • apps/web/src/lib/auth/data-export-download-codes.ts
  • apps/web/src/lib/auth/email-signin-eligibility.ts
  • apps/web/src/lib/auth/magic-link-tokens.ts
  • apps/web/src/lib/contributor-champions/service.ts
  • apps/web/src/lib/email-address.ts
  • apps/web/src/lib/fraud-detection-headers.ts
  • apps/web/src/lib/kilo-pass/apple-store-notifications.test.ts
  • apps/web/src/lib/kilo-pass/cancel-and-refund.ts
  • apps/web/src/lib/kilo-pass/google-play-notifications.test.ts
  • apps/web/src/lib/kilo-pass/issuance.ts
  • apps/web/src/lib/kilo-pass/store-subscription-completion.ts
  • apps/web/src/lib/kilo-pass/subscription-accounting.ts
  • apps/web/src/lib/kilo-pass/yearly-monthly-base-cron.test.ts
  • apps/web/src/lib/microdollars.ts
  • apps/web/src/lib/notifications.ts
  • apps/web/src/lib/organizations/organization-billing.ts
  • apps/web/src/lib/organizations/organization-seats.ts
  • apps/web/src/lib/organizations/organization-usage.ts
  • apps/web/src/lib/organizations/organizations.test.ts
  • apps/web/src/lib/organizations/organizations.ts
  • apps/web/src/lib/organizations/verified-domain.ts
  • apps/web/src/lib/promotionalCredits.ts
  • apps/web/src/lib/stripe/disputes.ts
  • apps/web/src/lib/stripe/index.ts
  • apps/web/src/lib/stytch.ts
  • apps/web/src/lib/user/deletion-queue/deletion-enqueue.ts
  • apps/web/src/lib/user/index.ts
  • apps/web/src/lib/user/server.ts
  • apps/web/src/lib/utils.ts
  • apps/web/src/routers/admin-router.ts
  • apps/web/src/routers/kilo-pass-router.ts
  • apps/web/src/routers/organizations/organization-admin-router.ts
  • apps/web/src/routers/organizations/organization-sub-organizations-router.ts
  • apps/web/src/tests/helpers/microdollar-usage.helper.ts

Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0

Review guidance: REVIEW.md from base branch main

…-helpers

# Conflicts:
#	apps/web/src/lib/organizations/organizations.test.ts
@chrarnoldus
chrarnoldus merged commit ea3f887 into main Sep 29, 2026
27 checks passed
@chrarnoldus
chrarnoldus deleted the refactor/utils-server-helpers branch September 29, 2026 13:50
iscekic added a commit that referenced this pull request Sep 30, 2026
Resolve three conflicts.

- Main moved `toMicrodollars` from `@/lib/utils` to `@/lib/microdollars` (#6915).
  Take the new path in both notification test files, and in the two credit pack
  files that the merge could not flag.
- Regenerate `.kilo/skills/kilo-mcp/SKILL.md` from the merged catalog, so the
  drift check passes.
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