@0xsequence/indexer 2.1.8 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xsequence/indexer",
3
- "version": "2.1.8",
3
+ "version": "2.2.0",
4
4
  "description": "indexer sub-package for Sequence",
5
5
  "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/indexer",
6
6
  "source": "src/index.ts",
package/src/index.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export * from './indexer.gen'
2
+ export * as IndexerGateway from './indexergw.gen'
2
3
 
3
4
  import { Indexer as IndexerRpc } from './indexer.gen'
5
+ import { IndexerGateway as IndexerGatewayRpc } from './indexergw.gen'
4
6
 
5
7
  export class SequenceIndexer extends IndexerRpc {
6
8
  constructor(
@@ -34,3 +36,36 @@ export class SequenceIndexer extends IndexerRpc {
34
36
  return fetch(input, init)
35
37
  }
36
38
  }
39
+
40
+ export class SequenceIndexerGateway extends IndexerGatewayRpc {
41
+ constructor(
42
+ hostname: string,
43
+ public projectAccessKey?: string,
44
+ public jwtAuth?: string
45
+ ) {
46
+ super(hostname.endsWith('/') ? hostname.slice(0, -1) : hostname, fetch)
47
+ this.fetch = this._fetch
48
+ }
49
+
50
+ _fetch = (input: RequestInfo, init?: RequestInit): Promise<Response> => {
51
+ // automatically include jwt and access key auth header to requests
52
+ // if its been set on the api client
53
+ const headers: { [key: string]: any } = {}
54
+
55
+ const jwtAuth = this.jwtAuth
56
+ const projectAccessKey = this.projectAccessKey
57
+
58
+ if (jwtAuth && jwtAuth.length > 0) {
59
+ headers['Authorization'] = `BEARER ${jwtAuth}`
60
+ }
61
+
62
+ if (projectAccessKey && projectAccessKey.length > 0) {
63
+ headers['X-Access-Key'] = projectAccessKey
64
+ }
65
+
66
+ // before the request is made
67
+ init!.headers = { ...init!.headers, ...headers }
68
+
69
+ return fetch(input, init)
70
+ }
71
+ }