@invezgo/sdk 1.3.1 → 2.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.
Files changed (56) hide show
  1. package/README.md +318 -313
  2. package/dist/cache.d.ts +27 -0
  3. package/dist/cache.d.ts.map +1 -0
  4. package/dist/client.d.ts +15 -18
  5. package/dist/client.d.ts.map +1 -1
  6. package/dist/errors.d.ts +71 -0
  7. package/dist/errors.d.ts.map +1 -0
  8. package/dist/generated/resources.d.ts +3291 -0
  9. package/dist/generated/resources.d.ts.map +1 -0
  10. package/dist/generated/types.d.ts +3449 -0
  11. package/dist/generated/types.d.ts.map +1 -0
  12. package/dist/http.d.ts +66 -0
  13. package/dist/http.d.ts.map +1 -0
  14. package/dist/index.d.ts +9 -15
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +755 -1005
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +775 -0
  19. package/dist/index.mjs.map +1 -0
  20. package/package.json +66 -60
  21. package/dist/endpoints/ai.d.ts +0 -98
  22. package/dist/endpoints/ai.d.ts.map +0 -1
  23. package/dist/endpoints/alerts.d.ts +0 -49
  24. package/dist/endpoints/alerts.d.ts.map +0 -1
  25. package/dist/endpoints/analysis.d.ts +0 -369
  26. package/dist/endpoints/analysis.d.ts.map +0 -1
  27. package/dist/endpoints/health.d.ts +0 -24
  28. package/dist/endpoints/health.d.ts.map +0 -1
  29. package/dist/endpoints/journals.d.ts +0 -49
  30. package/dist/endpoints/journals.d.ts.map +0 -1
  31. package/dist/endpoints/membership.d.ts +0 -35
  32. package/dist/endpoints/membership.d.ts.map +0 -1
  33. package/dist/endpoints/portfolios.d.ts +0 -14
  34. package/dist/endpoints/portfolios.d.ts.map +0 -1
  35. package/dist/endpoints/posts.d.ts +0 -42
  36. package/dist/endpoints/posts.d.ts.map +0 -1
  37. package/dist/endpoints/profile.d.ts +0 -34
  38. package/dist/endpoints/profile.d.ts.map +0 -1
  39. package/dist/endpoints/recommendation.d.ts +0 -10
  40. package/dist/endpoints/recommendation.d.ts.map +0 -1
  41. package/dist/endpoints/screener.d.ts +0 -45
  42. package/dist/endpoints/screener.d.ts.map +0 -1
  43. package/dist/endpoints/search.d.ts +0 -18
  44. package/dist/endpoints/search.d.ts.map +0 -1
  45. package/dist/endpoints/trades.d.ts +0 -31
  46. package/dist/endpoints/trades.d.ts.map +0 -1
  47. package/dist/endpoints/usage.d.ts +0 -11
  48. package/dist/endpoints/usage.d.ts.map +0 -1
  49. package/dist/endpoints/watchlists.d.ts +0 -64
  50. package/dist/endpoints/watchlists.d.ts.map +0 -1
  51. package/dist/index.esm.js +0 -1054
  52. package/dist/index.esm.js.map +0 -1
  53. package/dist/invezgo.d.ts +0 -40
  54. package/dist/invezgo.d.ts.map +0 -1
  55. package/dist/types.d.ts +0 -574
  56. package/dist/types.d.ts.map +0 -1
