Skip to content

Commit

Permalink
add indexer gateway client (#619)
Browse files Browse the repository at this point in the history
* add indexer-gateway

* fix chainId case

* update indexer-gateway client
  • Loading branch information
xiam authored Dec 11, 2024
1 parent dd7d1ad commit b84ed2d
Show file tree
Hide file tree
Showing 2 changed files with 1,454 additions and 0 deletions.
35 changes: 35 additions & 0 deletions packages/indexer/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export * from './indexer.gen'
export * as IndexerGateway from './indexergw.gen'

import { Indexer as IndexerRpc } from './indexer.gen'
import { IndexerGateway as IndexerGatewayRpc } from './indexergw.gen'

export class SequenceIndexer extends IndexerRpc {
constructor(
Expand Down Expand Up @@ -34,3 +36,36 @@ export class SequenceIndexer extends IndexerRpc {
return fetch(input, init)
}
}

export class SequenceIndexerGateway extends IndexerGatewayRpc {
constructor(
hostname: string,
public projectAccessKey?: string,
public jwtAuth?: string
) {
super(hostname.endsWith('/') ? hostname.slice(0, -1) : hostname, fetch)
this.fetch = this._fetch
}

_fetch = (input: RequestInfo, init?: RequestInit): Promise<Response> => {
// automatically include jwt and access key auth header to requests
// if its been set on the api client
const headers: { [key: string]: any } = {}

const jwtAuth = this.jwtAuth
const projectAccessKey = this.projectAccessKey

if (jwtAuth && jwtAuth.length > 0) {
headers['Authorization'] = `BEARER ${jwtAuth}`
}

if (projectAccessKey && projectAccessKey.length > 0) {
headers['X-Access-Key'] = projectAccessKey
}

// before the request is made
init!.headers = { ...init!.headers, ...headers }

return fetch(input, init)
}
}
Loading

0 comments on commit b84ed2d

Please sign in to comment.