@kodiak-finance/orderly-net 2.7.4
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 +1 -0
- package/dist/index.d.mts +108 -0
- package/dist/index.d.ts +108 -0
- package/dist/index.js +759 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +717 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @orderly.network/net
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import EventEmitter from 'eventemitter3';
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
__ORDERLY_VERSION__?: {
|
|
6
|
+
[key: string]: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
declare const _default: "2.7.4";
|
|
11
|
+
|
|
12
|
+
declare function get<R>(url: string, options?: RequestInit, formatter?: (data: any) => R): Promise<R>;
|
|
13
|
+
declare function post(url: string, data: any, options?: Omit<RequestInit, "method">): Promise<any>;
|
|
14
|
+
declare function put(url: string, data: any, options?: Omit<RequestInit, "method">): Promise<any>;
|
|
15
|
+
declare function del(url: string, options?: Omit<RequestInit, "method">): Promise<any>;
|
|
16
|
+
declare function mutate(url: string, init: RequestInit): Promise<any>;
|
|
17
|
+
|
|
18
|
+
declare const __ORDERLY_API_URL_KEY__: string;
|
|
19
|
+
|
|
20
|
+
type NetworkId = "testnet" | "mainnet";
|
|
21
|
+
type WSOptions = {
|
|
22
|
+
privateUrl: string;
|
|
23
|
+
publicUrl?: string;
|
|
24
|
+
networkId?: NetworkId;
|
|
25
|
+
accountId?: string;
|
|
26
|
+
onSigntureRequest?: (accountId: string) => Promise<any>;
|
|
27
|
+
};
|
|
28
|
+
type unsubscribe = () => void;
|
|
29
|
+
declare enum WebSocketEvent {
|
|
30
|
+
OPEN = "open",
|
|
31
|
+
CLOSE = "close",
|
|
32
|
+
ERROR = "error",
|
|
33
|
+
MESSAGE = "message",
|
|
34
|
+
CONNECTING = "connecting",
|
|
35
|
+
RECONNECTING = "reconnecting"
|
|
36
|
+
}
|
|
37
|
+
type WSMessageHandler = {
|
|
38
|
+
onMessage: (message: any) => void;
|
|
39
|
+
onError?: (error: any) => void;
|
|
40
|
+
onClose?: (event: any) => void;
|
|
41
|
+
onUnsubscribe: (event: any) => any;
|
|
42
|
+
formatter?: (message: any) => any;
|
|
43
|
+
};
|
|
44
|
+
declare class WS extends EventEmitter {
|
|
45
|
+
private options;
|
|
46
|
+
private _publicSocket;
|
|
47
|
+
private privateSocket?;
|
|
48
|
+
private _eventContainer;
|
|
49
|
+
private publicIsReconnecting;
|
|
50
|
+
private privateIsReconnecting;
|
|
51
|
+
private reconnectInterval;
|
|
52
|
+
private authenticated;
|
|
53
|
+
private _pendingPrivateSubscribe;
|
|
54
|
+
private _pendingPublicSubscribe;
|
|
55
|
+
private _eventHandlers;
|
|
56
|
+
private _eventPrivateHandlers;
|
|
57
|
+
private _publicHeartbeatTime?;
|
|
58
|
+
private _privateHeartbeatTime?;
|
|
59
|
+
private _publicRetryCount;
|
|
60
|
+
private _privateRetryCount;
|
|
61
|
+
constructor(options: WSOptions);
|
|
62
|
+
private bindEvents;
|
|
63
|
+
private onVisibilityChange;
|
|
64
|
+
private onNetworkStatusChange;
|
|
65
|
+
/**
|
|
66
|
+
* Determine the current connection status,
|
|
67
|
+
* 1. If it is disconnected, reconnect
|
|
68
|
+
* 2. If no message is received for too long, disconnect and reconnect actively
|
|
69
|
+
* 3. When returning from the background and the network status changes, the following process is followed
|
|
70
|
+
*/
|
|
71
|
+
private checkSocketStatus;
|
|
72
|
+
openPrivate(accountId: string): void;
|
|
73
|
+
closePrivate(code?: number, reason?: string): void;
|
|
74
|
+
private createPublicSC;
|
|
75
|
+
private createPrivateSC;
|
|
76
|
+
private onOpen;
|
|
77
|
+
private onPrivateOpen;
|
|
78
|
+
private onMessage;
|
|
79
|
+
private onPublicMessage;
|
|
80
|
+
private onPrivateMessage;
|
|
81
|
+
private handlePendingPrivateTopic;
|
|
82
|
+
private onPublicClose;
|
|
83
|
+
private onPrivateClose;
|
|
84
|
+
private onPublicError;
|
|
85
|
+
private onPrivateError;
|
|
86
|
+
private errorBoardscast;
|
|
87
|
+
send: (message: any) => void;
|
|
88
|
+
close(): void;
|
|
89
|
+
set accountId(accountId: string);
|
|
90
|
+
private authenticate;
|
|
91
|
+
privateSubscribe(params: any, callback: WSMessageHandler | Omit<WSMessageHandler, "onUnsubscribe">): () => void;
|
|
92
|
+
subscribe(params: any, callback: WSMessageHandler | Omit<WSMessageHandler, "onUnsubscribe">, once?: boolean, id?: string): unsubscribe | undefined;
|
|
93
|
+
private getTopicKeyFromParams;
|
|
94
|
+
private getTopicKeyFromMessage;
|
|
95
|
+
onceSubscribe(params: any, callback: Omit<WSMessageHandler, "onUnsubscribe">): void;
|
|
96
|
+
private unsubscribe;
|
|
97
|
+
private unsubscribePrivate;
|
|
98
|
+
private unsubscribePublic;
|
|
99
|
+
private generateMessage;
|
|
100
|
+
private reconnectPublic;
|
|
101
|
+
private reconnectPrivate;
|
|
102
|
+
get client(): {
|
|
103
|
+
public: WebSocket;
|
|
104
|
+
private?: WebSocket;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export { WS, WebSocketEvent, __ORDERLY_API_URL_KEY__, del, get, mutate, post, put, _default as version };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import EventEmitter from 'eventemitter3';
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
__ORDERLY_VERSION__?: {
|
|
6
|
+
[key: string]: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
declare const _default: "2.7.4";
|
|
11
|
+
|
|
12
|
+
declare function get<R>(url: string, options?: RequestInit, formatter?: (data: any) => R): Promise<R>;
|
|
13
|
+
declare function post(url: string, data: any, options?: Omit<RequestInit, "method">): Promise<any>;
|
|
14
|
+
declare function put(url: string, data: any, options?: Omit<RequestInit, "method">): Promise<any>;
|
|
15
|
+
declare function del(url: string, options?: Omit<RequestInit, "method">): Promise<any>;
|
|
16
|
+
declare function mutate(url: string, init: RequestInit): Promise<any>;
|
|
17
|
+
|
|
18
|
+
declare const __ORDERLY_API_URL_KEY__: string;
|
|
19
|
+
|
|
20
|
+
type NetworkId = "testnet" | "mainnet";
|
|
21
|
+
type WSOptions = {
|
|
22
|
+
privateUrl: string;
|
|
23
|
+
publicUrl?: string;
|
|
24
|
+
networkId?: NetworkId;
|
|
25
|
+
accountId?: string;
|
|
26
|
+
onSigntureRequest?: (accountId: string) => Promise<any>;
|
|
27
|
+
};
|
|
28
|
+
type unsubscribe = () => void;
|
|
29
|
+
declare enum WebSocketEvent {
|
|
30
|
+
OPEN = "open",
|
|
31
|
+
CLOSE = "close",
|
|
32
|
+
ERROR = "error",
|
|
33
|
+
MESSAGE = "message",
|
|
34
|
+
CONNECTING = "connecting",
|
|
35
|
+
RECONNECTING = "reconnecting"
|
|
36
|
+
}
|
|
37
|
+
type WSMessageHandler = {
|
|
38
|
+
onMessage: (message: any) => void;
|
|
39
|
+
onError?: (error: any) => void;
|
|
40
|
+
onClose?: (event: any) => void;
|
|
41
|
+
onUnsubscribe: (event: any) => any;
|
|
42
|
+
formatter?: (message: any) => any;
|
|
43
|
+
};
|
|
44
|
+
declare class WS extends EventEmitter {
|
|
45
|
+
private options;
|
|
46
|
+
private _publicSocket;
|
|
47
|
+
private privateSocket?;
|
|
48
|
+
private _eventContainer;
|
|
49
|
+
private publicIsReconnecting;
|
|
50
|
+
private privateIsReconnecting;
|
|
51
|
+
private reconnectInterval;
|
|
52
|
+
private authenticated;
|
|
53
|
+
private _pendingPrivateSubscribe;
|
|
54
|
+
private _pendingPublicSubscribe;
|
|
55
|
+
private _eventHandlers;
|
|
56
|
+
private _eventPrivateHandlers;
|
|
57
|
+
private _publicHeartbeatTime?;
|
|
58
|
+
private _privateHeartbeatTime?;
|
|
59
|
+
private _publicRetryCount;
|
|
60
|
+
private _privateRetryCount;
|
|
61
|
+
constructor(options: WSOptions);
|
|
62
|
+
private bindEvents;
|
|
63
|
+
private onVisibilityChange;
|
|
64
|
+
private onNetworkStatusChange;
|
|
65
|
+
/**
|
|
66
|
+
* Determine the current connection status,
|
|
67
|
+
* 1. If it is disconnected, reconnect
|
|
68
|
+
* 2. If no message is received for too long, disconnect and reconnect actively
|
|
69
|
+
* 3. When returning from the background and the network status changes, the following process is followed
|
|
70
|
+
*/
|
|
71
|
+
private checkSocketStatus;
|
|
72
|
+
openPrivate(accountId: string): void;
|
|
73
|
+
closePrivate(code?: number, reason?: string): void;
|
|
74
|
+
private createPublicSC;
|
|
75
|
+
private createPrivateSC;
|
|
76
|
+
private onOpen;
|
|
77
|
+
private onPrivateOpen;
|
|
78
|
+
private onMessage;
|
|
79
|
+
private onPublicMessage;
|
|
80
|
+
private onPrivateMessage;
|
|
81
|
+
private handlePendingPrivateTopic;
|
|
82
|
+
private onPublicClose;
|
|
83
|
+
private onPrivateClose;
|
|
84
|
+
private onPublicError;
|
|
85
|
+
private onPrivateError;
|
|
86
|
+
private errorBoardscast;
|
|
87
|
+
send: (message: any) => void;
|
|
88
|
+
close(): void;
|
|
89
|
+
set accountId(accountId: string);
|
|
90
|
+
private authenticate;
|
|
91
|
+
privateSubscribe(params: any, callback: WSMessageHandler | Omit<WSMessageHandler, "onUnsubscribe">): () => void;
|
|
92
|
+
subscribe(params: any, callback: WSMessageHandler | Omit<WSMessageHandler, "onUnsubscribe">, once?: boolean, id?: string): unsubscribe | undefined;
|
|
93
|
+
private getTopicKeyFromParams;
|
|
94
|
+
private getTopicKeyFromMessage;
|
|
95
|
+
onceSubscribe(params: any, callback: Omit<WSMessageHandler, "onUnsubscribe">): void;
|
|
96
|
+
private unsubscribe;
|
|
97
|
+
private unsubscribePrivate;
|
|
98
|
+
private unsubscribePublic;
|
|
99
|
+
private generateMessage;
|
|
100
|
+
private reconnectPublic;
|
|
101
|
+
private reconnectPrivate;
|
|
102
|
+
get client(): {
|
|
103
|
+
public: WebSocket;
|
|
104
|
+
private?: WebSocket;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export { WS, WebSocketEvent, __ORDERLY_API_URL_KEY__, del, get, mutate, post, put, _default as version };
|