# Indexer Service (Graph Protocol)

The indexer service provides a thin client around The Graph for querying
on-chain events emitted by Lilith smart contracts. It focuses on the high-value
flows required by the NFT marketplace roadmap:

- `ContentLicenseNFT::LicenseIssued` → exposed via `getRecentContentLicenses`
- `AccessToken::TokenPurchased` → exposed via `getAccessTokenPurchases`

## Usage

```ts
import { createIndexerClient } from './indexer';

const indexer = createIndexerClient({
  endpoint: 'https://api.studio.thegraph.com/query/lilith/indexer/latest',
  apiKey: process.env.GRAPH_API_KEY,
});

const recentLicenses = await indexer.getRecentContentLicenses({ limit: 25 });
const recentPurchases = await indexer.getAccessTokenPurchases({ limit: 50 });
```

### Domain Shapes

```ts
type ContentLicenseEvent = {
  id: string;
  tokenId: bigint;
  licensee: string;
  contentId: string;
  metadataUri: string;
  blockTimestamp: Date;
  transactionHash: string;
};

type AccessTokenPurchaseEvent = {
  id: string;
  buyer: string;
  tokenId: bigint;
  amount: bigint;
  totalPriceWei: bigint;
  blockTimestamp: Date;
};
```

The client validates all Graph responses with `zod`, ensuring malformed or
unexpected payloads surface as descriptive errors.

## Tests

Run the targeted Jest suite from the repository root:

```bash
npx jest --config apps/lilith/svc-indexer/jest.config.cjs --runInBand
```

The tests mock Graph responses to ensure the transformation and validation logic
remains deterministic and fast for CI.
