Skip to content

Commit 393fc21

Browse files
authored
add userdata service client (#940)
1 parent b53f734 commit 393fc21

7 files changed

Lines changed: 776 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# @0xsequence/userdata
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @0xsequence/userdata
2+
3+
See [0xsequence project page](https://github.com/0xsequence/sequence.js).
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "@0xsequence/userdata",
3+
"version": "3.0.0-beta.4",
4+
"description": "userdata sub-package for Sequence",
5+
"repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/services/userdata",
6+
"author": "Sequence Platforms Inc.",
7+
"license": "Apache-2.0",
8+
"publishConfig": {
9+
"access": "public"
10+
},
11+
"scripts": {
12+
"build": "tsc",
13+
"dev": "tsc --watch",
14+
"test": "echo",
15+
"typecheck": "tsc --noEmit"
16+
},
17+
"exports": {
18+
".": {
19+
"types": "./dist/index.d.ts",
20+
"default": "./dist/index.js"
21+
}
22+
},
23+
"devDependencies": {
24+
"@repo/typescript-config": "workspace:^",
25+
"@types/node": "^24.10.1",
26+
"typescript": "^5.9.3"
27+
}
28+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
export * from './userdata.gen'
2+
3+
import { UserData as UserdataRpc } from './userdata.gen'
4+
5+
export class SequenceUserdataClient extends UserdataRpc {
6+
constructor(
7+
hostname: string,
8+
public projectAccessKey?: string,
9+
public jwtAuth?: string,
10+
) {
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 jwt and access key auth header to requests
17+
// if its been set on the api client
18+
const headers: { [key: string]: any } = {}
19+
20+
const jwtAuth = this.jwtAuth
21+
const projectAccessKey = this.projectAccessKey
22+
23+
if (jwtAuth && jwtAuth.length > 0) {
24+
headers['Authorization'] = `BEARER ${jwtAuth}`
25+
}
26+
27+
if (projectAccessKey && projectAccessKey.length > 0) {
28+
headers['X-Access-Key'] = projectAccessKey
29+
}
30+
31+
// before the request is made
32+
init!.headers = { ...init!.headers, ...headers }
33+
34+
return fetch(input, init)
35+
}
36+
}

0 commit comments

Comments
 (0)