@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.js CHANGED
@@ -1,1054 +1,804 @@
1
- class InvezgoError extends Error {
2
- constructor(statusCode, message, error, response) {
3
- super(message);
4
- this.statusCode = statusCode;
5
- this.message = message;
6
- this.error = error;
7
- this.response = response;
8
- this.name = 'InvezgoError';
9
- Object.setPrototypeOf(this, InvezgoError.prototype);
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ class AnalysisResource {
6
+ transport;
7
+ constructor(transport) {
8
+ this.transport = transport;
10
9
  }
11
- }
12
- class HttpClient {
13
- constructor(config) {
14
- // Ensure baseURL doesn't have trailing slash since paths start with /
15
- const baseURL = config.baseURL || 'https://api.invezgo.com';
16
- this.baseURL = baseURL.endsWith('/') ? baseURL.slice(0, -1) : baseURL;
17
- this.apiKey = config.apiKey;
18
- this.timeout = config.timeout || 30000;
19
- if (!this.apiKey) {
20
- throw new Error('API Key is required');
21
- }
10
+ getStockList(options) {
11
+ return this.transport.request({ method: 'GET', route: '/analysis/list/stock', cache: 'default' }, options);
22
12
  }
23
- async request(method, path, options = {}) {
24
- const url = `${this.baseURL}${path}`;
25
- const controller = new AbortController();
26
- const timeoutId = setTimeout(() => controller.abort(), options.timeout || this.timeout);
27
- try {
28
- const headers = {
29
- 'Authorization': `Bearer ${this.apiKey}`,
30
- 'Content-Type': 'application/json',
31
- ...options.headers,
32
- };
33
- const response = await fetch(url, {
34
- method,
35
- headers,
36
- signal: controller.signal,
37
- });
38
- clearTimeout(timeoutId);
39
- // Handle 204 No Content
40
- if (response.status === 204) {
41
- return [];
42
- }
43
- const data = await response.json().catch(() => ({}));
44
- // Handle error responses
45
- if (!response.ok) {
46
- throw new InvezgoError(response.status, data?.message || response.statusText, data?.error, data);
47
- }
48
- return data;
49
- }
50
- catch (error) {
51
- clearTimeout(timeoutId);
52
- if (error.name === 'AbortError') {
53
- throw new InvezgoError(408, 'Request timeout', 'Timeout');
54
- }
55
- if (error instanceof InvezgoError) {
56
- throw error;
57
- }
58
- throw new InvezgoError(500, error.message || 'Unknown error occurred', 'InternalError', error);
59
- }
13
+ getBrokerList(options) {
14
+ return this.transport.request({ method: 'GET', route: '/analysis/list/broker', cache: 'default' }, options);
60
15
  }
61
- async get(path, params, options) {
62
- let url = path;
63
- if (params && Object.keys(params).length > 0) {
64
- const searchParams = new URLSearchParams();
65
- Object.entries(params).forEach(([key, value]) => {
66
- if (value !== undefined && value !== null) {
67
- if (Array.isArray(value)) {
68
- value.forEach(v => searchParams.append(key, String(v)));
69
- }
70
- else {
71
- searchParams.append(key, String(value));
72
- }
73
- }
74
- });
75
- url = `${path}?${searchParams.toString()}`;
76
- }
77
- return this.request('GET', url, options);
78
- }
79
- async post(path, body, options) {
80
- const requestOptions = {
81
- ...options,
82
- headers: {
83
- ...options?.headers,
84
- },
85
- };
86
- const controller = new AbortController();
87
- const timeoutId = setTimeout(() => controller.abort(), requestOptions.timeout || this.timeout);
88
- try {
89
- const url = `${this.baseURL}${path}`;
90
- const headers = {
91
- 'Authorization': `Bearer ${this.apiKey}`,
92
- 'Content-Type': 'application/json',
93
- ...requestOptions.headers,
94
- };
95
- const response = await fetch(url, {
96
- method: 'POST',
97
- headers,
98
- body: body ? JSON.stringify(body) : undefined,
99
- signal: controller.signal,
100
- });
101
- clearTimeout(timeoutId);
102
- if (response.status === 204) {
103
- return {};
104
- }
105
- const data = await response.json().catch(() => ({}));
106
- if (!response.ok) {
107
- throw new InvezgoError(response.status, data?.message || response.statusText, data?.error, data);
108
- }
109
- return data;
110
- }
111
- catch (error) {
112
- clearTimeout(timeoutId);
113
- if (error.name === 'AbortError') {
114
- throw new InvezgoError(408, 'Request timeout', 'Timeout');
115
- }
116
- if (error instanceof InvezgoError) {
117
- throw error;
118
- }
119
- throw new InvezgoError(500, error.message || 'Unknown error occurred', 'InternalError', error);
120
- }
16
+ getIndexList(options) {
17
+ return this.transport.request({ method: 'GET', route: '/analysis/list/index', cache: 'default' }, options);
121
18
  }
122
- async put(path, body, options) {
123
- const controller = new AbortController();
124
- const timeoutId = setTimeout(() => controller.abort(), options?.timeout || this.timeout);
125
- try {
126
- const url = `${this.baseURL}${path}`;
127
- const headers = {
128
- 'Authorization': `Bearer ${this.apiKey}`,
129
- 'Content-Type': 'application/json',
130
- ...options?.headers,
131
- };
132
- const response = await fetch(url, {
133
- method: 'PUT',
134
- headers,
135
- body: body ? JSON.stringify(body) : undefined,
136
- signal: controller.signal,
137
- });
138
- clearTimeout(timeoutId);
139
- if (response.status === 204) {
140
- return {};
141
- }
142
- const data = await response.json().catch(() => ({}));
143
- if (!response.ok) {
144
- throw new InvezgoError(response.status, data?.message || response.statusText, data?.error, data);
145
- }
146
- return data;
147
- }
148
- catch (error) {
149
- clearTimeout(timeoutId);
150
- if (error.name === 'AbortError') {
151
- throw new InvezgoError(408, 'Request timeout', 'Timeout');
152
- }
153
- if (error instanceof InvezgoError) {
154
- throw error;
155
- }
156
- throw new InvezgoError(500, error.message || 'Unknown error occurred', 'InternalError', error);
157
- }
19
+ getUma(params, options) {
20
+ return this.transport.request({ method: 'GET', route: '/analysis/uma', cache: 'default', query: params }, options);
158
21
  }
159
- async patch(path, body, options) {
160
- const controller = new AbortController();
161
- const timeoutId = setTimeout(() => controller.abort(), options?.timeout || this.timeout);
162
- try {
163
- const url = `${this.baseURL}${path}`;
164
- const headers = {
165
- 'Authorization': `Bearer ${this.apiKey}`,
166
- 'Content-Type': 'application/json',
167
- ...options?.headers,
168
- };
169
- const response = await fetch(url, {
170
- method: 'PATCH',
171
- headers,
172
- body: body ? JSON.stringify(body) : undefined,
173
- signal: controller.signal,
174
- });
175
- clearTimeout(timeoutId);
176
- if (response.status === 204) {
177
- return {};
178
- }
179
- const data = await response.json().catch(() => ({}));
180
- if (!response.ok) {
181
- throw new InvezgoError(response.status, data?.message || response.statusText, data?.error, data);
182
- }
183
- return data;
184
- }
185
- catch (error) {
186
- clearTimeout(timeoutId);
187
- if (error.name === 'AbortError') {
188
- throw new InvezgoError(408, 'Request timeout', 'Timeout');
189
- }
190
- if (error instanceof InvezgoError) {
191
- throw error;
192
- }
193
- throw new InvezgoError(500, error.message || 'Unknown error occurred', 'InternalError', error);
194
- }
22
+ getSuspend(params, options) {
23
+ return this.transport.request({ method: 'GET', route: '/analysis/suspend', cache: 'default', query: params }, options);
195
24
  }
196
- async delete(path, params, options) {
197
- let url = path;
198
- if (params && Object.keys(params).length > 0) {
199
- const searchParams = new URLSearchParams();
200
- Object.entries(params).forEach(([key, value]) => {
201
- if (value !== undefined && value !== null) {
202
- if (Array.isArray(value)) {
203
- value.forEach(v => searchParams.append(key, String(v)));
204
- }
205
- else {
206
- searchParams.append(key, String(value));
207
- }
208
- }
209
- });
210
- url = `${path}?${searchParams.toString()}`;
211
- }
212
- return this.request('DELETE', url, options);
25
+ getNotation(options) {
26
+ return this.transport.request({ method: 'GET', route: '/analysis/notation', cache: 'default' }, options);
27
+ }
28
+ getInformation(code, options) {
29
+ return this.transport.request({ method: 'GET', route: '/analysis/information/{code}', cache: 'default', pathParams: { code } }, options);
30
+ }
31
+ getTopChange(params, options) {
32
+ return this.transport.request({ method: 'GET', route: '/analysis/top/change', cache: 'default', query: params }, options);
33
+ }
34
+ getTopForeign(params, options) {
35
+ return this.transport.request({ method: 'GET', route: '/analysis/top/foreign', cache: 'default', query: params }, options);
36
+ }
37
+ getTopAccumulation(params, options) {
38
+ return this.transport.request({ method: 'GET', route: '/analysis/top/accumulation', cache: 'default', query: params }, options);
39
+ }
40
+ getTopRitel(params, options) {
41
+ return this.transport.request({ method: 'GET', route: '/analysis/top/ritel', cache: 'default', query: params }, options);
42
+ }
43
+ getStockRunningTrade(code, params, options) {
44
+ return this.transport.request({ method: 'GET', route: '/analysis/running-trade/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
45
+ }
46
+ getIntradayChart(code, params, options) {
47
+ return this.transport.request({ method: 'GET', route: '/analysis/intraday/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
48
+ }
49
+ getOrderBook(code, params, options) {
50
+ return this.transport.request({ method: 'GET', route: '/analysis/order-book/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
51
+ }
52
+ getOrderQueue(code, params, options) {
53
+ return this.transport.request({ method: 'GET', route: '/analysis/queue/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
54
+ }
55
+ getIntradayData(code, params, options) {
56
+ return this.transport.request({ method: 'GET', route: '/analysis/intraday-data/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
57
+ }
58
+ getIntradayIndex(code, options) {
59
+ return this.transport.request({ method: 'GET', route: '/analysis/intraday-index/{code}', cache: 'realtime', pathParams: { code } }, options);
60
+ }
61
+ getAdvanceChart(code, params, options) {
62
+ return this.transport.request({ method: 'GET', route: '/analysis/chart/stock/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
63
+ }
64
+ getIndexChart(code, params, options) {
65
+ return this.transport.request({ method: 'GET', route: '/analysis/chart/index/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
66
+ }
67
+ getMultiTimeChart(code, params, options) {
68
+ return this.transport.request({ method: 'GET', route: '/analysis/chart/multi-time/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
69
+ }
70
+ getIndicatorChart(indicator, code, params, options) {
71
+ return this.transport.request({ method: 'GET', route: '/analysis/chart/stock/{indicator}/{code}', cache: 'default', pathParams: { indicator, code }, query: params }, options);
72
+ }
73
+ getShareholderDetail(params, options) {
74
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder-detail', cache: 'default', query: params }, options);
75
+ }
76
+ getShareholderOneDetail(params, options) {
77
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder-detail-one', cache: 'default', query: params }, options);
78
+ }
79
+ getShareholderHigh(options) {
80
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder/high', cache: 'default' }, options);
81
+ }
82
+ getShareholderNumber(code, options) {
83
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder/number/{code}', cache: 'default', pathParams: { code } }, options);
84
+ }
85
+ getShareholderRelation(params, options) {
86
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder/relation', cache: 'default', query: params }, options);
87
+ }
88
+ getShareholder(code, options) {
89
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder/{code}', cache: 'default', pathParams: { code } }, options);
90
+ }
91
+ getShareholderKSEI(code, params, options) {
92
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder/ksei/{code}', cache: 'default', pathParams: { code }, query: params }, options);
93
+ }
94
+ getShareholderClassification(code, params, options) {
95
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder/classification/{code}', cache: 'default', pathParams: { code }, query: params }, options);
96
+ }
97
+ getShareholderClassifyTable(code, options) {
98
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder/classify-table/{code}', cache: 'default', pathParams: { code } }, options);
99
+ }
100
+ getSummaryStock(code, params, options) {
101
+ return this.transport.request({ method: 'GET', route: '/analysis/summary/stock/{code}', cache: 'default', pathParams: { code }, query: params }, options);
102
+ }
103
+ getSummaryBroker(code, params, options) {
104
+ return this.transport.request({ method: 'GET', route: '/analysis/summary/broker/{code}', cache: 'default', pathParams: { code }, query: params }, options);
105
+ }
106
+ getSectorStalker(params, options) {
107
+ return this.transport.request({ method: 'GET', route: '/analysis/stalker/sector', cache: 'realtime', query: params }, options);
108
+ }
109
+ getSectorRotation(params, options) {
110
+ return this.transport.request({ method: 'GET', route: '/analysis/sector/rotation', cache: 'realtime', query: params }, options);
111
+ }
112
+ getBrokerStalker(broker, stock, params, options) {
113
+ return this.transport.request({ method: 'GET', route: '/analysis/stalker/broker/{broker}/{stock}', cache: 'default', pathParams: { broker, stock }, query: params }, options);
114
+ }
115
+ getBrokerStalkerList(code, params, options) {
116
+ return this.transport.request({ method: 'GET', route: '/analysis/stalker/list/{code}', cache: 'default', pathParams: { code }, query: params }, options);
117
+ }
118
+ getSummaryStockChart(code, params, options) {
119
+ return this.transport.request({ method: 'GET', route: '/analysis/summary-chart/stock/{code}', cache: 'default', pathParams: { code }, query: params }, options);
120
+ }
121
+ getSummaryBrokerChart(code, params, options) {
122
+ return this.transport.request({ method: 'GET', route: '/analysis/summary-chart/broker/{code}', cache: 'default', pathParams: { code }, query: params }, options);
123
+ }
124
+ getInventoryStockChart(code, params, options) {
125
+ return this.transport.request({ method: 'GET', route: '/analysis/inventory-chart/stock/{code}', cache: 'default', pathParams: { code }, query: params }, options);
126
+ }
127
+ getInventoryBrokerChart(code, params, options) {
128
+ return this.transport.request({ method: 'GET', route: '/analysis/inventory-chart/broker/{code}', cache: 'default', pathParams: { code }, query: params }, options);
129
+ }
130
+ getMomentumChart(code, params, options) {
131
+ return this.transport.request({ method: 'GET', route: '/analysis/momentum-chart/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
132
+ }
133
+ getIntradayInventoryChart(code, params, options) {
134
+ return this.transport.request({ method: 'GET', route: '/analysis/intraday-inventory-chart/{code}', cache: 'default', pathParams: { code }, query: params }, options);
135
+ }
136
+ getSankeyChart(code, params, options) {
137
+ return this.transport.request({ method: 'GET', route: '/analysis/sankey-chart/{code}', cache: 'default', pathParams: { code }, query: params }, options);
138
+ }
139
+ getPriceTable(code, params, options) {
140
+ return this.transport.request({ method: 'GET', route: '/analysis/price-table/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
141
+ }
142
+ getTimeTable(code, params, options) {
143
+ return this.transport.request({ method: 'GET', route: '/analysis/time-table/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
144
+ }
145
+ getPriceDiary(code, options) {
146
+ return this.transport.request({ method: 'GET', route: '/analysis/price-diary/{code}', cache: 'default', pathParams: { code } }, options);
147
+ }
148
+ getPriceSeasonality(code, params, options) {
149
+ return this.transport.request({ method: 'GET', route: '/analysis/price-seasonality/{code}', cache: 'default', pathParams: { code }, query: params }, options);
150
+ }
151
+ getShareholderAbove(params, options) {
152
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder-above', cache: 'default', query: params }, options);
153
+ }
154
+ getShareholderAboveChart(code, params, options) {
155
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder-above-chart/{code}', cache: 'default', pathParams: { code }, query: params }, options);
156
+ }
157
+ getShareholderOne(params, options) {
158
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder-one', cache: 'default', query: params }, options);
159
+ }
160
+ getShareholderOneChart(code, params, options) {
161
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder-one-chart/{code}', cache: 'default', pathParams: { code }, query: params }, options);
162
+ }
163
+ getInsider(params, options) {
164
+ return this.transport.request({ method: 'GET', route: '/analysis/shareholder-insider', cache: 'default', query: params }, options);
165
+ }
166
+ getInsiderChart(code, params, options) {
167
+ return this.transport.request({ method: 'GET', route: '/analysis/insider-chart/{code}', cache: 'default', pathParams: { code }, query: params }, options);
168
+ }
169
+ getFinancialStatement(code, params, options) {
170
+ return this.transport.request({ method: 'GET', route: '/analysis/financial-statement/{code}', cache: 'default', pathParams: { code }, query: params }, options);
171
+ }
172
+ getFinancialStatementChart(code, params, options) {
173
+ return this.transport.request({ method: 'GET', route: '/analysis/financial-statement-chart/{code}', cache: 'default', pathParams: { code }, query: params }, options);
174
+ }
175
+ getKeystat(code, params, options) {
176
+ return this.transport.request({ method: 'GET', route: '/analysis/keystat/{code}', cache: 'default', pathParams: { code }, query: params }, options);
177
+ }
178
+ getKeystatChart(code, params, options) {
179
+ return this.transport.request({ method: 'GET', route: '/analysis/keystat-chart/{code}', cache: 'default', pathParams: { code }, query: params }, options);
180
+ }
181
+ getCalendar(params, options) {
182
+ return this.transport.request({ method: 'GET', route: '/analysis/calendar', cache: 'default', query: params }, options);
183
+ }
184
+ getNews(params, options) {
185
+ return this.transport.request({ method: 'GET', route: '/analysis/news', cache: 'default', query: params }, options);
186
+ }
187
+ getDisclosure(params, options) {
188
+ return this.transport.request({ method: 'GET', route: '/analysis/disclosure', cache: 'default', query: params }, options);
213
189
  }
214
190
  }
215
-
216
- class AlertsEndpoints {
217
- constructor(client) {
218
- this.client = client;
219
- }
220
- /**
221
- * Get list of alerts.
222
- */
223
- async list() {
224
- return this.client.get('/alerts');
225
- }
226
- /**
227
- * Create alert.
228
- */
229
- async add(dto) {
230
- return this.client.post('/alerts', dto);
231
- }
232
- /**
233
- * Update alert.
234
- */
235
- async update(id, dto) {
236
- return this.client.put(`/alerts/${id}`, dto);
237
- }
238
- /**
239
- * Delete alert.
240
- */
241
- async delete(id) {
242
- return this.client.delete(`/alerts/${id}`);
243
- }
244
- /**
245
- * Test alert formula.
246
- */
247
- async test(dto) {
248
- return this.client.post('/alerts/test', dto);
191
+ class BatchResource {
192
+ transport;
193
+ constructor(transport) {
194
+ this.transport = transport;
195
+ }
196
+ getOrderBook(code, params, options) {
197
+ return this.transport.request({ method: 'GET', route: '/batch/order-book/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
198
+ }
199
+ getIntradayData(code, params, options) {
200
+ return this.transport.request({ method: 'GET', route: '/batch/intraday-data/{code}', cache: 'realtime', pathParams: { code }, query: params }, options);
201
+ }
202
+ getIntradayIndex(code, options) {
203
+ return this.transport.request({ method: 'GET', route: '/batch/intraday-index/{code}', cache: 'realtime', pathParams: { code } }, options);
249
204
  }
250
205
  }
251
-
252
- class AnalysisEndpoints {
253
- constructor(client) {
254
- this.client = client;
255
- }
256
- /**
257
- * Get list of all stocks listed on BEI.
258
- */
259
- async getStockList() {
260
- return this.client.get('/analysis/list/stock');
261
- }
262
- /**
263
- * Get list of all brokers/securities on BEI.
264
- */
265
- async getBrokerList() {
266
- return this.client.get('/analysis/list/broker');
267
- }
268
- /**
269
- * Get list of all supported IDX indexes.
270
- */
271
- async getIndexList() {
272
- return this.client.get('/analysis/list/index');
273
- }
274
- /**
275
- * Get complete company information.
276
- */
277
- async getInformation(code) {
278
- return this.client.get(`/analysis/information/${code}`);
279
- }
280
- /**
281
- * Get top gainer and loser stocks for a specific date.
282
- */
283
- async getTopChange(date) {
284
- return this.client.get('/analysis/top/change', { date });
285
- }
286
- /**
287
- * Get top foreign accumulation and distribution.
288
- */
289
- async getTopForeign(date) {
290
- return this.client.get('/analysis/top/foreign', { date });
291
- }
292
- /**
293
- * Get top bandarmology accumulation and distribution.
294
- */
295
- async getTopAccumulation(date) {
296
- return this.client.get('/analysis/top/accumulation', { date });
297
- }
298
- /**
299
- * Get top retail accumulation and distribution.
300
- */
301
- async getTopRitel(date) {
302
- return this.client.get('/analysis/top/ritel', { date });
303
- }
304
- /**
305
- * Alias for getTopRitel.
306
- */
307
- async getTopRetail(date) {
308
- return this.getTopRitel(date);
309
- }
310
- /**
311
- * Get intraday chart data.
312
- */
313
- async getIntradayChart(code, market = 'RG') {
314
- return this.client.get(`/analysis/intraday/${code}`, { market });
315
- }
316
- /**
317
- * Get intraday stock summary data.
318
- */
319
- async getIntradayData(code, market = 'RG') {
320
- return this.client.get(`/analysis/intraday-data/${code}`, { market });
321
- }
322
- /**
323
- * Get intraday index summary data.
324
- */
325
- async getIntradayIndex(code, market = 'RG') {
326
- return this.client.get(`/analysis/intraday-index/${code}`, { market });
327
- }
328
- /**
329
- * Get order book data.
330
- */
331
- async getOrderBook(code, market = 'RG') {
332
- return this.client.get(`/analysis/order-book/${code}`, { market });
333
- }
334
- /**
335
- * Get complete stock chart data.
336
- */
337
- async getChart(code, params) {
338
- return this.client.get(`/analysis/chart/stock/${code}`, params);
339
- }
340
- /**
341
- * Get historical index chart data.
342
- */
343
- async getIndexChart(code, params) {
344
- return this.client.get(`/analysis/chart/index/${code}`, params);
345
- }
346
- /**
347
- * Get stock chart with technical indicator.
348
- */
349
- async getIndicatorChart(code, indicator, params) {
350
- return this.client.get(`/analysis/chart/stock/${indicator}/${code}`, params);
351
- }
352
- /**
353
- * Get shareholder detail above 5%.
354
- */
355
- async getShareholderDetail(code) {
356
- return this.client.get(`/analysis/shareholder-detail/${code}`);
357
- }
358
- /**
359
- * Get shareholder detail above 1% for a specific holder.
360
- */
361
- async getShareholderDetailOne(params) {
362
- return this.client.get('/analysis/shareholder-detail-one', params);
363
- }
364
- /**
365
- * Get number of shareholders.
366
- */
367
- async getShareholderNumber(code) {
368
- return this.client.get(`/analysis/shareholder/number/${code}`);
369
- }
370
- /**
371
- * Get shareholder relation graph.
372
- */
373
- async getShareholderRelation(params) {
374
- return this.client.get('/analysis/shareholder/relation', params);
375
- }
376
- /**
377
- * Get shareholder composition.
378
- */
379
- async getShareholder(code) {
380
- return this.client.get(`/analysis/shareholder/${code}`);
381
- }
382
- /**
383
- * Get KSEI shareholder data.
384
- */
385
- async getShareholderKSEI(code, range) {
386
- return this.client.get(`/analysis/shareholder/ksei/${code}`, {
387
- range: Math.min(range, 12),
388
- });
206
+ class SearchResource {
207
+ transport;
208
+ constructor(transport) {
209
+ this.transport = transport;
389
210
  }
390
- /**
391
- * Get broker summary for a stock.
392
- */
393
- async getBrokerSummaryStock(code, params) {
394
- return this.client.get(`/analysis/summary/stock/${code}`, params);
395
- }
396
- /**
397
- * Get broker summary for a broker.
398
- */
399
- async getBrokerSummaryBroker(code, params) {
400
- return this.client.get(`/analysis/summary/broker/${code}`, params);
401
- }
402
- /**
403
- * Get sector stalker data.
404
- */
405
- async getStalkerSector(params) {
406
- return this.client.get('/analysis/stalker/sector', params);
407
- }
408
- /**
409
- * Get sector rotation chart.
410
- */
411
- async getSectorRotation(params) {
412
- return this.client.get('/analysis/sector/rotation', params);
413
- }
414
- /**
415
- * Get broker stalker data for a stock.
416
- */
417
- async getBrokerStalker(broker, stock, params) {
418
- return this.client.get(`/analysis/stalker/broker/${broker}/${stock}`, params);
419
- }
420
- /**
421
- * Get broker stalker list.
422
- */
423
- async getBrokerStalkerList(code, params) {
424
- return this.client.get(`/analysis/stalker/list/${code}`, params);
425
- }
426
- /**
427
- * Get broker summary chart for a stock.
428
- */
429
- async getBrokerSummaryChartStock(code, params) {
430
- return this.client.get(`/analysis/summary-chart/stock/${code}`, params);
431
- }
432
- /**
433
- * Get broker summary chart for a broker.
434
- */
435
- async getBrokerSummaryChartBroker(code, params) {
436
- return this.client.get(`/analysis/summary-chart/broker/${code}`, params);
437
- }
438
- /**
439
- * Get inventory chart for a stock.
440
- */
441
- async getInventoryChartStock(code, params) {
442
- return this.client.get(`/analysis/inventory-chart/stock/${code}`, params);
443
- }
444
- /**
445
- * Get inventory chart for a broker.
446
- */
447
- async getInventoryChartBroker(code, params) {
448
- return this.client.get(`/analysis/inventory-chart/broker/${code}`, params);
449
- }
450
- /**
451
- * Get momentum chart.
452
- */
453
- async getMomentumChart(code, params) {
454
- return this.client.get(`/analysis/momentum-chart/${code}`, params);
455
- }
456
- /**
457
- * Get intraday inventory chart.
458
- */
459
- async getIntradayInventoryChart(code, params) {
460
- return this.client.get(`/analysis/intraday-inventory-chart/${code}`, params);
461
- }
462
- /**
463
- * Get distribution or crossing chart.
464
- */
465
- async getSankeyChart(code, params) {
466
- return this.client.get(`/analysis/sankey-chart/${code}`, params);
467
- }
468
- /**
469
- * Get price table.
470
- */
471
- async getPriceTable(code, date) {
472
- return this.client.get(`/analysis/price-table/${code}`, { date });
473
- }
474
- /**
475
- * Get time table.
476
- */
477
- async getTimeTable(code, params) {
478
- return this.client.get(`/analysis/time-table/${code}`, params);
479
- }
480
- /**
481
- * Get price diary.
482
- */
483
- async getPriceDiary(code) {
484
- return this.client.get(`/analysis/price-diary/${code}`);
485
- }
486
- /**
487
- * Get price seasonality.
488
- */
489
- async getPriceSeasonality(code, range) {
490
- return this.client.get(`/analysis/price-seasonality/${code}`, {
491
- range: Math.min(range, 60),
492
- });
211
+ search(params, options) {
212
+ return this.transport.request({ method: 'GET', route: '/search', cache: 'default', query: params }, options);
493
213
  }
494
- /**
495
- * Get shareholders above 5%.
496
- */
497
- async getShareholderAbove(params) {
498
- return this.client.get('/analysis/shareholder-above', params);
499
- }
500
- /**
501
- * Get shareholder above 5% chart.
502
- */
503
- async getShareholderAboveChart(code, params) {
504
- return this.client.get(`/analysis/shareholder-above-chart/${code}`, params);
505
- }
506
- /**
507
- * Get shareholders above 1%.
508
- */
509
- async getShareholderOne(params) {
510
- return this.client.get('/analysis/shareholder-one', params);
511
- }
512
- /**
513
- * Get shareholder above 1% chart.
514
- */
515
- async getShareholderOneChart(code, params) {
516
- return this.client.get(`/analysis/shareholder-one-chart/${code}`, params);
517
- }
518
- /**
519
- * Get insider trading data.
520
- */
521
- async getInsiderTrading(params) {
522
- return this.client.get('/analysis/shareholder-insider', params);
523
- }
524
- /**
525
- * Get insider chart.
526
- */
527
- async getInsiderChart(code, params) {
528
- return this.client.get(`/analysis/insider-chart/${code}`, params);
529
- }
530
- /**
531
- * Get financial statement.
532
- */
533
- async getFinancialStatement(code, params) {
534
- return this.client.get(`/analysis/financial-statement/${code}`, { ...params, limit: Math.min(params.limit, 20) });
535
- }
536
- /**
537
- * Get financial statement chart.
538
- */
539
- async getFinancialStatementChart(code, params) {
540
- return this.client.get(`/analysis/financial-statement-chart/${code}`, { ...params, limit: Math.min(params.limit, 20) });
541
- }
542
- /**
543
- * Get key statistics.
544
- */
545
- async getKeyStat(code, params) {
546
- return this.client.get(`/analysis/keystat/${code}`, {
547
- ...params,
548
- limit: Math.min(params.limit, 20),
549
- });
214
+ searchStock(params, options) {
215
+ return this.transport.request({ method: 'GET', route: '/search/stock', cache: 'default', query: params }, options);
550
216
  }
551
- /**
552
- * Get key statistics chart.
553
- */
554
- async getKeyStatChart(code, params) {
555
- return this.client.get(`/analysis/keystat-chart/${code}`, {
556
- ...params,
557
- limit: Math.min(params.limit, 20),
558
- });
217
+ searchUser(params, options) {
218
+ return this.transport.request({ method: 'GET', route: '/search/user', cache: 'default', query: params }, options);
219
+ }
220
+ }
221
+ class ScreenerResource {
222
+ transport;
223
+ constructor(transport) {
224
+ this.transport = transport;
225
+ }
226
+ screen(body, options) {
227
+ return this.transport.request({ method: 'POST', route: '/screener/screen', cache: 'none', body }, options);
228
+ }
229
+ list(options) {
230
+ return this.transport.request({ method: 'GET', route: '/screener', cache: 'default' }, options);
231
+ }
232
+ save(body, options) {
233
+ return this.transport.request({ method: 'POST', route: '/screener', cache: 'none', body }, options);
559
234
  }
560
- /**
561
- * Get corporate action calendar.
562
- */
563
- async getCalendar(params) {
564
- return this.client.get('/analysis/calendar', params);
565
- }
566
- /**
567
- * Alias for getCalendar.
568
- */
569
- async getCorporateActionCalendar(params) {
570
- return this.getCalendar(params);
571
- }
572
- /**
573
- * Get multi-timeframe chart data for stocks or indexes.
574
- */
575
- async getMultiTimeChart(code, params) {
576
- return this.client.get(`/analysis/chart/multi-time/${code}`, params);
577
- }
578
- /**
579
- * Get high concentration stock ownership data for all issuers.
580
- */
581
- async getShareholderHigh() {
582
- return this.client.get('/analysis/shareholder/high');
583
- }
584
- /**
585
- * Get complete shareholder data with all investor classifications for a specific period.
586
- */
587
- async getShareholderClassification(code, range) {
588
- return this.client.get(`/analysis/shareholder/classification/${code}`, { range: Math.min(range, 36) });
589
- }
590
- /**
591
- * Get latest shareholder data with investor classifications in table format.
592
- */
593
- async getShareholderClassifyTable(code) {
594
- return this.client.get(`/analysis/shareholder/classify-table/${code}`);
595
- }
596
- /**
597
- * Get order queue (order tracking) for a stock at a specific price, side, page, and limit.
598
- */
599
- async getOrderQueue(code, params) {
600
- return this.client.get(`/analysis/queue/${code}`, params);
235
+ update(id, body, options) {
236
+ return this.transport.request({ method: 'PUT', route: '/screener/{id}', cache: 'none', pathParams: { id }, body }, options);
237
+ }
238
+ delete(id, options) {
239
+ return this.transport.request({ method: 'DELETE', route: '/screener/{id}', cache: 'none', pathParams: { id } }, options);
601
240
  }
602
241
  }
603
-
604
- class WatchlistsEndpoints {
605
- constructor(client) {
606
- this.client = client;
607
- }
608
- /**
609
- * Get list of watchlists.
610
- */
611
- async list(group = 'null') {
612
- return this.client.get('/watchlists', { group });
613
- }
614
- /**
615
- * Add stock to watchlist.
616
- */
617
- async add(dto) {
618
- return this.client.post('/watchlists', dto);
619
- }
620
- /**
621
- * Delete watchlist entries.
622
- *
623
- * The current OpenAPI spec does not describe delete filters,
624
- * but the SDK keeps optional query params for batch deletion support.
625
- */
626
- async delete(params) {
627
- return this.client.delete('/watchlists', params);
628
- }
629
- /**
630
- * Get list of watchlist groups.
631
- */
632
- async listGroups() {
633
- return this.client.get('/watchlists/group');
634
- }
635
- /**
636
- * Add new watchlist group.
637
- */
638
- async addGroup(dto) {
639
- return this.client.post('/watchlists/group', dto);
640
- }
641
- /**
642
- * Update watchlist group.
643
- */
644
- async updateGroup(id, dto) {
645
- return this.client.put(`/watchlists/group/${id}`, dto);
646
- }
647
- /**
648
- * Delete watchlist group.
649
- */
650
- async deleteGroup(id) {
651
- return this.client.delete(`/watchlists/group/${id}`);
652
- }
653
- /**
654
- * Update watchlist.
655
- */
656
- async update(id, dto) {
657
- return this.client.put(`/watchlists/${id}`, dto);
658
- }
659
- /**
660
- * Update watchlist note.
661
- */
662
- async updateNote(id, dto) {
663
- return this.client.patch(`/watchlists/${id}`, dto);
242
+ class UsageResource {
243
+ transport;
244
+ constructor(transport) {
245
+ this.transport = transport;
246
+ }
247
+ getApiUsage(options) {
248
+ return this.transport.request({ method: 'GET', route: '/usage/api', cache: 'none' }, options);
249
+ }
250
+ getLogs(params, options) {
251
+ return this.transport.request({ method: 'GET', route: '/usage/logs', cache: 'none', query: params }, options);
664
252
  }
665
253
  }
666
-
667
- class JournalsEndpoints {
668
- constructor(client) {
669
- this.client = client;
670
- }
671
- /**
672
- * Extract journal transactions from uploaded file.
673
- */
674
- async extractFromFile(file) {
675
- const formData = new FormData();
676
- formData.append('file', file);
677
- const url = `${this.client.baseURL}/journals/file`;
678
- const response = await fetch(url, {
679
- method: 'POST',
680
- headers: {
681
- Authorization: `Bearer ${this.client.apiKey}`,
682
- },
683
- body: formData,
684
- });
685
- if (!response.ok) {
686
- const data = (await response.json().catch(() => ({})));
687
- throw new InvezgoError(response.status, data.message || 'Failed to extract journal from file', data.error, data);
688
- }
689
- return response.json().catch(() => ({}));
690
- }
691
- /**
692
- * Add new journal transaction.
693
- */
694
- async add(dto) {
695
- return this.client.post('/journals', dto);
696
- }
697
- /**
698
- * List journal transactions.
699
- */
700
- async list() {
701
- return this.client.get('/journals');
702
- }
703
- /**
704
- * Delete journal entries.
705
- *
706
- * The current OpenAPI spec does not describe delete filters,
707
- * but the SDK keeps optional query params for batch deletion support.
708
- */
709
- async delete(params) {
710
- return this.client.delete('/journals', params);
711
- }
712
- /**
713
- * Get journal transactions summary.
714
- */
715
- async getSummary() {
716
- return this.client.get('/journals/summary');
717
- }
718
- /**
719
- * Update journal transaction note.
720
- */
721
- async updateNote(id, dto) {
722
- return this.client.patch(`/journals/${id}`, dto);
254
+ class WatchlistsResource {
255
+ transport;
256
+ constructor(transport) {
257
+ this.transport = transport;
258
+ }
259
+ list(params, options) {
260
+ return this.transport.request({ method: 'GET', route: '/watchlists', cache: 'default', query: params }, options);
261
+ }
262
+ add(body, options) {
263
+ return this.transport.request({ method: 'POST', route: '/watchlists', cache: 'none', body }, options);
264
+ }
265
+ delete(body, options) {
266
+ return this.transport.request({ method: 'DELETE', route: '/watchlists', cache: 'none', body }, options);
267
+ }
268
+ listGroups(options) {
269
+ return this.transport.request({ method: 'GET', route: '/watchlists/group', cache: 'default' }, options);
270
+ }
271
+ addGroup(body, options) {
272
+ return this.transport.request({ method: 'POST', route: '/watchlists/group', cache: 'none', body }, options);
273
+ }
274
+ updateGroup(id, body, options) {
275
+ return this.transport.request({ method: 'PUT', route: '/watchlists/group/{id}', cache: 'none', pathParams: { id }, body }, options);
276
+ }
277
+ deleteGroup(id, options) {
278
+ return this.transport.request({ method: 'DELETE', route: '/watchlists/group/{id}', cache: 'none', pathParams: { id } }, options);
279
+ }
280
+ update(id, body, options) {
281
+ return this.transport.request({ method: 'PUT', route: '/watchlists/{id}', cache: 'none', pathParams: { id }, body }, options);
282
+ }
283
+ updateNote(id, body, options) {
284
+ return this.transport.request({ method: 'PATCH', route: '/watchlists/{id}', cache: 'none', pathParams: { id }, body }, options);
723
285
  }
724
286
  }
725
-
726
- class PortfoliosEndpoints {
727
- constructor(client) {
728
- this.client = client;
729
- }
730
- /**
731
- * Get list of portfolios
732
- */
733
- async list() {
734
- return this.client.get('/portfolios');
735
- }
736
- /**
737
- * Get portfolio summary
738
- */
739
- async getSummary() {
740
- return this.client.get('/portfolios/summary');
287
+ class JournalsResource {
288
+ transport;
289
+ constructor(transport) {
290
+ this.transport = transport;
291
+ }
292
+ add(body, options) {
293
+ return this.transport.request({ method: 'POST', route: '/journals', cache: 'none', body }, options);
294
+ }
295
+ list(params, options) {
296
+ return this.transport.request({ method: 'GET', route: '/journals', cache: 'default', query: params }, options);
297
+ }
298
+ delete(body, options) {
299
+ return this.transport.request({ method: 'DELETE', route: '/journals', cache: 'none', body }, options);
300
+ }
301
+ getSummary(params, options) {
302
+ return this.transport.request({ method: 'GET', route: '/journals/summary', cache: 'default', query: params }, options);
741
303
  }
742
304
  }
743
-
744
- class SearchEndpoints {
745
- constructor(client) {
746
- this.client = client;
747
- }
748
- /**
749
- * Search for stocks or users
750
- */
751
- async search(query) {
752
- return this.client.get('/search', { query });
753
- }
754
- /**
755
- * Search for stocks
756
- */
757
- async searchStock(query, cursor) {
758
- return this.client.get('/search/stock', { query, cursor });
759
- }
760
- /**
761
- * Search for users
762
- */
763
- async searchUser(query, cursor) {
764
- return this.client.get('/search/user', { query, cursor });
305
+ class PortfoliosResource {
306
+ transport;
307
+ constructor(transport) {
308
+ this.transport = transport;
309
+ }
310
+ list(options) {
311
+ return this.transport.request({ method: 'GET', route: '/portfolios', cache: 'default' }, options);
312
+ }
313
+ getSummary(options) {
314
+ return this.transport.request({ method: 'GET', route: '/portfolios/summary', cache: 'default' }, options);
765
315
  }
766
316
  }
767
-
768
- class ProfileEndpoints {
769
- constructor(client) {
770
- this.client = client;
771
- }
772
- /**
773
- * Get user profile details
774
- */
775
- async getUserDetails(username) {
776
- return this.client.get(`/profile/detail/${username}`);
777
- }
778
- /**
779
- * Get user posts
780
- */
781
- async getUserPosts(username, page, limit) {
782
- return this.client.get(`/profile/posts/${username}`, { page, limit });
783
- }
784
- /**
785
- * Get user posts by category
786
- */
787
- async getCategoryPosts(username, category, page, limit) {
788
- return this.client.get(`/profile/posts/${username}/${category}`, { page, limit });
789
- }
790
- /**
791
- * Get user watchlist
792
- */
793
- async getUserWatchlist(username) {
794
- return this.client.get(`/profile/watchlist/${username}`);
795
- }
796
- /**
797
- * Get user followers
798
- */
799
- async getFollowers(username) {
800
- return this.client.get(`/profile/follow/${username}`);
801
- }
802
- /**
803
- * Get users being followed
804
- */
805
- async getFollowing(username) {
806
- return this.client.get(`/profile/following/${username}`);
807
- }
808
- /**
809
- * Get user memberships
810
- */
811
- async getMemberships(username) {
812
- return this.client.get(`/profile/membership/${username}`);
317
+ class AlertsResource {
318
+ transport;
319
+ constructor(transport) {
320
+ this.transport = transport;
321
+ }
322
+ create(body, options) {
323
+ return this.transport.request({ method: 'POST', route: '/alerts', cache: 'none', body }, options);
324
+ }
325
+ list(options) {
326
+ return this.transport.request({ method: 'GET', route: '/alerts', cache: 'default' }, options);
327
+ }
328
+ test(body, options) {
329
+ return this.transport.request({ method: 'POST', route: '/alerts/test', cache: 'none', body }, options);
330
+ }
331
+ update(id, body, options) {
332
+ return this.transport.request({ method: 'PUT', route: '/alerts/{id}', cache: 'none', pathParams: { id }, body }, options);
333
+ }
334
+ delete(id, options) {
335
+ return this.transport.request({ method: 'DELETE', route: '/alerts/{id}', cache: 'none', pathParams: { id } }, options);
813
336
  }
814
337
  }
815
-
816
- class MembershipEndpoints {
817
- constructor(client) {
818
- this.client = client;
819
- }
820
- /**
821
- * Get list of memberships.
822
- */
823
- async list() {
824
- return this.client.get('/membership');
825
- }
826
- /**
827
- * Add new membership.
828
- */
829
- async add(dto) {
830
- return this.client.post('/membership', dto);
831
- }
832
- /**
833
- * Get membership scopes.
834
- */
835
- async getScope() {
836
- return this.client.get('/membership/scope');
837
- }
838
- /**
839
- * Get membership transactions.
840
- */
841
- async getTransactions() {
842
- return this.client.get('/membership/list');
843
- }
844
- /**
845
- * Update membership.
846
- */
847
- async update(id, dto) {
848
- return this.client.put(`/membership/${id}`, dto);
849
- }
850
- /**
851
- * Delete membership.
852
- */
853
- async delete(id) {
854
- return this.client.delete(`/membership/${id}`);
338
+ class PostsResource {
339
+ transport;
340
+ constructor(transport) {
341
+ this.transport = transport;
342
+ }
343
+ list(params, options) {
344
+ return this.transport.request({ method: 'GET', route: '/posts', cache: 'default', query: params }, options);
345
+ }
346
+ listByCategory(category, params, options) {
347
+ return this.transport.request({ method: 'GET', route: '/posts/category/{category}', cache: 'default', pathParams: { category }, query: params }, options);
348
+ }
349
+ listByStock(code, params, options) {
350
+ return this.transport.request({ method: 'GET', route: '/posts/space/{code}', cache: 'default', pathParams: { code }, query: params }, options);
351
+ }
352
+ listByStockCategory(code, category, params, options) {
353
+ return this.transport.request({ method: 'GET', route: '/posts/space/category/{code}/{category}', cache: 'default', pathParams: { code, category }, query: params }, options);
354
+ }
355
+ get(id, options) {
356
+ return this.transport.request({ method: 'GET', route: '/posts/detail/{id}', cache: 'default', pathParams: { id } }, options);
357
+ }
358
+ getComments(id, params, options) {
359
+ return this.transport.request({ method: 'GET', route: '/posts/comment/{id}', cache: 'default', pathParams: { id }, query: params }, options);
360
+ }
361
+ getLikes(params, options) {
362
+ return this.transport.request({ method: 'GET', route: '/posts/like', cache: 'default', query: params }, options);
363
+ }
364
+ getFavorites(params, options) {
365
+ return this.transport.request({ method: 'GET', route: '/posts/favorite', cache: 'default', query: params }, options);
366
+ }
367
+ getVoters(id, options) {
368
+ return this.transport.request({ method: 'GET', route: '/posts/vote/{id}', cache: 'default', pathParams: { id } }, options);
855
369
  }
856
370
  }
857
-
858
- class PostsEndpoints {
859
- constructor(client) {
860
- this.client = client;
861
- }
862
- /**
863
- * Get all posts
864
- */
865
- async getAll() {
866
- return this.client.get('/posts');
867
- }
868
- /**
869
- * Get posts by category
870
- */
871
- async getByCategory(category) {
872
- return this.client.get(`/posts/category/${category}`);
873
- }
874
- /**
875
- * Get posts for a stock
876
- */
877
- async getStockPosts(code) {
878
- return this.client.get(`/posts/space/${code}`);
879
- }
880
- /**
881
- * Get stock posts by category
882
- */
883
- async getStockCategoryPosts(code, category) {
884
- return this.client.get(`/posts/space/category/${code}/${category}`);
885
- }
886
- /**
887
- * Get post details
888
- */
889
- async getPostById(id) {
890
- return this.client.get(`/posts/detail/${id}`);
891
- }
892
- /**
893
- * Get post comments
894
- */
895
- async getComments(id) {
896
- return this.client.get(`/posts/comment/${id}`);
897
- }
898
- /**
899
- * Get liked posts
900
- */
901
- async getLiked() {
902
- return this.client.get('/posts/like');
903
- }
904
- /**
905
- * Get favorite posts
906
- */
907
- async getFavorites() {
908
- return this.client.get('/posts/favorite');
909
- }
910
- /**
911
- * Get post voters
912
- */
913
- async getVoters(id) {
914
- return this.client.get(`/posts/vote/${id}`);
371
+ class TradesResource {
372
+ transport;
373
+ constructor(transport) {
374
+ this.transport = transport;
375
+ }
376
+ list(params, options) {
377
+ return this.transport.request({ method: 'GET', route: '/trades', cache: 'default', query: params }, options);
378
+ }
379
+ delete(body, options) {
380
+ return this.transport.request({ method: 'DELETE', route: '/trades', cache: 'none', body }, options);
381
+ }
382
+ getSummary(params, options) {
383
+ return this.transport.request({ method: 'GET', route: '/trades/summary', cache: 'default', query: params }, options);
384
+ }
385
+ getSummaryChart(params, options) {
386
+ return this.transport.request({ method: 'GET', route: '/trades/summary-chart', cache: 'default', query: params }, options);
387
+ }
388
+ updateNote(id, body, options) {
389
+ return this.transport.request({ method: 'PATCH', route: '/trades/{id}', cache: 'none', pathParams: { id }, body }, options);
390
+ }
391
+ }
392
+ class InvezgoResources {
393
+ analysis;
394
+ batch;
395
+ search;
396
+ screener;
397
+ usage;
398
+ watchlists;
399
+ journals;
400
+ portfolios;
401
+ alerts;
402
+ posts;
403
+ trades;
404
+ constructor(transport) {
405
+ this.analysis = new AnalysisResource(transport);
406
+ this.batch = new BatchResource(transport);
407
+ this.search = new SearchResource(transport);
408
+ this.screener = new ScreenerResource(transport);
409
+ this.usage = new UsageResource(transport);
410
+ this.watchlists = new WatchlistsResource(transport);
411
+ this.journals = new JournalsResource(transport);
412
+ this.portfolios = new PortfoliosResource(transport);
413
+ this.alerts = new AlertsResource(transport);
414
+ this.posts = new PostsResource(transport);
415
+ this.trades = new TradesResource(transport);
915
416
  }
916
417
  }
917
418
 
918
- class RecommendationEndpoints {
919
- constructor(client) {
920
- this.client = client;
419
+ const encoder = new TextEncoder();
420
+ class LruCache {
421
+ maxEntries;
422
+ maxBytes;
423
+ now;
424
+ map = new Map();
425
+ totalBytes = 0;
426
+ constructor(maxEntries, maxBytes, now = () => performance.now()) {
427
+ this.maxEntries = maxEntries;
428
+ this.maxBytes = maxBytes;
429
+ this.now = now;
430
+ }
431
+ get size() {
432
+ return this.map.size;
433
+ }
434
+ get bytes() {
435
+ return this.totalBytes;
436
+ }
437
+ get(key) {
438
+ const entry = this.map.get(key);
439
+ if (!entry)
440
+ return undefined;
441
+ this.map.delete(key);
442
+ if (entry.expiresAt <= this.now()) {
443
+ this.totalBytes -= entry.size;
444
+ return undefined;
445
+ }
446
+ this.map.set(key, entry);
447
+ return entry.body;
448
+ }
449
+ set(key, body, ttlMs) {
450
+ const size = encoder.encode(body).length;
451
+ this.delete(key);
452
+ if (ttlMs <= 0 || size > this.maxBytes || this.maxEntries <= 0)
453
+ return;
454
+ this.map.set(key, { body, size, expiresAt: this.now() + ttlMs });
455
+ this.totalBytes += size;
456
+ for (const [oldest, entry] of this.map) {
457
+ if (this.map.size <= this.maxEntries && this.totalBytes <= this.maxBytes)
458
+ break;
459
+ this.map.delete(oldest);
460
+ this.totalBytes -= entry.size;
461
+ }
462
+ }
463
+ delete(key) {
464
+ const entry = this.map.get(key);
465
+ if (entry) {
466
+ this.map.delete(key);
467
+ this.totalBytes -= entry.size;
468
+ }
469
+ }
470
+ deleteWhere(predicate) {
471
+ for (const key of [...this.map.keys()])
472
+ if (predicate(key))
473
+ this.delete(key);
921
474
  }
922
- /**
923
- * Get user recommendations.
924
- */
925
- async getUserRecommendations() {
926
- return this.client.get('/recommendation/user');
475
+ clear() {
476
+ this.map.clear();
477
+ this.totalBytes = 0;
927
478
  }
928
479
  }
929
480
 
930
- class TradesEndpoints {
931
- constructor(client) {
932
- this.client = client;
933
- }
934
- /**
935
- * Get list of realized trades
936
- */
937
- async list() {
938
- return this.client.get('/trades');
939
- }
940
- /**
941
- * Delete trades
942
- */
943
- async delete(params) {
944
- return this.client.delete('/trades', params);
945
- }
946
- /**
947
- * Get trades summary
948
- */
949
- async getSummary() {
950
- return this.client.get('/trades/summary');
951
- }
952
- /**
953
- * Get trades summary chart
954
- */
955
- async getSummaryChart() {
956
- return this.client.get('/trades/summary-chart');
957
- }
958
- /**
959
- * Update trade note
960
- */
961
- async updateNote(id, dto) {
962
- return this.client.patch(`/trades/${id}`, dto);
481
+ class InvezgoError extends Error {
482
+ status;
483
+ error;
484
+ requestId;
485
+ path;
486
+ body;
487
+ constructor(init) {
488
+ super(init.message, init.cause === undefined ? undefined : { cause: init.cause });
489
+ this.name = new.target.name;
490
+ this.status = init.status;
491
+ this.error = init.error;
492
+ this.requestId = init.requestId;
493
+ this.path = init.path;
494
+ this.body = init.body;
963
495
  }
964
496
  }
965
-
966
- class ScreenerEndpoints {
967
- constructor(client) {
968
- this.client = client;
969
- }
970
- /**
971
- * Get list of preset screeners.
972
- */
973
- async list() {
974
- return this.client.get('/screener');
975
- }
976
- /**
977
- * Save preset screener.
978
- */
979
- async save(dto) {
980
- return this.client.post('/screener', dto);
981
- }
982
- /**
983
- * Update preset screener.
984
- */
985
- async update(id, dto) {
986
- return this.client.put(`/screener/${id}`, dto);
987
- }
988
- /**
989
- * Delete preset screener.
990
- */
991
- async delete(id) {
992
- return this.client.delete(`/screener/${id}`);
993
- }
994
- /**
995
- * Run screener.
996
- */
997
- async screen(dto) {
998
- return this.client.post('/screener/screen', dto);
497
+ class ValidationError extends InvezgoError {
498
+ }
499
+ class AuthenticationError extends InvezgoError {
500
+ }
501
+ class PaymentRequiredError extends InvezgoError {
502
+ }
503
+ class NotFoundError extends InvezgoError {
504
+ }
505
+ class ServerError extends InvezgoError {
506
+ }
507
+ class RateLimitError extends InvezgoError {
508
+ retryAfter;
509
+ limit;
510
+ remaining;
511
+ reset;
512
+ quotaExceeded;
513
+ constructor(init) {
514
+ super(init);
515
+ this.retryAfter = init.retryAfter;
516
+ this.limit = init.limit;
517
+ this.remaining = init.remaining;
518
+ this.reset = init.reset;
519
+ this.quotaExceeded = init.quotaExceeded;
999
520
  }
1000
521
  }
522
+ class ConnectionError extends InvezgoError {
523
+ }
524
+ class TimeoutError extends ConnectionError {
525
+ }
526
+ function errorClassFor(status) {
527
+ if (status === 400 || status === 422)
528
+ return ValidationError;
529
+ if (status === 401)
530
+ return AuthenticationError;
531
+ if (status === 402)
532
+ return PaymentRequiredError;
533
+ if (status === 404)
534
+ return NotFoundError;
535
+ if (status >= 500)
536
+ return ServerError;
537
+ return InvezgoError;
538
+ }
1001
539
 
1002
- class UsageEndpoints {
1003
- constructor(client) {
1004
- this.client = client;
540
+ const VERSION = '2.0.0';
541
+ const DEFAULT_BASE_URL = 'https://api.invezgo.com';
542
+ const PERSONAL_SEGMENTS = new Set(['watchlists', 'journals', 'portfolios', 'trades', 'alerts', 'screener']);
543
+ const QUOTA_MESSAGE = /quota|kuota|monthly|bulanan/i;
544
+ class Transport {
545
+ keys;
546
+ baseUrl;
547
+ timeout;
548
+ fetchImpl;
549
+ cache;
550
+ ttlMs = 0;
551
+ realtimeTtlMs = 0;
552
+ blocks = new Map();
553
+ constructor(config) {
554
+ if (!config || typeof config.apiKey !== 'string' || !config.apiKey.trim()) {
555
+ throw new TypeError('Invezgo: `apiKey` is required');
556
+ }
557
+ this.keys = [...new Set([config.apiKey, ...(config.additionalApiKeys ?? [])].filter((k) => !!k && !!k.trim()))];
558
+ this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, '');
559
+ this.timeout = config.timeout ?? 30_000;
560
+ const f = config.fetch ?? globalThis.fetch;
561
+ if (typeof f !== 'function')
562
+ throw new TypeError('Invezgo: global fetch is unavailable; pass `fetch` in the config (Node >= 18)');
563
+ this.fetchImpl = f;
564
+ if (config.cache !== false) {
565
+ const o = config.cache === true || config.cache === undefined ? {} : config.cache;
566
+ this.cache = new LruCache(o.maxEntries ?? 1000, o.maxBytes ?? 32 * 1024 * 1024);
567
+ this.ttlMs = (o.ttl ?? 60) * 1000;
568
+ this.realtimeTtlMs = (o.realtimeTtl ?? 5) * 1000;
569
+ }
1005
570
  }
1006
- /**
1007
- * Get API usage statistics for the configured API key.
1008
- */
1009
- async getApiUsage() {
1010
- return this.client.get('/usage/api');
571
+ clearCache() {
572
+ this.cache?.clear();
573
+ }
574
+ async request(spec, options) {
575
+ const path = spec.route.replace(/\{(\w+)\}/g, (_, name) => {
576
+ const value = spec.pathParams?.[name];
577
+ if (value === undefined || value === null || value === '')
578
+ throw new TypeError(`Invezgo: path parameter \`${name}\` is required`);
579
+ return encodeURIComponent(String(value));
580
+ });
581
+ const qs = canonicalQuery(spec.query);
582
+ const target = qs ? `${path}?${qs}` : path;
583
+ const ttl = spec.method !== 'GET' ? 0 : spec.cache === 'realtime' ? this.realtimeTtlMs : spec.cache === 'default' ? this.ttlMs : 0;
584
+ if (this.cache && ttl > 0) {
585
+ const hit = this.cache.get(target);
586
+ if (hit !== undefined)
587
+ return parseBody(hit);
588
+ }
589
+ const tried = new Set();
590
+ let last;
591
+ for (;;) {
592
+ const index = this.pickKey(spec.route, tried);
593
+ if (index < 0)
594
+ throw this.allKeysBlocked(spec.route, last);
595
+ tried.add(index);
596
+ const res = await this.send(index, spec, target, options);
597
+ const text = await res.text();
598
+ if (res.status === 429) {
599
+ last = this.rateLimited(index, spec.route, res, text);
600
+ continue;
601
+ }
602
+ if (!res.ok)
603
+ throw buildError(res, text);
604
+ let data;
605
+ try {
606
+ data = parseBody(text);
607
+ }
608
+ catch (cause) {
609
+ throw new InvezgoError({ status: res.status, message: 'Invezgo: response is not valid JSON', body: text, path, cause });
610
+ }
611
+ if (this.cache) {
612
+ if (ttl > 0)
613
+ this.cache.set(target, text, ttl);
614
+ else if (spec.method !== 'GET')
615
+ this.cache.deleteWhere((key) => PERSONAL_SEGMENTS.has(key.split(/[/?]/)[1]));
616
+ }
617
+ return data;
618
+ }
619
+ }
620
+ async send(index, spec, target, options) {
621
+ const headers = {
622
+ Authorization: `Bearer ${this.keys[index]}`,
623
+ Accept: 'application/json',
624
+ 'User-Agent': `invezgo-js-sdk/${VERSION}`,
625
+ };
626
+ let body;
627
+ if (spec.body !== undefined) {
628
+ headers['Content-Type'] = 'application/json';
629
+ body = JSON.stringify(spec.body);
630
+ }
631
+ const controller = new AbortController();
632
+ let timedOut = false;
633
+ const timer = setTimeout(() => {
634
+ timedOut = true;
635
+ controller.abort();
636
+ }, this.timeout);
637
+ const signal = options?.signal;
638
+ const onAbort = () => controller.abort(signal?.reason);
639
+ if (signal?.aborted)
640
+ onAbort();
641
+ else
642
+ signal?.addEventListener('abort', onAbort, { once: true });
643
+ try {
644
+ return await this.fetchImpl(this.baseUrl + target, { method: spec.method, headers, body, signal: controller.signal });
645
+ }
646
+ catch (cause) {
647
+ if (signal?.aborted)
648
+ throw cause;
649
+ if (timedOut)
650
+ throw new TimeoutError({ status: 0, message: `Invezgo: request timed out after ${this.timeout} ms`, path: target, cause });
651
+ throw new ConnectionError({ status: 0, message: `Invezgo: network error: ${cause?.message ?? cause}`, path: target, cause });
652
+ }
653
+ finally {
654
+ clearTimeout(timer);
655
+ signal?.removeEventListener('abort', onAbort);
656
+ }
657
+ }
658
+ blockedFor(index, route, now) {
659
+ let ms = 0;
660
+ let quota = false;
661
+ for (const [id, isQuota] of [[`${index}`, true], [`${index} ${route}`, false]]) {
662
+ const b = this.blocks.get(id);
663
+ if (!b)
664
+ continue;
665
+ if (b.until <= now)
666
+ this.blocks.delete(id);
667
+ else if (b.until - now > ms) {
668
+ ms = b.until - now;
669
+ quota = isQuota;
670
+ }
671
+ }
672
+ return { ms, quota };
673
+ }
674
+ pickKey(route, tried) {
675
+ const now = performance.now();
676
+ for (let i = 0; i < this.keys.length; i++) {
677
+ if (!tried.has(i) && this.blockedFor(i, route, now).ms === 0)
678
+ return i;
679
+ }
680
+ return -1;
681
+ }
682
+ rateLimited(index, route, res, text) {
683
+ const err = buildError(res, text);
684
+ const retryAfter = num(res.headers.get('retry-after'));
685
+ const reset = num(res.headers.get('x-ratelimit-reset'));
686
+ let wait = 60;
687
+ if (retryAfter !== undefined && retryAfter > 0)
688
+ wait = retryAfter;
689
+ else if (reset !== undefined && reset - Date.now() / 1000 > 0)
690
+ wait = reset - Date.now() / 1000;
691
+ const quota = QUOTA_MESSAGE.test(err.message);
692
+ this.blocks.set(quota ? `${index}` : `${index} ${route}`, { until: performance.now() + wait * 1000, quota });
693
+ return new RateLimitError({
694
+ status: 429,
695
+ message: err.message,
696
+ error: err.error,
697
+ requestId: err.requestId,
698
+ path: err.path,
699
+ body: err.body,
700
+ retryAfter: Math.ceil(wait),
701
+ limit: num(res.headers.get('x-ratelimit-limit')),
702
+ remaining: num(res.headers.get('x-ratelimit-remaining')),
703
+ reset,
704
+ quotaExceeded: quota,
705
+ });
706
+ }
707
+ allKeysBlocked(route, last) {
708
+ const now = performance.now();
709
+ let min = Infinity;
710
+ let allQuota = true;
711
+ for (let i = 0; i < this.keys.length; i++) {
712
+ const b = this.blockedFor(i, route, now);
713
+ min = Math.min(min, b.ms);
714
+ allQuota &&= b.quota;
715
+ }
716
+ const retryAfter = Math.max(0, Math.ceil((Number.isFinite(min) ? min : 0) / 1000));
717
+ if (last) {
718
+ return new RateLimitError({ ...last, message: last.message, retryAfter, quotaExceeded: last.quotaExceeded });
719
+ }
720
+ return new RateLimitError({
721
+ status: 429,
722
+ message: `Invezgo: all API keys are rate limited; retry in ${retryAfter}s`,
723
+ retryAfter,
724
+ quotaExceeded: allQuota,
725
+ });
1011
726
  }
1012
727
  }
728
+ function canonicalQuery(query) {
729
+ if (!query)
730
+ return '';
731
+ const entries = Object.entries(query)
732
+ .filter(([, v]) => v !== undefined && v !== null)
733
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
734
+ .map(([k, v]) => [k, String(v)]);
735
+ return new URLSearchParams(entries).toString();
736
+ }
737
+ function parseBody(text) {
738
+ return text.trim() === '' ? null : JSON.parse(text);
739
+ }
740
+ function num(value) {
741
+ if (value === null || value.trim() === '')
742
+ return undefined;
743
+ const n = Number(value);
744
+ return Number.isFinite(n) ? n : undefined;
745
+ }
746
+ function buildError(res, text) {
747
+ let body = text;
748
+ try {
749
+ body = text ? JSON.parse(text) : undefined;
750
+ }
751
+ catch {
752
+ }
753
+ const b = (typeof body === 'object' && body !== null ? body : {});
754
+ const msg = Array.isArray(b.message) ? b.message.join('; ') : typeof b.message === 'string' ? b.message : '';
755
+ const Cls = errorClassFor(res.status);
756
+ return new Cls({
757
+ status: res.status,
758
+ message: msg || res.statusText || `HTTP ${res.status}`,
759
+ error: typeof b.error === 'string' ? b.error : undefined,
760
+ requestId: typeof b.requestId === 'string' ? b.requestId : (res.headers.get('request-id') ?? undefined),
761
+ path: typeof b.path === 'string' ? b.path : undefined,
762
+ body,
763
+ });
764
+ }
1013
765
 
1014
- class Invezgo {
766
+ class Invezgo extends InvezgoResources {
767
+ #transport;
1015
768
  constructor(config) {
1016
- this.client = new HttpClient(config);
1017
- this.alerts = new AlertsEndpoints(this.client);
1018
- this.analysis = new AnalysisEndpoints(this.client);
1019
- this.watchlists = new WatchlistsEndpoints(this.client);
1020
- this.journals = new JournalsEndpoints(this.client);
1021
- this.portfolios = new PortfoliosEndpoints(this.client);
1022
- this.search = new SearchEndpoints(this.client);
1023
- this.profile = new ProfileEndpoints(this.client);
1024
- this.membership = new MembershipEndpoints(this.client);
1025
- this.posts = new PostsEndpoints(this.client);
1026
- this.recommendation = new RecommendationEndpoints(this.client);
1027
- this.trades = new TradesEndpoints(this.client);
1028
- this.screener = new ScreenerEndpoints(this.client);
1029
- this.usage = new UsageEndpoints(this.client);
1030
- }
1031
- /**
1032
- * Update API key.
1033
- */
1034
- setApiKey(apiKey) {
1035
- this.client.apiKey = apiKey;
1036
- }
1037
- /**
1038
- * Check whether an API key is currently configured.
1039
- */
1040
- hasApiKey() {
1041
- return !!this.client.apiKey;
769
+ const transport = new Transport(config);
770
+ super(transport);
771
+ this.#transport = transport;
772
+ }
773
+ clearCache() {
774
+ this.#transport.clearCache();
1042
775
  }
1043
776
  }
1044
777
 
1045
- /**
1046
- * Invezgo SDK for JavaScript and TypeScript.
1047
- *
1048
- * Official SDK for accessing Invezgo API.
1049
- *
1050
- * @packageDocumentation
1051
- */
1052
-
1053
- export { AlertsEndpoints, Invezgo, InvezgoError, JournalsEndpoints, MembershipEndpoints, RecommendationEndpoints, ScreenerEndpoints, TradesEndpoints, UsageEndpoints, WatchlistsEndpoints, Invezgo as default };
778
+ exports.AlertsResource = AlertsResource;
779
+ exports.AnalysisResource = AnalysisResource;
780
+ exports.AuthenticationError = AuthenticationError;
781
+ exports.BatchResource = BatchResource;
782
+ exports.ConnectionError = ConnectionError;
783
+ exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL;
784
+ exports.Invezgo = Invezgo;
785
+ exports.InvezgoClient = Invezgo;
786
+ exports.InvezgoError = InvezgoError;
787
+ exports.InvezgoResources = InvezgoResources;
788
+ exports.JournalsResource = JournalsResource;
789
+ exports.NotFoundError = NotFoundError;
790
+ exports.PaymentRequiredError = PaymentRequiredError;
791
+ exports.PortfoliosResource = PortfoliosResource;
792
+ exports.PostsResource = PostsResource;
793
+ exports.RateLimitError = RateLimitError;
794
+ exports.ScreenerResource = ScreenerResource;
795
+ exports.SearchResource = SearchResource;
796
+ exports.ServerError = ServerError;
797
+ exports.TimeoutError = TimeoutError;
798
+ exports.TradesResource = TradesResource;
799
+ exports.UsageResource = UsageResource;
800
+ exports.VERSION = VERSION;
801
+ exports.ValidationError = ValidationError;
802
+ exports.WatchlistsResource = WatchlistsResource;
803
+ exports.default = Invezgo;
1054
804
  //# sourceMappingURL=index.js.map