@0xsequence/builder 0.0.0-20241216114019

Sign up to get free protection for your applications and to get access to all the features.
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
+ }