Repository navigation
Prune backend deps, gate Swagger, wire minor-units, drop dead modules - #2048
Open
Amnesty-jr wants to merge 1 commit into
Open
Amnesty-jr wants to merge 1 commit into
Amnesty-jr wants to merge 1 commit into
Conversation
Closes DistinctCodes#1949, DistinctCodes#1950, DistinctCodes#1951 and DistinctCodes#1952. DistinctCodes#1949 — remove the in-memory helper modules that only their own specs imported and add a CI gate. Deleted jwks-cache, login-rate-limiter, password-reset-token.store, credit-adjustment-audit, credit-balance-cache, payment-credit-dedupe, usage-date-range, ledger-append-only.guard, metered-usage-timestamp, payment-creation-throttle, payment-orchestrator, refund-amount-guard, revenue-split-validator, settlement-backoff, rail-not-registered.error and the unused credits/interfaces barrel (its three importers now target the interface file directly). New scripts/check-dead-modules.js resolves the real import graph from the entrypoints and fails CI on any module reachable only from a spec. DistinctCodes#1950 — route money arithmetic through payments/utils/minor-units.ts. Added assertPositiveMinorUnits/addMinorUnits/subtractMinorUnits/ sumMinorUnits, and used them in refunds (remaining + total-refunded), in ledger leg validation and side totals, and in split-allocation (which now delegates its largest-remainder pass to apportionByBasisPoints while preserving the sortOrder tie-break). Added a property test asserting random refund sequences and random basis-point splits always reconcile to the exact input. Also fixed a seed bug in the existing spec whose "single minor unit" case used shares summing to 4000 instead of 10000. DistinctCodes#1951 — Swagger no longer ships in production. setupSwagger (new src/common/swagger.ts) serves the UI and document only when NODE_ENV != production or SWAGGER_ENABLED=true, optionally behind HTTP basic auth, and documents the accessToken cookie via addCookieAuth. GET /api/docs is a 404 in production by default; a unit test covers both the enabled and disabled settings. DistinctCodes#1952 — prune unused/misplaced backend dependencies. Removed the 19 unused packages the issue lists plus the unused swagger-ui-express, moved @nestjs/cli and the @types/* packages into devDependencies (adding the missing dotenv declaration), and aligned express to ^4 to match @nestjs/platform-express@10. Added a depcheck script + CI step; the pruned tree keeps `npm ci --omit=dev` free of our own type packages.
|
Someone is attempting to deploy a commit to the naijabuz's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@Amnesty-jr Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prune backend deps, gate Swagger, wire minor-units, drop dead modules
This closes #1949, #1950, #1951 and #1952.
Closes #1949
Closes #1950
Closes #1951
Closes #1952
Summary of changes
#1949 — Remove or wire up the unused in-memory helper modules
Removed the modules that were imported by nothing but their own spec, and added a CI gate so they cannot come back.
Deleted (all verified to have zero non-test importers, so no wiring was needed):
auth/jwks-cache.util.ts,auth/login-rate-limiter.util.ts,auth/password-reset-token.store.tscredits/credit-adjustment-audit.util.ts,credits/credit-balance-cache.util.ts,credits/payment-credit-dedupe.util.ts,credits/dto/usage-date-range.dto.tscredits/interfaces/index.ts(unused barrel — its three importers now targetinterfaces/external-payout-rail.interfacedirectly)payments/ledger-append-only.guard.ts,payments/metered-usage-timestamp.util.ts,payments/payment-creation-throttle.util.ts,payments/payment-orchestrator.ts,payments/refund-amount-guard.util.ts,payments/revenue-split-validator.util.ts,payments/settlement-backoff.util.ts,payments/errors/rail-not-registered.error.ts(and the now-emptypayments/errors/)CI check. The issue suggested
ts-prune, but ts-prune reports unused exports (including symbols exported purely for in-module use), which is a much broader concern than "a module that exists but is never wired into the running application." Insteadscripts/check-dead-modules.jsresolves the real import graph from the actual entrypoints (main.ts,database/data-source.ts,database/migrations/**,**/testing/**) and fails the job on any non-test module reachable only from a spec. It runs as the blockingDead module checkstep.#1950 — Currency arithmetic helpers are unused by the money paths
payments/utils/minor-units.tsis now the single home for minor-unit arithmetic and allocation.assertPositiveMinorUnits,addMinorUnits,subtractMinorUnits,sumMinorUnitsalongside the existingassertMinorUnits/multiplyMinorUnits/apportionByBasisPoints.refunds.service.ts): the amount check goes throughassertPositiveMinorUnits;remainingusessubtractMinorUnitsand the refunded-total check usesaddMinorUnits.ledger.service.ts): leg validation usesassertPositiveMinorUnitsandsideTotalusessumMinorUnits.split-allocation.ts): the largest-remainder pass is delegated toapportionByBasisPoints, so there is one rounding implementation to audit. The recipients are pre-sorted bysortOrder(then input position) to preserve the module's documented tie-break, then mapped back to the caller's order.Property test (acceptance criterion):
minor-units.spec.tsgains a "money conservation" suite that seeds 2,000 random partial-refund sequences and 2,000 random basis-point splits and asserts the pieces always reconcile back to the exact input — no unit is created and none is lost.Also fixed a bug in the existing spec: the "assigns a single minor unit" case used shares summing to 4000, not 10000, so it threw
MinorUnitsErrorinstead of testing the intended behaviour.Non-integer or unsafe amounts are already rejected with a 400 at the API boundary by the
@MinorUnitsDTO decorator (issue #1966); the service-level guards now share the same helpers so the two cannot drift.#1951 — Swagger UI and the OpenAPI document are served in production
New
src/common/swagger.tsexposessetupSwagger(app, env)andisSwaggerEnabled(env), called frommain.ts.SWAGGER_ENABLED=true(the explicit, auditable opt-in).GET /api/docsis a 404 in production by default.SWAGGER_USER/SWAGGER_PASSWORDare set (constant-time credential comparison).addCookieAuth('accessToken')in addition to the bearer token.The unit test covers both settings: disabled (404) and enabled (200), plus the production
SWAGGER_ENABLED=trueoverride and the basic-auth path.#1952 — Prune unused and misplaced backend dependencies
@sendgrid/mail,moment,mjml,nodemailer-mjml,otplib,pdfkit,qrcode,sharp,passport,passport-jwt,passport-local,@nestjs/passport,@nestjs/axios,axios,date-fns,json2csv,multer,cache-manager-ioredis,nestjs-command. Also removed the unusedswagger-ui-express(@nestjs/swaggerserves the UI fromswagger-ui-dist), plus the orphaned@types/json2csv/@types/multer/@types/passport-*/@types/pdfkit/@types/qrcode/@types/swagger-ui-express.@nestjs/cli,@types/cookie-parserand@types/handlebarstodevDependenciesso they no longer ship in production installs, and declared the missingdotenvdependency.expressto^4to match@nestjs/platform-express@^10(which bundles Express 4) and lowered@types/expressaccordingly.depcheckscript + blocking Dependency hygiene (depcheck) CI step. The script ignores only the tooling packages that are required by the build but never imported (@nestjs/schematics,@types/jest,source-map-support,ts-loader,tsconfig-paths).Verification
npm run build— passes.npm run dead-modules— clean.npm run depcheck— "No depcheck issue".npm ciandnpm ci --omit=dev— both succeed; the production install carries no app-declared@types/*and no CLI tooling.npm test— 6 failed suites / 3 failed tests, all pre-existing seeded-bug failures onmain(credits-admin.controller.spec,credits.controller.spec,payments.service.spec,lazy-initialization.spec,testnet-integration.spec,with-timeout.spec). This is an improvement over the baseline onmain(7 failed suites / 4 failed tests), because theminor-units.specseed bug is fixed here.