Skip to content

fix: replace as any casts with proper TypeScript types, fix webhook retry query, replace console with logger, add webhook stats return type - #507

Merged
DeFiVC merged 5 commits into
ChainLearnOfficial:mainfrom
Cyber-Mitch:chore/273-274-275-272-batch-fixes-v2
Sep 30, 2026
Merged

DeFiVC merged 5 commits into
ChainLearnOfficial:mainfrom
Cyber-Mitch:chore/273-274-275-272-batch-fixes-v2

Conversation

@Cyber-Mitch

Copy link
Copy Markdown
Contributor

This PR addresses issues #469, #470, #471, and #472:

#469: Replace as any casts with proper TypeScript types

  • Files changed: src/middleware/rate-limit.ts, src/modules/admin/webhook.service.ts, src/services/webhook-dispatcher.ts, src/routes/versioning.ts, src/stellar/transactions.ts, src/stellar/client.ts, src/middleware/response-envelope.ts, src/middleware/validation.ts, src/database/schema.ts
  • Changes:
    • Defined AuthenticatedRequest and VersionedRequest interfaces for request augmentation
    • Added type exports for Webhook and WebhookAttempt from database schema
    • Replaced error handling with unknown and proper type guards
    • Used unknown for payload casting in webhook dispatcher
    • Replaced as any with proper typed interfaces throughout the codebase
  • Acceptance criteria met:
    • ✅ No as any casts remain in the codebase
    • ✅ TypeScript compilation succeeds with strict mode
    • ✅ Error handling properly narrows types before accessing properties
    • ✅ All type assertions use more specific types or unknown

#470: Fix webhook retry query in processWebhookRetries

  • Files changed: src/services/webhook-dispatcher.ts
  • Changes:
    • Fixed incorrect Drizzle ORM query syntax in processWebhookRetries function
    • Replaced callback-based where clause with proper Drizzle operators
    • Used and(), lte(), isNull() for correct query construction
  • Acceptance criteria met:
    • ✅ Query uses proper Drizzle ORM syntax
    • ✅ Correctly filters for pending retries (next_retry_at <= now, succeeded_at IS NULL, failed_at IS NULL)
    • ✅ TypeScript compilation succeeds

#471: Replace console.log/warn/error with logger in config/index.ts

  • Files changed: src/config/index.ts
  • Changes:
    • Imported logger from ../utils/logger.js
    • Replaced console.warn with logger.warn (line 99)
    • Replaced console.error with logger.error (line 122)
  • Acceptance criteria met:
    • ✅ No console.warn or console.error calls remain in config/index.ts
    • ✅ Logger is properly imported and used
    • ✅ Log messages maintain the same context (error details, field errors)
    • ✅ TypeScript compilation succeeds

#472: Add return type to webhook getWebhookStats method

  • Files changed: src/modules/admin/webhook.service.ts, src/modules/admin/webhook.types.ts
  • Changes:
    • Defined WebhookStats interface in webhook.types.ts
    • Updated getWebhookStats method signature to return Promise<WebhookStats>
    • Added interface to exports
  • Acceptance criteria met:
    • ✅ WebhookStats interface is defined in webhook.types.ts
    • ✅ Method returns proper type instead of any
    • ✅ Interface includes: webhookId, totalAttempts, succeeded, failed, pending, successRate
    • ✅ TypeScript compilation succeeds

Testing

  • All changes maintain backward compatibility
  • No functional changes to API behavior
  • TypeScript compilation successful
  • Ready for review and testing

This closes #469
This closes #470
This closes #471
This closes #472

… retry query, replace console with logger, add webhook stats return type

This commit addresses issues ChainLearnOfficial#469, ChainLearnOfficial#470, ChainLearnOfficial#471, and ChainLearnOfficial#472:

- ChainLearnOfficial#469: Replace all `as any` casts with proper TypeScript types for improved type safety
  - Define AuthenticatedRequest and VersionedRequest interfaces for request augmentation
  - Use proper types from database schema (Webhook, WebhookAttempt)
  - Replace error handling with `unknown` and type guards
  - Use `unknown` for payload casting in webhook dispatcher

- ChainLearnOfficial#470: Fix incorrect Drizzle ORM query syntax in processWebhookRetries
  - Replace callback-based where clause with proper Drizzle operators
  - Use and(), lte(), isNull() for correct query construction

- ChainLearnOfficial#471: Replace console.warn/error with structured logger in config/index.ts
  - Import logger from utils/logger.js
  - Replace console.warn with logger.warn
  - Replace console.error with logger.error

- ChainLearnOfficial#472: Add proper return type to getWebhookStats method
  - Define WebhookStats interface in webhook.types.ts
  - Update method signature to return Promise<WebhookStats>
  - Export WebhookStats interface for use by consumers
@drips-wave

drips-wave Bot commented Sep 30, 2026

Copy link
Copy Markdown

@Cyber-Mitch 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! 🚀

Learn more about application limits

Fixed ESLint errors in e2e test files by removing duplicate vitest type references and duplicate FastifyInstance imports. This allows the CI lint workflow to pass.
@Cyber-Mitch
Cyber-Mitch force-pushed the chore/273-274-275-272-batch-fixes-v2 branch from 218102a to d777ca3 Compare September 30, 2026 02:47
Added NODE_ENV=test to CI workflow environment variables to prevent config loading errors in tests. Replaced invalid Stellar secret key fallback values ("test") with valid Stellar secret key format that matches the Zod schema regex requirement. This ensures tests can load config properly without validation errors.
@Cyber-Mitch
Cyber-Mitch force-pushed the chore/273-274-275-272-batch-fixes-v2 branch from dffecd3 to d6f7dc2 Compare September 30, 2026 02:57
@DeFiVC
DeFiVC merged commit 5fbf322 into ChainLearnOfficial:main Sep 30, 2026
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants