laplace-api 3.0.0 → 3.0.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/package.json
CHANGED
|
@@ -131,7 +131,7 @@ export interface HistoricalFinancialSheets {
|
|
|
131
131
|
|
|
132
132
|
export interface HistoricalFinancialSheet {
|
|
133
133
|
period: string;
|
|
134
|
-
|
|
134
|
+
items: HistoricalFinancialSheetRow[];
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
export interface HistoricalFinancialSheetRow {
|
|
@@ -107,6 +107,9 @@ export class LivePriceWebSocketClient {
|
|
|
107
107
|
private wsUrl: string | null = null;
|
|
108
108
|
private readonly options: Required<WebSocketOptions>;
|
|
109
109
|
private connectPromise: Promise<void> | null = null;
|
|
110
|
+
private lastMessageTimestamp: number = 0;
|
|
111
|
+
private inactivityCheckInterval: NodeJS.Timeout | null = null;
|
|
112
|
+
private readonly INACTIVITY_TIMEOUT = 15000;
|
|
110
113
|
|
|
111
114
|
constructor(options: WebSocketOptions = {}) {
|
|
112
115
|
this.options = {
|
|
@@ -119,6 +122,32 @@ export class LivePriceWebSocketClient {
|
|
|
119
122
|
};
|
|
120
123
|
}
|
|
121
124
|
|
|
125
|
+
private startInactivityInterval() {
|
|
126
|
+
this.lastMessageTimestamp = Date.now();
|
|
127
|
+
if (this.inactivityCheckInterval) {
|
|
128
|
+
clearInterval(this.inactivityCheckInterval);
|
|
129
|
+
this.inactivityCheckInterval = null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
this.inactivityCheckInterval = setInterval(async ()=> {
|
|
133
|
+
if (Date.now() - this.lastMessageTimestamp >= this.INACTIVITY_TIMEOUT) {
|
|
134
|
+
this.stopInactivityInterval();
|
|
135
|
+
try {
|
|
136
|
+
this.attemptReconnect();
|
|
137
|
+
} catch(error) {
|
|
138
|
+
this.log(`Failed to reconnect: ${error}`, "error");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}, this.INACTIVITY_TIMEOUT)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private stopInactivityInterval() {
|
|
145
|
+
if (this.inactivityCheckInterval) {
|
|
146
|
+
clearInterval(this.inactivityCheckInterval);
|
|
147
|
+
this.inactivityCheckInterval = null;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
122
151
|
private log(message: string, level: "info" | "error" | "warn" = "info") {
|
|
123
152
|
if (!this.options.enableLogging) return;
|
|
124
153
|
|
|
@@ -183,6 +212,7 @@ export class LivePriceWebSocketClient {
|
|
|
183
212
|
this.ws.onopen = () => {
|
|
184
213
|
this.reconnectAttempts = 0;
|
|
185
214
|
this.log("WebSocket connected");
|
|
215
|
+
this.startInactivityInterval();
|
|
186
216
|
resolve();
|
|
187
217
|
};
|
|
188
218
|
|
|
@@ -198,6 +228,8 @@ export class LivePriceWebSocketClient {
|
|
|
198
228
|
this.ws.onclose = () => {
|
|
199
229
|
this.isClosed = true;
|
|
200
230
|
this.log("WebSocket closed");
|
|
231
|
+
|
|
232
|
+
this.stopInactivityInterval();
|
|
201
233
|
if (this.closedReason !== WebSocketCloseReason.NORMAL_CLOSURE) {
|
|
202
234
|
try {
|
|
203
235
|
this.attemptReconnect();
|
|
@@ -225,6 +257,7 @@ export class LivePriceWebSocketClient {
|
|
|
225
257
|
};
|
|
226
258
|
|
|
227
259
|
this.ws.onmessage = (event) => {
|
|
260
|
+
this.lastMessageTimestamp = Date.now();
|
|
228
261
|
try {
|
|
229
262
|
const rawData = JSON.parse(event.data.toString());
|
|
230
263
|
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
FinancialSheetType,
|
|
8
8
|
FinancialSheetPeriod,
|
|
9
9
|
Currency,
|
|
10
|
+
HistoricalFinancialSheetRow,
|
|
10
11
|
} from "../client/financial_ratios";
|
|
11
12
|
import { Region, Locale } from "../client/collections";
|
|
12
13
|
import "./client_test_suite";
|
|
@@ -74,6 +75,35 @@ describe('FinancialRatios', () => {
|
|
|
74
75
|
Currency.TRY,
|
|
75
76
|
Region.Tr
|
|
76
77
|
);
|
|
78
|
+
|
|
79
|
+
expect(resp).toBeDefined();
|
|
80
|
+
expect(resp).not.toBeNull();
|
|
77
81
|
expect(resp).not.toBeEmpty();
|
|
82
|
+
|
|
83
|
+
expect(resp.sheets).toBeDefined();
|
|
84
|
+
expect(Array.isArray(resp.sheets)).toBe(true);
|
|
85
|
+
expect(resp.sheets.length).toBeGreaterThan(0);
|
|
86
|
+
|
|
87
|
+
const firstSheet = resp.sheets[0];
|
|
88
|
+
expect(firstSheet).toBeDefined();
|
|
89
|
+
|
|
90
|
+
expect(firstSheet.period).toBeDefined();
|
|
91
|
+
expect(typeof firstSheet.period).toBe("string")
|
|
92
|
+
|
|
93
|
+
expect(firstSheet.items).toBeDefined();
|
|
94
|
+
expect(Array.isArray(firstSheet.items)).toBe(true);
|
|
95
|
+
expect(firstSheet.items.length).toBeGreaterThan(0);
|
|
96
|
+
|
|
97
|
+
const firstRow = firstSheet.items[0];
|
|
98
|
+
expect(firstRow).toBeDefined();
|
|
99
|
+
|
|
100
|
+
expect(firstRow).toMatchObject<HistoricalFinancialSheetRow>({
|
|
101
|
+
description: expect.any(String),
|
|
102
|
+
value: expect.any(Number),
|
|
103
|
+
lineCodeId: expect.any(Number),
|
|
104
|
+
indentLevel: expect.any(Number),
|
|
105
|
+
firstAncestorLineCodeId: expect.any(Number),
|
|
106
|
+
sectionLineCodeId: expect.any(Number),
|
|
107
|
+
});
|
|
78
108
|
});
|
|
79
|
-
});
|
|
109
|
+
});
|
package/src/utilities/test.env
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
BASE_URL=
|
|
2
|
-
API_KEY=
|
|
1
|
+
BASE_URL=https://api.finfree.app
|
|
2
|
+
API_KEY=api-6fa6cefb-16df-4a19-8351-54f83c6bbe2f
|