@structbuild/sdk 0.3.0 → 0.3.1
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/README.md +134 -26
- package/dist/generated/polymarket.d.ts +137 -91
- package/dist/generated/ws-alerts.d.ts +2599 -0
- package/dist/generated/ws.d.ts +921 -0
- package/dist/index.cjs +545 -179
- package/dist/index.cjs.map +6 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.js +545 -179
- package/dist/index.js.map +6 -5
- package/dist/types/http.d.ts +1 -0
- package/dist/types/index.d.ts +4 -1
- package/dist/types/ws-helpers.d.ts +5 -0
- package/dist/types/ws.d.ts +119 -90
- package/dist/ws-alerts.d.ts +39 -0
- package/dist/ws-transport.d.ts +26 -7
- package/dist/ws.d.ts +27 -33
- package/package.json +8 -5
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ConnectionState, StructWebSocketConfig, AlertsWebSocketEventMap, WsAlertSubscribedResponse } from "./types/ws.js";
|
|
2
|
+
import type { WsAlertSubscribeMap, WsAlertEventName } from "./types/ws-helpers.js";
|
|
3
|
+
type Listener<T> = (payload: T) => void;
|
|
4
|
+
export declare class StructAlertsWebSocket {
|
|
5
|
+
private readonly transport;
|
|
6
|
+
private readonly listeners;
|
|
7
|
+
private readonly subscriptions;
|
|
8
|
+
private readonly pendingSubscribes;
|
|
9
|
+
private readonly subscribeTimeout;
|
|
10
|
+
private pingTimer;
|
|
11
|
+
private pongTimer;
|
|
12
|
+
private isEmittingListenerError;
|
|
13
|
+
constructor(config: StructWebSocketConfig);
|
|
14
|
+
get state(): ConnectionState;
|
|
15
|
+
connect(): Promise<void>;
|
|
16
|
+
disconnect(): void;
|
|
17
|
+
on<K extends keyof AlertsWebSocketEventMap>(event: K, listener: Listener<AlertsWebSocketEventMap[K]>): () => void;
|
|
18
|
+
off<K extends keyof AlertsWebSocketEventMap>(event: K, listener: Listener<AlertsWebSocketEventMap[K]>): void;
|
|
19
|
+
once<K extends keyof AlertsWebSocketEventMap>(event: K, listener: Listener<AlertsWebSocketEventMap[K]>): () => void;
|
|
20
|
+
removeAllListeners(event?: keyof AlertsWebSocketEventMap): void;
|
|
21
|
+
subscribe<E extends WsAlertEventName>(event: E, filters: Omit<WsAlertSubscribeMap[E], "op" | "event">): Promise<WsAlertSubscribedResponse>;
|
|
22
|
+
unsubscribe(event: WsAlertEventName): void;
|
|
23
|
+
private rebuildReplay;
|
|
24
|
+
private handleOpen;
|
|
25
|
+
private handleClose;
|
|
26
|
+
private handleMessage;
|
|
27
|
+
private emit;
|
|
28
|
+
private startPing;
|
|
29
|
+
private stopPing;
|
|
30
|
+
private sendSubscription;
|
|
31
|
+
private restartPendingSubscribes;
|
|
32
|
+
private pausePendingSubscribes;
|
|
33
|
+
private armSubscribeTimer;
|
|
34
|
+
private clearSubscribeTimer;
|
|
35
|
+
private armPongTimer;
|
|
36
|
+
private clearPongTimer;
|
|
37
|
+
private handleListenerError;
|
|
38
|
+
}
|
|
39
|
+
export {};
|
package/dist/ws-transport.d.ts
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { WebSocketClosedError } from "./errors.js";
|
|
2
|
+
import type { ConnectionState } from "./types/ws.js";
|
|
2
3
|
import type { RetryConfig } from "./types/http.js";
|
|
4
|
+
export declare function buildWebSocketUrl(path: string, config: {
|
|
5
|
+
apiKey: string;
|
|
6
|
+
jwt?: string;
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
}, defaultBaseUrl: string): string;
|
|
3
9
|
export interface WebSocketTransportCallbacks {
|
|
4
10
|
onOpen: () => void;
|
|
5
11
|
onClose: (code: number, reason: string) => void;
|
|
6
12
|
onError: (error: Error) => void;
|
|
7
13
|
onMessage: (data: unknown) => void;
|
|
8
14
|
onReconnecting: (attempt: number) => void;
|
|
15
|
+
onReconnectFailed: (error: Error) => void;
|
|
16
|
+
onAuthFailed: (error: WebSocketClosedError) => void;
|
|
17
|
+
onWarning: (warning: Error) => void;
|
|
9
18
|
}
|
|
10
19
|
export declare class WebSocketTransport {
|
|
11
20
|
private ws;
|
|
@@ -13,23 +22,33 @@ export declare class WebSocketTransport {
|
|
|
13
22
|
private reconnectTimer;
|
|
14
23
|
private reconnectAttempt;
|
|
15
24
|
private intentionalClose;
|
|
25
|
+
private readonly connectWaiters;
|
|
16
26
|
private readonly pendingMessages;
|
|
17
27
|
private readonly replayMessages;
|
|
18
|
-
private readonly
|
|
28
|
+
private readonly getUrl;
|
|
19
29
|
private readonly retry;
|
|
20
30
|
private readonly callbacks;
|
|
21
|
-
constructor(url: string, retry: RetryConfig, callbacks: WebSocketTransportCallbacks);
|
|
31
|
+
constructor(url: string | (() => string), retry: RetryConfig, callbacks: WebSocketTransportCallbacks);
|
|
22
32
|
get state(): ConnectionState;
|
|
23
|
-
connect(): void
|
|
33
|
+
connect(): Promise<void>;
|
|
24
34
|
disconnect(): void;
|
|
25
|
-
send(message:
|
|
26
|
-
|
|
27
|
-
|
|
35
|
+
send(message: Record<string, unknown>): boolean;
|
|
36
|
+
sendNow(message: Record<string, unknown>): boolean;
|
|
37
|
+
addReplayMessage(message: Record<string, unknown>): void;
|
|
38
|
+
addReplayMessages(messages: Record<string, unknown>[]): void;
|
|
28
39
|
clearReplayMessages(): void;
|
|
40
|
+
close(code: number, reason: string): void;
|
|
41
|
+
private createConnectPromise;
|
|
42
|
+
private resolveConnect;
|
|
43
|
+
private rejectConnect;
|
|
29
44
|
private createSocket;
|
|
30
45
|
private replaySubscriptions;
|
|
31
46
|
private flushPendingMessages;
|
|
32
47
|
private scheduleReconnect;
|
|
33
48
|
private clearReconnectTimer;
|
|
49
|
+
private sendMessage;
|
|
50
|
+
private enqueueMessage;
|
|
51
|
+
private enqueueReplayMessages;
|
|
52
|
+
private isAuthFailure;
|
|
34
53
|
private setState;
|
|
35
54
|
}
|
package/dist/ws.d.ts
CHANGED
|
@@ -1,46 +1,40 @@
|
|
|
1
|
-
import type { ConnectionState, StructWebSocketConfig, WebSocketEventMap } from "./types/ws.js";
|
|
2
|
-
import type { Address } from "./types/common.js";
|
|
1
|
+
import type { ConnectionState, StructWebSocketConfig, WebSocketEventMap, WsRoomId, WsFiltersOptionalRoom, WsFiltersRequiredRoom, WsSubscriptionMap, WsSubscribeResponseMap } from "./types/ws.js";
|
|
3
2
|
type Listener<T> = (payload: T) => void;
|
|
4
3
|
export declare class StructWebSocket {
|
|
5
4
|
private readonly transport;
|
|
6
5
|
private readonly listeners;
|
|
7
|
-
private readonly
|
|
8
|
-
private readonly
|
|
9
|
-
private readonly
|
|
10
|
-
private
|
|
11
|
-
private
|
|
6
|
+
private readonly subscriptions;
|
|
7
|
+
private readonly pendingSubscribes;
|
|
8
|
+
private readonly subscribeTimeout;
|
|
9
|
+
private pingTimer;
|
|
10
|
+
private pongTimer;
|
|
11
|
+
private isEmittingListenerError;
|
|
12
12
|
constructor(config: StructWebSocketConfig);
|
|
13
13
|
get state(): ConnectionState;
|
|
14
|
-
connect(): void
|
|
14
|
+
connect(): Promise<void>;
|
|
15
15
|
disconnect(): void;
|
|
16
|
-
on<K extends keyof WebSocketEventMap>(event: K, listener: Listener<WebSocketEventMap[K]>):
|
|
17
|
-
off<K extends keyof WebSocketEventMap>(event: K, listener: Listener<WebSocketEventMap[K]>):
|
|
18
|
-
once<K extends keyof WebSocketEventMap>(event: K, listener: Listener<WebSocketEventMap[K]>):
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
untrackWallets(addresses: Address[]): void;
|
|
25
|
-
subscribeWhaleTrades(): void;
|
|
26
|
-
unsubscribeWhaleTrades(): void;
|
|
27
|
-
subscribeSmartMoneyTrades(): void;
|
|
28
|
-
unsubscribeSmartMoneyTrades(): void;
|
|
29
|
-
subscribeInsiderTrades(): void;
|
|
30
|
-
unsubscribeInsiderTrades(): void;
|
|
31
|
-
trackConditions(conditionIds: string[]): void;
|
|
32
|
-
untrackConditions(conditionIds: string[]): void;
|
|
16
|
+
on<K extends keyof WebSocketEventMap>(event: K, listener: Listener<WebSocketEventMap[K]>): () => void;
|
|
17
|
+
off<K extends keyof WebSocketEventMap>(event: K, listener: Listener<WebSocketEventMap[K]>): void;
|
|
18
|
+
once<K extends keyof WebSocketEventMap>(event: K, listener: Listener<WebSocketEventMap[K]>): () => void;
|
|
19
|
+
removeAllListeners(event?: keyof WebSocketEventMap): void;
|
|
20
|
+
subscribe<R extends WsFiltersOptionalRoom>(room: R, filters?: WsSubscriptionMap[R]): Promise<WsSubscribeResponseMap[R]>;
|
|
21
|
+
subscribe<R extends WsFiltersRequiredRoom>(room: R, filters: WsSubscriptionMap[R]): Promise<WsSubscribeResponseMap[R]>;
|
|
22
|
+
unsubscribe(room: WsRoomId): void;
|
|
23
|
+
private rebuildReplay;
|
|
33
24
|
private handleOpen;
|
|
34
25
|
private handleClose;
|
|
35
26
|
private handleMessage;
|
|
36
27
|
private emit;
|
|
37
|
-
private
|
|
38
|
-
private
|
|
39
|
-
private
|
|
40
|
-
private
|
|
41
|
-
private
|
|
42
|
-
private
|
|
43
|
-
private
|
|
44
|
-
private
|
|
28
|
+
private startPing;
|
|
29
|
+
private stopPing;
|
|
30
|
+
private sendSubscription;
|
|
31
|
+
private restartPendingSubscribes;
|
|
32
|
+
private pausePendingSubscribes;
|
|
33
|
+
private armSubscribeTimer;
|
|
34
|
+
private clearSubscribeTimer;
|
|
35
|
+
private armPongTimer;
|
|
36
|
+
private clearPongTimer;
|
|
37
|
+
private getSubscribeError;
|
|
38
|
+
private handleListenerError;
|
|
45
39
|
}
|
|
46
40
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@structbuild/sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -24,14 +24,17 @@
|
|
|
24
24
|
"build": "rm -rf dist && bun build ./src/index.ts --target browser --format esm --sourcemap --outdir ./dist && bun build ./src/index.ts --target browser --format cjs --sourcemap --outdir ./dist-cjs && mv ./dist-cjs/index.js ./dist/index.cjs && mv ./dist-cjs/index.js.map ./dist/index.cjs.map && rm -rf dist-cjs && tsc --emitDeclarationOnly",
|
|
25
25
|
"check-routes": "bun run scripts/check-routes.ts",
|
|
26
26
|
"fix-spec": "bun run scripts/fix-spec.ts",
|
|
27
|
-
"
|
|
27
|
+
"fetch-specs": "bun run scripts/fetch-specs.ts",
|
|
28
|
+
"prep": "bun run fetch-specs && bun run fix-spec && bun run generate:polymarket && bun run generate:webhooks && bun run generate:ws && bun run check-routes && bun run build",
|
|
29
|
+
"prep:staging": "STRUCT_ENV=staging bun run prep",
|
|
28
30
|
"test": "bun test",
|
|
29
31
|
"test:watch": "bun test --watch",
|
|
30
32
|
"typecheck": "bun run tsc -p tsconfig.check.json",
|
|
31
|
-
"fetch-spec:polymarket": "curl -s -o openapi/polymarket.json https://api.struct.to/api-docs/openapi.json",
|
|
32
33
|
"generate:polymarket": "openapi-typescript openapi/polymarket.json -o src/generated/polymarket.ts",
|
|
33
|
-
"
|
|
34
|
-
"generate:
|
|
34
|
+
"generate:webhooks": "openapi-typescript openapi/webhooks.json -o src/generated/webhooks.ts",
|
|
35
|
+
"generate:ws": "bun run scripts/generate-ws-types.ts",
|
|
36
|
+
"link": "bun link",
|
|
37
|
+
"pack": "bun run build && bun pm pack"
|
|
35
38
|
},
|
|
36
39
|
"devDependencies": {
|
|
37
40
|
"@types/bun": "latest",
|