Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add indexer gateway client #619

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading