@pinixai/hub-client 0.1.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 +37 -0
- package/src/client.ts +33 -0
- package/src/gen/hub_pb.ts +1652 -0
- package/src/helpers.ts +47 -0
- package/src/index.ts +36 -0
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pinixai/hub-client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Typed Hub client for Pinix — Connect-RPC transport + proto types",
|
|
5
|
+
"main": "src/index.ts",
|
|
6
|
+
"module": "src/index.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./src/index.ts"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"src"
|
|
13
|
+
],
|
|
14
|
+
"keywords": [
|
|
15
|
+
"pinix",
|
|
16
|
+
"hub",
|
|
17
|
+
"connect-rpc",
|
|
18
|
+
"grpc"
|
|
19
|
+
],
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/epiral/hub-client.git"
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@bufbuild/protoc-gen-es": "^2.11.0",
|
|
27
|
+
"@types/bun": "^1.3.11"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"typescript": "^5.9.3"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@bufbuild/protobuf": "^2.11.0",
|
|
34
|
+
"@connectrpc/connect": "^2.1.1",
|
|
35
|
+
"@connectrpc/connect-web": "^2.1.1"
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createClient, type Client, type Interceptor } from "@connectrpc/connect";
|
|
2
|
+
import { createConnectTransport } from "@connectrpc/connect-web";
|
|
3
|
+
import { HubService } from "./gen/hub_pb";
|
|
4
|
+
|
|
5
|
+
export interface HubClientOptions {
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
token?: string;
|
|
8
|
+
interceptors?: Interceptor[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function createHubClient(
|
|
12
|
+
options: HubClientOptions,
|
|
13
|
+
): Client<typeof HubService> {
|
|
14
|
+
const interceptors: Interceptor[] = [];
|
|
15
|
+
|
|
16
|
+
if (options.token) {
|
|
17
|
+
interceptors.push((next) => (req) => {
|
|
18
|
+
req.header.set("Authorization", `Bearer ${options.token}`);
|
|
19
|
+
return next(req);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (options.interceptors) {
|
|
24
|
+
interceptors.push(...options.interceptors);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const transport = createConnectTransport({
|
|
28
|
+
baseUrl: options.baseUrl,
|
|
29
|
+
interceptors,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return createClient(HubService, transport);
|
|
33
|
+
}
|