@0xsequence/builder 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/src/index.ts ADDED
@@ -0,0 +1,30 @@
1
+ export * from './builder.gen'
2
+
3
+ import { Builder as BuilderRpc } from './builder.gen'
4
+
5
+ export class SequenceBuilderClient extends BuilderRpc {
6
+ constructor(
7
+ public projectAccessKey: string,
8
+ apiUrl?: string
9
+ ) {
10
+ const hostname = apiUrl ?? 'https://api.sequence.build'
11
+ super(hostname.endsWith('/') ? hostname.slice(0, -1) : hostname, fetch)
12
+ this.fetch = this._fetch
13
+ }
14
+
15
+ _fetch = (input: RequestInfo, init?: RequestInit): Promise<Response> => {
16
+ // automatically include access key auth header to requests
17
+ // if its been set on the api client
18
+ const headers: { [key: string]: any } = {}
19
+
20
+ const projectAccessKey = this.projectAccessKey
21
+ if (projectAccessKey && projectAccessKey.length > 0) {
22
+ headers['X-Access-Key'] = projectAccessKey
23
+ }
24
+
25
+ // before the request is made
26
+ init!.headers = { ...init!.headers, ...headers }
27
+
28
+ return fetch(input, init)
29
+ }
30
+ }