package/dist/index.mjs ADDED
@@ -0,0 +1,775 @@
1
+ class AnalysisResource {
2
+ transport;
3
+ constructor(transport) {
4
+ this.transport = transport;
5
+ }
6
+ getStockList(options) {
7
+ return this.transport.request({ method: 'GET', route: '/analysis/list/stock', cache: 'default' }, options);
8
+ }
9
+ getBrokerList(options) {
10
+ return this.transport.request({ method: 'GET', route: '/analysis/list/broker', cache: 'default' }, options);
11
+ }
12
+ getIndexList(options) {
13
+ return this.transport.request({ method: 'GET', route: '/analysis/list/index', cache: 'default' }, options);
14
+ }
15
+ getUma(params, options) {
16
+ return this.transport.request({ method: 'GET', route: '/analysis/uma', cache: 'default', query: params }, options);
17
+ }
18
+ getSuspend(params, options) {
19
+ return this.transport.request({ method: 'GET', route: '/analysis/suspend', cache: 'default', query: params }, options);
20
+ }
21
+ getNotation(options) {
22
+ return this.transport.request({ method: 'GET', route: '/analysis/notation', cache: 'default' }, options);
23
+ }
24
+ getInformation(code, options) {
25
+ return this.transport.request({ method: 'GET', route: '/analysis/information/{code}', cache: 'default', pathParams: { code } }, options);
26
+ }
27
+ getTopChange(params, options) {
28
+ return this.transport.request({ method: 'GET', route: '/analysis/top/change', cache: 'default', query: params }, options);
29
+ }
30
+ getTopForeign(params, options) {
31
+ return this.transport.request({ method: 'GET', route: '/analysis/top/foreign', cache: 'default', query: params }, options);
32
+ }
33
+ getTopAccumulation(params, options) {
34
+ return this.transport.request({ method: 'GET', route: '/analysis/top/accumulation', cache: 'default', query: params }, options);
35
+ }
36
+ getTopRitel(params, options) {
37
+ return this.transport.request({ method: 'GET', route: '/analysis/top/ritel', cache: 'default', query: params }, options);
38
+ }
39
+ getStockRunningTrade(code, params, options) {
40
+ return this.transport.request({ method: 'GET', route: '/analysis/running-trade/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
41
+ }
42
+ getIntradayChart(code, params, options) {
43
+ return this.transport.request({ method: 'GET', route: '/analysis/intraday/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
44
+ }
45
+ getOrderBook(code, params, options) {
46
+ return this.transport.request({ method: 'GET', route: '/analysis/order-book/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
47
+ }
48
+ getOrderQueue(code, params, options) {
49
+ return this.transport.request({ method: 'GET', route: '/analysis/queue/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
50
+ }
51
+ getIntradayData(code, params, options) {
52
+ return this.transport.request({ method: 'GET', route: '/analysis/intraday-data/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
53
+ }
54
+ getIntradayIndex(code, options) {
55
+ return this.transport.request({ method: 'GET', route: '/analysis/intraday-index/{code}', cache: 'realtime', pathParams: { code } }, options);
56
+ }
57
+ getAdvanceChart(code, params, options) {
58
+ return this.transport.request({ method: 'GET', route: '/analysis/chart/stock/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
59
+ }
60
+ getIndexChart(code, params, options) {
61
+ return this.transport.request({ method: 'GET', route: '/analysis/chart/index/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
62
+ }
63
+ getMultiTimeChart(code, params, options) {
64
+ return this.transport.request({ method: 'GET', route: '/analysis/chart/multi-time/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
65
+ }
66
+ getIndicatorChart(indicator, code, params, options) {
67
+ return this.transport.request({ method: 'GET', route: '/analysis/chart/stock/{indicator}/{code}', cache: 'default', pathParams: { indicator, code }, query: params }, options);
68
+ }
69
+ getShareholderDetail(params, options) {
70
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder-detail', cache: 'default', query: params }, options);
71
+ }
72
+ getShareholderOneDetail(params, options) {
73
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder-detail-one', cache: 'default', query: params }, options);
74
+ }
75
+ getShareholderHigh(options) {
76
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder/high', cache: 'default' }, options);
77
+ }
78
+ getShareholderNumber(code, options) {
79
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder/number/{code}', cache: 'default', pathParams: { code } }, options);
80
+ }
81
+ getShareholderRelation(params, options) {
82
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder/relation', cache: 'default', query: params }, options);
83
+ }
84
+ getShareholder(code, options) {
85
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder/{code}', cache: 'default', pathParams: { code } }, options);
86
+ }
87
+ getShareholderKSEI(code, params, options) {
88
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder/ksei/{code}', cache: 'default', pathParams: { code }, query: params }, options);
89
+ }
90
+ getShareholderClassification(code, params, options) {
91
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder/classification/{code}', cache: 'default', pathParams: { code }, query: params }, options);
92
+ }
93
+ getShareholderClassifyTable(code, options) {
94
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder/classify-table/{code}', cache: 'default', pathParams: { code } }, options);
95
+ }
96
+ getSummaryStock(code, params, options) {
97
+ return this.transport.request({ method: 'GET', route: '/analysis/summary/stock/{code}', cache: 'default', pathParams: { code }, query: params }, options);
98
+ }
99
+ getSummaryBroker(code, params, options) {
100
+ return this.transport.request({ method: 'GET', route: '/analysis/summary/broker/{code}', cache: 'default', pathParams: { code }, query: params }, options);
101
+ }
102
+ getSectorStalker(params, options) {
103
+ return this.transport.request({ method: 'GET', route: '/analysis/stalker/sector', cache: 'realtime', query: params }, options);
104
+ }
105
+ getSectorRotation(params, options) {
106
+ return this.transport.request({ method: 'GET', route: '/analysis/sector/rotation', cache: 'realtime', query: params }, options);
107
+ }
108
+ getBrokerStalker(broker, stock, params, options) {
109
+ return this.transport.request({ method: 'GET', route: '/analysis/stalker/broker/{broker}/{stock}', cache: 'default', pathParams: { broker, stock }, query: params }, options);
110
+ }
111
+ getBrokerStalkerList(code, params, options) {
112
+ return this.transport.request({ method: 'GET', route: '/analysis/stalker/list/{code}', cache: 'default', pathParams: { code }, query: params }, options);
113
+ }
114
+ getSummaryStockChart(code, params, options) {
115
+ return this.transport.request({ method: 'GET', route: '/analysis/summary-chart/stock/{code}', cache: 'default', pathParams: { code }, query: params }, options);
116
+ }
117
+ getSummaryBrokerChart(code, params, options) {
118
+ return this.transport.request({ method: 'GET', route: '/analysis/summary-chart/broker/{code}', cache: 'default', pathParams: { code }, query: params }, options);
119
+ }
120
+ getInventoryStockChart(code, params, options) {
121
+ return this.transport.request({ method: 'GET', route: '/analysis/inventory-chart/stock/{code}', cache: 'default', pathParams: { code }, query: params }, options);
122
+ }
123
+ getInventoryBrokerChart(code, params, options) {
124
+ return this.transport.request({ method: 'GET', route: '/analysis/inventory-chart/broker/{code}', cache: 'default', pathParams: { code }, query: params }, options);
125
+ }
126
+ getMomentumChart(code, params, options) {
127
+ return this.transport.request({ method: 'GET', route: '/analysis/momentum-chart/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
128
+ }
129
+ getIntradayInventoryChart(code, params, options) {
130
+ return this.transport.request({ method: 'GET', route: '/analysis/intraday-inventory-chart/{code}', cache: 'default', pathParams: { code }, query: params }, options);
131
+ }
132
+ getSankeyChart(code, params, options) {
133
+ return this.transport.request({ method: 'GET', route: '/analysis/sankey-chart/{code}', cache: 'default', pathParams: { code }, query: params }, options);
134
+ }
135
+ getPriceTable(code, params, options) {
136
+ return this.transport.request({ method: 'GET', route: '/analysis/price-table/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
137
+ }
138
+ getTimeTable(code, params, options) {
139
+ return this.transport.request({ method: 'GET', route: '/analysis/time-table/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
140
+ }
141
+ getPriceDiary(code, options) {
142
+ return this.transport.request({ method: 'GET', route: '/analysis/price-diary/{code}', cache: 'default', pathParams: { code } }, options);
143
+ }
144
+ getPriceSeasonality(code, params, options) {
145
+ return this.transport.request({ method: 'GET', route: '/analysis/price-seasonality/{code}', cache: 'default', pathParams: { code }, query: params }, options);
146
+ }
147
+ getShareholderAbove(params, options) {
148
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder-above', cache: 'default', query: params }, options);
149
+ }
150
+ getShareholderAboveChart(code, params, options) {
151
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder-above-chart/{code}', cache: 'default', pathParams: { code }, query: params }, options);
152
+ }
153
+ getShareholderOne(params, options) {
154
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder-one', cache: 'default', query: params }, options);
155
+ }
156
+ getShareholderOneChart(code, params, options) {
157
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder-one-chart/{code}', cache: 'default', pathParams: { code }, query: params }, options);
158
+ }
159
+ getInsider(params, options) {
160
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder-insider', cache: 'default', query: params }, options);
161
+ }
162
+ getInsiderChart(code, params, options) {
163
+ return this.transport.request({ method: 'GET', route: '/analysis/insider-chart/{code}', cache: 'default', pathParams: { code }, query: params }, options);
164
+ }
165
+ getFinancialStatement(code, params, options) {
166
+ return this.transport.request({ method: 'GET', route: '/analysis/financial-statement/{code}', cache: 'default', pathParams: { code }, query: params }, options);
167
+ }
168
+ getFinancialStatementChart(code, params, options) {
169
+ return this.transport.request({ method: 'GET', route: '/analysis/financial-statement-chart/{code}', cache: 'default', pathParams: { code }, query: params }, options);
170
+ }
171
+ getKeystat(code, params, options) {
172
+ return this.transport.request({ method: 'GET', route: '/analysis/keystat/{code}', cache: 'default', pathParams: { code }, query: params }, options);
173
+ }
174
+ getKeystatChart(code, params, options) {
175
+ return this.transport.request({ method: 'GET', route: '/analysis/keystat-chart/{code}', cache: 'default', pathParams: { code }, query: params }, options);
176
+ }
177
+ getCalendar(params, options) {
178
+ return this.transport.request({ method: 'GET', route: '/analysis/calendar', cache: 'default', query: params }, options);
179
+ }
180
+ getNews(params, options) {
181
+ return this.transport.request({ method: 'GET', route: '/analysis/news', cache: 'default', query: params }, options);
182
+ }
183
+ getDisclosure(params, options) {
184
+ return this.transport.request({ method: 'GET', route: '/analysis/disclosure', cache: 'default', query: params }, options);
185
+ }
186
+ }
187
+ class BatchResource {
188
+ transport;
189
+ constructor(transport) {
190
+ this.transport = transport;
191
+ }
192
+ getOrderBook(code, params, options) {
193
+ return this.transport.request({ method: 'GET', route: '/batch/order-book/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
194
+ }
195
+ getIntradayData(code, params, options) {
196
+ return this.transport.request({ method: 'GET', route: '/batch/intraday-data/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
197
+ }
198
+ getIntradayIndex(code, options) {
199
+ return this.transport.request({ method: 'GET', route: '/batch/intraday-index/{code}', cache: 'realtime', pathParams: { code } }, options);
200
+ }
201
+ }
202
+ class SearchResource {
203
+ transport;
204
+ constructor(transport) {
205
+ this.transport = transport;
206
+ }
207
+ search(params, options) {
208
+ return this.transport.request({ method: 'GET', route: '/search', cache: 'default', query: params }, options);
209
+ }
210
+ searchStock(params, options) {
211
+ return this.transport.request({ method: 'GET', route: '/search/stock', cache: 'default', query: params }, options);
212
+ }
213
+ searchUser(params, options) {
214
+ return this.transport.request({ method: 'GET', route: '/search/user', cache: 'default', query: params }, options);
215
+ }
216
+ }
217
+ class ScreenerResource {
218
+ transport;
219
+ constructor(transport) {
220
+ this.transport = transport;
221
+ }
222
+ screen(body, options) {
223
+ return this.transport.request({ method: 'POST', route: '/screener/screen', cache: 'none', body }, options);
224
+ }
225
+ list(options) {
226
+ return this.transport.request({ method: 'GET', route: '/screener', cache: 'default' }, options);
227
+ }
228
+ save(body, options) {
229
+ return this.transport.request({ method: 'POST', route: '/screener', cache: 'none', body }, options);
230
+ }
231
+ update(id, body, options) {
232
+ return this.transport.request({ method: 'PUT', route: '/screener/{id}', cache: 'none', pathParams: { id }, body }, options);
233
+ }
234
+ delete(id, options) {
235
+ return this.transport.request({ method: 'DELETE', route: '/screener/{id}', cache: 'none', pathParams: { id } }, options);
236
+ }
237
+ }
238
+ class UsageResource {
239
+ transport;
240
+ constructor(transport) {
241
+ this.transport = transport;
242
+ }
243
+ getApiUsage(options) {
244
+ return this.transport.request({ method: 'GET', route: '/usage/api', cache: 'none' }, options);
245
+ }
246
+ getLogs(params, options) {
247
+ return this.transport.request({ method: 'GET', route: '/usage/logs', cache: 'none', query: params }, options);
248
+ }
249
+ }
250
+ class WatchlistsResource {
251
+ transport;
252
+ constructor(transport) {
253
+ this.transport = transport;
254
+ }
255
+ list(params, options) {
256
+ return this.transport.request({ method: 'GET', route: '/watchlists', cache: 'default', query: params }, options);
257
+ }
258
+ add(body, options) {
259
+ return this.transport.request({ method: 'POST', route: '/watchlists', cache: 'none', body }, options);
260
+ }
261
+ delete(body, options) {
262
+ return this.transport.request({ method: 'DELETE', route: '/watchlists', cache: 'none', body }, options);
263
+ }
264
+ listGroups(options) {
265
+ return this.transport.request({ method: 'GET', route: '/watchlists/group', cache: 'default' }, options);
266
+ }
267
+ addGroup(body, options) {
268
+ return this.transport.request({ method: 'POST', route: '/watchlists/group', cache: 'none', body }, options);
269
+ }
270
+ updateGroup(id, body, options) {
271
+ return this.transport.request({ method: 'PUT', route: '/watchlists/group/{id}', cache: 'none', pathParams: { id }, body }, options);
272
+ }
273
+ deleteGroup(id, options) {
274
+ return this.transport.request({ method: 'DELETE', route: '/watchlists/group/{id}', cache: 'none', pathParams: { id } }, options);
275
+ }
276
+ update(id, body, options) {
277
+ return this.transport.request({ method: 'PUT', route: '/watchlists/{id}', cache: 'none', pathParams: { id }, body }, options);
278
+ }
279
+ updateNote(id, body, options) {
280
+ return this.transport.request({ method: 'PATCH', route: '/watchlists/{id}', cache: 'none', pathParams: { id }, body }, options);
281
+ }
282
+ }
283
+ class JournalsResource {
284
+ transport;
285
+ constructor(transport) {
286
+ this.transport = transport;
287
+ }
288
+ add(body, options) {
289
+ return this.transport.request({ method: 'POST', route: '/journals', cache: 'none', body }, options);
290
+ }
291
+ list(params, options) {
292
+ return this.transport.request({ method: 'GET', route: '/journals', cache: 'default', query: params }, options);
293
+ }
294
+ delete(body, options) {
295
+ return this.transport.request({ method: 'DELETE', route: '/journals', cache: 'none', body }, options);
296
+ }
297
+ getSummary(params, options) {
298
+ return this.transport.request({ method: 'GET', route: '/journals/summary', cache: 'default', query: params }, options);
299
+ }
300
+ }
301
+ class PortfoliosResource {
302
+ transport;
303
+ constructor(transport) {
304
+ this.transport = transport;
305
+ }
306
+ list(options) {
307
+ return this.transport.request({ method: 'GET', route: '/portfolios', cache: 'default' }, options);
308
+ }
309
+ getSummary(options) {
310
+ return this.transport.request({ method: 'GET', route: '/portfolios/summary', cache: 'default' }, options);
311
+ }
312
+ }
313
+ class AlertsResource {
314
+ transport;
315
+ constructor(transport) {
316
+ this.transport = transport;
317
+ }
318
+ create(body, options) {
319
+ return this.transport.request({ method: 'POST', route: '/alerts', cache: 'none', body }, options);
320
+ }
321
+ list(options) {
322
+ return this.transport.request({ method: 'GET', route: '/alerts', cache: 'default' }, options);
323
+ }
324
+ test(body, options) {
325
+ return this.transport.request({ method: 'POST', route: '/alerts/test', cache: 'none', body }, options);
326
+ }
327
+ update(id, body, options) {
328
+ return this.transport.request({ method: 'PUT', route: '/alerts/{id}', cache: 'none', pathParams: { id }, body }, options);
329
+ }
330
+ delete(id, options) {
331
+ return this.transport.request({ method: 'DELETE', route: '/alerts/{id}', cache: 'none', pathParams: { id } }, options);
332
+ }
333
+ }
334
+ class PostsResource {
335
+ transport;
336
+ constructor(transport) {
337
+ this.transport = transport;
338
+ }
339
+ list(params, options) {
340
+ return this.transport.request({ method: 'GET', route: '/posts', cache: 'default', query: params }, options);
341
+ }
342
+ listByCategory(category, params, options) {
343
+ return this.transport.request({ method: 'GET', route: '/posts/category/{category}', cache: 'default', pathParams: { category }, query: params }, options);
344
+ }
345
+ listByStock(code, params, options) {
346
+ return this.transport.request({ method: 'GET', route: '/posts/space/{code}', cache: 'default', pathParams: { code }, query: params }, options);
347
+ }
348
+ listByStockCategory(code, category, params, options) {
349
+ return this.transport.request({ method: 'GET', route: '/posts/space/category/{code}/{category}', cache: 'default', pathParams: { code, category }, query: params }, options);
350
+ }
351
+ get(id, options) {
352
+ return this.transport.request({ method: 'GET', route: '/posts/detail/{id}', cache: 'default', pathParams: { id } }, options);
353
+ }
354
+ getComments(id, params, options) {
355
+ return this.transport.request({ method: 'GET', route: '/posts/comment/{id}', cache: 'default', pathParams: { id }, query: params }, options);
356
+ }
357
+ getLikes(params, options) {
358
+ return this.transport.request({ method: 'GET', route: '/posts/like', cache: 'default', query: params }, options);
359
+ }
360
+ getFavorites(params, options) {
361
+ return this.transport.request({ method: 'GET', route: '/posts/favorite', cache: 'default', query: params }, options);
362
+ }
363
+ getVoters(id, options) {
364
+ return this.transport.request({ method: 'GET', route: '/posts/vote/{id}', cache: 'default', pathParams: { id } }, options);
365
+ }
366
+ }
367
+ class TradesResource {
368
+ transport;
369
+ constructor(transport) {
370
+ this.transport = transport;
371
+ }
372
+ list(params, options) {
373
+ return this.transport.request({ method: 'GET', route: '/trades', cache: 'default', query: params }, options);
374
+ }
375
+ delete(body, options) {
376
+ return this.transport.request({ method: 'DELETE', route: '/trades', cache: 'none', body }, options);
377
+ }
378
+ getSummary(params, options) {
379
+ return this.transport.request({ method: 'GET', route: '/trades/summary', cache: 'default', query: params }, options);
380
+ }
381
+ getSummaryChart(params, options) {
382
+ return this.transport.request({ method: 'GET', route: '/trades/summary-chart', cache: 'default', query: params }, options);
383
+ }
384
+ updateNote(id, body, options) {
385
+ return this.transport.request({ method: 'PATCH', route: '/trades/{id}', cache: 'none', pathParams: { id }, body }, options);
386
+ }
387
+ }
388
+ class InvezgoResources {
389
+ analysis;
390
+ batch;
391
+ search;
392
+ screener;
393
+ usage;
394
+ watchlists;
395
+ journals;
396
+ portfolios;
397
+ alerts;
398
+ posts;
399
+ trades;
400
+ constructor(transport) {
401
+ this.analysis = new AnalysisResource(transport);
402
+ this.batch = new BatchResource(transport);
403
+ this.search = new SearchResource(transport);
404
+ this.screener = new ScreenerResource(transport);
405
+ this.usage = new UsageResource(transport);
406
+ this.watchlists = new WatchlistsResource(transport);
407
+ this.journals = new JournalsResource(transport);
408
+ this.portfolios = new PortfoliosResource(transport);
409
+ this.alerts = new AlertsResource(transport);
410
+ this.posts = new PostsResource(transport);
411
+ this.trades = new TradesResource(transport);
412
+ }
413
+ }
414
+
415
+ const encoder = new TextEncoder();
416
+ class LruCache {
417
+ maxEntries;
418
+ maxBytes;
419
+ now;
420
+ map = new Map();
421
+ totalBytes = 0;
422
+ constructor(maxEntries, maxBytes, now = () => performance.now()) {
423
+ this.maxEntries = maxEntries;
424
+ this.maxBytes = maxBytes;
425
+ this.now = now;
426
+ }
427
+ get size() {
428
+ return this.map.size;
429
+ }
430
+ get bytes() {
431
+ return this.totalBytes;
432
+ }
433
+ get(key) {
434
+ const entry = this.map.get(key);
435
+ if (!entry)
436
+ return undefined;
437
+ this.map.delete(key);
438
+ if (entry.expiresAt <= this.now()) {
439
+ this.totalBytes -= entry.size;
440
+ return undefined;
441
+ }
442
+ this.map.set(key, entry);
443
+ return entry.body;
444
+ }
445
+ set(key, body, ttlMs) {
446
+ const size = encoder.encode(body).length;
447
+ this.delete(key);
448
+ if (ttlMs <= 0 || size > this.maxBytes || this.maxEntries <= 0)
449
+ return;
450
+ this.map.set(key, { body, size, expiresAt: this.now() + ttlMs });
451
+ this.totalBytes += size;
452
+ for (const [oldest, entry] of this.map) {
453
+ if (this.map.size <= this.maxEntries && this.totalBytes <= this.maxBytes)
454
+ break;
455
+ this.map.delete(oldest);
456
+ this.totalBytes -= entry.size;
457
+ }
458
+ }
459
+ delete(key) {
460
+ const entry = this.map.get(key);
461
+ if (entry) {
462
+ this.map.delete(key);
463
+ this.totalBytes -= entry.size;
464
+ }
465
+ }
466
+ deleteWhere(predicate) {
467
+ for (const key of [...this.map.keys()])
468
+ if (predicate(key))
469
+ this.delete(key);
470
+ }
471
+ clear() {
472
+ this.map.clear();
473
+ this.totalBytes = 0;
474
+ }
475
+ }
476
+
477
+ class InvezgoError extends Error {
478
+ status;
479
+ error;
480
+ requestId;
481
+ path;
482
+ body;
483
+ constructor(init) {
484
+ super(init.message, init.cause === undefined ? undefined : { cause: init.cause });
485
+ this.name = new.target.name;
486
+ this.status = init.status;
487
+ this.error = init.error;
488
+ this.requestId = init.requestId;
489
+ this.path = init.path;
490
+ this.body = init.body;
491
+ }
492
+ }
493
+ class ValidationError extends InvezgoError {
494
+ }
495
+ class AuthenticationError extends InvezgoError {
496
+ }
497
+ class PaymentRequiredError extends InvezgoError {
498
+ }
499
+ class NotFoundError extends InvezgoError {
500
+ }
501
+ class ServerError extends InvezgoError {
502
+ }
503
+ class RateLimitError extends InvezgoError {
504
+ retryAfter;
505
+ limit;
506
+ remaining;
507
+ reset;
508
+ quotaExceeded;
509
+ constructor(init) {
510
+ super(init);
511
+ this.retryAfter = init.retryAfter;
512
+ this.limit = init.limit;
513
+ this.remaining = init.remaining;
514
+ this.reset = init.reset;
515
+ this.quotaExceeded = init.quotaExceeded;
516
+ }
517
+ }
518
+ class ConnectionError extends InvezgoError {
519
+ }
520
+ class TimeoutError extends ConnectionError {
521
+ }
522
+ function errorClassFor(status) {
523
+ if (status === 400 || status === 422)
524
+ return ValidationError;
525
+ if (status === 401)
526
+ return AuthenticationError;
527
+ if (status === 402)
528
+ return PaymentRequiredError;
529
+ if (status === 404)
530
+ return NotFoundError;
531
+ if (status >= 500)
532
+ return ServerError;
533
+ return InvezgoError;
534
+ }
535
+
536
+ const VERSION = '2.0.0';
537
+ const DEFAULT_BASE_URL = 'https://api.invezgo.com';
538
+ const PERSONAL_SEGMENTS = new Set(['watchlists', 'journals', 'portfolios', 'trades', 'alerts', 'screener']);
539
+ const QUOTA_MESSAGE = /quota|kuota|monthly|bulanan/i;
540
+ class Transport {
541
+ keys;
542
+ baseUrl;
543
+ timeout;
544
+ fetchImpl;
545
+ cache;
546
+ ttlMs = 0;
547
+ realtimeTtlMs = 0;
548
+ blocks = new Map();
549
+ constructor(config) {
550
+ if (!config || typeof config.apiKey !== 'string' || !config.apiKey.trim()) {
551
+ throw new TypeError('Invezgo: `apiKey` is required');
552
+ }
553
+ this.keys = [...new Set([config.apiKey, ...(config.additionalApiKeys ?? [])].filter((k) => !!k && !!k.trim()))];
554
+ this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, '');
555
+ this.timeout = config.timeout ?? 30_000;
556
+ const f = config.fetch ?? globalThis.fetch;
557
+ if (typeof f !== 'function')
558
+ throw new TypeError('Invezgo: global fetch is unavailable; pass `fetch` in the config (Node >= 18)');
559
+ this.fetchImpl = f;
560
+ if (config.cache !== false) {
561
+ const o = config.cache === true || config.cache === undefined ? {} : config.cache;
562
+ this.cache = new LruCache(o.maxEntries ?? 1000, o.maxBytes ?? 32 * 1024 * 1024);
563
+ this.ttlMs = (o.ttl ?? 60) * 1000;
564
+ this.realtimeTtlMs = (o.realtimeTtl ?? 5) * 1000;
565
+ }
566
+ }
567
+ clearCache() {
568
+ this.cache?.clear();
569
+ }
570
+ async request(spec, options) {
571
+ const path = spec.route.replace(/\{(\w+)\}/g, (_, name) => {
572
+ const value = spec.pathParams?.[name];
573
+ if (value === undefined || value === null || value === '')
574
+ throw new TypeError(`Invezgo: path parameter \`${name}\` is required`);
575
+ return encodeURIComponent(String(value));
576
+ });
577
+ const qs = canonicalQuery(spec.query);
578
+ const target = qs ? `${path}?${qs}` : path;
579
+ const ttl = spec.method !== 'GET' ? 0 : spec.cache === 'realtime' ? this.realtimeTtlMs : spec.cache === 'default' ? this.ttlMs : 0;
580
+ if (this.cache && ttl > 0) {
581
+ const hit = this.cache.get(target);
582
+ if (hit !== undefined)
583
+ return parseBody(hit);
584
+ }
585
+ const tried = new Set();
586
+ let last;
587
+ for (;;) {
588
+ const index = this.pickKey(spec.route, tried);
589
+ if (index < 0)
590
+ throw this.allKeysBlocked(spec.route, last);
591
+ tried.add(index);
592
+ const res = await this.send(index, spec, target, options);
593
+ const text = await res.text();
594
+ if (res.status === 429) {
595
+ last = this.rateLimited(index, spec.route, res, text);
596
+ continue;
597
+ }
598
+ if (!res.ok)
599
+ throw buildError(res, text);
600
+ let data;
601
+ try {
602
+ data = parseBody(text);
603
+ }
604
+ catch (cause) {
605
+ throw new InvezgoError({ status: res.status, message: 'Invezgo: response is not valid JSON', body: text, path, cause });
606
+ }
607
+ if (this.cache) {
608
+ if (ttl > 0)
609
+ this.cache.set(target, text, ttl);
610
+ else if (spec.method !== 'GET')
611
+ this.cache.deleteWhere((key) => PERSONAL_SEGMENTS.has(key.split(/[/?]/)[1]));
612
+ }
613
+ return data;
614
+ }
615
+ }
616
+ async send(index, spec, target, options) {
617
+ const headers = {
618
+ Authorization: `Bearer ${this.keys[index]}`,
619
+ Accept: 'application/json',
620
+ 'User-Agent': `invezgo-js-sdk/${VERSION}`,
621
+ };
622
+ let body;
623
+ if (spec.body !== undefined) {
624
+ headers['Content-Type'] = 'application/json';
625
+ body = JSON.stringify(spec.body);
626
+ }
627
+ const controller = new AbortController();
628
+ let timedOut = false;
629
+ const timer = setTimeout(() => {
630
+ timedOut = true;
631
+ controller.abort();
632
+ }, this.timeout);
633
+ const signal = options?.signal;
634
+ const onAbort = () => controller.abort(signal?.reason);
635
+ if (signal?.aborted)
636
+ onAbort();
637
+ else
638
+ signal?.addEventListener('abort', onAbort, { once: true });
639
+ try {
640
+ return await this.fetchImpl(this.baseUrl + target, { method: spec.method, headers, body, signal: controller.signal });
641
+ }
642
+ catch (cause) {
643
+ if (signal?.aborted)
644
+ throw cause;
645
+ if (timedOut)
646
+ throw new TimeoutError({ status: 0, message: `Invezgo: request timed out after ${this.timeout} ms`, path: target, cause });
647
+ throw new ConnectionError({ status: 0, message: `Invezgo: network error: ${cause?.message ?? cause}`, path: target, cause });
648
+ }
649
+ finally {
650
+ clearTimeout(timer);
651
+ signal?.removeEventListener('abort', onAbort);
652
+ }
653
+ }
654
+ blockedFor(index, route, now) {
655
+ let ms = 0;
656
+ let quota = false;
657
+ for (const [id, isQuota] of [[`${index}`, true], [`${index} ${route}`, false]]) {
658
+ const b = this.blocks.get(id);
659
+ if (!b)
660
+ continue;
661
+ if (b.until <= now)
662
+ this.blocks.delete(id);
663
+ else if (b.until - now > ms) {
664
+ ms = b.until - now;
665
+ quota = isQuota;
666
+ }
667
+ }
668
+ return { ms, quota };
669
+ }
670
+ pickKey(route, tried) {
671
+ const now = performance.now();
672
+ for (let i = 0; i < this.keys.length; i++) {
673
+ if (!tried.has(i) && this.blockedFor(i, route, now).ms === 0)
674
+ return i;
675
+ }
676
+ return -1;
677
+ }
678
+ rateLimited(index, route, res, text) {
679
+ const err = buildError(res, text);
680
+ const retryAfter = num(res.headers.get('retry-after'));
681
+ const reset = num(res.headers.get('x-ratelimit-reset'));
682
+ let wait = 60;
683
+ if (retryAfter !== undefined && retryAfter > 0)
684
+ wait = retryAfter;
685
+ else if (reset !== undefined && reset - Date.now() / 1000 > 0)
686
+ wait = reset - Date.now() / 1000;
687
+ const quota = QUOTA_MESSAGE.test(err.message);
688
+ this.blocks.set(quota ? `${index}` : `${index} ${route}`, { until: performance.now() + wait * 1000, quota });
689
+ return new RateLimitError({
690
+ status: 429,
691
+ message: err.message,
692
+ error: err.error,
693
+ requestId: err.requestId,
694
+ path: err.path,
695
+ body: err.body,
696
+ retryAfter: Math.ceil(wait),
697
+ limit: num(res.headers.get('x-ratelimit-limit')),
698
+ remaining: num(res.headers.get('x-ratelimit-remaining')),
699
+ reset,
700
+ quotaExceeded: quota,
701
+ });
702
+ }
703
+ allKeysBlocked(route, last) {
704
+ const now = performance.now();
705
+ let min = Infinity;
706
+ let allQuota = true;
707
+ for (let i = 0; i < this.keys.length; i++) {
708
+ const b = this.blockedFor(i, route, now);
709
+ min = Math.min(min, b.ms);
710
+ allQuota &&= b.quota;
711
+ }
712
+ const retryAfter = Math.max(0, Math.ceil((Number.isFinite(min) ? min : 0) / 1000));
713
+ if (last) {
714
+ return new RateLimitError({ ...last, message: last.message, retryAfter, quotaExceeded: last.quotaExceeded });
715
+ }
716
+ return new RateLimitError({
717
+ status: 429,
718
+ message: `Invezgo: all API keys are rate limited; retry in ${retryAfter}s`,
719
+ retryAfter,
720
+ quotaExceeded: allQuota,
721
+ });
722
+ }
723
+ }
724
+ function canonicalQuery(query) {
725
+ if (!query)
726
+ return '';
727
+ const entries = Object.entries(query)
728
+ .filter(([, v]) => v !== undefined && v !== null)
729
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
730
+ .map(([k, v]) => [k, String(v)]);
731
+ return new URLSearchParams(entries).toString();
732
+ }
733
+ function parseBody(text) {
734
+ return text.trim() === '' ? null : JSON.parse(text);
735
+ }
736
+ function num(value) {
737
+ if (value === null || value.trim() === '')
738
+ return undefined;
739
+ const n = Number(value);
740
+ return Number.isFinite(n) ? n : undefined;
741
+ }
742
+ function buildError(res, text) {
743
+ let body = text;
744
+ try {
745
+ body = text ? JSON.parse(text) : undefined;
746
+ }
747
+ catch {
748
+ }
749
+ const b = (typeof body === 'object' && body !== null ? body : {});
750
+ const msg = Array.isArray(b.message) ? b.message.join('; ') : typeof b.message === 'string' ? b.message : '';
751
+ const Cls = errorClassFor(res.status);
752
+ return new Cls({
753
+ status: res.status,
754
+ message: msg || res.statusText || `HTTP ${res.status}`,
755
+ error: typeof b.error === 'string' ? b.error : undefined,
756
+ requestId: typeof b.requestId === 'string' ? b.requestId : (res.headers.get('request-id') ?? undefined),
757
+ path: typeof b.path === 'string' ? b.path : undefined,
758
+ body,
759
+ });
760
+ }
761
+
762
+ class Invezgo extends InvezgoResources {
763
+ #transport;
764
+ constructor(config) {
765
+ const transport = new Transport(config);
766
+ super(transport);
767
+ this.#transport = transport;
768
+ }
769
+ clearCache() {
770
+ this.#transport.clearCache();
771
+ }
772
+ }
773
+
774
+ export { AlertsResource, AnalysisResource, AuthenticationError, BatchResource, ConnectionError, DEFAULT_BASE_URL, Invezgo, Invezgo as InvezgoClient, InvezgoError, InvezgoResources, JournalsResource, NotFoundError, PaymentRequiredError, PortfoliosResource, PostsResource, RateLimitError, ScreenerResource, SearchResource, ServerError, TimeoutError, TradesResource, UsageResource, VERSION, ValidationError, WatchlistsResource, Invezgo as default };
775
+ //# sourceMappingURL=index.mjs.map