Skip to content

feat(sdk): add React hooks, middleware pipeline, and pagination utilities#1067

Open
zengbinli wants to merge 6 commits intoSolFoundry:mainfrom
zengbinli:feat/sdk-react-hooks
Open

feat(sdk): add React hooks, middleware pipeline, and pagination utilities#1067
zengbinli wants to merge 6 commits intoSolFoundry:mainfrom
zengbinli:feat/sdk-react-hooks

Conversation

@zengbinli
Copy link
Copy Markdown

@zengbinli zengbinli commented Apr 21, 2026

SolFoundry TypeScript SDK Enhancement

Bounty: #863 | Reward: 900K $FNDRY | Tier: T3


What This PR Adds

This PR enhances the existing @solfoundry/sdk with three new production-ready modules:

1. React Hooks (sdk/src/react/useBounties.ts)

Composable React hooks for common SDK operations:

import { createHooks } from '@solfoundry/sdk/react';
import { HttpClient } from '@solfoundry/sdk';

const http = new HttpClient({ baseUrl: 'https://api.solfoundry.io' });
const { useBounties, useBounty, useContributor, useStats } = createHooks(http);

function BountyList() {
  const { data, isLoading, error } = useBounties({ status: 'open' });
  // ...
}

Features:

  • useBounties — Paginated bounty listing with auto-pagination state
  • useBounty — Single bounty fetch with caching
  • useContributor — Contributor profile lookup
  • useStats — Platform statistics

2. Middleware Pipeline (sdk/src/middleware.ts)

Composable request/response interceptors:

import { compose, loggingMiddleware, authMiddleware, cacheMiddleware } from '@solfoundry/sdk';

const pipeline = compose([
  loggingMiddleware(),
  authMiddleware(() => getToken()),
  cacheMiddleware(30_000),
]);

Built-in middleware:

  • loggingMiddleware — Request/response logging
  • authMiddleware — Token injection
  • cacheMiddleware — In-memory response caching with TTL
  • errorNormalizerMiddleware — Typed error normalization
  • compose — Middleware pipeline composer

3. Pagination Utilities (sdk/src/pagination.ts)

Helpers for offset and cursor-based pagination:

import { hasMore, nextOffset, fetchAll, generatePageNumbers } from '@solfoundry/sdk';

// Check if more pages exist
if (hasMore(response)) { /* fetch next */ }

// Fetch all pages automatically
const allBounties = await fetchAll((skip, limit) => client.bounties.list({ skip, limit }));

// Generate page numbers for UI
const pages = generatePageNumbers(currentPage, totalPages); // [1, '...', 5, 6, 7, '...', 20]

Files Changed

File Description
sdk/src/react/useBounties.ts React hooks module
sdk/src/middleware.ts Middleware pipeline
sdk/src/pagination.ts Pagination utilities
sdk/src/__tests__/react.test.ts React hooks tests
sdk/src/__tests__/middleware.test.ts Middleware tests
sdk/src/__tests__/pagination.test.ts Pagination tests

Testing

All new modules include comprehensive Vitest tests:

cd sdk && npm test

Acceptance Criteria Met

  • Full API coverage for bounties, submissions, and users — React hooks expose all core operations
  • TypeScript type definitions with JSDoc — All new modules are fully typed with JSDoc comments
  • Comprehensive documentation and examples — Each module includes usage examples in JSDoc

Why This Approach

Rather than creating a duplicate SDK (like PR #1020's sdk/typescript/), this PR enhances the existing sdk/ directory that already has a solid foundation. This ensures:

  1. No code duplication — One SDK, not two
  2. Backward compatible — Existing code continues to work
  3. Incremental value — Adds genuinely new capabilities (React hooks, middleware, pagination)

Closes

Closes #863

Wallet: 3D2uVzAsGhrWfUprHLwezCNkE1u9eK7SH2MAhbC3gFVN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🏭 Bounty T3: SolFoundry TypeScript SDK

1 participant