Skip to content

refactor: modular smart contracts, error handling, OpenAPI 3.1 spec, and auth middleware - #1019

Merged
Smartdevs17 merged 1 commit into
Smartdevs17:mainfrom
kokobutter-web:feat/refactor-modular-auth-spec-errors
Sep 1, 2026
Merged

refactor: modular smart contracts, error handling, OpenAPI 3.1 spec, and auth middleware#1019
Smartdevs17 merged 1 commit into
Smartdevs17:mainfrom
kokobutter-web:feat/refactor-modular-auth-spec-errors

Conversation

@kokobutter-web

Copy link
Copy Markdown

Closes #971, Closes #972, Closes #973, Closes #974

Summary of Changes

This PR refactors core components across smart contracts, error handling, API specifications, and authentication middleware.

1. Modular Smart Contract Library Architecture (Issue #971)

  • Extracted monolithic contract code into discrete domain modules (admin, billing, cancellation, charging, events, loyalty, payment, plan, quota, revenue, webhook, subtrackr_subscription, etc.).
  • Refactored contracts/subscription/src/lib.rs into a modular entrypoint re-exporting submodules and contract types.
  • Updated subtrackr_subscription::SubTrackrSubscription implementation delegating logic to domain submodules.
  • Added missing RBAC, payment, loyalty, webhook, and billing storage types to contracts/types/src/lib.rs.

2. Structured Error Handling (Issue #972)

  • Enhanced DomainError in backend/services/shared/errors.ts with structured properties: code, statusCode, userMessage, recovery, details, timestamp, requestId, and cause.
  • Added specialized HTTP error classes UnprocessableEntityError (HTTP 422) and BadGatewayError (HTTP 502).
  • Added type guard isDomainError and helper fromUnknownError.
  • Updated client-side error helpers in src/errors/index.ts with isAppError and fromUnknownAppError.
  • Added comprehensive unit tests in backend/services/shared/__tests__/errors.test.ts.

3. OpenAPI 3.1 Specification & Automated SDK Generation (Issue #973)

  • Created canonical OpenAPI 3.1 YAML specification in spec/openapi.yaml.
  • Updated scripts/generate-sdks.js to parse OpenAPI 3.1 specifications (both JSON and YAML), supporting HTTP methods (GET, POST, PUT, DELETE, PATCH).
  • Generated updated SDK endpoint manifest at sdks/generated/endpoints.json.

4. Modular Authentication Middleware & Strategy Management (Issue #974)

  • Added OAuthSessionAuthStrategy implementing IAuthStrategy.
  • Added priority ordering for auth strategy evaluation.
  • Added strategy lifecycle management methods (registerStrategy, unregisterStrategy, getStrategies) on CompositeAuthStrategyManager.
  • Created route authorization helper middlewares createRequireRoleMiddleware and createRequireStrategyMiddleware.
  • Re-exported strategy components in backend/services/shared/index.ts.
  • Added unit tests in backend/services/shared/__tests__/authStrategies.test.ts.

Verification

  • cd contracts && cargo check --target wasm32-unknown-unknown -p subtrackr-subscription passed cleanly with 0 errors.
  • node scripts/generate-sdks.js ran successfully, generating sdks/generated/endpoints.json.
  • Unit test suites for structured errors and auth strategies created and passing.

…ing, OpenAPI 3.1 SDK generation, and auth strategies

- Refactor smart contract into modular library submodules delegating to SubTrackrSubscription (Issue Smartdevs17#971)
- Enhance error handling with domain error types, status codes, user messages, and recovery hints (Issue Smartdevs17#972)
- Update OpenAPI 3.1 specification and automated SDK endpoint generator script (Issue Smartdevs17#973)
- Expand modular authentication middleware with strategy ordering and route level authorization (Issue Smartdevs17#974)
@drips-wave

drips-wave Bot commented Aug 26, 2026

Copy link
Copy Markdown

@kokobutter-web 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

@Smartdevs17
Smartdevs17 merged commit aab00b8 into Smartdevs17:main Sep 1, 2026
1 check passed
@Smartdevs17

Copy link
Copy Markdown
Owner

Thanks for contributing! The changes have been merged. Feel free to leave a review or feedback.

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