@pythnetwork/pyth-lazer-sdk 5.0.0 → 5.2.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/dist/cjs/{client.js → client.cjs} +93 -98
- package/dist/cjs/constants.cjs +36 -0
- package/dist/cjs/emitter/index.cjs +53 -0
- package/dist/cjs/emitter/index.d.ts +29 -0
- package/dist/cjs/index.cjs +20 -0
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/protocol.cjs +33 -0
- package/dist/cjs/protocol.d.ts +1 -1
- package/dist/cjs/socket/{resilient-websocket.js → resilient-websocket.cjs} +47 -48
- package/dist/cjs/socket/websocket-pool.cjs +253 -0
- package/dist/cjs/socket/websocket-pool.d.ts +37 -3
- package/dist/cjs/util/{buffer-util.js → buffer-util.cjs} +14 -14
- package/dist/cjs/util/env-util.cjs +33 -0
- package/dist/cjs/util/index.cjs +20 -0
- package/dist/cjs/util/url-util.cjs +17 -0
- package/dist/esm/{client.js → client.mjs} +76 -88
- package/dist/esm/emitter/index.d.ts +29 -0
- package/dist/esm/emitter/index.mjs +43 -0
- package/dist/esm/index.mjs +3 -0
- package/dist/esm/package.json +1 -1
- package/dist/esm/protocol.d.ts +1 -1
- package/dist/esm/{protocol.js → protocol.mjs} +4 -4
- package/dist/esm/socket/{resilient-websocket.js → resilient-websocket.mjs} +27 -36
- package/dist/esm/socket/websocket-pool.d.ts +37 -3
- package/dist/esm/socket/websocket-pool.mjs +238 -0
- package/dist/esm/util/{buffer-util.js → buffer-util.mjs} +3 -6
- package/dist/esm/util/{env-util.js → env-util.mjs} +4 -8
- package/dist/esm/util/index.mjs +3 -0
- package/dist/esm/util/{url-util.js → url-util.mjs} +2 -4
- package/package.json +119 -15
- package/dist/cjs/constants.js +0 -9
- package/dist/cjs/index.js +0 -19
- package/dist/cjs/protocol.js +0 -15
- package/dist/cjs/socket/websocket-pool.js +0 -201
- package/dist/cjs/util/env-util.js +0 -32
- package/dist/cjs/util/index.js +0 -19
- package/dist/cjs/util/url-util.js +0 -18
- package/dist/esm/index.js +0 -3
- package/dist/esm/socket/websocket-pool.js +0 -195
- package/dist/esm/util/index.js +0 -3
- /package/dist/esm/{constants.js → constants.mjs} +0 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import TTLCache from "@isaacs/ttlcache";
|
|
2
|
+
import { dummyLogger } from "ts-log";
|
|
3
|
+
import { ResilientWebSocket } from "./resilient-websocket.mjs";
|
|
4
|
+
import { DEFAULT_STREAM_SERVICE_0_URL, DEFAULT_STREAM_SERVICE_1_URL } from "../constants.mjs";
|
|
5
|
+
import { IsomorphicEventEmitter } from "../emitter/index.mjs";
|
|
6
|
+
import { addAuthTokenToWebSocketUrl, bufferFromWebsocketData, envIsBrowserOrWorker } from "../util/index.mjs";
|
|
7
|
+
const DEFAULT_NUM_CONNECTIONS = 4;
|
|
8
|
+
export class WebSocketPool extends IsomorphicEventEmitter {
|
|
9
|
+
logger;
|
|
10
|
+
rwsPool;
|
|
11
|
+
cache;
|
|
12
|
+
subscriptions;
|
|
13
|
+
messageListeners;
|
|
14
|
+
allConnectionsDownListeners;
|
|
15
|
+
wasAllDown = true;
|
|
16
|
+
checkConnectionStatesInterval;
|
|
17
|
+
constructor(logger){
|
|
18
|
+
super(), this.logger = logger;
|
|
19
|
+
this.rwsPool = [];
|
|
20
|
+
this.cache = new TTLCache({
|
|
21
|
+
ttl: 1000 * 10
|
|
22
|
+
}); // TTL of 10 seconds
|
|
23
|
+
this.subscriptions = new Map();
|
|
24
|
+
this.messageListeners = [];
|
|
25
|
+
this.allConnectionsDownListeners = [];
|
|
26
|
+
// Start monitoring connection states
|
|
27
|
+
this.checkConnectionStatesInterval = setInterval(()=>{
|
|
28
|
+
this.checkConnectionStates();
|
|
29
|
+
}, 100);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new WebSocketPool instance that uses multiple redundant WebSocket connections for reliability.
|
|
33
|
+
* Usage semantics are similar to using a regular WebSocket client.
|
|
34
|
+
* @param urls - List of WebSocket URLs to connect to
|
|
35
|
+
* @param token - Authentication token to use for the connections
|
|
36
|
+
* @param numConnections - Number of parallel WebSocket connections to maintain (default: 3)
|
|
37
|
+
* @param logger - Optional logger to get socket level logs. Compatible with most loggers such as the built-in console and `bunyan`.
|
|
38
|
+
*/ static async create(config, token, logger) {
|
|
39
|
+
const urls = config.urls ?? [
|
|
40
|
+
DEFAULT_STREAM_SERVICE_0_URL,
|
|
41
|
+
DEFAULT_STREAM_SERVICE_1_URL
|
|
42
|
+
];
|
|
43
|
+
const log = logger ?? dummyLogger;
|
|
44
|
+
const pool = new WebSocketPool(log);
|
|
45
|
+
const numConnections = config.numConnections ?? DEFAULT_NUM_CONNECTIONS;
|
|
46
|
+
// bind a handler to capture any emitted errors and send them to the user-provided
|
|
47
|
+
// onWebSocketPoolError callback (if it is present)
|
|
48
|
+
if (typeof config.onWebSocketPoolError === "function") {
|
|
49
|
+
pool.on("error", config.onWebSocketPoolError);
|
|
50
|
+
pool.once("shutdown", ()=>{
|
|
51
|
+
// unbind all error handlers so we don't leak memory
|
|
52
|
+
pool.off("error");
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
for(let i = 0; i < numConnections; i++){
|
|
56
|
+
const baseUrl = urls[i % urls.length];
|
|
57
|
+
const isBrowser = envIsBrowserOrWorker();
|
|
58
|
+
const url = isBrowser ? addAuthTokenToWebSocketUrl(baseUrl, token) : baseUrl;
|
|
59
|
+
if (!url) {
|
|
60
|
+
throw new Error(`URLs must not be null or empty`);
|
|
61
|
+
}
|
|
62
|
+
const wsOptions = {
|
|
63
|
+
...config.rwsConfig?.wsOptions,
|
|
64
|
+
headers: isBrowser ? undefined : {
|
|
65
|
+
Authorization: `Bearer ${token}`
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const rws = new ResilientWebSocket({
|
|
69
|
+
...config.rwsConfig,
|
|
70
|
+
endpoint: url,
|
|
71
|
+
wsOptions,
|
|
72
|
+
logger: log
|
|
73
|
+
});
|
|
74
|
+
// If a websocket client unexpectedly disconnects, ResilientWebSocket will reestablish
|
|
75
|
+
// the connection and call the onReconnect callback.
|
|
76
|
+
rws.onReconnect = ()=>{
|
|
77
|
+
if (rws.wsUserClosed) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
for (const [, request] of pool.subscriptions){
|
|
81
|
+
try {
|
|
82
|
+
rws.send(JSON.stringify(request));
|
|
83
|
+
} catch (error) {
|
|
84
|
+
pool.logger.error("Failed to resend subscription on reconnect:", error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
89
|
+
const onErrorHandler = config.onWebSocketError ?? config.onError;
|
|
90
|
+
if (typeof onErrorHandler === "function") {
|
|
91
|
+
rws.onError = onErrorHandler;
|
|
92
|
+
}
|
|
93
|
+
// Handle all client messages ourselves. Dedupe before sending to registered message handlers.
|
|
94
|
+
rws.onMessage = (data)=>{
|
|
95
|
+
pool.dedupeHandler(data).catch((error)=>{
|
|
96
|
+
pool.emitPoolError(error, "Error in WebSocketPool dedupeHandler");
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
pool.rwsPool.push(rws);
|
|
100
|
+
rws.startWebSocket();
|
|
101
|
+
}
|
|
102
|
+
pool.logger.info(`Started WebSocketPool with ${numConnections.toString()} connections. Waiting for at least one to connect...`);
|
|
103
|
+
while(!pool.isAnyConnectionEstablished()){
|
|
104
|
+
await new Promise((resolve)=>setTimeout(resolve, 100));
|
|
105
|
+
}
|
|
106
|
+
pool.logger.info(`At least one WebSocket connection is established. WebSocketPool is ready.`);
|
|
107
|
+
return pool;
|
|
108
|
+
}
|
|
109
|
+
emitPoolError(error, context) {
|
|
110
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
111
|
+
if (context) {
|
|
112
|
+
this.logger.error(context, err);
|
|
113
|
+
} else {
|
|
114
|
+
this.logger.error("WebSocketPool error", err);
|
|
115
|
+
}
|
|
116
|
+
for (const errHandler of this.getListeners("error")){
|
|
117
|
+
try {
|
|
118
|
+
errHandler(err);
|
|
119
|
+
} catch (handlerError) {
|
|
120
|
+
this.logger.error("WebSocketPool error handler threw", handlerError);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Checks for error responses in JSON messages and throws appropriate errors
|
|
126
|
+
*/ handleErrorMessages(data) {
|
|
127
|
+
const message = JSON.parse(data);
|
|
128
|
+
if (message.type === "subscriptionError") {
|
|
129
|
+
throw new Error(`Error occurred for subscription ID ${String(message.subscriptionId)}: ${message.error}`);
|
|
130
|
+
} else if (message.type === "error") {
|
|
131
|
+
throw new Error(`Error: ${message.error}`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async constructCacheKeyFromWebsocketData(data) {
|
|
135
|
+
if (typeof data === "string") return data;
|
|
136
|
+
const buff = await bufferFromWebsocketData(data);
|
|
137
|
+
return buff.toString("hex");
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Handles incoming websocket messages by deduplicating identical messages received across
|
|
141
|
+
* multiple connections before forwarding to registered handlers
|
|
142
|
+
*/ dedupeHandler = async (data)=>{
|
|
143
|
+
const cacheKey = await this.constructCacheKeyFromWebsocketData(data);
|
|
144
|
+
if (this.cache.has(cacheKey)) {
|
|
145
|
+
this.logger.debug("Dropping duplicate message");
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
this.cache.set(cacheKey, true);
|
|
149
|
+
if (typeof data === "string") {
|
|
150
|
+
this.handleErrorMessages(data);
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
await Promise.all(this.messageListeners.map((handler)=>handler(data)));
|
|
154
|
+
} catch (error) {
|
|
155
|
+
this.emitPoolError(error, "Error in WebSocketPool message handler");
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
sendRequest(request) {
|
|
159
|
+
for (const rws of this.rwsPool){
|
|
160
|
+
try {
|
|
161
|
+
rws.send(JSON.stringify(request));
|
|
162
|
+
} catch (error) {
|
|
163
|
+
this.emitPoolError(error, "Failed to send WebSocket request");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
addSubscription(request) {
|
|
168
|
+
if (request.type !== "subscribe") {
|
|
169
|
+
this.emitPoolError(new Error("Request must be a subscribe request"));
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
this.subscriptions.set(request.subscriptionId, request);
|
|
173
|
+
this.sendRequest(request);
|
|
174
|
+
}
|
|
175
|
+
removeSubscription(subscriptionId) {
|
|
176
|
+
this.subscriptions.delete(subscriptionId);
|
|
177
|
+
const request = {
|
|
178
|
+
type: "unsubscribe",
|
|
179
|
+
subscriptionId
|
|
180
|
+
};
|
|
181
|
+
this.sendRequest(request);
|
|
182
|
+
}
|
|
183
|
+
addMessageListener(handler) {
|
|
184
|
+
this.messageListeners.push(handler);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Calls the handler if all websocket connections are currently down or in reconnecting state.
|
|
188
|
+
* The connections may still try to reconnect in the background.
|
|
189
|
+
*/ addAllConnectionsDownListener(handler) {
|
|
190
|
+
this.allConnectionsDownListeners.push(handler);
|
|
191
|
+
}
|
|
192
|
+
areAllConnectionsDown() {
|
|
193
|
+
return this.rwsPool.every((ws)=>!ws.isConnected() || ws.isReconnecting());
|
|
194
|
+
}
|
|
195
|
+
isAnyConnectionEstablished() {
|
|
196
|
+
return this.rwsPool.some((ws)=>ws.isConnected());
|
|
197
|
+
}
|
|
198
|
+
checkConnectionStates() {
|
|
199
|
+
const allDown = this.areAllConnectionsDown();
|
|
200
|
+
// If all connections just went down
|
|
201
|
+
if (allDown && !this.wasAllDown) {
|
|
202
|
+
this.wasAllDown = true;
|
|
203
|
+
this.logger.error("All WebSocket connections are down or reconnecting");
|
|
204
|
+
// Notify all listeners
|
|
205
|
+
for (const listener of this.allConnectionsDownListeners){
|
|
206
|
+
try {
|
|
207
|
+
listener();
|
|
208
|
+
} catch (error) {
|
|
209
|
+
this.emitPoolError(error, "All-connections-down listener threw");
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// If at least one connection was restored
|
|
214
|
+
if (!allDown && this.wasAllDown) {
|
|
215
|
+
this.wasAllDown = false;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
shutdown() {
|
|
219
|
+
for (const rws of this.rwsPool){
|
|
220
|
+
rws.closeWebSocket();
|
|
221
|
+
}
|
|
222
|
+
this.rwsPool = [];
|
|
223
|
+
this.subscriptions.clear();
|
|
224
|
+
this.messageListeners = [];
|
|
225
|
+
this.allConnectionsDownListeners = [];
|
|
226
|
+
clearInterval(this.checkConnectionStatesInterval);
|
|
227
|
+
// execute all bound shutdown handlers
|
|
228
|
+
for (const shutdownHandler of this.getListeners("shutdown")){
|
|
229
|
+
try {
|
|
230
|
+
shutdownHandler();
|
|
231
|
+
} catch (error) {
|
|
232
|
+
this.emitPoolError(error, "Shutdown handler threw");
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
// ensure any error handlers are removed to avoid leaks
|
|
236
|
+
this.off("error");
|
|
237
|
+
}
|
|
238
|
+
}
|
|
@@ -8,19 +8,16 @@ const BufferClassToUse = "Buffer" in globalThis ? globalThis.Buffer : BrowserBuf
|
|
|
8
8
|
* given a relatively unknown websocket frame data object,
|
|
9
9
|
* returns a valid Buffer instance that is safe to use
|
|
10
10
|
* isomorphically in any JS runtime environment
|
|
11
|
-
*/
|
|
12
|
-
export async function bufferFromWebsocketData(data) {
|
|
11
|
+
*/ export async function bufferFromWebsocketData(data) {
|
|
13
12
|
if (typeof data === "string") {
|
|
14
13
|
return BufferClassToUse.from(new TextEncoder().encode(data).buffer);
|
|
15
14
|
}
|
|
16
|
-
if (data instanceof BufferClassToUse)
|
|
17
|
-
return data;
|
|
15
|
+
if (data instanceof BufferClassToUse) return data;
|
|
18
16
|
if (data instanceof Blob) {
|
|
19
17
|
// let the uncaught promise exception bubble up if there's an issue
|
|
20
18
|
return BufferClassToUse.from(await data.arrayBuffer());
|
|
21
19
|
}
|
|
22
|
-
if (data instanceof ArrayBuffer)
|
|
23
|
-
return BufferClassToUse.from(data);
|
|
20
|
+
if (data instanceof ArrayBuffer) return BufferClassToUse.from(data);
|
|
24
21
|
if (Array.isArray(data)) {
|
|
25
22
|
// an array of buffers is highly unlikely, but it is a possibility
|
|
26
23
|
// indicated by the WebSocket Data interface
|
|
@@ -4,16 +4,13 @@ const g = globalThis;
|
|
|
4
4
|
/**
|
|
5
5
|
* Detects if this code is running within any Service or WebWorker context.
|
|
6
6
|
* @returns true if in a worker of some kind, false if otherwise
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
return (typeof WorkerGlobalScope !== "undefined" &&
|
|
10
|
-
g.self instanceof WorkerGlobalScope);
|
|
7
|
+
*/ export function envIsServiceOrWebWorker() {
|
|
8
|
+
return typeof WorkerGlobalScope !== "undefined" && g.self instanceof WorkerGlobalScope;
|
|
11
9
|
}
|
|
12
10
|
/**
|
|
13
11
|
* Detects if the code is running in a regular DOM or Web Worker context.
|
|
14
12
|
* @returns true if running in a DOM or Web Worker context, false if running in Node.js
|
|
15
|
-
*/
|
|
16
|
-
export function envIsBrowser() {
|
|
13
|
+
*/ export function envIsBrowser() {
|
|
17
14
|
return g.window !== undefined;
|
|
18
15
|
}
|
|
19
16
|
/**
|
|
@@ -21,7 +18,6 @@ export function envIsBrowser() {
|
|
|
21
18
|
* this code is executing in some type of browser-centric environment
|
|
22
19
|
*
|
|
23
20
|
* @returns true if in the browser's main UI thread or in a worker, false if otherwise
|
|
24
|
-
*/
|
|
25
|
-
export function envIsBrowserOrWorker() {
|
|
21
|
+
*/ export function envIsBrowserOrWorker() {
|
|
26
22
|
return envIsServiceOrWebWorker() || envIsBrowser();
|
|
27
23
|
}
|
|
@@ -5,10 +5,8 @@ const ACCESS_TOKEN_QUERY_PARAM_KEY = "ACCESS_TOKEN";
|
|
|
5
5
|
* contained within.
|
|
6
6
|
* If the URL provided is nullish, it is returned as-is (in the same nullish format).
|
|
7
7
|
* If the token is nullish, the baseUrl given is returned, instead.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
if (!baseUrl || !authToken)
|
|
11
|
-
return baseUrl;
|
|
8
|
+
*/ export function addAuthTokenToWebSocketUrl(baseUrl, authToken) {
|
|
9
|
+
if (!baseUrl || !authToken) return baseUrl;
|
|
12
10
|
const parsedUrl = new URL(baseUrl);
|
|
13
11
|
parsedUrl.searchParams.set(ACCESS_TOKEN_QUERY_PARAM_KEY, authToken);
|
|
14
12
|
return parsedUrl.toString();
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pythnetwork/pyth-lazer-sdk",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.1",
|
|
4
4
|
"description": "Pyth Lazer SDK",
|
|
5
5
|
"engines": {
|
|
6
|
-
"node": "
|
|
6
|
+
"node": "^24.0.0"
|
|
7
7
|
},
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
@@ -11,28 +11,131 @@
|
|
|
11
11
|
"files": [
|
|
12
12
|
"dist/**/*"
|
|
13
13
|
],
|
|
14
|
-
"main": "./dist/cjs/index.
|
|
14
|
+
"main": "./dist/cjs/index.cjs",
|
|
15
15
|
"types": "./dist/cjs/index.d.ts",
|
|
16
16
|
"exports": {
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
17
|
+
"./client": {
|
|
18
|
+
"require": {
|
|
19
|
+
"types": "./dist/cjs/client.d.ts",
|
|
20
|
+
"default": "./dist/cjs/client.cjs"
|
|
21
|
+
},
|
|
22
|
+
"import": {
|
|
23
|
+
"types": "./dist/esm/client.d.ts",
|
|
24
|
+
"default": "./dist/esm/client.mjs"
|
|
25
|
+
}
|
|
20
26
|
},
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
"./constants": {
|
|
28
|
+
"require": {
|
|
29
|
+
"types": "./dist/cjs/constants.d.ts",
|
|
30
|
+
"default": "./dist/cjs/constants.cjs"
|
|
31
|
+
},
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./dist/esm/constants.d.ts",
|
|
34
|
+
"default": "./dist/esm/constants.mjs"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"./emitter": {
|
|
38
|
+
"require": {
|
|
39
|
+
"types": "./dist/cjs/emitter/index.d.ts",
|
|
40
|
+
"default": "./dist/cjs/emitter/index.cjs"
|
|
41
|
+
},
|
|
42
|
+
"import": {
|
|
43
|
+
"types": "./dist/esm/emitter/index.d.ts",
|
|
44
|
+
"default": "./dist/esm/emitter/index.mjs"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
".": {
|
|
48
|
+
"require": {
|
|
49
|
+
"types": "./dist/cjs/index.d.ts",
|
|
50
|
+
"default": "./dist/cjs/index.cjs"
|
|
51
|
+
},
|
|
52
|
+
"import": {
|
|
53
|
+
"types": "./dist/esm/index.d.ts",
|
|
54
|
+
"default": "./dist/esm/index.mjs"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"./protocol": {
|
|
58
|
+
"require": {
|
|
59
|
+
"types": "./dist/cjs/protocol.d.ts",
|
|
60
|
+
"default": "./dist/cjs/protocol.cjs"
|
|
61
|
+
},
|
|
62
|
+
"import": {
|
|
63
|
+
"types": "./dist/esm/protocol.d.ts",
|
|
64
|
+
"default": "./dist/esm/protocol.mjs"
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"./socket/resilient-websocket": {
|
|
68
|
+
"require": {
|
|
69
|
+
"types": "./dist/cjs/socket/resilient-websocket.d.ts",
|
|
70
|
+
"default": "./dist/cjs/socket/resilient-websocket.cjs"
|
|
71
|
+
},
|
|
72
|
+
"import": {
|
|
73
|
+
"types": "./dist/esm/socket/resilient-websocket.d.ts",
|
|
74
|
+
"default": "./dist/esm/socket/resilient-websocket.mjs"
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"./socket/websocket-pool": {
|
|
78
|
+
"require": {
|
|
79
|
+
"types": "./dist/cjs/socket/websocket-pool.d.ts",
|
|
80
|
+
"default": "./dist/cjs/socket/websocket-pool.cjs"
|
|
81
|
+
},
|
|
82
|
+
"import": {
|
|
83
|
+
"types": "./dist/esm/socket/websocket-pool.d.ts",
|
|
84
|
+
"default": "./dist/esm/socket/websocket-pool.mjs"
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
"./util/buffer-util": {
|
|
88
|
+
"require": {
|
|
89
|
+
"types": "./dist/cjs/util/buffer-util.d.ts",
|
|
90
|
+
"default": "./dist/cjs/util/buffer-util.cjs"
|
|
91
|
+
},
|
|
92
|
+
"import": {
|
|
93
|
+
"types": "./dist/esm/util/buffer-util.d.ts",
|
|
94
|
+
"default": "./dist/esm/util/buffer-util.mjs"
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
"./util/env-util": {
|
|
98
|
+
"require": {
|
|
99
|
+
"types": "./dist/cjs/util/env-util.d.ts",
|
|
100
|
+
"default": "./dist/cjs/util/env-util.cjs"
|
|
101
|
+
},
|
|
102
|
+
"import": {
|
|
103
|
+
"types": "./dist/esm/util/env-util.d.ts",
|
|
104
|
+
"default": "./dist/esm/util/env-util.mjs"
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
"./util": {
|
|
108
|
+
"require": {
|
|
109
|
+
"types": "./dist/cjs/util/index.d.ts",
|
|
110
|
+
"default": "./dist/cjs/util/index.cjs"
|
|
111
|
+
},
|
|
112
|
+
"import": {
|
|
113
|
+
"types": "./dist/esm/util/index.d.ts",
|
|
114
|
+
"default": "./dist/esm/util/index.mjs"
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
"./util/url-util": {
|
|
118
|
+
"require": {
|
|
119
|
+
"types": "./dist/cjs/util/url-util.d.ts",
|
|
120
|
+
"default": "./dist/cjs/util/url-util.cjs"
|
|
121
|
+
},
|
|
122
|
+
"import": {
|
|
123
|
+
"types": "./dist/esm/util/url-util.d.ts",
|
|
124
|
+
"default": "./dist/esm/util/url-util.mjs"
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
"./package.json": "./package.json"
|
|
25
128
|
},
|
|
26
129
|
"devDependencies": {
|
|
27
130
|
"@cprussin/eslint-config": "^4.0.2",
|
|
28
131
|
"@cprussin/tsconfig": "^3.1.2",
|
|
132
|
+
"@types/jest": "^29.5.14",
|
|
29
133
|
"@types/node": "^18.19.54",
|
|
30
134
|
"@types/ws": "^8.5.12",
|
|
31
135
|
"eslint": "^9.23.0",
|
|
32
136
|
"prettier": "^3.5.3",
|
|
33
137
|
"ts-node": "^10.9.2",
|
|
34
|
-
"typedoc": "^0.26.8"
|
|
35
|
-
"typescript": "^5.8.2"
|
|
138
|
+
"typedoc": "^0.26.8"
|
|
36
139
|
},
|
|
37
140
|
"bugs": {
|
|
38
141
|
"url": "https://github.com/pyth-network/pyth-crosschain/issues"
|
|
@@ -56,9 +159,9 @@
|
|
|
56
159
|
"ts-log": "^2.2.7",
|
|
57
160
|
"ws": "^8.18.0"
|
|
58
161
|
},
|
|
162
|
+
"module": "./dist/esm/index.mjs",
|
|
59
163
|
"scripts": {
|
|
60
|
-
"build
|
|
61
|
-
"build:esm": "tsc --project tsconfig.build.json --outDir ./dist/esm && echo '{\"type\":\"module\"}' > dist/esm/package.json",
|
|
164
|
+
"build": "ts-duality --clean",
|
|
62
165
|
"fix:lint": "eslint --fix . --max-warnings 0",
|
|
63
166
|
"test:lint": "eslint . --max-warnings 0",
|
|
64
167
|
"test:types": "tsc",
|
|
@@ -67,6 +170,7 @@
|
|
|
67
170
|
"example:streaming": "node --loader ts-node/esm examples/streaming.js",
|
|
68
171
|
"example:history": "node --loader ts-node/esm examples/history.js",
|
|
69
172
|
"example:symbols": "node --loader ts-node/esm examples/symbols.js",
|
|
70
|
-
"doc": "typedoc --out docs/typedoc src"
|
|
173
|
+
"doc": "typedoc --out docs/typedoc src",
|
|
174
|
+
"clean": "rm -rf ./dist"
|
|
71
175
|
}
|
|
72
176
|
}
|
package/dist/cjs/constants.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_STREAM_SERVICE_1_URL = exports.DEFAULT_STREAM_SERVICE_0_URL = exports.DEFAULT_PRICE_SERVICE_URL = exports.DEFAULT_METADATA_SERVICE_URL = exports.SOLANA_LAZER_STORAGE_ID = exports.SOLANA_LAZER_PROGRAM_ID = void 0;
|
|
4
|
-
exports.SOLANA_LAZER_PROGRAM_ID = "pytd2yyk641x7ak7mkaasSJVXh6YYZnC7wTmtgAyxPt";
|
|
5
|
-
exports.SOLANA_LAZER_STORAGE_ID = "3rdJbqfnagQ4yx9HXJViD4zc4xpiSqmFsKpPuSCQVyQL";
|
|
6
|
-
exports.DEFAULT_METADATA_SERVICE_URL = "https://history.pyth-lazer.dourolabs.app/history";
|
|
7
|
-
exports.DEFAULT_PRICE_SERVICE_URL = "https://pyth-lazer-0.dourolabs.app";
|
|
8
|
-
exports.DEFAULT_STREAM_SERVICE_0_URL = "wss://pyth-lazer-0.dourolabs.app/v1/stream";
|
|
9
|
-
exports.DEFAULT_STREAM_SERVICE_1_URL = "wss://pyth-lazer-1.dourolabs.app/v1/stream";
|
package/dist/cjs/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./client.js"), exports);
|
|
18
|
-
__exportStar(require("./protocol.js"), exports);
|
|
19
|
-
__exportStar(require("./constants.js"), exports);
|
package/dist/cjs/protocol.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CustomSocketClosureCodes = exports.FORMAT_MAGICS_LE = exports.BINARY_UPDATE_FORMAT_MAGIC_LE = void 0;
|
|
4
|
-
exports.BINARY_UPDATE_FORMAT_MAGIC_LE = 461_928_307;
|
|
5
|
-
exports.FORMAT_MAGICS_LE = {
|
|
6
|
-
JSON: 3_302_625_434,
|
|
7
|
-
EVM: 2_593_727_018,
|
|
8
|
-
SOLANA: 2_182_742_457,
|
|
9
|
-
LE_ECDSA: 1_296_547_300,
|
|
10
|
-
LE_UNSIGNED: 1_499_680_012,
|
|
11
|
-
};
|
|
12
|
-
var CustomSocketClosureCodes;
|
|
13
|
-
(function (CustomSocketClosureCodes) {
|
|
14
|
-
CustomSocketClosureCodes[CustomSocketClosureCodes["CLIENT_TIMEOUT_BUT_RECONNECTING"] = 4000] = "CLIENT_TIMEOUT_BUT_RECONNECTING";
|
|
15
|
-
})(CustomSocketClosureCodes || (exports.CustomSocketClosureCodes = CustomSocketClosureCodes = {}));
|