@superblocksteam/sdk 2.0.0-next.38 → 2.0.0-next.39

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.
@@ -1,6 +1,4 @@
1
- import { ISocket } from "@superblocksteam/shared";
2
- import WebSocket from "ws";
3
- import type { GenericMiddleware, ISocketClient, MethodHandlers, RequestContextBase, SocketTimeouts } from "../types/index.js";
1
+ import type { ISocketClient } from "../types/index.js";
4
2
  import type { ServerMethods } from "@superblocksteam/shared";
5
3
  export type StdISocketRPCClient = ISocketClient<ServerMethods>;
6
4
  export declare function connectToISocketRPCServer({ superblocksBaseUrl, agentUrl, token, }: {
@@ -8,12 +6,4 @@ export declare function connectToISocketRPCServer({ superblocksBaseUrl, agentUrl
8
6
  token: string;
9
7
  agentUrl?: string;
10
8
  }): Promise<StdISocketRPCClient>;
11
- export declare class ISocketWithClientAuth<ImplementedMethods, CallableMethods, RequestContext extends RequestContextBase> extends ISocket<ImplementedMethods, CallableMethods, RequestContext> {
12
- private readonly authorization?;
13
- private hasSentAuth;
14
- constructor(ws: WebSocket, authorization: string | undefined, requestHandlers: MethodHandlers<ImplementedMethods, CallableMethods, RequestContext>, globalMiddlewares: GenericMiddleware<CallableMethods, RequestContext>[], timeouts?: SocketTimeouts);
15
- request<Params, Result>(method: string, params: Params): Promise<Result>;
16
- }
17
- export declare function connectISocket<CallableMethods, ImplementedMethods, RequestContext extends RequestContextBase = RequestContextBase>(wsUrl: string, authorization: string | undefined, requestHandlers: MethodHandlers<ImplementedMethods, CallableMethods, RequestContext>, globalMiddlewares: GenericMiddleware<CallableMethods, RequestContext>[], timeouts?: SocketTimeouts): Promise<ISocketClient<CallableMethods>>;
18
- export declare function connectWebSocket(wsUrl: string): Promise<WebSocket>;
19
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/socket/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,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ACjC,eAAe,EAAE,cAAc,CAC7B,kBAAkB,EAClB,eAAe,EACf,cAAc,CACf,EACD,iBAAiB,EAAE,iBAAiB,CAAC,eAAe,EAAE,cAAc,CAAC,EAAE,EACvE,QAAQ,CAAC,EAAE,cAAc,GACxB,OAAO,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC,CAUzC;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAgBlE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/socket/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE5E,MAAM,MAAM,mBAAmB,GAAG,aAAa,CAAC,aAAa,CAAC,CAAC;AAE/D,wBAAsB,yBAAyB,CAAC,EAC9C,kBAAkB,EAClB,QAAQ,EACR,KAAK,GACN,EAAE;IACD,kBAAkB,EAAE,MAAM,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CA8B/B"}
@@ -1,5 +1,5 @@
1
- import { createISocketClient, ISocket } from "@superblocksteam/shared";
2
- import WebSocket from "ws";
1
+ import { connectISocket } from "@superblocksteam/shared";
2
+ import tracer from "../dev-utils/dev-tracer.js";
3
3
  import { createRequestHandlers } from "./handlers.js";
4
4
  export async function connectToISocketRPCServer({ superblocksBaseUrl, agentUrl, token, }) {
5
5
  const requestHandlers = createRequestHandlers({
@@ -20,48 +20,9 @@ export async function connectToISocketRPCServer({ superblocksBaseUrl, agentUrl,
20
20
  else if (wsUrl.hostname === "localhost") {
21
21
  wsUrl.hostname = "127.0.0.1";
22
22
  }
23
- return await connectISocket(wsUrl.href, authorization, requestHandlers, [], {
23
+ return await connectISocket(wsUrl.href, authorization, requestHandlers, [], tracer, {
24
24
  connectionTimeoutInSeconds: 6 * 60, // 6 minutes
25
25
  noResponseTimeoutInSeconds: 5 * 60, // 5 minutes
26
26
  });
27
27
  }
28
- // a subclass of ISocket that sends an auth token on the first request
29
- // this is useful for client-side sockets that need to authenticate
30
- // TODO(george): if we start using this for long-lived connections, we should add a way to refresh the token
31
- export class ISocketWithClientAuth extends ISocket {
32
- authorization;
33
- hasSentAuth = false;
34
- constructor(ws, authorization, requestHandlers, globalMiddlewares, timeouts) {
35
- super(ws, requestHandlers, globalMiddlewares, timeouts);
36
- this.authorization = authorization;
37
- }
38
- // override `request` from the base class to send `authorization` when appropriate
39
- async request(method, params) {
40
- // only send `authorization` on the first request
41
- const authorization = this.hasSentAuth ? undefined : this.authorization;
42
- const result = await super.request(method, params, authorization);
43
- this.hasSentAuth = true;
44
- return result;
45
- }
46
- }
47
- export async function connectISocket(wsUrl, authorization, requestHandlers, globalMiddlewares, timeouts) {
48
- const ws = await connectWebSocket(wsUrl);
49
- const isocket = new ISocketWithClientAuth(ws, authorization, requestHandlers, globalMiddlewares, timeouts);
50
- return createISocketClient(isocket);
51
- }
52
- export function connectWebSocket(wsUrl) {
53
- return new Promise((resolve, reject) => {
54
- const ws = new WebSocket(wsUrl);
55
- ws.addEventListener("open", () => {
56
- // Resolve the promise with the WebSocket instance when the connection is open
57
- resolve(ws);
58
- });
59
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
60
- // @ts-ignore
61
- ws.addEventListener("error", (error) => {
62
- // Reject the promise if there's an error
63
- reject(error);
64
- });
65
- });
66
- }
67
28
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/socket/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,SAAS,MAAM,IAAI,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAA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AY;KACjD,CACF,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superblocksteam/sdk",
3
- "version": "2.0.0-next.38",
3
+ "version": "2.0.0-next.39",
4
4
  "type": "module",
5
5
  "description": "Superblocks JS SDK",
6
6
  "homepage": "https://www.superblocks.com",
@@ -26,9 +26,9 @@
26
26
  "@opentelemetry/semantic-conventions": "^1.28.0",
27
27
  "@rollup/wasm-node": "^4.35.0",
28
28
  "@superblocksteam/bucketeer-sdk": "0.4.1",
29
- "@superblocksteam/shared": "0.9132.0",
30
- "@superblocksteam/util": "2.0.0-next.38",
31
- "@superblocksteam/vite-plugin-file-sync": "2.0.0-next.38",
29
+ "@superblocksteam/shared": "0.9137.0",
30
+ "@superblocksteam/util": "2.0.0-next.39",
31
+ "@superblocksteam/vite-plugin-file-sync": "2.0.0-next.39",
32
32
  "@vitejs/plugin-react": "^4.3.4",
33
33
  "axios": "^1.4.0",
34
34
  "chokidar": "^4.0.3",
@@ -1,13 +1,7 @@
1
- import { createISocketClient, ISocket } from "@superblocksteam/shared";
2
- import WebSocket from "ws";
1
+ import { connectISocket } from "@superblocksteam/shared";
2
+ import tracer from "../dev-utils/dev-tracer.js";
3
3
  import { createRequestHandlers } from "./handlers.js";
4
- import type {
5
- GenericMiddleware,
6
- ISocketClient,
7
- MethodHandlers,
8
- RequestContextBase,
9
- SocketTimeouts,
10
- } from "../types/index.js";
4
+ import type { ISocketClient } from "../types/index.js";
11
5
  import type { ClientMethods, ServerMethods } from "@superblocksteam/shared";
12
6
 
13
7
  export type StdISocketRPCClient = ISocketClient<ServerMethods>;
@@ -44,96 +38,10 @@ export async function connectToISocketRPCServer({
44
38
  authorization,
45
39
  requestHandlers,
46
40
  [],
41
+ tracer,
47
42
  {
48
43
  connectionTimeoutInSeconds: 6 * 60, // 6 minutes
49
44
  noResponseTimeoutInSeconds: 5 * 60, // 5 minutes
50
45
  },
51
46
  );
52
47
  }
53
-
54
- // a subclass of ISocket that sends an auth token on the first request
55
- // this is useful for client-side sockets that need to authenticate
56
- // TODO(george): if we start using this for long-lived connections, we should add a way to refresh the token
57
- export class ISocketWithClientAuth<
58
- ImplementedMethods,
59
- CallableMethods,
60
- RequestContext extends RequestContextBase,
61
- > extends ISocket<ImplementedMethods, CallableMethods, RequestContext> {
62
- private readonly authorization?: string;
63
- private hasSentAuth = false;
64
-
65
- constructor(
66
- ws: WebSocket,
67
- authorization: string | undefined,
68
- requestHandlers: MethodHandlers<
69
- ImplementedMethods,
70
- CallableMethods,
71
- RequestContext
72
- >,
73
- globalMiddlewares: GenericMiddleware<CallableMethods, RequestContext>[],
74
- timeouts?: SocketTimeouts,
75
- ) {
76
- super(ws, requestHandlers, globalMiddlewares, timeouts);
77
- this.authorization = authorization;
78
- }
79
-
80
- // override `request` from the base class to send `authorization` when appropriate
81
- async request<Params, Result>(
82
- method: string,
83
- params: Params,
84
- ): Promise<Result> {
85
- // only send `authorization` on the first request
86
- const authorization = this.hasSentAuth ? undefined : this.authorization;
87
- const result = await super.request<Params, Result>(
88
- method,
89
- params,
90
- authorization,
91
- );
92
- this.hasSentAuth = true;
93
- return result;
94
- }
95
- }
96
-
97
- export async function connectISocket<
98
- CallableMethods,
99
- ImplementedMethods,
100
- RequestContext extends RequestContextBase = RequestContextBase,
101
- >(
102
- wsUrl: string,
103
- authorization: string | undefined,
104
- requestHandlers: MethodHandlers<
105
- ImplementedMethods,
106
- CallableMethods,
107
- RequestContext
108
- >,
109
- globalMiddlewares: GenericMiddleware<CallableMethods, RequestContext>[],
110
- timeouts?: SocketTimeouts,
111
- ): Promise<ISocketClient<CallableMethods>> {
112
- const ws = await connectWebSocket(wsUrl);
113
- const isocket = new ISocketWithClientAuth(
114
- ws,
115
- authorization,
116
- requestHandlers,
117
- globalMiddlewares,
118
- timeouts,
119
- );
120
- return createISocketClient(isocket);
121
- }
122
-
123
- export function connectWebSocket(wsUrl: string): Promise<WebSocket> {
124
- return new Promise((resolve, reject) => {
125
- const ws = new WebSocket(wsUrl);
126
-
127
- ws.addEventListener("open", () => {
128
- // Resolve the promise with the WebSocket instance when the connection is open
129
- resolve(ws);
130
- });
131
-
132
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
133
- // @ts-ignore
134
- ws.addEventListener("error", (error: Error) => {
135
- // Reject the promise if there's an error
136
- reject(error);
137
- });
138
- });
139
- }