Skip to content

feat(sdk): implement pagination cursors for getGigs()#61

Merged
meshackyaro merged 5 commits into
trustflow-protocol:mainfrom
stephanieoghenemega-eng:feat/issue-24-getgigs-pagination
Jun 24, 2026
Merged

feat(sdk): implement pagination cursors for getGigs()#61
meshackyaro merged 5 commits into
trustflow-protocol:mainfrom
stephanieoghenemega-eng:feat/issue-24-getgigs-pagination

Conversation

@stephanieoghenemega-eng

Copy link
Copy Markdown
Contributor

Closes #24

Summary

Adds getGigs() to TrustFlowEscrowClient with cursor-based pagination matching the backend schema. Each response carries a nextCursor to pass on the next call; null means the last page has been reached.

Changes

src/types/contract.ts

Added optional apiBaseUrl and apiKey to ContractConfig so the escrow client can reach the backend REST API:

export interface ContractConfig {
  contractId: string;
  network: 'TESTNET' | 'MAINNET';
  rpcUrl: string;
  networkPassphrase: string;
  apiBaseUrl?: string;
  apiKey?: string;
}

src/types/index.ts

Two new exported types:

export interface GetGigsParams {
  cursor?: string;       // omit to start from the first page
  limit?: number;        // default 20, capped at 100
  status?: EscrowState['status'];
  depositor?: StellarAddress;
  beneficiary?: StellarAddress;
}

export interface GigsPage {
  data: EscrowState[];
  nextCursor: string | null;
  hasMore: boolean;
}

src/escrow/client.ts

New getGigs(params?) on TrustFlowEscrowClient:

  • Returns { ok: false, error: 'apiBaseUrl is required...' } when unconfigured
  • Caps limit at 100 client-side before the request is sent
  • Sends Authorization: Bearer <apiKey> when apiKey is present
  • Wraps network failures in { ok: false, error: 'Network error: ...' } — consistent with SDKResult<T> across the codebase

Paginate all results:

let cursor: string | undefined;
do {
  const result = await client.getGigs({ cursor, limit: 20, status: 'active' });
  if (!result.ok) { console.error(result.error); break; }
  processBatch(result.data.data);
  cursor = result.data.nextCursor ?? undefined;
} while (cursor);

tests/gigs.test.ts

7 Jest tests covering:

  • Missing apiBaseUrl{ ok: false }
  • Empty first page response
  • All 5 query params forwarded correctly (cursor, limit, status, depositor, beneficiary)
  • limit: 500 capped to limit=100 in the URL
  • Authorization header present when apiKey is set
  • Multi-page cursor traversal chaining nextCursor across two pages
  • Non-2xx and network error paths

Test plan

npm test -- gigs
npm run build

@meshackyaro meshackyaro merged commit f628086 into trustflow-protocol:main Jun 24, 2026
2 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

Development

Successfully merging this pull request may close these issues.

Implement pagination cursors for SDK reads

2 participants