@0xtrails/api 0.6.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/.turbo/turbo-build.log +5 -0
- package/.turbo/turbo-test.log +5 -0
- package/.turbo/turbo-typecheck.log +5 -0
- package/CHANGELOG.md +219 -0
- package/LICENSE +202 -0
- package/README.md +2 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/trails-api.gen.d.ts +720 -0
- package/dist/trails-api.gen.d.ts.map +1 -0
- package/dist/trails-api.gen.js +1048 -0
- package/package.json +27 -0
- package/src/index.ts +46 -0
- package/src/trails-api.gen.ts +1620 -0
- package/tsconfig.json +10 -0
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@0xtrails/api",
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Trails API Client SDK",
|
|
6
|
+
"repository": "https://github.com/0xsequence/trails/tree/master/packages/trails-api",
|
|
7
|
+
"author": "Sequence Platforms Inc.",
|
|
8
|
+
"license": "Apache-2.0",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/node": "^24.10.1",
|
|
17
|
+
"typescript": "^5.9.3",
|
|
18
|
+
"@0xsequence/typescript-config": "^0.0.0"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"copy": "cp ../../../trails-api/proto/clients/trails-api.gen.ts src/",
|
|
23
|
+
"dev": "tsc --watch",
|
|
24
|
+
"test": "echo",
|
|
25
|
+
"typecheck": "tsc --noEmit"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export * from "./trails-api.gen.js"
|
|
2
|
+
|
|
3
|
+
import { Trails as BaseTrails } from "./trails-api.gen.js"
|
|
4
|
+
|
|
5
|
+
export interface TrailsApiOptions {
|
|
6
|
+
apiKey?: string
|
|
7
|
+
jwt?: string
|
|
8
|
+
hostname?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class TrailsApi extends BaseTrails {
|
|
12
|
+
constructor(apiKey: string, options?: TrailsApiOptions) {
|
|
13
|
+
const customFetch = (
|
|
14
|
+
input: RequestInfo,
|
|
15
|
+
init?: RequestInit,
|
|
16
|
+
): Promise<Response> => {
|
|
17
|
+
// automatically include jwt and access key auth header to requests
|
|
18
|
+
// if its been set on the api client
|
|
19
|
+
const headers: { [key: string]: any } = {}
|
|
20
|
+
|
|
21
|
+
if (options?.jwt && options?.jwt.length > 0) {
|
|
22
|
+
headers.Authorization = `BEARER ${options?.jwt}`
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (apiKey && apiKey.length > 0) {
|
|
26
|
+
headers["X-Access-Key"] = apiKey
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// before the request is made
|
|
30
|
+
init = init || {}
|
|
31
|
+
init.headers = { ...init.headers, ...headers }
|
|
32
|
+
|
|
33
|
+
return fetch(input, init)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const hostname =
|
|
37
|
+
options?.hostname && options?.hostname.length > 0
|
|
38
|
+
? options?.hostname
|
|
39
|
+
: "https://trails-api.sequence.app"
|
|
40
|
+
|
|
41
|
+
super(
|
|
42
|
+
hostname.endsWith("/") ? hostname.slice(0, -1) : hostname,
|
|
43
|
+
customFetch,
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
}
|